aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2013-11-19 05:18:03 -0500
committerAnton Vorontsov <anton@enomsg.org>2013-12-01 17:27:24 -0500
commitd36240d26025bec95f3499e2401a56db98d9f01c (patch)
tree345c489dc983fc87cf4927235d9e2361e3e10448 /drivers
parent93353e8088057dd988362e6cae727af43734b494 (diff)
power_supply: Add power_supply notifier
This patch adds a notifier chain to the power_supply, this helps drivers in other subsystem to listen to changes in power supply subsystem. This would help to take some actions in those drivers on changing the power supply properties. One such scenario is to increase/decrease system performance based on the battery capacity/voltage. Another scenario is to adjust the h/w peak current detection voltage/current thresholds based on battery voltage/capacity. The notifier helps drivers to listen to changes in power_suppy susbystem without polling the power_supply properties Signed-off-by: Jenny TC <jenny.tc@intel.com> Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Acked-by: Jenny TC <jenny.tc@intel.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/power_supply_core.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 557af943b2f5..6aac23cc6566 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/notifier.h>
18#include <linux/err.h> 19#include <linux/err.h>
19#include <linux/power_supply.h> 20#include <linux/power_supply.h>
20#include <linux/thermal.h> 21#include <linux/thermal.h>
@@ -24,6 +25,9 @@
24struct class *power_supply_class; 25struct class *power_supply_class;
25EXPORT_SYMBOL_GPL(power_supply_class); 26EXPORT_SYMBOL_GPL(power_supply_class);
26 27
28ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
29EXPORT_SYMBOL_GPL(power_supply_notifier);
30
27static struct device_type power_supply_dev_type; 31static struct device_type power_supply_dev_type;
28 32
29static bool __power_supply_is_supplied_by(struct power_supply *supplier, 33static bool __power_supply_is_supplied_by(struct power_supply *supplier,
@@ -80,6 +84,8 @@ static void power_supply_changed_work(struct work_struct *work)
80 class_for_each_device(power_supply_class, NULL, psy, 84 class_for_each_device(power_supply_class, NULL, psy,
81 __power_supply_changed_work); 85 __power_supply_changed_work);
82 power_supply_update_leds(psy); 86 power_supply_update_leds(psy);
87 atomic_notifier_call_chain(&power_supply_notifier,
88 PSY_EVENT_PROP_CHANGED, psy);
83 kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); 89 kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE);
84 spin_lock_irqsave(&psy->changed_lock, flags); 90 spin_lock_irqsave(&psy->changed_lock, flags);
85 } 91 }
@@ -347,6 +353,18 @@ static void power_supply_dev_release(struct device *dev)
347 kfree(dev); 353 kfree(dev);
348} 354}
349 355
356int power_supply_reg_notifier(struct notifier_block *nb)
357{
358 return atomic_notifier_chain_register(&power_supply_notifier, nb);
359}
360EXPORT_SYMBOL_GPL(power_supply_reg_notifier);
361
362void power_supply_unreg_notifier(struct notifier_block *nb)
363{
364 atomic_notifier_chain_unregister(&power_supply_notifier, nb);
365}
366EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
367
350#ifdef CONFIG_THERMAL 368#ifdef CONFIG_THERMAL
351static int power_supply_read_temp(struct thermal_zone_device *tzd, 369static int power_supply_read_temp(struct thermal_zone_device *tzd,
352 unsigned long *temp) 370 unsigned long *temp)