Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +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. |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | #include <cpu/x86/smm.h> |
| 20 | #include "southbridge/intel/i82801gx/i82801gx.h" |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 21 | #include "southbridge/intel/i82801gx/nvs.h" |
Sven Schnelle | 7592e8b | 2011-01-27 11:43:03 +0000 | [diff] [blame] | 22 | #include <ec/acpi/ec.h> |
| 23 | #include "ec_oem.c" |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 24 | |
| 25 | #define MAX_LCD_BRIGHTNESS 0xd8 |
| 26 | |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 27 | /* The southbridge SMI handler checks whether gnvs has a |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 28 | * valid pointer before calling the trap handler |
| 29 | */ |
| 30 | extern global_nvs_t *gnvs; |
| 31 | |
| 32 | int mainboard_io_trap_handler(int smif) |
| 33 | { |
| 34 | u8 reg8; |
| 35 | u32 reg32; |
| 36 | |
| 37 | switch (smif) { |
| 38 | case 0x2b: |
| 39 | printk(BIOS_DEBUG, "CPU power state switch\n"); |
| 40 | // TODO, move to CPU handler? |
| 41 | break; |
| 42 | case 0x3d: |
| 43 | printk(BIOS_DEBUG, "Enable C-State SMM coordination\n"); |
| 44 | // TODO, move to CPU handler? |
| 45 | break; |
| 46 | case 0x46: |
| 47 | printk(BIOS_DEBUG, "S3 DTS SMI (completely re-enable DTS)\n"); |
| 48 | // TODO, move to CPU handler? |
| 49 | break; |
| 50 | case 0x47: |
| 51 | printk(BIOS_DEBUG, "S4 DTS SMI (Update NVS DTS temperature)\n"); |
| 52 | // TODO, move to CPU handler? |
| 53 | break; |
| 54 | case 0xc0: |
| 55 | printk(BIOS_DEBUG, "Disable RF\n"); |
| 56 | // TODO |
| 57 | break; |
| 58 | case 0xd0: |
| 59 | printk(BIOS_DEBUG, "ACBS LAN Power on\n"); |
| 60 | // TODO |
| 61 | break; |
| 62 | case 0xd1: |
| 63 | printk(BIOS_DEBUG, "ACBS LAN Power off\n"); |
| 64 | // TODO |
| 65 | break; |
| 66 | case 0xd2: |
| 67 | printk(BIOS_DEBUG, "Check AC status\n"); |
| 68 | // TODO |
| 69 | break; |
| 70 | case 0xd3: |
| 71 | printk(BIOS_DEBUG, "Enable Bluetooth\n"); |
| 72 | // TODO |
| 73 | break; |
| 74 | case 0xd4: |
| 75 | printk(BIOS_DEBUG, "Disable Bluetooth\n"); |
| 76 | // TODO |
| 77 | break; |
| 78 | case 0xd5: |
| 79 | printk(BIOS_DEBUG, "Set Brightness\n"); |
| 80 | reg8 = gnvs->brtl; |
| 81 | printk(BIOS_DEBUG, "brtl: %x\n", reg8); |
| 82 | ec_write(0x17, reg8); |
| 83 | break; |
| 84 | case 0xd6: |
| 85 | printk(BIOS_DEBUG, "Get Brightness\n"); |
| 86 | reg8 = ec_read(0x17); |
| 87 | printk(BIOS_DEBUG, "brtl: %x\n", reg8); |
| 88 | gnvs->brtl = reg8; |
| 89 | break; |
| 90 | case 0xd7: |
| 91 | printk(BIOS_DEBUG, "Get ECO mode status\n"); |
| 92 | // TODO |
| 93 | break; |
| 94 | case 0xd8: |
| 95 | printk(BIOS_DEBUG, "Get sunlight readable status\n"); |
| 96 | // TODO |
| 97 | break; |
| 98 | case 0xd9: |
| 99 | printk(BIOS_DEBUG, "Get docking connection\n"); |
| 100 | // TODO |
| 101 | break; |
| 102 | case 0xda: |
| 103 | printk(BIOS_DEBUG, "Power off docking\n"); |
| 104 | // TODO |
| 105 | break; |
| 106 | case 0xdc: |
| 107 | printk(BIOS_DEBUG, "EC: Turn on LED on ECO enable\n"); |
| 108 | // TODO |
| 109 | break; |
| 110 | case 0xdd: |
| 111 | printk(BIOS_DEBUG, "EC: Turn off LED on ECO disable\n"); |
| 112 | // TODO |
| 113 | break; |
| 114 | case 0xde: |
| 115 | printk(BIOS_DEBUG, "LAN power off\n"); |
| 116 | reg32 = inl(DEFAULT_GPIOBASE + GP_LVL); |
| 117 | reg32 |= (1 << 24); // Disable LAN Power |
| 118 | outl(reg32, DEFAULT_GPIOBASE + GP_LVL); |
| 119 | break; |
| 120 | case 0xdf: |
| 121 | printk(BIOS_DEBUG, "RF enable\n"); |
| 122 | // TODO |
| 123 | break; |
| 124 | case 0xe0: |
| 125 | printk(BIOS_DEBUG, "Get RTC wake flag\n"); |
| 126 | // TODO |
| 127 | break; |
| 128 | case 0xe1: |
| 129 | printk(BIOS_DEBUG, "Hotkey function\n"); |
| 130 | // TODO |
| 131 | break; |
| 132 | case 0xe3: |
| 133 | printk(BIOS_DEBUG, "ECO disable\n"); |
| 134 | // TODO |
| 135 | break; |
| 136 | default: |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | /* gnvs->smif: |
| 141 | * On success, the IO Trap Handler returns 0 |
| 142 | * On failure, the IO Trap Handler returns a value != 0 |
| 143 | */ |
| 144 | gnvs->smif = 0; |
| 145 | return 1; |
| 146 | } |
| 147 | |
| 148 | static void mainboard_smi_hotkey(u8 hotkey) |
| 149 | { |
| 150 | u8 reg8; |
| 151 | |
| 152 | switch (hotkey) { |
| 153 | case 0x3b: break; // Fn+F1 |
| 154 | case 0x3c: break; // Fn+F2 |
| 155 | case 0x3d: break; // Fn+F3 |
| 156 | case 0x3e: break; // Fn+F4 |
| 157 | case 0x3f: break; // Fn+F5 |
| 158 | case 0x40: // Fn+F6 (Decrease Display Brightness) |
| 159 | reg8 = ec_read(0x17); |
| 160 | reg8 = (reg8 > 8) ? (reg8 - 8) : 0; |
| 161 | ec_write(0x17, reg8); |
| 162 | return; |
| 163 | case 0x41: // Fn+F7 (Increase Display Brightness) |
| 164 | reg8 = ec_read(0x17); |
| 165 | reg8 += 8; |
| 166 | reg8 = (reg8 >= MAX_LCD_BRIGHTNESS) ? MAX_LCD_BRIGHTNESS : reg8; |
| 167 | ec_write(0x17, reg8); |
| 168 | return; |
| 169 | case 0x42: break; // Fn+F8 |
| 170 | case 0x43: break; // Fn+F9 |
| 171 | case 0x44: break; // Fn+F10 |
| 172 | case 0x57: break; // Fn+F11 |
| 173 | case 0x58: break; // Fn+F12 |
| 174 | } |
| 175 | printk(BIOS_DEBUG, "EC hotkey: %02x\n", hotkey); |
| 176 | } |
| 177 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 178 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 179 | { |
| 180 | u8 source, hotkey; |
| 181 | send_ec_oem_command(0x5c); |
| 182 | source = recv_ec_oem_data(); |
| 183 | |
| 184 | switch (source) { |
| 185 | case 0: |
| 186 | // Some kind of ACK? |
| 187 | break; |
| 188 | case 1: |
| 189 | send_ec_oem_command(0x59); |
| 190 | hotkey = recv_ec_oem_data(); |
| 191 | mainboard_smi_hotkey(hotkey); |
| 192 | break; |
| 193 | default: |
| 194 | printk(BIOS_DEBUG, "EC SMI source: %02x\n", source); |
| 195 | } |
| 196 | } |