blob: 41e9d5a2ab1264625883d42ec1674486c1fc3c6f [file] [log] [blame]
Matt DeVillierc12e5ae2016-11-27 02:19:02 -06001/*
2 * This file is part of the coreboot project.
3 *
Matt DeVillierc12e5ae2016-11-27 02:19:02 -06004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <arch/acpi.h>
16#include <arch/io.h>
17#include <console/console.h>
18#include <cpu/x86/smm.h>
19#include <southbridge/intel/lynxpoint/nvs.h>
20#include <southbridge/intel/lynxpoint/pch.h>
21#include <southbridge/intel/common/gpio.h>
22#include <southbridge/intel/lynxpoint/me.h>
23#include <northbridge/intel/haswell/haswell.h>
24#include <cpu/intel/haswell/haswell.h>
25#include <elog.h>
26
27/* Include EC functions */
28#include <ec/google/chromeec/ec.h>
29#include "ec.h"
30
31/* Codec enable: GPIO45 */
32#define GPIO_PP3300_CODEC_EN 45
33/* GPIO46 controls the WLAN_DISABLE_L signal. */
34#define GPIO_WLAN_DISABLE_L 46
35#define GPIO_LTE_DISABLE_L 59
36
37static u8 mainboard_smi_ec(void)
38{
39 u8 cmd = google_chromeec_get_event();
40 u32 pm1_cnt;
41
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060042 /* Log this event */
43 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020044 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Matt DeVillierc12e5ae2016-11-27 02:19:02 -060045
46 switch (cmd) {
47 case EC_HOST_EVENT_LID_CLOSED:
48 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
49
50 /* Go to S5 */
51 pm1_cnt = inl(get_pmbase() + PM1_CNT);
52 pm1_cnt |= (0xf << 10);
53 outl(pm1_cnt, get_pmbase() + PM1_CNT);
54 break;
55 }
56
57 return cmd;
58}
59
60/* gpi_sts is GPIO 47:32 */
61void mainboard_smi_gpi(u32 gpi_sts)
62{
63 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
64 /* Process all pending events */
65 while (mainboard_smi_ec() != 0);
66 }
67}
68
69void mainboard_smi_sleep(u8 slp_typ)
70{
71 /* Disable USB charging if required */
72 switch (slp_typ) {
73 case ACPI_S3:
74 if (smm_get_gnvs()->s3u0 == 0)
75 google_chromeec_set_usb_charge_mode(
76 0, USB_CHARGE_MODE_DISABLED);
77 if (smm_get_gnvs()->s3u1 == 0)
78 google_chromeec_set_usb_charge_mode(
79 1, USB_CHARGE_MODE_DISABLED);
80
81 /* Prevent leak from standby rail to WLAN rail in S3. */
82 set_gpio(GPIO_WLAN_DISABLE_L, 0);
83 set_gpio(GPIO_PP3300_CODEC_EN, 0);
84 /* Disable LTE */
85 set_gpio(GPIO_LTE_DISABLE_L, 0);
86
87 /* Enable wake events */
88 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
89 break;
90 case ACPI_S4:
91 case ACPI_S5:
92 if (smm_get_gnvs()->s5u0 == 0)
93 google_chromeec_set_usb_charge_mode(
94 0, USB_CHARGE_MODE_DISABLED);
95 if (smm_get_gnvs()->s5u1 == 0)
96 google_chromeec_set_usb_charge_mode(
97 1, USB_CHARGE_MODE_DISABLED);
98
99 /* Prevent leak from standby rail to WLAN rail in S5. */
100 set_gpio(GPIO_WLAN_DISABLE_L, 0);
101 set_gpio(GPIO_PP3300_CODEC_EN, 0);
102 /* Disable LTE */
103 set_gpio(GPIO_LTE_DISABLE_L, 0);
104
105 /* Enable wake events */
106 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
107 break;
108 }
109
110 /* Disable SCI and SMI events */
111 google_chromeec_set_smi_mask(0);
112 google_chromeec_set_sci_mask(0);
113
114 /* Clear pending events that may trigger immediate wake */
115 while (google_chromeec_get_event() != 0);
116}
117
Matt DeVillierc12e5ae2016-11-27 02:19:02 -0600118int mainboard_smi_apmc(u8 apmc)
119{
120 switch (apmc) {
Matt DeVillierc12e5ae2016-11-27 02:19:02 -0600121 case APM_CNT_ACPI_ENABLE:
122 google_chromeec_set_smi_mask(0);
123 /* Clear all pending events */
124 while (google_chromeec_get_event() != 0);
125 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
126 break;
127 case APM_CNT_ACPI_DISABLE:
128 google_chromeec_set_sci_mask(0);
129 /* Clear all pending events */
130 while (google_chromeec_get_event() != 0);
131 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
132 break;
133 }
134 return 0;
135}