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 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 8 | #include <malloc.h> |
Álvaro Fernández Rojas | 8bdcdae | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 9 | #include <power-domain-uclass.h> |
| 10 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 11 | #include <linux/bitops.h> |
Álvaro Fernández Rojas | 8bdcdae | 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 | |
| 27 | static int bcm6328_power_domain_free(struct power_domain *power_domain) |
| 28 | { |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static 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 | |
| 41 | static 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 | |
| 50 | static int bcm6328_power_domain_probe(struct udevice *dev) |
| 51 | { |
| 52 | struct bcm6328_power_domain *priv = dev_get_priv(dev); |
Álvaro Fernández Rojas | 8bdcdae | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 53 | |
Álvaro Fernández Rojas | 713857a | 2018-03-22 19:39:35 +0100 | [diff] [blame] | 54 | priv->regs = dev_remap_addr(dev); |
| 55 | if (!priv->regs) |
Álvaro Fernández Rojas | 8bdcdae | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 56 | return -EINVAL; |
| 57 | |
Álvaro Fernández Rojas | 8bdcdae | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static const struct udevice_id bcm6328_power_domain_ids[] = { |
| 62 | { .compatible = "brcm,bcm6328-power-domain" }, |
| 63 | { /* sentinel */ } |
| 64 | }; |
| 65 | |
| 66 | struct power_domain_ops bcm6328_power_domain_ops = { |
Simon Glass | 92ed3a3 | 2020-02-03 07:35:51 -0700 | [diff] [blame] | 67 | .rfree = bcm6328_power_domain_free, |
Álvaro Fernández Rojas | 8bdcdae | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 68 | .off = bcm6328_power_domain_off, |
| 69 | .on = bcm6328_power_domain_on, |
| 70 | .request = bcm6328_power_domain_request, |
| 71 | }; |
| 72 | |
| 73 | U_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, |
| 78 | .priv_auto_alloc_size = sizeof(struct bcm6328_power_domain), |
| 79 | .probe = bcm6328_power_domain_probe, |
| 80 | }; |