blob: 6e20500234e923be29b96d90488e0d4f2fa9f6da [file] [log] [blame]
Nicolas Reinecke29d358e2015-01-31 19:20:50 +01001/*
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.
Nicolas Reinecke29d358e2015-01-31 19:20:50 +010016 */
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/nvs.h>
24#include <southbridge/intel/bd82x6x/pch.h>
25#include <southbridge/intel/bd82x6x/me.h>
26#include <northbridge/intel/sandybridge/sandybridge.h>
27#include <cpu/intel/model_206ax/model_206ax.h>
28
29#define GPE_EC_SCI 1
30#define GPE_EC_WAKE 13
31
Nicolas Reinecke29d358e2015-01-31 19:20:50 +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
48 switch (smif) {
49 default:
50 return 0;
51 }
52
53 /* On success, the IO Trap Handler returns 1
54 * On failure, the IO Trap Handler returns a value != 1 */
55 return 1;
56}
57
58static void mainboard_smi_brightness_up(void)
59{
60 u8 value;
61
62 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) < 0xf0)
63 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value + 0x10) | 0xf);
64}
65
66static void mainboard_smi_brightness_down(void)
67{
68 u8 value;
69
70 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) > 0x10)
71 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4,
72 (value - 0x10) & 0xf0);
73}
74
75static void mainboard_smi_handle_ec_sci(void)
76{
77 u8 status = inb(EC_SC);
78 u8 event;
79
80 if (!(status & EC_SCI_EVT))
81 return;
82
83 event = ec_query();
84 printk(BIOS_DEBUG, "EC event %02x\n", event);
85
86 switch (event) {
87 case 0x14:
88 /* brightness up */
89 mainboard_smi_brightness_up();
90 break;
91 case 0x15:
92 /* brightness down */
93 mainboard_smi_brightness_down();
94 break;
95 default:
96 break;
97 }
98}
99
100void mainboard_smi_gpi(u32 gpi_sts)
101{
102 if (gpi_sts & (1 << GPE_EC_SCI))
103 mainboard_smi_handle_ec_sci();
104}
105
Nicolas Reinecke29d358e2015-01-31 19:20:50 +0100106int mainboard_smi_apmc(u8 data)
107{
Nicolas Reinecke29d358e2015-01-31 19:20:50 +0100108 switch (data) {
109 case APM_CNT_ACPI_ENABLE:
110 /* use 0x1600/0x1604 to prevent races with userspace */
111 ec_set_ports(0x1604, 0x1600);
112 /* route EC_SCI to SCI */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200113 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
Nicolas Reinecke29d358e2015-01-31 19:20:50 +0100114 /* discard all events, and enable attention */
115 ec_write(0x80, 0x01);
116 break;
117 case APM_CNT_ACPI_DISABLE:
118 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
119 provide a EC query function */
120 ec_set_ports(0x66, 0x62);
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200121 /* route EC_SCI to SMI */
122 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
Nicolas Reinecke29d358e2015-01-31 19:20:50 +0100123 /* discard all events, and enable attention */
124 ec_write(0x80, 0x01);
125 break;
Nicolas Reinecke29d358e2015-01-31 19:20:50 +0100126 default:
127 break;
128 }
129 return 0;
130}
131
132void mainboard_smi_sleep(u8 slp_typ)
133{
134 if (slp_typ == 3) {
135 u8 ec_wake = ec_read(0x32);
136 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
137 if (ec_wake & 0x14) {
Nicolas Reinecke29d358e2015-01-31 19:20:50 +0100138 /* Redirect EC WAKE GPE to SCI. */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200139 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
Nicolas Reinecke29d358e2015-01-31 19:20:50 +0100140 }
141 }
142}