1 From 0325b48d6149e131c90ed6ec77458f4d2df73898 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Fri, 20 Dec 2013 22:41:07 +0100
4 Subject: [PATCH] reset: Add of_reset_control_get
6 In some cases, you might need to deassert from reset an hardware block that
7 doesn't associated to a struct device (CPUs, timers, etc.).
9 Add a small helper to retrieve the reset controller from the device tree
10 without the need to pass a struct device.
12 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
14 drivers/reset/core.c | 39 ++++++++++++++++++++++++++++++---------
15 include/linux/reset.h | 4 ++++
16 2 files changed, 34 insertions(+), 9 deletions(-)
18 diff --git a/drivers/reset/core.c b/drivers/reset/core.c
19 index d1b6089..4f3dda7 100644
20 --- a/drivers/reset/core.c
21 +++ b/drivers/reset/core.c
22 @@ -127,15 +127,16 @@ int reset_control_deassert(struct reset_control *rstc)
23 EXPORT_SYMBOL_GPL(reset_control_deassert);
26 - * reset_control_get - Lookup and obtain a reference to a reset controller.
27 - * @dev: device to be reset by the controller
28 + * of_reset_control_get - Lookup and obtain a reference to a reset controller.
29 + * @node: device to be reset by the controller
30 * @id: reset line name
32 * Returns a struct reset_control or IS_ERR() condition containing errno.
34 * Use of id names is optional.
36 -struct reset_control *reset_control_get(struct device *dev, const char *id)
37 +struct reset_control *of_reset_control_get(struct device_node *node,
40 struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
41 struct reset_controller_dev *r, *rcdev;
42 @@ -144,13 +145,10 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
47 - return ERR_PTR(-EINVAL);
50 - index = of_property_match_string(dev->of_node,
51 + index = of_property_match_string(node,
53 - ret = of_parse_phandle_with_args(dev->of_node, "resets", "#reset-cells",
54 + ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
58 @@ -185,12 +183,35 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
59 return ERR_PTR(-ENOMEM);
68 +EXPORT_SYMBOL_GPL(of_reset_control_get);
71 + * reset_control_get - Lookup and obtain a reference to a reset controller.
72 + * @dev: device to be reset by the controller
73 + * @id: reset line name
75 + * Returns a struct reset_control or IS_ERR() condition containing errno.
77 + * Use of id names is optional.
79 +struct reset_control *reset_control_get(struct device *dev, const char *id)
81 + struct reset_control *rstc;
84 + return ERR_PTR(-EINVAL);
86 + rstc = of_reset_control_get(dev->of_node, id);
92 EXPORT_SYMBOL_GPL(reset_control_get);
95 diff --git a/include/linux/reset.h b/include/linux/reset.h
96 index 6082247..a398025 100644
97 --- a/include/linux/reset.h
98 +++ b/include/linux/reset.h
100 #ifndef _LINUX_RESET_H_
101 #define _LINUX_RESET_H_
103 +#include <linux/of.h>
106 struct reset_control;
109 int reset_control_assert(struct reset_control *rstc);
110 int reset_control_deassert(struct reset_control *rstc);
112 +struct reset_control *of_reset_control_get(struct device_node *node,
114 struct reset_control *reset_control_get(struct device *dev, const char *id);
115 void reset_control_put(struct reset_control *rstc);
116 struct reset_control *devm_reset_control_get(struct device *dev, const char *id);