blob: e4c100933c029d4a9f7b41faf6b590db017f99f6 [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>
21
22#define PMC_HID "INTC1026"
23
24enum pch_pmc_xtal pmc_get_xtal_freq(void)
25{
26 uint8_t *const pmcbase = pmc_mmio_regs();
27
28 return PCH_EPOC_XTAL_FREQ(read32(pmcbase + PCH_PMC_EPOC));
29}
30
31static 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
72static void pmc_init(struct device *dev)
73{
74 const config_t *config = config_of_soc();
75
76 rtc_init();
77
78 pmc_set_power_failure_state(true);
79 pmc_gpe_init();
80
81 config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
82 config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
83 config_deep_sx(config->deep_sx_config);
84}
85
86static void soc_pmc_read_resources(struct device *dev)
87{
88 struct resource *res;
89
90 /* Add the fixed MMIO resource */
91 mmio_resource(dev, 0, PCH_PWRM_BASE_ADDRESS / KiB, PCH_PWRM_BASE_SIZE / KiB);
92
93 /* Add the fixed I/O resource */
94 res = new_resource(dev, 1);
95 res->base = (resource_t)ACPI_BASE_ADDRESS;
96 res->size = (resource_t)ACPI_BASE_SIZE;
97 res->limit = res->base + res->size - 1;
98 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
99}
100
101static void soc_pmc_fill_ssdt(const struct device *dev)
102{
103 const char *scope = acpi_device_scope(dev);
104 const char *name = acpi_device_name(dev);
105 if (!scope || !name)
106 return;
107
108 acpigen_write_scope(scope);
109 acpigen_write_device(name);
110
111 acpigen_write_name_string("_HID", PMC_HID);
112 acpigen_write_name_string("_DDN", "Intel(R) Alder Lake IPC Controller");
113
114 /*
115 * Part of the PCH's reserved 32 MB MMIO range (0xFC800000 - 0xFE7FFFFF).
116 * The PMC gets 0xFE000000 - 0xFE00FFFF.
117 */
118 acpigen_write_name("_CRS");
119 acpigen_write_resourcetemplate_header();
120 acpigen_write_mem32fixed(1, PCH_PWRM_BASE_ADDRESS, PCH_PWRM_BASE_SIZE);
121 acpigen_write_resourcetemplate_footer();
122
123 acpigen_pop_len(); /* PMC Device */
124 acpigen_pop_len(); /* Scope */
125
126 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name,
127 dev_path(dev));
128}
129
130static void soc_acpi_mode_init(struct device *dev)
131{
132 /*
133 * pmc_set_acpi_mode() should be delayed until BS_DEV_INIT in order
134 * to ensure the ordering does not break the assumptions that other
135 * drivers make about ACPI mode (e.g. Chrome EC). Since it disables
136 * ACPI mode, other drivers may take different actions based on this
137 * (e.g. Chrome EC will flush any pending hostevent bits). Because
138 * TGL has its PMC device available for device_operations, it can be
139 * done from the "ops->init" callback.
140 */
141 pmc_set_acpi_mode();
142}
143
144struct device_operations pmc_ops = {
145 .read_resources = soc_pmc_read_resources,
146 .set_resources = noop_set_resources,
147 .init = soc_acpi_mode_init,
148 .enable = pmc_init,
149#if CONFIG(HAVE_ACPI_TABLES)
150 .acpi_fill_ssdt = soc_pmc_fill_ssdt,
151#endif
152 .scan_bus = scan_static_bus,
153};