mb/google/brya/var/uldrenite: Generate RAM ID and SPD file
[coreboot.git] / src / soc / intel / alderlake / pmc.c
blob8930a06251c4f952c3622f58c3780a2dc3a10c2c
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 /*
4 * This file is created based on Intel Alder Lake Processor PCH Datasheet
5 * Document number: 621483
6 * Chapter number: 4
7 */
9 #include <acpi/acpigen.h>
10 #include <console/console.h>
11 #include <device/mmio.h>
12 #include <device/device.h>
13 #include <drivers/intel/pmc_mux/chip.h>
14 #include <intelblocks/acpi.h>
15 #include <intelblocks/pmc.h>
16 #include <intelblocks/pmc_ipc.h>
17 #include <intelblocks/pmclib.h>
18 #include <intelblocks/rtc.h>
19 #include <soc/cpu.h>
20 #include <soc/pci_devs.h>
21 #include <soc/pm.h>
22 #include <soc/soc_chip.h>
23 #include <static.h>
24 #include <stdint.h>
25 #include <bootstate.h>
27 #define PMC_HID "INTC1026"
29 static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
31 uint32_t reg;
32 uint8_t *pmcbase = pmc_mmio_regs();
34 printk(BIOS_DEBUG, "%sabling Deep S%c\n",
35 enable ? "En" : "Dis", sx + '0');
36 reg = read32(pmcbase + offset);
37 if (enable)
38 reg |= mask;
39 else
40 reg &= ~mask;
41 write32(pmcbase + offset, reg);
44 static void config_deep_s5(int on_ac, int on_dc)
46 /* Treat S4 the same as S5. */
47 config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac);
48 config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc);
49 config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac);
50 config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc);
53 static void config_deep_s3(int on_ac, int on_dc)
55 config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac);
56 config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc);
59 static void config_deep_sx(uint32_t deepsx_config)
61 uint32_t reg;
62 uint8_t *pmcbase = pmc_mmio_regs();
64 reg = read32(pmcbase + DSX_CFG);
65 reg &= ~DSX_CFG_MASK;
66 reg |= deepsx_config;
67 write32(pmcbase + DSX_CFG, reg);
70 static void soc_pmc_enable(struct device *dev)
72 const config_t *config = config_of_soc();
74 rtc_init();
76 pmc_set_power_failure_state(true);
77 pmc_gpe_init();
79 config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
80 config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
81 config_deep_sx(config->deep_sx_config);
84 static void soc_pmc_read_resources(struct device *dev)
86 struct resource *res;
88 /* Add the fixed MMIO resource */
89 mmio_range(dev, PWRMBASE, PCH_PWRM_BASE_ADDRESS, PCH_PWRM_BASE_SIZE);
91 /* Add the fixed I/O resource */
92 res = new_resource(dev, 1);
93 res->base = (resource_t)ACPI_BASE_ADDRESS;
94 res->size = (resource_t)ACPI_BASE_SIZE;
95 res->limit = res->base + res->size - 1;
96 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
99 static void soc_pmc_fill_ssdt(const struct device *dev)
101 const char *scope = acpi_device_scope(dev);
102 const char *name = acpi_device_name(dev);
103 if (!scope || !name)
104 return;
106 acpigen_write_scope(scope);
107 acpigen_write_device(name);
109 acpigen_write_name_string("_HID", PMC_HID);
110 acpigen_write_name_string("_DDN", "Intel(R) Alder Lake IPC Controller");
111 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
114 * Part of the PCH's reserved 32 MB MMIO range (0xFC800000 - 0xFE7FFFFF).
115 * The PMC gets 0xFE000000 - 0xFE00FFFF.
117 acpigen_write_name("_CRS");
118 acpigen_write_resourcetemplate_header();
119 acpigen_write_mem32fixed(1, PCH_PWRM_BASE_ADDRESS, PCH_PWRM_BASE_SIZE);
120 acpigen_write_resourcetemplate_footer();
122 /* Define IPC Write Method */
123 if (CONFIG(PMC_IPC_ACPI_INTERFACE))
124 pmc_ipc_acpi_fill_ssdt();
126 acpigen_pop_len(); /* PMC Device */
127 acpigen_pop_len(); /* Scope */
129 if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP)) {
130 const struct soc_pmc_lpm adl_pmc_lpm = {
131 .num_substates = 8,
132 .num_req_regs = 6,
133 .lpm_ipc_offset = 0x1000,
134 .req_reg_stride = 0x30,
135 .lpm_enable_mask = get_supported_lpm_mask(),
138 generate_acpi_power_engine_with_lpm(&adl_pmc_lpm);
141 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name,
142 dev_path(dev));
145 static void soc_pmc_init(struct device *dev)
148 * pmc_set_acpi_mode() should be delayed until BS_DEV_INIT in order
149 * to ensure the ordering does not break the assumptions that other
150 * drivers make about ACPI mode (e.g. Chrome EC). Since it disables
151 * ACPI mode, other drivers may take different actions based on this
152 * (e.g. Chrome EC will flush any pending hostevent bits). Because
153 * TGL has its PMC device available for device_operations, it can be
154 * done from the "ops->init" callback.
156 pmc_set_acpi_mode();
159 * Disable ACPI PM timer based on Kconfig
161 * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
162 * Disabling ACPI PM timer also switches off TCO
164 if (!CONFIG(USE_PM_ACPI_TIMER))
165 setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL, ACPI_TIM_DIS);
168 static void pm1_enable_pwrbtn_smi(void *unused)
170 /* Enable power button SMI after BS_DEV_INIT_CHIPS (FSP-S) is done. */
171 pmc_update_pm1_enable(PWRBTN_EN);
174 BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL);
177 * `pmc_final` function is native implementation of equivalent events performed by
178 * each FSP NotifyPhase() API invocations.
181 * Clear PMCON status bits (Global Reset/Power Failure/Host Reset Status bits)
183 * Perform the PMCON status bit clear operation from `.final`
184 * to cover any such chances where later boot stage requested a global
185 * reset and PMCON status bit remains set.
187 static void pmc_final(struct device *dev)
189 pmc_clear_pmcon_sts();
192 struct device_operations pmc_ops = {
193 .read_resources = soc_pmc_read_resources,
194 .set_resources = noop_set_resources,
195 .init = soc_pmc_init,
196 .enable = soc_pmc_enable,
197 #if CONFIG(HAVE_ACPI_TABLES)
198 .acpi_fill_ssdt = soc_pmc_fill_ssdt,
199 #endif
200 .scan_bus = scan_static_bus,
201 .final = pmc_final,