2015-05-13 03:23:27 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2009 coresystems GmbH
|
|
|
|
* Copyright (C) 2014 Google Inc.
|
2017-11-22 11:08:19 +01:00
|
|
|
* Copyright (C) 2015-2017 Intel Corporation.
|
2015-05-13 03:23:27 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2017-12-14 11:58:45 +01:00
|
|
|
#include <bootstate.h>
|
2015-05-13 03:23:27 +02:00
|
|
|
#include <chip.h>
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
2018-04-18 10:11:59 +02:00
|
|
|
#include <device/pci_ops.h>
|
2017-11-22 11:08:19 +01:00
|
|
|
#include <intelblocks/pmc.h>
|
2017-07-08 10:08:40 +02:00
|
|
|
#include <intelblocks/pmclib.h>
|
2017-11-22 11:08:19 +01:00
|
|
|
#include <intelblocks/rtc.h>
|
2015-05-13 03:23:27 +02:00
|
|
|
#include <reg_script.h>
|
|
|
|
#include <soc/pci_devs.h>
|
|
|
|
#include <soc/pm.h>
|
2017-11-22 11:08:19 +01:00
|
|
|
|
|
|
|
void pmc_set_disb(void)
|
|
|
|
{
|
|
|
|
/* Set the DISB after DRAM init */
|
|
|
|
u32 disb_val;
|
2018-06-12 22:06:09 +02:00
|
|
|
#if defined(__SIMPLE_DEVICE__)
|
|
|
|
pci_devfn_t dev = PCH_DEV_PMC;
|
|
|
|
#else
|
|
|
|
struct device *dev = PCH_DEV_PMC;
|
|
|
|
#endif
|
2017-11-22 11:08:19 +01:00
|
|
|
|
|
|
|
disb_val = pci_read_config32(dev, GEN_PMCON_A);
|
|
|
|
disb_val |= DISB;
|
|
|
|
|
|
|
|
/* Don't clear bits that are write-1-to-clear */
|
|
|
|
disb_val &= ~(GBL_RST_STS | MS4V);
|
|
|
|
pci_write_config32(dev, GEN_PMCON_A, disb_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENV_RAMSTAGE
|
|
|
|
/* Fill up PMC resource structure */
|
|
|
|
int pmc_soc_get_resources(struct pmc_resource_config *cfg)
|
|
|
|
{
|
|
|
|
cfg->pwrmbase_offset = PWRMBASE;
|
|
|
|
cfg->pwrmbase_addr = PCH_PWRM_BASE_ADDRESS;
|
|
|
|
cfg->pwrmbase_size = PCH_PWRM_BASE_SIZE;
|
|
|
|
cfg->abase_offset = ABASE;
|
|
|
|
cfg->abase_addr = ACPI_BASE_ADDRESS;
|
|
|
|
cfg->abase_size = ACPI_BASE_SIZE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-13 03:23:27 +02:00
|
|
|
|
|
|
|
static const struct reg_script pch_pmc_misc_init_script[] = {
|
2015-08-04 21:02:54 +02:00
|
|
|
/* SLP_S4=4s, SLP_S3=50ms, disable SLP_X stretching after SUS loss. */
|
|
|
|
REG_PCI_RMW16(GEN_PMCON_B,
|
|
|
|
~(S4MAW_MASK | SLP_S3_MIN_ASST_WDTH_MASK),
|
|
|
|
S4MAW_4S | SLP_S3_MIN_ASST_WDTH_50MS |
|
|
|
|
DIS_SLP_X_STRCH_SUS_UP),
|
|
|
|
/* Enable SCI and clear SLP requests. */
|
2015-05-13 03:23:27 +02:00
|
|
|
REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
|
|
|
|
REG_SCRIPT_END
|
|
|
|
};
|
|
|
|
|
2015-08-05 04:04:02 +02:00
|
|
|
static const struct reg_script pmc_write1_to_clear_script[] = {
|
|
|
|
REG_PCI_OR32(GEN_PMCON_A, 0),
|
|
|
|
REG_PCI_OR32(GEN_PMCON_B, 0),
|
|
|
|
REG_PCI_OR32(GEN_PMCON_B, 0),
|
|
|
|
REG_RES_OR32(PWRMBASE, GBLRST_CAUSE0, 0),
|
|
|
|
REG_RES_OR32(PWRMBASE, GBLRST_CAUSE1, 0),
|
|
|
|
REG_SCRIPT_END
|
|
|
|
};
|
|
|
|
|
2017-12-19 05:57:45 +01:00
|
|
|
/*
|
|
|
|
* Set which power state system will be after reapplying
|
|
|
|
* the power (from G3 State)
|
|
|
|
*/
|
|
|
|
static void pmc_set_afterg3(struct device *dev, int s5pwr)
|
|
|
|
{
|
|
|
|
uint8_t reg8;
|
|
|
|
|
|
|
|
reg8 = pci_read_config8(dev, GEN_PMCON_B);
|
|
|
|
|
|
|
|
switch (s5pwr) {
|
|
|
|
case MAINBOARD_POWER_STATE_OFF:
|
|
|
|
reg8 |= 1;
|
|
|
|
break;
|
|
|
|
case MAINBOARD_POWER_STATE_ON:
|
|
|
|
reg8 &= ~1;
|
|
|
|
break;
|
|
|
|
case MAINBOARD_POWER_STATE_PREVIOUS:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_write_config8(dev, GEN_PMCON_B, reg8);
|
|
|
|
}
|
|
|
|
|
2017-11-22 11:08:19 +01:00
|
|
|
static void pch_power_options(struct device *dev)
|
2015-05-13 03:23:27 +02:00
|
|
|
{
|
|
|
|
const char *state;
|
2017-11-22 11:08:19 +01:00
|
|
|
|
2015-05-13 03:23:27 +02:00
|
|
|
/* Get the chip configuration */
|
2017-12-19 05:57:45 +01:00
|
|
|
int pwr_on = pmc_get_mainboard_power_failure_state_choice();
|
2015-05-13 03:23:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Which state do we want to goto after g3 (power restored)?
|
2017-12-19 05:57:45 +01:00
|
|
|
* 0 == S5 Soft Off
|
|
|
|
* 1 == S0 Full On
|
|
|
|
* 2 == Keep Previous State
|
2015-05-13 03:23:27 +02:00
|
|
|
*/
|
|
|
|
switch (pwr_on) {
|
2017-12-19 05:57:45 +01:00
|
|
|
case MAINBOARD_POWER_STATE_OFF:
|
2015-05-13 03:23:27 +02:00
|
|
|
state = "off";
|
|
|
|
break;
|
2017-12-19 05:57:45 +01:00
|
|
|
case MAINBOARD_POWER_STATE_ON:
|
2015-05-13 03:23:27 +02:00
|
|
|
state = "on";
|
|
|
|
break;
|
2017-12-19 05:57:45 +01:00
|
|
|
case MAINBOARD_POWER_STATE_PREVIOUS:
|
2015-05-13 03:23:27 +02:00
|
|
|
state = "state keep";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
state = "undefined";
|
|
|
|
}
|
2017-12-19 05:57:45 +01:00
|
|
|
pmc_set_afterg3(dev, pwr_on);
|
2015-05-13 03:23:27 +02:00
|
|
|
printk(BIOS_INFO, "Set power %s after power failure.\n", state);
|
2015-08-08 05:29:42 +02:00
|
|
|
|
|
|
|
/* Set up GPE configuration. */
|
2016-10-26 05:03:56 +02:00
|
|
|
pmc_gpe_init();
|
2015-05-13 03:23:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
|
|
|
|
{
|
|
|
|
uint32_t reg;
|
|
|
|
uint8_t *pmcbase = pmc_mmio_regs();
|
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "%sabling Deep S%c\n",
|
|
|
|
enable ? "En" : "Dis", sx + '0');
|
|
|
|
reg = read32(pmcbase + offset);
|
|
|
|
if (enable)
|
|
|
|
reg |= mask;
|
|
|
|
else
|
|
|
|
reg &= ~mask;
|
|
|
|
write32(pmcbase + offset, reg);
|
|
|
|
}
|
|
|
|
|
2017-04-11 06:02:13 +02:00
|
|
|
static void config_deep_s5(int on_ac, int on_dc)
|
2015-05-13 03:23:27 +02:00
|
|
|
{
|
|
|
|
/* Treat S4 the same as S5. */
|
2017-04-11 06:02:13 +02:00
|
|
|
config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac);
|
|
|
|
config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc);
|
|
|
|
config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac);
|
|
|
|
config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc);
|
2015-05-13 03:23:27 +02:00
|
|
|
}
|
|
|
|
|
2017-04-11 06:02:13 +02:00
|
|
|
static void config_deep_s3(int on_ac, int on_dc)
|
2015-05-13 03:23:27 +02:00
|
|
|
{
|
2017-04-11 06:02:13 +02:00
|
|
|
config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac);
|
|
|
|
config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc);
|
2015-05-13 03:23:27 +02:00
|
|
|
}
|
|
|
|
|
2015-07-25 00:37:13 +02:00
|
|
|
static void config_deep_sx(uint32_t deepsx_config)
|
|
|
|
{
|
|
|
|
uint32_t reg;
|
|
|
|
uint8_t *pmcbase = pmc_mmio_regs();
|
|
|
|
|
|
|
|
reg = read32(pmcbase + DSX_CFG);
|
|
|
|
reg &= ~DSX_CFG_MASK;
|
|
|
|
reg |= deepsx_config;
|
|
|
|
write32(pmcbase + DSX_CFG, reg);
|
|
|
|
}
|
|
|
|
|
2017-11-22 11:08:19 +01:00
|
|
|
void pmc_soc_init(struct device *dev)
|
2015-05-13 03:23:27 +02:00
|
|
|
{
|
2017-11-22 11:08:19 +01:00
|
|
|
const config_t *config = dev->chip_info;
|
2015-05-13 03:23:27 +02:00
|
|
|
|
2017-11-22 11:08:19 +01:00
|
|
|
rtc_init();
|
2015-05-13 03:23:27 +02:00
|
|
|
|
|
|
|
/* Initialize power management */
|
2017-11-22 11:08:19 +01:00
|
|
|
pch_power_options(dev);
|
2015-05-13 03:23:27 +02:00
|
|
|
|
2015-08-04 21:02:54 +02:00
|
|
|
/* Note that certain bits may be cleared from running script as
|
|
|
|
* certain bit fields are write 1 to clear. */
|
2015-05-13 03:23:27 +02:00
|
|
|
reg_script_run_on_dev(dev, pch_pmc_misc_init_script);
|
2017-11-22 11:08:19 +01:00
|
|
|
pmc_set_acpi_mode();
|
2015-05-13 03:23:27 +02:00
|
|
|
|
2017-04-11 06:02:13 +02:00
|
|
|
config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
|
|
|
|
config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
|
2015-07-25 00:37:13 +02:00
|
|
|
config_deep_sx(config->deep_sx_config);
|
2015-08-05 04:04:02 +02:00
|
|
|
|
|
|
|
/* Clear registers that contain write-1-to-clear bits. */
|
|
|
|
reg_script_run_on_dev(dev, pmc_write1_to_clear_script);
|
2015-05-13 03:23:27 +02:00
|
|
|
}
|
2017-12-19 05:57:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set PMC register to know which state system should be after
|
|
|
|
* power reapplied
|
|
|
|
*/
|
|
|
|
void pmc_soc_restore_power_failure(void)
|
|
|
|
{
|
|
|
|
pmc_set_afterg3(PCH_DEV_PMC,
|
|
|
|
pmc_get_mainboard_power_failure_state_choice());
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:58:45 +01:00
|
|
|
static void pm1_enable_pwrbtn_smi(void *unused)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Enable power button SMI only before jumping to payload. This ensures
|
|
|
|
* that:
|
|
|
|
* 1. Power button SMI is enabled only after coreboot is done.
|
|
|
|
* 2. On resume path, power button SMI is not enabled and thus avoids
|
|
|
|
* any shutdowns because of power button presses due to power button
|
|
|
|
* press in resume path.
|
|
|
|
*/
|
|
|
|
pmc_update_pm1_enable(PWRBTN_EN);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL);
|
|
|
|
|
2017-11-22 11:08:19 +01:00
|
|
|
#endif
|