1 // SPDX-License-Identifier: GPL-2.0
3 * Sandbox PMC for testing
5 * Copyright 2019 Google LLC
8 #define LOG_CATEGORY UCLASS_ACPI_PMC
13 #include <power/acpi_pmc.h>
15 #define GPIO_GPE_CFG 0x1050
17 /* Memory mapped IO registers behind PMC_BASE_ADDRESS */
19 #define GEN_PMCON1 0x1020
20 #define GEN_PMCON2 0x1024
21 #define GEN_PMCON3 0x1028
23 /* Offset of TCO registers from ACPI base I/O address */
24 #define TCO_REG_OFFSET 0x60
30 struct sandbox_pmc_priv {
34 static int sandbox_pmc_fill_power_state(struct udevice *dev)
36 struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev);
38 upriv->tco1_sts = inw(upriv->acpi_base + TCO1_STS);
39 upriv->tco2_sts = inw(upriv->acpi_base + TCO2_STS);
41 upriv->prsts = readl(upriv->pmc_bar0 + PRSTS);
42 upriv->gen_pmcon1 = readl(upriv->pmc_bar0 + GEN_PMCON1);
43 upriv->gen_pmcon2 = readl(upriv->pmc_bar0 + GEN_PMCON2);
44 upriv->gen_pmcon3 = readl(upriv->pmc_bar0 + GEN_PMCON3);
49 static int sandbox_prev_sleep_state(struct udevice *dev, int prev_sleep_state)
51 return prev_sleep_state;
54 static int sandbox_disable_tco(struct udevice *dev)
56 struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev);
58 pmc_disable_tco_base(upriv->acpi_base + TCO_REG_OFFSET);
63 static int sandbox_pmc_probe(struct udevice *dev)
65 struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev);
69 uclass_first_device(UCLASS_PCI, &bus);
70 base = dm_pci_read_bar32(dev, 0);
71 if (base == FDT_ADDR_T_NONE)
72 return log_msg_ret("No base address", -EINVAL);
73 upriv->pmc_bar0 = map_sysmem(base, 0x2000);
74 upriv->gpe_cfg = (u32 *)(upriv->pmc_bar0 + GPIO_GPE_CFG);
76 return pmc_ofdata_to_uc_plat(dev);
79 static struct acpi_pmc_ops sandbox_pmc_ops = {
80 .init = sandbox_pmc_fill_power_state,
81 .prev_sleep_state = sandbox_prev_sleep_state,
82 .disable_tco = sandbox_disable_tco,
85 static const struct udevice_id sandbox_pmc_ids[] = {
86 { .compatible = "sandbox,pmc" },
90 U_BOOT_DRIVER(pmc_sandbox) = {
91 .name = "pmc_sandbox",
92 .id = UCLASS_ACPI_PMC,
93 .of_match = sandbox_pmc_ids,
94 .probe = sandbox_pmc_probe,
95 .ops = &sandbox_pmc_ops,
96 .priv_auto = sizeof(struct sandbox_pmc_priv),