mainboard/[g-p]*: Remove copyright notices
[coreboot.git] / src / mainboard / lenovo / x60 / smihandler.c
blobdf33133adee4683e4a1c1fcabbd5c1058d824995
1 /*
2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <arch/io.h>
17 #include <device/pci_ops.h>
18 #include <console/console.h>
19 #include <cpu/x86/smm.h>
20 #include <southbridge/intel/i82801gx/nvs.h>
21 #include <southbridge/intel/common/pmutil.h>
22 #include <ec/acpi/ec.h>
23 #include <option.h>
24 #include <ec/lenovo/h8/h8.h>
25 #include <delay.h>
26 #include "dock.h"
27 #include "smi.h"
29 #define GPE_EC_SCI 12
31 static void mainboard_smi_save_cmos(void)
33 u8 val;
34 u8 tmp70, tmp72;
36 tmp70 = inb(0x70);
37 tmp72 = inb(0x72);
39 val = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4);
40 set_option("tft_brightness", &val);
41 val = ec_read(H8_VOLUME_CONTROL);
42 set_option("volume", &val);
44 outb(tmp70, 0x70);
45 outb(tmp72, 0x72);
48 int mainboard_io_trap_handler(int smif)
50 switch (smif) {
51 case SMI_DOCK_CONNECT:
52 ec_clr_bit(0x03, 2);
53 mdelay(250);
54 if (!dock_connect()) {
55 ec_set_bit(0x03, 2);
56 /* set dock LED to indicate status */
57 ec_write(0x0c, 0x09);
58 ec_write(0x0c, 0x88);
59 } else {
60 /* blink dock LED to indicate failure */
61 ec_write(0x0c, 0x08);
62 ec_write(0x0c, 0xc9);
64 break;
66 case SMI_DOCK_DISCONNECT:
67 ec_clr_bit(0x03, 2);
68 dock_disconnect();
69 break;
71 case SMI_SAVE_CMOS:
72 mainboard_smi_save_cmos();
73 break;
74 default:
75 return 0;
78 /* On success, the IO Trap Handler returns 1
79 * On failure, the IO Trap Handler returns a value != 1 */
80 return 1;
83 static void mainboard_smi_brightness_up(void)
85 u8 value;
87 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) < 0xf0)
88 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value + 0x10) | 0xf);
91 static void mainboard_smi_brightness_down(void)
93 u8 value;
95 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) > 0x10)
96 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value - 0x10) & 0xf0);
99 static void mainboard_smi_handle_ec_sci(void)
101 u8 status = inb(EC_SC);
102 u8 event;
104 if (!(status & EC_SCI_EVT))
105 return;
107 event = ec_query();
108 printk(BIOS_DEBUG, "EC event %02x\n", event);
110 switch (event) {
111 /* brightness up */
112 case 0x14:
113 mainboard_smi_brightness_up();
114 mainboard_smi_save_cmos();
115 break;
116 /* brightness down */
117 case 0x15:
118 mainboard_smi_brightness_down();
119 mainboard_smi_save_cmos();
120 break;
121 /* Fn-F9 key */
122 case 0x18:
123 /* Power loss */
124 case 0x27:
125 /* Undock Key */
126 case 0x50:
127 mainboard_io_trap_handler(SMI_DOCK_DISCONNECT);
128 break;
129 /* Dock Event */
130 case 0x37:
131 case 0x58:
132 mainboard_io_trap_handler(SMI_DOCK_CONNECT);
133 break;
134 default:
135 break;
139 void mainboard_smi_gpi(u32 gpi)
141 if (gpi & (1 << GPE_EC_SCI))
142 mainboard_smi_handle_ec_sci();
145 int mainboard_smi_apmc(u8 data)
147 switch (data) {
148 case APM_CNT_ACPI_ENABLE:
149 /* use 0x1600/0x1604 to prevent races with userspace */
150 ec_set_ports(0x1604, 0x1600);
151 /* route H8SCI to SCI */
152 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
153 /* discard all events, and enable attention */
154 ec_write(0x80, 0x01);
155 break;
156 case APM_CNT_ACPI_DISABLE:
157 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
158 provide a EC query function */
159 ec_set_ports(0x66, 0x62);
160 /* route H8SCI# to SMI */
161 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
162 /* discard all events, and enable attention */
163 ec_write(0x80, 0x01);
164 break;
165 default:
166 break;
168 return 0;