mb/ocp/tiogapass: Fix GPIOs
[coreboot2.git] / src / mainboard / lenovo / l520 / smihandler.c
blobb5c6395f51f1120e28dd7de721c7a94f29a08557
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/io.h>
4 #include <console/console.h>
5 #include <cpu/x86/smm.h>
6 #include <ec/acpi/ec.h>
7 #include <ec/lenovo/h8/h8.h>
8 #include <southbridge/intel/common/pmutil.h>
9 #include <southbridge/intel/bd82x6x/pch.h>
11 #define GPE_EC_SCI 6
12 /* FIXME: check this */
13 #define GPE_EC_WAKE 13
15 static void mainboard_smi_handle_ec_sci(void)
17 u8 status = inb(EC_SC);
18 u8 event;
20 if (!(status & EC_SCI_EVT))
21 return;
23 event = ec_query();
24 printk(BIOS_DEBUG, "EC event %#02x\n", event);
27 void mainboard_smi_gpi(u32 gpi_sts)
29 if (gpi_sts & (1 << GPE_EC_SCI))
30 mainboard_smi_handle_ec_sci();
33 int mainboard_smi_apmc(u8 data)
35 switch (data) {
36 case APM_CNT_ACPI_ENABLE:
37 /* use 0x1600/0x1604 to prevent races with userspace */
38 ec_set_ports(0x1604, 0x1600);
39 /* route EC_SCI to SCI */
40 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
41 /* discard all events, and enable attention */
42 ec_write(0x80, 0x01);
43 break;
44 case APM_CNT_ACPI_DISABLE:
45 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
46 provide a EC query function */
47 ec_set_ports(0x66, 0x62);
48 /* route EC_SCI to SMI */
49 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
50 /* discard all events, and enable attention */
51 ec_write(0x80, 0x01);
52 break;
53 default:
54 break;
56 return 0;
59 void mainboard_smi_sleep(u8 slp_typ)
61 if (slp_typ == 3) {
62 u8 ec_wake = ec_read(0x32);
63 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
64 if (ec_wake & 0x14) {
65 /* Redirect EC WAKE GPE to SCI. */
66 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);