blob: 40075536f39dc2794217056dfe65f2f32aef6bab [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>
Lee Leahyb0005132015-05-12 18:19:47 -070023#include <arch/io.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>
Aaron Durbin38613d02016-07-14 00:56:58 -050030#include <halt.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070031#include <intelblocks/lpc_lib.h>
Subrata Banik7bc4dc52018-05-17 18:40:32 +053032#include <intelblocks/tco.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070033#include <stdlib.h>
Duncan Laurief0ba2252016-10-25 20:03:56 -070034#include <soc/gpe.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070035#include <soc/gpio.h>
Lee Leahyb0005132015-05-12 18:19:47 -070036#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070037#include <soc/pci_devs.h>
38#include <soc/pm.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070039#include <soc/pmc.h>
40#include <soc/smbus.h>
Duncan Laurie2f3736e2016-11-03 10:33:43 -070041#include <timer.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020042#include <security/vboot/vbnv.h>
Duncan Laurief0ba2252016-10-25 20:03:56 -070043#include "chip.h"
Lee Leahyb0005132015-05-12 18:19:47 -070044
Lee Leahyb0005132015-05-12 18:19:47 -070045/*
46 * SMI
47 */
48
Shaunak Sahad3476802017-07-08 01:08:40 -070049const char *const *soc_smi_sts_array(size_t *smi_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070050{
Shaunak Sahad3476802017-07-08 01:08:40 -070051 static const char *const smi_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070052 [2] = "BIOS",
53 [3] = "LEGACY_USB",
54 [4] = "SLP_SMI",
55 [5] = "APM",
56 [6] = "SWSMI_TMR",
57 [8] = "PM1",
58 [9] = "GPE0",
59 [10] = "GPI",
60 [11] = "MCSMI",
61 [12] = "DEVMON",
62 [13] = "TCO",
63 [14] = "PERIODIC",
64 [15] = "SERIRQ_SMI",
65 [16] = "SMBUS_SMI",
66 [17] = "LEGACY_USB2",
67 [18] = "INTEL_USB2",
68 [20] = "PCI_EXP_SMI",
69 [21] = "MONITOR",
70 [26] = "SPI",
Duncan Laurie8d019022016-10-25 19:58:27 -070071 [27] = "GPIO_UNLOCK",
72 [28] = "ESPI_SMI",
Lee Leahyb0005132015-05-12 18:19:47 -070073 };
74
Shaunak Sahad3476802017-07-08 01:08:40 -070075 *smi_arr = ARRAY_SIZE(smi_sts_bits);
76 return smi_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -070077}
78
Lee Leahyb0005132015-05-12 18:19:47 -070079/*
80 * TCO
81 */
82
Shaunak Sahad3476802017-07-08 01:08:40 -070083const char *const *soc_tco_sts_array(size_t *tco_arr)
Lee Leahyb0005132015-05-12 18:19:47 -070084{
Shaunak Sahad3476802017-07-08 01:08:40 -070085 static const char *const tco_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -070086 [0] = "NMI2SMI",
87 [1] = "SW_TCO",
88 [2] = "TCO_INT",
89 [3] = "TIMEOUT",
90 [7] = "NEWCENTURY",
91 [8] = "BIOSWR",
92 [9] = "DMISCI",
93 [10] = "DMISMI",
94 [12] = "DMISERR",
95 [13] = "SLVSEL",
96 [16] = "INTRD_DET",
97 [17] = "SECOND_TO",
98 [18] = "BOOT",
99 [20] = "SMLINK_SLV"
100 };
101
Shaunak Sahad3476802017-07-08 01:08:40 -0700102 *tco_arr = ARRAY_SIZE(tco_sts_bits);
103 return tco_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -0700104}
105
Lee Leahyb0005132015-05-12 18:19:47 -0700106/*
107 * GPE0
108 */
109
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700110const char *const *soc_std_gpe_sts_array(size_t *gpe_arr)
Lee Leahyb0005132015-05-12 18:19:47 -0700111{
Shaunak Sahad3476802017-07-08 01:08:40 -0700112 static const char *const gpe_sts_bits[] = {
Lee Leahyb0005132015-05-12 18:19:47 -0700113 [1] = "HOTPLUG",
114 [2] = "SWGPE",
115 [6] = "TCO_SCI",
116 [7] = "SMB_WAK",
117 [9] = "PCI_EXP",
118 [10] = "BATLOW",
119 [11] = "PME",
120 [12] = "ME",
121 [13] = "PME_B0",
Aaron Durbin7f788492015-07-24 17:10:31 -0500122 [14] = "eSPI",
123 [15] = "GPIO Tier-2",
124 [16] = "LAN_WAKE",
Lee Leahyb0005132015-05-12 18:19:47 -0700125 [18] = "WADT"
126 };
127
Shaunak Sahad3476802017-07-08 01:08:40 -0700128 *gpe_arr = ARRAY_SIZE(gpe_sts_bits);
129 return gpe_sts_bits;
Lee Leahyb0005132015-05-12 18:19:47 -0700130}
131
132int acpi_sci_irq(void)
133{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700134 int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL;
Lee Leahyb0005132015-05-12 18:19:47 -0700135 int sci_irq = 9;
136
137 /* Determine how SCI is routed. */
138 switch (scis) {
139 case SCIS_IRQ9:
140 case SCIS_IRQ10:
141 case SCIS_IRQ11:
142 sci_irq = scis - SCIS_IRQ9 + 9;
143 break;
144 case SCIS_IRQ20:
145 case SCIS_IRQ21:
146 case SCIS_IRQ22:
147 case SCIS_IRQ23:
148 sci_irq = scis - SCIS_IRQ20 + 20;
149 break;
150 default:
151 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n");
152 sci_irq = 9;
153 break;
154 }
155
156 printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq);
157 return sci_irq;
158}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700159
160uint8_t *pmc_mmio_regs(void)
161{
162 uint32_t reg32;
163
164 reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE);
165
166 /* 4KiB alignment. */
167 reg32 &= ~0xfff;
168
Shaunak Sahad3476802017-07-08 01:08:40 -0700169 return (void *)(uintptr_t) reg32;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700170}
171
Shaunak Sahad3476802017-07-08 01:08:40 -0700172uintptr_t soc_read_pmc_base(void)
173{
174 return (uintptr_t) (pmc_mmio_regs());
175}
176
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700177void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2)
Duncan Laurief0ba2252016-10-25 20:03:56 -0700178{
Aaron Durbine4d7abc2017-04-16 22:05:36 -0500179 DEVTREE_CONST struct soc_intel_skylake_config *config;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700180
181 /* Look up the device in devicetree */
Shaunak Sahad3476802017-07-08 01:08:40 -0700182 DEVTREE_CONST struct device *dev = dev_find_slot(0, PCH_DEVFN_PMC);
Duncan Laurief0ba2252016-10-25 20:03:56 -0700183 if (!dev || !dev->chip_info) {
184 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
Shaunak Sahaec1a24c2017-10-06 12:50:38 -0700185 return;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700186 }
187 config = dev->chip_info;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700188
Shaunak Sahad3476802017-07-08 01:08:40 -0700189 /* Assign to out variable */
190 *dw0 = config->gpe0_dw0;
191 *dw1 = config->gpe0_dw1;
192 *dw2 = config->gpe0_dw2;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700193}
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600194
195int rtc_failure(void)
196{
197 u8 reg8;
198 int rtc_failed;
199 /* PMC Controller Device 0x1F, Func 02 */
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200200#if defined(__SIMPLE_DEVICE__)
201 pci_devfn_t dev = PCH_DEV_PMC;
202#else
203 struct device *dev = PCH_DEV_PMC;
204#endif
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600205 reg8 = pci_read_config8(dev, GEN_PMCON_B);
206 rtc_failed = reg8 & RTC_BATTERY_DEAD;
207 if (rtc_failed) {
208 reg8 &= ~RTC_BATTERY_DEAD;
209 pci_write_config8(dev, GEN_PMCON_B, reg8);
210 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
211 }
212
213 return !!rtc_failed;
214}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600215
216int vbnv_cmos_failed(void)
217{
218 return rtc_failure();
219}
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700220
221/* Return 0, 3, or 5 to indicate the previous sleep state. */
222int soc_prev_sleep_state(const struct chipset_power_state *ps,
223 int prev_sleep_state)
224{
225 /*
226 * Check for any power failure to determine if this a wake from
227 * S5 because the PCH does not set the WAK_STS bit when waking
228 * from a true G3 state.
229 */
230 if (!(ps->pm1_sts & WAK_STS) &&
231 (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR)))
232 prev_sleep_state = ACPI_S5;
233
234 /*
235 * If waking from S3 determine if deep S3 is enabled. If not,
236 * need to check both deep sleep well and normal suspend well.
237 * Otherwise just check deep sleep well.
238 */
239 if (prev_sleep_state == ACPI_S3) {
240 /* PWR_FLR represents deep sleep power well loss. */
241 uint32_t mask = PWR_FLR;
242
243 /* If deep s3 isn't enabled check the suspend well too. */
244 if (!deep_s3_enabled())
245 mask |= SUS_PWR_FLR;
246
247 if (ps->gen_pmcon_b & mask)
248 prev_sleep_state = ACPI_S5;
249 }
250 return prev_sleep_state;
251}
252
253void soc_fill_power_state(struct chipset_power_state *ps)
254{
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700255 uint8_t *pmc;
256
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530257 ps->tco1_sts = tco_read_reg(TCO1_STS);
258 ps->tco2_sts = tco_read_reg(TCO2_STS);
Furquan Shaikh3efeeb22017-10-14 19:24:43 -0700259
260 printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n",
261 ps->tco1_sts, ps->tco2_sts);
262
263 ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A);
264 ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B);
265
266 pmc = pmc_mmio_regs();
267 ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0);
268 ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1);
269
270 printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n",
271 ps->gen_pmcon_a, ps->gen_pmcon_b);
272
273 printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n",
274 ps->gblrst_cause[0], ps->gblrst_cause[1]);
275}