blob: 9dd22e9c7cb685645641d5e3f389899af790bc66 [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
Duncan Laurief0ba2252016-10-25 20:03:56 -070022#define __SIMPLE_DEVICE__
23
Lee Leahyb0005132015-05-12 18:19:47 -070024#include <arch/io.h>
25#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>
Furquan Shaikh97e0a652016-08-18 21:42:36 -070032#include <rules.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>
Aaron Durbin0990fbf2017-09-15 15:23:04 -060042#include <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
Shaunak Sahad3476802017-07-08 01:08:40 -0700110const char *const *soc_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
Barnali Sarkar49eca132016-08-12 00:05:27 +0530172uint16_t smbus_tco_regs(void)
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700173{
174 uint16_t reg16;
175
176 reg16 = pci_read_config16(PCH_DEV_SMBUS, TCOBASE);
177
178 reg16 &= ~0x1f;
179
180 return reg16;
181}
Aaron Durbin38613d02016-07-14 00:56:58 -0500182
Shaunak Sahad3476802017-07-08 01:08:40 -0700183uint32_t soc_reset_tco_status(void)
Aaron Durbin38613d02016-07-14 00:56:58 -0500184{
Shaunak Sahad3476802017-07-08 01:08:40 -0700185 u16 tco1_sts;
186 u16 tco2_sts;
187 u16 tcobase;
Furquan Shaikh97e0a652016-08-18 21:42:36 -0700188
Shaunak Sahad3476802017-07-08 01:08:40 -0700189 tcobase = smbus_tco_regs();
190
191 /* TCO Status 2 register */
192 tco2_sts = inw(tcobase + TCO2_STS);
193 tco2_sts |= (TCO2_STS_SECOND_TO | TCO2_STS_BOOT);
194 outw(tco2_sts, tcobase + TCO2_STS);
195
196 /* TCO Status 1 register */
197 tco1_sts = inw(tcobase + TCO1_STS);
198
199 /* Clear SECOND_TO_STS bit */
200 if (tco2_sts & TCO2_STS_SECOND_TO)
201 outw(tco2_sts & ~TCO2_STS_SECOND_TO, tcobase + TCO2_STS);
202
203 return (tco2_sts << 16) | tco1_sts;
Aaron Durbin38613d02016-07-14 00:56:58 -0500204}
Duncan Laurief0ba2252016-10-25 20:03:56 -0700205
Shaunak Sahad3476802017-07-08 01:08:40 -0700206uintptr_t soc_read_pmc_base(void)
207{
208 return (uintptr_t) (pmc_mmio_regs());
209}
210
211void soc_get_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2)
Duncan Laurief0ba2252016-10-25 20:03:56 -0700212{
Aaron Durbine4d7abc2017-04-16 22:05:36 -0500213 DEVTREE_CONST struct soc_intel_skylake_config *config;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700214
215 /* Look up the device in devicetree */
Shaunak Sahad3476802017-07-08 01:08:40 -0700216 DEVTREE_CONST struct device *dev = dev_find_slot(0, PCH_DEVFN_PMC);
Duncan Laurief0ba2252016-10-25 20:03:56 -0700217 if (!dev || !dev->chip_info) {
218 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
Duncan Laurief0ba2252016-10-25 20:03:56 -0700219 }
220 config = dev->chip_info;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700221
Shaunak Sahad3476802017-07-08 01:08:40 -0700222 /* Assign to out variable */
223 *dw0 = config->gpe0_dw0;
224 *dw1 = config->gpe0_dw1;
225 *dw2 = config->gpe0_dw2;
Duncan Laurief0ba2252016-10-25 20:03:56 -0700226}
Aaron Durbind1fc8c12017-09-15 12:37:05 -0600227
228int rtc_failure(void)
229{
230 u8 reg8;
231 int rtc_failed;
232 /* PMC Controller Device 0x1F, Func 02 */
233 device_t dev = PCH_DEV_PMC;
234 reg8 = pci_read_config8(dev, GEN_PMCON_B);
235 rtc_failed = reg8 & RTC_BATTERY_DEAD;
236 if (rtc_failed) {
237 reg8 &= ~RTC_BATTERY_DEAD;
238 pci_write_config8(dev, GEN_PMCON_B, reg8);
239 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
240 }
241
242 return !!rtc_failed;
243}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600244
245int vbnv_cmos_failed(void)
246{
247 return rtc_failure();
248}