~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: a9589d448dca30f8b15fa98985fbf5b108f02c16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: GPL-2.0
/*
 * Texas Instruments DRA7 reset driver
 *
 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
 * Author: Keerthy <j-keerthy@ti.com>
 */

#include <asm/io.h>
#include <common.h>
#include <dm.h>
#include <reset-uclass.h>
#include <dm/device_compat.h>

struct dra7_reset_priv {
	u32 rstctrl;
	u32 rstst;
	u8 nreset;
};

static inline void dra7_reset_rmw(u32 addr, u32 value, u32 mask)
{
	writel(((readl(addr) & (~mask)) | (value & mask)), addr);
}

static int dra7_reset_deassert(struct reset_ctl *reset_ctl)
{
	struct dra7_reset_priv *priv = dev_get_priv(reset_ctl->dev);
	int mask = 1 << reset_ctl->id;

	if (reset_ctl->id < 0 || reset_ctl->id >= priv->nreset)
		return -EINVAL;

	dra7_reset_rmw(priv->rstctrl, 0x0, mask);

	while ((readl(priv->rstst) & mask) != mask)
		;

	return 0;
}

static int dra7_reset_assert(struct reset_ctl *reset_ctl)
{
	struct dra7_reset_priv *priv = dev_get_priv(reset_ctl->dev);
	int mask = 1 << reset_ctl->id;

	if (reset_ctl->id < 0 || reset_ctl->id >= priv->nreset)
		return -EINVAL;

	dra7_reset_rmw(priv->rstctrl, mask, 0x0);

	return 0;
}

struct reset_ops dra7_reset_ops = {
	.rst_assert = dra7_reset_assert,
	.rst_deassert = dra7_reset_deassert,
};

static const struct udevice_id dra7_reset_ids[] = {
	{ .compatible = "ti,dra7-reset" },
	{ }
};

static int dra7_reset_probe(struct udevice *dev)
{
	struct dra7_reset_priv *priv = dev_get_priv(dev);

	priv->rstctrl = dev_read_addr(dev);
	priv->rstst = priv->rstctrl + 0x4;
	priv->nreset = dev_read_u32_default(dev, "ti,nresets", 1);

	dev_info(dev, "dra7-reset successfully probed %s\n", dev->name);

	return 0;
}

U_BOOT_DRIVER(dra7_reset) = {
	.name = "dra7_reset",
	.id = UCLASS_RESET,
	.of_match = dra7_reset_ids,
	.probe = dra7_reset_probe,
	.ops = &dra7_reset_ops,
	.priv_auto = sizeof(struct dra7_reset_priv),
};