1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * SMI handler -- mostly takes care of SMIs from the EC
8 #include <console/console.h>
9 #include <cpu/x86/smm.h>
10 #include <ec/compal/ene932/ec.h>
11 #include <southbridge/amd/agesa/hudson/hudson.h>
12 #include <southbridge/amd/agesa/hudson/smi.h>
16 #define ACPI_PM1_CNT_SLEEP(state) ((1 << 13) | (state & 0x7) << 10)
27 EC_SMI_EVENT_IDLE
= 0x80,
28 EC_SMI_BATTERY_LOW
= 0xb3,
31 /* Tell EC to operate in APM mode. Events generate SMIs instead of SCIs */
32 static void ec_enter_apm_mode(void)
34 ec_kbc_write_cmd(0x59);
35 ec_kbc_write_ib(0xE9);
37 /* Tell EC to operate in ACPI mode, thus generating SCIs on events, not SMIs */
38 static void ec_enter_acpi_mode(void)
40 ec_kbc_write_cmd(0x59);
41 ec_kbc_write_ib(0xE8);
44 static uint8_t ec_get_smi_event(void)
46 ec_kbc_write_cmd(0x56);
47 return ec_kbc_read_ob();
50 static void ec_process_smi(uint8_t src
)
52 /* Reading the SMI source satisfies the EC in terms of responding to
53 * the event, regardless of whether we take an action or not.
57 case EC_SMI_BATTERY_LOW
:
58 printk(BIOS_DEBUG
, "Battery low. Shutting down\n");
59 outl(ACPI_PM1_CNT_SLEEP(S5
), ACPI_PM1_CNT_BLK
);
62 printk(BIOS_DEBUG
, "EC_SMI event 0x%x\n", src
);
66 static void handle_ec_smi(void)
70 while ((src
= ec_get_smi_event()) != EC_SMI_EVENT_IDLE
)
74 static void handle_lid_smi(void)
76 /* Only triggered in non-ACPI mode on lid close. */
77 outl(ACPI_PM1_CNT_SLEEP(S4
), ACPI_PM1_CNT_BLK
);
80 int mainboard_smi_apmc(uint8_t data
)
83 case ACPI_SMI_CMD_ENABLE
:
84 printk(BIOS_DEBUG
, "Enable ACPI mode\n");
86 hudson_disable_gevent_smi(EC_LID_GEVENT
);
88 case ACPI_SMI_CMD_DISABLE
:
89 printk(BIOS_DEBUG
, "Disable ACPI mode\n");
91 hudson_configure_gevent_smi(EC_LID_GEVENT
, SMI_MODE_SMI
,
95 printk(BIOS_DEBUG
, "Unhandled ACPI command: 0x%x\n", data
);
100 void mainboard_smi_gpi(uint32_t gpi_sts
)
102 if (gpi_sts
& (1 << EC_SMI_GEVENT
))
104 if (gpi_sts
& (1 << EC_LID_GEVENT
))