From cea89a78d8126c8687617e5e9caf994a96db6df7 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 22 Feb 2023 14:27:47 -0700 Subject: [PATCH] Use ESPI VW signals wherever possible --- src/board/system76/addw3/gpio.c | 2 - src/board/system76/addw3/include/board/gpio.h | 2 - src/board/system76/common/peci.c | 15 ++--- src/board/system76/common/power.c | 65 +++++++++---------- src/board/system76/gaze18/gpio.c | 2 - .../system76/gaze18/include/board/gpio.h | 2 - src/board/system76/oryp11/board.mk | 2 +- .../system76/oryp11/include/board/gpio.h | 2 - src/board/system76/serw13/gpio.c | 2 - .../system76/serw13/include/board/gpio.h | 2 - src/ec/ite/espi.c | 2 + src/ec/ite/include/ec/espi.h | 3 + 12 files changed, 42 insertions(+), 59 deletions(-) diff --git a/src/board/system76/addw3/gpio.c b/src/board/system76/addw3/gpio.c index ba93b05..e47e43d 100644 --- a/src/board/system76/addw3/gpio.c +++ b/src/board/system76/addw3/gpio.c @@ -26,8 +26,6 @@ struct Gpio __code PM_PWROK = GPIO(C, 6); struct Gpio __code PWR_BTN_N = GPIO(D, 5); struct Gpio __code PWR_SW_N = GPIO(B, 3); struct Gpio __code SLP_SUS_N = GPIO(H, 7); -struct Gpio __code SUSB_N_PCH = GPIO(H, 6); -struct Gpio __code SUSC_N_PCH = GPIO(H, 1); struct Gpio __code VA_EC_EN = GPIO(J, 4); struct Gpio __code WLAN_EN = GPIO(G, 1); struct Gpio __code WLAN_PWR_EN = GPIO(D, 3); diff --git a/src/board/system76/addw3/include/board/gpio.h b/src/board/system76/addw3/include/board/gpio.h index 2a74fe3..c27239b 100644 --- a/src/board/system76/addw3/include/board/gpio.h +++ b/src/board/system76/addw3/include/board/gpio.h @@ -33,8 +33,6 @@ extern struct Gpio __code PWR_BTN_N; extern struct Gpio __code PWR_SW_N; extern struct Gpio __code SLP_SUS_N; #define HAVE_SUS_PWR_ACK 0 -extern struct Gpio __code SUSB_N_PCH; -extern struct Gpio __code SUSC_N_PCH; extern struct Gpio __code VA_EC_EN; extern struct Gpio __code WLAN_EN; extern struct Gpio __code WLAN_PWR_EN; diff --git a/src/board/system76/common/peci.c b/src/board/system76/common/peci.c index 543b1fb..9febff0 100644 --- a/src/board/system76/common/peci.c +++ b/src/board/system76/common/peci.c @@ -14,10 +14,6 @@ #define USE_PECI_OVER_ESPI 0 #endif -#ifndef USE_S0IX -#define USE_S0IX 0 -#endif - // Fan speed is the lowest requested over HEATUP seconds #ifndef BOARD_HEATUP #define BOARD_HEATUP 4 @@ -246,13 +242,14 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) { uint8_t peci_get_fan_duty(void) { uint8_t duty; -#if USE_S0IX - // Use PECI if platform is not in CS - peci_on = gpio_get(&SLP_S0_N); -#else // USE_S0IX +#if CONFIG_BUS_ESPI + // Use PECI if CPU is not in C10 sleep state + // HOST_C10 virtual wire is high when CPU is in C10 sleep state + peci_on = !vw_get(&VW_HOST_C10); +#else // CONFIG_BUS_ESPI // Use PECI if in S0 state peci_on = power_state == POWER_STATE_S0; -#endif // USE_S0IX +#endif // CONFIG_BUS_ESPI if (peci_on) { int16_t peci_offset = 0; diff --git a/src/board/system76/common/power.c b/src/board/system76/common/power.c index 216425c..18229f5 100644 --- a/src/board/system76/common/power.c +++ b/src/board/system76/common/power.c @@ -22,10 +22,6 @@ #include #endif -#ifndef USE_S0IX -#define USE_S0IX 0 -#endif - #define GPIO_SET_DEBUG(G, V) \ { \ DEBUG("%s = %s\n", #G, V ? "true" : "false"); \ @@ -64,14 +60,6 @@ #define HAVE_SLP_SUS_N 1 #endif -#ifndef HAVE_SUSB_N_PCH -#define HAVE_SUSB_N_PCH 1 -#endif - -#ifndef HAVE_SUSC_N_PCH -#define HAVE_SUSC_N_PCH 1 -#endif - #ifndef HAVE_SUSWARN_N #define HAVE_SUSWARN_N 1 #endif @@ -133,36 +121,41 @@ enum PowerState power_state = POWER_STATE_OFF; enum PowerState calculate_power_state(void) { //TODO: Deep Sx states using SLP_SUS# -#if HAVE_SUSB_N_PCH - if (gpio_get(&SUSB_N_PCH)) { - // S3, S4, and S5 planes powered - return POWER_STATE_S0; - } -#else - // Use eSPI virtual wire if there is no dedicated GPIO +#if CONFIG_BUS_ESPI + // Use eSPI virtual wires if available + if (vw_get(&VW_SLP_S3_N)) { // S3, S4, and S5 planes powered return POWER_STATE_S0; } -#endif -#if HAVE_SUSC_N_PCH - if (gpio_get(&SUSC_N_PCH)) { - // S4 and S5 planes powered - return POWER_STATE_S3; - } -#else - // Use eSPI virtual wire if there is no dedicated GPIO if (vw_get(&VW_SLP_S4_N)) { // S4 and S5 planes powered return POWER_STATE_S3; } -#endif + + if (vw_get(&VW_SLP_S5_N)) { + // S5 plane powered + return POWER_STATE_S5; + } +#else // CONFIG_BUS_ESPI + // Use dedicated GPIOs if not using ESPI + + if (gpio_get(&SUSB_N_PCH)) { + // S3, S4, and S5 planes powered + return POWER_STATE_S0; + } + + if (gpio_get(&SUSC_N_PCH)) { + // S4 and S5 planes powered + return POWER_STATE_S3; + } if (gpio_get(&EC_RSMRST_N)) { // S5 plane powered return POWER_STATE_S5; } +#endif // CONFIG_BUS_ESPI return POWER_STATE_OFF; } @@ -346,11 +339,12 @@ static bool power_peci_limit(bool ac) { void power_set_limit(void) { static bool last_power_limit_ac = true; // We don't use power_state because the latency needs to be low -#if USE_S0IX - if (gpio_get(&SLP_S0_N)) { -#else +#if CONFIG_BUS_ESPI + // HOST_C10 virtual wire is high when CPU is in C10 sleep state + if (!vw_get(&VW_HOST_C10)) { +#else // CONFIG_BUS_ESPI if (gpio_get(&BUF_PLT_RST_N)) { -#endif +#endif // CONFIG_BUS_ESPI bool ac = !gpio_get(&ACIN_N); if (last_power_limit_ac != ac) { if (power_peci_limit(ac)) { @@ -361,7 +355,7 @@ void power_set_limit(void) { last_power_limit_ac = true; } } -#else +#else // HAVE_DGPU void power_set_limit(void) {} #endif // HAVE_DGPU @@ -582,8 +576,9 @@ void power_event(void) { static uint32_t last_time = 0; uint32_t time = time_get(); if (power_state == POWER_STATE_S0) { -#if USE_S0IX - if (!gpio_get(&SLP_S0_N)) { +#if CONFIG_BUS_ESPI + // HOST_C10 virtual wire is high when CPU is in C10 sleep state + if (vw_get(&VW_HOST_C10)) { // Modern suspend, flashing green light if ((time - last_time) >= 1000) { gpio_set(&LED_PWR, !gpio_get(&LED_PWR)); diff --git a/src/board/system76/gaze18/gpio.c b/src/board/system76/gaze18/gpio.c index e1bc572..5309fc6 100644 --- a/src/board/system76/gaze18/gpio.c +++ b/src/board/system76/gaze18/gpio.c @@ -27,8 +27,6 @@ struct Gpio __code PCH_PWROK_EC = GPIO(F, 3); struct Gpio __code PWR_BTN_N = GPIO(D, 5); struct Gpio __code PWR_SW_N = GPIO(B, 3); struct Gpio __code SLP_SUS_N = GPIO(J, 4); -struct Gpio __code SUSB_N_PCH = GPIO(H, 6); -struct Gpio __code SUSC_N_PCH = GPIO(H, 1); struct Gpio __code VA_EC_EN = GPIO(H, 7); struct Gpio __code WLAN_EN = GPIO(G, 1); struct Gpio __code WLAN_PWR_EN = GPIO(A, 3); diff --git a/src/board/system76/gaze18/include/board/gpio.h b/src/board/system76/gaze18/include/board/gpio.h index 080be9e..8f6dc7c 100644 --- a/src/board/system76/gaze18/include/board/gpio.h +++ b/src/board/system76/gaze18/include/board/gpio.h @@ -34,8 +34,6 @@ extern struct Gpio __code PWR_BTN_N; extern struct Gpio __code PWR_SW_N; extern struct Gpio __code SLP_SUS_N; #define HAVE_SUS_PWR_ACK 0 -extern struct Gpio __code SUSB_N_PCH; -extern struct Gpio __code SUSC_N_PCH; extern struct Gpio __code VA_EC_EN; extern struct Gpio __code WLAN_EN; extern struct Gpio __code WLAN_PWR_EN; diff --git a/src/board/system76/oryp11/board.mk b/src/board/system76/oryp11/board.mk index d10ce71..6ddbfda 100644 --- a/src/board/system76/oryp11/board.mk +++ b/src/board/system76/oryp11/board.mk @@ -34,7 +34,7 @@ CFLAGS+=\ -DCHARGER_CHARGE_VOLTAGE=17600 \ -DCHARGER_INPUT_CURRENT=11500 -# Use PECI over ESPI +# Use PECI over ESPI CFLAGS+=-DUSE_PECI_OVER_ESPI=1 # Set CPU power limits in watts diff --git a/src/board/system76/oryp11/include/board/gpio.h b/src/board/system76/oryp11/include/board/gpio.h index e94b71d..08ed55e 100644 --- a/src/board/system76/oryp11/include/board/gpio.h +++ b/src/board/system76/oryp11/include/board/gpio.h @@ -34,8 +34,6 @@ extern struct Gpio __code PWR_BTN_N; extern struct Gpio __code PWR_SW_N; extern struct Gpio __code SLP_SUS_N; #define HAVE_SUS_PWR_ACK 0 -#define HAVE_SUSB_N_PCH 0 -#define HAVE_SUSC_N_PCH 0 extern struct Gpio __code VA_EC_EN; #define HAVE_WLAN_EN 0 extern struct Gpio __code WLAN_PWR_EN; diff --git a/src/board/system76/serw13/gpio.c b/src/board/system76/serw13/gpio.c index 0e4a22a..afd1e49 100644 --- a/src/board/system76/serw13/gpio.c +++ b/src/board/system76/serw13/gpio.c @@ -26,8 +26,6 @@ struct Gpio __code PCH_PWROK_EC = GPIO(C, 6); struct Gpio __code PWR_BTN_N = GPIO(D, 5); struct Gpio __code PWR_SW_N = GPIO(B, 3); struct Gpio __code SLP_SUS_N = GPIO(H, 7); -struct Gpio __code SUSB_N_PCH = GPIO(H, 6); -struct Gpio __code SUSC_N_PCH = GPIO(H, 1); struct Gpio __code SWI_N = GPIO(B, 5); struct Gpio __code USB_PWR_EN_N = GPIO(E, 3); struct Gpio __code VA_EC_EN = GPIO(J, 4); diff --git a/src/board/system76/serw13/include/board/gpio.h b/src/board/system76/serw13/include/board/gpio.h index b5ca8a5..721e551 100644 --- a/src/board/system76/serw13/include/board/gpio.h +++ b/src/board/system76/serw13/include/board/gpio.h @@ -35,8 +35,6 @@ extern struct Gpio __code PWR_SW_N; extern struct Gpio __code SLP_SUS_N; #define HAVE_SUSWARN_N 0 #define HAVE_SUS_PWR_ACK 0 -extern struct Gpio __code SUSB_N_PCH; -extern struct Gpio __code SUSC_N_PCH; extern struct Gpio __code SWI_N; extern struct Gpio __code USB_PWR_EN_N; extern struct Gpio __code VA_EC_EN; diff --git a/src/ec/ite/espi.c b/src/ec/ite/espi.c index 07576e9..f74a5a7 100644 --- a/src/ec/ite/espi.c +++ b/src/ec/ite/espi.c @@ -34,6 +34,8 @@ struct VirtualWire __code VW_SUS_ACK_N = VIRTUAL_WIRE(40, 0); // Index 41 - AP to EC (platform specific) struct VirtualWire __code VW_SUS_WARN_N = VIRTUAL_WIRE(41, 0); struct VirtualWire __code VW_SUS_PWRDN_ACK = VIRTUAL_WIRE(41, 1); +// Index 47 - AP to EC (platform specific) +struct VirtualWire __code VW_HOST_C10 = VIRTUAL_WIRE(47, 0); enum VirtualWireState vw_get(struct VirtualWire *vw) __critical { uint8_t index = *vw->index; diff --git a/src/ec/ite/include/ec/espi.h b/src/ec/ite/include/ec/espi.h index 1d84075..1035b9c 100644 --- a/src/ec/ite/include/ec/espi.h +++ b/src/ec/ite/include/ec/espi.h @@ -59,6 +59,8 @@ extern struct VirtualWire __code VW_SUS_ACK_N; // Index 41 - AP to EC (platform specific) extern struct VirtualWire __code VW_SUS_WARN_N; extern struct VirtualWire __code VW_SUS_PWRDN_ACK; +// Index 47 - AP to EC (platform specific) +extern struct VirtualWire __code VW_HOST_C10; // General capabilities and configurations volatile uint8_t __xdata __at(0x3107) ESGCAC0; @@ -154,6 +156,7 @@ volatile uint8_t __xdata __at(0x3207) VWIDX7; volatile uint8_t __xdata __at(0x3240) VWIDX40; volatile uint8_t __xdata __at(0x3241) VWIDX41; volatile uint8_t __xdata __at(0x3242) VWIDX42; +volatile uint8_t __xdata __at(0x3247) VWIDX47; // Virtual wire control volatile uint8_t __xdata __at(0x3290) VWCTRL0;