tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / mainboard / google / parrot / smihandler.c
blob351f08258c44ac12826b5f0827118b77bf253653
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 coresystems GmbH
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <arch/io.h>
17 #include <console/console.h>
18 #include <cpu/x86/smm.h>
19 #include <southbridge/intel/bd82x6x/nvs.h>
20 #include <southbridge/intel/bd82x6x/pch.h>
21 #include <southbridge/intel/bd82x6x/me.h>
22 #include <northbridge/intel/sandybridge/sandybridge.h>
23 #include <cpu/intel/model_206ax/model_206ax.h>
24 #include <elog.h>
25 #include <ec/compal/ene932/ec.h>
26 #include "ec.h"
28 static u8 mainboard_smi_ec(void)
30 u8 src;
31 u32 pm1_cnt;
32 #if CONFIG_ELOG_GSMI
33 static int battery_critical_logged;
34 #endif
36 ec_kbc_write_cmd(0x56);
37 src = ec_kbc_read_ob();
38 printk(BIOS_DEBUG, "mainboard_smi_ec src: %x\n", src);
40 switch (src) {
41 case EC_BATTERY_CRITICAL:
42 #if CONFIG_ELOG_GSMI
43 if (!battery_critical_logged)
44 elog_add_event_byte(ELOG_TYPE_EC_EVENT,
45 EC_EVENT_BATTERY_CRITICAL);
46 battery_critical_logged = 1;
47 #endif
48 break;
49 case EC_LID_CLOSE:
50 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
52 #if CONFIG_ELOG_GSMI
53 elog_add_event_byte(ELOG_TYPE_EC_EVENT, EC_EVENT_LID_CLOSED);
54 #endif
55 /* Go to S5 */
56 pm1_cnt = inl(smm_get_pmbase() + PM1_CNT);
57 pm1_cnt |= (0xf << 10);
58 outl(pm1_cnt, smm_get_pmbase() + PM1_CNT);
59 break;
62 return src;
65 void mainboard_smi_gpi(u32 gpi_sts)
67 u32 pm1_cnt;
69 printk(BIOS_DEBUG, "mainboard_smi_gpi: %x\n", gpi_sts);
70 if (gpi_sts & (1 << EC_SMI_GPI)) {
71 /* Process all pending events from EC */
72 while (mainboard_smi_ec() != EC_NO_EVENT);
74 else if (gpi_sts & (1 << EC_LID_GPI)) {
75 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
77 #if CONFIG_ELOG_GSMI
78 elog_add_event_byte(ELOG_TYPE_EC_EVENT, EC_EVENT_LID_CLOSED);
79 #endif
80 /* Go to S5 */
81 pm1_cnt = inl(smm_get_pmbase() + PM1_CNT);
82 pm1_cnt |= (0xf << 10);
83 outl(pm1_cnt, smm_get_pmbase() + PM1_CNT);
87 void mainboard_smi_sleep(u8 slp_typ)
89 printk(BIOS_DEBUG, "mainboard_smi_sleep: %x\n", slp_typ);
90 /* Disable SCI and SMI events */
93 /* Clear pending events that may trigger immediate wake */
96 /* Enable wake events */
99 /* Tell the EC to Disable USB power */
100 if (smm_get_gnvs()->s3u0 == 0 && smm_get_gnvs()->s3u1 == 0) {
101 ec_kbc_write_cmd(0x45);
102 ec_kbc_write_ib(0xF2);
106 #define APMC_ACPI_EN 0xe1
107 #define APMC_ACPI_DIS 0x1e
109 int mainboard_smi_apmc(u8 apmc)
111 printk(BIOS_DEBUG, "mainboard_smi_apmc: %x\n", apmc);
112 switch (apmc) {
113 case APMC_ACPI_EN:
114 printk(BIOS_DEBUG, "APMC: ACPI_EN\n");
115 /* Clear all pending events */
116 /* EC cmd:59 data:E8 */
117 ec_kbc_write_cmd(0x59);
118 ec_kbc_write_ib(0xE8);
120 /* Set LID GPI to generate SCIs */
121 gpi_route_interrupt(EC_LID_GPI, GPI_IS_SCI);
122 break;
123 case APMC_ACPI_DIS:
124 printk(BIOS_DEBUG, "APMC: ACPI_DIS\n");
125 /* Clear all pending events */
126 /* EC cmd:59 data:e9 */
127 ec_kbc_write_cmd(0x59);
128 ec_kbc_write_ib(0xE9);
130 /* Set LID GPI to generate SMIs */
131 gpi_route_interrupt(EC_LID_GPI, GPI_IS_SMI);
132 break;
134 return 0;