[RFC 2/3] power: power_supply: Add core support for supplied_nodes
Rhyland Klein
rklein at nvidia.com
Sat Feb 16 10:36:55 EST 2013
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 at 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
More information about the devicetree-discuss
mailing list