blob: 74db2eba7e23cd3cadc9ade0f4c5987ba25fb8ed [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>
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
14struct sandbox_power_domain {
15 bool on[SANDBOX_POWER_DOMAINS];
16};
17
18static 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
28static 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
35static 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
46static 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
57static int sandbox_power_domain_bind(struct udevice *dev)
58{
59 debug("%s(dev=%p)\n", __func__, dev);
60
61 return 0;
62}
63
64static int sandbox_power_domain_probe(struct udevice *dev)
65{
66 debug("%s(dev=%p)\n", __func__, dev);
67
68 return 0;
69}
70
71static const struct udevice_id sandbox_power_domain_ids[] = {
72 { .compatible = "sandbox,power-domain" },
73 { }
74};
75
76struct 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
83U_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
93int 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}