blob: 71d1ef0c0cb9f38df1f1081f6947ff8ecfbdcab2 [file] [log] [blame]
Angel Pons3bd1e3d2020-04-05 15:47:17 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy1d14b3e2015-05-12 18:23:27 -07002
Angel Pons72b8fd52021-09-28 10:28:38 +02003#include <arch/io.h>
Subrata Banikc1d99c92017-12-14 16:28:45 +05304#include <bootstate.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -07005#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02006#include <device/mmio.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -07007#include <device/device.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +02008#include <device/pci_ops.h>
Subrata Banik2153ea52017-11-22 15:38:19 +05309#include <intelblocks/pmc.h>
Shaunak Sahad3476802017-07-08 01:08:40 -070010#include <intelblocks/pmclib.h>
Subrata Banik2153ea52017-11-22 15:38:19 +053011#include <intelblocks/rtc.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070012#include <soc/pci_devs.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070013#include <soc/pm.h>
Subrata Banik2153ea52017-11-22 15:38:19 +053014
Elyes HAOUASc3385072019-03-21 15:38:06 +010015#include "chip.h"
16
Subrata Banik2153ea52017-11-22 15:38:19 +053017/* Fill up PMC resource structure */
18int pmc_soc_get_resources(struct pmc_resource_config *cfg)
19{
20 cfg->pwrmbase_offset = PWRMBASE;
21 cfg->pwrmbase_addr = PCH_PWRM_BASE_ADDRESS;
22 cfg->pwrmbase_size = PCH_PWRM_BASE_SIZE;
23 cfg->abase_offset = ABASE;
24 cfg->abase_addr = ACPI_BASE_ADDRESS;
25 cfg->abase_size = ACPI_BASE_SIZE;
26
27 return 0;
28}
Lee Leahy1d14b3e2015-05-12 18:23:27 -070029
Lee Leahy1d14b3e2015-05-12 18:23:27 -070030static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
31{
32 uint32_t reg;
33 uint8_t *pmcbase = pmc_mmio_regs();
34
35 printk(BIOS_DEBUG, "%sabling Deep S%c\n",
36 enable ? "En" : "Dis", sx + '0');
37 reg = read32(pmcbase + offset);
38 if (enable)
39 reg |= mask;
40 else
41 reg &= ~mask;
42 write32(pmcbase + offset, reg);
43}
44
Duncan Laurie1fe32d62017-04-10 21:02:13 -070045static void config_deep_s5(int on_ac, int on_dc)
Lee Leahy1d14b3e2015-05-12 18:23:27 -070046{
47 /* Treat S4 the same as S5. */
Duncan Laurie1fe32d62017-04-10 21:02:13 -070048 config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac);
49 config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc);
50 config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac);
51 config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc);
Lee Leahy1d14b3e2015-05-12 18:23:27 -070052}
53
Duncan Laurie1fe32d62017-04-10 21:02:13 -070054static void config_deep_s3(int on_ac, int on_dc)
Lee Leahy1d14b3e2015-05-12 18:23:27 -070055{
Duncan Laurie1fe32d62017-04-10 21:02:13 -070056 config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac);
57 config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc);
Lee Leahy1d14b3e2015-05-12 18:23:27 -070058}
59
Duncan Laurieedf1cb72015-07-24 15:37:13 -070060static void config_deep_sx(uint32_t deepsx_config)
61{
62 uint32_t reg;
63 uint8_t *pmcbase = pmc_mmio_regs();
64
65 reg = read32(pmcbase + DSX_CFG);
66 reg &= ~DSX_CFG_MASK;
67 reg |= deepsx_config;
68 write32(pmcbase + DSX_CFG, reg);
69}
70
Subrata Banik2153ea52017-11-22 15:38:19 +053071void pmc_soc_init(struct device *dev)
Lee Leahy1d14b3e2015-05-12 18:23:27 -070072{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +030073 const config_t *config = config_of(dev);
Angel Pons72b8fd52021-09-28 10:28:38 +020074 uint8_t *const pwrmbase = pmc_mmio_regs();
75 uint32_t reg32;
Lee Leahy1d14b3e2015-05-12 18:23:27 -070076
Subrata Banik2153ea52017-11-22 15:38:19 +053077 rtc_init();
Lee Leahy1d14b3e2015-05-12 18:23:27 -070078
Nico Huber04ce8fe2019-08-05 19:33:09 +020079 pmc_set_power_failure_state(true);
80 pmc_gpe_init();
Lee Leahy1d14b3e2015-05-12 18:23:27 -070081
Angel Pons72b8fd52021-09-28 10:28:38 +020082 /* SLP_S4=4s, SLP_S3=50ms, disable SLP_X stretching after SUS loss. */
83 pci_update_config32(dev, GEN_PMCON_B, ~(S4MAW_MASK | SLP_S3_MIN_ASST_WDTH_MASK),
84 S4MAW_4S | SLP_S3_MIN_ASST_WDTH_50MS | DIS_SLP_X_STRCH_SUS_UP);
85
86 /* Enable SCI and clear SLP requests. */
87 reg32 = inl(ACPI_BASE_ADDRESS + PM1_CNT);
88 reg32 &= ~SLP_TYP;
89 reg32 |= SCI_EN;
90 outl(reg32, ACPI_BASE_ADDRESS + PM1_CNT);
91
Subrata Banik2153ea52017-11-22 15:38:19 +053092 pmc_set_acpi_mode();
Lee Leahy1d14b3e2015-05-12 18:23:27 -070093
Duncan Laurie1fe32d62017-04-10 21:02:13 -070094 config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
95 config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
Duncan Laurieedf1cb72015-07-24 15:37:13 -070096 config_deep_sx(config->deep_sx_config);
Aaron Durbin6fd5bd22015-08-04 21:04:02 -050097
98 /* Clear registers that contain write-1-to-clear bits. */
Angel Pons72b8fd52021-09-28 10:28:38 +020099 pci_or_config32(dev, GEN_PMCON_B, 0);
100 pci_or_config32(dev, GEN_PMCON_B, 0);
101 setbits32(pwrmbase + GBLRST_CAUSE0, 0);
102 setbits32(pwrmbase + GBLRST_CAUSE1, 0);
Michael Niewöhner68bacc22021-09-24 23:57:37 +0200103
104 /*
105 * Disable ACPI PM timer based on Kconfig
106 *
107 * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
108 * Disabling ACPI PM timer also switches off TCO.
109 */
110 if (!CONFIG(USE_PM_ACPI_TIMER))
111 setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL, ACPI_TIM_DIS);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700112}
Subrata Banik7f4ec962017-12-19 10:27:45 +0530113
Subrata Banikc1d99c92017-12-14 16:28:45 +0530114static void pm1_enable_pwrbtn_smi(void *unused)
115{
116 /*
117 * Enable power button SMI only before jumping to payload. This ensures
118 * that:
119 * 1. Power button SMI is enabled only after coreboot is done.
120 * 2. On resume path, power button SMI is not enabled and thus avoids
121 * any shutdowns because of power button presses due to power button
122 * press in resume path.
123 */
124 pmc_update_pm1_enable(PWRBTN_EN);
125}
126
127BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL);
128
Furquan Shaikh99d258a2018-10-05 11:04:01 -0700129/*
130 * Check if WAKE# pin is enabled based on DSX_EN_WAKE_PIN setting in
131 * deep_sx_config. If WAKE# pin is not enabled, then PCI Express Wake Disable
132 * bit needs to be set in PM1_EN to avoid unnecessary wakes caused by WAKE#
133 * pin.
134 */
135static void pm1_handle_wake_pin(void *unused)
136{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300137 const config_t *conf = config_of_soc();
Furquan Shaikh99d258a2018-10-05 11:04:01 -0700138
139 /* If WAKE# pin is enabled, bail out early. */
140 if (conf->deep_sx_config & DSX_EN_WAKE_PIN)
141 return;
142
143 pmc_update_pm1_enable(PCIEXPWAK_DIS);
144}
145
146BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_handle_wake_pin, NULL);
Arthur Heymans897d63a2023-02-01 11:10:00 +0100147BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, pm1_handle_wake_pin, NULL);