devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rhyland Klein <rklein@nvidia.com>
To: Anton Vorontsov <cbou@mail.ru>,
	David Woodhouse <dwmw2@infradead.org>,
	Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>
Cc: devicetree-discuss@lists.ozlabs.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org, Rhyland Klein <rklein@nvidia.com>
Subject: [RFC 2/3] power: power_supply: Add core support for supplied_nodes
Date: Fri, 15 Feb 2013 18:36:55 -0500	[thread overview]
Message-ID: <1360971416-30717-3-git-send-email-rklein@nvidia.com> (raw)
In-Reply-To: <1360971416-30717-1-git-send-email-rklein@nvidia.com>

With the growing support for dt, it make sense to try to make sure of
dt features as to make the general code cleaner. This patch is an
attempt to commonize how chargers receive their "supplied_to" list
of supplicants. This was previously done via passing an array of
strings.

Currently, charger drivers that make use of the supplicant list, do
so using custom private dt mechanisms, this will should make a common
implementation that all can use.

With device tree, it is much cleaner to instead use a list of phandles
in the device tree to point directly to the supplicants thus ensuring
a proper reference without having to hard code in names.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 drivers/power/power_supply_core.c |   25 +++++++++++++++++++++++--
 include/linux/power_supply.h      |    4 ++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 8a7cfb3..9e42702 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -26,6 +26,27 @@ EXPORT_SYMBOL_GPL(power_supply_class);
 
 static struct device_type power_supply_dev_type;
 
+static int __power_supply_is_supplied_by(struct power_supply *psy1,
+					 struct power_supply *psy2,
+					 int supply_idx)
+{
+
+	if (supply_idx < 0)
+		return -EINVAL;
+
+#ifdef CONFIG_OF
+	if (psy2->node && psy1->supplied_nodes)
+		if (psy1->supplied_nodes[supply_idx] == psy2->node)
+			return 0;
+#endif
+
+	if (psy2->name && psy1->supplied_to)
+		if (!strcmp(psy1->supplied_to[supply_idx], psy2->name))
+			return 0;
+
+	return -EINVAL;
+}
+
 static int __power_supply_changed_work(struct device *dev, void *data)
 {
 	struct power_supply *psy = (struct power_supply *)data;
@@ -33,7 +54,7 @@ static int __power_supply_changed_work(struct device *dev, void *data)
 	int i;
 
 	for (i = 0; i < psy->num_supplicants; i++)
-		if (!strcmp(psy->supplied_to[i], pst->name)) {
+		if (__power_supply_is_supplied_by(psy, pst, i)) {
 			if (pst->external_power_changed)
 				pst->external_power_changed(pst);
 		}
@@ -71,7 +92,7 @@ static int __power_supply_am_i_supplied(struct device *dev, void *data)
 	int i;
 
 	for (i = 0; i < epsy->num_supplicants; i++) {
-		if (!strcmp(epsy->supplied_to[i], psy->name)) {
+		if (__power_supply_is_supplied_by(epsy, psy, i)) {
 			if (epsy->get_property(epsy,
 				  POWER_SUPPLY_PROP_ONLINE, &ret))
 				continue;
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 1f0ab90..8c8693b 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -166,6 +166,10 @@ struct power_supply {
 	enum power_supply_property *properties;
 	size_t num_properties;
 
+#ifdef CONFIG_OF
+	struct device_node *node;
+	struct device_node **supplied_nodes;
+#endif
 	char **supplied_to;
 	size_t num_supplicants;
 
-- 
1.7.9.5

  parent reply	other threads:[~2013-02-15 23:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15 23:36 [RFC 0/3] Add DT Binding for Power-Supply supplied-nodes property Rhyland Klein
2013-02-15 23:36 ` [RFC 1/3] power_supply: Define Binding for supplied-nodes Rhyland Klein
     [not found]   ` <1360971416-30717-2-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-02-16 22:38     ` Anton Vorontsov
2013-02-18  6:04       ` Rajanikanth HV
     [not found]       ` <20130216223804.GF1741-SAfYLu58TvsKrcn4e17nTyIbA2bwYUBrKwcig+XE9tjR7s880joybQ@public.gmane.org>
2013-02-19 18:00         ` Rhyland Klein
2013-02-15 23:36 ` Rhyland Klein [this message]
2013-02-15 23:36 ` [RFC 3/3] power: power_supply: add support for getting supplied-nodes from dt Rhyland Klein

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=1360971416-30717-3-git-send-email-rklein@nvidia.com \
    --to=rklein@nvidia.com \
    --cc=cbou@mail.ru \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=dwmw2@infradead.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).