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