summaryrefslogtreecommitdiff
path: root/drivers/power/acpi_pmc/sandbox.c
blob: 7fbbf97b45411da0453cd8cf7b0c195a7d099679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-License-Identifier: GPL-2.0
/*
 * Sandbox PMC for testing
 *
 * Copyright 2019 Google LLC
 */

#define LOG_CATEGORY UCLASS_ACPI_PMC

#include <common.h>
#include <dm.h>
#include <asm/io.h>
#include <power/acpi_pmc.h>

#define GPIO_GPE_CFG		0x1050

/* Memory mapped IO registers behind PMC_BASE_ADDRESS */
#define PRSTS			0x1000
#define GEN_PMCON1		0x1020
#define GEN_PMCON2		0x1024
#define GEN_PMCON3		0x1028

/* Offset of TCO registers from ACPI base I/O address */
#define TCO_REG_OFFSET		0x60
#define TCO1_STS	0x64
#define TCO2_STS	0x66
#define TCO1_CNT	0x68
#define TCO2_CNT	0x6a

struct sandbox_pmc_priv {
	ulong base;
};

static int sandbox_pmc_fill_power_state(struct udevice *dev)
{
	struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev);

	upriv->tco1_sts = inw(upriv->acpi_base + TCO1_STS);
	upriv->tco2_sts = inw(upriv->acpi_base + TCO2_STS);

	upriv->prsts = readl(upriv->pmc_bar0 + PRSTS);
	upriv->gen_pmcon1 = readl(upriv->pmc_bar0 + GEN_PMCON1);
	upriv->gen_pmcon2 = readl(upriv->pmc_bar0 + GEN_PMCON2);
	upriv->gen_pmcon3 = readl(upriv->pmc_bar0 + GEN_PMCON3);

	return 0;
}

static int sandbox_prev_sleep_state(struct udevice *dev, int prev_sleep_state)
{
	return prev_sleep_state;
}

static int sandbox_disable_tco(struct udevice *dev)
{
	struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev);

	pmc_disable_tco_base(upriv->acpi_base + TCO_REG_OFFSET);

	return 0;
}

static int sandbox_pmc_probe(struct udevice *dev)
{
	struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev);
	struct udevice *bus;
	ulong base;

	uclass_first_device(UCLASS_PCI, &bus);
	base = dm_pci_read_bar32(dev, 0);
	if (base == FDT_ADDR_T_NONE)
		return log_msg_ret("No base address", -EINVAL);
	upriv->pmc_bar0 = map_sysmem(base, 0x2000);
	upriv->gpe_cfg = (u32 *)(upriv->pmc_bar0 + GPIO_GPE_CFG);

	return pmc_ofdata_to_uc_platdata(dev);
}

static struct acpi_pmc_ops sandbox_pmc_ops = {
	.init			= sandbox_pmc_fill_power_state,
	.prev_sleep_state	= sandbox_prev_sleep_state,
	.disable_tco		= sandbox_disable_tco,
};

static const struct udevice_id sandbox_pmc_ids[] = {
	{ .compatible = "sandbox,pmc" },
	{ }
};

U_BOOT_DRIVER(pmc_sandbox) = {
	.name = "pmc_sandbox",
	.id = UCLASS_ACPI_PMC,
	.of_match = sandbox_pmc_ids,
	.probe = sandbox_pmc_probe,
	.ops = &sandbox_pmc_ops,
	.priv_auto_alloc_size = sizeof(struct sandbox_pmc_priv),
};