blob: 906a1cf56f67566c02c2ceccae6022fbd28608de [file] [log] [blame]
Angel Pons3bd1e3d2020-04-05 15:47:17 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahyb0005132015-05-12 18:19:47 -07002
3/*
4 * Helper functions for dealing with power management registers
5 * and the differences between PCH variants.
6 */
7
Angel Ponsa15a6042021-02-19 17:34:26 +01008#define __SIMPLE_DEVICE__
9
Furquan Shaikh76cedd22020-05-02 10:24:23 -070010#include <acpi/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020011#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020012#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070013#include <device/device.h>
14#include <device/pci.h>
15#include <device/pci_def.h>
16#include <console/console.h>
Shaunak Sahad3476802017-07-08 01:08:40 -070017#include <intelblocks/pmclib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070018#include <intelblocks/lpc_lib.h>
Subrata Banik7bc4dc52018-05-17 18:40:32 +053019#include <intelblocks/tco.h>
Duncan Laurief0ba2252016-10-25 20:03:56 -070020#include <soc/gpe.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070021#include <soc/gpio.h>
Lee Leahyb0005132015-05-12 18:19:47 -070022#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070023#include <soc/pci_devs.h>
24#include <soc/pm.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070025#include <soc/pmc.h>
26#include <soc/smbus.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020027#include <security/vboot/vbnv.h>
Elyes HAOUASadd76f92019-03-21 09:55:49 +010028
Duncan Laurief0ba2252016-10-25 20:03:56 -070029#include "chip.h"
Lee Leahyb0005132015-05-12 18:19:47 -070030
Lee Leahyb0005132015-05-12 18:19:47 -070031/*
32 * SMI
33 */
34
Shaunak Sahad3476802017-07-08 01:08:40 -070035const char *const *soc_smi_sts_array(size_t *smi_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070036{
Shaunak Sahad3476802017-07-08 01:08:40 -070037 static const char *const smi_sts_bits[] = {
Angel Ponsdf8462c2021-02-19 16:35:45 +010038 [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 Leahyb0005132015-05-12 18:19:47 -070057 };
58
Shaunak Sahad3476802017-07-08 01:08:40 -070059 *smi_arr = ARRAY_SIZE(smi_sts_bits);
60 return smi_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070061}
62
Lee Leahyb0005132015-05-12 18:19:47 -070063/*
64 * TCO
65 */
66
Shaunak Sahad3476802017-07-08 01:08:40 -070067const char *const *soc_tco_sts_array(size_t *tco_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070068{
Shaunak Sahad3476802017-07-08 01:08:40 -070069 static const char *const tco_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070070 [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 Sahad3476802017-07-08 01:08:40 -070086 *tco_arr = ARRAY_SIZE(tco_sts_bits);
87 return tco_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070088}
89
Lee Leahyb0005132015-05-12 18:19:47 -070090/*
91 * GPE0
92 */
93
Furquan Shaikhc4e652f2017-10-11 14:44:29 -070094const char *const *soc_std_gpe_sts_array(size_t *gpe_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070095{
Shaunak Sahad3476802017-07-08 01:08:40 -070096 static const char *const gpe_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070097 [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 Durbin7f788492015-07-24 17:10:31 -0500106 [14] = "eSPI",
107 [15] = "GPIO Tier-2",
108 [16] = "LAN_WAKE",
Lee Leahyb0005132015-05-12 18:19:47 -0700109 [18] = "WADT"
110 };
111
Shaunak Sahad3476802017-07-08 01:08:40 -0700112 *gpe_arr = ARRAY_SIZE(gpe_sts_bits);
113 return gpe_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -0700114}
115
116int acpi_sci_irq(void)
117{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700118 int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL;
Lee Leahyb0005132015-05-12 18:19:47 -0700119 int sci_irq = 9;
120
121 /* Determine how SCI is routed. */
122 switch (scis) {
123 case SCIS_IRQ9:
124 case SCIS_IRQ10:
125 case SCIS_IRQ11:
126 sci_irq = scis - SCIS_IRQ9 + 9;
127 break;
128 case SCIS_IRQ20:
129 case SCIS_IRQ21:
130 case SCIS_IRQ22:
131 case SCIS_IRQ23:
132 sci_irq = scis - SCIS_IRQ20 + 20;
133 break;
134 default:
135 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n");
136 sci_irq = 9;
137 break;
138 }
139
140 printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq);
141 return sci_irq;
142}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700143
144uint8_t *pmc_mmio_regs(void)
145{
146 uint32_t reg32;
147
148 reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE);
149
150 /* 4KiB alignment. */
151 reg32 &= ~0xfff;
152
Shaunak Sahad3476802017-07-08 01:08:40 -0700153 return (void *)(uintptr_t) reg32;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700154}
155
Shaunak Sahad3476802017-07-08 01:08:40 -0700156uintptr_t soc_read_pmc_base(void)
157{
158 return (uintptr_t) (pmc_mmio_regs());
159}
160
Michael Niewöhner35e76dd2019-11-02 12:14:06 +0100161uint32_t *soc_pmc_etr_addr(void)
162{
163 /*
164 * The pointer returned must not be cached, because the address depends on the
165 * MMCONF base address and the assigned PCI bus number, which both may change
166 * during the boot process!
167 */
168 return pci_mmio_config32_addr(PCH_DEVFN_PMC << 12, ETR);
169}
170
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700171void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2)
Duncan Laurief0ba2252016-10-25 20:03:56 -0700172{
Aaron Durbine4d7abc2017-04-16 22:05:36 -0500173 DEVTREE_CONST struct soc_intel_skylake_config *config;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700174
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300175 config = config_of_soc();
Duncan Laurief0ba2252016-10-25 20:03:56 -0700176
Shaunak Sahad3476802017-07-08 01:08:40 -0700177 /* Assign to out variable */
178 *dw0 = config->gpe0_dw0;
179 *dw1 = config->gpe0_dw1;
180 *dw2 = config->gpe0_dw2;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700181}
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600182
183int rtc_failure(void)
184{
185 u8 reg8;
186 int rtc_failed;
187 /* PMC Controller Device 0x1F, Func 02 */
Angel Ponsa15a6042021-02-19 17:34:26 +0100188 const pci_devfn_t dev = PCH_DEV_PMC;
189
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600190 reg8 = pci_read_config8(dev, GEN_PMCON_B);
191 rtc_failed = reg8 & RTC_BATTERY_DEAD;
192 if (rtc_failed) {
193 reg8 &= ~RTC_BATTERY_DEAD;
194 pci_write_config8(dev, GEN_PMCON_B, reg8);
195 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
196 }
197
198 return !!rtc_failed;
199}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600200
201int vbnv_cmos_failed(void)
202{
203 return rtc_failure();
204}
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700205
206/* Return 0, 3, or 5 to indicate the previous sleep state. */
Angel Ponsf5d090d2021-02-19 17:49:00 +0100207int soc_prev_sleep_state(const struct chipset_power_state *ps, int prev_sleep_state)
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700208{
209 /*
210 * Check for any power failure to determine if this a wake from
211 * S5 because the PCH does not set the WAK_STS bit when waking
212 * from a true G3 state.
213 */
214 if (!(ps->pm1_sts & WAK_STS) &&
215 (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR)))
216 prev_sleep_state = ACPI_S5;
217
218 /*
219 * If waking from S3 determine if deep S3 is enabled. If not,
220 * need to check both deep sleep well and normal suspend well.
221 * Otherwise just check deep sleep well.
222 */
223 if (prev_sleep_state == ACPI_S3) {
224 /* PWR_FLR represents deep sleep power well loss. */
225 uint32_t mask = PWR_FLR;
226
227 /* If deep s3 isn't enabled check the suspend well too. */
228 if (!deep_s3_enabled())
229 mask |= SUS_PWR_FLR;
230
231 if (ps->gen_pmcon_b & mask)
232 prev_sleep_state = ACPI_S5;
233 }
234 return prev_sleep_state;
235}
236
237void soc_fill_power_state(struct chipset_power_state *ps)
238{
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700239 uint8_t *pmc;
240
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530241 ps->tco1_sts = tco_read_reg(TCO1_STS);
242 ps->tco2_sts = tco_read_reg(TCO2_STS);
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700243
Angel Ponsf5d090d2021-02-19 17:49:00 +0100244 printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n", ps->tco1_sts, ps->tco2_sts);
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700245
246 ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A);
247 ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B);
248
249 pmc = pmc_mmio_regs();
250 ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0);
251 ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1);
252
253 printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n",
254 ps->gen_pmcon_a, ps->gen_pmcon_b);
255
256 printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n",
257 ps->gblrst_cause[0], ps->gblrst_cause[1]);
258}
Eugene Myersebc84232020-01-21 16:46:16 -0500259
260/* STM Support */
261uint16_t get_pmbase(void)
262{
263 return ACPI_BASE_ADDRESS;
264}