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
22 #include <console/console.h>
23 #include <cpu/x86/smm.h>
25 #include <ec/google/chromeec/ec.h>
26 #include <soc/iomap.h>
33 int mainboard_io_trap_handler(int smif
)
37 printk(BIOS_DEBUG
, "Sample\n");
38 smm_get_gnvs()->smif
= 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.
53 static u8
mainboard_smi_ec(void)
56 #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
58 cmd
= google_chromeec_get_event();
61 if (IS_ENABLED(CONFIG_ELOG_GSMI
) && cmd
)
62 elog_add_event_byte(ELOG_TYPE_EC_EVENT
, cmd
);
65 case EC_HOST_EVENT_LID_CLOSED
:
66 printk(BIOS_DEBUG
, "LID CLOSED, SHUTDOWN\n");
69 pm1_cnt
= inl(ACPI_BASE_ADDRESS
+ PM1_CNT
);
70 pm1_cnt
|= (0xf << 10);
71 outl(pm1_cnt
, ACPI_BASE_ADDRESS
+ PM1_CNT
);
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)
92 /* Enable wake events */
93 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS
);
96 /* Enable wake events */
97 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS
);
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)
111 int mainboard_smi_apmc(u8 apmc
)
113 #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
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
);
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
);