summaryrefslogtreecommitdiff
path: root/drivers/power/domain/sandbox-power-domain.c
blob: 74db2eba7e23cd3cadc9ade0f4c5987ba25fb8ed (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
98
99
100
101
102
103
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2016, NVIDIA CORPORATION.
 */

#include <common.h>
#include <dm.h>
#include <power-domain-uclass.h>
#include <asm/io.h>
#include <asm/power-domain.h>

#define SANDBOX_POWER_DOMAINS 3

struct sandbox_power_domain {
	bool on[SANDBOX_POWER_DOMAINS];
};

static int sandbox_power_domain_request(struct power_domain *power_domain)
{
	debug("%s(power_domain=%p)\n", __func__, power_domain);

	if (power_domain->id >= SANDBOX_POWER_DOMAINS)
		return -EINVAL;

	return 0;
}

static int sandbox_power_domain_free(struct power_domain *power_domain)
{
	debug("%s(power_domain=%p)\n", __func__, power_domain);

	return 0;
}

static int sandbox_power_domain_on(struct power_domain *power_domain)
{
	struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev);

	debug("%s(power_domain=%p)\n", __func__, power_domain);

	sbr->on[power_domain->id] = true;

	return 0;
}

static int sandbox_power_domain_off(struct power_domain *power_domain)
{
	struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev);

	debug("%s(power_domain=%p)\n", __func__, power_domain);

	sbr->on[power_domain->id] = false;

	return 0;
}

static int sandbox_power_domain_bind(struct udevice *dev)
{
	debug("%s(dev=%p)\n", __func__, dev);

	return 0;
}

static int sandbox_power_domain_probe(struct udevice *dev)
{
	debug("%s(dev=%p)\n", __func__, dev);

	return 0;
}

static const struct udevice_id sandbox_power_domain_ids[] = {
	{ .compatible = "sandbox,power-domain" },
	{ }
};

struct power_domain_ops sandbox_power_domain_ops = {
	.request = sandbox_power_domain_request,
	.free = sandbox_power_domain_free,
	.on = sandbox_power_domain_on,
	.off = sandbox_power_domain_off,
};

U_BOOT_DRIVER(sandbox_power_domain) = {
	.name = "sandbox_power_domain",
	.id = UCLASS_POWER_DOMAIN,
	.of_match = sandbox_power_domain_ids,
	.bind = sandbox_power_domain_bind,
	.probe = sandbox_power_domain_probe,
	.priv_auto_alloc_size = sizeof(struct sandbox_power_domain),
	.ops = &sandbox_power_domain_ops,
};

int sandbox_power_domain_query(struct udevice *dev, unsigned long id)
{
	struct sandbox_power_domain *sbr = dev_get_priv(dev);

	debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);

	if (id >= SANDBOX_POWER_DOMAINS)
		return -EINVAL;

	return sbr->on[id];
}