blob: 9dd490b14a3f6e502baccd94d32704e4b6bd56ed [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren61f5ddc2016-07-13 13:45:31 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren61f5ddc2016-07-13 13:45:31 -06004 */
5
Stephen Warren61f5ddc2016-07-13 13:45:31 -06006#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06007#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -07008#include <malloc.h>
Stephen Warren61f5ddc2016-07-13 13:45:31 -06009#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,
Simon Glass4f511882020-02-03 07:35:51 -070079 .rfree = sandbox_power_domain_free,
Stephen Warren61f5ddc2016-07-13 13:45:31 -060080 .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,
Simon Glass41575d82020-12-03 16:55:17 -070090 .priv_auto = sizeof(struct sandbox_power_domain),
Stephen Warren61f5ddc2016-07-13 13:45:31 -060091 .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}