1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <acpi/acpi_gnvs.h>
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
7 #include <ec/google/chromeec/ec.h>
12 static int chromeec_process_one_event(void)
14 uint8_t event
= google_chromeec_get_event();
18 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT
, event
);
21 case EC_HOST_EVENT_LID_CLOSED
:
22 printk(BIOS_DEBUG
, "LID CLOSED, SHUTDOWN\n");
30 void chromeec_smi_process_events(void)
32 /* Process all pending events */
33 while (chromeec_process_one_event())
37 static void clear_pending_events(void)
39 struct ec_response_get_next_event mkbp_event
;
41 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE
)
44 printk(BIOS_DEBUG
, "Clearing pending EC events. Error code EC_RES_UNAVAILABLE(9) is expected.\n");
45 while (google_chromeec_get_mkbp_event(&mkbp_event
) == 0)
49 void chromeec_set_usb_charge_mode(int slp_type
)
51 bool usb0_disable
= 0, usb1_disable
= 0;
53 usb_charge_mode_from_gnvs(slp_type
, &usb0_disable
, &usb1_disable
);
56 google_chromeec_set_usb_charge_mode(0, USB_CHARGE_MODE_DISABLED
);
59 google_chromeec_set_usb_charge_mode(1, USB_CHARGE_MODE_DISABLED
);
62 void chromeec_smi_sleep(int slp_type
, uint64_t s3_mask
, uint64_t s5_mask
)
64 if (!google_chromeec_is_uhepi_supported()) {
67 /* Enable wake events */
68 google_chromeec_set_wake_mask(s3_mask
);
72 /* Enable wake events */
73 google_chromeec_set_wake_mask(s5_mask
);
78 /* Disable SCI and SMI events */
79 google_chromeec_set_smi_mask(0);
80 google_chromeec_set_sci_mask(0);
82 /* Clear pending events that may trigger immediate wake */
83 clear_pending_events();
86 void chromeec_smi_device_event_sleep(int slp_type
, uint64_t s3_mask
,
91 /* Enable device wake events */
92 google_chromeec_set_device_enabled_events(s3_mask
);
95 /* Enable device wake events */
96 google_chromeec_set_device_enabled_events(s5_mask
);
100 /* Read and clear pending events that may trigger immediate wake */
101 google_chromeec_get_device_current_events();
104 void chromeec_smi_apmc(int apmc
, uint64_t sci_mask
, uint64_t smi_mask
)
107 case APM_CNT_ACPI_ENABLE
:
108 google_chromeec_set_smi_mask(0);
109 clear_pending_events();
110 google_chromeec_set_sci_mask(sci_mask
);
112 case APM_CNT_ACPI_DISABLE
:
113 google_chromeec_set_sci_mask(0);
114 clear_pending_events();
115 google_chromeec_set_smi_mask(smi_mask
);