blob: 351f08258c44ac12826b5f0827118b77bf253653 [file] [log] [blame]
Stefan Reinauera7198b32012-12-11 16:00:47 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
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.
9 *
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.
Stefan Reinauera7198b32012-12-11 16:00:47 -080014 */
15
16#include <arch/io.h>
Stefan Reinauera7198b32012-12-11 16:00:47 -080017#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"
27
Stefan Reinauera7198b32012-12-11 16:00:47 -080028static u8 mainboard_smi_ec(void)
29{
30 u8 src;
31 u32 pm1_cnt;
Paul Menzel5679e5a2013-10-21 20:23:35 +020032#if CONFIG_ELOG_GSMI
Stefan Reinauera7198b32012-12-11 16:00:47 -080033 static int battery_critical_logged;
Paul Menzel5679e5a2013-10-21 20:23:35 +020034#endif
Stefan Reinauera7198b32012-12-11 16:00:47 -080035
36 ec_kbc_write_cmd(0x56);
37 src = ec_kbc_read_ob();
38 printk(BIOS_DEBUG, "mainboard_smi_ec src: %x\n", src);
39
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);
Stefan Reinauera7198b32012-12-11 16:00:47 -080046 battery_critical_logged = 1;
Paul Menzel5679e5a2013-10-21 20:23:35 +020047#endif
Stefan Reinauera7198b32012-12-11 16:00:47 -080048 break;
49 case EC_LID_CLOSE:
50 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
51
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;
60 }
61
62 return src;
63}
64
Duncan Laurie0edc2242013-04-29 15:04:30 -070065void mainboard_smi_gpi(u32 gpi_sts)
Stefan Reinauera7198b32012-12-11 16:00:47 -080066{
67 u32 pm1_cnt;
68
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);
73 }
74 else if (gpi_sts & (1 << EC_LID_GPI)) {
75 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
76
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);
84 }
85}
86
87void mainboard_smi_sleep(u8 slp_typ)
88{
89 printk(BIOS_DEBUG, "mainboard_smi_sleep: %x\n", slp_typ);
90 /* Disable SCI and SMI events */
91
92
93 /* Clear pending events that may trigger immediate wake */
94
95
96 /* Enable wake events */
97
98
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);
103 }
104}
105
Stefan Reinauera7198b32012-12-11 16:00:47 -0800106#define APMC_ACPI_EN 0xe1
107#define APMC_ACPI_DIS 0x1e
108
Stefan Reinauera7198b32012-12-11 16:00:47 -0800109int mainboard_smi_apmc(u8 apmc)
110{
111 printk(BIOS_DEBUG, "mainboard_smi_apmc: %x\n", apmc);
112 switch (apmc) {
Stefan Reinauera7198b32012-12-11 16:00:47 -0800113 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);
119
120 /* Set LID GPI to generate SCIs */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200121 gpi_route_interrupt(EC_LID_GPI, GPI_IS_SCI);
Stefan Reinauera7198b32012-12-11 16:00:47 -0800122 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);
129
130 /* Set LID GPI to generate SMIs */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200131 gpi_route_interrupt(EC_LID_GPI, GPI_IS_SMI);
Stefan Reinauera7198b32012-12-11 16:00:47 -0800132 break;
133 }
134 return 0;
135}