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 | |
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>
-rw-r--r-- | drivers/power/power_supply_core.c | 26 | ||||
-rw-r--r-- | include/linux/power_supply.h | 8 |
2 files changed, 34 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"); |
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 3e28fe188d17..c9dc4e09854c 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h | |||
@@ -244,6 +244,14 @@ extern struct atomic_notifier_head power_supply_notifier; | |||
244 | extern int power_supply_reg_notifier(struct notifier_block *nb); | 244 | extern int power_supply_reg_notifier(struct notifier_block *nb); |
245 | extern void power_supply_unreg_notifier(struct notifier_block *nb); | 245 | extern void power_supply_unreg_notifier(struct notifier_block *nb); |
246 | extern struct power_supply *power_supply_get_by_name(const char *name); | 246 | extern struct power_supply *power_supply_get_by_name(const char *name); |
247 | #ifdef CONFIG_OF | ||
248 | extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, | ||
249 | const char *property); | ||
250 | #else /* !CONFIG_OF */ | ||
251 | static inline struct power_supply * | ||
252 | power_supply_get_by_phandle(struct device_node *np, const char *property) | ||
253 | { return NULL; } | ||
254 | #endif /* CONFIG_OF */ | ||
247 | extern void power_supply_changed(struct power_supply *psy); | 255 | extern void power_supply_changed(struct power_supply *psy); |
248 | extern int power_supply_am_i_supplied(struct power_supply *psy); | 256 | extern int power_supply_am_i_supplied(struct power_supply *psy); |
249 | extern int power_supply_set_battery_charged(struct power_supply *psy); | 257 | extern int power_supply_set_battery_charged(struct power_supply *psy); |