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