From fbca3e6806bfcc44de99295bbe07d7ac0da5da5f Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Sun, 20 Apr 2025 14:20:36 -0500 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/87382 Tested-by: build bot (Jenkins) Reviewed-by: Maxim Polyakov --- src/superio/ite/common/env_ctrl.c | 28 +++++++++++++++++++++++++++ src/superio/ite/common/env_ctrl.h | 11 +++++++++++ src/superio/ite/it8720f/it8720f.h | 4 ---- src/superio/ite/it8720f/superio.c | 32 +------------------------------ src/superio/ite/it8728f/superio.c | 30 +---------------------------- 5 files changed, 41 insertions(+), 64 deletions(-) diff --git a/src/superio/ite/common/env_ctrl.c b/src/superio/ite/common/env_ctrl.c index 105d6da8cf..c6b5ef04d5 100644 --- a/src/superio/ite/common/env_ctrl.c +++ b/src/superio/ite/common/env_ctrl.c @@ -4,6 +4,7 @@ #include #include #include +#include #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); +} diff --git a/src/superio/ite/common/env_ctrl.h b/src/superio/ite/common/env_ctrl.h index 8a461aa3f2..4471bea756 100644 --- a/src/superio/ite/common/env_ctrl.h +++ b/src/superio/ite/common/env_ctrl.h @@ -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 */ diff --git a/src/superio/ite/it8720f/it8720f.h b/src/superio/ite/it8720f/it8720f.h index 45c8256b64..77159506eb 100644 --- a/src/superio/ite/it8720f/it8720f.h +++ b/src/superio/ite/it8720f/it8720f.h @@ -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 */ diff --git a/src/superio/ite/it8720f/superio.c b/src/superio/ite/it8720f/superio.c index 4491c10134..b51e768aef 100644 --- a/src/superio/ite/it8720f/superio.c +++ b/src/superio/ite/it8720f/superio.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -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); diff --git a/src/superio/ite/it8728f/superio.c b/src/superio/ite/it8728f/superio.c index f3bdd85b49..ca18e68f57 100644 --- a/src/superio/ite/it8728f/superio.c +++ b/src/superio/ite/it8728f/superio.c @@ -5,21 +5,14 @@ #include #include #include -#include #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();