blob: 1e463baf402dae7b96b6e3b579edb24416925246 [file] [log] [blame]
Patrick Rudolphaae6e9c2016-12-30 17:02:04 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2016 Patrick Rudolph <siro@das-labor.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <arch/io.h>
19#include <console/console.h>
20#include <cpu/x86/smm.h>
21#include <ec/acpi/ec.h>
22#include <ec/lenovo/h8/h8.h>
23#include <southbridge/intel/bd82x6x/pch.h>
24
25#define GPE_EC_SCI 6
26/* FIXME: check this */
27#define GPE_EC_WAKE 13
28
29static void mainboard_smm_init(void)
30{
31 printk(BIOS_DEBUG, "initializing SMI\n");
32 /* Enable 0x1600/0x1600 register pair */
33 ec_set_bit(0x00, 0x05);
34}
35
36int mainboard_io_trap_handler(int smif)
37{
38 static int smm_initialized;
39
40 if (!smm_initialized) {
41 mainboard_smm_init();
42 smm_initialized = 1;
43 }
44
45 return 0;
46}
47
48static void mainboard_smi_handle_ec_sci(void)
49{
50 u8 status = inb(EC_SC);
51 u8 event;
52
53 if (!(status & EC_SCI_EVT))
54 return;
55
56 event = ec_query();
57 printk(BIOS_DEBUG, "EC event %02x\n", event);
58}
59
60void mainboard_smi_gpi(u32 gpi_sts)
61{
62 if (gpi_sts & (1 << GPE_EC_SCI))
63 mainboard_smi_handle_ec_sci();
64}
65
66int mainboard_smi_apmc(u8 data)
67{
68 switch (data) {
69 case APM_CNT_ACPI_ENABLE:
70 /* use 0x1600/0x1604 to prevent races with userspace */
71 ec_set_ports(0x1604, 0x1600);
72 /* route EC_SCI to SCI */
73 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
74 /* discard all events, and enable attention */
75 ec_write(0x80, 0x01);
76 break;
77 case APM_CNT_ACPI_DISABLE:
78 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
79 provide a EC query function */
80 ec_set_ports(0x66, 0x62);
81 /* route EC_SCI to SMI */
82 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
83 /* discard all events, and enable attention */
84 ec_write(0x80, 0x01);
85 break;
86 default:
87 break;
88 }
89 return 0;
90}
91
92void mainboard_smi_sleep(u8 slp_typ)
93{
94 if (slp_typ == 3) {
95 u8 ec_wake = ec_read(0x32);
96 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
97 if (ec_wake & 0x14) {
98 /* Redirect EC WAKE GPE to SCI. */
99 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
100 }
101 }
102}