[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1360971416-30717-3-git-send-email-rklein@nvidia.com>
Date: Fri, 15 Feb 2013 18:36:55 -0500
From: Rhyland Klein <rklein@...dia.com>
To: Anton Vorontsov <cbou@...l.ru>,
David Woodhouse <dwmw2@...radead.org>,
Grant Likely <grant.likely@...retlab.ca>,
Rob Herring <rob.herring@...xeda.com>
CC: <devicetree-discuss@...ts.ozlabs.org>,
<linux-tegra@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
Rhyland Klein <rklein@...dia.com>
Subject: [RFC 2/3] power: power_supply: Add core support for supplied_nodes
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@...dia.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists