blob: 329cea9621360b78c87a8a2f11c5eeb9de3f7e72 [file] [log] [blame]
Lee Leahyb0005132015-05-12 18:19:47 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
Lee Leahy1d14b3e2015-05-12 18:23:27 -07005 * Copyright (C) 2015 Intel Corporation.
Lee Leahyb0005132015-05-12 18:19:47 -07006 *
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 Leahyb0005132015-05-12 18:19:47 -070015 */
16
17/*
18 * Helper functions for dealing with power management registers
19 * and the differences between PCH variants.
20 */
21
Furquan Shaikh3efeeb22017-10-14 19:24:43 -070022#include <arch/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020023#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020024#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070025#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_def.h>
28#include <console/console.h>
Shaunak Sahad3476802017-07-08 01:08:40 -070029#include <intelblocks/pmclib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070030#include <intelblocks/lpc_lib.h>
Subrata Banik7bc4dc52018-05-17 18:40:32 +053031#include <intelblocks/tco.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070032#include <stdlib.h>
Duncan Laurief0ba2252016-10-25 20:03:56 -070033#include <soc/gpe.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070034#include <soc/gpio.h>
Lee Leahyb0005132015-05-12 18:19:47 -070035#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070036#include <soc/pci_devs.h>
37#include <soc/pm.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070038#include <soc/pmc.h>
39#include <soc/smbus.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020040#include <security/vboot/vbnv.h>
Elyes HAOUASadd76f92019-03-21 09:55:49 +010041
Duncan Laurief0ba2252016-10-25 20:03:56 -070042#include "chip.h"
Lee Leahyb0005132015-05-12 18:19:47 -070043
Lee Leahyb0005132015-05-12 18:19:47 -070044/*
45 * SMI
46 */
47
Shaunak Sahad3476802017-07-08 01:08:40 -070048const char *const *soc_smi_sts_array(size_t *smi_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070049{
Shaunak Sahad3476802017-07-08 01:08:40 -070050 static const char *const smi_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070051 [2] = "BIOS",
52 [3] = "LEGACY_USB",
53 [4] = "SLP_SMI",
54 [5] = "APM",
55 [6] = "SWSMI_TMR",
56 [8] = "PM1",
57 [9] = "GPE0",
58 [10] = "GPI",
59 [11] = "MCSMI",
60 [12] = "DEVMON",
61 [13] = "TCO",
62 [14] = "PERIODIC",
63 [15] = "SERIRQ_SMI",
64 [16] = "SMBUS_SMI",
65 [17] = "LEGACY_USB2",
66 [18] = "INTEL_USB2",
67 [20] = "PCI_EXP_SMI",
68 [21] = "MONITOR",
69 [26] = "SPI",
Duncan Laurie8d019022016-10-25 19:58:27 -070070 [27] = "GPIO_UNLOCK",
71 [28] = "ESPI_SMI",
Lee Leahyb0005132015-05-12 18:19:47 -070072 };
73
Shaunak Sahad3476802017-07-08 01:08:40 -070074 *smi_arr = ARRAY_SIZE(smi_sts_bits);
75 return smi_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070076}
77
Lee Leahyb0005132015-05-12 18:19:47 -070078/*
79 * TCO
80 */
81
Shaunak Sahad3476802017-07-08 01:08:40 -070082const char *const *soc_tco_sts_array(size_t *tco_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070083{
Shaunak Sahad3476802017-07-08 01:08:40 -070084 static const char *const tco_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070085 [0] = "NMI2SMI",
86 [1] = "SW_TCO",
87 [2] = "TCO_INT",
88 [3] = "TIMEOUT",
89 [7] = "NEWCENTURY",
90 [8] = "BIOSWR",
91 [9] = "DMISCI",
92 [10] = "DMISMI",
93 [12] = "DMISERR",
94 [13] = "SLVSEL",
95 [16] = "INTRD_DET",
96 [17] = "SECOND_TO",
97 [18] = "BOOT",
98 [20] = "SMLINK_SLV"
99 };
100
Shaunak Sahad3476802017-07-08 01:08:40 -0700101 *tco_arr = ARRAY_SIZE(tco_sts_bits);
102 return tco_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -0700103}
104
Lee Leahyb0005132015-05-12 18:19:47 -0700105/*
106 * GPE0
107 */
108
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700109const char *const *soc_std_gpe_sts_array(size_t *gpe_arr)
Lee Leahyb0005132015-05-12 18:19:47 -0700110{
Shaunak Sahad3476802017-07-08 01:08:40 -0700111 static const char *const gpe_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -0700112 [1] = "HOTPLUG",
113 [2] = "SWGPE",
114 [6] = "TCO_SCI",
115 [7] = "SMB_WAK",
116 [9] = "PCI_EXP",
117 [10] = "BATLOW",
118 [11] = "PME",
119 [12] = "ME",
120 [13] = "PME_B0",
Aaron Durbin7f788492015-07-24 17:10:31 -0500121 [14] = "eSPI",
122 [15] = "GPIO Tier-2",
123 [16] = "LAN_WAKE",
Lee Leahyb0005132015-05-12 18:19:47 -0700124 [18] = "WADT"
125 };
126
Shaunak Sahad3476802017-07-08 01:08:40 -0700127 *gpe_arr = ARRAY_SIZE(gpe_sts_bits);
128 return gpe_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -0700129}
130
131int acpi_sci_irq(void)
132{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700133 int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL;
Lee Leahyb0005132015-05-12 18:19:47 -0700134 int sci_irq = 9;
135
136 /* Determine how SCI is routed. */
137 switch (scis) {
138 case SCIS_IRQ9:
139 case SCIS_IRQ10:
140 case SCIS_IRQ11:
141 sci_irq = scis - SCIS_IRQ9 + 9;
142 break;
143 case SCIS_IRQ20:
144 case SCIS_IRQ21:
145 case SCIS_IRQ22:
146 case SCIS_IRQ23:
147 sci_irq = scis - SCIS_IRQ20 + 20;
148 break;
149 default:
150 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n");
151 sci_irq = 9;
152 break;
153 }
154
155 printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq);
156 return sci_irq;
157}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700158
159uint8_t *pmc_mmio_regs(void)
160{
161 uint32_t reg32;
162
163 reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE);
164
165 /* 4KiB alignment. */
166 reg32 &= ~0xfff;
167
Shaunak Sahad3476802017-07-08 01:08:40 -0700168 return (void *)(uintptr_t) reg32;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700169}
170
Shaunak Sahad3476802017-07-08 01:08:40 -0700171uintptr_t soc_read_pmc_base(void)
172{
173 return (uintptr_t) (pmc_mmio_regs());
174}
175
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700176void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2)
Duncan Laurief0ba2252016-10-25 20:03:56 -0700177{
Aaron Durbine4d7abc2017-04-16 22:05:36 -0500178 DEVTREE_CONST struct soc_intel_skylake_config *config;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700179
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300180 config = config_of_soc();
Duncan Laurief0ba2252016-10-25 20:03:56 -0700181
Shaunak Sahad3476802017-07-08 01:08:40 -0700182 /* Assign to out variable */
183 *dw0 = config->gpe0_dw0;
184 *dw1 = config->gpe0_dw1;
185 *dw2 = config->gpe0_dw2;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700186}
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600187
188int rtc_failure(void)
189{
190 u8 reg8;
191 int rtc_failed;
192 /* PMC Controller Device 0x1F, Func 02 */
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200193#if defined(__SIMPLE_DEVICE__)
194 pci_devfn_t dev = PCH_DEV_PMC;
195#else
196 struct device *dev = PCH_DEV_PMC;
197#endif
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600198 reg8 = pci_read_config8(dev, GEN_PMCON_B);
199 rtc_failed = reg8 & RTC_BATTERY_DEAD;
200 if (rtc_failed) {
201 reg8 &= ~RTC_BATTERY_DEAD;
202 pci_write_config8(dev, GEN_PMCON_B, reg8);
203 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
204 }
205
206 return !!rtc_failed;
207}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600208
209int vbnv_cmos_failed(void)
210{
211 return rtc_failure();
212}
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700213
214/* Return 0, 3, or 5 to indicate the previous sleep state. */
215int soc_prev_sleep_state(const struct chipset_power_state *ps,
216 int prev_sleep_state)
217{
218 /*
219 * Check for any power failure to determine if this a wake from
220 * S5 because the PCH does not set the WAK_STS bit when waking
221 * from a true G3 state.
222 */
223 if (!(ps->pm1_sts & WAK_STS) &&
224 (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR)))
225 prev_sleep_state = ACPI_S5;
226
227 /*
228 * If waking from S3 determine if deep S3 is enabled. If not,
229 * need to check both deep sleep well and normal suspend well.
230 * Otherwise just check deep sleep well.
231 */
232 if (prev_sleep_state == ACPI_S3) {
233 /* PWR_FLR represents deep sleep power well loss. */
234 uint32_t mask = PWR_FLR;
235
236 /* If deep s3 isn't enabled check the suspend well too. */
237 if (!deep_s3_enabled())
238 mask |= SUS_PWR_FLR;
239
240 if (ps->gen_pmcon_b & mask)
241 prev_sleep_state = ACPI_S5;
242 }
243 return prev_sleep_state;
244}
245
246void soc_fill_power_state(struct chipset_power_state *ps)
247{
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700248 uint8_t *pmc;
249
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530250 ps->tco1_sts = tco_read_reg(TCO1_STS);
251 ps->tco2_sts = tco_read_reg(TCO2_STS);
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700252
253 printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n",
254 ps->tco1_sts, ps->tco2_sts);
255
256 ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A);
257 ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B);
258
259 pmc = pmc_mmio_regs();
260 ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0);
261 ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1);
262
263 printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n",
264 ps->gen_pmcon_a, ps->gen_pmcon_b);
265
266 printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n",
267 ps->gblrst_cause[0], ps->gblrst_cause[1]);
268}