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 | |
Angel Pons | a15a604 | 2021-02-19 17:34:26 +0100 | [diff] [blame] | 8 | #define __SIMPLE_DEVICE__ |
| 9 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 11 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 12 | #include <device/pci_ops.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 13 | #include <device/device.h> |
| 14 | #include <device/pci.h> |
| 15 | #include <device/pci_def.h> |
| 16 | #include <console/console.h> |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 17 | #include <intelblocks/pmclib.h> |
Ravi Sarawadi | 1483d1f | 2017-09-28 17:06:01 -0700 | [diff] [blame] | 18 | #include <intelblocks/lpc_lib.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 19 | #include <intelblocks/tco.h> |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 20 | #include <soc/gpe.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 21 | #include <soc/gpio.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 22 | #include <soc/iomap.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 23 | #include <soc/pci_devs.h> |
| 24 | #include <soc/pm.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 25 | #include <soc/pmc.h> |
| 26 | #include <soc/smbus.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 27 | #include <security/vboot/vbnv.h> |
Elyes HAOUAS | add76f9 | 2019-03-21 09:55:49 +0100 | [diff] [blame] | 28 | |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 29 | #include "chip.h" |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 30 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 31 | /* |
| 32 | * SMI |
| 33 | */ |
| 34 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 35 | const char *const *soc_smi_sts_array(size_t *smi_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 36 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 37 | static const char *const smi_sts_bits[] = { |
Angel Pons | df8462c | 2021-02-19 16:35:45 +0100 | [diff] [blame] | 38 | [BIOS_STS_BIT] = "BIOS", |
| 39 | [LEGACY_USB_STS_BIT] = "LEGACY_USB", |
| 40 | [SMI_ON_SLP_EN_STS_BIT] = "SLP_SMI", |
| 41 | [APM_STS_BIT] = "APM", |
| 42 | [SWSMI_TMR_STS_BIT] = "SWSMI_TMR", |
| 43 | [PM1_STS_BIT] = "PM1", |
| 44 | [GPE0_STS_BIT] = "GPE0", |
| 45 | [GPIO_STS_BIT] = "GPI", |
| 46 | [MCSMI_STS_BIT] = "MCSMI", |
| 47 | [DEVMON_STS_BIT] = "DEVMON", |
| 48 | [TCO_STS_BIT] = "TCO", |
| 49 | [PERIODIC_STS_BIT] = "PERIODIC", |
| 50 | [SERIRQ_SMI_STS_BIT] = "SERIRQ_SMI", |
| 51 | [SMBUS_SMI_STS_BIT] = "SMBUS_SMI", |
| 52 | [PCI_EXP_SMI_STS_BIT] = "PCI_EXP_SMI", |
| 53 | [MONITOR_STS_BIT] = "MONITOR", |
| 54 | [SPI_SMI_STS_BIT] = "SPI", |
| 55 | [GPIO_UNLOCK_SMI_STS_BIT] = "GPIO_UNLOCK", |
| 56 | [ESPI_SMI_STS_BIT] = "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 | |
Angel Pons | f643b63 | 2021-04-17 12:55:59 +0200 | [diff] [blame] | 116 | void pmc_set_disb(void) |
| 117 | { |
| 118 | /* Set the DISB after DRAM init */ |
| 119 | u32 disb_val; |
| 120 | const pci_devfn_t dev = PCH_DEV_PMC; |
| 121 | |
| 122 | disb_val = pci_read_config32(dev, GEN_PMCON_A); |
| 123 | disb_val |= DISB; |
| 124 | |
| 125 | /* Don't clear bits that are write-1-to-clear */ |
| 126 | disb_val &= ~(GBL_RST_STS | MS4V); |
| 127 | pci_write_config32(dev, GEN_PMCON_A, disb_val); |
| 128 | } |
| 129 | |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 130 | uint8_t *pmc_mmio_regs(void) |
| 131 | { |
| 132 | uint32_t reg32; |
| 133 | |
| 134 | reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE); |
| 135 | |
| 136 | /* 4KiB alignment. */ |
| 137 | reg32 &= ~0xfff; |
| 138 | |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 139 | return (void *)(uintptr_t)reg32; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 142 | uintptr_t soc_read_pmc_base(void) |
| 143 | { |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 144 | return (uintptr_t)(pmc_mmio_regs()); |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Michael Niewöhner | 35e76dd | 2019-11-02 12:14:06 +0100 | [diff] [blame] | 147 | uint32_t *soc_pmc_etr_addr(void) |
| 148 | { |
| 149 | /* |
| 150 | * The pointer returned must not be cached, because the address depends on the |
| 151 | * MMCONF base address and the assigned PCI bus number, which both may change |
| 152 | * during the boot process! |
| 153 | */ |
| 154 | return pci_mmio_config32_addr(PCH_DEVFN_PMC << 12, ETR); |
| 155 | } |
| 156 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 157 | 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] | 158 | { |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 159 | DEVTREE_CONST struct soc_intel_skylake_config *config; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 160 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 161 | config = config_of_soc(); |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 162 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 163 | /* Assign to out variable */ |
| 164 | *dw0 = config->gpe0_dw0; |
| 165 | *dw1 = config->gpe0_dw1; |
| 166 | *dw2 = config->gpe0_dw2; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 167 | } |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 168 | |
| 169 | int rtc_failure(void) |
| 170 | { |
| 171 | u8 reg8; |
| 172 | int rtc_failed; |
| 173 | /* PMC Controller Device 0x1F, Func 02 */ |
Angel Pons | a15a604 | 2021-02-19 17:34:26 +0100 | [diff] [blame] | 174 | const pci_devfn_t dev = PCH_DEV_PMC; |
| 175 | |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 176 | reg8 = pci_read_config8(dev, GEN_PMCON_B); |
| 177 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 178 | if (rtc_failed) { |
| 179 | reg8 &= ~RTC_BATTERY_DEAD; |
| 180 | pci_write_config8(dev, GEN_PMCON_B, reg8); |
| 181 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 182 | } |
| 183 | |
| 184 | return !!rtc_failed; |
| 185 | } |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 186 | |
| 187 | int vbnv_cmos_failed(void) |
| 188 | { |
| 189 | return rtc_failure(); |
| 190 | } |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 191 | |
| 192 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
Angel Pons | f5d090d | 2021-02-19 17:49:00 +0100 | [diff] [blame] | 193 | int soc_prev_sleep_state(const struct chipset_power_state *ps, int prev_sleep_state) |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 194 | { |
| 195 | /* |
| 196 | * Check for any power failure to determine if this a wake from |
| 197 | * S5 because the PCH does not set the WAK_STS bit when waking |
| 198 | * from a true G3 state. |
| 199 | */ |
| 200 | if (!(ps->pm1_sts & WAK_STS) && |
| 201 | (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR))) |
| 202 | prev_sleep_state = ACPI_S5; |
| 203 | |
| 204 | /* |
| 205 | * If waking from S3 determine if deep S3 is enabled. If not, |
| 206 | * need to check both deep sleep well and normal suspend well. |
| 207 | * Otherwise just check deep sleep well. |
| 208 | */ |
| 209 | if (prev_sleep_state == ACPI_S3) { |
| 210 | /* PWR_FLR represents deep sleep power well loss. */ |
| 211 | uint32_t mask = PWR_FLR; |
| 212 | |
| 213 | /* If deep s3 isn't enabled check the suspend well too. */ |
| 214 | if (!deep_s3_enabled()) |
| 215 | mask |= SUS_PWR_FLR; |
| 216 | |
| 217 | if (ps->gen_pmcon_b & mask) |
| 218 | prev_sleep_state = ACPI_S5; |
| 219 | } |
| 220 | return prev_sleep_state; |
| 221 | } |
| 222 | |
| 223 | void soc_fill_power_state(struct chipset_power_state *ps) |
| 224 | { |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 225 | uint8_t *pmc; |
| 226 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 227 | ps->tco1_sts = tco_read_reg(TCO1_STS); |
| 228 | ps->tco2_sts = tco_read_reg(TCO2_STS); |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 229 | |
Angel Pons | f5d090d | 2021-02-19 17:49:00 +0100 | [diff] [blame] | 230 | printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n", ps->tco1_sts, ps->tco2_sts); |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 231 | |
| 232 | ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A); |
| 233 | ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B); |
| 234 | |
| 235 | pmc = pmc_mmio_regs(); |
| 236 | ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0); |
| 237 | ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1); |
| 238 | |
| 239 | printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n", |
| 240 | ps->gen_pmcon_a, ps->gen_pmcon_b); |
| 241 | |
| 242 | printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n", |
| 243 | ps->gblrst_cause[0], ps->gblrst_cause[1]); |
| 244 | } |
Eugene Myers | ebc8423 | 2020-01-21 16:46:16 -0500 | [diff] [blame] | 245 | |
| 246 | /* STM Support */ |
| 247 | uint16_t get_pmbase(void) |
| 248 | { |
| 249 | return ACPI_BASE_ADDRESS; |
| 250 | } |
Angel Pons | 505e383 | 2021-04-17 13:02:37 +0200 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * Set which power state system will be after reapplying |
| 254 | * the power (from G3 State) |
| 255 | */ |
| 256 | void pmc_soc_set_afterg3_en(const bool on) |
| 257 | { |
| 258 | uint8_t reg8; |
| 259 | const pci_devfn_t dev = PCH_DEV_PMC; |
| 260 | |
| 261 | reg8 = pci_read_config8(dev, GEN_PMCON_B); |
| 262 | if (on) |
| 263 | reg8 &= ~SLEEP_AFTER_POWER_FAIL; |
| 264 | else |
| 265 | reg8 |= SLEEP_AFTER_POWER_FAIL; |
| 266 | pci_write_config8(dev, GEN_PMCON_B, reg8); |
| 267 | } |