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