diff options
author | Sebastian Reichel <sre@debian.org> | 2013-11-24 17:49:29 +0100 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-11-18 12:00:52 +0900 |
commit | 14bc065c7ecf9e8021dfc49fae3548f094d403e8 (patch) | |
tree | 40679621fe2abbc599e7719eb1a35b7626f8973a | |
parent | 9e39c7ce34b53aa9f7766edafc22377cb4d7e382 (diff) | |
download | linux-3.10-14bc065c7ecf9e8021dfc49fae3548f094d403e8.tar.gz linux-3.10-14bc065c7ecf9e8021dfc49fae3548f094d403e8.tar.bz2 linux-3.10-14bc065c7ecf9e8021dfc49fae3548f094d403e8.zip |
power_supply: Add power_supply_get_by_phandle
Add method to get power supply by device tree phandle.
Change-Id: I486cb12098d96a0c0b1a930b194dd899fb5a61c8
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 6aac23cc656..26606641fe4 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"); diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 4bdfc9c0fc3..94562393bb6 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; extern int power_supply_reg_notifier(struct notifier_block *nb); extern void power_supply_unreg_notifier(struct notifier_block *nb); extern struct power_supply *power_supply_get_by_name(const char *name); +#ifdef CONFIG_OF +extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, + const char *property); +#else /* !CONFIG_OF */ +static inline struct power_supply * +power_supply_get_by_phandle(struct device_node *np, const char *property) +{ return NULL; } +#endif /* CONFIG_OF */ extern void power_supply_changed(struct power_supply *psy); extern int power_supply_am_i_supplied(struct power_supply *psy); extern int power_supply_set_battery_charged(struct power_supply *psy); |