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