blob: c88e5ae8bf1c3bfad64a80cde4ce0de329b282e5 [file] [log] [blame]
Hannah Williams01bc8972016-02-04 20:13:34 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 * Copyright (C) 2015-2016 Intel Corp.
6 *
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, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
Alexandru Gagniuca6339802016-04-05 12:40:24 -070018#define __SIMPLE_DEVICE__
19
Duncan Laurie2e790092016-09-19 12:05:49 -070020#include <arch/acpi.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080021#include <arch/io.h>
22#include <console/console.h>
Shaunak Saha60b46182016-08-02 17:25:13 -070023#include <cbmem.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080024#include <rules.h>
25#include <device/pci_def.h>
Aaron Durbinc2b77792016-07-14 00:26:50 -050026#include <halt.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080027#include <soc/iomap.h>
Alexandru Gagniuca6339802016-04-05 12:40:24 -070028#include <soc/pci_devs.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080029#include <soc/pm.h>
30#include <device/device.h>
31#include <device/pci.h>
Duncan Laurie2f3736e2016-11-03 10:33:43 -070032#include <timer.h>
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070033#include <vboot/vboot_common.h>
Duncan Lauriea673d1c2016-09-19 12:02:54 -070034#include "chip.h"
Hannah Williams01bc8972016-02-04 20:13:34 -080035
Alexandru Gagniuca6339802016-04-05 12:40:24 -070036static uintptr_t read_pmc_mmio_bar(void)
37{
Lijian Zhao91086802016-09-06 18:15:29 -070038 return PMC_BAR0;
Alexandru Gagniuca6339802016-04-05 12:40:24 -070039}
Hannah Williams01bc8972016-02-04 20:13:34 -080040
Shaunak Saha9a0c9ac2016-06-27 23:00:15 -070041uintptr_t get_pmc_mmio_bar(void)
42{
43 return read_pmc_mmio_bar();
44}
45
Hannah Williams01bc8972016-02-04 20:13:34 -080046static void print_num_status_bits(int num_bits, uint32_t status,
47 const char * const bit_names[])
48{
49 int i;
50
51 if (!status)
52 return;
53
54 for (i = num_bits - 1; i >= 0; i--) {
55 if (status & (1 << i)) {
56 if (bit_names[i])
57 printk(BIOS_DEBUG, "%s ", bit_names[i]);
58 else
59 printk(BIOS_DEBUG, "BIT%d ", i);
60 }
61 }
62}
63
64static uint32_t print_smi_status(uint32_t smi_sts)
65{
66 static const char * const smi_sts_bits[] = {
Aaron Durbin7929dd02016-06-10 18:01:45 -050067 [BIOS_SMI_STS] = "BIOS",
68 [LEGACY_USB_SMI_STS] = "LEGACY USB",
69 [SLP_SMI_STS] = "SLP_SMI",
70 [APM_SMI_STS] = "APM",
71 [SWSMI_TMR_SMI_STS] = "SWSMI_TMR",
Aaron Durbina554b712016-06-10 18:04:21 -050072 [FAKE_PM1_SMI_STS] = "PM1",
Aaron Durbin7929dd02016-06-10 18:01:45 -050073 [GPIO_SMI_STS]= "GPIO_SMI",
74 [GPIO_UNLOCK_SMI_STS]= "GPIO_UNLOCK_SSMI",
75 [MC_SMI_STS] = "MCSMI",
76 [TCO_SMI_STS] = "TCO",
77 [PERIODIC_SMI_STS] = "PERIODIC",
78 [SERIRQ_SMI_STS] = "SERIRQ",
79 [SMBUS_SMI_STS] = "SMBUS_SMI",
80 [XHCI_SMI_STS] = "XHCI",
81 [HSMBUS_SMI_STS] = "HOST_SMBUS",
82 [SCS_SMI_STS] = "SCS",
83 [PCIE_SMI_STS] = "PCI_EXP_SMI",
84 [SCC2_SMI_STS] = "SCC2",
85 [SPI_SSMI_STS] = "SPI_SSMI",
86 [SPI_SMI_STS] = "SPI",
87 [PMC_OCP_SMI_STS] = "OCP_CSE",
Hannah Williams01bc8972016-02-04 20:13:34 -080088 };
89
90 if (!smi_sts)
91 return 0;
92
93 printk(BIOS_DEBUG, "SMI_STS: ");
94 print_num_status_bits(ARRAY_SIZE(smi_sts_bits), smi_sts, smi_sts_bits);
95 printk(BIOS_DEBUG, "\n");
96
97 return smi_sts;
98}
99
100static uint32_t reset_smi_status(void)
101{
102 uint32_t smi_sts = inl(ACPI_PMIO_BASE + SMI_STS);
103 outl(smi_sts, ACPI_PMIO_BASE + SMI_STS);
104 return smi_sts;
105}
106
107uint32_t clear_smi_status(void)
108{
Aaron Durbina554b712016-06-10 18:04:21 -0500109 uint32_t sts = reset_smi_status();
110
111 /*
112 * Check for power button status if nothing else is indicating an SMI
113 * and SMIs aren't turned into SCIs. Apparently, there is no PM1 status
114 * bit in the SMI status register. That makes things difficult for
115 * determining if the power button caused an SMI.
116 */
117 if (sts == 0 && !(inl(ACPI_PMIO_BASE + PM1_CNT) & SCI_EN)) {
118 uint16_t pm1_sts = inw(ACPI_PMIO_BASE + PM1_STS);
119
120 /* Fake PM1 status bit if power button pressed. */
121 if (pm1_sts & PWRBTN_STS)
122 sts |= (1 << FAKE_PM1_SMI_STS);
123 }
124
125 return print_smi_status(sts);
Hannah Williams01bc8972016-02-04 20:13:34 -0800126}
127
128uint32_t get_smi_en(void)
129{
130 return inl(ACPI_PMIO_BASE + SMI_EN);
131}
132
133void enable_smi(uint32_t mask)
134{
135 uint32_t smi_en = inl(ACPI_PMIO_BASE + SMI_EN);
136 smi_en |= mask;
137 outl(smi_en, ACPI_PMIO_BASE + SMI_EN);
138}
139
140void disable_smi(uint32_t mask)
141{
142 uint32_t smi_en = inl(ACPI_PMIO_BASE + SMI_EN);
143 smi_en &= ~mask;
144 outl(smi_en, ACPI_PMIO_BASE + SMI_EN);
145}
146
147void enable_pm1_control(uint32_t mask)
148{
149 uint32_t pm1_cnt = inl(ACPI_PMIO_BASE + PM1_CNT);
150 pm1_cnt |= mask;
151 outl(pm1_cnt, ACPI_PMIO_BASE + PM1_CNT);
152}
153
154void disable_pm1_control(uint32_t mask)
155{
156 uint32_t pm1_cnt = inl(ACPI_PMIO_BASE + PM1_CNT);
157 pm1_cnt &= ~mask;
158 outl(pm1_cnt, ACPI_PMIO_BASE + PM1_CNT);
159}
160
161static uint16_t reset_pm1_status(void)
162{
163 uint16_t pm1_sts = inw(ACPI_PMIO_BASE + PM1_STS);
164 outw(pm1_sts, ACPI_PMIO_BASE + PM1_STS);
165 return pm1_sts;
166}
167
168static uint16_t print_pm1_status(uint16_t pm1_sts)
169{
170 static const char * const pm1_sts_bits[] = {
171 [0] = "TMROF",
172 [5] = "GBL",
173 [8] = "PWRBTN",
174 [10] = "RTC",
175 [11] = "PRBTNOR",
176 [13] = "USB",
177 [14] = "PCIEXPWAK",
178 [15] = "WAK",
179 };
180
181 if (!pm1_sts)
182 return 0;
183
184 printk(BIOS_SPEW, "PM1_STS: ");
185 print_num_status_bits(ARRAY_SIZE(pm1_sts_bits), pm1_sts, pm1_sts_bits);
186 printk(BIOS_SPEW, "\n");
187
188 return pm1_sts;
189}
190
191uint16_t clear_pm1_status(void)
192{
193 return print_pm1_status(reset_pm1_status());
194}
195
196void enable_pm1(uint16_t events)
197{
198 outw(events, ACPI_PMIO_BASE + PM1_EN);
199}
200
201static uint32_t print_tco_status(uint32_t tco_sts)
202{
203 static const char * const tco_sts_bits[] = {
204 [3] = "TIMEOUT",
205 [17] = "SECOND_TO",
206 };
207
208 if (!tco_sts)
209 return 0;
210
211 printk(BIOS_DEBUG, "TCO_STS: ");
212 print_num_status_bits(ARRAY_SIZE(tco_sts_bits), tco_sts, tco_sts_bits);
213 printk(BIOS_DEBUG, "\n");
214
215 return tco_sts;
216}
217
218static uint32_t reset_tco_status(void)
219{
220 uint32_t tco_sts = inl(ACPI_PMIO_BASE + TCO_STS);
221 uint32_t tco_en = inl(ACPI_PMIO_BASE + TCO1_CNT);
222
223 outl(tco_sts, ACPI_PMIO_BASE + TCO_STS);
224 return tco_sts & tco_en;
225}
226
227uint32_t clear_tco_status(void)
228{
229 return print_tco_status(reset_tco_status());
230}
231
232void enable_gpe(uint32_t mask)
233{
234 uint32_t gpe0a_en = inl(ACPI_PMIO_BASE + GPE0_EN(0));
235 gpe0a_en |= mask;
236 outl(gpe0a_en, ACPI_PMIO_BASE + GPE0_EN(0));
237}
238
239void disable_gpe(uint32_t mask)
240{
241 uint32_t gpe0a_en = inl(ACPI_PMIO_BASE + GPE0_EN(0));
242 gpe0a_en &= ~mask;
243 outl(gpe0a_en, ACPI_PMIO_BASE + GPE0_EN(0));
244}
245
246void disable_all_gpe(void)
247{
248 disable_gpe(~0);
249}
250
Shaunak Sahad6bb5492016-08-22 21:55:23 -0700251/* Clear the gpio gpe0 status bits in ACPI registers */
252void clear_gpi_gpe_sts(void)
253{
254 int i;
255
256 for (i = 1; i < GPE0_REG_MAX; i++) {
257 uint32_t gpe_sts = inl(ACPI_PMIO_BASE + GPE0_STS(i));
258 outl(gpe_sts, ACPI_PMIO_BASE + GPE0_STS(i));
259 }
260}
Hannah Williams01bc8972016-02-04 20:13:34 -0800261
262static uint32_t reset_gpe_status(void)
263{
264 uint32_t gpe_sts = inl(ACPI_PMIO_BASE + GPE0_STS(0));
265 outl(gpe_sts, ACPI_PMIO_BASE + GPE0_STS(0));
266 return gpe_sts;
267}
268
269static uint32_t print_gpe_sts(uint32_t gpe_sts)
270{
271 static const char * const gpe_sts_bits[] = {
272 [0] = "PCIE_SCI",
273 [2] = "SWGPE",
274 [3] = "PCIE_WAKE0",
275 [4] = "PUNIT",
276 [6] = "PCIE_WAKE1",
277 [7] = "PCIE_WAKE2",
278 [8] = "PCIE_WAKE3",
279 [9] = "PCI_EXP",
280 [10] = "BATLOW",
281 [11] = "CSE_PME",
282 [12] = "XDCI_PME",
283 [13] = "XHCI_PME",
284 [14] = "AVS_PME",
285 [15] = "GPIO_TIER1_SCI",
286 [16] = "SMB_WAK",
287 [17] = "SATA_PME",
288 };
289
290 if (!gpe_sts)
291 return gpe_sts;
292
293 printk(BIOS_DEBUG, "GPE0a_STS: ");
294 print_num_status_bits(ARRAY_SIZE(gpe_sts_bits), gpe_sts, gpe_sts_bits);
295 printk(BIOS_DEBUG, "\n");
296
297 return gpe_sts;
298}
299
300uint32_t clear_gpe_status(void)
301{
302 return print_gpe_sts(reset_gpe_status());
303}
304
Duncan Laurie2e790092016-09-19 12:05:49 -0700305/* Read and clear GPE status (defined in arch/acpi.h) */
306int acpi_get_gpe(int gpe)
307{
308 int bank;
309 uint32_t mask, sts;
Duncan Laurie2f3736e2016-11-03 10:33:43 -0700310 struct stopwatch sw;
311 int rc = 0;
Duncan Laurie2e790092016-09-19 12:05:49 -0700312
313 if (gpe < 0 || gpe > GPE0_DW3_31)
314 return -1;
315
316 bank = gpe / 32;
317 mask = 1 << (gpe % 32);
318
Duncan Laurie2f3736e2016-11-03 10:33:43 -0700319 /* Wait up to 1ms for GPE status to clear */
320 stopwatch_init_msecs_expire(&sw, 1);
321 do {
322 if (stopwatch_expired(&sw))
323 return rc;
324
325 sts = inl(ACPI_PMIO_BASE + GPE0_STS(bank));
326 if (sts & mask) {
327 outl(mask, ACPI_PMIO_BASE + GPE0_STS(bank));
328 rc = 1;
329 }
330 } while (sts & mask);
331
332 return rc;
Duncan Laurie2e790092016-09-19 12:05:49 -0700333}
334
Hannah Williams01bc8972016-02-04 20:13:34 -0800335void clear_pmc_status(void)
336{
337 uint32_t prsts;
338 uint32_t gen_pmcon1;
Alexandru Gagniuca6339802016-04-05 12:40:24 -0700339 uintptr_t pmc_bar0 = read_pmc_mmio_bar();
Hannah Williams01bc8972016-02-04 20:13:34 -0800340
Alexandru Gagniuca6339802016-04-05 12:40:24 -0700341 prsts = read32((void *)(pmc_bar0 + PRSTS));
342 gen_pmcon1 = read32((void *)(pmc_bar0 + GEN_PMCON1));
Hannah Williams01bc8972016-02-04 20:13:34 -0800343
344 /* Clear the status bits. The RPS field is cleared on a 0 write. */
Alexandru Gagniuca6339802016-04-05 12:40:24 -0700345 write32((void *)(pmc_bar0 + GEN_PMCON1), gen_pmcon1 & ~RPS);
346 write32((void *)(pmc_bar0 + PRSTS), prsts);
Hannah Williams01bc8972016-02-04 20:13:34 -0800347}
348
349
350/* Return 0, 3, or 5 to indicate the previous sleep state. */
351int chipset_prev_sleep_state(struct chipset_power_state *ps)
352{
353 /* Default to S0. */
Aaron Durbined35b7c2016-07-13 23:17:38 -0500354 int prev_sleep_state = ACPI_S0;
Hannah Williams01bc8972016-02-04 20:13:34 -0800355
356 if (ps->pm1_sts & WAK_STS) {
Aaron Durbined35b7c2016-07-13 23:17:38 -0500357 switch (acpi_sleep_from_pm1(ps->pm1_cnt)) {
358 case ACPI_S3:
359 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME))
360 prev_sleep_state = ACPI_S3;
Hannah Williams01bc8972016-02-04 20:13:34 -0800361 break;
Aaron Durbined35b7c2016-07-13 23:17:38 -0500362 case ACPI_S5:
363 prev_sleep_state = ACPI_S5;
Hannah Williams01bc8972016-02-04 20:13:34 -0800364 break;
365 }
Hannah Williams5992afa2016-06-23 09:50:28 -0700366
367 /* Clear SLP_TYP. */
368 outl(ps->pm1_cnt & ~(SLP_TYP), ACPI_PMIO_BASE + PM1_CNT);
Hannah Williams01bc8972016-02-04 20:13:34 -0800369 }
370 return prev_sleep_state;
371}
372
Shaunak Saha60b46182016-08-02 17:25:13 -0700373/*
374 * This function re-writes the gpe0 register values in power state
375 * cbmem variable. After system wakes from sleep state internal PMC logic
376 * writes default values in GPE_CFG register which gives a wrong offset to
377 * calculate the wake reason. So we need to set it again to the routing
378 * table as per the devicetree.
379 */
380void fixup_power_state(void)
381{
382 int i;
383 struct chipset_power_state *ps;
384
385 ps = cbmem_find(CBMEM_ID_POWER_STATE);
386 if (ps == NULL)
387 return;
388
389 for (i = 0; i < GPE0_REG_MAX; i++) {
390 ps->gpe0_sts[i] = inl(ACPI_PMIO_BASE + GPE0_STS(i));
391 ps->gpe0_en[i] = inl(ACPI_PMIO_BASE + GPE0_EN(i));
392 printk(BIOS_DEBUG, "gpe0_sts[%d]: %08x gpe0_en[%d]: %08x\n",
393 i, ps->gpe0_sts[i], i, ps->gpe0_en[i]);
394 }
395}
396
Hannah Williams01bc8972016-02-04 20:13:34 -0800397/* returns prev_sleep_state */
398int fill_power_state(struct chipset_power_state *ps)
399{
400 int i;
Alexandru Gagniuca6339802016-04-05 12:40:24 -0700401 uintptr_t pmc_bar0 = read_pmc_mmio_bar();
402
Hannah Williams01bc8972016-02-04 20:13:34 -0800403 ps->pm1_sts = inw(ACPI_PMIO_BASE + PM1_STS);
404 ps->pm1_en = inw(ACPI_PMIO_BASE + PM1_EN);
405 ps->pm1_cnt = inl(ACPI_PMIO_BASE + PM1_CNT);
406 ps->tco_sts = inl(ACPI_PMIO_BASE + TCO_STS);
Alexandru Gagniuca6339802016-04-05 12:40:24 -0700407 ps->prsts = read32((void *)(pmc_bar0 + PRSTS));
408 ps->gen_pmcon1 =read32((void *)(pmc_bar0 + GEN_PMCON1));
409 ps->gen_pmcon2 = read32((void *)(pmc_bar0 + GEN_PMCON2));
410 ps->gen_pmcon3 = read32((void *)(pmc_bar0 + GEN_PMCON3));
Hannah Williams01bc8972016-02-04 20:13:34 -0800411
412 ps->prev_sleep_state = chipset_prev_sleep_state(ps);
413
414 printk(BIOS_DEBUG, "pm1_sts: %04x pm1_en: %04x pm1_cnt: %08x\n",
415 ps->pm1_sts, ps->pm1_en, ps->pm1_cnt);
416 printk(BIOS_DEBUG, "prsts: %08x tco_sts: %08x\n",
417 ps->prsts, ps->tco_sts);
418 printk(BIOS_DEBUG,
419 "gen_pmcon1: %08x gen_pmcon2: %08x gen_pmcon3: %08x\n",
420 ps->gen_pmcon1, ps->gen_pmcon2, ps->gen_pmcon3);
421 printk(BIOS_DEBUG, "smi_en: %08x smi_sts: %08x\n",
422 inl(ACPI_PMIO_BASE + SMI_EN), inl(ACPI_PMIO_BASE + SMI_STS));
423 for (i=0; i < GPE0_REG_MAX; i++) {
424 ps->gpe0_sts[i] = inl(ACPI_PMIO_BASE + GPE0_STS(i));
425 ps->gpe0_en[i] = inl(ACPI_PMIO_BASE + GPE0_EN(i));
426 printk(BIOS_DEBUG, "gpe0_sts[%d]: %08x gpe0_en[%d]: %08x\n",
427 i, ps->gpe0_sts[i], i, ps->gpe0_en[i]);
428 }
429 printk(BIOS_DEBUG, "prev_sleep_state %d\n", ps->prev_sleep_state);
430 return ps->prev_sleep_state;
431}
Aaron Durbinbef75e72016-05-26 11:00:44 -0500432
433int vboot_platform_is_resuming(void)
434{
Aaron Durbinbef75e72016-05-26 11:00:44 -0500435 if (!(inw(ACPI_PMIO_BASE + PM1_STS) & WAK_STS))
436 return 0;
437
Aaron Durbined35b7c2016-07-13 23:17:38 -0500438 return acpi_sleep_from_pm1(inl(ACPI_PMIO_BASE + PM1_CNT)) == ACPI_S3;
Aaron Durbinbef75e72016-05-26 11:00:44 -0500439}
Andrey Petrov0f593c22016-06-17 15:30:13 -0700440
441/*
442 * If possible, lock 0xcf9. Once the register is locked, it can't be changed.
443 * This lock is reset on cold boot, hard reset, soft reset and Sx.
444 */
445void global_reset_lock(void)
446{
447 uintptr_t etr = read_pmc_mmio_bar() + ETR;
448 uint32_t reg;
449
450 reg = read32((void *)etr);
451 if (reg & CF9_LOCK)
452 return;
453 reg |= CF9_LOCK;
454 write32((void *)etr, reg);
455}
456
457/*
458 * Enable or disable global reset. If global reset is enabled, hard reset and
459 * soft reset will trigger global reset, where both host and TXE are reset.
460 * This is cleared on cold boot, hard reset, soft reset and Sx.
461 */
462void global_reset_enable(bool enable)
463{
464 uintptr_t etr = read_pmc_mmio_bar() + ETR;
465 uint32_t reg;
466
467 reg = read32((void *)etr);
468 reg = enable ? reg | CF9_GLB_RST : reg & ~CF9_GLB_RST;
469 write32((void *)etr, reg);
470}
Furquan Shaikh4c1cb422016-06-23 14:00:05 -0700471
472/*
473 * The PM1 control is set to S5 when vboot requests a reboot because the power
474 * state code above may not have collected its data yet. Therefore, set it to
475 * S5 when vboot requests a reboot. That's necessary if vboot fails in the
476 * resume path and requests a reboot. This prevents a reboot loop where the
477 * error is continually hit on the failing vboot resume path.
478 */
479void vboot_platform_prepare_reboot(void)
480{
481 const uint16_t port = ACPI_PMIO_BASE + PM1_CNT;
482 outl((inl(port) & ~(SLP_TYP)) | (SLP_TYP_S5 << SLP_TYP_SHIFT), port);
483}
Aaron Durbinc2b77792016-07-14 00:26:50 -0500484
485void poweroff(void)
486{
487 enable_pm1_control(SLP_EN | (SLP_TYP_S5 << SLP_TYP_SHIFT));
Furquan Shaikh3828e552016-08-18 21:31:50 -0700488
489 /*
490 * Setting SLP_TYP_S5 in PM1 triggers SLP_SMI, which is handled by SMM
491 * to transition to S5 state. If halt is called in SMM, then it prevents
492 * the SMI handler from being triggered and system never enters S5.
493 */
494 if (!ENV_SMM)
495 halt();
Aaron Durbinc2b77792016-07-14 00:26:50 -0500496}
Duncan Lauriea673d1c2016-09-19 12:02:54 -0700497
498void pmc_gpe_init(void)
499{
500 uint32_t gpio_cfg = 0;
501 uint32_t gpio_cfg_reg;
502 uint8_t dw1, dw2, dw3;
503 ROMSTAGE_CONST struct soc_intel_apollolake_config *config;
504
505 /* Look up the device in devicetree */
506 ROMSTAGE_CONST struct device *dev = dev_find_slot(0, NB_DEVFN);
507 if (!dev || !dev->chip_info) {
508 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
509 return;
510 }
511 config = dev->chip_info;
512
513 uintptr_t pmc_bar = get_pmc_mmio_bar();
514
515 const uint32_t gpio_cfg_mask =
516 (GPE0_DWX_MASK << GPE0_DW1_SHIFT) |
517 (GPE0_DWX_MASK << GPE0_DW2_SHIFT) |
518 (GPE0_DWX_MASK << GPE0_DW3_SHIFT);
519
520 /* Assign to local variable */
521 dw1 = config->gpe0_dw1;
522 dw2 = config->gpe0_dw2;
523 dw3 = config->gpe0_dw3;
524
525 /* Making sure that bad values don't bleed into the other fields */
526 dw1 &= GPE0_DWX_MASK;
527 dw2 &= GPE0_DWX_MASK;
528 dw3 &= GPE0_DWX_MASK;
529
530 /* Route the GPIOs to the GPE0 block. Determine that all values
531 * are different, and if they aren't use the reset values.
532 * DW0 is reserved/unused */
533 if (dw1 == dw2 || dw2 == dw3) {
534 printk(BIOS_INFO, "PMC: Using default GPE route.\n");
535 gpio_cfg = read32((void *)pmc_bar + GPIO_GPE_CFG);
536
537 dw1 = (gpio_cfg >> GPE0_DW1_SHIFT) & GPE0_DWX_MASK;
538 dw2 = (gpio_cfg >> GPE0_DW2_SHIFT) & GPE0_DWX_MASK;
539 dw3 = (gpio_cfg >> GPE0_DW3_SHIFT) & GPE0_DWX_MASK;
540 } else {
541 gpio_cfg |= (uint32_t)dw1 << GPE0_DW1_SHIFT;
542 gpio_cfg |= (uint32_t)dw2 << GPE0_DW2_SHIFT;
543 gpio_cfg |= (uint32_t)dw3 << GPE0_DW3_SHIFT;
544 }
545
546 gpio_cfg_reg = read32((void *)pmc_bar + GPIO_GPE_CFG) & ~gpio_cfg_mask;
547 gpio_cfg_reg |= gpio_cfg & gpio_cfg_mask;
548
549 write32((void *)pmc_bar + GPIO_GPE_CFG, gpio_cfg_reg);
550
551 /* Set the routes in the GPIO communities as well. */
552 gpio_route_gpe(dw1, dw2, dw3);
553}