blob: a90b2c83df8498a55f0ba93007f2b5863c52975e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +02002/*
3 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +02004 */
5
6#include <common.h>
7#include <dm.h>
8#include <power-domain-uclass.h>
9#include <asm/io.h>
10
11#define MAX_DOMAINS 32
12
13struct bcm6328_power_domain {
14 void __iomem *regs;
15};
16
17static int bcm6328_power_domain_request(struct power_domain *power_domain)
18{
19 if (power_domain->id >= MAX_DOMAINS)
20 return -EINVAL;
21
22 return 0;
23}
24
25static int bcm6328_power_domain_free(struct power_domain *power_domain)
26{
27 return 0;
28}
29
30static int bcm6328_power_domain_on(struct power_domain *power_domain)
31{
32 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
33
34 clrbits_be32(priv->regs, BIT(power_domain->id));
35
36 return 0;
37}
38
39static int bcm6328_power_domain_off(struct power_domain *power_domain)
40{
41 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
42
43 setbits_be32(priv->regs, BIT(power_domain->id));
44
45 return 0;
46}
47
48static int bcm6328_power_domain_probe(struct udevice *dev)
49{
50 struct bcm6328_power_domain *priv = dev_get_priv(dev);
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020051
Álvaro Fernández Rojas713857a2018-03-22 19:39:35 +010052 priv->regs = dev_remap_addr(dev);
53 if (!priv->regs)
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020054 return -EINVAL;
55
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020056 return 0;
57}
58
59static const struct udevice_id bcm6328_power_domain_ids[] = {
60 { .compatible = "brcm,bcm6328-power-domain" },
61 { /* sentinel */ }
62};
63
64struct power_domain_ops bcm6328_power_domain_ops = {
65 .free = bcm6328_power_domain_free,
66 .off = bcm6328_power_domain_off,
67 .on = bcm6328_power_domain_on,
68 .request = bcm6328_power_domain_request,
69};
70
71U_BOOT_DRIVER(bcm6328_power_domain) = {
72 .name = "bcm6328_power_domain",
73 .id = UCLASS_POWER_DOMAIN,
74 .of_match = bcm6328_power_domain_ids,
75 .ops = &bcm6328_power_domain_ops,
76 .priv_auto_alloc_size = sizeof(struct bcm6328_power_domain),
77 .probe = bcm6328_power_domain_probe,
78};