blob: 153a07169b7d3a1b70e2177416e3f1e2839242d6 [file] [log] [blame]
Angel Pons58c0d322020-04-05 13:20:46 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Marc Jones07cf24c2015-06-09 14:42:55 -06003
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
Marc Jones07cf24c2015-06-09 14:42:55 -06005#include <arch/io.h>
6#include <console/console.h>
7#include <cpu/x86/smm.h>
Marc Jonesd8621212015-06-09 21:18:38 -06008#include <soc/pm.h>
Marc Jones07cf24c2015-06-09 14:42:55 -06009#include <elog.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060010#include <ec/google/chromeec/ec.h>
Marc Jonesd8621212015-06-09 21:18:38 -060011#include <soc/gpio.h>
12#include <soc/iomap.h>
13#include <soc/nvs.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060014#include "ec.h"
Matt DeVillier45e11aa2016-12-18 11:59:58 -060015#include <variant/onboard.h>
Marc Jonesd8621212015-06-09 21:18:38 -060016
Marc Jones07cf24c2015-06-09 14:42:55 -060017static u8 mainboard_smi_ec(void)
18{
19 u8 cmd = google_chromeec_get_event();
20 u32 pm1_cnt;
21
Marc Jones07cf24c2015-06-09 14:42:55 -060022 /* Log this event */
23 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020024 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Marc Jones07cf24c2015-06-09 14:42:55 -060025
26 switch (cmd) {
27 case EC_HOST_EVENT_LID_CLOSED:
28 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
29
30 /* Go to S5 */
Marc Jonesd8621212015-06-09 21:18:38 -060031 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060032 pm1_cnt |= (0xf << 10);
Marc Jonesd8621212015-06-09 21:18:38 -060033 outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060034 break;
35 }
36
37 return cmd;
38}
39
40/* gpi_sts is GPIO 47:32 */
41void mainboard_smi_gpi(u32 gpi_sts)
42{
43 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
44 /* Process all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -060045 while (mainboard_smi_ec() != 0)
46 ;
Marc Jones07cf24c2015-06-09 14:42:55 -060047 }
48}
49
Matt DeVillier45e11aa2016-12-18 11:59:58 -060050static void mainboard_disable_gpios(void)
51{
Julius Wernercd49cce2019-03-05 16:53:33 -080052#if CONFIG(BOARD_GOOGLE_SAMUS)
Matt DeVillier45e11aa2016-12-18 11:59:58 -060053 /* Put SSD in reset to prevent leak */
54 set_gpio(BOARD_SSD_RESET_GPIO, 0);
55 /* Disable LTE */
56 set_gpio(BOARD_LTE_DISABLE_GPIO, 0);
57#else
58 set_gpio(BOARD_PP3300_CODEC_GPIO, 0);
59#endif
60 /* Prevent leak from standby rail to WLAN rail */
61 set_gpio(BOARD_WLAN_DISABLE_GPIO, 0);
62}
63
Marc Jones07cf24c2015-06-09 14:42:55 -060064void mainboard_smi_sleep(u8 slp_typ)
65{
66 /* Disable USB charging if required */
67 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050068 case ACPI_S3:
Marc Jonesd8621212015-06-09 21:18:38 -060069 if (smm_get_gnvs()->s3u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060070 google_chromeec_set_usb_charge_mode(
71 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060072 google_chromeec_set_usb_charge_mode(
73 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060074 }
Marc Jones07cf24c2015-06-09 14:42:55 -060075
Matt DeVillier45e11aa2016-12-18 11:59:58 -060076 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060077
78 /* Enable wake events */
79 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
80 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050081 case ACPI_S5:
Marc Jonesd8621212015-06-09 21:18:38 -060082 if (smm_get_gnvs()->s5u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060083 google_chromeec_set_usb_charge_mode(
84 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060085 google_chromeec_set_usb_charge_mode(
86 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060087 }
Marc Jones07cf24c2015-06-09 14:42:55 -060088
Matt DeVillier45e11aa2016-12-18 11:59:58 -060089 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060090
91 /* Enable wake events */
92 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
93 break;
94 }
95
96 /* Disable SCI and SMI events */
97 google_chromeec_set_smi_mask(0);
98 google_chromeec_set_sci_mask(0);
99
100 /* Clear pending events that may trigger immediate wake */
Marc Jonesd8621212015-06-09 21:18:38 -0600101 while (google_chromeec_get_event() != 0)
102 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600103}
104
Marc Jones07cf24c2015-06-09 14:42:55 -0600105int mainboard_smi_apmc(u8 apmc)
106{
107 switch (apmc) {
Marc Jones07cf24c2015-06-09 14:42:55 -0600108 case APM_CNT_ACPI_ENABLE:
109 google_chromeec_set_smi_mask(0);
110 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600111 while (google_chromeec_get_event() != 0)
112 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600113 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
114 break;
115 case APM_CNT_ACPI_DISABLE:
116 google_chromeec_set_sci_mask(0);
117 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600118 while (google_chromeec_get_event() != 0)
119 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600120 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
121 break;
122 }
123 return 0;
124}