blob: 237a2b3c31093be4a4f8ca9ec507dd019ee82e7d [file] [log] [blame]
Angel Pons58c0d322020-04-05 13:20:46 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones07cf24c2015-06-09 14:42:55 -06002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Marc Jones07cf24c2015-06-09 14:42:55 -06004#include <console/console.h>
5#include <cpu/x86/smm.h>
Marc Jonesd8621212015-06-09 21:18:38 -06006#include <soc/pm.h>
Marc Jones07cf24c2015-06-09 14:42:55 -06007#include <ec/google/chromeec/ec.h>
Kyösti Mälkki923b8ec2022-11-29 07:36:44 +02008#include <ec/google/chromeec/smm.h>
Angel Pons52e48b52021-01-28 17:03:19 +01009#include <southbridge/intel/lynxpoint/lp_gpio.h>
Marc Jonesd8621212015-06-09 21:18:38 -060010#include <soc/iomap.h>
11#include <soc/nvs.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060012#include "ec.h"
Matt DeVillier45e11aa2016-12-18 11:59:58 -060013#include <variant/onboard.h>
Marc Jonesd8621212015-06-09 21:18:38 -060014
Marc Jones07cf24c2015-06-09 14:42:55 -060015/* gpi_sts is GPIO 47:32 */
16void mainboard_smi_gpi(u32 gpi_sts)
17{
Kyösti Mälkki83faa5d2023-01-05 15:39:16 +020018 if (gpi_sts & (1 << (EC_SMI_GPI - 32)))
19 chromeec_smi_process_events();
Marc Jones07cf24c2015-06-09 14:42:55 -060020}
21
Matt DeVillier45e11aa2016-12-18 11:59:58 -060022static void mainboard_disable_gpios(void)
23{
Julius Wernercd49cce2019-03-05 16:53:33 -080024#if CONFIG(BOARD_GOOGLE_SAMUS)
Matt DeVillier45e11aa2016-12-18 11:59:58 -060025 /* Put SSD in reset to prevent leak */
26 set_gpio(BOARD_SSD_RESET_GPIO, 0);
27 /* Disable LTE */
28 set_gpio(BOARD_LTE_DISABLE_GPIO, 0);
29#else
30 set_gpio(BOARD_PP3300_CODEC_GPIO, 0);
31#endif
32 /* Prevent leak from standby rail to WLAN rail */
33 set_gpio(BOARD_WLAN_DISABLE_GPIO, 0);
34}
35
Marc Jones07cf24c2015-06-09 14:42:55 -060036void mainboard_smi_sleep(u8 slp_typ)
37{
38 /* Disable USB charging if required */
39 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050040 case ACPI_S3:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030041 if (gnvs->s3u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060042 google_chromeec_set_usb_charge_mode(
43 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060044 google_chromeec_set_usb_charge_mode(
45 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060046 }
Marc Jones07cf24c2015-06-09 14:42:55 -060047
Matt DeVillier45e11aa2016-12-18 11:59:58 -060048 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060049
50 /* Enable wake events */
51 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
52 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050053 case ACPI_S5:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030054 if (gnvs->s5u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060055 google_chromeec_set_usb_charge_mode(
56 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060057 google_chromeec_set_usb_charge_mode(
58 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060059 }
Marc Jones07cf24c2015-06-09 14:42:55 -060060
Matt DeVillier45e11aa2016-12-18 11:59:58 -060061 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060062
63 /* Enable wake events */
64 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
65 break;
66 }
67
68 /* Disable SCI and SMI events */
69 google_chromeec_set_smi_mask(0);
70 google_chromeec_set_sci_mask(0);
71
72 /* Clear pending events that may trigger immediate wake */
Rob Barnesf1ade482021-06-14 10:22:21 -060073 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE)
Marc Jonesd8621212015-06-09 21:18:38 -060074 ;
Marc Jones07cf24c2015-06-09 14:42:55 -060075}
76
Marc Jones07cf24c2015-06-09 14:42:55 -060077int mainboard_smi_apmc(u8 apmc)
78{
Kyösti Mälkki923b8ec2022-11-29 07:36:44 +020079 chromeec_smi_apmc(apmc, MAINBOARD_EC_SCI_EVENTS, MAINBOARD_EC_SMI_EVENTS);
Marc Jones07cf24c2015-06-09 14:42:55 -060080 return 0;
81}