Aamir Bohra | dd7acaa | 2020-03-25 11:36:22 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | /* |
| 16 | * This file is created based on Intel Tiger Lake Processor PCH Datasheet |
| 17 | * Document number: 575857 |
| 18 | * Chapter number: 4 |
| 19 | */ |
| 20 | |
| 21 | #include <bootstate.h> |
| 22 | #include <console/console.h> |
| 23 | #include <device/mmio.h> |
| 24 | #include <device/device.h> |
| 25 | #include <intelblocks/pmc.h> |
| 26 | #include <intelblocks/pmclib.h> |
| 27 | #include <intelblocks/rtc.h> |
| 28 | #include <soc/pci_devs.h> |
| 29 | #include <soc/pm.h> |
| 30 | #include <soc/soc_chip.h> |
| 31 | |
| 32 | /* |
| 33 | * Set which power state system will be after reapplying |
| 34 | * the power (from G3 State) |
| 35 | */ |
| 36 | void pmc_soc_set_afterg3_en(const bool on) |
| 37 | { |
| 38 | uint8_t reg8; |
| 39 | uint8_t *const pmcbase = pmc_mmio_regs(); |
| 40 | |
| 41 | reg8 = read8(pmcbase + GEN_PMCON_A); |
| 42 | if (on) |
| 43 | reg8 &= ~SLEEP_AFTER_POWER_FAIL; |
| 44 | else |
| 45 | reg8 |= SLEEP_AFTER_POWER_FAIL; |
| 46 | write8(pmcbase + GEN_PMCON_A, reg8); |
| 47 | } |
| 48 | |
| 49 | static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable) |
| 50 | { |
| 51 | uint32_t reg; |
| 52 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 53 | |
| 54 | printk(BIOS_DEBUG, "%sabling Deep S%c\n", |
| 55 | enable ? "En" : "Dis", sx + '0'); |
| 56 | reg = read32(pmcbase + offset); |
| 57 | if (enable) |
| 58 | reg |= mask; |
| 59 | else |
| 60 | reg &= ~mask; |
| 61 | write32(pmcbase + offset, reg); |
| 62 | } |
| 63 | |
| 64 | static void config_deep_s5(int on_ac, int on_dc) |
| 65 | { |
| 66 | /* Treat S4 the same as S5. */ |
| 67 | config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac); |
| 68 | config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc); |
| 69 | config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac); |
| 70 | config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc); |
| 71 | } |
| 72 | |
| 73 | static void config_deep_s3(int on_ac, int on_dc) |
| 74 | { |
| 75 | config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac); |
| 76 | config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc); |
| 77 | } |
| 78 | |
| 79 | static void config_deep_sx(uint32_t deepsx_config) |
| 80 | { |
| 81 | uint32_t reg; |
| 82 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 83 | |
| 84 | reg = read32(pmcbase + DSX_CFG); |
| 85 | reg &= ~DSX_CFG_MASK; |
| 86 | reg |= deepsx_config; |
| 87 | write32(pmcbase + DSX_CFG, reg); |
| 88 | } |
| 89 | |
| 90 | static void pmc_init(void *unused) |
| 91 | { |
| 92 | const config_t *config = config_of_soc(); |
| 93 | |
| 94 | rtc_init(); |
| 95 | |
| 96 | pmc_set_power_failure_state(true); |
| 97 | pmc_gpe_init(); |
| 98 | |
| 99 | pmc_set_acpi_mode(); |
| 100 | |
| 101 | config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc); |
| 102 | config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc); |
| 103 | config_deep_sx(config->deep_sx_config); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Initialize PMC controller. |
| 108 | * |
| 109 | * PMC controller gets hidden from PCI bus during FSP-Silicon init call. |
| 110 | * Hence PCI enumeration can't be used to initialize bus device and |
| 111 | * allocate resources. |
| 112 | */ |
| 113 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pmc_init, NULL); |