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 3/3] power: power_supply: add support for getting supplied-nodes from dt
Date: Fri, 15 Feb 2013 18:36:56 -0500	[thread overview]
Message-ID: <1360971416-30717-4-git-send-email-rklein@nvidia.com> (raw)
In-Reply-To: <1360971416-30717-1-git-send-email-rklein@nvidia.com>

With the addition of the device_nodes to use similar to how
supplied_to works, add a helper function which will parse out the
phandles for the supplied-nodes directly from the node. This
implmentation requires the property name to be "supplied-nodes".

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

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 9e42702..4bc682b 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -84,6 +84,63 @@ void power_supply_changed(struct power_supply *psy)
 }
 EXPORT_SYMBOL_GPL(power_supply_changed);
 
+#ifdef CONFIG_OF
+#include <linux/of.h>
+
+static int __power_supply_get_supplied_nodes(struct device *dev,
+					     struct device_node *np,
+					     struct device_node **supplicants,
+					     int *count)
+{
+	int i = 0;
+	int num_nodes = 0;
+	struct device_node *node;
+
+	do {
+		node = of_parse_phandle(np, "power-supply,supplied-nodes", i++);
+		if (node)
+			num_nodes++;
+	} while (node);
+
+	if (!num_nodes) {
+		dev_warn(dev, "No supplicant phandles found.\n");
+		return -EINVAL;
+	}
+
+	*supplicants = devm_kzalloc(dev, sizeof(struct device_node *) *
+				    num_nodes, GFP_KERNEL);
+
+	if (!*supplicants) {
+		dev_err(dev, "Failed allocation for memory for supplicants\n");
+		return -ENOMEM;
+	}
+
+	for (i = 0; i < num_nodes; i++)
+		supplicants[i] = of_parse_phandle(np,
+					"power-supply,supplied-nodes", i);
+
+	*count = num_nodes;
+
+	return 0;
+}
+
+int power_supply_get_supplied_nodes(struct device *dev,
+				    struct device_node *np,
+				    struct device_node **supplicants,
+				    int *count)
+{
+	int error;
+
+	if (!np || !supplicants)
+		return -EINVAL;
+
+	error = __power_supply_get_supplied_nodes(dev, np, supplicants, count);
+
+	return error;
+}
+EXPORT_SYMBOL_GPL(power_supply_get_supplied_nodes);
+#endif
+
 static int __power_supply_am_i_supplied(struct device *dev, void *data)
 {
 	union power_supply_propval ret = {0,};
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 8c8693b..359335a 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -230,6 +230,12 @@ struct power_supply_info {
 
 extern struct power_supply *power_supply_get_by_name(char *name);
 extern void power_supply_changed(struct power_supply *psy);
+#ifdef CONFIG_OF
+extern int power_supply_get_supplied_nodes(struct device *dev,
+					   struct device_node *np,
+					   struct device_node **supplicants,
+					   int *count);
+#endif
 extern int power_supply_am_i_supplied(struct power_supply *psy);
 extern int power_supply_set_battery_charged(struct power_supply *psy);
 
-- 
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 ` [RFC 2/3] power: power_supply: Add core support for supplied_nodes Rhyland Klein
2013-02-15 23:36 ` Rhyland Klein [this message]

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-4-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).