Angel Pons | 89ab250 | 2020-04-03 01:22:28 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 2 | |
| 3 | #include <arch/io.h> |
| 4 | #include <console/console.h> |
| 5 | #include <cpu/x86/smm.h> |
| 6 | #include <ec/acpi/ec.h> |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 7 | #include <ec/lenovo/h8/h8.h> |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 8 | #include <southbridge/intel/bd82x6x/pch.h> |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 9 | #include <southbridge/intel/common/pmutil.h> |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 10 | |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 11 | #define GPE_EC_SCI 1 |
| 12 | #define GPE_EC_WAKE 13 |
| 13 | |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 14 | static void mainboard_smi_handle_ec_sci(void) |
| 15 | { |
| 16 | u8 status = inb(EC_SC); |
| 17 | u8 event; |
| 18 | |
| 19 | if (!(status & EC_SCI_EVT)) |
| 20 | return; |
| 21 | |
| 22 | event = ec_query(); |
Paul Menzel | 5664293 | 2020-07-19 09:42:53 +0200 | [diff] [blame] | 23 | printk(BIOS_DEBUG, "EC event %#02x\n", event); |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void mainboard_smi_gpi(u32 gpi_sts) |
| 27 | { |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 28 | if (gpi_sts & (1 << GPE_EC_SCI)) |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 29 | mainboard_smi_handle_ec_sci(); |
| 30 | } |
| 31 | |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 32 | int mainboard_smi_apmc(u8 data) |
| 33 | { |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 34 | switch (data) { |
| 35 | case APM_CNT_ACPI_ENABLE: |
| 36 | /* use 0x1600/0x1604 to prevent races with userspace */ |
| 37 | ec_set_ports(0x1604, 0x1600); |
Nicolas Reinecke | b0922f0 | 2015-02-01 02:53:35 +0100 | [diff] [blame] | 38 | /* route EC_SCI to SCI */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 39 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI); |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 40 | /* discard all events, and enable attention */ |
| 41 | ec_write(0x80, 0x01); |
| 42 | break; |
| 43 | case APM_CNT_ACPI_DISABLE: |
| 44 | /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't |
| 45 | provide a EC query function */ |
| 46 | ec_set_ports(0x66, 0x62); |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 47 | /* route EC_SCI to SMI */ |
| 48 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI); |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 49 | /* discard all events, and enable attention */ |
| 50 | ec_write(0x80, 0x01); |
| 51 | break; |
Vladimir Serbinenko | e7e9502 | 2014-01-12 15:26:15 +0100 | [diff] [blame] | 52 | default: |
| 53 | break; |
| 54 | } |
| 55 | return 0; |
| 56 | } |
Vladimir Serbinenko | 782ac36 | 2014-08-08 00:00:20 +0200 | [diff] [blame] | 57 | |
| 58 | void mainboard_smi_sleep(u8 slp_typ) |
| 59 | { |
| 60 | if (slp_typ == 3) { |
| 61 | u8 ec_wake = ec_read(0x32); |
Peter Lemenkov | 6b7d40a | 2020-01-22 11:40:16 +0100 | [diff] [blame] | 62 | /* If EC wake events are enabled, enable wake on EC WAKE GPE. */ |
Vladimir Serbinenko | 782ac36 | 2014-08-08 00:00:20 +0200 | [diff] [blame] | 63 | if (ec_wake & 0x14) { |
Peter Lemenkov | 6b7d40a | 2020-01-22 11:40:16 +0100 | [diff] [blame] | 64 | /* Redirect EC WAKE GPE to SCI. */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 65 | gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI); |
Vladimir Serbinenko | 782ac36 | 2014-08-08 00:00:20 +0200 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |