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> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Álvaro Fernández Rojas | 18393f7 | 2017-05-03 15:10:21 +0200 | [diff] [blame] | 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 = { |
Simon Glass | 94474b2 | 2020-02-03 07:35:52 -0700 | [diff] [blame] | 56 | .rfree = bcm6345_reset_free, |
Álvaro Fernández Rojas | 18393f7 | 2017-05-03 15:10:21 +0200 | [diff] [blame] | 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); |
Álvaro Fernández Rojas | 18393f7 | 2017-05-03 15:10:21 +0200 | [diff] [blame] | 70 | |
Álvaro Fernández Rojas | 56d4b70 | 2018-03-22 19:39:31 +0100 | [diff] [blame] | 71 | priv->regs = dev_remap_addr(dev); |
| 72 | if (!priv->regs) |
Álvaro Fernández Rojas | 18393f7 | 2017-05-03 15:10:21 +0200 | [diff] [blame] | 73 | return -EINVAL; |
| 74 | |
Álvaro Fernández Rojas | 18393f7 | 2017-05-03 15:10:21 +0200 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | U_BOOT_DRIVER(bcm6345_reset) = { |
| 79 | .name = "bcm6345-reset", |
| 80 | .id = UCLASS_RESET, |
| 81 | .of_match = bcm6345_reset_ids, |
| 82 | .ops = &bcm6345_reset_reset_ops, |
| 83 | .probe = bcm6345_reset_probe, |
| 84 | .priv_auto_alloc_size = sizeof(struct bcm6345_reset_priv), |
| 85 | }; |