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