blob: 80144dd977250b1d236e61e28b0a600b2e628dda [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
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020027static int bcm6328_power_domain_on(struct power_domain *power_domain)
28{
29 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
30
31 clrbits_be32(priv->regs, BIT(power_domain->id));
32
33 return 0;
34}
35
36static int bcm6328_power_domain_off(struct power_domain *power_domain)
37{
38 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
39
40 setbits_be32(priv->regs, BIT(power_domain->id));
41
42 return 0;
43}
44
45static int bcm6328_power_domain_probe(struct udevice *dev)
46{
47 struct bcm6328_power_domain *priv = dev_get_priv(dev);
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020048
Álvaro Fernández Rojas713857a2018-03-22 19:39:35 +010049 priv->regs = dev_remap_addr(dev);
50 if (!priv->regs)
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020051 return -EINVAL;
52
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020053 return 0;
54}
55
56static const struct udevice_id bcm6328_power_domain_ids[] = {
57 { .compatible = "brcm,bcm6328-power-domain" },
58 { /* sentinel */ }
59};
60
61struct power_domain_ops bcm6328_power_domain_ops = {
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020062 .off = bcm6328_power_domain_off,
63 .on = bcm6328_power_domain_on,
64 .request = bcm6328_power_domain_request,
65};
66
67U_BOOT_DRIVER(bcm6328_power_domain) = {
68 .name = "bcm6328_power_domain",
69 .id = UCLASS_POWER_DOMAIN,
70 .of_match = bcm6328_power_domain_ids,
71 .ops = &bcm6328_power_domain_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070072 .priv_auto = sizeof(struct bcm6328_power_domain),
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020073 .probe = bcm6328_power_domain_probe,
74};