All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Reichel <sre@debian.org>
To: Sebastian Reichel <sre@ring0.de>,
	Anton Vorontsov <anton@enomsg.org>,
	David Woodhouse <dwmw2@infradead.org>
Cc: "Rob Herring" <rob.herring@calxeda.com>,
	"Pawel Moll" <pawel.moll@arm.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Stephen Warren" <swarren@wwwdotorg.org>,
	"Ian Campbell" <ijc+devicetree@hellion.org.uk>,
	"Rob Landley" <rob@landley.net>,
	linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
	devicetree@vger.kernel.org, "Pali Rohár" <pali.rohar@gmail.com>,
	freemangordon@abv.bg, aaro.koskinen@iki.fi, pavel@ucw.cz,
	"Sebastian Reichel" <sre@debian.org>
Subject: [PATCH 1/3] power_supply: add power_supply_get_by_phandle
Date: Sun, 24 Nov 2013 17:49:29 +0100	[thread overview]
Message-ID: <1385311771-447-2-git-send-email-sre@debian.org> (raw)
In-Reply-To: <1385311771-447-1-git-send-email-sre@debian.org>

Add method to get power supply by device tree phandle.

Signed-off-by: Sebastian Reichel <sre@debian.org>
---
 drivers/power/power_supply_core.c | 24 ++++++++++++++++++++++++
 include/linux/power_supply.h      |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 08bce22..99e4b41 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -340,6 +340,30 @@ struct power_supply *power_supply_get_by_name(const char *name)
 }
 EXPORT_SYMBOL_GPL(power_supply_get_by_name);
 
+static int power_supply_match_device_node(struct device *dev, const void *data)
+{
+	return dev->parent && dev->parent->of_node == data;
+}
+
+struct power_supply *power_supply_get_by_phandle(struct device_node *np,
+							const char *property)
+{
+	struct device_node *power_supply_np;
+	struct device *dev;
+
+	power_supply_np = of_parse_phandle(np, property, 0);
+	if (!power_supply_np)
+		return ERR_PTR(-ENODEV);
+
+	dev = class_find_device(power_supply_class, NULL, power_supply_np,
+						power_supply_match_device_node);
+
+	of_node_put(power_supply_np);
+
+	return dev ? dev_get_drvdata(dev) : NULL;
+}
+EXPORT_SYMBOL_GPL(power_supply_get_by_phandle);
+
 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 c6f52c0..4d0e0b4 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -246,6 +246,8 @@ 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 struct power_supply *power_supply_get_by_phandle(struct device_node *np,
+							const char *property);
 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.8.4.3


  reply	other threads:[~2013-11-24 16:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-24 16:49 [PATCH 0/3] DT support for bq2415x Sebastian Reichel
2013-11-24 16:49 ` Sebastian Reichel [this message]
2013-11-25 12:32   ` [PATCH 1/3] power_supply: add power_supply_get_by_phandle Pavel Machek
2013-12-24  2:20   ` Anton Vorontsov
2013-12-24  2:20     ` Anton Vorontsov
2013-12-24  3:37     ` Sebastian Reichel
2013-11-24 16:49 ` [PATCH 2/3] bq2415x_charger: add DT support Sebastian Reichel
2013-11-25 12:39   ` Pavel Machek
2013-11-24 16:49 ` [PATCH 3/3] dt: binding documentation for bq2415x charger Sebastian Reichel
2013-11-25 13:07   ` Pavel Machek
2013-12-24  2:20 ` [PATCH 0/3] DT support for bq2415x Anton Vorontsov
2013-12-24  2:20   ` Anton Vorontsov
2013-12-24  3:39   ` Sebastian Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1385311771-447-2-git-send-email-sre@debian.org \
    --to=sre@debian.org \
    --cc=aaro.koskinen@iki.fi \
    --cc=anton@enomsg.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=freemangordon@abv.bg \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pali.rohar@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=pawel.moll@arm.com \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=sre@ring0.de \
    --cc=swarren@wwwdotorg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.