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