blob: 35a26c0ebde8e7529b62c9be55a2559e1839e45f [file] [log] [blame]
Vladimir Serbinenko94930e22014-08-24 22:40:33 +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.
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020016 */
17
18#include <arch/io.h>
19#include <console/console.h>
20#include <cpu/x86/smm.h>
21#include <ec/acpi/ec.h>
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020022#include <ec/lenovo/h8/h8.h>
Arthur Heymansa0508172018-01-25 11:30:22 +010023#include <southbridge/intel/common/pmutil.h>
Peter Lemenkov0f79a922018-10-11 15:15:02 +020024#include <southbridge/intel/bd82x6x/pch.h>
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020025
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010026#define GPE_EC_SCI 1
27#define GPE_EC_WAKE 13
28
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020029static void mainboard_smi_handle_ec_sci(void)
30{
31 u8 status = inb(EC_SC);
32 u8 event;
33
34 if (!(status & EC_SCI_EVT))
35 return;
36
37 event = ec_query();
38 printk(BIOS_DEBUG, "EC event %02x\n", event);
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020039}
40
41void mainboard_smi_gpi(u32 gpi_sts)
42{
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010043 if (gpi_sts & (1 << GPE_EC_SCI))
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020044 mainboard_smi_handle_ec_sci();
45}
46
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020047int mainboard_smi_apmc(u8 data)
48{
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020049 switch (data) {
50 case APM_CNT_ACPI_ENABLE:
51 /* use 0x1600/0x1604 to prevent races with userspace */
52 ec_set_ports(0x1604, 0x1600);
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010053 /* route EC_SCI to SCI */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020054 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020055 /* discard all events, and enable attention */
56 ec_write(0x80, 0x01);
57 break;
58 case APM_CNT_ACPI_DISABLE:
59 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
60 provide a EC query function */
61 ec_set_ports(0x66, 0x62);
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020062 /* route EC_SCI to SMI */
63 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020064 /* discard all events, and enable attention */
65 ec_write(0x80, 0x01);
66 break;
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020067 default:
68 break;
69 }
70 return 0;
71}
72
73void mainboard_smi_sleep(u8 slp_typ)
74{
75 if (slp_typ == 3) {
76 u8 ec_wake = ec_read(0x32);
Peter Lemenkov0f79a922018-10-11 15:15:02 +020077 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020078 if (ec_wake & 0x14) {
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020079 /* Redirect EC WAKE GPE to SCI. */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +020080 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
Vladimir Serbinenko94930e22014-08-24 22:40:33 +020081 }
82 }
83}