Angel Pons | 3bd1e3d | 2020-04-05 15:47:17 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Helper functions for dealing with power management registers |
| 5 | * and the differences between PCH variants. |
| 6 | */ |
| 7 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 8 | #include <acpi/acpi.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 9 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 11 | #include <device/device.h> |
| 12 | #include <device/pci.h> |
| 13 | #include <device/pci_def.h> |
| 14 | #include <console/console.h> |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 15 | #include <intelblocks/pmclib.h> |
Ravi Sarawadi | 1483d1f | 2017-09-28 17:06:01 -0700 | [diff] [blame] | 16 | #include <intelblocks/lpc_lib.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 17 | #include <intelblocks/tco.h> |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 18 | #include <soc/gpe.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 19 | #include <soc/gpio.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 20 | #include <soc/iomap.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 21 | #include <soc/pci_devs.h> |
| 22 | #include <soc/pm.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 23 | #include <soc/pmc.h> |
| 24 | #include <soc/smbus.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 25 | #include <security/vboot/vbnv.h> |
Elyes HAOUAS | add76f9 | 2019-03-21 09:55:49 +0100 | [diff] [blame] | 26 | |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 27 | #include "chip.h" |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 28 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 29 | /* |
| 30 | * SMI |
| 31 | */ |
| 32 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 33 | const char *const *soc_smi_sts_array(size_t *smi_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 34 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 35 | static const char *const smi_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 36 | [2] = "BIOS", |
| 37 | [3] = "LEGACY_USB", |
| 38 | [4] = "SLP_SMI", |
| 39 | [5] = "APM", |
| 40 | [6] = "SWSMI_TMR", |
| 41 | [8] = "PM1", |
| 42 | [9] = "GPE0", |
| 43 | [10] = "GPI", |
| 44 | [11] = "MCSMI", |
| 45 | [12] = "DEVMON", |
| 46 | [13] = "TCO", |
| 47 | [14] = "PERIODIC", |
| 48 | [15] = "SERIRQ_SMI", |
| 49 | [16] = "SMBUS_SMI", |
| 50 | [17] = "LEGACY_USB2", |
| 51 | [18] = "INTEL_USB2", |
| 52 | [20] = "PCI_EXP_SMI", |
| 53 | [21] = "MONITOR", |
| 54 | [26] = "SPI", |
Duncan Laurie | 8d01902 | 2016-10-25 19:58:27 -0700 | [diff] [blame] | 55 | [27] = "GPIO_UNLOCK", |
| 56 | [28] = "ESPI_SMI", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 59 | *smi_arr = ARRAY_SIZE(smi_sts_bits); |
| 60 | return smi_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 63 | /* |
| 64 | * TCO |
| 65 | */ |
| 66 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 67 | const char *const *soc_tco_sts_array(size_t *tco_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 68 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 69 | static const char *const tco_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 70 | [0] = "NMI2SMI", |
| 71 | [1] = "SW_TCO", |
| 72 | [2] = "TCO_INT", |
| 73 | [3] = "TIMEOUT", |
| 74 | [7] = "NEWCENTURY", |
| 75 | [8] = "BIOSWR", |
| 76 | [9] = "DMISCI", |
| 77 | [10] = "DMISMI", |
| 78 | [12] = "DMISERR", |
| 79 | [13] = "SLVSEL", |
| 80 | [16] = "INTRD_DET", |
| 81 | [17] = "SECOND_TO", |
| 82 | [18] = "BOOT", |
| 83 | [20] = "SMLINK_SLV" |
| 84 | }; |
| 85 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 86 | *tco_arr = ARRAY_SIZE(tco_sts_bits); |
| 87 | return tco_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 90 | /* |
| 91 | * GPE0 |
| 92 | */ |
| 93 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 94 | const char *const *soc_std_gpe_sts_array(size_t *gpe_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 95 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 96 | static const char *const gpe_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 97 | [1] = "HOTPLUG", |
| 98 | [2] = "SWGPE", |
| 99 | [6] = "TCO_SCI", |
| 100 | [7] = "SMB_WAK", |
| 101 | [9] = "PCI_EXP", |
| 102 | [10] = "BATLOW", |
| 103 | [11] = "PME", |
| 104 | [12] = "ME", |
| 105 | [13] = "PME_B0", |
Aaron Durbin | 7f78849 | 2015-07-24 17:10:31 -0500 | [diff] [blame] | 106 | [14] = "eSPI", |
| 107 | [15] = "GPIO Tier-2", |
| 108 | [16] = "LAN_WAKE", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 109 | [18] = "WADT" |
| 110 | }; |
| 111 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 112 | *gpe_arr = ARRAY_SIZE(gpe_sts_bits); |
| 113 | return gpe_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | int acpi_sci_irq(void) |
| 117 | { |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 118 | int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 119 | int sci_irq = 9; |
| 120 | |
| 121 | /* Determine how SCI is routed. */ |
| 122 | switch (scis) { |
| 123 | case SCIS_IRQ9: |
| 124 | case SCIS_IRQ10: |
| 125 | case SCIS_IRQ11: |
| 126 | sci_irq = scis - SCIS_IRQ9 + 9; |
| 127 | break; |
| 128 | case SCIS_IRQ20: |
| 129 | case SCIS_IRQ21: |
| 130 | case SCIS_IRQ22: |
| 131 | case SCIS_IRQ23: |
| 132 | sci_irq = scis - SCIS_IRQ20 + 20; |
| 133 | break; |
| 134 | default: |
| 135 | printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n"); |
| 136 | sci_irq = 9; |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq); |
| 141 | return sci_irq; |
| 142 | } |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 143 | |
| 144 | uint8_t *pmc_mmio_regs(void) |
| 145 | { |
| 146 | uint32_t reg32; |
| 147 | |
| 148 | reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE); |
| 149 | |
| 150 | /* 4KiB alignment. */ |
| 151 | reg32 &= ~0xfff; |
| 152 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 153 | return (void *)(uintptr_t) reg32; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 156 | uintptr_t soc_read_pmc_base(void) |
| 157 | { |
| 158 | return (uintptr_t) (pmc_mmio_regs()); |
| 159 | } |
| 160 | |
Michael Niewöhner | 35e76dd | 2019-11-02 12:14:06 +0100 | [diff] [blame] | 161 | uint32_t *soc_pmc_etr_addr(void) |
| 162 | { |
| 163 | /* |
| 164 | * The pointer returned must not be cached, because the address depends on the |
| 165 | * MMCONF base address and the assigned PCI bus number, which both may change |
| 166 | * during the boot process! |
| 167 | */ |
| 168 | return pci_mmio_config32_addr(PCH_DEVFN_PMC << 12, ETR); |
| 169 | } |
| 170 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 171 | void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2) |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 172 | { |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 173 | DEVTREE_CONST struct soc_intel_skylake_config *config; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 174 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 175 | config = config_of_soc(); |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 176 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 177 | /* Assign to out variable */ |
| 178 | *dw0 = config->gpe0_dw0; |
| 179 | *dw1 = config->gpe0_dw1; |
| 180 | *dw2 = config->gpe0_dw2; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 181 | } |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 182 | |
| 183 | int rtc_failure(void) |
| 184 | { |
| 185 | u8 reg8; |
| 186 | int rtc_failed; |
| 187 | /* PMC Controller Device 0x1F, Func 02 */ |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 188 | #if defined(__SIMPLE_DEVICE__) |
| 189 | pci_devfn_t dev = PCH_DEV_PMC; |
| 190 | #else |
| 191 | struct device *dev = PCH_DEV_PMC; |
| 192 | #endif |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 193 | reg8 = pci_read_config8(dev, GEN_PMCON_B); |
| 194 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 195 | if (rtc_failed) { |
| 196 | reg8 &= ~RTC_BATTERY_DEAD; |
| 197 | pci_write_config8(dev, GEN_PMCON_B, reg8); |
| 198 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 199 | } |
| 200 | |
| 201 | return !!rtc_failed; |
| 202 | } |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 203 | |
| 204 | int vbnv_cmos_failed(void) |
| 205 | { |
| 206 | return rtc_failure(); |
| 207 | } |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 208 | |
| 209 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
| 210 | int soc_prev_sleep_state(const struct chipset_power_state *ps, |
| 211 | int prev_sleep_state) |
| 212 | { |
| 213 | /* |
| 214 | * Check for any power failure to determine if this a wake from |
| 215 | * S5 because the PCH does not set the WAK_STS bit when waking |
| 216 | * from a true G3 state. |
| 217 | */ |
| 218 | if (!(ps->pm1_sts & WAK_STS) && |
| 219 | (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR))) |
| 220 | prev_sleep_state = ACPI_S5; |
| 221 | |
| 222 | /* |
| 223 | * If waking from S3 determine if deep S3 is enabled. If not, |
| 224 | * need to check both deep sleep well and normal suspend well. |
| 225 | * Otherwise just check deep sleep well. |
| 226 | */ |
| 227 | if (prev_sleep_state == ACPI_S3) { |
| 228 | /* PWR_FLR represents deep sleep power well loss. */ |
| 229 | uint32_t mask = PWR_FLR; |
| 230 | |
| 231 | /* If deep s3 isn't enabled check the suspend well too. */ |
| 232 | if (!deep_s3_enabled()) |
| 233 | mask |= SUS_PWR_FLR; |
| 234 | |
| 235 | if (ps->gen_pmcon_b & mask) |
| 236 | prev_sleep_state = ACPI_S5; |
| 237 | } |
| 238 | return prev_sleep_state; |
| 239 | } |
| 240 | |
| 241 | void soc_fill_power_state(struct chipset_power_state *ps) |
| 242 | { |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 243 | uint8_t *pmc; |
| 244 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 245 | ps->tco1_sts = tco_read_reg(TCO1_STS); |
| 246 | ps->tco2_sts = tco_read_reg(TCO2_STS); |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 247 | |
| 248 | printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n", |
| 249 | ps->tco1_sts, ps->tco2_sts); |
| 250 | |
| 251 | ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A); |
| 252 | ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B); |
| 253 | |
| 254 | pmc = pmc_mmio_regs(); |
| 255 | ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0); |
| 256 | ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1); |
| 257 | |
| 258 | printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n", |
| 259 | ps->gen_pmcon_a, ps->gen_pmcon_b); |
| 260 | |
| 261 | printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n", |
| 262 | ps->gblrst_cause[0], ps->gblrst_cause[1]); |
| 263 | } |
Eugene Myers | ebc8423 | 2020-01-21 16:46:16 -0500 | [diff] [blame] | 264 | |
| 265 | /* STM Support */ |
| 266 | uint16_t get_pmbase(void) |
| 267 | { |
| 268 | return ACPI_BASE_ADDRESS; |
| 269 | } |