| 1 |
|
| 2 |
|
| 3 |
#include <arch/io.h> |
| 4 |
#include <bootstate.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <device/mmio.h> |
| 7 |
#include <device/device.h> |
| 8 |
#include <device/pci_ops.h> |
| 9 |
#include <intelblocks/pmc.h> |
| 10 |
#include <intelblocks/pmclib.h> |
| 11 |
#include <intelblocks/rtc.h> |
| 12 |
#include <soc/pci_devs.h> |
| 13 |
#include <soc/pm.h> |
| 14 |
#include <static.h> |
| 15 |
|
| 16 |
#include "chip.h" |
| 17 |
|
| 18 |
|
| 19 |
int pmc_soc_get_resources(struct pmc_resource_config *cfg) |
| 20 |
{ |
| 21 |
cfg->pwrmbase_offset = PWRMBASE; |
| 22 |
cfg->pwrmbase_addr = PCH_PWRM_BASE_ADDRESS; |
| 23 |
cfg->pwrmbase_size = PCH_PWRM_BASE_SIZE; |
| 24 |
cfg->abase_offset = ABASE; |
| 25 |
cfg->abase_addr = ACPI_BASE_ADDRESS; |
| 26 |
cfg->abase_size = ACPI_BASE_SIZE; |
| 27 |
|
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable) |
| 32 |
{ |
| 33 |
uint32_t reg; |
| 34 |
uint8_t *pmcbase = pmc_mmio_regs(); |
| 35 |
|
| 36 |
printk(BIOS_DEBUG, "%sabling Deep S%c\n", |
| 37 |
enable ? "En" : "Dis", sx + '0'); |
| 38 |
reg = read32(pmcbase + offset); |
| 39 |
if (enable) |
| 40 |
reg |= mask; |
| 41 |
else |
| 42 |
reg &= ~mask; |
| 43 |
write32(pmcbase + offset, reg); |
| 44 |
} |
| 45 |
|
| 46 |
static void config_deep_s5(int on_ac, int on_dc) |
| 47 |
{ |
| 48 |
|
| 49 |
config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac); |
| 50 |
config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc); |
| 51 |
config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac); |
| 52 |
config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc); |
| 53 |
} |
| 54 |
|
| 55 |
static void config_deep_s3(int on_ac, int on_dc) |
| 56 |
{ |
| 57 |
config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac); |
| 58 |
config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc); |
| 59 |
} |
| 60 |
|
| 61 |
static void config_deep_sx(uint32_t deepsx_config) |
| 62 |
{ |
| 63 |
uint32_t reg; |
| 64 |
uint8_t *pmcbase = pmc_mmio_regs(); |
| 65 |
|
| 66 |
reg = read32(pmcbase + DSX_CFG); |
| 67 |
reg &= ~DSX_CFG_MASK; |
| 68 |
reg |= deepsx_config; |
| 69 |
write32(pmcbase + DSX_CFG, reg); |
| 70 |
} |
| 71 |
|
| 72 |
void pmc_soc_init(struct device *dev) |
| 73 |
{ |
| 74 |
const config_t *config = config_of(dev); |
| 75 |
uint8_t *const pwrmbase = pmc_mmio_regs(); |
| 76 |
uint32_t reg32; |
| 77 |
|
| 78 |
rtc_init(); |
| 79 |
|
| 80 |
pmc_set_power_failure_state(true); |
| 81 |
pmc_gpe_init(); |
| 82 |
|
| 83 |
|
| 84 |
pci_update_config32(dev, GEN_PMCON_B, ~(S4MAW_MASK | SLP_S3_MIN_ASST_WDTH_MASK), |
| 85 |
S4MAW_4S | SLP_S3_MIN_ASST_WDTH_50MS | DIS_SLP_X_STRCH_SUS_UP); |
| 86 |
|
| 87 |
|
| 88 |
reg32 = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 89 |
reg32 &= ~SLP_TYP; |
| 90 |
reg32 |= SCI_EN; |
| 91 |
outl(reg32, ACPI_BASE_ADDRESS + PM1_CNT); |
| 92 |
|
| 93 |
pmc_set_acpi_mode(); |
| 94 |
|
| 95 |
config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc); |
| 96 |
config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc); |
| 97 |
config_deep_sx(config->deep_sx_config); |
| 98 |
|
| 99 |
|
| 100 |
pci_or_config32(dev, GEN_PMCON_B, 0); |
| 101 |
pci_or_config32(dev, GEN_PMCON_B, 0); |
| 102 |
setbits32(pwrmbase + GBLRST_CAUSE0, 0); |
| 103 |
setbits32(pwrmbase + GBLRST_CAUSE1, 0); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
if (!CONFIG(USE_PM_ACPI_TIMER)) |
| 112 |
setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL, ACPI_TIM_DIS); |
| 113 |
} |
| 114 |
|
| 115 |
static void pm1_enable_pwrbtn_smi(void *unused) |
| 116 |
{ |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
pmc_update_pm1_enable(PWRBTN_EN); |
| 126 |
} |
| 127 |
|
| 128 |
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
static void pm1_handle_wake_pin(void *unused) |
| 137 |
{ |
| 138 |
const config_t *conf = config_of_soc(); |
| 139 |
|
| 140 |
|
| 141 |
if (conf->deep_sx_config & DSX_EN_WAKE_PIN) |
| 142 |
return; |
| 143 |
|
| 144 |
pmc_update_pm1_enable(PCIEXPWAK_DIS); |
| 145 |
} |
| 146 |
|
| 147 |
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_handle_wake_pin, NULL); |
| 148 |
BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, pm1_handle_wake_pin, NULL); |