blob: a80316576384b27dc8159e81b5c79fc355af2860 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren92c67fa2016-07-13 13:45:31 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren92c67fa2016-07-13 13:45:31 -06004 */
5
Stephen Warren92c67fa2016-07-13 13:45:31 -06006#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Stephen Warren92c67fa2016-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{
Miquel Raynalc1f527e2025-04-25 08:49:32 +020067 struct power_domain_plat *plat = dev_get_uclass_plat(dev);
68
Stephen Warren92c67fa2016-07-13 13:45:31 -060069 debug("%s(dev=%p)\n", __func__, dev);
70
Miquel Raynalc1f527e2025-04-25 08:49:32 +020071 plat->subdomains = 1;
72
Stephen Warren92c67fa2016-07-13 13:45:31 -060073 return 0;
74}
75
76static const struct udevice_id sandbox_power_domain_ids[] = {
77 { .compatible = "sandbox,power-domain" },
78 { }
79};
80
81struct power_domain_ops sandbox_power_domain_ops = {
82 .request = sandbox_power_domain_request,
Simon Glass92ed3a32020-02-03 07:35:51 -070083 .rfree = sandbox_power_domain_free,
Stephen Warren92c67fa2016-07-13 13:45:31 -060084 .on = sandbox_power_domain_on,
85 .off = sandbox_power_domain_off,
86};
87
88U_BOOT_DRIVER(sandbox_power_domain) = {
89 .name = "sandbox_power_domain",
90 .id = UCLASS_POWER_DOMAIN,
91 .of_match = sandbox_power_domain_ids,
92 .bind = sandbox_power_domain_bind,
93 .probe = sandbox_power_domain_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -070094 .priv_auto = sizeof(struct sandbox_power_domain),
Stephen Warren92c67fa2016-07-13 13:45:31 -060095 .ops = &sandbox_power_domain_ops,
96};
97
98int sandbox_power_domain_query(struct udevice *dev, unsigned long id)
99{
100 struct sandbox_power_domain *sbr = dev_get_priv(dev);
101
102 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
103
104 if (id >= SANDBOX_POWER_DOMAINS)
105 return -EINVAL;
106
107 return sbr->on[id];
108}