blob: b465e3a5205809316b5fbb4c2b19919ff2e226d6 [file] [log] [blame]
Lee Leahy5cb9dda2015-05-01 10:34:54 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2015 Intel Corp.
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.
Lee Leahy5cb9dda2015-05-01 10:34:54 -070015 */
16
17#include <arch/io.h>
18#include <console/console.h>
19#include <cpu/x86/smm.h>
20#include "ec.h"
21
22#include <ec/google/chromeec/ec.h>
23#include <elog.h>
24
25#include <soc/nvs.h>
26#include <soc/pm.h>
27#include <soc/gpio.h>
28
29#include "onboard.h"
30
31/* The wake gpio is SUS_GPIO[0]. */
32#define WAKE_GPIO_EN SUS_GPIO_EN0
33
34int mainboard_io_trap_handler(int smif)
35{
36 switch (smif) {
37 case 0x99:
38 printk(BIOS_DEBUG, "Sample\n");
39 smm_get_gnvs()->smif = 0;
40 break;
41 default:
42 return 0;
43 }
44
45 /*
46 * On success, the IO Trap Handler returns 0
47 * On failure, the IO Trap Handler returns a value != 0
48 *
49 * For now, we force the return value to 0 and log all traps to
50 * see what's going on.
51 */
52 //gnvs->smif = 0;
53 return 1;
54}
55
56#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
57static uint8_t mainboard_smi_ec(void)
58{
59 uint8_t cmd = google_chromeec_get_event();
60 uint16_t pmbase = get_pmbase();
61 uint32_t pm1_cnt;
62
63#if IS_ENABLED(CONFIG_ELOG_GSMI)
64 /* Log this event */
65 if (cmd)
66 elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
67#endif
68
69 switch (cmd) {
70 case EC_HOST_EVENT_LID_CLOSED:
71 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
72
73 /* Go to S5 */
74 pm1_cnt = inl(pmbase + PM1_CNT);
75 pm1_cnt |= SLP_EN | (SLP_TYP_S5 << SLP_TYP_SHIFT);
76 outl(pm1_cnt, pmbase + PM1_CNT);
77 break;
78 }
79
80 return cmd;
81}
82#endif
83
84/*
85 * The entire 32-bit ALT_GPIO_SMI register is passed as a parameter. Note, that
86 * this includes the enable bits in the lower 16 bits.
87 */
88void mainboard_smi_gpi(uint32_t alt_gpio_smi)
89{
90#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
91 if (alt_gpio_smi & (1 << EC_SMI_GPI)) {
92 /* Process all pending events */
93 while (mainboard_smi_ec() != 0)
94 ;
95 }
96#endif
97}
98
99void mainboard_smi_sleep(uint8_t slp_typ)
100{
101 /* Disable USB charging if required */
102 switch (slp_typ) {
103 case 3:
104#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
105 if (smm_get_gnvs()->s3u0 == 0)
106 google_chromeec_set_usb_charge_mode(
107 0, USB_CHARGE_MODE_DISABLED);
108 if (smm_get_gnvs()->s3u1 == 0)
109 google_chromeec_set_usb_charge_mode(
110 1, USB_CHARGE_MODE_DISABLED);
111
112 /* Enable wake events */
113 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
114#endif
115 /* Enable wake pin in GPE block. */
116 enable_gpe(WAKE_GPIO_EN);
117 break;
118 case 5:
119#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
120 if (smm_get_gnvs()->s5u0 == 0)
121 google_chromeec_set_usb_charge_mode(
122 0, USB_CHARGE_MODE_DISABLED);
123 if (smm_get_gnvs()->s5u1 == 0)
124 google_chromeec_set_usb_charge_mode(
125 1, USB_CHARGE_MODE_DISABLED);
126
127 /* Enable wake events */
128 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
129#endif
130 break;
131 }
132
133#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
134 /* Disable SCI and SMI events */
135 google_chromeec_set_smi_mask(0);
136 google_chromeec_set_sci_mask(0);
137
138 /* Clear pending events that may trigger immediate wake */
139 while (google_chromeec_get_event() != 0)
140 ;
141
142 if (smm_get_gnvs()->bdid == BOARD_DVT) {
143 /* Set LPC lines to low power in S3/S5. */
144 if ((slp_typ == SLEEP_STATE_S3) || (slp_typ == SLEEP_STATE_S5))
145 lpc_set_low_power();
146 }
147#endif
148}
149
150int mainboard_smi_apmc(uint8_t apmc)
151{
152 switch (apmc) {
153 case APM_CNT_ACPI_ENABLE:
154#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
155 google_chromeec_set_smi_mask(0);
156 /* Clear all pending events */
157 while (google_chromeec_get_event() != 0)
158 ;
159 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
160#endif
161 break;
162 case APM_CNT_ACPI_DISABLE:
163#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
164 google_chromeec_set_sci_mask(0);
165 /* Clear all pending events */
166 while (google_chromeec_get_event() != 0)
167 ;
168 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
169#endif
170 break;
171 }
172 return 0;
173}