diff options
author | Sebastian Reichel <sre@debian.org> | 2013-11-24 17:49:29 +0100 |
---|---|---|
committer | Anton Vorontsov <anton@enomsg.org> | 2013-12-23 18:21:11 -0800 |
commit | abce97708a9b5ba897ad94fa289804d8af8d3ea9 (patch) | |
tree | 130cb8a31d312f755b0f26303218b377863c3b7c /drivers/power | |
parent | 32260308b4cafcd71b1c0aac35675dc68120c33d (diff) | |
download | linux-abce97708a9b5ba897ad94fa289804d8af8d3ea9.tar.bz2 |
power_supply: Add power_supply_get_by_phandle
Add method to get power supply by device tree phandle.
Signed-off-by: Sebastian Reichel <sre@debian.org>
Reviewed-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/power_supply_core.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 6aac23cc6566..26606641fe44 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -341,6 +341,32 @@ struct power_supply *power_supply_get_by_name(const char *name) } EXPORT_SYMBOL_GPL(power_supply_get_by_name); +#ifdef CONFIG_OF +static int power_supply_match_device_node(struct device *dev, const void *data) +{ + return dev->parent && dev->parent->of_node == data; +} + +struct power_supply *power_supply_get_by_phandle(struct device_node *np, + const char *property) +{ + struct device_node *power_supply_np; + struct device *dev; + + power_supply_np = of_parse_phandle(np, property, 0); + if (!power_supply_np) + return ERR_PTR(-ENODEV); + + dev = class_find_device(power_supply_class, NULL, power_supply_np, + power_supply_match_device_node); + + of_node_put(power_supply_np); + + return dev ? dev_get_drvdata(dev) : NULL; +} +EXPORT_SYMBOL_GPL(power_supply_get_by_phandle); +#endif /* CONFIG_OF */ + int power_supply_powers(struct power_supply *psy, struct device *dev) { return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers"); |