blob: 6e720e0798c31d277c23c7577e025395388f49ef [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>
Simon Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +02009#include <power-domain-uclass.h>
10#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060011#include <linux/bitops.h>
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020012
13#define MAX_DOMAINS 32
14
15struct bcm6328_power_domain {
16 void __iomem *regs;
17};
18
19static int bcm6328_power_domain_request(struct power_domain *power_domain)
20{
21 if (power_domain->id >= MAX_DOMAINS)
22 return -EINVAL;
23
24 return 0;
25}
26
27static int bcm6328_power_domain_free(struct power_domain *power_domain)
28{
29 return 0;
30}
31
32static int bcm6328_power_domain_on(struct power_domain *power_domain)
33{
34 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
35
36 clrbits_be32(priv->regs, BIT(power_domain->id));
37
38 return 0;
39}
40
41static int bcm6328_power_domain_off(struct power_domain *power_domain)
42{
43 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
44
45 setbits_be32(priv->regs, BIT(power_domain->id));
46
47 return 0;
48}
49
50static int bcm6328_power_domain_probe(struct udevice *dev)
51{
52 struct bcm6328_power_domain *priv = dev_get_priv(dev);
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020053
Álvaro Fernández Rojas713857a2018-03-22 19:39:35 +010054 priv->regs = dev_remap_addr(dev);
55 if (!priv->regs)
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020056 return -EINVAL;
57
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020058 return 0;
59}
60
61static const struct udevice_id bcm6328_power_domain_ids[] = {
62 { .compatible = "brcm,bcm6328-power-domain" },
63 { /* sentinel */ }
64};
65
66struct power_domain_ops bcm6328_power_domain_ops = {
Simon Glass92ed3a32020-02-03 07:35:51 -070067 .rfree = bcm6328_power_domain_free,
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020068 .off = bcm6328_power_domain_off,
69 .on = bcm6328_power_domain_on,
70 .request = bcm6328_power_domain_request,
71};
72
73U_BOOT_DRIVER(bcm6328_power_domain) = {
74 .name = "bcm6328_power_domain",
75 .id = UCLASS_POWER_DOMAIN,
76 .of_match = bcm6328_power_domain_ids,
77 .ops = &bcm6328_power_domain_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070078 .priv_auto = sizeof(struct bcm6328_power_domain),
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020079 .probe = bcm6328_power_domain_probe,
80};