Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sebastian Reichel and committed by
Anton Vorontsov
abce9770 32260308

+34
+26
drivers/power/power_supply_core.c
··· 341 341 } 342 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 370 int power_supply_powers(struct power_supply *psy, struct device *dev) 345 371 { 346 372 return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers");
+8
include/linux/power_supply.h
··· 244 244 extern int power_supply_reg_notifier(struct notifier_block *nb); 245 245 extern void power_supply_unreg_notifier(struct notifier_block *nb); 246 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 255 extern void power_supply_changed(struct power_supply *psy); 248 256 extern int power_supply_am_i_supplied(struct power_supply *psy); 249 257 extern int power_supply_set_battery_charged(struct power_supply *psy);