[PATCH] power_supply: Add power_supply notifier

From: Jenny TC
Date: Thu Jul 25 2013 - 07:26:11 EST

This patch adds a notifier chain to the power_supply.
This notifier 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@xxxxxxxxx>
drivers/power/power_supply_core.c | 18 ++++++++++++++++++
include/linux/power_supply.h | 7 +++++++
2 files changed, 25 insertions(+)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 3b2d5df..a5779b3 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -24,6 +24,9 @@
struct class *power_supply_class;

static struct device_type power_supply_dev_type;

static bool __power_supply_is_supplied_by(struct power_supply *supplier,
@@ -76,6 +79,9 @@ static void power_supply_changed_work(struct work_struct *work)

+ atomic_notifier_call_chain(&power_supply_notifier,

kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE);
@@ -328,6 +334,18 @@ static void power_supply_dev_release(struct device *dev)

+int power_supply_reg_notifier(struct notifier_block *nb)
+ return atomic_notifier_chain_register(&power_supply_notifier, nb);
+void power_supply_unreg_notifier(struct notifier_block *nb)
+ atomic_notifier_chain_unregister(&power_supply_notifier, nb);
static int power_supply_read_temp(struct thermal_zone_device *tzd,
unsigned long *temp)
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 516e4c4..32fae9c 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -217,6 +217,10 @@ enum psy_throttle_action {

+enum power_supply_notifier_events {
struct psy_throttle_state {
enum psy_throttle_action throttle_action;
unsigned throttle_val;
@@ -293,6 +297,9 @@ struct power_supply_info {
int use_for_apm;

+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);
extern void power_supply_changed(struct power_supply *psy);
extern int power_supply_am_i_supplied(struct power_supply *psy);

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/