blob: 2f0ec4c042f73d1da94b2eda16c57ed9d2cca401 [file] [log] [blame]
Keerthy0c0bdbb2022-01-27 13:16:51 +01001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Texas Instruments DRA7 reset driver
4 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
Keerthy0c0bdbb2022-01-27 13:16:51 +01006 * Author: Keerthy <j-keerthy@ti.com>
7 */
8
9#include <asm/io.h>
Keerthy0c0bdbb2022-01-27 13:16:51 +010010#include <dm.h>
11#include <reset-uclass.h>
12#include <dm/device_compat.h>
13
14struct dra7_reset_priv {
15 u32 rstctrl;
16 u32 rstst;
17 u8 nreset;
18};
19
Keerthy0c0bdbb2022-01-27 13:16:51 +010020static inline void dra7_reset_rmw(u32 addr, u32 value, u32 mask)
21{
22 writel(((readl(addr) & (~mask)) | (value & mask)), addr);
23}
24
25static 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
41static 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
54struct reset_ops dra7_reset_ops = {
Keerthy0c0bdbb2022-01-27 13:16:51 +010055 .rst_assert = dra7_reset_assert,
56 .rst_deassert = dra7_reset_deassert,
57};
58
59static const struct udevice_id dra7_reset_ids[] = {
60 { .compatible = "ti,dra7-reset" },
61 { }
62};
63
64static 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
77U_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};