1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Helper functions for dealing with power management registers
5 * and the differences between PCH variants.
9 * This file is created based on Intel Tiger Lake Processor PCH Datasheet
10 * Document number: 575857
14 #define __SIMPLE_DEVICE__
16 #include <acpi/acpi_pm.h>
17 #include <console/console.h>
18 #include <device/mmio.h>
19 #include <device/device.h>
20 #include <device/pci.h>
22 #include <intelblocks/pmclib.h>
23 #include <intelblocks/rtc.h>
24 #include <intelblocks/tco.h>
25 #include <intelpch/espi.h>
27 #include <soc/iomap.h>
28 #include <soc/pci_devs.h>
30 #include <soc/smbus.h>
31 #include <soc/soc_chip.h>
32 #include <security/vboot/vbnv.h>
39 const char *const *soc_smi_sts_array(size_t *a
)
41 static const char *const smi_sts_bits
[] = {
42 [BIOS_STS_BIT
] = "BIOS",
43 [LEGACY_USB_STS_BIT
] = "LEGACY_USB",
44 [SMI_ON_SLP_EN_STS_BIT
] = "SLP_SMI",
45 [APM_STS_BIT
] = "APM",
46 [SWSMI_TMR_STS_BIT
] = "SWSMI_TMR",
47 [PM1_STS_BIT
] = "PM1",
48 [GPE0_STS_BIT
] = "GPE0",
49 [GPIO_STS_BIT
] = "GPI",
50 [MCSMI_STS_BIT
] = "MCSMI",
51 [DEVMON_STS_BIT
] = "DEVMON",
52 [TCO_STS_BIT
] = "TCO",
53 [PERIODIC_STS_BIT
] = "PERIODIC",
54 [SERIRQ_SMI_STS_BIT
] = "SERIRQ_SMI",
55 [SMBUS_SMI_STS_BIT
] = "SMBUS_SMI",
56 [PCI_EXP_SMI_STS_BIT
] = "PCI_EXP_SMI",
57 [MONITOR_STS_BIT
] = "MONITOR",
58 [SPI_SMI_STS_BIT
] = "SPI",
59 [GPIO_UNLOCK_SMI_STS_BIT
] = "GPIO_UNLOCK",
60 [ESPI_SMI_STS_BIT
] = "ESPI_SMI",
63 *a
= ARRAY_SIZE(smi_sts_bits
);
71 const char *const *soc_tco_sts_array(size_t *a
)
73 static const char *const tco_sts_bits
[] = {
90 *a
= ARRAY_SIZE(tco_sts_bits
);
98 const char *const *soc_std_gpe_sts_array(size_t *a
)
100 static const char *const gpe_sts_bits
[] = {
111 [15] = "GPIO Tier-2",
116 *a
= ARRAY_SIZE(gpe_sts_bits
);
120 void pmc_set_disb(void)
122 /* Set the DISB after DRAM init */
124 /* Only care about bits [23:16] of register GEN_PMCON_A */
125 uint8_t *addr
= (uint8_t *)(pmc_mmio_regs() + GEN_PMCON_A
+ 2);
127 disb_val
= read8(addr
);
128 disb_val
|= (DISB
>> 16);
130 /* Don't clear bits that are write-1-to-clear */
131 disb_val
&= ~((MS4V
| SUS_PWR_FLR
) >> 16);
132 write8(addr
, disb_val
);
136 * PMC controller gets hidden from PCI bus
137 * during FSP-Silicon init call. Hence PWRMBASE
138 * can't be accessible using PCI configuration space
141 uint8_t *pmc_mmio_regs(void)
143 return (void *)(uintptr_t)PCH_PWRM_BASE_ADDRESS
;
146 uintptr_t soc_read_pmc_base(void)
148 return (uintptr_t)pmc_mmio_regs();
151 uint32_t *soc_pmc_etr_addr(void)
153 return (uint32_t *)(soc_read_pmc_base() + ETR
);
156 static void pmc_gpe0_different_values(const struct soc_intel_tigerlake_config
*config
)
158 bool result
= (config
->pmc_gpe0_dw0
!= config
->pmc_gpe0_dw1
) &&
159 (config
->pmc_gpe0_dw0
!= config
->pmc_gpe0_dw2
) &&
160 (config
->pmc_gpe0_dw1
!= config
->pmc_gpe0_dw2
);
165 void soc_get_gpi_gpe_configs(uint8_t *dw0
, uint8_t *dw1
, uint8_t *dw2
)
167 DEVTREE_CONST
struct soc_intel_tigerlake_config
*config
;
169 config
= config_of_soc();
171 pmc_gpe0_different_values(config
);
173 /* Assign to out variable */
174 *dw0
= config
->pmc_gpe0_dw0
;
175 *dw1
= config
->pmc_gpe0_dw1
;
176 *dw2
= config
->pmc_gpe0_dw2
;
179 static int rtc_failed(uint32_t gen_pmcon_b
)
181 return !!(gen_pmcon_b
& RTC_BATTERY_DEAD
);
184 static void clear_rtc_failed(void)
186 clrbits8(pmc_mmio_regs() + GEN_PMCON_B
, RTC_BATTERY_DEAD
);
189 static int check_rtc_failed(uint32_t gen_pmcon_b
)
191 const int failed
= rtc_failed(gen_pmcon_b
);
194 printk(BIOS_DEBUG
, "rtc_failed = 0x%x\n", failed
);
200 int soc_get_rtc_failed(void)
202 const struct chipset_power_state
*ps
;
204 if (acpi_fetch_pm_state(&ps
, PS_CLAIMER_RTC
) < 0)
207 return check_rtc_failed(ps
->gen_pmcon_b
);
210 int vbnv_cmos_failed(void)
212 return check_rtc_failed(read32(pmc_mmio_regs() + GEN_PMCON_B
));
215 static inline int deep_s3_enabled(void)
217 uint32_t deep_s3_pol
;
219 deep_s3_pol
= read32(pmc_mmio_regs() + S3_PWRGATE_POL
);
220 return !!(deep_s3_pol
& (S3DC_GATE_SUS
| S3AC_GATE_SUS
));
223 /* Return 0, 3, or 5 to indicate the previous sleep state. */
224 int soc_prev_sleep_state(const struct chipset_power_state
*ps
, int prev_sleep_state
)
227 * Check for any power failure to determine if this a wake from
228 * S5 because the PCH does not set the WAK_STS bit when waking
229 * from a true G3 state.
231 if (!(ps
->pm1_sts
& WAK_STS
) && (ps
->gen_pmcon_a
& (PWR_FLR
| SUS_PWR_FLR
)))
232 prev_sleep_state
= ACPI_S5
;
235 * If waking from S3 determine if deep S3 is enabled. If not,
236 * need to check both deep sleep well and normal suspend well.
237 * Otherwise just check deep sleep well.
239 if (prev_sleep_state
== ACPI_S3
) {
240 /* PWR_FLR represents deep sleep power well loss. */
241 uint32_t mask
= PWR_FLR
;
243 /* If deep s3 isn't enabled check the suspend well too. */
244 if (!deep_s3_enabled())
247 if (ps
->gen_pmcon_a
& mask
)
248 prev_sleep_state
= ACPI_S5
;
251 return prev_sleep_state
;
254 void soc_fill_power_state(struct chipset_power_state
*ps
)
258 ps
->tco1_sts
= tco_read_reg(TCO1_STS
);
259 ps
->tco2_sts
= tco_read_reg(TCO2_STS
);
261 printk(BIOS_DEBUG
, "TCO_STS: %04x %04x\n", ps
->tco1_sts
, ps
->tco2_sts
);
263 pmc
= pmc_mmio_regs();
264 ps
->gen_pmcon_a
= read32(pmc
+ GEN_PMCON_A
);
265 ps
->gen_pmcon_b
= read32(pmc
+ GEN_PMCON_B
);
266 ps
->gblrst_cause
[0] = read32(pmc
+ GBLRST_CAUSE0
);
267 ps
->gblrst_cause
[1] = read32(pmc
+ GBLRST_CAUSE1
);
268 ps
->hpr_cause0
= read32(pmc
+ HPR_CAUSE0
);
270 printk(BIOS_DEBUG
, "GEN_PMCON: %08x %08x\n",
271 ps
->gen_pmcon_a
, ps
->gen_pmcon_b
);
273 printk(BIOS_DEBUG
, "GBLRST_CAUSE: %08x %08x\n",
274 ps
->gblrst_cause
[0], ps
->gblrst_cause
[1]);
276 printk(BIOS_DEBUG
, "HPR_CAUSE0: %08x\n", ps
->hpr_cause0
);
280 uint16_t get_pmbase(void)
282 return (uint16_t)ACPI_BASE_ADDRESS
;
286 * Set which power state system will be after reapplying
287 * the power (from G3 State)
289 void pmc_soc_set_afterg3_en(const bool on
)
292 uint8_t *const pmcbase
= pmc_mmio_regs();
294 reg8
= read8(pmcbase
+ GEN_PMCON_A
);
296 reg8
&= ~SLEEP_AFTER_POWER_FAIL
;
298 reg8
|= SLEEP_AFTER_POWER_FAIL
;
299 write8(pmcbase
+ GEN_PMCON_A
, reg8
);