glados: Remove code to set USB charge behavior on sleep
[coreboot.git] / src / mainboard / google / glados / smihandler.c
blob2a90089450b5ff827de8cb1865c682b93ef86e06
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2015 Google Inc.
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.
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.
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.
21 #include <arch/io.h>
22 #include <console/console.h>
23 #include <cpu/x86/smm.h>
24 #include <elog.h>
25 #include <ec/google/chromeec/ec.h>
26 #include <soc/iomap.h>
27 #include <soc/nvs.h>
28 #include <soc/pm.h>
29 #include <soc/smm.h>
30 #include "ec.h"
31 #include "gpio.h"
33 int mainboard_io_trap_handler(int smif)
35 switch (smif) {
36 case 0x99:
37 printk(BIOS_DEBUG, "Sample\n");
38 smm_get_gnvs()->smif = 0;
39 break;
40 default:
41 return 0;
44 /* On success, the IO Trap Handler returns 0
45 * On failure, the IO Trap Handler returns a value != 0
47 * For now, we force the return value to 0 and log all traps to
48 * see what's going on.
50 return 1;
53 static u8 mainboard_smi_ec(void)
55 u8 cmd = 0;
56 #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
57 u32 pm1_cnt;
58 cmd = google_chromeec_get_event();
60 /* Log this event */
61 if (IS_ENABLED(CONFIG_ELOG_GSMI) && cmd)
62 elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
64 switch (cmd) {
65 case EC_HOST_EVENT_LID_CLOSED:
66 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
68 /* Go to S5 */
69 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
70 pm1_cnt |= (0xf << 10);
71 outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT);
72 break;
74 #endif
75 return cmd;
78 void mainboard_smi_gpi_handler(const struct gpi_status *sts)
80 if (gpi_status_get(sts, EC_SMI_GPI)) {
81 /* Process all pending events */
82 while (mainboard_smi_ec() != 0)
87 void mainboard_smi_sleep(u8 slp_typ)
89 #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
90 switch (slp_typ) {
91 case 3:
92 /* Enable wake events */
93 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
94 break;
95 case 5:
96 /* Enable wake events */
97 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
98 break;
101 /* Disable SCI and SMI events */
102 google_chromeec_set_smi_mask(0);
103 google_chromeec_set_sci_mask(0);
105 /* Clear pending events that may trigger immediate wake */
106 while (google_chromeec_get_event() != 0)
108 #endif
111 int mainboard_smi_apmc(u8 apmc)
113 #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
114 switch (apmc) {
115 case APM_CNT_ACPI_ENABLE:
116 google_chromeec_set_smi_mask(0);
117 /* Clear all pending events */
118 while (google_chromeec_get_event() != 0)
120 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
121 break;
122 case APM_CNT_ACPI_DISABLE:
123 google_chromeec_set_sci_mask(0);
124 /* Clear all pending events */
125 while (google_chromeec_get_event() != 0)
127 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
128 break;
130 #endif
131 return 0;