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>
12 #define GPE_PALMDET1 2
13 #define GPE_PALMDET2 4
16 /* FIXME: check this */
17 #define GPE_EC_WAKE 13
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)
65 while ((src
= ec_get_smi_event()) != EC_SMI_EVENT_IDLE
)
69 void mainboard_smi_gpi(u32 gpi_sts
)
71 if (gpi_sts
& (1 << GPE_EC_SMI
))
75 int mainboard_smi_apmc(u8 data
)
78 case APM_CNT_ACPI_ENABLE
:
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
);
84 case APM_CNT_ACPI_DISABLE
:
86 gpi_route_interrupt(GPE_EC_SCI
, GPI_IS_SMI
);
89 printk(BIOS_DEBUG
, "Unhandled ACPI command: 0x%x\n", data
);
94 void mainboard_smi_sleep(u8 slp_typ
)
97 u8 ec_wake
= ec_read(0x32);
98 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
100 gpi_route_interrupt(GPE_EC_WAKE
, GPI_IS_SCI
);