blob: 04a071044f3b5f6d01ab5c35eb1dc726a5a6eee1 [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
6#include <common.h>
7#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -07009#include <malloc.h>
Stephen Warren61f5ddc2016-07-13 13:45:31 -060010#include <power-domain-uclass.h>
11#include <asm/io.h>
12#include <asm/power-domain.h>
13
14#define SANDBOX_POWER_DOMAINS 3
15
16struct sandbox_power_domain {
17 bool on[SANDBOX_POWER_DOMAINS];
18};
19
20static 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
30static 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
37static 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
48static 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
59static int sandbox_power_domain_bind(struct udevice *dev)
60{
61 debug("%s(dev=%p)\n", __func__, dev);
62
63 return 0;
64}
65
66static int sandbox_power_domain_probe(struct udevice *dev)
67{
68 debug("%s(dev=%p)\n", __func__, dev);
69
70 return 0;
71}
72
73static const struct udevice_id sandbox_power_domain_ids[] = {
74 { .compatible = "sandbox,power-domain" },
75 { }
76};
77
78struct power_domain_ops sandbox_power_domain_ops = {
79 .request = sandbox_power_domain_request,
Simon Glass4f511882020-02-03 07:35:51 -070080 .rfree = sandbox_power_domain_free,
Stephen Warren61f5ddc2016-07-13 13:45:31 -060081 .on = sandbox_power_domain_on,
82 .off = sandbox_power_domain_off,
83};
84
85U_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,
Simon Glass41575d82020-12-03 16:55:17 -070091 .priv_auto = sizeof(struct sandbox_power_domain),
Stephen Warren61f5ddc2016-07-13 13:45:31 -060092 .ops = &sandbox_power_domain_ops,
93};
94
95int 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}