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