blob: 59dc0ff9af9e850a22ee681324586d98f4a6b580 [file] [log] [blame]
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Xilinx, Inc.
4 *
5 */
6
7#include <linux/err.h>
8#include <linux/of.h>
9#include <linux/platform_device.h>
10#include <linux/reset-controller.h>
11#include <linux/firmware/xlnx-zynqmp.h>
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053012#include <linux/of_device.h>
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053013
14#define ZYNQMP_NR_RESETS (ZYNQMP_PM_RESET_END - ZYNQMP_PM_RESET_START)
15#define ZYNQMP_RESET_ID ZYNQMP_PM_RESET_START
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053016#define VERSAL_NR_RESETS 95
17
18struct zynqmp_reset_soc_data {
19 u32 reset_id;
20 u32 num_resets;
21};
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053022
23struct zynqmp_reset_data {
24 struct reset_controller_dev rcdev;
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053025 const struct zynqmp_reset_soc_data *data;
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053026};
27
28static inline struct zynqmp_reset_data *
29to_zynqmp_reset_data(struct reset_controller_dev *rcdev)
30{
31 return container_of(rcdev, struct zynqmp_reset_data, rcdev);
32}
33
34static int zynqmp_reset_assert(struct reset_controller_dev *rcdev,
35 unsigned long id)
36{
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053037 struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
38
39 return zynqmp_pm_reset_assert(priv->data->reset_id + id,
Rajan Vajacf23ec32020-04-24 13:57:54 -070040 PM_RESET_ACTION_ASSERT);
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053041}
42
43static int zynqmp_reset_deassert(struct reset_controller_dev *rcdev,
44 unsigned long id)
45{
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053046 struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
47
48 return zynqmp_pm_reset_assert(priv->data->reset_id + id,
Rajan Vajacf23ec32020-04-24 13:57:54 -070049 PM_RESET_ACTION_RELEASE);
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053050}
51
52static int zynqmp_reset_status(struct reset_controller_dev *rcdev,
53 unsigned long id)
54{
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053055 struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
Sai Krishna Potthuried104ca2021-06-23 13:46:20 +020056 int err;
57 u32 val;
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053058
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053059 err = zynqmp_pm_reset_get_status(priv->data->reset_id + id, &val);
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053060 if (err)
61 return err;
62
63 return val;
64}
65
66static int zynqmp_reset_reset(struct reset_controller_dev *rcdev,
67 unsigned long id)
68{
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053069 struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
70
71 return zynqmp_pm_reset_assert(priv->data->reset_id + id,
Rajan Vajacf23ec32020-04-24 13:57:54 -070072 PM_RESET_ACTION_PULSE);
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053073}
74
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053075static int zynqmp_reset_of_xlate(struct reset_controller_dev *rcdev,
76 const struct of_phandle_args *reset_spec)
77{
78 return reset_spec->args[0];
79}
80
81static const struct zynqmp_reset_soc_data zynqmp_reset_data = {
82 .reset_id = ZYNQMP_RESET_ID,
83 .num_resets = ZYNQMP_NR_RESETS,
84};
85
86static const struct zynqmp_reset_soc_data versal_reset_data = {
Philipp Zabel829cdfe2020-10-16 15:47:01 +020087 .reset_id = 0,
88 .num_resets = VERSAL_NR_RESETS,
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +053089};
90
Philipp Zabelc1b065b2019-10-21 16:08:13 +020091static const struct reset_control_ops zynqmp_reset_ops = {
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +053092 .reset = zynqmp_reset_reset,
93 .assert = zynqmp_reset_assert,
94 .deassert = zynqmp_reset_deassert,
95 .status = zynqmp_reset_status,
96};
97
98static int zynqmp_reset_probe(struct platform_device *pdev)
99{
100 struct zynqmp_reset_data *priv;
101
102 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
103 if (!priv)
104 return -ENOMEM;
105
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +0530106 priv->data = of_device_get_match_data(&pdev->dev);
107 if (!priv->data)
108 return -EINVAL;
109
Rajan Vaja3d031372019-03-04 15:18:08 -0800110 platform_set_drvdata(pdev, priv);
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +0530111
112 priv->rcdev.ops = &zynqmp_reset_ops;
113 priv->rcdev.owner = THIS_MODULE;
114 priv->rcdev.of_node = pdev->dev.of_node;
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +0530115 priv->rcdev.nr_resets = priv->data->num_resets;
116 priv->rcdev.of_reset_n_cells = 1;
117 priv->rcdev.of_xlate = zynqmp_reset_of_xlate;
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +0530118
119 return devm_reset_controller_register(&pdev->dev, &priv->rcdev);
120}
121
122static const struct of_device_id zynqmp_reset_dt_ids[] = {
Sai Krishna Potthuri552f3882020-07-22 12:46:05 +0530123 { .compatible = "xlnx,zynqmp-reset", .data = &zynqmp_reset_data, },
124 { .compatible = "xlnx,versal-reset", .data = &versal_reset_data, },
Nava kishore Manne62f0d7d2019-01-25 13:16:54 +0530125 { /* sentinel */ },
126};
127
128static struct platform_driver zynqmp_reset_driver = {
129 .probe = zynqmp_reset_probe,
130 .driver = {
131 .name = KBUILD_MODNAME,
132 .of_match_table = zynqmp_reset_dt_ids,
133 },
134};
135
136static int __init zynqmp_reset_init(void)
137{
138 return platform_driver_register(&zynqmp_reset_driver);
139}
140
141arch_initcall(zynqmp_reset_init);