1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
9 #include <ec/google/chromeec/ec.h>
18 /* The wake gpio is SUS_GPIO[0]. */
19 #define WAKE_GPIO_EN SUS_GPIO_EN0
21 int mainboard_io_trap_handler(int smif
)
25 printk(BIOS_DEBUG
, "Sample\n");
33 * On success, the IO Trap Handler returns 0
34 * On failure, the IO Trap Handler returns a value != 0
36 * For now, we force the return value to 0 and log all traps to
37 * see what's going on.
43 static uint8_t mainboard_smi_ec(void)
45 uint8_t cmd
= google_chromeec_get_event();
46 uint16_t pmbase
= get_pmbase();
51 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT
, cmd
);
54 case EC_HOST_EVENT_LID_CLOSED
:
55 printk(BIOS_DEBUG
, "LID CLOSED, SHUTDOWN\n");
58 pm1_cnt
= inl(pmbase
+ PM1_CNT
);
59 pm1_cnt
|= SLP_EN
| (SLP_TYP_S5
<< SLP_TYP_SHIFT
);
60 outl(pm1_cnt
, pmbase
+ PM1_CNT
);
68 * The entire 32-bit ALT_GPIO_SMI register is passed as a parameter. Note, that
69 * this includes the enable bits in the lower 16 bits.
71 void mainboard_smi_gpi(uint32_t alt_gpio_smi
)
73 if (alt_gpio_smi
& (1 << EC_SMI_GPI
)) {
74 /* Process all pending events */
75 while (mainboard_smi_ec() != 0)
80 void mainboard_smi_sleep(uint8_t slp_typ
)
82 /* Disable USB charging if required */
86 google_chromeec_set_usb_charge_mode(
87 0, USB_CHARGE_MODE_DISABLED
);
89 google_chromeec_set_usb_charge_mode(
90 1, USB_CHARGE_MODE_DISABLED
);
92 /* Enable wake events */
93 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS
);
94 /* Enable wake pin in GPE block. */
95 enable_gpe(WAKE_GPIO_EN
);
99 google_chromeec_set_usb_charge_mode(
100 0, USB_CHARGE_MODE_DISABLED
);
102 google_chromeec_set_usb_charge_mode(
103 1, USB_CHARGE_MODE_DISABLED
);
105 /* Enable wake events */
106 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS
);
110 /* Disable SCI and SMI events */
111 google_chromeec_set_smi_mask(0);
112 google_chromeec_set_sci_mask(0);
114 /* Clear pending events that may trigger immediate wake */
115 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE
)
118 /* Set LPC lines to low power in S3/S5. */
119 if ((slp_typ
== ACPI_S3
) || (slp_typ
== ACPI_S5
))
123 int mainboard_smi_apmc(uint8_t apmc
)
126 case APM_CNT_ACPI_ENABLE
:
127 google_chromeec_set_smi_mask(0);
128 /* Clear all pending events */
129 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE
)
131 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS
);
133 case APM_CNT_ACPI_DISABLE
:
134 google_chromeec_set_sci_mask(0);
135 /* Clear all pending events */
136 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE
)
138 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS
);