blob: f9dfa8b2b55da361344460e6b76e149f20ca5361 [file] [log] [blame]
Angel Pons3bd1e3d2020-04-05 15:47:17 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Lee Leahyb0005132015-05-12 18:19:47 -07003
4/*
5 * Helper functions for dealing with power management registers
6 * and the differences between PCH variants.
7 */
8
Furquan Shaikh76cedd22020-05-02 10:24:23 -07009#include <acpi/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020010#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070012#include <device/device.h>
13#include <device/pci.h>
14#include <device/pci_def.h>
15#include <console/console.h>
Shaunak Sahad3476802017-07-08 01:08:40 -070016#include <intelblocks/pmclib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070017#include <intelblocks/lpc_lib.h>
Subrata Banik7bc4dc52018-05-17 18:40:32 +053018#include <intelblocks/tco.h>
Duncan Laurief0ba2252016-10-25 20:03:56 -070019#include <soc/gpe.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070020#include <soc/gpio.h>
Lee Leahyb0005132015-05-12 18:19:47 -070021#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070022#include <soc/pci_devs.h>
23#include <soc/pm.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070024#include <soc/pmc.h>
25#include <soc/smbus.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020026#include <security/vboot/vbnv.h>
Elyes HAOUASadd76f92019-03-21 09:55:49 +010027
Duncan Laurief0ba2252016-10-25 20:03:56 -070028#include "chip.h"
Lee Leahyb0005132015-05-12 18:19:47 -070029
Lee Leahyb0005132015-05-12 18:19:47 -070030/*
31 * SMI
32 */
33
Shaunak Sahad3476802017-07-08 01:08:40 -070034const char *const *soc_smi_sts_array(size_t *smi_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070035{
Shaunak Sahad3476802017-07-08 01:08:40 -070036 static const char *const smi_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070037 [2] = "BIOS",
38 [3] = "LEGACY_USB",
39 [4] = "SLP_SMI",
40 [5] = "APM",
41 [6] = "SWSMI_TMR",
42 [8] = "PM1",
43 [9] = "GPE0",
44 [10] = "GPI",
45 [11] = "MCSMI",
46 [12] = "DEVMON",
47 [13] = "TCO",
48 [14] = "PERIODIC",
49 [15] = "SERIRQ_SMI",
50 [16] = "SMBUS_SMI",
51 [17] = "LEGACY_USB2",
52 [18] = "INTEL_USB2",
53 [20] = "PCI_EXP_SMI",
54 [21] = "MONITOR",
55 [26] = "SPI",
Duncan Laurie8d019022016-10-25 19:58:27 -070056 [27] = "GPIO_UNLOCK",
57 [28] = "ESPI_SMI",
Lee Leahyb0005132015-05-12 18:19:47 -070058 };
59
Shaunak Sahad3476802017-07-08 01:08:40 -070060 *smi_arr = ARRAY_SIZE(smi_sts_bits);
61 return smi_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070062}
63
Lee Leahyb0005132015-05-12 18:19:47 -070064/*
65 * TCO
66 */
67
Shaunak Sahad3476802017-07-08 01:08:40 -070068const char *const *soc_tco_sts_array(size_t *tco_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070069{
Shaunak Sahad3476802017-07-08 01:08:40 -070070 static const char *const tco_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070071 [0] = "NMI2SMI",
72 [1] = "SW_TCO",
73 [2] = "TCO_INT",
74 [3] = "TIMEOUT",
75 [7] = "NEWCENTURY",
76 [8] = "BIOSWR",
77 [9] = "DMISCI",
78 [10] = "DMISMI",
79 [12] = "DMISERR",
80 [13] = "SLVSEL",
81 [16] = "INTRD_DET",
82 [17] = "SECOND_TO",
83 [18] = "BOOT",
84 [20] = "SMLINK_SLV"
85 };
86
Shaunak Sahad3476802017-07-08 01:08:40 -070087 *tco_arr = ARRAY_SIZE(tco_sts_bits);
88 return tco_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070089}
90
Lee Leahyb0005132015-05-12 18:19:47 -070091/*
92 * GPE0
93 */
94
Furquan Shaikhc4e652f2017-10-11 14:44:29 -070095const char *const *soc_std_gpe_sts_array(size_t *gpe_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070096{
Shaunak Sahad3476802017-07-08 01:08:40 -070097 static const char *const gpe_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070098 [1] = "HOTPLUG",
99 [2] = "SWGPE",
100 [6] = "TCO_SCI",
101 [7] = "SMB_WAK",
102 [9] = "PCI_EXP",
103 [10] = "BATLOW",
104 [11] = "PME",
105 [12] = "ME",
106 [13] = "PME_B0",
Aaron Durbin7f788492015-07-24 17:10:31 -0500107 [14] = "eSPI",
108 [15] = "GPIO Tier-2",
109 [16] = "LAN_WAKE",
Lee Leahyb0005132015-05-12 18:19:47 -0700110 [18] = "WADT"
111 };
112
Shaunak Sahad3476802017-07-08 01:08:40 -0700113 *gpe_arr = ARRAY_SIZE(gpe_sts_bits);
114 return gpe_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -0700115}
116
117int acpi_sci_irq(void)
118{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700119 int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL;
Lee Leahyb0005132015-05-12 18:19:47 -0700120 int sci_irq = 9;
121
122 /* Determine how SCI is routed. */
123 switch (scis) {
124 case SCIS_IRQ9:
125 case SCIS_IRQ10:
126 case SCIS_IRQ11:
127 sci_irq = scis - SCIS_IRQ9 + 9;
128 break;
129 case SCIS_IRQ20:
130 case SCIS_IRQ21:
131 case SCIS_IRQ22:
132 case SCIS_IRQ23:
133 sci_irq = scis - SCIS_IRQ20 + 20;
134 break;
135 default:
136 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n");
137 sci_irq = 9;
138 break;
139 }
140
141 printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq);
142 return sci_irq;
143}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700144
145uint8_t *pmc_mmio_regs(void)
146{
147 uint32_t reg32;
148
149 reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE);
150
151 /* 4KiB alignment. */
152 reg32 &= ~0xfff;
153
Shaunak Sahad3476802017-07-08 01:08:40 -0700154 return (void *)(uintptr_t) reg32;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700155}
156
Shaunak Sahad3476802017-07-08 01:08:40 -0700157uintptr_t soc_read_pmc_base(void)
158{
159 return (uintptr_t) (pmc_mmio_regs());
160}
161
Michael Niewöhner35e76dd2019-11-02 12:14:06 +0100162uint32_t *soc_pmc_etr_addr(void)
163{
164 /*
165 * The pointer returned must not be cached, because the address depends on the
166 * MMCONF base address and the assigned PCI bus number, which both may change
167 * during the boot process!
168 */
169 return pci_mmio_config32_addr(PCH_DEVFN_PMC << 12, ETR);
170}
171
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700172void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2)
Duncan Laurief0ba2252016-10-25 20:03:56 -0700173{
Aaron Durbine4d7abc2017-04-16 22:05:36 -0500174 DEVTREE_CONST struct soc_intel_skylake_config *config;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700175
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300176 config = config_of_soc();
Duncan Laurief0ba2252016-10-25 20:03:56 -0700177
Shaunak Sahad3476802017-07-08 01:08:40 -0700178 /* Assign to out variable */
179 *dw0 = config->gpe0_dw0;
180 *dw1 = config->gpe0_dw1;
181 *dw2 = config->gpe0_dw2;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700182}
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600183
184int rtc_failure(void)
185{
186 u8 reg8;
187 int rtc_failed;
188 /* PMC Controller Device 0x1F, Func 02 */
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200189#if defined(__SIMPLE_DEVICE__)
190 pci_devfn_t dev = PCH_DEV_PMC;
191#else
192 struct device *dev = PCH_DEV_PMC;
193#endif
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600194 reg8 = pci_read_config8(dev, GEN_PMCON_B);
195 rtc_failed = reg8 & RTC_BATTERY_DEAD;
196 if (rtc_failed) {
197 reg8 &= ~RTC_BATTERY_DEAD;
198 pci_write_config8(dev, GEN_PMCON_B, reg8);
199 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
200 }
201
202 return !!rtc_failed;
203}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600204
205int vbnv_cmos_failed(void)
206{
207 return rtc_failure();
208}
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700209
210/* Return 0, 3, or 5 to indicate the previous sleep state. */
211int soc_prev_sleep_state(const struct chipset_power_state *ps,
212 int prev_sleep_state)
213{
214 /*
215 * Check for any power failure to determine if this a wake from
216 * S5 because the PCH does not set the WAK_STS bit when waking
217 * from a true G3 state.
218 */
219 if (!(ps->pm1_sts & WAK_STS) &&
220 (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR)))
221 prev_sleep_state = ACPI_S5;
222
223 /*
224 * If waking from S3 determine if deep S3 is enabled. If not,
225 * need to check both deep sleep well and normal suspend well.
226 * Otherwise just check deep sleep well.
227 */
228 if (prev_sleep_state == ACPI_S3) {
229 /* PWR_FLR represents deep sleep power well loss. */
230 uint32_t mask = PWR_FLR;
231
232 /* If deep s3 isn't enabled check the suspend well too. */
233 if (!deep_s3_enabled())
234 mask |= SUS_PWR_FLR;
235
236 if (ps->gen_pmcon_b & mask)
237 prev_sleep_state = ACPI_S5;
238 }
239 return prev_sleep_state;
240}
241
242void soc_fill_power_state(struct chipset_power_state *ps)
243{
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700244 uint8_t *pmc;
245
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530246 ps->tco1_sts = tco_read_reg(TCO1_STS);
247 ps->tco2_sts = tco_read_reg(TCO2_STS);
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700248
249 printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n",
250 ps->tco1_sts, ps->tco2_sts);
251
252 ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A);
253 ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B);
254
255 pmc = pmc_mmio_regs();
256 ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0);
257 ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1);
258
259 printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n",
260 ps->gen_pmcon_a, ps->gen_pmcon_b);
261
262 printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n",
263 ps->gblrst_cause[0], ps->gblrst_cause[1]);
264}
Eugene Myersebc84232020-01-21 16:46:16 -0500265
266/* STM Support */
267uint16_t get_pmbase(void)
268{
269 return ACPI_BASE_ADDRESS;
270}