From 01885609e80cd66d809711ab49c23dbb68f9f6eb Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Wed, 12 Oct 2022 17:03:26 -0600 Subject: [PATCH] HACK: pmc: Add hack to force S0ix entry on lemp11 lemp11 sometimes fails to reach C10 and gets stuck in C0 during s2idle. For some reason, sending a PMC SCI allows the CPU to go to C10. Signed-off-by: Tim Crawford --- src/board/system76/common/acpi.c | 8 ++++++- src/board/system76/common/pmc.c | 35 ++++++++++++++++++++++++++++++ src/board/system76/lemp11/board.mk | 2 ++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/board/system76/common/acpi.c b/src/board/system76/common/acpi.c index 3a36f05..192fc84 100644 --- a/src/board/system76/common/acpi.c +++ b/src/board/system76/common/acpi.c @@ -19,6 +19,8 @@ extern uint8_t sci_extra; enum EcOs acpi_ecos = EC_OS_NONE; +extern bool pmc_s0_hack; + static uint8_t fcmd = 0; static uint8_t fdat = 0; static uint8_t fbuf[4] = { 0, 0, 0, 0 }; @@ -130,7 +132,11 @@ uint8_t acpi_read(uint8_t addr) { ACPI_16(0x42, battery_info.cycle_count); - ACPI_8(0x68, acpi_ecos); + case 0x68: + data = acpi_ecos; + // HACK: Kick PMC to fix suspend on lemp11 + pmc_s0_hack = true; + break; case 0xBC: data = battery_get_start_threshold(); diff --git a/src/board/system76/common/pmc.c b/src/board/system76/common/pmc.c index 539bb22..abc46d7 100644 --- a/src/board/system76/common/pmc.c +++ b/src/board/system76/common/pmc.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only +#include #include #include #include @@ -8,6 +9,12 @@ #include #include +#ifndef PMC_S0IX_HACK +#define PMC_S0IX_HACK 0 +#endif + +bool pmc_s0_hack = false; + void pmc_init(void) { *(PMC_1.control) = 0x41; *(PMC_2.control) = 0x41; @@ -180,9 +187,37 @@ static void pmc_on_output_empty(struct Pmc * pmc) { } } +#if PMC_S0IX_HACK +// HACK: Kick PMC to fix suspend on lemp11 +static void pmc_hack(void) { + static bool pmc_s0_hack2 = false; + static uint32_t last_time = 0; + // Get time the system requested S0ix (ACPI MS0X) + if (pmc_s0_hack) { + last_time = time_get(); + pmc_s0_hack = false; + pmc_s0_hack2 = true; + } + uint32_t time = time_get(); + // If SLP_S0# not asserted after 5 seconds, apply the hack + if ((time - last_time) >= 5000) { + if (pmc_s0_hack2 && gpio_get(&SLP_S0_N)) { + DEBUG("FIXME: PMC HACK\n"); + pmc_sci(&PMC_1, 0x50); + } + pmc_s0_hack2 = false; + last_time = time; + } +} +#else +static void pmc_hack(void) {} +#endif + void pmc_event(struct Pmc * pmc) { uint8_t sts; + pmc_hack(); + // Read command/data if available sts = pmc_status(pmc); if (sts & PMC_STS_IBF) { diff --git a/src/board/system76/lemp11/board.mk b/src/board/system76/lemp11/board.mk index 2fc6827..5469c0d 100644 --- a/src/board/system76/lemp11/board.mk +++ b/src/board/system76/lemp11/board.mk @@ -7,6 +7,8 @@ CFLAGS+=-DEC_ESPI=1 # Use S0ix CFLAGS+=-DUSE_S0IX=1 +# Apply PMC hack for S0ix +CFLAGS+=-DPMC_S0IX_HACK=1 # Include keyboard KEYBOARD=14in_83