mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] power_supply: API to return the power supply object from supplied to list
@ 2012-07-25  9:50 Ramakrishna Pallala
  0 siblings, 0 replies; only message in thread
From: Ramakrishna Pallala @ 2012-07-25  9:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: Anton Vorontsov, Anton Vorontsov, Ramakrishna Pallala

This patch adds an API in the power supply core to get the
power supply object from supplied_to list based on power
supply attribute(present/online).

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
---
 drivers/power/power_supply_core.c |   19 +++++++++++++++++++
 include/linux/power_supply.h      |    3 +++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index ff990d2..8ef1d8b 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -158,6 +158,25 @@ struct power_supply *power_supply_get_by_name(char *name)
 }
 EXPORT_SYMBOL_GPL(power_supply_get_by_name);
 
+struct power_supply *power_supply_get_by_suppliedto(struct power_supply *psy,
+						enum power_supply_property psp)
+{
+	union power_supply_propval ret = {0,};
+	struct power_supply *pst;
+	int i;
+
+	for (i = 0; i < psy->num_supplicants; i++) {
+		pst = power_supply_get_by_name(psy->supplied_to[i]);
+		if (!pst || pst->get_property(pst, psp, &ret))
+			continue;
+		if (ret.intval)
+			return pst;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(power_supply_get_by_suppliedto);
+
 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 0bafbb1..2fdcf77 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -219,6 +219,9 @@ struct power_supply_info {
 };
 
 extern struct power_supply *power_supply_get_by_name(char *name);
+extern struct power_supply *power_supply_get_by_suppliedto(
+					struct power_supply *psy,
+					enum power_supply_property psp);
 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);
-- 
1.7.0.4


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-07-25 11:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-25  9:50 [PATCH] power_supply: API to return the power supply object from supplied to list Ramakrishna Pallala

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®