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