blob: 9071346f9844eb7c2c186c29672890165d19b66e [file] [log] [blame]
Stephen Warren61f5ddc2016-07-13 13:45:31 -06001/*
2 * Copyright (c) 2016, NVIDIA CORPORATION.
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <power-domain-uclass.h>
10#include <asm/io.h>
11#include <asm/power-domain.h>
12
13#define SANDBOX_POWER_DOMAINS 3
14
15struct sandbox_power_domain {
16 bool on[SANDBOX_POWER_DOMAINS];
17};
18
19static int sandbox_power_domain_request(struct power_domain *power_domain)
20{
21 debug("%s(power_domain=%p)\n", __func__, power_domain);
22
23 if (power_domain->id >= SANDBOX_POWER_DOMAINS)
24 return -EINVAL;
25
26 return 0;
27}
28
29static int sandbox_power_domain_free(struct power_domain *power_domain)
30{
31 debug("%s(power_domain=%p)\n", __func__, power_domain);
32
33 return 0;
34}
35
36static int sandbox_power_domain_on(struct power_domain *power_domain)
37{
38 struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev);
39
40 debug("%s(power_domain=%p)\n", __func__, power_domain);
41
42 sbr->on[power_domain->id] = true;
43
44 return 0;
45}
46
47static int sandbox_power_domain_off(struct power_domain *power_domain)
48{
49 struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev);
50
51 debug("%s(power_domain=%p)\n", __func__, power_domain);
52
53 sbr->on[power_domain->id] = false;
54
55 return 0;
56}
57
58static int sandbox_power_domain_bind(struct udevice *dev)
59{
60 debug("%s(dev=%p)\n", __func__, dev);
61
62 return 0;
63}
64
65static int sandbox_power_domain_probe(struct udevice *dev)
66{
67 debug("%s(dev=%p)\n", __func__, dev);
68
69 return 0;
70}
71
72static const struct udevice_id sandbox_power_domain_ids[] = {
73 { .compatible = "sandbox,power-domain" },
74 { }
75};
76
77struct power_domain_ops sandbox_power_domain_ops = {
78 .request = sandbox_power_domain_request,
79 .free = sandbox_power_domain_free,
80 .on = sandbox_power_domain_on,
81 .off = sandbox_power_domain_off,
82};
83
84U_BOOT_DRIVER(sandbox_power_domain) = {
85 .name = "sandbox_power_domain",
86 .id = UCLASS_POWER_DOMAIN,
87 .of_match = sandbox_power_domain_ids,
88 .bind = sandbox_power_domain_bind,
89 .probe = sandbox_power_domain_probe,
90 .priv_auto_alloc_size = sizeof(struct sandbox_power_domain),
91 .ops = &sandbox_power_domain_ops,
92};
93
94int sandbox_power_domain_query(struct udevice *dev, unsigned long id)
95{
96 struct sandbox_power_domain *sbr = dev_get_priv(dev);
97
98 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
99
100 if (id >= SANDBOX_POWER_DOMAINS)
101 return -EINVAL;
102
103 return sbr->on[id];
104}