diff options
author | Sebastian Reichel <sre@debian.org> | 2013-11-24 11:49:29 -0500 |
---|---|---|
committer | Anton Vorontsov <anton@enomsg.org> | 2013-12-23 21:21:11 -0500 |
commit | abce97708a9b5ba897ad94fa289804d8af8d3ea9 (patch) | |
tree | 130cb8a31d312f755b0f26303218b377863c3b7c /drivers/power | |
parent | 32260308b4cafcd71b1c0aac35675dc68120c33d (diff) |
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) | |||
341 | } | 341 | } |
342 | EXPORT_SYMBOL_GPL(power_supply_get_by_name); | 342 | EXPORT_SYMBOL_GPL(power_supply_get_by_name); |
343 | 343 | ||
344 | #ifdef CONFIG_OF | ||
345 | static int power_supply_match_device_node(struct device *dev, const void *data) | ||
346 | { | ||
347 | return dev->parent && dev->parent->of_node == data; | ||
348 | } | ||
349 | |||
350 | struct power_supply *power_supply_get_by_phandle(struct device_node *np, | ||
351 | const char *property) | ||
352 | { | ||
353 | struct device_node *power_supply_np; | ||
354 | struct device *dev; | ||
355 | |||
356 | power_supply_np = of_parse_phandle(np, property, 0); | ||
357 | if (!power_supply_np) | ||
358 | return ERR_PTR(-ENODEV); | ||
359 | |||
360 | dev = class_find_device(power_supply_class, NULL, power_supply_np, | ||
361 | power_supply_match_device_node); | ||
362 | |||
363 | of_node_put(power_supply_np); | ||
364 | |||
365 | return dev ? dev_get_drvdata(dev) : NULL; | ||
366 | } | ||
367 | EXPORT_SYMBOL_GPL(power_supply_get_by_phandle); | ||
368 | #endif /* CONFIG_OF */ | ||
369 | |||
344 | int power_supply_powers(struct power_supply *psy, struct device *dev) | 370 | int power_supply_powers(struct power_supply *psy, struct device *dev) |
345 | { | 371 | { |
346 | return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers"); | 372 | return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers"); |