blob: 032b882148e678fe5f86bd6bd2d42542f0a2c752 [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[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070036 [2] = "BIOS",
37 [3] = "LEGACY_USB",
38 [4] = "SLP_SMI",
39 [5] = "APM",
40 [6] = "SWSMI_TMR",
41 [8] = "PM1",
42 [9] = "GPE0",
43 [10] = "GPI",
44 [11] = "MCSMI",
45 [12] = "DEVMON",
46 [13] = "TCO",
47 [14] = "PERIODIC",
48 [15] = "SERIRQ_SMI",
49 [16] = "SMBUS_SMI",
50 [17] = "LEGACY_USB2",
51 [18] = "INTEL_USB2",
52 [20] = "PCI_EXP_SMI",
53 [21] = "MONITOR",
54 [26] = "SPI",
Duncan Laurie8d019022016-10-25 19:58:27 -070055 [27] = "GPIO_UNLOCK",
56 [28] = "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 */
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200188#if defined(__SIMPLE_DEVICE__)
189 pci_devfn_t dev = PCH_DEV_PMC;
190#else
191 struct device *dev = PCH_DEV_PMC;
192#endif
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600193 reg8 = pci_read_config8(dev, GEN_PMCON_B);
194 rtc_failed = reg8 & RTC_BATTERY_DEAD;
195 if (rtc_failed) {
196 reg8 &= ~RTC_BATTERY_DEAD;
197 pci_write_config8(dev, GEN_PMCON_B, reg8);
198 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
199 }
200
201 return !!rtc_failed;
202}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600203
204int vbnv_cmos_failed(void)
205{
206 return rtc_failure();
207}
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700208
209/* Return 0, 3, or 5 to indicate the previous sleep state. */
210int soc_prev_sleep_state(const struct chipset_power_state *ps,
211 int prev_sleep_state)
212{
213 /*
214 * Check for any power failure to determine if this a wake from
215 * S5 because the PCH does not set the WAK_STS bit when waking
216 * from a true G3 state.
217 */
218 if (!(ps->pm1_sts & WAK_STS) &&
219 (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR)))
220 prev_sleep_state = ACPI_S5;
221
222 /*
223 * If waking from S3 determine if deep S3 is enabled. If not,
224 * need to check both deep sleep well and normal suspend well.
225 * Otherwise just check deep sleep well.
226 */
227 if (prev_sleep_state == ACPI_S3) {
228 /* PWR_FLR represents deep sleep power well loss. */
229 uint32_t mask = PWR_FLR;
230
231 /* If deep s3 isn't enabled check the suspend well too. */
232 if (!deep_s3_enabled())
233 mask |= SUS_PWR_FLR;
234
235 if (ps->gen_pmcon_b & mask)
236 prev_sleep_state = ACPI_S5;
237 }
238 return prev_sleep_state;
239}
240
241void soc_fill_power_state(struct chipset_power_state *ps)
242{
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700243 uint8_t *pmc;
244
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530245 ps->tco1_sts = tco_read_reg(TCO1_STS);
246 ps->tco2_sts = tco_read_reg(TCO2_STS);
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700247
248 printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n",
249 ps->tco1_sts, ps->tco2_sts);
250
251 ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A);
252 ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B);
253
254 pmc = pmc_mmio_regs();
255 ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0);
256 ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1);
257
258 printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n",
259 ps->gen_pmcon_a, ps->gen_pmcon_b);
260
261 printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n",
262 ps->gblrst_cause[0], ps->gblrst_cause[1]);
263}
Eugene Myersebc84232020-01-21 16:46:16 -0500264
265/* STM Support */
266uint16_t get_pmbase(void)
267{
268 return ACPI_BASE_ADDRESS;
269}