Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corporation. |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Helper functions for dealing with power management registers |
| 19 | * and the differences between PCH variants. |
| 20 | */ |
| 21 | |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 22 | #define __SIMPLE_DEVICE__ |
| 23 | |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame^] | 24 | #include <arch/acpi.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 25 | #include <arch/io.h> |
| 26 | #include <device/device.h> |
| 27 | #include <device/pci.h> |
| 28 | #include <device/pci_def.h> |
| 29 | #include <console/console.h> |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 30 | #include <intelblocks/pmclib.h> |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 31 | #include <halt.h> |
Ravi Sarawadi | 1483d1f | 2017-09-28 17:06:01 -0700 | [diff] [blame] | 32 | #include <intelblocks/lpc_lib.h> |
Furquan Shaikh | 97e0a65 | 2016-08-18 21:42:36 -0700 | [diff] [blame] | 33 | #include <rules.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 34 | #include <stdlib.h> |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 35 | #include <soc/gpe.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 36 | #include <soc/gpio.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 37 | #include <soc/iomap.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 38 | #include <soc/pci_devs.h> |
| 39 | #include <soc/pm.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 40 | #include <soc/pmc.h> |
| 41 | #include <soc/smbus.h> |
Duncan Laurie | 2f3736e | 2016-11-03 10:33:43 -0700 | [diff] [blame] | 42 | #include <timer.h> |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 43 | #include <vboot/vbnv.h> |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 44 | #include "chip.h" |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 45 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 46 | /* |
| 47 | * SMI |
| 48 | */ |
| 49 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 50 | const char *const *soc_smi_sts_array(size_t *smi_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 51 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 52 | static const char *const smi_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 53 | [2] = "BIOS", |
| 54 | [3] = "LEGACY_USB", |
| 55 | [4] = "SLP_SMI", |
| 56 | [5] = "APM", |
| 57 | [6] = "SWSMI_TMR", |
| 58 | [8] = "PM1", |
| 59 | [9] = "GPE0", |
| 60 | [10] = "GPI", |
| 61 | [11] = "MCSMI", |
| 62 | [12] = "DEVMON", |
| 63 | [13] = "TCO", |
| 64 | [14] = "PERIODIC", |
| 65 | [15] = "SERIRQ_SMI", |
| 66 | [16] = "SMBUS_SMI", |
| 67 | [17] = "LEGACY_USB2", |
| 68 | [18] = "INTEL_USB2", |
| 69 | [20] = "PCI_EXP_SMI", |
| 70 | [21] = "MONITOR", |
| 71 | [26] = "SPI", |
Duncan Laurie | 8d01902 | 2016-10-25 19:58:27 -0700 | [diff] [blame] | 72 | [27] = "GPIO_UNLOCK", |
| 73 | [28] = "ESPI_SMI", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 76 | *smi_arr = ARRAY_SIZE(smi_sts_bits); |
| 77 | return smi_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 80 | /* |
| 81 | * TCO |
| 82 | */ |
| 83 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 84 | const char *const *soc_tco_sts_array(size_t *tco_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 85 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 86 | static const char *const tco_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 87 | [0] = "NMI2SMI", |
| 88 | [1] = "SW_TCO", |
| 89 | [2] = "TCO_INT", |
| 90 | [3] = "TIMEOUT", |
| 91 | [7] = "NEWCENTURY", |
| 92 | [8] = "BIOSWR", |
| 93 | [9] = "DMISCI", |
| 94 | [10] = "DMISMI", |
| 95 | [12] = "DMISERR", |
| 96 | [13] = "SLVSEL", |
| 97 | [16] = "INTRD_DET", |
| 98 | [17] = "SECOND_TO", |
| 99 | [18] = "BOOT", |
| 100 | [20] = "SMLINK_SLV" |
| 101 | }; |
| 102 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 103 | *tco_arr = ARRAY_SIZE(tco_sts_bits); |
| 104 | return tco_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 107 | /* |
| 108 | * GPE0 |
| 109 | */ |
| 110 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 111 | const char *const *soc_std_gpe_sts_array(size_t *gpe_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 112 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 113 | static const char *const gpe_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 114 | [1] = "HOTPLUG", |
| 115 | [2] = "SWGPE", |
| 116 | [6] = "TCO_SCI", |
| 117 | [7] = "SMB_WAK", |
| 118 | [9] = "PCI_EXP", |
| 119 | [10] = "BATLOW", |
| 120 | [11] = "PME", |
| 121 | [12] = "ME", |
| 122 | [13] = "PME_B0", |
Aaron Durbin | 7f78849 | 2015-07-24 17:10:31 -0500 | [diff] [blame] | 123 | [14] = "eSPI", |
| 124 | [15] = "GPIO Tier-2", |
| 125 | [16] = "LAN_WAKE", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 126 | [18] = "WADT" |
| 127 | }; |
| 128 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 129 | *gpe_arr = ARRAY_SIZE(gpe_sts_bits); |
| 130 | return gpe_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | int acpi_sci_irq(void) |
| 134 | { |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 135 | int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 136 | int sci_irq = 9; |
| 137 | |
| 138 | /* Determine how SCI is routed. */ |
| 139 | switch (scis) { |
| 140 | case SCIS_IRQ9: |
| 141 | case SCIS_IRQ10: |
| 142 | case SCIS_IRQ11: |
| 143 | sci_irq = scis - SCIS_IRQ9 + 9; |
| 144 | break; |
| 145 | case SCIS_IRQ20: |
| 146 | case SCIS_IRQ21: |
| 147 | case SCIS_IRQ22: |
| 148 | case SCIS_IRQ23: |
| 149 | sci_irq = scis - SCIS_IRQ20 + 20; |
| 150 | break; |
| 151 | default: |
| 152 | printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n"); |
| 153 | sci_irq = 9; |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq); |
| 158 | return sci_irq; |
| 159 | } |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 160 | |
| 161 | uint8_t *pmc_mmio_regs(void) |
| 162 | { |
| 163 | uint32_t reg32; |
| 164 | |
| 165 | reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE); |
| 166 | |
| 167 | /* 4KiB alignment. */ |
| 168 | reg32 &= ~0xfff; |
| 169 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 170 | return (void *)(uintptr_t) reg32; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Barnali Sarkar | 49eca13 | 2016-08-12 00:05:27 +0530 | [diff] [blame] | 173 | uint16_t smbus_tco_regs(void) |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 174 | { |
| 175 | uint16_t reg16; |
| 176 | |
| 177 | reg16 = pci_read_config16(PCH_DEV_SMBUS, TCOBASE); |
| 178 | |
| 179 | reg16 &= ~0x1f; |
| 180 | |
| 181 | return reg16; |
| 182 | } |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 183 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 184 | uint32_t soc_reset_tco_status(void) |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 185 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 186 | u16 tco1_sts; |
| 187 | u16 tco2_sts; |
| 188 | u16 tcobase; |
Furquan Shaikh | 97e0a65 | 2016-08-18 21:42:36 -0700 | [diff] [blame] | 189 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 190 | tcobase = smbus_tco_regs(); |
| 191 | |
| 192 | /* TCO Status 2 register */ |
| 193 | tco2_sts = inw(tcobase + TCO2_STS); |
| 194 | tco2_sts |= (TCO2_STS_SECOND_TO | TCO2_STS_BOOT); |
| 195 | outw(tco2_sts, tcobase + TCO2_STS); |
| 196 | |
| 197 | /* TCO Status 1 register */ |
| 198 | tco1_sts = inw(tcobase + TCO1_STS); |
| 199 | |
| 200 | /* Clear SECOND_TO_STS bit */ |
| 201 | if (tco2_sts & TCO2_STS_SECOND_TO) |
| 202 | outw(tco2_sts & ~TCO2_STS_SECOND_TO, tcobase + TCO2_STS); |
| 203 | |
| 204 | return (tco2_sts << 16) | tco1_sts; |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 205 | } |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 206 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 207 | uintptr_t soc_read_pmc_base(void) |
| 208 | { |
| 209 | return (uintptr_t) (pmc_mmio_regs()); |
| 210 | } |
| 211 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 212 | 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] | 213 | { |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 214 | DEVTREE_CONST struct soc_intel_skylake_config *config; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 215 | |
| 216 | /* Look up the device in devicetree */ |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 217 | DEVTREE_CONST struct device *dev = dev_find_slot(0, PCH_DEVFN_PMC); |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 218 | if (!dev || !dev->chip_info) { |
| 219 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
Shaunak Saha | ec1a24c | 2017-10-06 12:50:38 -0700 | [diff] [blame] | 220 | return; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 221 | } |
| 222 | config = dev->chip_info; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 223 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 224 | /* Assign to out variable */ |
| 225 | *dw0 = config->gpe0_dw0; |
| 226 | *dw1 = config->gpe0_dw1; |
| 227 | *dw2 = config->gpe0_dw2; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 228 | } |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 229 | |
| 230 | int rtc_failure(void) |
| 231 | { |
| 232 | u8 reg8; |
| 233 | int rtc_failed; |
| 234 | /* PMC Controller Device 0x1F, Func 02 */ |
| 235 | device_t dev = PCH_DEV_PMC; |
| 236 | reg8 = pci_read_config8(dev, GEN_PMCON_B); |
| 237 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 238 | if (rtc_failed) { |
| 239 | reg8 &= ~RTC_BATTERY_DEAD; |
| 240 | pci_write_config8(dev, GEN_PMCON_B, reg8); |
| 241 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 242 | } |
| 243 | |
| 244 | return !!rtc_failed; |
| 245 | } |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 246 | |
| 247 | int vbnv_cmos_failed(void) |
| 248 | { |
| 249 | return rtc_failure(); |
| 250 | } |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame^] | 251 | |
| 252 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
| 253 | int soc_prev_sleep_state(const struct chipset_power_state *ps, |
| 254 | int prev_sleep_state) |
| 255 | { |
| 256 | /* |
| 257 | * Check for any power failure to determine if this a wake from |
| 258 | * S5 because the PCH does not set the WAK_STS bit when waking |
| 259 | * from a true G3 state. |
| 260 | */ |
| 261 | if (!(ps->pm1_sts & WAK_STS) && |
| 262 | (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR))) |
| 263 | prev_sleep_state = ACPI_S5; |
| 264 | |
| 265 | /* |
| 266 | * If waking from S3 determine if deep S3 is enabled. If not, |
| 267 | * need to check both deep sleep well and normal suspend well. |
| 268 | * Otherwise just check deep sleep well. |
| 269 | */ |
| 270 | if (prev_sleep_state == ACPI_S3) { |
| 271 | /* PWR_FLR represents deep sleep power well loss. */ |
| 272 | uint32_t mask = PWR_FLR; |
| 273 | |
| 274 | /* If deep s3 isn't enabled check the suspend well too. */ |
| 275 | if (!deep_s3_enabled()) |
| 276 | mask |= SUS_PWR_FLR; |
| 277 | |
| 278 | if (ps->gen_pmcon_b & mask) |
| 279 | prev_sleep_state = ACPI_S5; |
| 280 | } |
| 281 | return prev_sleep_state; |
| 282 | } |
| 283 | |
| 284 | void soc_fill_power_state(struct chipset_power_state *ps) |
| 285 | { |
| 286 | uint16_t tcobase; |
| 287 | uint8_t *pmc; |
| 288 | |
| 289 | tcobase = smbus_tco_regs(); |
| 290 | |
| 291 | ps->tco1_sts = inw(tcobase + TCO1_STS); |
| 292 | ps->tco2_sts = inw(tcobase + TCO2_STS); |
| 293 | |
| 294 | printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n", |
| 295 | ps->tco1_sts, ps->tco2_sts); |
| 296 | |
| 297 | ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A); |
| 298 | ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B); |
| 299 | |
| 300 | pmc = pmc_mmio_regs(); |
| 301 | ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0); |
| 302 | ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1); |
| 303 | |
| 304 | printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n", |
| 305 | ps->gen_pmcon_a, ps->gen_pmcon_b); |
| 306 | |
| 307 | printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n", |
| 308 | ps->gblrst_cause[0], ps->gblrst_cause[1]); |
| 309 | } |
| 310 | |
| 311 | int acpi_get_sleep_type(void) |
| 312 | { |
| 313 | struct chipset_power_state *ps; |
| 314 | |
| 315 | ps = pmc_get_power_state(); |
| 316 | return ps->prev_sleep_state; |
| 317 | } |