From dbe6336f908800ec028dc1a1087d6782e5a38851 Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Thu, 17 Apr 2014 00:47:47 -0500 Subject: hp/pavilion_m6_1035dx: Shutdown on low battery with non-ACPI OS Intercept the low battery SMI from the EC, and shut down the system immediately. The EC only sends this SMI when the OS did not enable ACPI mode, so ACPI OSes are not affected by this. On the other hand, payloads such as GRUB or SeaBIOS will experience the shutdown. This behavior is helpful for protecting the battery, for example, when the OS fails to boot and we are stuck in the payload. The low battery SMI is triggered at 10% charge, at which point the risk of cell degradation exists. Change-Id: I4c6c1a4feed8576cbdbb1945768de0805a1f5e42 Signed-off-by: Alexandru Gagniuc Reviewed-on: http://review.coreboot.org/5527 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- .../hp/pavilion_m6_1035dx/mainboard_smi.c | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/mainboard/hp') diff --git a/src/mainboard/hp/pavilion_m6_1035dx/mainboard_smi.c b/src/mainboard/hp/pavilion_m6_1035dx/mainboard_smi.c index bb9cc2e0a2..f9114434ab 100644 --- a/src/mainboard/hp/pavilion_m6_1035dx/mainboard_smi.c +++ b/src/mainboard/hp/pavilion_m6_1035dx/mainboard_smi.c @@ -6,14 +6,26 @@ */ #include "ec.h" +#include #include #include #include #include #include +#define ACPI_PM1_CNT_SLEEP(state) ((1 << 13) | (state & 0x7) << 10) + +enum sleep_states { + S0 = 0, + S1 = 1, + S3 = 3, + S4 = 4, + S5 = 5, +}; + enum ec_smi_event { EC_SMI_EVENT_IDLE = 0x80, + EC_SMI_BATTERY_LOW = 0xb3, }; /* Tell EC to operate in APM mode. Events generate SMIs instead of SCIs */ @@ -37,12 +49,18 @@ static uint8_t ec_get_smi_event(void) static void ec_process_smi(uint8_t src) { - /* - * Stub: We aren't processing any events yet, but reading the SMI source - * satisfies the EC in terms of responding to the event. + /* Reading the SMI source satisfies the EC in terms of responding to + * the event, regardless of whether we take an action or not. */ - printk(BIOS_DEBUG, "EC_SMI event 0x%x\n", src); + switch (src) { + case EC_SMI_BATTERY_LOW: + printk(BIOS_DEBUG, "Battery low. Shutting down\n"); + outl(ACPI_PM1_CNT_SLEEP(S5), ACPI_PM1_CNT_BLK); + break; + default: + printk(BIOS_DEBUG, "EC_SMI event 0x%x\n", src); + } } static void handle_ec_smi(void) -- cgit v1.2.3