1 /* 2 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com> 3 * 4 * Derived from linux/arch/mips/bcm63xx/reset.c: 5 * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com> 6 * 7 * SPDX-License-Identifier: GPL-2.0+ 8 */ 9 10 #include <common.h> 11 #include <dm.h> 12 #include <errno.h> 13 #include <reset-uclass.h> 14 #include <asm/io.h> 15 16 #define MAX_RESETS 32 17 18 struct bcm6345_reset_priv { 19 void __iomem *regs; 20 }; 21 22 static int bcm6345_reset_assert(struct reset_ctl *rst) 23 { 24 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev); 25 26 clrbits_be32(priv->regs, BIT(rst->id)); 27 mdelay(20); 28 29 return 0; 30 } 31 32 static int bcm6345_reset_deassert(struct reset_ctl *rst) 33 { 34 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev); 35 36 setbits_be32(priv->regs, BIT(rst->id)); 37 mdelay(20); 38 39 return 0; 40 } 41 42 static int bcm6345_reset_free(struct reset_ctl *rst) 43 { 44 return 0; 45 } 46 47 static int bcm6345_reset_request(struct reset_ctl *rst) 48 { 49 if (rst->id >= MAX_RESETS) 50 return -EINVAL; 51 52 return bcm6345_reset_assert(rst); 53 } 54 55 struct reset_ops bcm6345_reset_reset_ops = { 56 .free = bcm6345_reset_free, 57 .request = bcm6345_reset_request, 58 .rst_assert = bcm6345_reset_assert, 59 .rst_deassert = bcm6345_reset_deassert, 60 }; 61 62 static const struct udevice_id bcm6345_reset_ids[] = { 63 { .compatible = "brcm,bcm6345-reset" }, 64 { /* sentinel */ } 65 }; 66 67 static int bcm6345_reset_probe(struct udevice *dev) 68 { 69 struct bcm6345_reset_priv *priv = dev_get_priv(dev); 70 fdt_addr_t addr; 71 fdt_size_t size; 72 73 addr = devfdt_get_addr_size_index(dev, 0, &size); 74 if (addr == FDT_ADDR_T_NONE) 75 return -EINVAL; 76 77 priv->regs = ioremap(addr, size); 78 79 return 0; 80 } 81 82 U_BOOT_DRIVER(bcm6345_reset) = { 83 .name = "bcm6345-reset", 84 .id = UCLASS_RESET, 85 .of_match = bcm6345_reset_ids, 86 .ops = &bcm6345_reset_reset_ops, 87 .probe = bcm6345_reset_probe, 88 .priv_auto_alloc_size = sizeof(struct bcm6345_reset_priv), 89 }; 90