Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Vladimir Serbinenko | b2939f7 | 2014-01-22 17:12:35 +0100 | [diff] [blame] | 5 | * Copyright (C) 2014 Vladimir Serbinenko |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 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. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 19 | * Foundation, Inc. |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <arch/io.h> |
| 23 | #include <console/console.h> |
| 24 | #include <cpu/x86/smm.h> |
| 25 | #include <ec/acpi/ec.h> |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 26 | #include <ec/lenovo/h8/h8.h> |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 27 | #include <southbridge/intel/bd82x6x/pch.h> |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 28 | |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 29 | #define GPE_EC_SCI 1 |
| 30 | #define GPE_EC_WAKE 13 |
| 31 | |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 32 | static void mainboard_smm_init(void) |
| 33 | { |
| 34 | printk(BIOS_DEBUG, "initializing SMI\n"); |
| 35 | /* Enable 0x1600/0x1600 register pair */ |
| 36 | ec_set_bit(0x00, 0x05); |
| 37 | } |
| 38 | |
| 39 | int mainboard_io_trap_handler(int smif) |
| 40 | { |
| 41 | static int smm_initialized; |
| 42 | |
| 43 | if (!smm_initialized) { |
| 44 | mainboard_smm_init(); |
| 45 | smm_initialized = 1; |
| 46 | } |
| 47 | |
Vladimir Serbinenko | 7ef3d90 | 2015-05-28 11:25:50 +0200 | [diff] [blame^] | 48 | return 0; |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 51 | static void mainboard_smi_handle_ec_sci(void) |
| 52 | { |
| 53 | u8 status = inb(EC_SC); |
| 54 | u8 event; |
| 55 | |
| 56 | if (!(status & EC_SCI_EVT)) |
| 57 | return; |
| 58 | |
| 59 | event = ec_query(); |
| 60 | printk(BIOS_DEBUG, "EC event %02x\n", event); |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void mainboard_smi_gpi(u32 gpi_sts) |
| 64 | { |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 65 | if (gpi_sts & (1 << GPE_EC_SCI)) |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 66 | mainboard_smi_handle_ec_sci(); |
| 67 | } |
| 68 | |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 69 | int mainboard_smi_apmc(u8 data) |
| 70 | { |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 71 | switch (data) { |
| 72 | case APM_CNT_ACPI_ENABLE: |
| 73 | /* use 0x1600/0x1604 to prevent races with userspace */ |
| 74 | ec_set_ports(0x1604, 0x1600); |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 75 | /* route EC_SCI to SCI */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 76 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI); |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 77 | /* discard all events, and enable attention */ |
| 78 | ec_write(0x80, 0x01); |
| 79 | break; |
| 80 | case APM_CNT_ACPI_DISABLE: |
| 81 | /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't |
| 82 | provide a EC query function */ |
| 83 | ec_set_ports(0x66, 0x62); |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 84 | /* route EC_SCI to SMI */ |
| 85 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI); |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 86 | /* discard all events, and enable attention */ |
| 87 | ec_write(0x80, 0x01); |
| 88 | break; |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 89 | default: |
| 90 | break; |
| 91 | } |
| 92 | return 0; |
| 93 | } |
Vladimir Serbinenko | 782ac36 | 2014-08-08 00:00:20 +0200 | [diff] [blame] | 94 | |
| 95 | void mainboard_smi_sleep(u8 slp_typ) |
| 96 | { |
| 97 | if (slp_typ == 3) { |
| 98 | u8 ec_wake = ec_read(0x32); |
| 99 | /* If EC wake events are enabled, enable wake on EC WAKE GPE. */ |
| 100 | if (ec_wake & 0x14) { |
Vladimir Serbinenko | 782ac36 | 2014-08-08 00:00:20 +0200 | [diff] [blame] | 101 | /* Redirect EC WAKE GPE to SCI. */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 102 | gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI); |
Vladimir Serbinenko | 782ac36 | 2014-08-08 00:00:20 +0200 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | } |