mb/google/brya: Create rull variant
[coreboot2.git] / src / mainboard / lenovo / s230u / smihandler.c
blobf5fb9b4a7d1211e0847df2c17838c455915206af
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <cpu/x86/smm.h>
5 #include <ec/acpi/ec.h>
6 #include <ec/compal/ene932/ec.h>
7 #include <southbridge/intel/bd82x6x/pch.h>
8 #include <southbridge/intel/common/pmutil.h>
10 #include "ec.h"
12 #define GPE_PALMDET1 2
13 #define GPE_PALMDET2 4
14 #define GPE_EC_SCI 7
15 #define GPE_EC_SMI 8
16 /* FIXME: check this */
17 #define GPE_EC_WAKE 13
19 enum sleep_states {
20 S0 = 0,
21 S1 = 1,
22 S3 = 3,
23 S4 = 4,
24 S5 = 5,
27 enum ec_smi_event {
28 EC_SMI_EVENT_IDLE = 0x80,
29 EC_SMI_BATTERY_LOW = 0xb3,
32 /* Tell EC to operate in APM mode. Events generate SMIs instead of SCIs. */
33 static void ec_enter_apm_mode(void)
35 ec_kbc_write_cmd(0x59);
36 ec_kbc_write_ib(0xE9);
38 /* Tell EC to operate in ACPI mode, thus generating SCIs on events, not SMIs. */
39 static void ec_enter_acpi_mode(void)
41 ec_kbc_write_cmd(0x59);
42 ec_kbc_write_ib(0xE8);
45 static uint8_t ec_get_smi_event(void)
47 ec_kbc_write_cmd(0x56);
48 return ec_kbc_read_ob();
51 static void ec_process_smi(uint8_t src)
54 * Reading the SMI source satisfies the EC in terms of responding to
55 * the event, regardless of whether we take an action or not.
58 printk(BIOS_DEBUG, "Unhandled EC_SMI event 0x%x\n", src);
61 static void handle_ec_smi(void)
63 uint8_t src;
65 while ((src = ec_get_smi_event()) != EC_SMI_EVENT_IDLE)
66 ec_process_smi(src);
69 void mainboard_smi_gpi(u32 gpi_sts)
71 if (gpi_sts & (1 << GPE_EC_SMI))
72 handle_ec_smi();
75 int mainboard_smi_apmc(u8 data)
77 switch (data) {
78 case APM_CNT_ACPI_ENABLE:
79 ec_enter_acpi_mode();
80 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
81 gpi_route_interrupt(GPE_PALMDET1, GPI_IS_SCI);
82 gpi_route_interrupt(GPE_PALMDET2, GPI_IS_SCI);
83 break;
84 case APM_CNT_ACPI_DISABLE:
85 ec_enter_apm_mode();
86 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
87 break;
88 default:
89 printk(BIOS_DEBUG, "Unhandled ACPI command: 0x%x\n", data);
91 return 0;
94 void mainboard_smi_sleep(u8 slp_typ)
96 if (slp_typ == S3) {
97 u8 ec_wake = ec_read(0x32);
98 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
99 if (ec_wake & 0x14)
100 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);