summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt DeVillier <matt.devillier@gmail.com>2025-04-20 14:20:36 -0500
committerMatt DeVillier <matt.devillier@gmail.com>2025-04-23 14:16:03 +0000
commitfbca3e6806bfcc44de99295bbe07d7ac0da5da5f (patch)
tree5bd51d25f582d09a8abadaf25d327217678a5456 /src
parent60b414fc135a49751812b37442b8c166cc2ae199 (diff)
downloadcoreboot-fbca3e6806bfcc44de99295bbe07d7ac0da5da5f.tar.gz
coreboot-fbca3e6806bfcc44de99295bbe07d7ac0da5da5f.tar.bz2
coreboot-fbca3e6806bfcc44de99295bbe07d7ac0da5da5f.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/superio/ite/common/env_ctrl.c28
-rw-r--r--src/superio/ite/common/env_ctrl.h11
-rw-r--r--src/superio/ite/it8720f/it8720f.h4
-rw-r--r--src/superio/ite/it8720f/superio.c32
-rw-r--r--src/superio/ite/it8728f/superio.c30
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 105d6da8cff3..c6b5ef04d525 100644
--- a/src/superio/ite/common/env_ctrl.c
+++ b/src/superio/ite/common/env_ctrl.c
@@ -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);
+}
diff --git a/src/superio/ite/common/env_ctrl.h b/src/superio/ite/common/env_ctrl.h
index 8a461aa3f287..4471bea756b3 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 45c8256b6408..77159506eb26 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 4491c101349e..b51e768aef46 100644
--- a/src/superio/ite/it8720f/superio.c
+++ b/src/superio/ite/it8720f/superio.c
@@ -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);
diff --git a/src/superio/ite/it8728f/superio.c b/src/superio/ite/it8728f/superio.c
index f3bdd85b49ae..ca18e68f570e 100644
--- a/src/superio/ite/it8728f/superio.c
+++ b/src/superio/ite/it8728f/superio.c
@@ -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();