3ff7c26
From 69dd0606a0d8680fe0a5e9b959f6662e582e1674 Mon Sep 17 00:00:00 2001
3ff7c26
From: Hans de Goede <hdegoede@redhat.com>
3ff7c26
Date: Tue, 2 May 2017 13:43:34 +0200
3ff7c26
Subject: [PATCH 03/16] power: supply: core: Add support for supplied-from
3ff7c26
 device-property
3ff7c26
3ff7c26
On devicetree using platforms the devicetree can provide info on which
3ff7c26
power-supplies supply another power-supply through phandles.
3ff7c26
3ff7c26
This commit adds support for providing this info on non devicetree
3ff7c26
platforms through the platform code setting a supplied-from
3ff7c26
device-property on the power-supplies parent device.
3ff7c26
3ff7c26
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3ff7c26
---
3ff7c26
 drivers/power/supply/power_supply_core.c | 24 +++++++++++++++++++++++-
3ff7c26
 1 file changed, 23 insertions(+), 1 deletion(-)
3ff7c26
3ff7c26
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
3ff7c26
index 7ec7c7c202bd..0c09144193a6 100644
3ff7c26
--- a/drivers/power/supply/power_supply_core.c
3ff7c26
+++ b/drivers/power/supply/power_supply_core.c
3ff7c26
@@ -274,8 +274,30 @@ static int power_supply_check_supplies(struct power_supply *psy)
3ff7c26
 	return power_supply_populate_supplied_from(psy);
3ff7c26
 }
3ff7c26
 #else
3ff7c26
-static inline int power_supply_check_supplies(struct power_supply *psy)
3ff7c26
+static int power_supply_check_supplies(struct power_supply *psy)
3ff7c26
 {
3ff7c26
+	int nval, ret;
3ff7c26
+
3ff7c26
+	if (!psy->dev.parent)
3ff7c26
+		return 0;
3ff7c26
+
3ff7c26
+	nval = device_property_read_string_array(psy->dev.parent,
3ff7c26
+						 "supplied-from", NULL, 0);
3ff7c26
+	if (nval <= 0)
3ff7c26
+		return 0;
3ff7c26
+
3ff7c26
+	psy->supplied_from = devm_kmalloc_array(&psy->dev, nval,
3ff7c26
+						sizeof(char *), GFP_KERNEL);
3ff7c26
+	if (!psy->supplied_from)
3ff7c26
+		return -ENOMEM;
3ff7c26
+
3ff7c26
+	ret = device_property_read_string_array(psy->dev.parent,
3ff7c26
+		"supplied-from", (const char **)psy->supplied_from, nval);
3ff7c26
+	if (ret < 0)
3ff7c26
+		return ret;
3ff7c26
+
3ff7c26
+	psy->num_supplies = nval;
3ff7c26
+
3ff7c26
 	return 0;
3ff7c26
 }
3ff7c26
 #endif
3ff7c26
-- 
3ff7c26
2.13.0
3ff7c26