Keerthy | 0c0bdbb | 2022-01-27 13:16:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Texas Instruments DRA7 reset driver |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/ |
Keerthy | 0c0bdbb | 2022-01-27 13:16:51 +0100 | [diff] [blame] | 6 | * Author: Keerthy <j-keerthy@ti.com> |
| 7 | */ |
| 8 | |
| 9 | #include <asm/io.h> |
Keerthy | 0c0bdbb | 2022-01-27 13:16:51 +0100 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <reset-uclass.h> |
| 12 | #include <dm/device_compat.h> |
| 13 | |
| 14 | struct dra7_reset_priv { |
| 15 | u32 rstctrl; |
| 16 | u32 rstst; |
| 17 | u8 nreset; |
| 18 | }; |
| 19 | |
Keerthy | 0c0bdbb | 2022-01-27 13:16:51 +0100 | [diff] [blame] | 20 | static inline void dra7_reset_rmw(u32 addr, u32 value, u32 mask) |
| 21 | { |
| 22 | writel(((readl(addr) & (~mask)) | (value & mask)), addr); |
| 23 | } |
| 24 | |
| 25 | static int dra7_reset_deassert(struct reset_ctl *reset_ctl) |
| 26 | { |
| 27 | struct dra7_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 28 | int mask = 1 << reset_ctl->id; |
| 29 | |
| 30 | if (reset_ctl->id < 0 || reset_ctl->id >= priv->nreset) |
| 31 | return -EINVAL; |
| 32 | |
| 33 | dra7_reset_rmw(priv->rstctrl, 0x0, mask); |
| 34 | |
| 35 | while ((readl(priv->rstst) & mask) != mask) |
| 36 | ; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static int dra7_reset_assert(struct reset_ctl *reset_ctl) |
| 42 | { |
| 43 | struct dra7_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 44 | int mask = 1 << reset_ctl->id; |
| 45 | |
| 46 | if (reset_ctl->id < 0 || reset_ctl->id >= priv->nreset) |
| 47 | return -EINVAL; |
| 48 | |
| 49 | dra7_reset_rmw(priv->rstctrl, mask, 0x0); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | struct reset_ops dra7_reset_ops = { |
Keerthy | 0c0bdbb | 2022-01-27 13:16:51 +0100 | [diff] [blame] | 55 | .rst_assert = dra7_reset_assert, |
| 56 | .rst_deassert = dra7_reset_deassert, |
| 57 | }; |
| 58 | |
| 59 | static const struct udevice_id dra7_reset_ids[] = { |
| 60 | { .compatible = "ti,dra7-reset" }, |
| 61 | { } |
| 62 | }; |
| 63 | |
| 64 | static int dra7_reset_probe(struct udevice *dev) |
| 65 | { |
| 66 | struct dra7_reset_priv *priv = dev_get_priv(dev); |
| 67 | |
| 68 | priv->rstctrl = dev_read_addr(dev); |
| 69 | priv->rstst = priv->rstctrl + 0x4; |
| 70 | priv->nreset = dev_read_u32_default(dev, "ti,nresets", 1); |
| 71 | |
| 72 | dev_info(dev, "dra7-reset successfully probed %s\n", dev->name); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | U_BOOT_DRIVER(dra7_reset) = { |
| 78 | .name = "dra7_reset", |
| 79 | .id = UCLASS_RESET, |
| 80 | .of_match = dra7_reset_ids, |
| 81 | .probe = dra7_reset_probe, |
| 82 | .ops = &dra7_reset_ops, |
| 83 | .priv_auto = sizeof(struct dra7_reset_priv), |
| 84 | }; |