Thomas Heijligen | 819d872 | 2019-03-18 11:32:34 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
| 4 | #include <console/console.h> |
| 5 | #include <cpu/x86/smm.h> |
| 6 | #include <ec/acpi/ec.h> |
Felix Singer | e877493 | 2020-11-24 19:27:47 +0000 | [diff] [blame^] | 7 | #include <mainboard/ec.h> |
Thomas Heijligen | 819d872 | 2019-03-18 11:32:34 +0100 | [diff] [blame] | 8 | #include <timer.h> |
| 9 | |
Thomas Heijligen | 819d872 | 2019-03-18 11:32:34 +0100 | [diff] [blame] | 10 | #define EC_STATUS 0x50 |
| 11 | #define EC_RUNNING (1 << 1) |
| 12 | #define EC_DEVICE_CONTROL_1 0x80 |
| 13 | #define EC_DEVICE_CONTROL_1_PROGAS_ON (1 << 0) |
| 14 | #define EC_DEVICE_CONTROL_1_BOOMER_ON (1 << 1) |
| 15 | #define EC_DEVICE_CONTROL_1_BT_RF_ON (1 << 2) |
| 16 | #define EC_DEVICE_CONTROL_1_TP_ON (1 << 3) |
| 17 | #define EC_DEVICE_CONTROL_1_LAN2_RST (1 << 6) |
| 18 | #define EC_DEVICE_CONTROL_2 0x81 |
| 19 | #define EC_DEVICE_CONTROL_2_LAN_1_ON (1 << 0) |
| 20 | #define EC_DEVICE_CONTROL_2_LAN_2_ON (1 << 1) |
| 21 | #define EC_DEVICE_CONTROL_2_WLAN_ON (1 << 2) |
| 22 | #define EC_DEVICE_CONTROL_2_USB_ON (1 << 3) |
| 23 | #define EC_DEVICE_CONTROL_2_IDE1_ON (1 << 4) |
| 24 | #define EC_DEVICE_CONTROL_2_IDE2_ON (1 << 5) |
| 25 | #define EC_DEVICE_CONTROL_2_COM1_ON (1 << 6) |
| 26 | #define EC_DEVICE_CONTROL_2_MPI_ON (1 << 7) |
| 27 | |
| 28 | #define RUNNING_TIMEOUT_MS 3333 |
| 29 | |
| 30 | static bool ec_running(void) |
| 31 | { |
| 32 | struct stopwatch sw; |
| 33 | uint8_t ec_status; |
| 34 | |
| 35 | stopwatch_init_msecs_expire(&sw, RUNNING_TIMEOUT_MS); |
| 36 | do |
| 37 | ec_status = ec_read(EC_STATUS); |
| 38 | while (!(ec_status & EC_RUNNING) && !stopwatch_expired(&sw)); |
| 39 | |
| 40 | if (!(ec_status & EC_RUNNING)) |
| 41 | printk(BIOS_WARNING, "EC not ready after %dms\n", RUNNING_TIMEOUT_MS); |
| 42 | |
| 43 | return !!(ec_status & EC_RUNNING); |
| 44 | } |
| 45 | |
| 46 | void ec_enable_devices(bool enable_usb) |
| 47 | { |
| 48 | uint8_t control_1, control_2; |
| 49 | |
| 50 | if (!ec_running()) |
| 51 | return; |
| 52 | |
| 53 | control_1 = ec_read(EC_DEVICE_CONTROL_1); |
| 54 | control_2 = ec_read(EC_DEVICE_CONTROL_2); |
| 55 | |
| 56 | printk(BIOS_INFO, "EC previous EDC1: 0x%02x\n", control_1); |
| 57 | printk(BIOS_INFO, "EC previous EDC2: 0x%02x\n", control_2); |
| 58 | |
| 59 | control_1 &= ~(EC_DEVICE_CONTROL_1_BT_RF_ON); |
| 60 | control_1 |= EC_DEVICE_CONTROL_1_BOOMER_ON; |
| 61 | |
| 62 | control_2 &= ~(EC_DEVICE_CONTROL_2_WLAN_ON | EC_DEVICE_CONTROL_2_USB_ON); |
| 63 | control_2 |= EC_DEVICE_CONTROL_2_MPI_ON; |
| 64 | if (enable_usb) |
| 65 | control_2 |= EC_DEVICE_CONTROL_2_USB_ON; |
| 66 | |
| 67 | ec_write(EC_DEVICE_CONTROL_1, control_1); |
| 68 | ec_write(EC_DEVICE_CONTROL_2, control_2); |
| 69 | |
| 70 | printk(BIOS_INFO, "EC current EDC1: 0x%02x\n", ec_read(EC_DEVICE_CONTROL_1)); |
| 71 | printk(BIOS_INFO, "EC current EDC2: 0x%02x\n", ec_read(EC_DEVICE_CONTROL_2)); |
| 72 | } |
| 73 | |
| 74 | void mainboard_smi_sleep(const uint8_t slp_typ) |
| 75 | { |
| 76 | uint8_t control_1, control_2; |
| 77 | |
| 78 | if (slp_typ != ACPI_S5) |
| 79 | return; |
| 80 | |
| 81 | if (!ec_running()) |
| 82 | return; |
| 83 | |
| 84 | control_1 = ec_read(EC_DEVICE_CONTROL_1); |
| 85 | control_2 = ec_read(EC_DEVICE_CONTROL_2); |
| 86 | |
| 87 | printk(BIOS_INFO, "EC previous EDC1: 0x%02x\n", control_1); |
| 88 | printk(BIOS_INFO, "EC previous EDC2: 0x%02x\n", control_2); |
| 89 | |
| 90 | control_1 &= ~(EC_DEVICE_CONTROL_1_BOOMER_ON); |
| 91 | control_2 &= ~(EC_DEVICE_CONTROL_2_USB_ON | EC_DEVICE_CONTROL_2_MPI_ON); |
| 92 | |
| 93 | ec_write(EC_DEVICE_CONTROL_1, control_1); |
| 94 | ec_write(EC_DEVICE_CONTROL_2, control_2); |
| 95 | |
| 96 | printk(BIOS_INFO, "EC current EDC1: 0x%02x\n", ec_read(EC_DEVICE_CONTROL_1)); |
| 97 | printk(BIOS_INFO, "EC current EDC2: 0x%02x\n", ec_read(EC_DEVICE_CONTROL_2)); |
| 98 | } |