[RFC PATCH 2/4] charger-manager: Get power_supply device using of_power_supply_get_dev()

From: Chanwoo Choi
Date: Mon Mar 17 2014 - 08:44:52 EST


This patch use of_power_supply_get_dev() dt funtion to get power_supply device
instead of legacy method. This patch get direclty the instance of power supply
device from dt.

Signed-off-by: Chanwoo Choi <cw00.choi@xxxxxxxxxxx>
Signed-off-by: Myungjoo Ham <myungjoo.ham@xxxxxxxxxxx>
---
---
drivers/power/charger-manager.c | 22 ++++++++++++++++------
include/linux/power/charger-manager.h | 2 ++
2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 9e4dab4..a5bb9ae 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -23,6 +23,7 @@
#include <linux/workqueue.h>
#include <linux/platform_device.h>
#include <linux/power/charger-manager.h>
+#include <linux/power/of_power_supply.h>
#include <linux/regulator/consumer.h>
#include <linux/sysfs.h>
#include <linux/of.h>
@@ -1584,7 +1585,12 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)
}
}

- of_property_read_string(np, "cm-fuel-gauge", &desc->psy_fuel_gauge);
+ desc->fuel_gauge = of_power_supply_get_dev(dev,
+ POWER_SUPPLY_DEV_FUELGAUGE, 0);
+ if (IS_ERR_OR_NULL(desc->fuel_gauge)) {
+ dev_err(dev, "Failed to get device instance of fuel-gague\n");
+ return ERR_PTR(-ENODEV);
+ }

of_property_read_string(np, "cm-thermal-zone", &desc->thermal_zone);

@@ -1739,11 +1745,15 @@ static int charger_manager_probe(struct platform_device *pdev)
}
}

- cm->fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
- if (!cm->fuel_gauge) {
- dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
- desc->psy_fuel_gauge);
- return -ENODEV;
+ if (desc->fuel_gauge) {
+ cm->fuel_gauge = desc->fuel_gauge;
+ } else {
+ cm->fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
+ if (!cm->fuel_gauge) {
+ dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
+ desc->psy_fuel_gauge);
+ return -ENODEV;
+ }
}

if (desc->polling_interval_ms == 0 ||
diff --git a/include/linux/power/charger-manager.h b/include/linux/power/charger-manager.h
index 07e7945..92cc47a 100644
--- a/include/linux/power/charger-manager.h
+++ b/include/linux/power/charger-manager.h
@@ -175,6 +175,7 @@ struct charger_regulator {
* @num_charger_regulator: the number of entries in charger_regulators
* @charger_regulators: array of charger regulators
* @psy_fuel_gauge: the name of power-supply for fuel gauge
+ * @fuel_gauge: power_supply device for fuel gauge
* @thermal_zone : the name of thermal zone for battery
* @temp_min : Minimum battery temperature for charging.
* @temp_max : Maximum battery temperature for charging.
@@ -210,6 +211,7 @@ struct charger_desc {
struct charger_regulator *charger_regulators;

const char *psy_fuel_gauge;
+ struct power_supply *fuel_gauge;

const char *thermal_zone;

--
1.8.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/