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>
This commit is contained in:
Maxime Ripard 2013-12-20 22:41:07 +01:00 committed by Philipp Zabel
parent 0c5b2b915a
commit fc0a592156
2 changed files with 34 additions and 9 deletions

View file

@ -126,15 +126,16 @@ int reset_control_deassert(struct reset_control *rstc)
EXPORT_SYMBOL_GPL(reset_control_deassert); EXPORT_SYMBOL_GPL(reset_control_deassert);
/** /**
* reset_control_get - Lookup and obtain a reference to a reset controller. * of_reset_control_get - Lookup and obtain a reference to a reset controller.
* @dev: device to be reset by the controller * @node: device to be reset by the controller
* @id: reset line name * @id: reset line name
* *
* Returns a struct reset_control or IS_ERR() condition containing errno. * Returns a struct reset_control or IS_ERR() condition containing errno.
* *
* Use of id names is optional. * Use of id names is optional.
*/ */
struct reset_control *reset_control_get(struct device *dev, const char *id) struct reset_control *of_reset_control_get(struct device_node *node,
const char *id)
{ {
struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER); struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
struct reset_controller_dev *r, *rcdev; struct reset_controller_dev *r, *rcdev;
@ -143,13 +144,10 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
int rstc_id; int rstc_id;
int ret; int ret;
if (!dev)
return ERR_PTR(-EINVAL);
if (id) if (id)
index = of_property_match_string(dev->of_node, index = of_property_match_string(node,
"reset-names", id); "reset-names", id);
ret = of_parse_phandle_with_args(dev->of_node, "resets", "#reset-cells", ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
index, &args); index, &args);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
@ -184,12 +182,35 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
rstc->dev = dev;
rstc->rcdev = rcdev; rstc->rcdev = rcdev;
rstc->id = rstc_id; rstc->id = rstc_id;
return rstc; return rstc;
} }
EXPORT_SYMBOL_GPL(of_reset_control_get);
/**
* reset_control_get - Lookup and obtain a reference to a reset controller.
* @dev: device to be reset by the controller
* @id: reset line name
*
* Returns a struct reset_control or IS_ERR() condition containing errno.
*
* Use of id names is optional.
*/
struct reset_control *reset_control_get(struct device *dev, const char *id)
{
struct reset_control *rstc;
if (!dev)
return ERR_PTR(-EINVAL);
rstc = of_reset_control_get(dev->of_node, id);
if (!IS_ERR(rstc))
rstc->dev = dev;
return rstc;
}
EXPORT_SYMBOL_GPL(reset_control_get); EXPORT_SYMBOL_GPL(reset_control_get);
/** /**

View file

@ -1,6 +1,8 @@
#ifndef _LINUX_RESET_H_ #ifndef _LINUX_RESET_H_
#define _LINUX_RESET_H_ #define _LINUX_RESET_H_
#include <linux/of.h>
struct device; struct device;
struct reset_control; struct reset_control;
@ -8,6 +10,8 @@ int reset_control_reset(struct reset_control *rstc);
int reset_control_assert(struct reset_control *rstc); int reset_control_assert(struct reset_control *rstc);
int reset_control_deassert(struct reset_control *rstc); int reset_control_deassert(struct reset_control *rstc);
struct reset_control *of_reset_control_get(struct device_node *node,
const char *id);
struct reset_control *reset_control_get(struct device *dev, const char *id); struct reset_control *reset_control_get(struct device *dev, const char *id);
void reset_control_put(struct reset_control *rstc); void reset_control_put(struct reset_control *rstc);
struct reset_control *devm_reset_control_get(struct device *dev, const char *id); struct reset_control *devm_reset_control_get(struct device *dev, const char *id);