blob: 36b5a933748073e5aa774298a2fd07757e5a779c [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
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +02006#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -07007#include <malloc.h>
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +02008#include <power-domain-uclass.h>
9#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060010#include <linux/bitops.h>
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020011
12#define MAX_DOMAINS 32
13
14struct bcm6328_power_domain {
15 void __iomem *regs;
16};
17
18static int bcm6328_power_domain_request(struct power_domain *power_domain)
19{
20 if (power_domain->id >= MAX_DOMAINS)
21 return -EINVAL;
22
23 return 0;
24}
25
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020026static int bcm6328_power_domain_on(struct power_domain *power_domain)
27{
28 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
29
30 clrbits_be32(priv->regs, BIT(power_domain->id));
31
32 return 0;
33}
34
35static int bcm6328_power_domain_off(struct power_domain *power_domain)
36{
37 struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev);
38
39 setbits_be32(priv->regs, BIT(power_domain->id));
40
41 return 0;
42}
43
44static int bcm6328_power_domain_probe(struct udevice *dev)
45{
46 struct bcm6328_power_domain *priv = dev_get_priv(dev);
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020047
Álvaro Fernández Rojas713857a2018-03-22 19:39:35 +010048 priv->regs = dev_remap_addr(dev);
49 if (!priv->regs)
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020050 return -EINVAL;
51
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020052 return 0;
53}
54
55static const struct udevice_id bcm6328_power_domain_ids[] = {
56 { .compatible = "brcm,bcm6328-power-domain" },
57 { /* sentinel */ }
58};
59
60struct power_domain_ops bcm6328_power_domain_ops = {
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020061 .off = bcm6328_power_domain_off,
62 .on = bcm6328_power_domain_on,
63 .request = bcm6328_power_domain_request,
64};
65
66U_BOOT_DRIVER(bcm6328_power_domain) = {
67 .name = "bcm6328_power_domain",
68 .id = UCLASS_POWER_DOMAIN,
69 .of_match = bcm6328_power_domain_ids,
70 .ops = &bcm6328_power_domain_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070071 .priv_auto = sizeof(struct bcm6328_power_domain),
Álvaro Fernández Rojas8bdcdae2017-05-07 20:28:36 +020072 .probe = bcm6328_power_domain_probe,
73};