summaryrefslogtreecommitdiff
path: root/drivers/reset/reset-zynqmp.c
blob: 57652346738da74c94a476d03af23bd85d213f23 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2021 Xilinx, Inc. - Michal Simek
 */

#define LOG_CATEGORY UCLASS_RESET

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

#define ZYNQMP_NR_RESETS	(ZYNQMP_PM_RESET_END - ZYNQMP_PM_RESET_START)
#define ZYNQMP_RESET_ID		ZYNQMP_PM_RESET_START

struct zynqmp_reset_priv {
	u32 reset_id;
	u32 nr_reset;
};

static int zynqmp_pm_reset_assert(const u32 reset,
				  const enum zynqmp_pm_reset_action assert_flag)
{
	return xilinx_pm_request(PM_RESET_ASSERT, reset, assert_flag, 0, 0,
				 NULL);
}

static int zynqmp_reset_assert(struct reset_ctl *rst)
{
	struct zynqmp_reset_priv *priv = dev_get_priv(rst->dev);

	dev_dbg(rst->dev, "%s(rst=%p) (id=%lu)\n", __func__, rst, rst->id);

	return zynqmp_pm_reset_assert(priv->reset_id + rst->id,
				      PM_RESET_ACTION_ASSERT);
}

static int zynqmp_reset_deassert(struct reset_ctl *rst)
{
	struct zynqmp_reset_priv *priv = dev_get_priv(rst->dev);

	dev_dbg(rst->dev, "%s(rst=%p) (id=%lu)\n", __func__, rst, rst->id);

	return zynqmp_pm_reset_assert(priv->reset_id + rst->id,
				      PM_RESET_ACTION_RELEASE);
}

static int zynqmp_reset_request(struct reset_ctl *rst)
{
	struct zynqmp_reset_priv *priv = dev_get_priv(rst->dev);

	dev_dbg(rst->dev, "%s(rst=%p) (id=%lu) (nr_reset=%d)\n", __func__,
		rst, rst->id, priv->nr_reset);

	if (rst->id > priv->nr_reset)
		return -EINVAL;

	return 0;
}

static int zynqmp_reset_free(struct reset_ctl *rst)
{
	struct zynqmp_reset_priv *priv = dev_get_priv(rst->dev);

	dev_dbg(rst->dev, "%s(rst=%p) (id=%lu) (nr_reset=%d)\n", __func__,
		rst, rst->id, priv->nr_reset);

	return 0;
}

static int zynqmp_reset_probe(struct udevice *dev)
{
	struct zynqmp_reset_priv *priv = dev_get_priv(dev);

	priv->reset_id = ZYNQMP_RESET_ID;
	priv->nr_reset = ZYNQMP_NR_RESETS;
	return 0;
}

const struct reset_ops zynqmp_reset_ops = {
	.request = zynqmp_reset_request,
	.rfree = zynqmp_reset_free,
	.rst_assert = zynqmp_reset_assert,
	.rst_deassert = zynqmp_reset_deassert,
};

static const struct udevice_id zynqmp_reset_ids[] = {
	{ .compatible = "xlnx,zynqmp-reset" },
	{ }
};

U_BOOT_DRIVER(zynqmp_reset) = {
	.name		= "zynqmp_reset",
	.id		= UCLASS_RESET,
	.of_match	= zynqmp_reset_ids,
	.ops		= &zynqmp_reset_ops,
	.probe		= zynqmp_reset_probe,
	.priv_auto	= sizeof(struct zynqmp_reset_priv),
};