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