blob: 6c887d608f1098a32ac00f32bbfdde7d04af824b [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>
Arthur Heymansa0508172018-01-25 11:30:22 +010024#include <southbridge/intel/common/pmutil.h>
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010025
Nicolas Reineckeb0922f02015-02-01 02:53:35 +010026#define GPE_EC_SCI 1
27#define GPE_EC_WAKE 13
28
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010029static 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 Serbinenkoe7e95022014-01-12 15:26:15 +010039}
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 Serbinenkoe7e95022014-01-12 15:26:15 +010044 mainboard_smi_handle_ec_sci();
45}
46
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010047int mainboard_smi_apmc(u8 data)
48{
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010049 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 Serbinenkoe7e95022014-01-12 15:26:15 +010055 /* 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 Serbinenkoe7e95022014-01-12 15:26:15 +010064 /* discard all events, and enable attention */
65 ec_write(0x80, 0x01);
66 break;
Vladimir Serbinenkoe7e95022014-01-12 15:26:15 +010067 default:
68 break;
69 }
70 return 0;
71}
Vladimir Serbinenko782ac362014-08-08 00:00:20 +020072
73void mainboard_smi_sleep(u8 slp_typ)
74{
75 if (slp_typ == 3) {
76 u8 ec_wake = ec_read(0x32);
Peter Lemenkov6b7d40a2020-01-22 11:40:16 +010077 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
Vladimir Serbinenko782ac362014-08-08 00:00:20 +020078 if (ec_wake & 0x14) {
Peter Lemenkov6b7d40a2020-01-22 11:40:16 +010079 /* 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 Serbinenko782ac362014-08-08 00:00:20 +020081 }
82 }
83}