Angel Pons | fabfe9d | 2020-04-05 15:47:07 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Aamir Bohra | dd7acaa | 2020-03-25 11:36:22 +0530 | [diff] [blame] | 3 | |
Aamir Bohra | dd7acaa | 2020-03-25 11:36:22 +0530 | [diff] [blame] | 4 | #include <bootstate.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/mmio.h> |
| 7 | #include <device/device.h> |
| 8 | #include <intelblocks/pmc.h> |
| 9 | #include <intelblocks/pmclib.h> |
| 10 | #include <intelblocks/rtc.h> |
| 11 | #include <soc/pci_devs.h> |
| 12 | #include <soc/pm.h> |
| 13 | #include <soc/soc_chip.h> |
| 14 | |
| 15 | /* |
| 16 | * Set which power state system will be after reapplying |
| 17 | * the power (from G3 State) |
| 18 | */ |
| 19 | void pmc_soc_set_afterg3_en(const bool on) |
| 20 | { |
| 21 | uint8_t reg8; |
| 22 | uint8_t *const pmcbase = pmc_mmio_regs(); |
| 23 | |
| 24 | reg8 = read8(pmcbase + GEN_PMCON_A); |
| 25 | if (on) |
| 26 | reg8 &= ~SLEEP_AFTER_POWER_FAIL; |
| 27 | else |
| 28 | reg8 |= SLEEP_AFTER_POWER_FAIL; |
| 29 | write8(pmcbase + GEN_PMCON_A, reg8); |
| 30 | } |
| 31 | |
| 32 | static 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 | |
| 47 | static 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 | |
| 56 | static 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 | |
| 62 | static 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 | |
| 73 | static void pmc_init(void *unused) |
| 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 | pmc_set_acpi_mode(); |
| 83 | |
| 84 | config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc); |
| 85 | config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc); |
| 86 | config_deep_sx(config->deep_sx_config); |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * Initialize PMC controller. |
| 91 | * |
| 92 | * PMC controller gets hidden from PCI bus during FSP-Silicon init call. |
| 93 | * Hence PCI enumeration can't be used to initialize bus device and |
| 94 | * allocate resources. |
| 95 | */ |
| 96 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pmc_init, NULL); |