blob: 27d00d7ffdc5d3b3ae00239c328172d37ee2cc14 [file] [log] [blame]
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <bootstate.h>
4#include <console/console.h>
5#include <device/device.h>
6#include <device/mmio.h>
Tim Wawrzynczak46c5f8f2021-07-01 08:45:47 -06007#include <intelblocks/acpi.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07008#include <intelblocks/pmc.h>
9#include <intelblocks/pmclib.h>
10#include <intelblocks/rtc.h>
11#include <soc/pci_devs.h>
12#include <soc/pm.h>
13#include <soc/soc_chip.h>
14
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070015static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
16{
17 uint32_t reg;
18 uint8_t *pmcbase = pmc_mmio_regs();
19
20 printk(BIOS_DEBUG, "%sabling Deep S%c\n",
21 enable ? "En" : "Dis", sx + '0');
22 reg = read32(pmcbase + offset);
23 if (enable)
24 reg |= mask;
25 else
26 reg &= ~mask;
27 write32(pmcbase + offset, reg);
28}
29
30static void config_deep_s5(int on_ac, int on_dc)
31{
32 /* Treat S4 the same as S5. */
33 config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac);
34 config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc);
35 config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac);
36 config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc);
37}
38
39static void config_deep_s3(int on_ac, int on_dc)
40{
41 config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac);
42 config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc);
43}
44
45static void config_deep_sx(uint32_t deepsx_config)
46{
47 uint32_t reg;
48 uint8_t *pmcbase = pmc_mmio_regs();
49
50 reg = read32(pmcbase + DSX_CFG);
51 reg &= ~DSX_CFG_MASK;
52 reg |= deepsx_config;
53 write32(pmcbase + DSX_CFG, reg);
54}
55
Michael Niewöhner38bf4962021-09-27 23:55:05 +020056static void soc_pmc_enable(struct device *dev)
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070057{
58 const config_t *config = config_of_soc();
59
60 rtc_init();
61
62 pmc_set_power_failure_state(true);
63 pmc_gpe_init();
64
65 config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
66 config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
67 config_deep_sx(config->deep_sx_config);
68}
69
70static void soc_pmc_read_resources(struct device *dev)
71{
72 struct resource *res;
73
Subrata Banikc8b96082022-11-04 22:14:38 +053074 mmio_resource_kb(dev, PWRMBASE, PCH_PWRM_BASE_ADDRESS / KiB,
75 PCH_PWRM_BASE_SIZE / KiB);
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070076
77 res = new_resource(dev, 1);
78 res->base = (resource_t)ACPI_BASE_ADDRESS;
79 res->size = (resource_t)ACPI_BASE_SIZE;
Tim Wawrzynczak2f8f1b42022-06-27 11:10:26 -060080 res->limit = res->base + res->size - 1;
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070081 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
82}
83
Michael Niewöhner38bf4962021-09-27 23:55:05 +020084static void soc_pmc_init(struct device *dev)
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070085{
86 /*
87 * pmc_set_acpi_mode() should be delayed until BS_DEV_INIT in order
88 * to ensure the ordering does not break the assumptions that other
89 * drivers make about ACPI mode (e.g. Chrome EC). Since it disables
90 * ACPI mode, other drivers may take different actions based on this
91 * (e.g. Chrome EC will flush any pending hostevent bits). Because
92 * EHL has its PMC device available for device_operations, it can be
93 * done from the "ops->init" callback.
94 */
95 pmc_set_acpi_mode();
Michael Niewöhner01b3c402021-09-27 18:39:41 +020096
97 /*
98 * Disable ACPI PM timer based on Kconfig
99 *
100 * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
101 * Disabling ACPI PM timer also switches off TCO
102 */
103 if (!CONFIG(USE_PM_ACPI_TIMER))
Michael Niewöhner6eaffcd2021-09-27 18:45:10 +0200104 setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL, ACPI_TIM_DIS);
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700105}
106
Tim Wawrzynczak46c5f8f2021-07-01 08:45:47 -0600107static void pmc_fill_ssdt(const struct device *dev)
108{
109 if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP))
110 generate_acpi_power_engine();
111}
112
Subrata Banikb3671ec2022-02-06 18:21:50 +0530113/*
114 * `pmc_final` function is native implementation of equivalent events performed by
115 * each FSP NotifyPhase() API invocations.
116 *
117 *
118 * Clear PMCON status bits (Global Reset/Power Failure/Host Reset Status bits)
119 *
120 * Perform the PMCON status bit clear operation from `.final`
121 * to cover any such chances where later boot stage requested a global
122 * reset and PMCON status bit remains set.
123 */
124static void pmc_final(struct device *dev)
125{
126 pmc_clear_pmcon_sts();
127}
128
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700129struct device_operations pmc_ops = {
130 .read_resources = soc_pmc_read_resources,
131 .set_resources = noop_set_resources,
Michael Niewöhner38bf4962021-09-27 23:55:05 +0200132 .init = soc_pmc_init,
133 .enable = soc_pmc_enable,
Tim Wawrzynczak46c5f8f2021-07-01 08:45:47 -0600134#if CONFIG(HAVE_ACPI_TABLES)
135 .acpi_fill_ssdt = pmc_fill_ssdt,
136#endif
Subrata Banikb3671ec2022-02-06 18:21:50 +0530137 .final = pmc_final,
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700138};