blob: 7e22fbb6c8f9b29a3954bae29d79865d83653f14 [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 <arch/io.h>
5#include <console/console.h>
6#include <cpu/x86/smm.h>
Marc Jonesd8621212015-06-09 21:18:38 -06007#include <soc/pm.h>
Marc Jones07cf24c2015-06-09 14:42:55 -06008#include <elog.h>
Marc Jones07cf24c2015-06-09 14:42:55 -06009#include <ec/google/chromeec/ec.h>
Marc Jonesd8621212015-06-09 21:18:38 -060010#include <soc/gpio.h>
11#include <soc/iomap.h>
12#include <soc/nvs.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060013#include "ec.h"
Matt DeVillier45e11aa2016-12-18 11:59:58 -060014#include <variant/onboard.h>
Marc Jonesd8621212015-06-09 21:18:38 -060015
Marc Jones07cf24c2015-06-09 14:42:55 -060016static u8 mainboard_smi_ec(void)
17{
18 u8 cmd = google_chromeec_get_event();
19 u32 pm1_cnt;
20
Marc Jones07cf24c2015-06-09 14:42:55 -060021 /* Log this event */
22 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020023 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Marc Jones07cf24c2015-06-09 14:42:55 -060024
25 switch (cmd) {
26 case EC_HOST_EVENT_LID_CLOSED:
27 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
28
29 /* Go to S5 */
Marc Jonesd8621212015-06-09 21:18:38 -060030 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060031 pm1_cnt |= (0xf << 10);
Marc Jonesd8621212015-06-09 21:18:38 -060032 outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060033 break;
34 }
35
36 return cmd;
37}
38
39/* gpi_sts is GPIO 47:32 */
40void mainboard_smi_gpi(u32 gpi_sts)
41{
42 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
43 /* Process all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -060044 while (mainboard_smi_ec() != 0)
45 ;
Marc Jones07cf24c2015-06-09 14:42:55 -060046 }
47}
48
Matt DeVillier45e11aa2016-12-18 11:59:58 -060049static void mainboard_disable_gpios(void)
50{
Julius Wernercd49cce2019-03-05 16:53:33 -080051#if CONFIG(BOARD_GOOGLE_SAMUS)
Matt DeVillier45e11aa2016-12-18 11:59:58 -060052 /* Put SSD in reset to prevent leak */
53 set_gpio(BOARD_SSD_RESET_GPIO, 0);
54 /* Disable LTE */
55 set_gpio(BOARD_LTE_DISABLE_GPIO, 0);
56#else
57 set_gpio(BOARD_PP3300_CODEC_GPIO, 0);
58#endif
59 /* Prevent leak from standby rail to WLAN rail */
60 set_gpio(BOARD_WLAN_DISABLE_GPIO, 0);
61}
62
Marc Jones07cf24c2015-06-09 14:42:55 -060063void mainboard_smi_sleep(u8 slp_typ)
64{
65 /* Disable USB charging if required */
66 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050067 case ACPI_S3:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030068 if (gnvs->s3u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060069 google_chromeec_set_usb_charge_mode(
70 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060071 google_chromeec_set_usb_charge_mode(
72 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060073 }
Marc Jones07cf24c2015-06-09 14:42:55 -060074
Matt DeVillier45e11aa2016-12-18 11:59:58 -060075 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060076
77 /* Enable wake events */
78 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
79 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050080 case ACPI_S5:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030081 if (gnvs->s5u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060082 google_chromeec_set_usb_charge_mode(
83 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060084 google_chromeec_set_usb_charge_mode(
85 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060086 }
Marc Jones07cf24c2015-06-09 14:42:55 -060087
Matt DeVillier45e11aa2016-12-18 11:59:58 -060088 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060089
90 /* Enable wake events */
91 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
92 break;
93 }
94
95 /* Disable SCI and SMI events */
96 google_chromeec_set_smi_mask(0);
97 google_chromeec_set_sci_mask(0);
98
99 /* Clear pending events that may trigger immediate wake */
Marc Jonesd8621212015-06-09 21:18:38 -0600100 while (google_chromeec_get_event() != 0)
101 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600102}
103
Marc Jones07cf24c2015-06-09 14:42:55 -0600104int mainboard_smi_apmc(u8 apmc)
105{
106 switch (apmc) {
Marc Jones07cf24c2015-06-09 14:42:55 -0600107 case APM_CNT_ACPI_ENABLE:
108 google_chromeec_set_smi_mask(0);
109 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600110 while (google_chromeec_get_event() != 0)
111 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600112 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
113 break;
114 case APM_CNT_ACPI_DISABLE:
115 google_chromeec_set_sci_mask(0);
116 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600117 while (google_chromeec_get_event() != 0)
118 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600119 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
120 break;
121 }
122 return 0;
123}