Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Vladimir Serbinenko |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <arch/io.h> |
| 19 | #include <console/console.h> |
| 20 | #include <cpu/x86/smm.h> |
| 21 | #include <ec/acpi/ec.h> |
| 22 | #include <pc80/mc146818rtc.h> |
| 23 | #include <ec/lenovo/h8/h8.h> |
| 24 | #include <delay.h> |
| 25 | #include <southbridge/intel/bd82x6x/nvs.h> |
| 26 | #include <southbridge/intel/bd82x6x/pch.h> |
| 27 | #include <southbridge/intel/bd82x6x/me.h> |
| 28 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 29 | #include <cpu/intel/model_206ax/model_206ax.h> |
| 30 | |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 31 | #define GPE_EC_SCI 1 |
| 32 | #define GPE_EC_WAKE 13 |
| 33 | |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 34 | static void mainboard_smm_init(void) |
| 35 | { |
| 36 | printk(BIOS_DEBUG, "initializing SMI\n"); |
| 37 | /* Enable 0x1600/0x1600 register pair */ |
| 38 | ec_set_bit(0x00, 0x05); |
| 39 | } |
| 40 | |
| 41 | int mainboard_io_trap_handler(int smif) |
| 42 | { |
| 43 | static int smm_initialized; |
| 44 | |
| 45 | if (!smm_initialized) { |
| 46 | mainboard_smm_init(); |
| 47 | smm_initialized = 1; |
| 48 | } |
| 49 | |
| 50 | switch (smif) { |
| 51 | default: |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | /* On success, the IO Trap Handler returns 1 |
| 56 | * On failure, the IO Trap Handler returns a value != 1 */ |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | static void mainboard_smi_brightness_up(void) |
| 61 | { |
| 62 | u8 value; |
| 63 | |
| 64 | if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) < 0xf0) |
| 65 | pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value + 0x10) | 0xf); |
| 66 | } |
| 67 | |
| 68 | static void mainboard_smi_brightness_down(void) |
| 69 | { |
| 70 | u8 value; |
| 71 | |
| 72 | if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) > 0x10) |
| 73 | pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, |
| 74 | (value - 0x10) & 0xf0); |
| 75 | } |
| 76 | |
| 77 | static void mainboard_smi_handle_ec_sci(void) |
| 78 | { |
| 79 | u8 status = inb(EC_SC); |
| 80 | u8 event; |
| 81 | |
| 82 | if (!(status & EC_SCI_EVT)) |
| 83 | return; |
| 84 | |
| 85 | event = ec_query(); |
| 86 | printk(BIOS_DEBUG, "EC event %02x\n", event); |
| 87 | |
| 88 | switch (event) { |
| 89 | case 0x14: |
| 90 | /* brightness up */ |
| 91 | mainboard_smi_brightness_up(); |
| 92 | break; |
| 93 | case 0x15: |
| 94 | /* brightness down */ |
| 95 | mainboard_smi_brightness_down(); |
| 96 | break; |
| 97 | default: |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void mainboard_smi_gpi(u32 gpi_sts) |
| 103 | { |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 104 | if (gpi_sts & (1 << GPE_EC_SCI)) |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 105 | mainboard_smi_handle_ec_sci(); |
| 106 | } |
| 107 | |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 108 | int mainboard_smi_apmc(u8 data) |
| 109 | { |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 110 | switch (data) { |
| 111 | case APM_CNT_ACPI_ENABLE: |
| 112 | /* use 0x1600/0x1604 to prevent races with userspace */ |
| 113 | ec_set_ports(0x1604, 0x1600); |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 114 | /* route EC_SCI to SCI */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 115 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI); |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 116 | /* discard all events, and enable attention */ |
| 117 | ec_write(0x80, 0x01); |
| 118 | break; |
| 119 | case APM_CNT_ACPI_DISABLE: |
| 120 | /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't |
| 121 | provide a EC query function */ |
| 122 | ec_set_ports(0x66, 0x62); |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 123 | /* route EC_SCI to SMI */ |
| 124 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI); |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 125 | /* discard all events, and enable attention */ |
| 126 | ec_write(0x80, 0x01); |
| 127 | break; |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 128 | default: |
| 129 | break; |
| 130 | } |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | void mainboard_smi_sleep(u8 slp_typ) |
| 135 | { |
| 136 | if (slp_typ == 3) { |
| 137 | u8 ec_wake = ec_read(0x32); |
| 138 | /* If EC wake events are enabled, enable wake on EC WAKE GPE. */ |
| 139 | if (ec_wake & 0x14) { |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 140 | /* Redirect EC WAKE GPE to SCI. */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 141 | gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI); |
Nicolas Reinecke | 572795b | 2014-12-29 19:57:29 +0100 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |