coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pmc.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <bootstate.h>
4 #include <console/console.h>
5 #include <device/mmio.h>
6 #include <device/device.h>
7 #include <intelblocks/acpi.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 static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
16 {
17  uint32_t reg;
18  uint8_t *pmcbase = pmc_mmio_regs();
19 
20  printk(BIOS_DEBUG, "%sabling Deep S%c\n",
21  enable ? "En" : "Dis", sx + '0');
22  reg = read32(pmcbase + offset);
23  if (enable)
24  reg |= mask;
25  else
26  reg &= ~mask;
27  write32(pmcbase + offset, reg);
28 }
29 
30 static void config_deep_s5(int on_ac, int on_dc)
31 {
32  /* Treat S4 the same as S5. */
37 }
38 
39 static void config_deep_s3(int on_ac, int on_dc)
40 {
43 }
44 
45 static void config_deep_sx(uint32_t deepsx_config)
46 {
47  uint32_t reg;
48  uint8_t *pmcbase = pmc_mmio_regs();
49 
50  reg = read32(pmcbase + DSX_CFG);
51  reg &= ~DSX_CFG_MASK;
52  reg |= deepsx_config;
53  write32(pmcbase + DSX_CFG, reg);
54 }
55 
56 static void soc_pmc_enable(struct device *dev)
57 {
58  const config_t *config = config_of_soc();
59 
60  rtc_init();
61 
63  pmc_gpe_init();
64 
65  config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
66  config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
67  config_deep_sx(config->deep_sx_config);
68 }
69 
70 static void soc_pmc_read_resources(struct device *dev)
71 {
72  struct resource *res;
73 
75 
76  res = new_resource(dev, 1);
79  res->limit = res->base + res->size + 1;
81 }
82 
83 static void soc_pmc_init(struct device *dev)
84 {
85  /*
86  * pmc_set_acpi_mode() should be delayed until BS_DEV_INIT in order
87  * to ensure the ordering does not break the assumptions that other
88  * drivers make about ACPI mode (e.g. Chrome EC). Since it disables
89  * ACPI mode, other drivers may take different actions based on this
90  * (e.g. Chrome EC will flush any pending hostevent bits). Because
91  * JSL has its PMC device available for device_operations, it can be
92  * done from the "ops->init" callback.
93  */
95 
96  /*
97  * Disable ACPI PM timer based on Kconfig
98  *
99  * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
100  * Disabling ACPI PM timer also switches off TCO
101  */
102  if (!CONFIG(USE_PM_ACPI_TIMER))
104 }
105 
106 static void pm1_enable_pwrbtn_smi(void *unused)
107 {
108  /* Enable power button SMI after BS_DEV_INIT_CHIPS (FSP-S) is done. */
110 }
111 
113 
114 static void pmc_fill_ssdt(const struct device *dev)
115 {
116  if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP))
118 }
119 
120 /*
121  * `pmc_final` function is native implementation of equivalent events performed by
122  * each FSP NotifyPhase() API invocations.
123  *
124  *
125  * Clear PMCON status bits (Global Reset/Power Failure/Host Reset Status bits)
126  *
127  * Perform the PMCON status bit clear operation from `.final`
128  * to cover any such chances where later boot stage requested a global
129  * reset and PMCON status bit remains set.
130  */
131 static void pmc_final(struct device *dev)
132 {
134 }
135 
136 struct device_operations pmc_ops = {
138  .set_resources = noop_set_resources,
139  .init = soc_pmc_init,
140  .enable = soc_pmc_enable,
141 #if CONFIG(HAVE_ACPI_TABLES)
142  .acpi_fill_ssdt = pmc_fill_ssdt,
143 #endif
144  .final = pmc_final,
145 };
uint8_t * pmc_mmio_regs(void)
Definition: pmutil.c:142
BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL)
struct device_operations pmc_ops
Definition: pmc.c:190
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
@ BS_DEV_INIT_CHIPS
Definition: bootstate.h:79
@ BS_ON_EXIT
Definition: bootstate.h:96
#define KiB
Definition: helpers.h:75
#define PWRBTN_EN
Definition: southbridge.h:36
#define printk(level,...)
Definition: stdlib.h:16
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
@ CONFIG
Definition: dsi_common.h:201
static size_t offset
Definition: flashconsole.c:16
static void noop_set_resources(struct device *dev)
Definition: device.h:74
#define config_of_soc()
Definition: device.h:394
#define mmio_resource(dev, idx, basek, sizek)
Definition: device.h:334
#define setbits8(addr, set)
Definition: mmio.h:19
#define PCH_PWRM_BASE_ADDRESS
Definition: iomap.h:70
#define PCH_PWRM_BASE_SIZE
Definition: iomap.h:71
#define ACPI_BASE_ADDRESS
Definition: iomap.h:99
#define ACPI_BASE_SIZE
Definition: iomap.h:100
#define S3DC_GATE_SUS
Definition: pmc.h:84
#define S4_PWRGATE_POL
Definition: pmc.h:87
#define S4DC_GATE_SUS
Definition: pmc.h:88
#define ACPI_TIM_DIS
Definition: pmc.h:108
#define S3AC_GATE_SUS
Definition: pmc.h:85
#define S3_PWRGATE_POL
Definition: pmc.h:83
#define DSX_CFG_MASK
Definition: pmc.h:101
#define S5_PWRGATE_POL
Definition: pmc.h:91
#define S5AC_GATE_SUS
Definition: pmc.h:93
#define PCH_PWRM_ACPI_TMR_CTL
Definition: pmc.h:107
#define S4AC_GATE_SUS
Definition: pmc.h:89
#define DSX_CFG
Definition: pmc.h:95
#define S5DC_GATE_SUS
Definition: pmc.h:92
static void config_deep_s5(int on_ac, int on_dc)
Definition: pmc.c:30
static void config_deep_sx(uint32_t deepsx_config)
Definition: pmc.c:45
static void pmc_final(struct device *dev)
Definition: pmc.c:131
static void soc_pmc_enable(struct device *dev)
Definition: pmc.c:56
static void soc_pmc_read_resources(struct device *dev)
Definition: pmc.c:70
static void pm1_enable_pwrbtn_smi(void *unused)
Definition: pmc.c:106
static void soc_pmc_init(struct device *dev)
Definition: pmc.c:83
static void pmc_fill_ssdt(const struct device *dev)
Definition: pmc.c:114
static void config_deep_s3(int on_ac, int on_dc)
Definition: pmc.c:39
static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
Definition: pmc.c:15
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
enum board_config config
Definition: memory.c:448
void generate_acpi_power_engine(void)
Definition: pep.c:207
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
u64 resource_t
Definition: resource.h:43
#define IORESOURCE_FIXED
Definition: resource.h:36
static const int mask[4]
Definition: gpio.c:308
void pmc_set_power_failure_state(bool target_on)
Definition: pmclib.c:623
void pmc_set_acpi_mode(void)
Definition: pmclib.c:754
void pmc_update_pm1_enable(uint16_t events)
Definition: pmclib.c:151
void pmc_clear_pmcon_sts(void)
void pmc_gpe_init(void)
Definition: pmclib.c:535
void rtc_init(void)
Definition: rtc.c:29
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
unsigned long flags
Definition: resource.h:49
resource_t limit
Definition: resource.h:47
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46