Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 1 | /* |
| 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 Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | #include <cpu/x86/smm.h> |
| 20 | #include "southbridge/intel/i82801gx/nvs.h" |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 21 | #include "southbridge/intel/i82801gx/i82801gx.h" |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 22 | #include <ec/acpi/ec.h> |
Sven Schnelle | 4297a9a | 2011-06-12 14:35:11 +0200 | [diff] [blame] | 23 | #include <pc80/mc146818rtc.h> |
| 24 | #include <ec/lenovo/h8/h8.h> |
Sven Schnelle | 483ec41 | 2012-01-10 14:44:12 +0100 | [diff] [blame] | 25 | #include <delay.h> |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 26 | #include "dock.h" |
| 27 | #include "smi.h" |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 28 | |
Kyösti Mälkki | 189f3ba | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 29 | #define GPE_EC_SCI 12 |
| 30 | |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 31 | static 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 Schnelle | 4297a9a | 2011-06-12 14:35:11 +0200 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static void mainboard_smi_save_cmos(void) |
| 39 | { |
| 40 | u8 val; |
Sven Schnelle | edcf9f4 | 2011-06-28 08:05:26 +0200 | [diff] [blame] | 41 | u8 tmp70, tmp72; |
Sven Schnelle | 4297a9a | 2011-06-12 14:35:11 +0200 | [diff] [blame] | 42 | |
| 43 | tmp70 = inb(0x70); |
| 44 | tmp72 = inb(0x72); |
Sven Schnelle | 4297a9a | 2011-06-12 14:35:11 +0200 | [diff] [blame] | 45 | |
| 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 Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 55 | int mainboard_io_trap_handler(int smif) |
| 56 | { |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 57 | static int smm_initialized; |
| 58 | |
| 59 | if (!smm_initialized) { |
| 60 | mainboard_smm_init(); |
| 61 | smm_initialized = 1; |
| 62 | } |
| 63 | |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 64 | switch (smif) { |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 65 | case SMI_DOCK_CONNECT: |
Sven Schnelle | 8d0b86c | 2011-07-11 18:36:16 +0200 | [diff] [blame] | 66 | ec_clr_bit(0x03, 2); |
Sven Schnelle | 483ec41 | 2012-01-10 14:44:12 +0100 | [diff] [blame] | 67 | udelay(250000); |
| 68 | if (!dock_connect()) { |
Sven Schnelle | 8d0b86c | 2011-07-11 18:36:16 +0200 | [diff] [blame] | 69 | ec_set_bit(0x03, 2); |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 70 | /* set dock LED to indicate status */ |
Sven Schnelle | 8d0b86c | 2011-07-11 18:36:16 +0200 | [diff] [blame] | 71 | ec_write(0x0c, 0x09); |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 72 | ec_write(0x0c, 0x88); |
| 73 | } else { |
| 74 | /* blink dock LED to indicate failure */ |
Sven Schnelle | 8d0b86c | 2011-07-11 18:36:16 +0200 | [diff] [blame] | 75 | ec_write(0x0c, 0x08); |
| 76 | ec_write(0x0c, 0xc9); |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 77 | } |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 78 | break; |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 79 | |
| 80 | case SMI_DOCK_DISCONNECT: |
Sven Schnelle | 8d0b86c | 2011-07-11 18:36:16 +0200 | [diff] [blame] | 81 | ec_clr_bit(0x03, 2); |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 82 | dock_disconnect(); |
Sven Schnelle | fea6bd1 | 2011-04-01 07:28:56 +0000 | [diff] [blame] | 83 | break; |
| 84 | |
Sven Schnelle | 4297a9a | 2011-06-12 14:35:11 +0200 | [diff] [blame] | 85 | case SMI_SAVE_CMOS: |
| 86 | mainboard_smi_save_cmos(); |
| 87 | break; |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 88 | default: |
Sven Schnelle | 0f9cd43 | 2011-06-12 16:55:56 +0200 | [diff] [blame] | 89 | return 0; |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Sven Schnelle | 0f9cd43 | 2011-06-12 16:55:56 +0200 | [diff] [blame] | 92 | /* On success, the IO Trap Handler returns 1 |
| 93 | * On failure, the IO Trap Handler returns a value != 1 */ |
| 94 | return 1; |
Sven Schnelle | e2ca71e | 2011-02-14 20:02:47 +0000 | [diff] [blame] | 95 | } |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 96 | |
| 97 | static 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 | |
| 105 | static 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 | |
| 113 | static 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 Schnelle | 8d0b86c | 2011-07-11 18:36:16 +0200 | [diff] [blame] | 135 | /* 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 Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 148 | default: |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 153 | void mainboard_smi_gpi(u32 gpi) |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 154 | { |
Kyösti Mälkki | 189f3ba | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 155 | if (gpi & (1 << GPE_EC_SCI)) |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 156 | mainboard_smi_handle_ec_sci(); |
| 157 | } |
| 158 | |
Stefan Reinauer | bf34e94 | 2012-04-27 00:44:04 +0200 | [diff] [blame] | 159 | int mainboard_smi_apmc(u8 data) |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 160 | { |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 161 | 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älkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 166 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI); |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 167 | /* 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älkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 175 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI); |
Sven Schnelle | 8b39e07 | 2011-06-12 16:49:13 +0200 | [diff] [blame] | 176 | /* discard all events, and enable attention */ |
| 177 | ec_write(0x80, 0x01); |
| 178 | break; |
| 179 | default: |
| 180 | break; |
| 181 | } |
| 182 | return 0; |
| 183 | } |