* [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt
@ 2014-03-17 12:43 Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 1/4] power_supply: of: Add an API to get power_supply device from dt node Chanwoo Choi
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Chanwoo Choi @ 2014-03-17 12:43 UTC (permalink / raw)
To: dbaryshkov, dwmw2; +Cc: myungjoo.ham, kyungmin.park, linux-kernel, Chanwoo Choi
This patchset add DT helper function to get power-supply device from devicetree.
- of_power_supply_get_dev(struct device *dev, enum power_supply_dev_type type,
int index)
Power-supply class provides 'power_supply_get_by_name()' to users who want to
find power-supply device with the name of power-supply device.
If CONFIG_OF is enabled, device drivers which want to get power-supply device
would directly get the power-supply device from devicetree by using of_power_
supply_get_dev(). This function can be used instead of power_supply_get_by_name().
For example,
[After]
The charger-manager must need the power-supply device of fuelgauge to
read the battery capacity. The charger-manager dt don't need to consider
the name of power-supply device for fuelgauge because of only needing
phandle of fuelgauge power-supply device.
fuelgauge0: max17047@36 {
compatible = "maxim,max17047";
interrupt-parent = <&gpx2>;
interrputs = <3 2>;
reg = <0x36>;
};
charger-manager@0 {
compatible = "charger-manager";
...
fuel-gauge = <&fuelgauge0>; /* Need phandle of fuelgauge
phandle name is always same. */
...
};
[Before]
Previous way use the name of fuelgauge power-supply device to get
fuel-gauge device using power_supply_get_by_name(). If change the name
of fuelgauge device, we have to modify both fuelgauge dt and charger-
manager dt. The charger-manager has dependency on the name of fuel-gague
power-supply device.
max17047@36 {
compatible = "maxim,max17047";
interrupt-parent = <&gpx2>;
interrputs = <3 2>;
reg = <0x36>;
};
charger-manager@0 {
compatible = "charger-manager";
...
cm-fuel-gauge = "max170xx_battery"; /* Need the name of fuel-gauge */
...
};
Chanwoo Choi (4):
power_supply: of: Add an API to get power_supply device from dt node
charger-manager: Get power_supply device using of_power_supply_get_dev()
Documentation: dt: charger-manager: Change the way to get fuel-gauge power-supply device
max17042_battery: Change battery name instead of static name according to device type
.../bindings/power_supply/charger-manager.txt | 8 ++-
drivers/power/Kconfig | 4 ++
drivers/power/Makefile | 2 +
drivers/power/charger-manager.c | 22 ++++--
drivers/power/max17042_battery.c | 2 +-
drivers/power/of_power_supply.c | 82 ++++++++++++++++++++++
include/linux/power/charger-manager.h | 2 +
include/linux/power/of_power_supply.h | 46 ++++++++++++
8 files changed, 159 insertions(+), 9 deletions(-)
create mode 100644 drivers/power/of_power_supply.c
create mode 100644 include/linux/power/of_power_supply.h
--
1.8.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH 1/4] power_supply: of: Add an API to get power_supply device from dt node
2014-03-17 12:43 [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt Chanwoo Choi
@ 2014-03-17 12:43 ` Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 2/4] charger-manager: Get power_supply device using of_power_supply_get_dev() Chanwoo Choi
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Chanwoo Choi @ 2014-03-17 12:43 UTC (permalink / raw)
To: dbaryshkov, dwmw2; +Cc: myungjoo.ham, kyungmin.park, linux-kernel, Chanwoo Choi
This patch add an API of_power_supply_get_dev() to be used by drivers to
get power_supply device in the case of DT(DeviceTree) node
(this can be used instead of power_supply_get_by_name()).
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
drivers/power/Kconfig | 4 ++
drivers/power/Makefile | 2 +
drivers/power/of_power_supply.c | 82 +++++++++++++++++++++++++++++++++++
include/linux/power/of_power_supply.h | 46 ++++++++++++++++++++
4 files changed, 134 insertions(+)
create mode 100644 drivers/power/of_power_supply.c
create mode 100644 include/linux/power/of_power_supply.h
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index ba69751..02240aa 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -8,6 +8,10 @@ menuconfig POWER_SUPPLY
if POWER_SUPPLY
+config OF_POWER_SUPPLY
+ def_tristate y
+ depends on OF
+
config POWER_SUPPLY_DEBUG
bool "Power supply debug"
help
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index ee54a3e..27d0c9c 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -4,6 +4,8 @@ power_supply-y := power_supply_core.o
power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o
power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o
+obj-$(CONFIG_OF_POWER_SUPPLY) += of_power_supply.o
+
obj-$(CONFIG_POWER_SUPPLY) += power_supply.o
obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.o
diff --git a/drivers/power/of_power_supply.c b/drivers/power/of_power_supply.c
new file mode 100644
index 0000000..25d93a1
--- /dev/null
+++ b/drivers/power/of_power_supply.c
@@ -0,0 +1,82 @@
+/*
+ * OF helpers for Power supply class
+ *
+ * Copyright (C) 2014 Samsung Electronics
+ * Chanwoo Choi <cw00.choi@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/power_supply.h>
+#include <linux/power/of_power_supply.h>
+
+/*
+ * of_power_supply_get_dev - Get the power_supply device from devicetree
+ * @dev - instance to the given device
+ * @index - index into list of power_supply
+ *
+ * return the instance of power_supply device
+ */
+struct power_supply *of_power_supply_get_dev(struct device *dev,
+ enum power_supply_dev_type type,
+ int index)
+{
+ struct power_supply *power_supply_dev;
+ struct device_node *node;
+ const char *name;
+ union __parent_dev {
+ struct platform_device *platform;
+ struct i2c_client *i2c;
+ } parent_dev;
+
+ if (!dev->of_node) {
+ dev_dbg(dev, "device does not have a device node entry\n");
+ return ERR_PTR(-EINVAL);
+ }
+
+ if (type >= POWER_SUPPLY_DEV_END || type <= POWER_SUPPLY_DEV_UNKNOWN) {
+ dev_dbg(dev, "unknown power_supply device : %d\n", type);
+ return ERR_PTR(-EINVAL);
+ }
+
+ node = of_parse_phandle(dev->of_node, power_supply_dev_list[type],
+ index);
+ if (!node) {
+ dev_dbg(dev, "failed to get phandle in %s node\n",
+ dev->of_node->full_name);
+ return ERR_PTR(-ENODEV);
+ }
+
+ parent_dev.platform = of_find_device_by_node(node);
+ if (parent_dev.platform) {
+ name = dev_name(&parent_dev.platform->dev);
+ goto success;
+ }
+
+ parent_dev.i2c = of_find_i2c_device_by_node(node);
+ if (parent_dev.i2c) {
+ name = parent_dev.i2c->name;
+ goto success;
+ }
+
+ return ERR_PTR(-ENODEV);
+
+success:
+ power_supply_dev = power_supply_get_by_name(name);
+ if (!power_supply_dev) {
+ dev_dbg(dev, "unable to get power supply device : %s\n", name);
+ return ERR_PTR(-ENODEV);
+ }
+
+ return power_supply_dev;
+}
+EXPORT_SYMBOL_GPL(of_power_supply_get_dev);
diff --git a/include/linux/power/of_power_supply.h b/include/linux/power/of_power_supply.h
new file mode 100644
index 0000000..cfd4874
--- /dev/null
+++ b/include/linux/power/of_power_supply.h
@@ -0,0 +1,46 @@
+/*
+ * OF helpers for Power supply class
+ *
+ * Copyright (C) 2014 Samsung Electronics
+ * Chanwoo Choi <cw00.choi@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef __LINUX_OF_POWER_SUPPLY_H
+#define __LINUX_OF_POWER_SUPPLY_H
+
+#include <linux/err.h>
+
+enum power_supply_dev_type {
+ POWER_SUPPLY_DEV_UNKNOWN = 0,
+ POWER_SUPPLY_DEV_FUELGAUGE,
+ POWER_SUPPLY_DEV_CHARGER,
+
+ POWER_SUPPLY_DEV_END,
+};
+
+static const char * const power_supply_dev_list[] = {
+ [POWER_SUPPLY_DEV_UNKNOWN] = "unknown",
+ [POWER_SUPPLY_DEV_FUELGAUGE] = "fuelgauge",
+ [POWER_SUPPLY_DEV_CHARGER] = "charger",
+};
+
+#if IS_ENABLED(CONFIG_OF_POWER_SUPPLY)
+extern struct power_supply
+ *of_power_supply_get_dev(struct device *dev,
+ enum power_supply_dev_type type,
+ int index);
+#else
+static inline struct power_supply
+ *of_power_supply_get_dev(struct device *dev,
+ enum power_supply_dev_type type,
+ int index)
+{
+ return ERR_PTR(-ENOSYS);
+}
+#endif /* CONFIG_OF_POWER_SUPPLY */
+#endif /* __LINUX_OF_POWER_SUPPLY_H */
--
1.8.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC PATCH 2/4] charger-manager: Get power_supply device using of_power_supply_get_dev()
2014-03-17 12:43 [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 1/4] power_supply: of: Add an API to get power_supply device from dt node Chanwoo Choi
@ 2014-03-17 12:43 ` Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 3/4] Documentation: dt: charger-manager: Change the way to get fuel-gauge power-supply device Chanwoo Choi
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Chanwoo Choi @ 2014-03-17 12:43 UTC (permalink / raw)
To: dbaryshkov, dwmw2; +Cc: myungjoo.ham, kyungmin.park, linux-kernel, Chanwoo Choi
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@samsung.com>
Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com>
---
---
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC PATCH 3/4] Documentation: dt: charger-manager: Change the way to get fuel-gauge power-supply device
2014-03-17 12:43 [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 1/4] power_supply: of: Add an API to get power_supply device from dt node Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 2/4] charger-manager: Get power_supply device using of_power_supply_get_dev() Chanwoo Choi
@ 2014-03-17 12:43 ` Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 4/4] max17042_battery: Change battery name instead of static name according to device type Chanwoo Choi
2014-03-18 0:38 ` [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt sre
4 siblings, 0 replies; 9+ messages in thread
From: Chanwoo Choi @ 2014-03-17 12:43 UTC (permalink / raw)
To: dbaryshkov, dwmw2; +Cc: myungjoo.ham, kyungmin.park, linux-kernel, Chanwoo Choi
This patch use the phandle of fuel-gauge device instead of the name of fuel-gauge
device to get fuel-gauge device directly from dt.
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com>
---
.../devicetree/bindings/power_supply/charger-manager.txt | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/power_supply/charger-manager.txt b/Documentation/devicetree/bindings/power_supply/charger-manager.txt
index 2b33750..ceebd66 100644
--- a/Documentation/devicetree/bindings/power_supply/charger-manager.txt
+++ b/Documentation/devicetree/bindings/power_supply/charger-manager.txt
@@ -6,7 +6,7 @@ Required properties :
- <>-supply : for regulator consumer
- cm-num-chargers : number of chargers
- cm-chargers : name of chargers
- - cm-fuel-gauge : name of battery fuel gauge
+ - fuelgauge : phandle of fuelgauge power-supply device
- subnode <regulator> :
- cm-regulator-name : name of charger regulator
- subnode <cable> :
@@ -30,6 +30,10 @@ Optional properties :
- cm-dis/charging-max = limits of charging duration
Example :
+ fuelgauge0: max17047@36 {
+ compatible = "maxim,max17047";
+ };
+
charger-manager@0 {
compatible = "charger-manager";
chg-reg-supply = <&charger_regulator>;
@@ -48,7 +52,7 @@ Example :
cm-num-chargers = <3>;
cm-chargers = "charger0", "charger1", "charger2";
- cm-fuel-gauge = "fuelgauge0";
+ fuelgauge = <&fuelgauge0>;
cm-thermal-zone = "thermal_zone.1"
/* in deci centigrade */
--
1.8.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC PATCH 4/4] max17042_battery: Change battery name instead of static name according to device type
2014-03-17 12:43 [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt Chanwoo Choi
` (2 preceding siblings ...)
2014-03-17 12:43 ` [RFC PATCH 3/4] Documentation: dt: charger-manager: Change the way to get fuel-gauge power-supply device Chanwoo Choi
@ 2014-03-17 12:43 ` Chanwoo Choi
2014-03-18 0:38 ` [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt sre
4 siblings, 0 replies; 9+ messages in thread
From: Chanwoo Choi @ 2014-03-17 12:43 UTC (permalink / raw)
To: dbaryshkov, dwmw2; +Cc: myungjoo.ham, kyungmin.park, linux-kernel, Chanwoo Choi
This patch use device name to make power_supply path according to device type:
[Before]
In case of max17042/max17047/max17050,
- /sys/class/power_supply/max170xx_battery
[After]
In case of max17042,
- /sys/class/power_supply/max17042
In case of max17047,
- /sys/class/power_supply/max17047
In case of max17050,
- /sys/class/power_supply/max17050
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
drivers/power/max17042_battery.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 66da691..cba6def 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -707,7 +707,7 @@ static int max17042_probe(struct i2c_client *client,
return -EIO;
}
- chip->battery.name = "max170xx_battery";
+ chip->battery.name = client->name;
chip->battery.type = POWER_SUPPLY_TYPE_BATTERY;
chip->battery.get_property = max17042_get_property;
chip->battery.properties = max17042_battery_props;
--
1.8.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt
2014-03-17 12:43 [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt Chanwoo Choi
` (3 preceding siblings ...)
2014-03-17 12:43 ` [RFC PATCH 4/4] max17042_battery: Change battery name instead of static name according to device type Chanwoo Choi
@ 2014-03-18 0:38 ` sre
2014-03-18 1:25 ` Chanwoo Choi
2014-03-18 6:06 ` Chanwoo Choi
4 siblings, 2 replies; 9+ messages in thread
From: sre @ 2014-03-18 0:38 UTC (permalink / raw)
To: Chanwoo Choi; +Cc: dbaryshkov, dwmw2, myungjoo.ham, kyungmin.park, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 873 bytes --]
Hi,
On Mon, Mar 17, 2014 at 09:43:43PM +0900, Chanwoo Choi wrote:
> This patchset add DT helper function to get power-supply device from devicetree.
> - of_power_supply_get_dev(struct device *dev, enum power_supply_dev_type type,
> int index)
> Power-supply class provides 'power_supply_get_by_name()' to users who want to
> find power-supply device with the name of power-supply device.
>
> If CONFIG_OF is enabled, device drivers which want to get power-supply device
> would directly get the power-supply device from devicetree by using of_power_
> supply_get_dev(). This function can be used instead of power_supply_get_by_name().
>
> For example,
> [...]
include/linux/power_supply.h provides the following function already:
struct power_supply *
power_supply_get_by_phandle(struct device_node *np, const char *property);
-- Sebastian
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt
2014-03-18 0:38 ` [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt sre
@ 2014-03-18 1:25 ` Chanwoo Choi
2014-03-18 6:06 ` Chanwoo Choi
1 sibling, 0 replies; 9+ messages in thread
From: Chanwoo Choi @ 2014-03-18 1:25 UTC (permalink / raw)
To: sre; +Cc: dbaryshkov, dwmw2, myungjoo.ham, kyungmin.park, linux-kernel
Hi,
On 03/18/2014 09:38 AM, sre@ring0.de wrote:
> Hi,
>
> On Mon, Mar 17, 2014 at 09:43:43PM +0900, Chanwoo Choi wrote:
>> This patchset add DT helper function to get power-supply device from devicetree.
>> - of_power_supply_get_dev(struct device *dev, enum power_supply_dev_type type,
>> int index)
>> Power-supply class provides 'power_supply_get_by_name()' to users who want to
>> find power-supply device with the name of power-supply device.
>>
>> If CONFIG_OF is enabled, device drivers which want to get power-supply device
>> would directly get the power-supply device from devicetree by using of_power_
>> supply_get_dev(). This function can be used instead of power_supply_get_by_name().
>>
>> For example,
>> [...]
>
> include/linux/power_supply.h provides the following function already:
>
> struct power_supply *
> power_supply_get_by_phandle(struct device_node *np, const char *property);
>
OK, thanks for your reply.
Dear all,
Ignore this patchset. I'll re-send new patchset using power_supply_get_by_phandle().
Best Regards,
Chanwoo Choi
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt
2014-03-18 0:38 ` [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt sre
2014-03-18 1:25 ` Chanwoo Choi
@ 2014-03-18 6:06 ` Chanwoo Choi
2014-03-18 15:01 ` sre
1 sibling, 1 reply; 9+ messages in thread
From: Chanwoo Choi @ 2014-03-18 6:06 UTC (permalink / raw)
To: sre; +Cc: dbaryshkov, dwmw2, myungjoo.ham, kyungmin.park, linux-kernel
Hi Sebastian,
On 03/18/2014 09:38 AM, sre@ring0.de wrote:
> Hi,
>
> On Mon, Mar 17, 2014 at 09:43:43PM +0900, Chanwoo Choi wrote:
>> This patchset add DT helper function to get power-supply device from devicetree.
>> - of_power_supply_get_dev(struct device *dev, enum power_supply_dev_type type,
>> int index)
>> Power-supply class provides 'power_supply_get_by_name()' to users who want to
>> find power-supply device with the name of power-supply device.
>>
>> If CONFIG_OF is enabled, device drivers which want to get power-supply device
>> would directly get the power-supply device from devicetree by using of_power_
>> supply_get_dev(). This function can be used instead of power_supply_get_by_name().
>>
>> For example,
>> [...]
>
> include/linux/power_supply.h provides the following function already:
>
> struct power_supply *
> power_supply_get_by_phandle(struct device_node *np, const char *property);
>
I checked power_supply_get_by_phandle().
But power_supply_get_by_phandle() is different from of_power_supply_get_dev()
So, I expalin the difference between "power_supply_get_by_phandle()" and "of_power_supply_get_dev()".
Existing "power_supply_get_by_phandle()"
- Need correct the name of power_supply property.
some device driver using power_supply_get_by_phandle() has the dependecy of
the name of power_supply property.
If the name of power_supply property is modified,
have to modify some device driver using power_supply_get_by_phandle().
But,
Proposed "of_power_supply_get_dev()"
- of_power_supply_get_dev() has not dependency of specific name.
of_power_supply_get_dev() only need device type of power_supply device among following device type:
"fuelgague"
"charger"
we can do addtional device type of power_supply device.
If some device driver use of_poewr_supply_get_dev(),
don't need to consider the name of power_supply device.
Thanks,
Chanwoo Choi
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt
2014-03-18 6:06 ` Chanwoo Choi
@ 2014-03-18 15:01 ` sre
0 siblings, 0 replies; 9+ messages in thread
From: sre @ 2014-03-18 15:01 UTC (permalink / raw)
To: Chanwoo Choi; +Cc: dbaryshkov, dwmw2, myungjoo.ham, kyungmin.park, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2140 bytes --]
Hi Chanwoo,
On Tue, Mar 18, 2014 at 03:06:00PM +0900, Chanwoo Choi wrote:
> I checked power_supply_get_by_phandle().
> But power_supply_get_by_phandle() is different from of_power_supply_get_dev()
>
> So, I expalin the difference between "power_supply_get_by_phandle()" and "of_power_supply_get_dev()".
>
> Existing "power_supply_get_by_phandle()"
> - Need correct the name of power_supply property.
> some device driver using power_supply_get_by_phandle() has the dependecy of
> the name of power_supply property.
>
> If the name of power_supply property is modified,
> have to modify some device driver using power_supply_get_by_phandle().
The property names are part of the DT ABI, which is not supposed to
be stable.
> But,
> Proposed "of_power_supply_get_dev()"
> - of_power_supply_get_dev() has not dependency of specific name.
> of_power_supply_get_dev() only need device type of power_supply device among following device type:
> "fuelgague"
> "charger"
> we can do addtional device type of power_supply device.
>
> If some device driver use of_poewr_supply_get_dev(),
> don't need to consider the name of power_supply device.
You don't need to consider the name of the power_supply device for
power_supply_get_by_phandle either. You only need to consider the
property name, which references the power_supply device. You can
have a look at drivers/power/bq2415x_charger.c, which makes use
of this function:
power_supply_get_by_phandle(np, "ti,usb-charger-detection");
A corresponding DT node can be found in arch/arm/boot/dts/omap3-n900.dts:
bq24150a: bq24150a@6b {
/* ... */
ti,usb-charger-detection = <&isp1704>;
}
As you can see the property name has nothing to do with any
names from the referenced node. Apart from that the node name
is also needed by your proposed of_power_supply_get_dev. The
difference is, that you hardcoded it to be either "fuelgauge"
or "charger". The following two calls should return the same
node:
of_power_supply_get_dev(dev, POWER_SUPPLY_DEV_FUELGAUGE, 0);
of_power_supply_get_dev(dev, "fuelgauge");
-- Sebastian
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-03-18 15:01 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-17 12:43 [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 1/4] power_supply: of: Add an API to get power_supply device from dt node Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 2/4] charger-manager: Get power_supply device using of_power_supply_get_dev() Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 3/4] Documentation: dt: charger-manager: Change the way to get fuel-gauge power-supply device Chanwoo Choi
2014-03-17 12:43 ` [RFC PATCH 4/4] max17042_battery: Change battery name instead of static name according to device type Chanwoo Choi
2014-03-18 0:38 ` [RFC PATCH 0/4] power_supply: Add DT helper function to get power-supply dev from dt sre
2014-03-18 1:25 ` Chanwoo Choi
2014-03-18 6:06 ` Chanwoo Choi
2014-03-18 15:01 ` sre
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).