aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/reset
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2013-12-20 16:41:07 -0500
committerPhilipp Zabel <p.zabel@pengutronix.de>2014-02-03 04:19:40 -0500
commitfc0a5921561c71be2c334a335c1680f7930434d7 (patch)
treeebd4f9ae0b08f5e0ca414586d24d49606a0bcc49 /drivers/reset
parent0c5b2b915a5863643b4534dabd028d4bb34c3b27 (diff)
reset: Add of_reset_control_get
In some cases, you might need to deassert from reset an hardware block that doesn't associated to a struct device (CPUs, timers, etc.). Add a small helper to retrieve the reset controller from the device tree without the need to pass a struct device. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Diffstat (limited to 'drivers/reset')
-rw-r--r--drivers/reset/core.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 217d2fa4fd95..baeaf82d40d9 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -126,15 +126,16 @@ int reset_control_deassert(struct reset_control *rstc)
126EXPORT_SYMBOL_GPL(reset_control_deassert); 126EXPORT_SYMBOL_GPL(reset_control_deassert);
127 127
128/** 128/**
129 * reset_control_get - Lookup and obtain a reference to a reset controller. 129 * of_reset_control_get - Lookup and obtain a reference to a reset controller.
130 * @dev: device to be reset by the controller 130 * @node: device to be reset by the controller
131 * @id: reset line name 131 * @id: reset line name
132 * 132 *
133 * Returns a struct reset_control or IS_ERR() condition containing errno. 133 * Returns a struct reset_control or IS_ERR() condition containing errno.
134 * 134 *
135 * Use of id names is optional. 135 * Use of id names is optional.
136 */ 136 */
137struct reset_control *reset_control_get(struct device *dev, const char *id) 137struct reset_control *of_reset_control_get(struct device_node *node,
138 const char *id)
138{ 139{
139 struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER); 140 struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
140 struct reset_controller_dev *r, *rcdev; 141 struct reset_controller_dev *r, *rcdev;
@@ -143,13 +144,10 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
143 int rstc_id; 144 int rstc_id;
144 int ret; 145 int ret;
145 146
146 if (!dev)
147 return ERR_PTR(-EINVAL);
148
149 if (id) 147 if (id)
150 index = of_property_match_string(dev->of_node, 148 index = of_property_match_string(node,
151 "reset-names", id); 149 "reset-names", id);
152 ret = of_parse_phandle_with_args(dev->of_node, "resets", "#reset-cells", 150 ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
153 index, &args); 151 index, &args);
154 if (ret) 152 if (ret)
155 return ERR_PTR(ret); 153 return ERR_PTR(ret);
@@ -184,12 +182,35 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
184 return ERR_PTR(-ENOMEM); 182 return ERR_PTR(-ENOMEM);
185 } 183 }
186 184
187 rstc->dev = dev;
188 rstc->rcdev = rcdev; 185 rstc->rcdev = rcdev;
189 rstc->id = rstc_id; 186 rstc->id = rstc_id;
190 187
191 return rstc; 188 return rstc;
192} 189}
190EXPORT_SYMBOL_GPL(of_reset_control_get);
191
192/**
193 * reset_control_get - Lookup and obtain a reference to a reset controller.
194 * @dev: device to be reset by the controller
195 * @id: reset line name
196 *
197 * Returns a struct reset_control or IS_ERR() condition containing errno.
198 *
199 * Use of id names is optional.
200 */
201struct reset_control *reset_control_get(struct device *dev, const char *id)
202{
203 struct reset_control *rstc;
204
205 if (!dev)
206 return ERR_PTR(-EINVAL);
207
208 rstc = of_reset_control_get(dev->of_node, id);
209 if (!IS_ERR(rstc))
210 rstc->dev = dev;
211
212 return rstc;
213}
193EXPORT_SYMBOL_GPL(reset_control_get); 214EXPORT_SYMBOL_GPL(reset_control_get);
194 215
195/** 216/**