blob: 5d7df375ae6d26b8947c4214196bec9db6a643d6 [file] [log] [blame]
Marc Jones07cf24c2015-06-09 14:42:55 -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 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.
19 */
20
21#include <arch/io.h>
22#include <console/console.h>
23#include <cpu/x86/smm.h>
24#include <southbridge/intel/lynxpoint/nvs.h>
25#include <southbridge/intel/lynxpoint/pch.h>
26#include <southbridge/intel/lynxpoint/me.h>
27#include <northbridge/intel/haswell/haswell.h>
28#include <cpu/intel/haswell/haswell.h>
29#include <elog.h>
30
31/* Include EC functions */
32#include <ec/google/chromeec/ec.h>
33#include "ec.h"
34
35/* Codec enable: GPIO45 */
36#define GPIO_PP3300_CODEC_EN 45
37/* WLAN / BT enable: GPIO46 */
38#define GPIO_WLAN_DISABLE_L 46
39
40static u8 mainboard_smi_ec(void)
41{
42 u8 cmd = google_chromeec_get_event();
43 u32 pm1_cnt;
44
45#if CONFIG_ELOG_GSMI
46 /* Log this event */
47 if (cmd)
48 elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
49#endif
50
51 switch (cmd) {
52 case EC_HOST_EVENT_LID_CLOSED:
53 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
54
55 /* Go to S5 */
56 pm1_cnt = inl(get_pmbase() + PM1_CNT);
57 pm1_cnt |= (0xf << 10);
58 outl(pm1_cnt, get_pmbase() + PM1_CNT);
59 break;
60 }
61
62 return cmd;
63}
64
65/* gpi_sts is GPIO 47:32 */
66void mainboard_smi_gpi(u32 gpi_sts)
67{
68 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
69 /* Process all pending events */
70 while (mainboard_smi_ec() != 0);
71 }
72}
73
74void mainboard_smi_sleep(u8 slp_typ)
75{
76 /* Disable USB charging if required */
77 switch (slp_typ) {
78 case 3:
79 if (smm_get_gnvs()->s3u0 == 0)
80 google_chromeec_set_usb_charge_mode(
81 0, USB_CHARGE_MODE_DISABLED);
82 if (smm_get_gnvs()->s3u1 == 0)
83 google_chromeec_set_usb_charge_mode(
84 1, USB_CHARGE_MODE_DISABLED);
85
86 set_gpio(GPIO_PP3300_CODEC_EN, 0);
87 set_gpio(GPIO_WLAN_DISABLE_L, 0);
88
89 /* Enable wake events */
90 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
91 break;
92 case 5:
93 if (smm_get_gnvs()->s5u0 == 0)
94 google_chromeec_set_usb_charge_mode(
95 0, USB_CHARGE_MODE_DISABLED);
96 if (smm_get_gnvs()->s5u1 == 0)
97 google_chromeec_set_usb_charge_mode(
98 1, USB_CHARGE_MODE_DISABLED);
99
100 set_gpio(GPIO_PP3300_CODEC_EN, 0);
101 set_gpio(GPIO_WLAN_DISABLE_L, 0);
102
103 /* Enable wake events */
104 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
105 break;
106 }
107
108 /* Disable SCI and SMI events */
109 google_chromeec_set_smi_mask(0);
110 google_chromeec_set_sci_mask(0);
111
112 /* Clear pending events that may trigger immediate wake */
113 while (google_chromeec_get_event() != 0);
114}
115
116
117static int mainboard_finalized = 0;
118
119int mainboard_smi_apmc(u8 apmc)
120{
121 switch (apmc) {
122 case APM_CNT_FINALIZE:
123 if (mainboard_finalized) {
124 printk(BIOS_DEBUG, "SMI#: Already finalized\n");
125 return 0;
126 }
127
128 intel_pch_finalize_smm();
129 intel_northbridge_haswell_finalize_smm();
130 intel_cpu_haswell_finalize_smm();
131
132 mainboard_finalized = 1;
133 break;
134 case APM_CNT_ACPI_ENABLE:
135 google_chromeec_set_smi_mask(0);
136 /* Clear all pending events */
137 while (google_chromeec_get_event() != 0);
138 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
139 break;
140 case APM_CNT_ACPI_DISABLE:
141 google_chromeec_set_sci_mask(0);
142 /* Clear all pending events */
143 while (google_chromeec_get_event() != 0);
144 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
145 break;
146 }
147 return 0;
148}