Nicolas Reinecke | b165c4a | 2015-07-04 23:37:06 +0200 | [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. |
| 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
| 18 | #include <console/console.h> |
| 19 | #include <cpu/x86/smm.h> |
| 20 | #include <southbridge/intel/ibexpeak/nvs.h> |
| 21 | #include <southbridge/intel/common/pmutil.h> |
| 22 | #include <northbridge/intel/nehalem/nehalem.h> |
| 23 | #include <ec/acpi/ec.h> |
| 24 | #include <ec/lenovo/h8/h8.h> |
| 25 | #include <delay.h> |
| 26 | #include "dock.h" |
| 27 | |
| 28 | #define GPE_EC_SCI 1 |
| 29 | #define GPE_EC_WAKE 13 |
| 30 | |
| 31 | static void mainboard_smi_handle_ec_sci(void) |
| 32 | { |
| 33 | u8 status = inb(EC_SC); |
| 34 | u8 event; |
| 35 | |
| 36 | if (!(status & EC_SCI_EVT)) |
| 37 | return; |
| 38 | |
| 39 | event = ec_query(); |
| 40 | printk(BIOS_DEBUG, "EC event %02x\n", event); |
| 41 | |
| 42 | switch (event) { |
| 43 | case 0x18: |
| 44 | /* Fn-F9 key */ |
| 45 | case 0x27: |
| 46 | /* Power loss */ |
| 47 | case 0x50: |
| 48 | /* Undock Key */ |
| 49 | ec_clr_bit(0x03, 2); |
| 50 | dock_disconnect(); |
| 51 | break; |
| 52 | case 0x37: |
| 53 | case 0x58: |
| 54 | /* Dock Event */ |
| 55 | ec_clr_bit(0x03, 2); |
| 56 | mdelay(250); |
| 57 | dock_connect(); |
| 58 | ec_set_bit(0x03, 2); |
| 59 | /* set dock LED to indicate status */ |
| 60 | ec_write(0x0c, 0x09); |
| 61 | ec_write(0x0c, 0x88); |
| 62 | break; |
| 63 | default: |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void mainboard_smi_gpi(u32 gpi_sts) |
| 69 | { |
| 70 | if (gpi_sts & (1 << GPE_EC_SCI)) |
| 71 | mainboard_smi_handle_ec_sci(); |
| 72 | } |
| 73 | |
| 74 | int mainboard_smi_apmc(u8 data) |
| 75 | { |
| 76 | switch (data) { |
| 77 | case APM_CNT_ACPI_ENABLE: |
| 78 | /* use 0x1600/0x1604 to prevent races with userspace */ |
| 79 | ec_set_ports(0x1604, 0x1600); |
| 80 | /* route H8SCI to SCI */ |
| 81 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI); |
| 82 | /* discard all events, and enable attention */ |
| 83 | ec_write(0x80, 0x01); |
| 84 | break; |
| 85 | case APM_CNT_ACPI_DISABLE: |
| 86 | /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't |
| 87 | provide a EC query function */ |
| 88 | ec_set_ports(0x66, 0x62); |
| 89 | /* route H8SCI# to SMI */ |
| 90 | gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI); |
| 91 | /* discard all events, and enable attention */ |
| 92 | ec_write(0x80, 0x01); |
| 93 | break; |
| 94 | default: |
| 95 | break; |
| 96 | } |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | void mainboard_smi_sleep(u8 slp_typ) |
| 101 | { |
| 102 | if (slp_typ == 3) { |
| 103 | u8 ec_wake = ec_read(0x32); |
| 104 | /* If EC wake events are enabled, enable wake on EC WAKE GPE. */ |
| 105 | if (ec_wake & 0x14) { |
| 106 | /* Redirect EC WAKE GPE to SCI. */ |
| 107 | gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI); |
| 108 | } |
| 109 | } |
| 110 | } |