Álvaro Fernández Rojas | 8bdcdae | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <power-domain-uclass.h> |
| 10 | #include <asm/io.h> |
| 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 | |
| 26 | static int bcm6328_power_domain_free(struct power_domain *power_domain) |
| 27 | { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static int bcm6328_power_domain_on(struct power_domain *power_domain) |
| 32 | { |
| 33 | struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev); |
| 34 | |
| 35 | clrbits_be32(priv->regs, BIT(power_domain->id)); |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int bcm6328_power_domain_off(struct power_domain *power_domain) |
| 41 | { |
| 42 | struct bcm6328_power_domain *priv = dev_get_priv(power_domain->dev); |
| 43 | |
| 44 | setbits_be32(priv->regs, BIT(power_domain->id)); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int bcm6328_power_domain_probe(struct udevice *dev) |
| 50 | { |
| 51 | struct bcm6328_power_domain *priv = dev_get_priv(dev); |
| 52 | fdt_addr_t addr; |
| 53 | fdt_size_t size; |
| 54 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 55 | addr = devfdt_get_addr_size_index(dev, 0, &size); |
Álvaro Fernández Rojas | 8bdcdae | 2017-05-07 20:28:36 +0200 | [diff] [blame] | 56 | if (addr == FDT_ADDR_T_NONE) |
| 57 | return -EINVAL; |
| 58 | |
| 59 | priv->regs = ioremap(addr, size); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static const struct udevice_id bcm6328_power_domain_ids[] = { |
| 65 | { .compatible = "brcm,bcm6328-power-domain" }, |
| 66 | { /* sentinel */ } |
| 67 | }; |
| 68 | |
| 69 | struct power_domain_ops bcm6328_power_domain_ops = { |
| 70 | .free = bcm6328_power_domain_free, |
| 71 | .off = bcm6328_power_domain_off, |
| 72 | .on = bcm6328_power_domain_on, |
| 73 | .request = bcm6328_power_domain_request, |
| 74 | }; |
| 75 | |
| 76 | U_BOOT_DRIVER(bcm6328_power_domain) = { |
| 77 | .name = "bcm6328_power_domain", |
| 78 | .id = UCLASS_POWER_DOMAIN, |
| 79 | .of_match = bcm6328_power_domain_ids, |
| 80 | .ops = &bcm6328_power_domain_ops, |
| 81 | .priv_auto_alloc_size = sizeof(struct bcm6328_power_domain), |
| 82 | .probe = bcm6328_power_domain_probe, |
| 83 | }; |