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 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 24 | #include <arch/io.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <device/pci_def.h> |
| 28 | #include <console/console.h> |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 29 | #include <intelblocks/pmclib.h> |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 30 | #include <halt.h> |
Ravi Sarawadi | 1483d1f | 2017-09-28 17:06:01 -0700 | [diff] [blame] | 31 | #include <intelblocks/lpc_lib.h> |
Furquan Shaikh | 97e0a65 | 2016-08-18 21:42:36 -0700 | [diff] [blame] | 32 | #include <rules.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 33 | #include <stdlib.h> |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 34 | #include <soc/gpe.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 35 | #include <soc/gpio.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 36 | #include <soc/iomap.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 37 | #include <soc/pci_devs.h> |
| 38 | #include <soc/pm.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 39 | #include <soc/pmc.h> |
| 40 | #include <soc/smbus.h> |
Duncan Laurie | 2f3736e | 2016-11-03 10:33:43 -0700 | [diff] [blame] | 41 | #include <timer.h> |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 42 | #include <vboot/vbnv.h> |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 43 | #include "chip.h" |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 44 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 45 | /* |
| 46 | * SMI |
| 47 | */ |
| 48 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 49 | const char *const *soc_smi_sts_array(size_t *smi_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 50 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 51 | static const char *const smi_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 52 | [2] = "BIOS", |
| 53 | [3] = "LEGACY_USB", |
| 54 | [4] = "SLP_SMI", |
| 55 | [5] = "APM", |
| 56 | [6] = "SWSMI_TMR", |
| 57 | [8] = "PM1", |
| 58 | [9] = "GPE0", |
| 59 | [10] = "GPI", |
| 60 | [11] = "MCSMI", |
| 61 | [12] = "DEVMON", |
| 62 | [13] = "TCO", |
| 63 | [14] = "PERIODIC", |
| 64 | [15] = "SERIRQ_SMI", |
| 65 | [16] = "SMBUS_SMI", |
| 66 | [17] = "LEGACY_USB2", |
| 67 | [18] = "INTEL_USB2", |
| 68 | [20] = "PCI_EXP_SMI", |
| 69 | [21] = "MONITOR", |
| 70 | [26] = "SPI", |
Duncan Laurie | 8d01902 | 2016-10-25 19:58:27 -0700 | [diff] [blame] | 71 | [27] = "GPIO_UNLOCK", |
| 72 | [28] = "ESPI_SMI", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 75 | *smi_arr = ARRAY_SIZE(smi_sts_bits); |
| 76 | return smi_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 79 | /* |
| 80 | * TCO |
| 81 | */ |
| 82 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 83 | const char *const *soc_tco_sts_array(size_t *tco_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 84 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 85 | static const char *const tco_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 86 | [0] = "NMI2SMI", |
| 87 | [1] = "SW_TCO", |
| 88 | [2] = "TCO_INT", |
| 89 | [3] = "TIMEOUT", |
| 90 | [7] = "NEWCENTURY", |
| 91 | [8] = "BIOSWR", |
| 92 | [9] = "DMISCI", |
| 93 | [10] = "DMISMI", |
| 94 | [12] = "DMISERR", |
| 95 | [13] = "SLVSEL", |
| 96 | [16] = "INTRD_DET", |
| 97 | [17] = "SECOND_TO", |
| 98 | [18] = "BOOT", |
| 99 | [20] = "SMLINK_SLV" |
| 100 | }; |
| 101 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 102 | *tco_arr = ARRAY_SIZE(tco_sts_bits); |
| 103 | return tco_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 106 | /* |
| 107 | * GPE0 |
| 108 | */ |
| 109 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 110 | const char *const *soc_std_gpe_sts_array(size_t *gpe_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 111 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 112 | static const char *const gpe_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 113 | [1] = "HOTPLUG", |
| 114 | [2] = "SWGPE", |
| 115 | [6] = "TCO_SCI", |
| 116 | [7] = "SMB_WAK", |
| 117 | [9] = "PCI_EXP", |
| 118 | [10] = "BATLOW", |
| 119 | [11] = "PME", |
| 120 | [12] = "ME", |
| 121 | [13] = "PME_B0", |
Aaron Durbin | 7f78849 | 2015-07-24 17:10:31 -0500 | [diff] [blame] | 122 | [14] = "eSPI", |
| 123 | [15] = "GPIO Tier-2", |
| 124 | [16] = "LAN_WAKE", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 125 | [18] = "WADT" |
| 126 | }; |
| 127 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 128 | *gpe_arr = ARRAY_SIZE(gpe_sts_bits); |
| 129 | return gpe_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | int acpi_sci_irq(void) |
| 133 | { |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 134 | int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 135 | int sci_irq = 9; |
| 136 | |
| 137 | /* Determine how SCI is routed. */ |
| 138 | switch (scis) { |
| 139 | case SCIS_IRQ9: |
| 140 | case SCIS_IRQ10: |
| 141 | case SCIS_IRQ11: |
| 142 | sci_irq = scis - SCIS_IRQ9 + 9; |
| 143 | break; |
| 144 | case SCIS_IRQ20: |
| 145 | case SCIS_IRQ21: |
| 146 | case SCIS_IRQ22: |
| 147 | case SCIS_IRQ23: |
| 148 | sci_irq = scis - SCIS_IRQ20 + 20; |
| 149 | break; |
| 150 | default: |
| 151 | printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n"); |
| 152 | sci_irq = 9; |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq); |
| 157 | return sci_irq; |
| 158 | } |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 159 | |
| 160 | uint8_t *pmc_mmio_regs(void) |
| 161 | { |
| 162 | uint32_t reg32; |
| 163 | |
| 164 | reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE); |
| 165 | |
| 166 | /* 4KiB alignment. */ |
| 167 | reg32 &= ~0xfff; |
| 168 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 169 | return (void *)(uintptr_t) reg32; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Barnali Sarkar | 49eca13 | 2016-08-12 00:05:27 +0530 | [diff] [blame] | 172 | uint16_t smbus_tco_regs(void) |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 173 | { |
| 174 | uint16_t reg16; |
| 175 | |
| 176 | reg16 = pci_read_config16(PCH_DEV_SMBUS, TCOBASE); |
| 177 | |
| 178 | reg16 &= ~0x1f; |
| 179 | |
| 180 | return reg16; |
| 181 | } |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 182 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 183 | uint32_t soc_reset_tco_status(void) |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 184 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 185 | u16 tco1_sts; |
| 186 | u16 tco2_sts; |
| 187 | u16 tcobase; |
Furquan Shaikh | 97e0a65 | 2016-08-18 21:42:36 -0700 | [diff] [blame] | 188 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 189 | tcobase = smbus_tco_regs(); |
| 190 | |
| 191 | /* TCO Status 2 register */ |
| 192 | tco2_sts = inw(tcobase + TCO2_STS); |
| 193 | tco2_sts |= (TCO2_STS_SECOND_TO | TCO2_STS_BOOT); |
| 194 | outw(tco2_sts, tcobase + TCO2_STS); |
| 195 | |
| 196 | /* TCO Status 1 register */ |
| 197 | tco1_sts = inw(tcobase + TCO1_STS); |
| 198 | |
| 199 | /* Clear SECOND_TO_STS bit */ |
| 200 | if (tco2_sts & TCO2_STS_SECOND_TO) |
| 201 | outw(tco2_sts & ~TCO2_STS_SECOND_TO, tcobase + TCO2_STS); |
| 202 | |
| 203 | return (tco2_sts << 16) | tco1_sts; |
Aaron Durbin | 38613d0 | 2016-07-14 00:56:58 -0500 | [diff] [blame] | 204 | } |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 205 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 206 | uintptr_t soc_read_pmc_base(void) |
| 207 | { |
| 208 | return (uintptr_t) (pmc_mmio_regs()); |
| 209 | } |
| 210 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 211 | 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] | 212 | { |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 213 | DEVTREE_CONST struct soc_intel_skylake_config *config; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 214 | |
| 215 | /* Look up the device in devicetree */ |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 216 | DEVTREE_CONST struct device *dev = dev_find_slot(0, PCH_DEVFN_PMC); |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 217 | if (!dev || !dev->chip_info) { |
| 218 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
Shaunak Saha | ec1a24c | 2017-10-06 12:50:38 -0700 | [diff] [blame^] | 219 | return; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 220 | } |
| 221 | config = dev->chip_info; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 222 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 223 | /* Assign to out variable */ |
| 224 | *dw0 = config->gpe0_dw0; |
| 225 | *dw1 = config->gpe0_dw1; |
| 226 | *dw2 = config->gpe0_dw2; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 227 | } |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 228 | |
| 229 | int rtc_failure(void) |
| 230 | { |
| 231 | u8 reg8; |
| 232 | int rtc_failed; |
| 233 | /* PMC Controller Device 0x1F, Func 02 */ |
| 234 | device_t dev = PCH_DEV_PMC; |
| 235 | reg8 = pci_read_config8(dev, GEN_PMCON_B); |
| 236 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 237 | if (rtc_failed) { |
| 238 | reg8 &= ~RTC_BATTERY_DEAD; |
| 239 | pci_write_config8(dev, GEN_PMCON_B, reg8); |
| 240 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 241 | } |
| 242 | |
| 243 | return !!rtc_failed; |
| 244 | } |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 245 | |
| 246 | int vbnv_cmos_failed(void) |
| 247 | { |
| 248 | return rtc_failure(); |
| 249 | } |