blob: 585f8323c52e3a5b12c52ebcc85aeccea8e424fc [file] [log] [blame]
Keerthy0c0bdbb2022-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
21static int dra7_reset_request(struct reset_ctl *reset_ctl)
22{
23 return 0;
24}
25
26static int dra7_reset_free(struct reset_ctl *reset_ctl)
27{
28 return 0;
29}
30
31static inline void dra7_reset_rmw(u32 addr, u32 value, u32 mask)
32{
33 writel(((readl(addr) & (~mask)) | (value & mask)), addr);
34}
35
36static int dra7_reset_deassert(struct reset_ctl *reset_ctl)
37{
38 struct dra7_reset_priv *priv = dev_get_priv(reset_ctl->dev);
39 int mask = 1 << reset_ctl->id;
40
41 if (reset_ctl->id < 0 || reset_ctl->id >= priv->nreset)
42 return -EINVAL;
43
44 dra7_reset_rmw(priv->rstctrl, 0x0, mask);
45
46 while ((readl(priv->rstst) & mask) != mask)
47 ;
48
49 return 0;
50}
51
52static int dra7_reset_assert(struct reset_ctl *reset_ctl)
53{
54 struct dra7_reset_priv *priv = dev_get_priv(reset_ctl->dev);
55 int mask = 1 << reset_ctl->id;
56
57 if (reset_ctl->id < 0 || reset_ctl->id >= priv->nreset)
58 return -EINVAL;
59
60 dra7_reset_rmw(priv->rstctrl, mask, 0x0);
61
62 return 0;
63}
64
65struct reset_ops dra7_reset_ops = {
66 .request = dra7_reset_request,
67 .rfree = dra7_reset_free,
68 .rst_assert = dra7_reset_assert,
69 .rst_deassert = dra7_reset_deassert,
70};
71
72static const struct udevice_id dra7_reset_ids[] = {
73 { .compatible = "ti,dra7-reset" },
74 { }
75};
76
77static int dra7_reset_probe(struct udevice *dev)
78{
79 struct dra7_reset_priv *priv = dev_get_priv(dev);
80
81 priv->rstctrl = dev_read_addr(dev);
82 priv->rstst = priv->rstctrl + 0x4;
83 priv->nreset = dev_read_u32_default(dev, "ti,nresets", 1);
84
85 dev_info(dev, "dra7-reset successfully probed %s\n", dev->name);
86
87 return 0;
88}
89
90U_BOOT_DRIVER(dra7_reset) = {
91 .name = "dra7_reset",
92 .id = UCLASS_RESET,
93 .of_match = dra7_reset_ids,
94 .probe = dra7_reset_probe,
95 .ops = &dra7_reset_ops,
96 .priv_auto = sizeof(struct dra7_reset_priv),
97};