gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / reset / reset-zynqmp.c
blob0144075b11a6e1a2f341b5f05b6757f761fa144c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2018 Xilinx, Inc.
5 */
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>
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,
28 unsigned long id)
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,
37 unsigned long id)
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,
46 unsigned long id)
48 struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
49 int val, err;
51 err = priv->eemi_ops->reset_get_status(ZYNQMP_RESET_ID + id, &val);
52 if (err)
53 return err;
55 return val;
58 static int zynqmp_reset_reset(struct reset_controller_dev *rcdev,
59 unsigned long id)
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 const 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);
79 if (!priv)
80 return -ENOMEM;
82 priv->eemi_ops = zynqmp_pm_get_eemi_ops();
83 if (IS_ERR(priv->eemi_ops))
84 return PTR_ERR(priv->eemi_ops);
86 platform_set_drvdata(pdev, priv);
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", },
98 { /* sentinel */ },
101 static struct platform_driver zynqmp_reset_driver = {
102 .probe = zynqmp_reset_probe,
103 .driver = {
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);