superio/ite/*: Move setting of power state to common code

Move the programming of the power state after power failure to the ITE
EC common code, in order to unify and extend to other ITE SIO chips.
The implementations in the it8720f and it8728f are functionally
identical, so take the "best" style elements of both, using clear
variable names and defines for registers rather than magic values.

Change-Id: I4b7e9455e964320f35997fdf04a515b942e030c7
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87382
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Maxim Polyakov <max.senia.poliak@gmail.com>
This commit is contained in:
Matt DeVillier 2025-04-20 14:20:36 -05:00
commit fbca3e6806
5 changed files with 41 additions and 64 deletions

View file

@ -4,6 +4,7 @@
#include <delay.h>
#include <stddef.h>
#include <superio/hwm5_conf.h>
#include <option.h>
#include "env_ctrl.h"
#include "env_ctrl_chip.h"
@ -374,3 +375,30 @@ void ite_ec_init(const u16 base, const struct ite_ec_config *const conf)
if (conf->tmpin[i].mode == THERMAL_PECI)
extemp_force_idle_status(base);
}
void ite_ec_set_power_state(struct device *dev)
{
uint8_t power_status;
uint8_t reg_pcr1, reg_pcr2;
/* Set power state after power fail */
power_status = get_uint_option("power_on_after_fail",
CONFIG_MAINBOARD_POWER_FAILURE_STATE);
pnp_enter_conf_mode(dev);
pnp_set_logical_device(dev);
reg_pcr1 = pnp_read_config(dev, ITE_EC_REG_PCR1);
reg_pcr2 = pnp_read_config(dev, ITE_EC_REG_PCR2);
if (power_status == MAINBOARD_POWER_ON) {
reg_pcr2 |= (1 << 5);
} else if (power_status == MAINBOARD_POWER_KEEP) {
reg_pcr2 &= ~(1 << 5);
reg_pcr1 |= (1 << 5);
} else {
reg_pcr2 &= ~(1 << 5);
reg_pcr1 &= ~(1 << 5);
}
pnp_write_config(dev, ITE_EC_REG_PCR1, reg_pcr1);
pnp_write_config(dev, ITE_EC_REG_PCR2, reg_pcr2);
pnp_exit_conf_mode(dev);
printk(BIOS_INFO, "set power %u after power fail\n", power_status);
}

View file

@ -235,6 +235,17 @@ static const u8 ITE_EC_TEMP_ADJUST[] = { 0x56, 0x57, 0x59 };
#define PECI_GETTEMP_WRITE_LENGTH 0x01
#define PECI_GETTEMP_READ_LENGTH 0x02
/* Registers in EC LDN */
#define ITE_EC_REG_PCR1 0xf2
#define ITE_EC_REG_PCR2 0xf4
/* These must match the values in src/mainboard/Kconfig */
#define MAINBOARD_POWER_OFF 0
#define MAINBOARD_POWER_ON 1
#define MAINBOARD_POWER_KEEP 2
void ite_ec_set_power_state(struct device *dev);
void ite_ec_init(u16 base, const struct ite_ec_config *conf);
#endif /* SUPERIO_ITE_ENV_CTRL_H */

View file

@ -14,8 +14,4 @@
#define IT8720F_GPIO 0x07 /* GPIO (including SPI flash interface) */
#define IT8720F_CIR 0x0a /* Consumer IR */
/* Registers in LDNs */
#define IT8720F_EC_PCR1 0xf2
#define IT8720F_EC_PCR2 0xf4
#endif /* SUPERIO_ITE_IT8720F_H */

View file

@ -3,7 +3,6 @@
#include <device/device.h>
#include <device/pnp.h>
#include <pc80/keyboard.h>
#include <option.h>
#include <superio/ite/common/env_ctrl.h>
#include <superio/conf_mode.h>
#include <types.h>
@ -11,35 +10,6 @@
#include "chip.h"
#include "it8720f.h"
#define MAINBOARD_POWER_OFF 0
#define MAINBOARD_POWER_ON 1
#define MAINBOARD_POWER_KEEP 2
static void power_control_init(struct device *dev)
{
unsigned int power_on = get_uint_option("power_on_after_fail", MAINBOARD_POWER_OFF);
u8 value;
pnp_enter_conf_mode(dev);
pnp_set_logical_device(dev);
value = pnp_read_config(dev, IT8720F_EC_PCR1);
if (power_on == MAINBOARD_POWER_KEEP)
value |= (1 << 5);
else
value &= ~(1 << 5);
pnp_write_config(dev, IT8720F_EC_PCR1, value);
value = pnp_read_config(dev, IT8720F_EC_PCR2);
if (power_on == MAINBOARD_POWER_ON)
value |= (1 << 5);
else
value &= ~(1 << 5);
pnp_write_config(dev, IT8720F_EC_PCR2, value);
pnp_exit_conf_mode(dev);
}
static void it8720f_init(struct device *dev)
{
const struct superio_ite_it8720f_config *conf;
@ -55,7 +25,7 @@ static void it8720f_init(struct device *dev)
if (!conf || !res)
break;
ite_ec_init(res->base, &conf->ec);
power_control_init(dev);
ite_ec_set_power_state(dev);
break;
case IT8720F_KBCK:
pc_keyboard_init(NO_AUX_DEVICE);

View file

@ -5,21 +5,14 @@
#include <superio/conf_mode.h>
#include <pc80/keyboard.h>
#include <superio/ite/common/env_ctrl.h>
#include <option.h>
#include "chip.h"
#include "it8728f.h"
#define MAINBOARD_POWER_OFF 0
#define MAINBOARD_POWER_ON 1
#define MAINBOARD_POWER_KEEP 2
static void it8728f_init(struct device *dev)
{
const struct superio_ite_it8728f_config *conf = dev->chip_info;
const struct resource *res;
uint8_t power_status;
uint8_t byte_f2, byte_f4;
if (!dev->enabled)
return;
@ -31,28 +24,7 @@ static void it8728f_init(struct device *dev)
if (!conf || !res)
break;
ite_ec_init(res->base, &conf->ec);
/* Set power state after power fail */
power_status = get_uint_option("power_on_after_fail",
CONFIG_MAINBOARD_POWER_FAILURE_STATE);
pnp_enter_conf_mode(dev);
pnp_set_logical_device(dev);
byte_f4 = pnp_read_config(dev, 0xf4);
byte_f2 = pnp_read_config(dev, 0xf2);
if (power_status == MAINBOARD_POWER_ON) {
byte_f4 |= 0x20;
} else if (power_status == MAINBOARD_POWER_KEEP) {
byte_f4 &= ~0x20;
byte_f2 |= 0x20;
} else {
byte_f4 &= ~0x20;
byte_f2 &= ~0x20;
}
pnp_write_config(dev, 0xf4, byte_f4);
pnp_write_config(dev, 0xf2, byte_f2);
pnp_exit_conf_mode(dev);
printk(BIOS_INFO, "set power %u after power fail\n", power_status);
ite_ec_set_power_state(dev);
break;
case IT8728F_KBCK:
set_kbc_ps2_mode();