blob: ec960b5fbe53922cdef173753e6e6754470c7092 [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
Furquan Shaikh76cedd22020-05-02 10:24:23 -07008#include <acpi/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02009#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020010#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070011#include <device/device.h>
12#include <device/pci.h>
13#include <device/pci_def.h>
14#include <console/console.h>
Shaunak Sahad3476802017-07-08 01:08:40 -070015#include <intelblocks/pmclib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070016#include <intelblocks/lpc_lib.h>
Subrata Banik7bc4dc52018-05-17 18:40:32 +053017#include <intelblocks/tco.h>
Duncan Laurief0ba2252016-10-25 20:03:56 -070018#include <soc/gpe.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070019#include <soc/gpio.h>
Lee Leahyb0005132015-05-12 18:19:47 -070020#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070021#include <soc/pci_devs.h>
22#include <soc/pm.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070023#include <soc/pmc.h>
24#include <soc/smbus.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020025#include <security/vboot/vbnv.h>
Elyes HAOUASadd76f92019-03-21 09:55:49 +010026
Duncan Laurief0ba2252016-10-25 20:03:56 -070027#include "chip.h"
Lee Leahyb0005132015-05-12 18:19:47 -070028
Lee Leahyb0005132015-05-12 18:19:47 -070029/*
30 * SMI
31 */
32
Shaunak Sahad3476802017-07-08 01:08:40 -070033const char *const *soc_smi_sts_array(size_t *smi_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070034{
Shaunak Sahad3476802017-07-08 01:08:40 -070035 static const char *const smi_sts_bits[] = {
Angel Ponsdf8462c2021-02-19 16:35:45 +010036 [BIOS_STS_BIT] = "BIOS",
37 [LEGACY_USB_STS_BIT] = "LEGACY_USB",
38 [SMI_ON_SLP_EN_STS_BIT] = "SLP_SMI",
39 [APM_STS_BIT] = "APM",
40 [SWSMI_TMR_STS_BIT] = "SWSMI_TMR",
41 [PM1_STS_BIT] = "PM1",
42 [GPE0_STS_BIT] = "GPE0",
43 [GPIO_STS_BIT] = "GPI",
44 [MCSMI_STS_BIT] = "MCSMI",
45 [DEVMON_STS_BIT] = "DEVMON",
46 [TCO_STS_BIT] = "TCO",
47 [PERIODIC_STS_BIT] = "PERIODIC",
48 [SERIRQ_SMI_STS_BIT] = "SERIRQ_SMI",
49 [SMBUS_SMI_STS_BIT] = "SMBUS_SMI",
50 [PCI_EXP_SMI_STS_BIT] = "PCI_EXP_SMI",
51 [MONITOR_STS_BIT] = "MONITOR",
52 [SPI_SMI_STS_BIT] = "SPI",
53 [GPIO_UNLOCK_SMI_STS_BIT] = "GPIO_UNLOCK",
54 [ESPI_SMI_STS_BIT] = "ESPI_SMI",
Lee Leahyb0005132015-05-12 18:19:47 -070055 };
56
Shaunak Sahad3476802017-07-08 01:08:40 -070057 *smi_arr = ARRAY_SIZE(smi_sts_bits);
58 return smi_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070059}
60
Lee Leahyb0005132015-05-12 18:19:47 -070061/*
62 * TCO
63 */
64
Shaunak Sahad3476802017-07-08 01:08:40 -070065const char *const *soc_tco_sts_array(size_t *tco_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070066{
Shaunak Sahad3476802017-07-08 01:08:40 -070067 static const char *const tco_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070068 [0] = "NMI2SMI",
69 [1] = "SW_TCO",
70 [2] = "TCO_INT",
71 [3] = "TIMEOUT",
72 [7] = "NEWCENTURY",
73 [8] = "BIOSWR",
74 [9] = "DMISCI",
75 [10] = "DMISMI",
76 [12] = "DMISERR",
77 [13] = "SLVSEL",
78 [16] = "INTRD_DET",
79 [17] = "SECOND_TO",
80 [18] = "BOOT",
81 [20] = "SMLINK_SLV"
82 };
83
Shaunak Sahad3476802017-07-08 01:08:40 -070084 *tco_arr = ARRAY_SIZE(tco_sts_bits);
85 return tco_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070086}
87
Lee Leahyb0005132015-05-12 18:19:47 -070088/*
89 * GPE0
90 */
91
Furquan Shaikhc4e652f2017-10-11 14:44:29 -070092const char *const *soc_std_gpe_sts_array(size_t *gpe_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070093{
Shaunak Sahad3476802017-07-08 01:08:40 -070094 static const char *const gpe_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070095 [1] = "HOTPLUG",
96 [2] = "SWGPE",
97 [6] = "TCO_SCI",
98 [7] = "SMB_WAK",
99 [9] = "PCI_EXP",
100 [10] = "BATLOW",
101 [11] = "PME",
102 [12] = "ME",
103 [13] = "PME_B0",
Aaron Durbin7f788492015-07-24 17:10:31 -0500104 [14] = "eSPI",
105 [15] = "GPIO Tier-2",
106 [16] = "LAN_WAKE",
Lee Leahyb0005132015-05-12 18:19:47 -0700107 [18] = "WADT"
108 };
109
Shaunak Sahad3476802017-07-08 01:08:40 -0700110 *gpe_arr = ARRAY_SIZE(gpe_sts_bits);
111 return gpe_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -0700112}
113
114int acpi_sci_irq(void)
115{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700116 int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL;
Lee Leahyb0005132015-05-12 18:19:47 -0700117 int sci_irq = 9;
118
119 /* Determine how SCI is routed. */
120 switch (scis) {
121 case SCIS_IRQ9:
122 case SCIS_IRQ10:
123 case SCIS_IRQ11:
124 sci_irq = scis - SCIS_IRQ9 + 9;
125 break;
126 case SCIS_IRQ20:
127 case SCIS_IRQ21:
128 case SCIS_IRQ22:
129 case SCIS_IRQ23:
130 sci_irq = scis - SCIS_IRQ20 + 20;
131 break;
132 default:
133 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n");
134 sci_irq = 9;
135 break;
136 }
137
138 printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq);
139 return sci_irq;
140}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700141
142uint8_t *pmc_mmio_regs(void)
143{
144 uint32_t reg32;
145
146 reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE);
147
148 /* 4KiB alignment. */
149 reg32 &= ~0xfff;
150
Shaunak Sahad3476802017-07-08 01:08:40 -0700151 return (void *)(uintptr_t) reg32;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700152}
153
Shaunak Sahad3476802017-07-08 01:08:40 -0700154uintptr_t soc_read_pmc_base(void)
155{
156 return (uintptr_t) (pmc_mmio_regs());
157}
158
Michael Niewöhner35e76dd2019-11-02 12:14:06 +0100159uint32_t *soc_pmc_etr_addr(void)
160{
161 /*
162 * The pointer returned must not be cached, because the address depends on the
163 * MMCONF base address and the assigned PCI bus number, which both may change
164 * during the boot process!
165 */
166 return pci_mmio_config32_addr(PCH_DEVFN_PMC << 12, ETR);
167}
168
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700169void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2)
Duncan Laurief0ba2252016-10-25 20:03:56 -0700170{
Aaron Durbine4d7abc2017-04-16 22:05:36 -0500171 DEVTREE_CONST struct soc_intel_skylake_config *config;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700172
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300173 config = config_of_soc();
Duncan Laurief0ba2252016-10-25 20:03:56 -0700174
Shaunak Sahad3476802017-07-08 01:08:40 -0700175 /* Assign to out variable */
176 *dw0 = config->gpe0_dw0;
177 *dw1 = config->gpe0_dw1;
178 *dw2 = config->gpe0_dw2;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700179}
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600180
181int rtc_failure(void)
182{
183 u8 reg8;
184 int rtc_failed;
185 /* PMC Controller Device 0x1F, Func 02 */
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200186#if defined(__SIMPLE_DEVICE__)
187 pci_devfn_t dev = PCH_DEV_PMC;
188#else
189 struct device *dev = PCH_DEV_PMC;
190#endif
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600191 reg8 = pci_read_config8(dev, GEN_PMCON_B);
192 rtc_failed = reg8 & RTC_BATTERY_DEAD;
193 if (rtc_failed) {
194 reg8 &= ~RTC_BATTERY_DEAD;
195 pci_write_config8(dev, GEN_PMCON_B, reg8);
196 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
197 }
198
199 return !!rtc_failed;
200}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600201
202int vbnv_cmos_failed(void)
203{
204 return rtc_failure();
205}
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700206
207/* Return 0, 3, or 5 to indicate the previous sleep state. */
208int soc_prev_sleep_state(const struct chipset_power_state *ps,
209 int prev_sleep_state)
210{
211 /*
212 * Check for any power failure to determine if this a wake from
213 * S5 because the PCH does not set the WAK_STS bit when waking
214 * from a true G3 state.
215 */
216 if (!(ps->pm1_sts & WAK_STS) &&
217 (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR)))
218 prev_sleep_state = ACPI_S5;
219
220 /*
221 * If waking from S3 determine if deep S3 is enabled. If not,
222 * need to check both deep sleep well and normal suspend well.
223 * Otherwise just check deep sleep well.
224 */
225 if (prev_sleep_state == ACPI_S3) {
226 /* PWR_FLR represents deep sleep power well loss. */
227 uint32_t mask = PWR_FLR;
228
229 /* If deep s3 isn't enabled check the suspend well too. */
230 if (!deep_s3_enabled())
231 mask |= SUS_PWR_FLR;
232
233 if (ps->gen_pmcon_b & mask)
234 prev_sleep_state = ACPI_S5;
235 }
236 return prev_sleep_state;
237}
238
239void soc_fill_power_state(struct chipset_power_state *ps)
240{
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700241 uint8_t *pmc;
242
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530243 ps->tco1_sts = tco_read_reg(TCO1_STS);
244 ps->tco2_sts = tco_read_reg(TCO2_STS);
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700245
246 printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n",
247 ps->tco1_sts, ps->tco2_sts);
248
249 ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A);
250 ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B);
251
252 pmc = pmc_mmio_regs();
253 ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0);
254 ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1);
255
256 printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n",
257 ps->gen_pmcon_a, ps->gen_pmcon_b);
258
259 printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n",
260 ps->gblrst_cause[0], ps->gblrst_cause[1]);
261}
Eugene Myersebc84232020-01-21 16:46:16 -0500262
263/* STM Support */
264uint16_t get_pmbase(void)
265{
266 return ACPI_BASE_ADDRESS;
267}