Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com> |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 8 | #include <malloc.h> |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 9 | #include <power-domain-uclass.h> |
| 10 | #include <asm/io.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 11 | #include <linux/bitops.h> |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 12 | |
| 13 | #define MAX_DOMAINS 32 |
| 14 | |
| 15 | struct bcm6328_power_domain { |
| 16 | void __iomem *regs; |
| 17 | }; |
| 18 | |
| 19 | static 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 Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 27 | static 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 | |
| 36 | static 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 | |
| 45 | static int bcm6328_power_domain_probe(struct udevice *dev) |
| 46 | { |
| 47 | struct bcm6328_power_domain *priv = dev_get_priv(dev); |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 48 | |
Álvaro Fernández Rojas | 34c0fc3 | 2018-03-22 19:39:35 +0100 | [diff] [blame] | 49 | priv->regs = dev_remap_addr(dev); |
| 50 | if (!priv->regs) |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 51 | return -EINVAL; |
| 52 | |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static const struct udevice_id bcm6328_power_domain_ids[] = { |
| 57 | { .compatible = "brcm,bcm6328-power-domain" }, |
| 58 | { /* sentinel */ } |
| 59 | }; |
| 60 | |
| 61 | struct power_domain_ops bcm6328_power_domain_ops = { |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 62 | .off = bcm6328_power_domain_off, |
| 63 | .on = bcm6328_power_domain_on, |
| 64 | .request = bcm6328_power_domain_request, |
| 65 | }; |
| 66 | |
| 67 | U_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 Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 72 | .priv_auto = sizeof(struct bcm6328_power_domain), |
Álvaro Fernández Rojas | 7810fb9 | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 73 | .probe = bcm6328_power_domain_probe, |
| 74 | }; |