1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Xilinx, Inc.
9 #include <linux/platform_device.h>
10 #include <linux/reset-controller.h>
11 #include <linux/firmware/xlnx-zynqmp.h>
13 #define ZYNQMP_NR_RESETS (ZYNQMP_PM_RESET_END - ZYNQMP_PM_RESET_START)
14 #define ZYNQMP_RESET_ID ZYNQMP_PM_RESET_START
16 struct zynqmp_reset_data
{
17 struct reset_controller_dev rcdev
;
18 const struct zynqmp_eemi_ops
*eemi_ops
;
21 static inline struct zynqmp_reset_data
*
22 to_zynqmp_reset_data(struct reset_controller_dev
*rcdev
)
24 return container_of(rcdev
, struct zynqmp_reset_data
, rcdev
);
27 static int zynqmp_reset_assert(struct reset_controller_dev
*rcdev
,
30 struct zynqmp_reset_data
*priv
= to_zynqmp_reset_data(rcdev
);
32 return priv
->eemi_ops
->reset_assert(ZYNQMP_RESET_ID
+ id
,
33 PM_RESET_ACTION_ASSERT
);
36 static int zynqmp_reset_deassert(struct reset_controller_dev
*rcdev
,
39 struct zynqmp_reset_data
*priv
= to_zynqmp_reset_data(rcdev
);
41 return priv
->eemi_ops
->reset_assert(ZYNQMP_RESET_ID
+ id
,
42 PM_RESET_ACTION_RELEASE
);
45 static int zynqmp_reset_status(struct reset_controller_dev
*rcdev
,
48 struct zynqmp_reset_data
*priv
= to_zynqmp_reset_data(rcdev
);
51 err
= priv
->eemi_ops
->reset_get_status(ZYNQMP_RESET_ID
+ id
, &val
);
58 static int zynqmp_reset_reset(struct reset_controller_dev
*rcdev
,
61 struct zynqmp_reset_data
*priv
= to_zynqmp_reset_data(rcdev
);
63 return priv
->eemi_ops
->reset_assert(ZYNQMP_RESET_ID
+ id
,
64 PM_RESET_ACTION_PULSE
);
67 static struct reset_control_ops zynqmp_reset_ops
= {
68 .reset
= zynqmp_reset_reset
,
69 .assert = zynqmp_reset_assert
,
70 .deassert
= zynqmp_reset_deassert
,
71 .status
= zynqmp_reset_status
,
74 static int zynqmp_reset_probe(struct platform_device
*pdev
)
76 struct zynqmp_reset_data
*priv
;
78 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
82 platform_set_drvdata(pdev
, priv
);
84 priv
->eemi_ops
= zynqmp_pm_get_eemi_ops();
88 priv
->rcdev
.ops
= &zynqmp_reset_ops
;
89 priv
->rcdev
.owner
= THIS_MODULE
;
90 priv
->rcdev
.of_node
= pdev
->dev
.of_node
;
91 priv
->rcdev
.nr_resets
= ZYNQMP_NR_RESETS
;
93 return devm_reset_controller_register(&pdev
->dev
, &priv
->rcdev
);
96 static const struct of_device_id zynqmp_reset_dt_ids
[] = {
97 { .compatible
= "xlnx,zynqmp-reset", },
101 static struct platform_driver zynqmp_reset_driver
= {
102 .probe
= zynqmp_reset_probe
,
104 .name
= KBUILD_MODNAME
,
105 .of_match_table
= zynqmp_reset_dt_ids
,
109 static int __init
zynqmp_reset_init(void)
111 return platform_driver_register(&zynqmp_reset_driver
);
114 arch_initcall(zynqmp_reset_init
);