blob: e1d60915f55a4826aecda60d642d796dc736cbda [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glassc7805d52016-03-11 22:07:25 -07002/*
3 * From coreboot src/soc/intel/broadwell/romstage/power_state.c
4 *
5 * Copyright (C) 2016 Google, Inc.
Simon Glassc7805d52016-03-11 22:07:25 -07006 */
7
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glassc7805d52016-03-11 22:07:25 -07009#include <pci.h>
10#include <asm/io.h>
11#include <asm/intel_regs.h>
12#include <asm/arch/iomap.h>
13#include <asm/arch/lpc.h>
14#include <asm/arch/pch.h>
15#include <asm/arch/pm.h>
16
17/* Return 0, 3, or 5 to indicate the previous sleep state. */
18static int prev_sleep_state(struct chipset_power_state *ps)
19{
20 /* Default to S0. */
21 int prev_sleep_state = SLEEP_STATE_S0;
22
23 if (ps->pm1_sts & WAK_STS) {
24 switch ((ps->pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) {
Simon Glassc7805d52016-03-11 22:07:25 -070025 case SLP_TYP_S3:
Simon Glasse6ad2022020-07-09 18:43:16 -060026 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME))
27 prev_sleep_state = SLEEP_STATE_S3;
Simon Glassc7805d52016-03-11 22:07:25 -070028 break;
Simon Glassc7805d52016-03-11 22:07:25 -070029 case SLP_TYP_S5:
30 prev_sleep_state = SLEEP_STATE_S5;
31 break;
32 }
33 /* Clear SLP_TYP. */
34 outl(ps->pm1_cnt & ~(SLP_TYP), ACPI_BASE_ADDRESS + PM1_CNT);
35 }
36
37 if (ps->gen_pmcon3 & (PWR_FLR | SUS_PWR_FLR))
38 prev_sleep_state = SLEEP_STATE_S5;
39
40 return prev_sleep_state;
41}
42
43static void dump_power_state(struct chipset_power_state *ps)
44{
45 debug("PM1_STS: %04x\n", ps->pm1_sts);
46 debug("PM1_EN: %04x\n", ps->pm1_en);
47 debug("PM1_CNT: %08x\n", ps->pm1_cnt);
48 debug("TCO_STS: %04x %04x\n", ps->tco1_sts, ps->tco2_sts);
49
50 debug("GPE0_STS: %08x %08x %08x %08x\n",
51 ps->gpe0_sts[0], ps->gpe0_sts[1],
52 ps->gpe0_sts[2], ps->gpe0_sts[3]);
53 debug("GPE0_EN: %08x %08x %08x %08x\n",
54 ps->gpe0_en[0], ps->gpe0_en[1],
55 ps->gpe0_en[2], ps->gpe0_en[3]);
56
57 debug("GEN_PMCON: %04x %04x %04x\n",
58 ps->gen_pmcon1, ps->gen_pmcon2, ps->gen_pmcon3);
59
60 debug("Previous Sleep State: S%d\n",
61 ps->prev_sleep_state);
62}
63
64/* Fill power state structure from ACPI PM registers */
65void power_state_get(struct udevice *pch_dev, struct chipset_power_state *ps)
66{
67 ps->pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS);
68 ps->pm1_en = inw(ACPI_BASE_ADDRESS + PM1_EN);
69 ps->pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
70 ps->tco1_sts = inw(ACPI_BASE_ADDRESS + TCO1_STS);
71 ps->tco2_sts = inw(ACPI_BASE_ADDRESS + TCO2_STS);
72 ps->gpe0_sts[0] = inl(ACPI_BASE_ADDRESS + GPE0_STS(0));
73 ps->gpe0_sts[1] = inl(ACPI_BASE_ADDRESS + GPE0_STS(1));
74 ps->gpe0_sts[2] = inl(ACPI_BASE_ADDRESS + GPE0_STS(2));
75 ps->gpe0_sts[3] = inl(ACPI_BASE_ADDRESS + GPE0_STS(3));
76 ps->gpe0_en[0] = inl(ACPI_BASE_ADDRESS + GPE0_EN(0));
77 ps->gpe0_en[1] = inl(ACPI_BASE_ADDRESS + GPE0_EN(1));
78 ps->gpe0_en[2] = inl(ACPI_BASE_ADDRESS + GPE0_EN(2));
79 ps->gpe0_en[3] = inl(ACPI_BASE_ADDRESS + GPE0_EN(3));
80
81 dm_pci_read_config16(pch_dev, GEN_PMCON_1, &ps->gen_pmcon1);
82 dm_pci_read_config16(pch_dev, GEN_PMCON_2, &ps->gen_pmcon2);
83 dm_pci_read_config16(pch_dev, GEN_PMCON_3, &ps->gen_pmcon3);
84
85 ps->prev_sleep_state = prev_sleep_state(ps);
86
87 dump_power_state(ps);
88}