blob: 16a1b18b7a467aa7b361b9ab1a0d7b77945bc27e [file] [log] [blame]
Angel Ponsd28443e2020-04-05 13:22:44 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Matt DeVillierc12e5ae2016-11-27 02:19:02 -06002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Matt DeVillierc12e5ae2016-11-27 02:19:02 -06004#include <arch/io.h>
5#include <console/console.h>
6#include <cpu/x86/smm.h>
Kyösti Mälkki661ad462020-12-29 06:26:21 +02007#include <soc/nvs.h>
Matt DeVillierc12e5ae2016-11-27 02:19:02 -06008#include <southbridge/intel/lynxpoint/pch.h>
9#include <southbridge/intel/common/gpio.h>
10#include <southbridge/intel/lynxpoint/me.h>
11#include <northbridge/intel/haswell/haswell.h>
12#include <cpu/intel/haswell/haswell.h>
13#include <elog.h>
14
15/* Include EC functions */
16#include <ec/google/chromeec/ec.h>
17#include "ec.h"
18
19/* Codec enable: GPIO45 */
20#define GPIO_PP3300_CODEC_EN 45
21/* GPIO46 controls the WLAN_DISABLE_L signal. */
22#define GPIO_WLAN_DISABLE_L 46
23#define GPIO_LTE_DISABLE_L 59
24
25static u8 mainboard_smi_ec(void)
26{
27 u8 cmd = google_chromeec_get_event();
28 u32 pm1_cnt;
29
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060030 /* Log this event */
31 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020032 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060033
34 switch (cmd) {
35 case EC_HOST_EVENT_LID_CLOSED:
36 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
37
38 /* Go to S5 */
39 pm1_cnt = inl(get_pmbase() + PM1_CNT);
40 pm1_cnt |= (0xf << 10);
41 outl(pm1_cnt, get_pmbase() + PM1_CNT);
42 break;
43 }
44
45 return cmd;
46}
47
48/* gpi_sts is GPIO 47:32 */
49void mainboard_smi_gpi(u32 gpi_sts)
50{
51 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
52 /* Process all pending events */
53 while (mainboard_smi_ec() != 0);
54 }
55}
56
57void mainboard_smi_sleep(u8 slp_typ)
58{
59 /* Disable USB charging if required */
60 switch (slp_typ) {
61 case ACPI_S3:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030062 if (gnvs->s3u0 == 0)
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060063 google_chromeec_set_usb_charge_mode(
64 0, USB_CHARGE_MODE_DISABLED);
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030065 if (gnvs->s3u1 == 0)
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060066 google_chromeec_set_usb_charge_mode(
67 1, USB_CHARGE_MODE_DISABLED);
68
69 /* Prevent leak from standby rail to WLAN rail in S3. */
70 set_gpio(GPIO_WLAN_DISABLE_L, 0);
71 set_gpio(GPIO_PP3300_CODEC_EN, 0);
72 /* Disable LTE */
73 set_gpio(GPIO_LTE_DISABLE_L, 0);
74
75 /* Enable wake events */
76 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
77 break;
78 case ACPI_S4:
79 case ACPI_S5:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030080 if (gnvs->s5u0 == 0)
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060081 google_chromeec_set_usb_charge_mode(
82 0, USB_CHARGE_MODE_DISABLED);
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030083 if (gnvs->s5u1 == 0)
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060084 google_chromeec_set_usb_charge_mode(
85 1, USB_CHARGE_MODE_DISABLED);
86
87 /* Prevent leak from standby rail to WLAN rail in S5. */
88 set_gpio(GPIO_WLAN_DISABLE_L, 0);
89 set_gpio(GPIO_PP3300_CODEC_EN, 0);
90 /* Disable LTE */
91 set_gpio(GPIO_LTE_DISABLE_L, 0);
92
93 /* Enable wake events */
94 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
95 break;
96 }
97
98 /* Disable SCI and SMI events */
99 google_chromeec_set_smi_mask(0);
100 google_chromeec_set_sci_mask(0);
101
102 /* Clear pending events that may trigger immediate wake */
Rob Barnesf1ade482021-06-14 10:22:21 -0600103 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE)
104 ;
Matt DeVillierc12e5ae2016-11-27 02:19:02 -0600105}
106
Matt DeVillierc12e5ae2016-11-27 02:19:02 -0600107int mainboard_smi_apmc(u8 apmc)
108{
109 switch (apmc) {
Matt DeVillierc12e5ae2016-11-27 02:19:02 -0600110 case APM_CNT_ACPI_ENABLE:
111 google_chromeec_set_smi_mask(0);
112 /* Clear all pending events */
Rob Barnesf1ade482021-06-14 10:22:21 -0600113 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE)
114 ;
Matt DeVillierc12e5ae2016-11-27 02:19:02 -0600115 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
116 break;
117 case APM_CNT_ACPI_DISABLE:
118 google_chromeec_set_sci_mask(0);
119 /* Clear all pending events */
Rob Barnesf1ade482021-06-14 10:22:21 -0600120 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE)
121 ;
Matt DeVillierc12e5ae2016-11-27 02:19:02 -0600122 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
123 break;
124 }
125 return 0;
126}