blob: f0a32b9379c2f296312f65512319b6724d5fd3c3 [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lijian Zhaoac87a982017-08-28 17:46:55 -07002
Subrata Banik0baad612017-11-23 13:58:34 +05303#include <bootstate.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -07004#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -07006#include <device/device.h>
Tim Wawrzynczak6d444372021-07-01 08:42:01 -06007#include <intelblocks/acpi.h>
Subrata Banik0baad612017-11-23 13:58:34 +05308#include <intelblocks/pmc.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -07009#include <intelblocks/pmclib.h>
10#include <intelblocks/rtc.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -070011#include <soc/pci_devs.h>
12#include <soc/pm.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -070013
Elyes HAOUASc3385072019-03-21 15:38:06 +010014#include "chip.h"
15
Krzysztof Sywula42a66fb2019-03-13 16:48:56 -070016static void pm1_enable_pwrbtn_smi(void *unused)
17{
18 /*
19 * Enable power button SMI only before jumping to payload. This ensures
20 * that:
21 * 1. Power button SMI is enabled only after coreboot is done.
22 * 2. On resume path, power button SMI is not enabled and thus avoids
23 * any shutdowns because of power button presses due to power button
24 * press in resume path.
25 */
26 pmc_update_pm1_enable(PWRBTN_EN);
27}
28
29BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL);
30
Lijian Zhaoac87a982017-08-28 17:46:55 -070031static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
32{
33 uint32_t reg;
34 uint8_t *pmcbase = pmc_mmio_regs();
35
36 printk(BIOS_DEBUG, "%sabling Deep S%c\n",
37 enable ? "En" : "Dis", sx + '0');
38 reg = read32(pmcbase + offset);
39 if (enable)
40 reg |= mask;
41 else
42 reg &= ~mask;
43 write32(pmcbase + offset, reg);
44}
45
46static void config_deep_s5(int on_ac, int on_dc)
47{
48 /* Treat S4 the same as S5. */
49 config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac);
50 config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc);
51 config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac);
52 config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc);
53}
54
55static void config_deep_s3(int on_ac, int on_dc)
56{
57 config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac);
58 config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc);
59}
60
61static void config_deep_sx(uint32_t deepsx_config)
62{
63 uint32_t reg;
64 uint8_t *pmcbase = pmc_mmio_regs();
65
66 reg = read32(pmcbase + DSX_CFG);
67 reg &= ~DSX_CFG_MASK;
68 reg |= deepsx_config;
69 write32(pmcbase + DSX_CFG, reg);
70}
71
Tim Wawrzynczakbd5b4aa2021-07-01 08:41:48 -060072static void soc_pmc_read_resources(struct device *dev)
73{
74 struct resource *res;
75
76 /* Add the fixed MMIO resource */
Kyösti Mälkki27d62992022-05-24 20:25:58 +030077 mmio_resource_kb(dev, 0, PCH_PWRM_BASE_ADDRESS / KiB, PCH_PWRM_BASE_SIZE / KiB);
Tim Wawrzynczakbd5b4aa2021-07-01 08:41:48 -060078
79 /* Add the fixed I/O resource */
80 res = new_resource(dev, 1);
81 res->base = (resource_t)ACPI_BASE_ADDRESS;
82 res->size = (resource_t)ACPI_BASE_SIZE;
83 res->limit = res->base + res->size - 1;
84 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
85}
86
Michael Niewöhner38bf4962021-09-27 23:55:05 +020087static void soc_pmc_enable(struct device *dev)
Lijian Zhaoac87a982017-08-28 17:46:55 -070088{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +030089 const config_t *config = config_of_soc();
Lijian Zhaoac87a982017-08-28 17:46:55 -070090
91 rtc_init();
92
Nico Huber733c28f2019-08-05 19:33:09 +020093 pmc_set_power_failure_state(true);
94 pmc_gpe_init();
Lijian Zhaoac87a982017-08-28 17:46:55 -070095
Lijian Zhaoac87a982017-08-28 17:46:55 -070096 config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
97 config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
98 config_deep_sx(config->deep_sx_config);
99}
100
Michael Niewöhner38bf4962021-09-27 23:55:05 +0200101static void soc_pmc_init(struct device *dev)
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800102{
103 /*
104 * PMC initialization happens earlier for this SoC because FSP-Silicon
105 * init hides PMC from PCI bus. However, pmc_set_acpi_mode, which
106 * disables ACPI mode doesn't need to happen that early and can be
Furquan Shaikh67a489f2019-02-27 00:59:06 -0800107 * delayed till typical BS_DEV_INIT. This ensures that ACPI mode
108 * disabling happens the same way for all SoCs and hence the ordering of
109 * events is the same.
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800110 *
111 * This is important to ensure that the ordering does not break the
112 * assumptions of any other drivers (e.g. ChromeEC) which could be
113 * taking different actions based on disabling of ACPI (e.g. flushing of
114 * all EC hostevent bits).
Furquan Shaikh67a489f2019-02-27 00:59:06 -0800115 *
Tim Wawrzynczakbd5b4aa2021-07-01 08:41:48 -0600116 * Because the device is set as `hidden` in the devicetree, enumeration
117 * is skipped, but the device callbacks are still called as if it were
118 * found.
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800119 */
120 pmc_set_acpi_mode();
Michael Niewöhner68bacc22021-09-24 23:57:37 +0200121
122 /*
123 * Disable ACPI PM timer based on Kconfig
124 *
125 * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
126 * Disabling ACPI PM timer also switches off TCO.
127 */
128 if (!CONFIG(USE_PM_ACPI_TIMER))
129 setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL, ACPI_TIM_DIS);
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800130}
Furquan Shaikh67a489f2019-02-27 00:59:06 -0800131
Tim Wawrzynczak6d444372021-07-01 08:42:01 -0600132static void pmc_fill_ssdt(const struct device *dev)
133{
134 if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP))
135 generate_acpi_power_engine();
136}
137
Subrata Banikb3671ec2022-02-06 18:21:50 +0530138/*
139 * `pmc_final` function is native implementation of equivalent events performed by
140 * each FSP NotifyPhase() API invocations.
141 *
142 *
143 * Clear PMCON status bits (Global Reset/Power Failure/Host Reset Status bits)
144 *
145 * Perform the PMCON status bit clear operation from `.final`
146 * to cover any such chances where later boot stage requested a global
147 * reset and PMCON status bit remains set.
148 */
149static void pmc_final(struct device *dev)
150{
151 pmc_clear_pmcon_sts();
152}
153
Tim Wawrzynczakbd5b4aa2021-07-01 08:41:48 -0600154struct device_operations pmc_ops = {
155 .read_resources = soc_pmc_read_resources,
156 .set_resources = noop_set_resources,
Michael Niewöhner38bf4962021-09-27 23:55:05 +0200157 .init = soc_pmc_init,
158 .enable = soc_pmc_enable,
Tim Wawrzynczak6d444372021-07-01 08:42:01 -0600159#if CONFIG(HAVE_ACPI_TABLES)
160 .acpi_fill_ssdt = pmc_fill_ssdt,
161#endif
Tim Wawrzynczakbd5b4aa2021-07-01 08:41:48 -0600162 .scan_bus = scan_static_bus,
Subrata Banikb3671ec2022-02-06 18:21:50 +0530163 .final = pmc_final,
Tim Wawrzynczakbd5b4aa2021-07-01 08:41:48 -0600164};