aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/power/power_supply_core.c38
-rw-r--r--include/linux/power_supply.h1
2 files changed, 39 insertions, 0 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index e51405b176c8..b4ec14683b7f 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -336,6 +336,17 @@ static int power_supply_match_device_by_name(struct device *dev, const void *dat
336 return strcmp(psy->desc->name, name) == 0; 336 return strcmp(psy->desc->name, name) == 0;
337} 337}
338 338
339/**
340 * power_supply_get_by_name() - Search for a power supply and returns its ref
341 * @name: Power supply name to fetch
342 *
343 * If power supply was found, it increases reference count for the
344 * internal power supply's device. The user should power_supply_put()
345 * after usage.
346 *
347 * Return: On success returns a reference to a power supply with
348 * matching name equals to @name, a NULL otherwise.
349 */
339struct power_supply *power_supply_get_by_name(const char *name) 350struct power_supply *power_supply_get_by_name(const char *name)
340{ 351{
341 struct device *dev = class_find_device(power_supply_class, NULL, name, 352 struct device *dev = class_find_device(power_supply_class, NULL, name,
@@ -345,12 +356,39 @@ struct power_supply *power_supply_get_by_name(const char *name)
345} 356}
346EXPORT_SYMBOL_GPL(power_supply_get_by_name); 357EXPORT_SYMBOL_GPL(power_supply_get_by_name);
347 358
359/**
360 * power_supply_put() - Drop reference obtained with power_supply_get_by_name
361 * @psy: Reference to put
362 *
363 * The reference to power supply should be put before unregistering
364 * the power supply.
365 */
366void power_supply_put(struct power_supply *psy)
367{
368 might_sleep();
369
370 put_device(&psy->dev);
371}
372EXPORT_SYMBOL_GPL(power_supply_put);
373
348#ifdef CONFIG_OF 374#ifdef CONFIG_OF
349static int power_supply_match_device_node(struct device *dev, const void *data) 375static int power_supply_match_device_node(struct device *dev, const void *data)
350{ 376{
351 return dev->parent && dev->parent->of_node == data; 377 return dev->parent && dev->parent->of_node == data;
352} 378}
353 379
380/**
381 * power_supply_get_by_phandle() - Search for a power supply and returns its ref
382 * @np: Pointer to device node holding phandle property
383 * @phandle_name: Name of property holding a power supply name
384 *
385 * If power supply was found, it increases reference count for the
386 * internal power supply's device. The user should power_supply_put()
387 * after usage.
388 *
389 * Return: On success returns a reference to a power supply with
390 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
391 */
354struct power_supply *power_supply_get_by_phandle(struct device_node *np, 392struct power_supply *power_supply_get_by_phandle(struct device_node *np,
355 const char *property) 393 const char *property)
356{ 394{
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index ea15eb68f609..75a1dd8dc56e 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -282,6 +282,7 @@ extern struct atomic_notifier_head power_supply_notifier;
282extern int power_supply_reg_notifier(struct notifier_block *nb); 282extern int power_supply_reg_notifier(struct notifier_block *nb);
283extern void power_supply_unreg_notifier(struct notifier_block *nb); 283extern void power_supply_unreg_notifier(struct notifier_block *nb);
284extern struct power_supply *power_supply_get_by_name(const char *name); 284extern struct power_supply *power_supply_get_by_name(const char *name);
285extern void power_supply_put(struct power_supply *psy);
285#ifdef CONFIG_OF 286#ifdef CONFIG_OF
286extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, 287extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
287 const char *property); 288 const char *property);