blob: 23a98ddd83eb56f852021216e8ea38f542503f2f [file] [log] [blame]
Nicolas Reinecke2bffa8a2015-10-01 15:34:37 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2014 Vladimir Serbinenko
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 1
26#define GPE_EC_WAKE 13
27
28static void mainboard_smm_init(void)
29{
30 printk(BIOS_DEBUG, "initializing SMI\n");
31 /* Enable 0x1600/0x1600 register pair */
32 ec_set_bit(0x00, 0x05);
33}
34
35int mainboard_io_trap_handler(int smif)
36{
37 static int smm_initialized;
38
39 if (!smm_initialized) {
40 mainboard_smm_init();
41 smm_initialized = 1;
42 }
43
44 return 0;
45}
46
47static void mainboard_smi_handle_ec_sci(void)
48{
49 u8 status = inb(EC_SC);
50 u8 event;
51
52 if (!(status & EC_SCI_EVT))
53 return;
54
55 event = ec_query();
56 printk(BIOS_DEBUG, "EC event %02x\n", event);
57}
58
59void mainboard_smi_gpi(u32 gpi_sts)
60{
61 if (gpi_sts & (1 << GPE_EC_SCI))
62 mainboard_smi_handle_ec_sci();
63}
64
65int mainboard_smi_apmc(u8 data)
66{
67 switch (data) {
68 case APM_CNT_ACPI_ENABLE:
69 /* use 0x1600/0x1604 to prevent races with userspace */
70 ec_set_ports(0x1604, 0x1600);
71 /* route EC_SCI to SCI */
72 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
73 /* discard all events, and enable attention */
74 ec_write(0x80, 0x01);
75 break;
76 case APM_CNT_ACPI_DISABLE:
77 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
78 provide a EC query function */
79 ec_set_ports(0x66, 0x62);
80 /* route EC_SCI to SMI */
81 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
82 /* discard all events, and enable attention */
83 ec_write(0x80, 0x01);
84 break;
85 default:
86 break;
87 }
88 return 0;
89}
90
91void mainboard_smi_sleep(u8 slp_typ)
92{
93 if (slp_typ == 3) {
94 u8 ec_wake = ec_read(0x32);
95 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
96 if (ec_wake & 0x14) {
97 /* Redirect EC WAKE GPE to SCI. */
98 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
99 }
100 }
101}