blob: b9f0a577a02b71fdb4ba0488a5127cae4441c08d [file] [log] [blame]
Sven Schnellee2ca71e2011-02-14 20:02:47 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Sven Schnellee2ca71e2011-02-14 20:02:47 +000015 */
16
17#include <arch/io.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000018#include <console/console.h>
19#include <cpu/x86/smm.h>
20#include "southbridge/intel/i82801gx/nvs.h"
Sven Schnelle8b39e072011-06-12 16:49:13 +020021#include "southbridge/intel/i82801gx/i82801gx.h"
Sven Schnellefea6bd12011-04-01 07:28:56 +000022#include <ec/acpi/ec.h>
Sven Schnelle4297a9a2011-06-12 14:35:11 +020023#include <pc80/mc146818rtc.h>
24#include <ec/lenovo/h8/h8.h>
Sven Schnelle483ec412012-01-10 14:44:12 +010025#include <delay.h>
Sven Schnellefea6bd12011-04-01 07:28:56 +000026#include "dock.h"
27#include "smi.h"
Sven Schnellee2ca71e2011-02-14 20:02:47 +000028
Kyösti Mälkki189f3ba2014-12-29 11:32:27 +020029#define GPE_EC_SCI 12
30
Sven Schnellefea6bd12011-04-01 07:28:56 +000031static void mainboard_smm_init(void)
32{
33 printk(BIOS_DEBUG, "initializing SMI\n");
34 /* Enable 0x1600/0x1600 register pair */
35 ec_set_bit(0x00, 0x05);
Sven Schnelle4297a9a2011-06-12 14:35:11 +020036}
37
38static void mainboard_smi_save_cmos(void)
39{
40 u8 val;
Sven Schnelleedcf9f42011-06-28 08:05:26 +020041 u8 tmp70, tmp72;
Sven Schnelle4297a9a2011-06-12 14:35:11 +020042
43 tmp70 = inb(0x70);
44 tmp72 = inb(0x72);
Sven Schnelle4297a9a2011-06-12 14:35:11 +020045
46 val = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4);
47 set_option("tft_brightness", &val);
48 val = ec_read(H8_VOLUME_CONTROL);
49 set_option("volume", &val);
50
51 outb(tmp70, 0x70);
52 outb(tmp72, 0x72);
Sven Schnellefea6bd12011-04-01 07:28:56 +000053}
54
Sven Schnellee2ca71e2011-02-14 20:02:47 +000055int mainboard_io_trap_handler(int smif)
56{
Sven Schnellefea6bd12011-04-01 07:28:56 +000057 static int smm_initialized;
58
59 if (!smm_initialized) {
60 mainboard_smm_init();
61 smm_initialized = 1;
62 }
63
Sven Schnellee2ca71e2011-02-14 20:02:47 +000064 switch (smif) {
Sven Schnellefea6bd12011-04-01 07:28:56 +000065 case SMI_DOCK_CONNECT:
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020066 ec_clr_bit(0x03, 2);
Sven Schnelle483ec412012-01-10 14:44:12 +010067 udelay(250000);
68 if (!dock_connect()) {
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020069 ec_set_bit(0x03, 2);
Sven Schnellefea6bd12011-04-01 07:28:56 +000070 /* set dock LED to indicate status */
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020071 ec_write(0x0c, 0x09);
Sven Schnellefea6bd12011-04-01 07:28:56 +000072 ec_write(0x0c, 0x88);
73 } else {
74 /* blink dock LED to indicate failure */
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020075 ec_write(0x0c, 0x08);
76 ec_write(0x0c, 0xc9);
Sven Schnellefea6bd12011-04-01 07:28:56 +000077 }
Sven Schnellee2ca71e2011-02-14 20:02:47 +000078 break;
Sven Schnellefea6bd12011-04-01 07:28:56 +000079
80 case SMI_DOCK_DISCONNECT:
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020081 ec_clr_bit(0x03, 2);
Sven Schnellefea6bd12011-04-01 07:28:56 +000082 dock_disconnect();
Sven Schnellefea6bd12011-04-01 07:28:56 +000083 break;
84
Sven Schnelle4297a9a2011-06-12 14:35:11 +020085 case SMI_SAVE_CMOS:
86 mainboard_smi_save_cmos();
87 break;
Sven Schnellee2ca71e2011-02-14 20:02:47 +000088 default:
Sven Schnelle0f9cd432011-06-12 16:55:56 +020089 return 0;
Sven Schnellee2ca71e2011-02-14 20:02:47 +000090 }
91
Sven Schnelle0f9cd432011-06-12 16:55:56 +020092 /* On success, the IO Trap Handler returns 1
93 * On failure, the IO Trap Handler returns a value != 1 */
94 return 1;
Sven Schnellee2ca71e2011-02-14 20:02:47 +000095}
Sven Schnelle8b39e072011-06-12 16:49:13 +020096
97static void mainboard_smi_brightness_up(void)
98{
99 u8 value;
100
101 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) < 0xf0)
102 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value + 0x10) | 0xf);
103}
104
105static void mainboard_smi_brightness_down(void)
106{
107 u8 value;
108
109 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) > 0x10)
110 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value - 0x10) & 0xf0);
111}
112
113static void mainboard_smi_handle_ec_sci(void)
114{
115 u8 status = inb(EC_SC);
116 u8 event;
117
118 if (!(status & EC_SCI_EVT))
119 return;
120
121 event = ec_query();
122 printk(BIOS_DEBUG, "EC event %02x\n", event);
123
124 switch(event) {
125 /* brightness up */
126 case 0x14:
127 mainboard_smi_brightness_up();
128 mainboard_smi_save_cmos();
129 break;
130 /* brightness down */
131 case 0x15:
132 mainboard_smi_brightness_down();
133 mainboard_smi_save_cmos();
134 break;
Sven Schnelle8d0b86c2011-07-11 18:36:16 +0200135 /* Fn-F9 key */
136 case 0x18:
137 /* Power loss */
138 case 0x27:
139 /* Undock Key */
140 case 0x50:
141 mainboard_io_trap_handler(SMI_DOCK_DISCONNECT);
142 break;
143 /* Dock Event */
144 case 0x37:
145 case 0x58:
146 mainboard_io_trap_handler(SMI_DOCK_CONNECT);
147 break;
Sven Schnelle8b39e072011-06-12 16:49:13 +0200148 default:
149 break;
150 }
151}
152
Duncan Laurie0edc2242013-04-29 15:04:30 -0700153void mainboard_smi_gpi(u32 gpi)
Sven Schnelle8b39e072011-06-12 16:49:13 +0200154{
Kyösti Mälkki189f3ba2014-12-29 11:32:27 +0200155 if (gpi & (1 << GPE_EC_SCI))
Sven Schnelle8b39e072011-06-12 16:49:13 +0200156 mainboard_smi_handle_ec_sci();
157}
158
Stefan Reinauerbf34e942012-04-27 00:44:04 +0200159int mainboard_smi_apmc(u8 data)
Sven Schnelle8b39e072011-06-12 16:49:13 +0200160{
Sven Schnelle8b39e072011-06-12 16:49:13 +0200161 switch(data) {
162 case APM_CNT_ACPI_ENABLE:
163 /* use 0x1600/0x1604 to prevent races with userspace */
164 ec_set_ports(0x1604, 0x1600);
165 /* route H8SCI to SCI */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200166 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
Sven Schnelle8b39e072011-06-12 16:49:13 +0200167 /* discard all events, and enable attention */
168 ec_write(0x80, 0x01);
169 break;
170 case APM_CNT_ACPI_DISABLE:
171 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
172 provide a EC query function */
173 ec_set_ports(0x66, 0x62);
174 /* route H8SCI# to SMI */
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200175 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
Sven Schnelle8b39e072011-06-12 16:49:13 +0200176 /* discard all events, and enable attention */
177 ec_write(0x80, 0x01);
178 break;
179 default:
180 break;
181 }
182 return 0;
183}