1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
5 #include <device/mmio.h>
6 #include <device/device.h>
7 #include <intelblocks/acpi.h>
8 #include <intelblocks/pmc.h>
9 #include <intelblocks/pmclib.h>
10 #include <intelblocks/rtc.h>
11 #include <soc/pci_devs.h>
17 static void pm1_enable_pwrbtn_smi(void *unused
)
20 * Enable power button SMI only before jumping to payload. This ensures
22 * 1. Power button SMI is enabled only after coreboot is done.
23 * 2. On resume path, power button SMI is not enabled and thus avoids
24 * any shutdowns because of power button presses due to power button
25 * press in resume path.
27 pmc_update_pm1_enable(PWRBTN_EN
);
30 BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD
, BS_ON_EXIT
, pm1_enable_pwrbtn_smi
, NULL
);
32 static void config_deep_sX(uint32_t offset
, uint32_t mask
, int sx
, int enable
)
35 uint8_t *pmcbase
= pmc_mmio_regs();
37 printk(BIOS_DEBUG
, "%sabling Deep S%c\n",
38 enable
? "En" : "Dis", sx
+ '0');
39 reg
= read32(pmcbase
+ offset
);
44 write32(pmcbase
+ offset
, reg
);
47 static void config_deep_s5(int on_ac
, int on_dc
)
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
);
56 static void config_deep_s3(int on_ac
, int on_dc
)
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
);
62 static void config_deep_sx(uint32_t deepsx_config
)
65 uint8_t *pmcbase
= pmc_mmio_regs();
67 reg
= read32(pmcbase
+ DSX_CFG
);
70 write32(pmcbase
+ DSX_CFG
, reg
);
73 static void soc_pmc_read_resources(struct device
*dev
)
77 /* Add the fixed MMIO resource */
78 mmio_range(dev
, PWRMBASE
, PCH_PWRM_BASE_ADDRESS
, PCH_PWRM_BASE_SIZE
);
80 /* Add the fixed I/O resource */
81 res
= new_resource(dev
, 1);
82 res
->base
= (resource_t
)ACPI_BASE_ADDRESS
;
83 res
->size
= (resource_t
)ACPI_BASE_SIZE
;
84 res
->limit
= res
->base
+ res
->size
- 1;
85 res
->flags
= IORESOURCE_IO
| IORESOURCE_ASSIGNED
| IORESOURCE_FIXED
;
88 static void soc_pmc_enable(struct device
*dev
)
90 const config_t
*config
= config_of_soc();
94 pmc_set_power_failure_state(true);
97 config_deep_s3(config
->deep_s3_enable_ac
, config
->deep_s3_enable_dc
);
98 config_deep_s5(config
->deep_s5_enable_ac
, config
->deep_s5_enable_dc
);
99 config_deep_sx(config
->deep_sx_config
);
102 static void soc_pmc_init(struct device
*dev
)
105 * PMC initialization happens earlier for this SoC because FSP-Silicon
106 * init hides PMC from PCI bus. However, pmc_set_acpi_mode, which
107 * disables ACPI mode doesn't need to happen that early and can be
108 * delayed till typical BS_DEV_INIT. This ensures that ACPI mode
109 * disabling happens the same way for all SoCs and hence the ordering of
110 * events is the same.
112 * This is important to ensure that the ordering does not break the
113 * assumptions of any other drivers (e.g. ChromeEC) which could be
114 * taking different actions based on disabling of ACPI (e.g. flushing of
115 * all EC hostevent bits).
117 * Because the device is set as `hidden` in the devicetree, enumeration
118 * is skipped, but the device callbacks are still called as if it were
124 * Disable ACPI PM timer based on Kconfig
126 * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
127 * Disabling ACPI PM timer also switches off TCO.
129 if (!CONFIG(USE_PM_ACPI_TIMER
))
130 setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL
, ACPI_TIM_DIS
);
133 static void pmc_fill_ssdt(const struct device
*dev
)
135 if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP
))
136 generate_acpi_power_engine();
140 * `pmc_final` function is native implementation of equivalent events performed by
141 * each FSP NotifyPhase() API invocations.
144 * Clear PMCON status bits (Global Reset/Power Failure/Host Reset Status bits)
146 * Perform the PMCON status bit clear operation from `.final`
147 * to cover any such chances where later boot stage requested a global
148 * reset and PMCON status bit remains set.
150 static void pmc_final(struct device
*dev
)
152 pmc_clear_pmcon_sts();
155 struct device_operations pmc_ops
= {
156 .read_resources
= soc_pmc_read_resources
,
157 .set_resources
= noop_set_resources
,
158 .init
= soc_pmc_init
,
159 .enable
= soc_pmc_enable
,
160 #if CONFIG(HAVE_ACPI_TABLES)
161 .acpi_fill_ssdt
= pmc_fill_ssdt
,
163 .scan_bus
= scan_static_bus
,