Angel Pons | 80d9238 | 2020-04-05 15:47:00 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <arch/io.h> |
| 5 | #include <console/console.h> |
| 6 | |
| 7 | #include <soc/iomap.h> |
| 8 | #include <soc/soc_util.h> |
| 9 | #include <soc/pm.h> |
| 10 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 11 | static void print_num_status_bits(int num_bits, uint32_t status, |
| 12 | const char *const bit_names[]) |
| 13 | { |
| 14 | int i; |
| 15 | |
| 16 | if (!status) |
| 17 | return; |
| 18 | |
| 19 | for (i = num_bits - 1; i >= 0; i--) { |
| 20 | if (status & (1 << i)) { |
| 21 | if (bit_names[i]) |
| 22 | printk(BIOS_DEBUG, "%s ", bit_names[i]); |
| 23 | else |
| 24 | printk(BIOS_DEBUG, "BIT%d ", i); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | static uint32_t print_smi_status(uint32_t smi_sts) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 30 | { |
Elyes HAOUAS | 39303d5 | 2018-07-08 12:40:45 +0200 | [diff] [blame] | 31 | static const char *const smi_sts_bits[] = { |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 32 | [2] = "BIOS", |
| 33 | [4] = "SLP_SMI", |
| 34 | [5] = "APM", |
| 35 | [6] = "SWSMI_TMR", |
| 36 | [8] = "PM1", |
| 37 | [9] = "GPE0", |
| 38 | [10] = "GPE1", |
| 39 | [11] = "MC_SMI", |
| 40 | [12] = "DEVMON", |
| 41 | [13] = "TCO", |
| 42 | [14] = "PERIODIC", |
| 43 | [15] = "SERIRQ", |
| 44 | [16] = "SMBUS_SMI", |
| 45 | [17] = "LEGACY_USB2", |
| 46 | [18] = "INTEL_USB2", |
| 47 | [19] = "PATCH", |
| 48 | [20] = "PCI_EXP_SMI", |
| 49 | [21] = "MONITOR", |
| 50 | [26] = "SPI", |
| 51 | [27] = "GPIO_UNLOCK", |
| 52 | [31] = "LEGACY_USB3", |
| 53 | }; |
| 54 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 55 | if (!smi_sts) |
| 56 | return 0; |
| 57 | |
| 58 | printk(BIOS_DEBUG, "SMI_STS: "); |
| 59 | print_num_status_bits(ARRAY_SIZE(smi_sts_bits), smi_sts, smi_sts_bits); |
| 60 | printk(BIOS_DEBUG, "\n"); |
| 61 | |
| 62 | return smi_sts; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 65 | static uint32_t reset_smi_status(void) |
| 66 | { |
| 67 | uint16_t pmbase = get_pmbase(); |
| 68 | uint32_t smi_sts = inl((uint16_t)(pmbase + SMI_STS)); |
| 69 | outl(smi_sts, (uint16_t)(pmbase + SMI_STS)); |
| 70 | return smi_sts; |
| 71 | } |
| 72 | |
| 73 | uint32_t clear_smi_status(void) { return print_smi_status(reset_smi_status()); } |
| 74 | |
| 75 | void enable_smi(uint32_t mask) |
| 76 | { |
| 77 | uint16_t pmbase = get_pmbase(); |
| 78 | uint32_t smi_en = inl((uint16_t)(pmbase + SMI_EN)); |
| 79 | smi_en |= mask; |
| 80 | outl(smi_en, (uint16_t)(pmbase + SMI_EN)); |
| 81 | } |
| 82 | |
| 83 | void disable_smi(uint32_t mask) |
| 84 | { |
| 85 | uint16_t pmbase = get_pmbase(); |
| 86 | uint32_t smi_en = inl((uint16_t)(pmbase + SMI_EN)); |
| 87 | smi_en &= ~mask; |
| 88 | outl(smi_en, (uint16_t)(pmbase + SMI_EN)); |
| 89 | } |
| 90 | |
| 91 | void enable_pm1_control(uint32_t mask) |
| 92 | { |
| 93 | uint16_t pmbase = get_pmbase(); |
| 94 | uint32_t pm1_cnt = inl((uint16_t)(pmbase + PM1_CNT)); |
| 95 | pm1_cnt |= mask; |
| 96 | outl(pm1_cnt, (uint16_t)(pmbase + PM1_CNT)); |
| 97 | } |
| 98 | |
| 99 | void disable_pm1_control(uint32_t mask) |
| 100 | { |
| 101 | uint16_t pmbase = get_pmbase(); |
| 102 | uint32_t pm1_cnt = inl((uint16_t)(pmbase + PM1_CNT)); |
| 103 | pm1_cnt &= ~mask; |
| 104 | outl(pm1_cnt, (uint16_t)(pmbase + PM1_CNT)); |
| 105 | } |
| 106 | |
| 107 | static uint16_t reset_pm1_status(void) |
| 108 | { |
| 109 | uint16_t pmbase = get_pmbase(); |
| 110 | uint16_t pm1_sts = inw((uint16_t)(pmbase + PM1_STS)); |
| 111 | outw(pm1_sts, (uint16_t)(pmbase + PM1_STS)); |
| 112 | return pm1_sts; |
| 113 | } |
| 114 | |
| 115 | static uint16_t print_pm1_status(uint16_t pm1_sts) |
| 116 | { |
| 117 | static const char *const pm1_sts_bits[] = { |
| 118 | [0] = "TMROF", [4] = "BM", [5] = "GBL", |
| 119 | [8] = "PWRBTN", [10] = "RTC", [11] = "PRBTNOR", |
| 120 | [15] = "WAK", |
| 121 | }; |
| 122 | |
| 123 | if (!pm1_sts) |
| 124 | return 0; |
| 125 | |
| 126 | printk(BIOS_SPEW, "PM1_STS: "); |
| 127 | print_num_status_bits(ARRAY_SIZE(pm1_sts_bits), pm1_sts, pm1_sts_bits); |
| 128 | printk(BIOS_SPEW, "\n"); |
| 129 | |
| 130 | return pm1_sts; |
| 131 | } |
| 132 | |
| 133 | uint16_t clear_pm1_status(void) { return print_pm1_status(reset_pm1_status()); } |
| 134 | |
| 135 | void enable_pm1(uint16_t events) |
| 136 | { |
| 137 | uint16_t pmbase = get_pmbase(); |
| 138 | outw(events, (uint16_t)(pmbase + PM1_EN)); |
| 139 | } |
| 140 | |
| 141 | static uint32_t print_tco_status(uint32_t tco_sts) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 142 | { |
Elyes HAOUAS | 39303d5 | 2018-07-08 12:40:45 +0200 | [diff] [blame] | 143 | static const char *const tco_sts_bits[] = { |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 144 | [0] = "NMI2SMI", [1] = "OS_TCO_SMI", |
| 145 | [2] = "TCO_INIT", [3] = "TIMEOUT", |
| 146 | [7] = "NEWCENTURY ", [8] = "BIOSWR ", |
| 147 | [9] = "CPUSCI ", [10] = "CPUSMI ", |
| 148 | [12] = "CPUSERR ", [16] = "INTRD_DET ", |
| 149 | [17] = "SECOND_TO", [20] = "SMLINK_SLV_SMI", |
| 150 | }; |
| 151 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 152 | if (!tco_sts) |
| 153 | return 0; |
| 154 | |
| 155 | printk(BIOS_DEBUG, "TCO_STS: "); |
| 156 | print_num_status_bits(ARRAY_SIZE(tco_sts_bits), tco_sts, tco_sts_bits); |
| 157 | printk(BIOS_DEBUG, "\n"); |
| 158 | |
| 159 | return tco_sts; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 162 | static uint32_t reset_tco_status(void) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 163 | { |
| 164 | uint16_t tcobase = get_tcobase(); |
| 165 | uint32_t tco_sts = inl((uint16_t)(tcobase + TCO1_STS)); |
| 166 | uint32_t tco_en = inl((uint16_t)(tcobase + TCO1_CNT)); |
| 167 | |
| 168 | outl(tco_sts, (uint16_t)(tcobase + TCO1_STS)); |
| 169 | return tco_sts & tco_en; |
| 170 | } |
| 171 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 172 | uint32_t clear_tco_status(void) { return print_tco_status(reset_tco_status()); } |
| 173 | |
| 174 | void enable_gpe(uint32_t mask) |
| 175 | { |
| 176 | uint16_t pmbase = get_pmbase(); |
| 177 | uint32_t gpe0_en = inl((uint16_t)(pmbase + GPE0_EN(GPE_STD))); |
| 178 | gpe0_en |= mask; |
| 179 | outl(gpe0_en, (uint16_t)(pmbase + GPE0_EN(GPE_STD))); |
| 180 | } |
| 181 | |
| 182 | void disable_gpe(uint32_t mask) |
| 183 | { |
| 184 | uint16_t pmbase = get_pmbase(); |
| 185 | uint32_t gpe0_en = inl((uint16_t)(pmbase + GPE0_EN(GPE_STD))); |
| 186 | gpe0_en &= ~mask; |
| 187 | outl(gpe0_en, (uint16_t)(pmbase + GPE0_EN(GPE_STD))); |
| 188 | } |
| 189 | |
| 190 | void disable_all_gpe(void) { disable_gpe(~0); } |
| 191 | |
| 192 | static uint32_t reset_gpe_status(void) |
| 193 | { |
| 194 | uint16_t pmbase = get_pmbase(); |
| 195 | uint32_t gpe_sts = inl((uint16_t)(pmbase + GPE0_STS(GPE_STD))); |
| 196 | outl(gpe_sts, (uint16_t)(pmbase + GPE0_STS(GPE_STD))); |
| 197 | return gpe_sts; |
| 198 | } |
| 199 | |
| 200 | static uint32_t print_gpe_sts(uint32_t gpe_sts) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 201 | { |
Elyes HAOUAS | 39303d5 | 2018-07-08 12:40:45 +0200 | [diff] [blame] | 202 | static const char *const gpe_sts_bits[] = { |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 203 | [0] = "GPIO_0", [1] = "GPIO_1", |
| 204 | [2] = "GPIO_2", [3] = "GPIO_3", |
| 205 | [4] = "GPIO_4", [5] = "GPIO_5", |
| 206 | [6] = "GPIO_6", [7] = "GPIO_7", |
| 207 | [8] = "GPIO_8", [9] = "GPIO_9", |
| 208 | [10] = "GPIO_10", [11] = "GPIO_11", |
| 209 | [12] = "GPIO_12", [13] = "GPIO_13", |
| 210 | [14] = "GPIO_14", [15] = "GPIO_15", |
| 211 | [16] = "GPIO_16", [17] = "GPIO_17", |
| 212 | [18] = "GPIO_18", [19] = "GPIO_19", |
| 213 | [20] = "GPIO_20", [21] = "GPIO_21", |
| 214 | [22] = "GPIO_22", [23] = "GPIO_23", |
| 215 | [24] = "GPIO_24", [25] = "GPIO_25", |
| 216 | [26] = "GPIO_26", [27] = "GPIO_27", |
| 217 | [28] = "GPIO_28", [29] = "GPIO_29", |
| 218 | [30] = "GPIO_30", [31] = "GPIO_31", |
| 219 | }; |
| 220 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 221 | if (!gpe_sts) |
| 222 | return gpe_sts; |
| 223 | |
| 224 | printk(BIOS_DEBUG, "GPE0a_STS: "); |
| 225 | print_num_status_bits(ARRAY_SIZE(gpe_sts_bits), gpe_sts, gpe_sts_bits); |
| 226 | printk(BIOS_DEBUG, "\n"); |
| 227 | |
| 228 | return gpe_sts; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Patrick Georgi | ff28371 | 2019-01-24 16:03:41 +0100 | [diff] [blame] | 231 | uint32_t clear_gpe_status(void) { return print_gpe_sts(reset_gpe_status()); } |
| 232 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 233 | void clear_pmc_status(void) { /* TODO */ } |