2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 coresystems GmbH
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
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23 #include <arch/romcc_io.h>
24 #include <console/console.h>
25 #include <cpu/x86/smm.h>
26 #include "southbridge/intel/i82801gx/nvs.h"
27 #include "southbridge/intel/i82801gx/i82801gx.h"
28 #include <ec/acpi/ec.h>
29 #include <pc80/mc146818rtc.h>
30 #include <ec/lenovo/h8/h8.h>
35 /* The southbridge SMI handler checks whether gnvs has a
36 * valid pointer before calling the trap handler
38 extern global_nvs_t *gnvs;
40 static void mainboard_smm_init(void)
42 printk(BIOS_DEBUG, "initializing SMI\n");
43 /* Enable 0x1600/0x1600 register pair */
44 ec_set_bit(0x00, 0x05);
47 static void mainboard_smi_save_cmos(void)
55 val = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4);
56 set_option("tft_brightness", &val);
57 val = ec_read(H8_VOLUME_CONTROL);
58 set_option("volume", &val);
64 int mainboard_io_trap_handler(int smif)
66 static int smm_initialized;
68 if (!smm_initialized) {
74 case SMI_DOCK_CONNECT:
77 if (!dock_connect()) {
79 /* set dock LED to indicate status */
83 /* blink dock LED to indicate failure */
89 case SMI_DOCK_DISCONNECT:
95 mainboard_smi_save_cmos();
101 /* On success, the IO Trap Handler returns 1
102 * On failure, the IO Trap Handler returns a value != 1 */
106 static void mainboard_smi_brightness_up(void)
110 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) < 0xf0)
111 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value + 0x10) | 0xf);
114 static void mainboard_smi_brightness_down(void)
118 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) > 0x10)
119 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value - 0x10) & 0xf0);
122 static void mainboard_smi_handle_ec_sci(void)
124 u8 status = inb(EC_SC);
127 if (!(status & EC_SCI_EVT))
131 printk(BIOS_DEBUG, "EC event %02x\n", event);
136 mainboard_smi_brightness_up();
137 mainboard_smi_save_cmos();
139 /* brightness down */
141 mainboard_smi_brightness_down();
142 mainboard_smi_save_cmos();
150 mainboard_io_trap_handler(SMI_DOCK_DISCONNECT);
155 mainboard_io_trap_handler(SMI_DOCK_CONNECT);
162 void mainboard_smi_gpi(u16 gpi)
165 mainboard_smi_handle_ec_sci();
168 int mainboard_apm_cnt(u8 data)
170 u16 pmbase = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc;
173 printk(BIOS_DEBUG, "%s: pmbase %04X, data %02X\n", __func__, pmbase, data);
179 case APM_CNT_ACPI_ENABLE:
180 /* use 0x1600/0x1604 to prevent races with userspace */
181 ec_set_ports(0x1604, 0x1600);
182 /* route H8SCI to SCI */
183 outw(inw(ALT_GP_SMI_EN) & ~0x1000, pmbase + ALT_GP_SMI_EN);
184 tmp = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xbb);
187 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xbb, tmp);
188 /* discard all events, and enable attention */
189 ec_write(0x80, 0x01);
191 case APM_CNT_ACPI_DISABLE:
192 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
193 provide a EC query function */
194 ec_set_ports(0x66, 0x62);
195 /* route H8SCI# to SMI */
196 outw(inw(pmbase + ALT_GP_SMI_EN) | 0x1000, pmbase + ALT_GP_SMI_EN);
197 tmp = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xbb);
200 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xbb, tmp);
201 /* discard all events, and enable attention */
202 ec_write(0x80, 0x01);