blob: 4e3f907980f61d96afb546e5c23998bc74f2baa9 [file] [log] [blame]
Michal Simekf0e47692021-07-30 08:00:10 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2021 Xilinx, Inc. - Michal Simek
4 */
5
6#define LOG_CATEGORY UCLASS_RESET
7
8#include <common.h>
9#include <dm.h>
10#include <dm/device_compat.h>
11#include <reset-uclass.h>
12#include <zynqmp_firmware.h>
13
14#define ZYNQMP_NR_RESETS (ZYNQMP_PM_RESET_END - ZYNQMP_PM_RESET_START)
15#define ZYNQMP_RESET_ID ZYNQMP_PM_RESET_START
16
17struct zynqmp_reset_priv {
18 u32 reset_id;
19 u32 nr_reset;
20};
21
22static int zynqmp_pm_reset_assert(const u32 reset,
23 const enum zynqmp_pm_reset_action assert_flag)
24{
25 return xilinx_pm_request(PM_RESET_ASSERT, reset, assert_flag, 0, 0,
26 NULL);
27}
28
29static int zynqmp_reset_assert(struct reset_ctl *rst)
30{
31 struct zynqmp_reset_priv *priv = dev_get_priv(rst->dev);
32
33 dev_dbg(rst->dev, "%s(rst=%p) (id=%lu)\n", __func__, rst, rst->id);
34
35 return zynqmp_pm_reset_assert(priv->reset_id + rst->id,
36 PM_RESET_ACTION_ASSERT);
37}
38
39static int zynqmp_reset_deassert(struct reset_ctl *rst)
40{
41 struct zynqmp_reset_priv *priv = dev_get_priv(rst->dev);
42
43 dev_dbg(rst->dev, "%s(rst=%p) (id=%lu)\n", __func__, rst, rst->id);
44
45 return zynqmp_pm_reset_assert(priv->reset_id + rst->id,
46 PM_RESET_ACTION_RELEASE);
47}
48
49static int zynqmp_reset_request(struct reset_ctl *rst)
50{
51 struct zynqmp_reset_priv *priv = dev_get_priv(rst->dev);
52
53 dev_dbg(rst->dev, "%s(rst=%p) (id=%lu) (nr_reset=%d)\n", __func__,
54 rst, rst->id, priv->nr_reset);
55
56 if (rst->id > priv->nr_reset)
57 return -EINVAL;
58
59 return 0;
60}
61
Michal Simekf0e47692021-07-30 08:00:10 +020062static int zynqmp_reset_probe(struct udevice *dev)
63{
64 struct zynqmp_reset_priv *priv = dev_get_priv(dev);
65
66 priv->reset_id = ZYNQMP_RESET_ID;
67 priv->nr_reset = ZYNQMP_NR_RESETS;
68 return 0;
69}
70
71const struct reset_ops zynqmp_reset_ops = {
72 .request = zynqmp_reset_request,
Michal Simekf0e47692021-07-30 08:00:10 +020073 .rst_assert = zynqmp_reset_assert,
74 .rst_deassert = zynqmp_reset_deassert,
75};
76
77static const struct udevice_id zynqmp_reset_ids[] = {
78 { .compatible = "xlnx,zynqmp-reset" },
79 { }
80};
81
82U_BOOT_DRIVER(zynqmp_reset) = {
83 .name = "zynqmp_reset",
84 .id = UCLASS_RESET,
85 .of_match = zynqmp_reset_ids,
86 .ops = &zynqmp_reset_ops,
87 .probe = zynqmp_reset_probe,
88 .priv_auto = sizeof(struct zynqmp_reset_priv),
89};