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
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.
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>
24 #include <ec/lenovo/h8/h8.h>
31 static void mainboard_smi_save_cmos(void)
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
);
48 int mainboard_io_trap_handler(int smif
)
51 case SMI_DOCK_CONNECT
:
54 if (!dock_connect()) {
56 /* set dock LED to indicate status */
60 /* blink dock LED to indicate failure */
66 case SMI_DOCK_DISCONNECT
:
72 mainboard_smi_save_cmos();
78 /* On success, the IO Trap Handler returns 1
79 * On failure, the IO Trap Handler returns a value != 1 */
83 static void mainboard_smi_brightness_up(void)
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)
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
);
104 if (!(status
& EC_SCI_EVT
))
108 printk(BIOS_DEBUG
, "EC event %02x\n", event
);
113 mainboard_smi_brightness_up();
114 mainboard_smi_save_cmos();
116 /* brightness down */
118 mainboard_smi_brightness_down();
119 mainboard_smi_save_cmos();
127 mainboard_io_trap_handler(SMI_DOCK_DISCONNECT
);
132 mainboard_io_trap_handler(SMI_DOCK_CONNECT
);
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
)
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);
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);