blob: a9589d448dca30f8b15fa98985fbf5b108f02c16 [file] [log] [blame]
Keerthy795b2c42022-01-27 13:16:51 +01001// 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
15struct dra7_reset_priv {
16 u32 rstctrl;
17 u32 rstst;
18 u8 nreset;
19};
20
Keerthy795b2c42022-01-27 13:16:51 +010021static inline void dra7_reset_rmw(u32 addr, u32 value, u32 mask)
22{
23 writel(((readl(addr) & (~mask)) | (value & mask)), addr);
24}
25
26static 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
42static 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
55struct reset_ops dra7_reset_ops = {
Keerthy795b2c42022-01-27 13:16:51 +010056 .rst_assert = dra7_reset_assert,
57 .rst_deassert = dra7_reset_deassert,
58};
59
60static const struct udevice_id dra7_reset_ids[] = {
61 { .compatible = "ti,dra7-reset" },
62 { }
63};
64
65static 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
78U_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};