blob: eb9255610c3b26dd9e6552577a120157f8daf1ec [file] [log] [blame]
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
Vladimir Serbinenkob2939f72014-01-22 17:12:35 +01005 * Copyright (C) 2014 Vladimir Serbinenko
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +01006 *
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.
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010016 */
17
18#include <arch/io.h>
19#include <console/console.h>
20#include <cpu/x86/smm.h>
21#include <ec/acpi/ec.h>
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010022#include <ec/lenovo/h8/h8.h>
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010023#include <southbridge/intel/bd82x6x/pch.h>
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010024
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010025#define GPE_EC_SCI 1
26#define GPE_EC_WAKE 13
27
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010028static 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
Vladimir Serbinenko7ef3d902015-05-28 11:25:50 +020044 return 0;
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010045}
46
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010047static 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);
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010057}
58
59void mainboard_smi_gpi(u32 gpi_sts)
60{
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010061 if (gpi_sts & (1 << GPE_EC_SCI))
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010062 mainboard_smi_handle_ec_sci();
63}
64
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010065int mainboard_smi_apmc(u8 data)
66{
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010067 switch (data) {
68 case APM_CNT_ACPI_ENABLE:
69 /* use 0x1600/0x1604 to prevent races with userspace */
70 ec_set_ports(0x1604, 0x1600);
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010071 /* route EC_SCI to SCI */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020072 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010073 /* 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);
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020080 /* route EC_SCI to SMI */
81 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010082 /* discard all events, and enable attention */
83 ec_write(0x80, 0x01);
84 break;
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010085 default:
86 break;
87 }
88 return 0;
89}
Vladimir Serbinenko782ac362014-08-08 00:00:20 +020090
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) {
Vladimir Serbinenko782ac362014-08-08 00:00:20 +020097 /* Redirect EC WAKE GPE to SCI. */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020098 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
Vladimir Serbinenko782ac362014-08-08 00:00:20 +020099 }
100 }
101}