Angel Pons | 16f6aa8 | 2020-04-05 15:47:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Helper functions for dealing with power management registers |
| 5 | * and the differences between PCH variants. |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This file is created based on Intel Tiger Lake Processor PCH Datasheet |
| 10 | * Document number: 575857 |
| 11 | * Chapter number: 4 |
| 12 | */ |
| 13 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 14 | #define __SIMPLE_DEVICE__ |
| 15 | |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 16 | #include <acpi/acpi_pm.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 17 | #include <device/mmio.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_def.h> |
| 21 | #include <console/console.h> |
| 22 | #include <intelblocks/pmclib.h> |
| 23 | #include <intelblocks/rtc.h> |
| 24 | #include <intelblocks/tco.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 25 | #include <soc/espi.h> |
| 26 | #include <soc/gpe.h> |
| 27 | #include <soc/gpio.h> |
| 28 | #include <soc/iomap.h> |
| 29 | #include <soc/pci_devs.h> |
| 30 | #include <soc/pm.h> |
| 31 | #include <soc/smbus.h> |
| 32 | #include <soc/soc_chip.h> |
| 33 | #include <security/vboot/vbnv.h> |
| 34 | |
| 35 | /* |
| 36 | * SMI |
| 37 | */ |
| 38 | |
| 39 | const char *const *soc_smi_sts_array(size_t *a) |
| 40 | { |
| 41 | static const char *const smi_sts_bits[] = { |
| 42 | [BIOS_STS_BIT] = "BIOS", |
| 43 | [LEGACY_USB_STS_BIT] = "LEGACY_USB", |
| 44 | [SMI_ON_SLP_EN_STS_BIT] = "SLP_SMI", |
| 45 | [APM_STS_BIT] = "APM", |
| 46 | [SWSMI_TMR_STS_BIT] = "SWSMI_TMR", |
| 47 | [PM1_STS_BIT] = "PM1", |
| 48 | [GPE0_STS_BIT] = "GPE0", |
| 49 | [GPIO_STS_BIT] = "GPI", |
| 50 | [MCSMI_STS_BIT] = "MCSMI", |
| 51 | [DEVMON_STS_BIT] = "DEVMON", |
| 52 | [TCO_STS_BIT] = "TCO", |
| 53 | [PERIODIC_STS_BIT] = "PERIODIC", |
| 54 | [SERIRQ_SMI_STS_BIT] = "SERIRQ_SMI", |
| 55 | [SMBUS_SMI_STS_BIT] = "SMBUS_SMI", |
| 56 | [PCI_EXP_SMI_STS_BIT] = "PCI_EXP_SMI", |
| 57 | [MONITOR_STS_BIT] = "MONITOR", |
| 58 | [SPI_SMI_STS_BIT] = "SPI", |
| 59 | [GPIO_UNLOCK_SMI_STS_BIT] = "GPIO_UNLOCK", |
| 60 | [ESPI_SMI_STS_BIT] = "ESPI_SMI", |
| 61 | }; |
| 62 | |
| 63 | *a = ARRAY_SIZE(smi_sts_bits); |
| 64 | return smi_sts_bits; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * TCO |
| 69 | */ |
| 70 | |
| 71 | const char *const *soc_tco_sts_array(size_t *a) |
| 72 | { |
| 73 | static const char *const tco_sts_bits[] = { |
| 74 | [0] = "NMI2SMI", |
| 75 | [1] = "SW_TCO", |
| 76 | [2] = "TCO_INT", |
| 77 | [3] = "TIMEOUT", |
| 78 | [7] = "NEWCENTURY", |
| 79 | [8] = "BIOSWR", |
| 80 | [9] = "DMISCI", |
| 81 | [10] = "DMISMI", |
| 82 | [12] = "DMISERR", |
| 83 | [13] = "SLVSEL", |
| 84 | [16] = "INTRD_DET", |
| 85 | [17] = "SECOND_TO", |
| 86 | [18] = "BOOT", |
| 87 | [20] = "SMLINK_SLV" |
| 88 | }; |
| 89 | |
| 90 | *a = ARRAY_SIZE(tco_sts_bits); |
| 91 | return tco_sts_bits; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * GPE0 |
| 96 | */ |
| 97 | |
| 98 | const char *const *soc_std_gpe_sts_array(size_t *a) |
| 99 | { |
| 100 | static const char *const gpe_sts_bits[] = { |
| 101 | [1] = "HOTPLUG", |
| 102 | [2] = "SWGPE", |
| 103 | [6] = "TCO_SCI", |
| 104 | [7] = "SMB_WAK", |
| 105 | [9] = "PCI_EXP", |
| 106 | [10] = "BATLOW", |
| 107 | [11] = "PME", |
| 108 | [12] = "ME", |
| 109 | [13] = "PME_B0", |
| 110 | [14] = "eSPI", |
| 111 | [15] = "GPIO Tier-2", |
| 112 | [16] = "LAN_WAKE", |
| 113 | [18] = "WADT" |
| 114 | }; |
| 115 | |
| 116 | *a = ARRAY_SIZE(gpe_sts_bits); |
| 117 | return gpe_sts_bits; |
| 118 | } |
| 119 | |
| 120 | void pmc_set_disb(void) |
| 121 | { |
| 122 | /* Set the DISB after DRAM init */ |
| 123 | uint8_t disb_val; |
| 124 | /* Only care about bits [23:16] of register GEN_PMCON_A */ |
| 125 | uint8_t *addr = (uint8_t *)(pmc_mmio_regs() + GEN_PMCON_A + 2); |
| 126 | |
| 127 | disb_val = read8(addr); |
| 128 | disb_val |= (DISB >> 16); |
| 129 | |
| 130 | /* Don't clear bits that are write-1-to-clear */ |
| 131 | disb_val &= ~((MS4V | SUS_PWR_FLR) >> 16); |
| 132 | write8(addr, disb_val); |
| 133 | } |
| 134 | |
| 135 | void pmc_clear_pmcon_sts(void) |
| 136 | { |
| 137 | uint32_t reg_val; |
| 138 | uint8_t *addr; |
| 139 | addr = pmc_mmio_regs(); |
| 140 | |
| 141 | reg_val = read32(addr + GEN_PMCON_A); |
| 142 | /* Clear SUS_PWR_FLR, GBL_RST_STS, HOST_RST_STS, PWR_FLR bits |
| 143 | * while retaining MS4V write-1-to-clear bit */ |
| 144 | reg_val &= ~(MS4V); |
| 145 | |
| 146 | write32((addr + GEN_PMCON_A), reg_val); |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * PMC controller gets hidden from PCI bus |
| 151 | * during FSP-Silicon init call. Hence PWRMBASE |
| 152 | * can't be accessible using PCI configuration space |
| 153 | * read/write. |
| 154 | */ |
| 155 | uint8_t *pmc_mmio_regs(void) |
| 156 | { |
| 157 | return (void *)(uintptr_t)PCH_PWRM_BASE_ADDRESS; |
| 158 | } |
| 159 | |
| 160 | uintptr_t soc_read_pmc_base(void) |
| 161 | { |
| 162 | return (uintptr_t)pmc_mmio_regs(); |
| 163 | } |
| 164 | |
Aamir Bohra | e0cdaf0 | 2019-12-06 19:37:37 +0530 | [diff] [blame] | 165 | uint32_t *soc_pmc_etr_addr(void) |
| 166 | { |
| 167 | return (uint32_t *)(soc_read_pmc_base() + ETR); |
| 168 | } |
| 169 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 170 | void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2) |
| 171 | { |
| 172 | DEVTREE_CONST struct soc_intel_tigerlake_config *config; |
| 173 | |
| 174 | config = config_of_soc(); |
| 175 | |
| 176 | /* Assign to out variable */ |
Ravi Sarawadi | 2fd4972 | 2019-12-16 23:41:36 -0800 | [diff] [blame] | 177 | *dw0 = config->pmc_gpe0_dw0; |
| 178 | *dw1 = config->pmc_gpe0_dw1; |
| 179 | *dw2 = config->pmc_gpe0_dw2; |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static int rtc_failed(uint32_t gen_pmcon_b) |
| 183 | { |
| 184 | return !!(gen_pmcon_b & RTC_BATTERY_DEAD); |
| 185 | } |
| 186 | |
Tim Wawrzynczak | e186821 | 2021-07-28 11:30:59 -0600 | [diff] [blame] | 187 | static void clear_rtc_failed(void) |
| 188 | { |
| 189 | clrbits8(pmc_mmio_regs() + GEN_PMCON_B, RTC_BATTERY_DEAD); |
| 190 | } |
| 191 | |
| 192 | static int check_rtc_failed(uint32_t gen_pmcon_b) |
| 193 | { |
| 194 | const int failed = rtc_failed(gen_pmcon_b); |
| 195 | if (failed) { |
| 196 | clear_rtc_failed(); |
| 197 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", failed); |
| 198 | } |
| 199 | |
| 200 | return failed; |
| 201 | } |
| 202 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 203 | int soc_get_rtc_failed(void) |
| 204 | { |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 205 | const struct chipset_power_state *ps; |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 206 | |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 207 | if (acpi_pm_state_for_rtc(&ps) < 0) |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 208 | return 1; |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 209 | |
Tim Wawrzynczak | e186821 | 2021-07-28 11:30:59 -0600 | [diff] [blame] | 210 | return check_rtc_failed(ps->gen_pmcon_b); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | int vbnv_cmos_failed(void) |
| 214 | { |
Tim Wawrzynczak | e186821 | 2021-07-28 11:30:59 -0600 | [diff] [blame] | 215 | return check_rtc_failed(read32(pmc_mmio_regs() + GEN_PMCON_B)); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static inline int deep_s3_enabled(void) |
| 219 | { |
| 220 | uint32_t deep_s3_pol; |
| 221 | |
| 222 | deep_s3_pol = read32(pmc_mmio_regs() + S3_PWRGATE_POL); |
| 223 | return !!(deep_s3_pol & (S3DC_GATE_SUS | S3AC_GATE_SUS)); |
| 224 | } |
| 225 | |
| 226 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
Angel Pons | f5d090d | 2021-02-19 17:49:00 +0100 | [diff] [blame] | 227 | int soc_prev_sleep_state(const struct chipset_power_state *ps, int prev_sleep_state) |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 228 | { |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 229 | /* |
| 230 | * Check for any power failure to determine if this a wake from |
Angel Pons | f5d090d | 2021-02-19 17:49:00 +0100 | [diff] [blame] | 231 | * S5 because the PCH does not set the WAK_STS bit when waking |
| 232 | * from a true G3 state. |
| 233 | */ |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 234 | if (ps->gen_pmcon_a & (PWR_FLR | SUS_PWR_FLR)) |
| 235 | prev_sleep_state = ACPI_S5; |
| 236 | |
| 237 | /* |
| 238 | * If waking from S3 determine if deep S3 is enabled. If not, |
| 239 | * need to check both deep sleep well and normal suspend well. |
| 240 | * Otherwise just check deep sleep well. |
| 241 | */ |
| 242 | if (prev_sleep_state == ACPI_S3) { |
| 243 | /* PWR_FLR represents deep sleep power well loss. */ |
| 244 | uint32_t mask = PWR_FLR; |
| 245 | |
| 246 | /* If deep s3 isn't enabled check the suspend well too. */ |
| 247 | if (!deep_s3_enabled()) |
| 248 | mask |= SUS_PWR_FLR; |
| 249 | |
| 250 | if (ps->gen_pmcon_a & mask) |
| 251 | prev_sleep_state = ACPI_S5; |
| 252 | } |
| 253 | |
| 254 | return prev_sleep_state; |
| 255 | } |
| 256 | |
| 257 | void soc_fill_power_state(struct chipset_power_state *ps) |
| 258 | { |
| 259 | uint8_t *pmc; |
| 260 | |
| 261 | ps->tco1_sts = tco_read_reg(TCO1_STS); |
| 262 | ps->tco2_sts = tco_read_reg(TCO2_STS); |
| 263 | |
Angel Pons | f5d090d | 2021-02-19 17:49:00 +0100 | [diff] [blame] | 264 | printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n", ps->tco1_sts, ps->tco2_sts); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 265 | |
| 266 | pmc = pmc_mmio_regs(); |
| 267 | ps->gen_pmcon_a = read32(pmc + GEN_PMCON_A); |
| 268 | ps->gen_pmcon_b = read32(pmc + GEN_PMCON_B); |
| 269 | ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0); |
| 270 | ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1); |
derek.huang | e685107 | 2020-04-23 14:55:24 +0800 | [diff] [blame] | 271 | ps->hpr_cause0 = read32(pmc + HPR_CAUSE0); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 272 | |
| 273 | printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n", |
| 274 | ps->gen_pmcon_a, ps->gen_pmcon_b); |
| 275 | |
| 276 | printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n", |
| 277 | ps->gblrst_cause[0], ps->gblrst_cause[1]); |
derek.huang | e685107 | 2020-04-23 14:55:24 +0800 | [diff] [blame] | 278 | |
| 279 | printk(BIOS_DEBUG, "HPR_CAUSE0: %08x\n", ps->hpr_cause0); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 280 | } |
Eugene Myers | ebc8423 | 2020-01-21 16:46:16 -0500 | [diff] [blame] | 281 | |
| 282 | /* STM Support */ |
| 283 | uint16_t get_pmbase(void) |
| 284 | { |
| 285 | return (uint16_t) ACPI_BASE_ADDRESS; |
| 286 | } |
Tim Wawrzynczak | 2c26108 | 2020-05-14 13:24:21 -0600 | [diff] [blame] | 287 | |
| 288 | /* |
| 289 | * Set which power state system will be after reapplying |
| 290 | * the power (from G3 State) |
| 291 | */ |
| 292 | void pmc_soc_set_afterg3_en(const bool on) |
| 293 | { |
| 294 | uint8_t reg8; |
| 295 | uint8_t *const pmcbase = pmc_mmio_regs(); |
| 296 | |
| 297 | reg8 = read8(pmcbase + GEN_PMCON_A); |
| 298 | if (on) |
| 299 | reg8 &= ~SLEEP_AFTER_POWER_FAIL; |
| 300 | else |
| 301 | reg8 |= SLEEP_AFTER_POWER_FAIL; |
| 302 | write8(pmcbase + GEN_PMCON_A, reg8); |
| 303 | } |