blob: 03399c312e373764daa52d5d75db0604e8e5931f [file] [log] [blame]
Subrata Banik2871e0e2020-09-27 11:30:58 +05301/* SPDX-License-Identifier: GPL-2.0-only */
2
3/*
4 * This file is created based on Intel Alder Lake Processor PCH Datasheet
5 * Document number: 621483
6 * Chapter number: 4
7 */
8
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/pmc.h>
15#include <intelblocks/pmclib.h>
16#include <intelblocks/rtc.h>
17#include <soc/pci_devs.h>
18#include <soc/pm.h>
19#include <soc/soc_chip.h>
20#include <stdint.h>
Kane Chen3aee3ad2021-05-04 09:53:38 +080021#include <bootstate.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053022
23#define PMC_HID "INTC1026"
24
25enum pch_pmc_xtal pmc_get_xtal_freq(void)
26{
27 uint8_t *const pmcbase = pmc_mmio_regs();
28
29 return PCH_EPOC_XTAL_FREQ(read32(pmcbase + PCH_PMC_EPOC));
30}
31
32static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
33{
34 uint32_t reg;
35 uint8_t *pmcbase = pmc_mmio_regs();
36
37 printk(BIOS_DEBUG, "%sabling Deep S%c\n",
38 enable ? "En" : "Dis", sx + '0');
39 reg = read32(pmcbase + offset);
40 if (enable)
41 reg |= mask;
42 else
43 reg &= ~mask;
44 write32(pmcbase + offset, reg);
45}
46
47static void config_deep_s5(int on_ac, int on_dc)
48{
49 /* Treat S4 the same as S5. */
50 config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac);
51 config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc);
52 config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac);
53 config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc);
54}
55
56static void config_deep_s3(int on_ac, int on_dc)
57{
58 config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac);
59 config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc);
60}
61
62static void config_deep_sx(uint32_t deepsx_config)
63{
64 uint32_t reg;
65 uint8_t *pmcbase = pmc_mmio_regs();
66
67 reg = read32(pmcbase + DSX_CFG);
68 reg &= ~DSX_CFG_MASK;
69 reg |= deepsx_config;
70 write32(pmcbase + DSX_CFG, reg);
71}
72
73static void pmc_init(struct device *dev)
74{
75 const config_t *config = config_of_soc();
76
77 rtc_init();
78
79 pmc_set_power_failure_state(true);
80 pmc_gpe_init();
81
82 config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
83 config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
84 config_deep_sx(config->deep_sx_config);
85}
86
87static void soc_pmc_read_resources(struct device *dev)
88{
89 struct resource *res;
90
91 /* Add the fixed MMIO resource */
92 mmio_resource(dev, 0, PCH_PWRM_BASE_ADDRESS / KiB, PCH_PWRM_BASE_SIZE / KiB);
93
94 /* Add the fixed I/O resource */
95 res = new_resource(dev, 1);
96 res->base = (resource_t)ACPI_BASE_ADDRESS;
97 res->size = (resource_t)ACPI_BASE_SIZE;
98 res->limit = res->base + res->size - 1;
99 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
100}
101
102static void soc_pmc_fill_ssdt(const struct device *dev)
103{
104 const char *scope = acpi_device_scope(dev);
105 const char *name = acpi_device_name(dev);
106 if (!scope || !name)
107 return;
108
109 acpigen_write_scope(scope);
110 acpigen_write_device(name);
111
112 acpigen_write_name_string("_HID", PMC_HID);
113 acpigen_write_name_string("_DDN", "Intel(R) Alder Lake IPC Controller");
114
115 /*
116 * Part of the PCH's reserved 32 MB MMIO range (0xFC800000 - 0xFE7FFFFF).
117 * The PMC gets 0xFE000000 - 0xFE00FFFF.
118 */
119 acpigen_write_name("_CRS");
120 acpigen_write_resourcetemplate_header();
121 acpigen_write_mem32fixed(1, PCH_PWRM_BASE_ADDRESS, PCH_PWRM_BASE_SIZE);
122 acpigen_write_resourcetemplate_footer();
123
124 acpigen_pop_len(); /* PMC Device */
125 acpigen_pop_len(); /* Scope */
126
127 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name,
128 dev_path(dev));
129}
130
131static void soc_acpi_mode_init(struct device *dev)
132{
133 /*
134 * pmc_set_acpi_mode() should be delayed until BS_DEV_INIT in order
135 * to ensure the ordering does not break the assumptions that other
136 * drivers make about ACPI mode (e.g. Chrome EC). Since it disables
137 * ACPI mode, other drivers may take different actions based on this
138 * (e.g. Chrome EC will flush any pending hostevent bits). Because
139 * TGL has its PMC device available for device_operations, it can be
140 * done from the "ops->init" callback.
141 */
142 pmc_set_acpi_mode();
143}
144
Kane Chen3aee3ad2021-05-04 09:53:38 +0800145static void pm1_enable_pwrbtn_smi(void *unused)
146{
147 /* Enable power button SMI after BS_DEV_INIT_CHIPS (FSP-S) is done. */
148 pmc_update_pm1_enable(PWRBTN_EN);
149}
150
151BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL);
152
Subrata Banik2871e0e2020-09-27 11:30:58 +0530153struct device_operations pmc_ops = {
154 .read_resources = soc_pmc_read_resources,
155 .set_resources = noop_set_resources,
156 .init = soc_acpi_mode_init,
157 .enable = pmc_init,
158#if CONFIG(HAVE_ACPI_TABLES)
159 .acpi_fill_ssdt = soc_pmc_fill_ssdt,
160#endif
161 .scan_bus = scan_static_bus,
162};