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