blob: f0ef637fb5440c736b474b506e9ccecf8ac7c31a [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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010019 * Foundation, Inc.
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010020 */
21
22#include <arch/io.h>
23#include <console/console.h>
24#include <cpu/x86/smm.h>
25#include <ec/acpi/ec.h>
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010026#include <ec/lenovo/h8/h8.h>
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010027#include <southbridge/intel/bd82x6x/pch.h>
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010028
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010029#define GPE_EC_SCI 1
30#define GPE_EC_WAKE 13
31
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010032static void mainboard_smm_init(void)
33{
34 printk(BIOS_DEBUG, "initializing SMI\n");
35 /* Enable 0x1600/0x1600 register pair */
36 ec_set_bit(0x00, 0x05);
37}
38
39int mainboard_io_trap_handler(int smif)
40{
41 static int smm_initialized;
42
43 if (!smm_initialized) {
44 mainboard_smm_init();
45 smm_initialized = 1;
46 }
47
Vladimir Serbinenko7ef3d902015-05-28 11:25:50 +020048 return 0;
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010049}
50
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010051static void mainboard_smi_handle_ec_sci(void)
52{
53 u8 status = inb(EC_SC);
54 u8 event;
55
56 if (!(status & EC_SCI_EVT))
57 return;
58
59 event = ec_query();
60 printk(BIOS_DEBUG, "EC event %02x\n", event);
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010061}
62
63void mainboard_smi_gpi(u32 gpi_sts)
64{
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010065 if (gpi_sts & (1 << GPE_EC_SCI))
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010066 mainboard_smi_handle_ec_sci();
67}
68
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010069int mainboard_smi_apmc(u8 data)
70{
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010071 switch (data) {
72 case APM_CNT_ACPI_ENABLE:
73 /* use 0x1600/0x1604 to prevent races with userspace */
74 ec_set_ports(0x1604, 0x1600);
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010075 /* route EC_SCI to SCI */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020076 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010077 /* discard all events, and enable attention */
78 ec_write(0x80, 0x01);
79 break;
80 case APM_CNT_ACPI_DISABLE:
81 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
82 provide a EC query function */
83 ec_set_ports(0x66, 0x62);
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020084 /* route EC_SCI to SMI */
85 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010086 /* discard all events, and enable attention */
87 ec_write(0x80, 0x01);
88 break;
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010089 default:
90 break;
91 }
92 return 0;
93}
Vladimir Serbinenko782ac362014-08-08 00:00:20 +020094
95void mainboard_smi_sleep(u8 slp_typ)
96{
97 if (slp_typ == 3) {
98 u8 ec_wake = ec_read(0x32);
99 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
100 if (ec_wake & 0x14) {
Vladimir Serbinenko782ac362014-08-08 00:00:20 +0200101 /* Redirect EC WAKE GPE to SCI. */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200102 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
Vladimir Serbinenko782ac362014-08-08 00:00:20 +0200103 }
104 }
105}