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