* [PATCH v2 1/4] dt-bindings: w1: document sub-node bindings for DS2760
2018-06-28 7:55 [PATCH v2 0/4] Add devicetree functionality to w1 busses Daniel Mack
@ 2018-06-28 7:55 ` Daniel Mack
2018-07-03 23:16 ` Rob Herring
2018-06-28 7:55 ` [PATCH v2 2/4] w1: core: match sub-nodes of bus masters in devicetree Daniel Mack
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Daniel Mack @ 2018-06-28 7:55 UTC (permalink / raw)
To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik,
Daniel Mack
This patch add a generic w1 bindings document that merely describes how
slave deviceses are grouped under master nodes. It also adds a specific
binding for the ds2760 battery monitor.
Signed-off-by: Daniel Mack <daniel@zonque.org>
---
.../devicetree/bindings/w1/maxim,ds2760.txt | 15 +++++++++++++++
.../devicetree/bindings/w1/w1-gpio.txt | 6 ++++++
Documentation/devicetree/bindings/w1/w1.txt | 18 ++++++++++++++++++
3 files changed, 39 insertions(+)
create mode 100644 Documentation/devicetree/bindings/w1/maxim,ds2760.txt
create mode 100644 Documentation/devicetree/bindings/w1/w1.txt
diff --git a/Documentation/devicetree/bindings/w1/maxim,ds2760.txt b/Documentation/devicetree/bindings/w1/maxim,ds2760.txt
new file mode 100644
index 000000000000..d916fdd213f7
--- /dev/null
+++ b/Documentation/devicetree/bindings/w1/maxim,ds2760.txt
@@ -0,0 +1,15 @@
+Devicetree bindings for Maxim DS2760
+====================================
+
+The ds2760 is a w1 slave device and must hence have its sub-node in DT
+under a w1 bus master node.
+
+The device exposes a power supply, so the details described in
+Documentation/devicetree/bindings/power/supply/power_supply.txt apply.
+
+Required properties:
+- compatible: must be "maxim,ds2760"
+
+Optional properties:
+- power-supplies: Refers to one or more power supplies connected to
+ this battery.
diff --git a/Documentation/devicetree/bindings/w1/w1-gpio.txt b/Documentation/devicetree/bindings/w1/w1-gpio.txt
index 6e09c35d9f1a..6694317bcbed 100644
--- a/Documentation/devicetree/bindings/w1/w1-gpio.txt
+++ b/Documentation/devicetree/bindings/w1/w1-gpio.txt
@@ -13,10 +13,16 @@ Optional properties:
- linux,open-drain: if specified, the data pin is considered in
open-drain mode.
+Also refer to the generic w1.txt document.
+
Examples:
onewire@0 {
compatible = "w1-gpio";
gpios = <&gpio 126 0>, <&gpio 105 0>;
+
+ battery {
+ compatible = "maxim,ds2760";
+ };
};
diff --git a/Documentation/devicetree/bindings/w1/w1.txt b/Documentation/devicetree/bindings/w1/w1.txt
new file mode 100644
index 000000000000..6ac103f972a0
--- /dev/null
+++ b/Documentation/devicetree/bindings/w1/w1.txt
@@ -0,0 +1,18 @@
+Generic devicetree bindings for onewire (w1) busses
+===================================================
+
+Onewire busses are described through nodes of their master bus controller.
+Slave devices are listed as sub-nodes of such master devices. For now, one
+one slave is allowed per bus master.
+
+
+Example:
+
+ onewire {
+ compatible = "w1-gpio";
+ gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
+
+ battery {
+ compatible = "maxim,ds2760";
+ };
+ };
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 1/4] dt-bindings: w1: document sub-node bindings for DS2760
2018-06-28 7:55 ` [PATCH v2 1/4] dt-bindings: w1: document sub-node bindings for DS2760 Daniel Mack
@ 2018-07-03 23:16 ` Rob Herring
0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2018-07-03 23:16 UTC (permalink / raw)
To: Daniel Mack
Cc: zbr, mark.rutland, szabolcs.gyurko, sre, devicetree, linux-kernel,
linux-pm, robert.jarzmik
On Thu, Jun 28, 2018 at 09:55:37AM +0200, Daniel Mack wrote:
> This patch add a generic w1 bindings document that merely describes how
> slave deviceses are grouped under master nodes. It also adds a specific
> binding for the ds2760 battery monitor.
>
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
> .../devicetree/bindings/w1/maxim,ds2760.txt | 15 +++++++++++++++
> .../devicetree/bindings/w1/w1-gpio.txt | 6 ++++++
> Documentation/devicetree/bindings/w1/w1.txt | 18 ++++++++++++++++++
> 3 files changed, 39 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/w1/maxim,ds2760.txt
> create mode 100644 Documentation/devicetree/bindings/w1/w1.txt
>
> diff --git a/Documentation/devicetree/bindings/w1/maxim,ds2760.txt b/Documentation/devicetree/bindings/w1/maxim,ds2760.txt
> new file mode 100644
> index 000000000000..d916fdd213f7
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/w1/maxim,ds2760.txt
> @@ -0,0 +1,15 @@
> +Devicetree bindings for Maxim DS2760
> +====================================
> +
> +The ds2760 is a w1 slave device and must hence have its sub-node in DT
> +under a w1 bus master node.
> +
> +The device exposes a power supply, so the details described in
> +Documentation/devicetree/bindings/power/supply/power_supply.txt apply.
> +
> +Required properties:
> +- compatible: must be "maxim,ds2760"
> +
> +Optional properties:
> +- power-supplies: Refers to one or more power supplies connected to
> + this battery.
> diff --git a/Documentation/devicetree/bindings/w1/w1-gpio.txt b/Documentation/devicetree/bindings/w1/w1-gpio.txt
> index 6e09c35d9f1a..6694317bcbed 100644
> --- a/Documentation/devicetree/bindings/w1/w1-gpio.txt
> +++ b/Documentation/devicetree/bindings/w1/w1-gpio.txt
> @@ -13,10 +13,16 @@ Optional properties:
> - linux,open-drain: if specified, the data pin is considered in
> open-drain mode.
>
> +Also refer to the generic w1.txt document.
> +
> Examples:
>
> onewire@0 {
> compatible = "w1-gpio";
> gpios = <&gpio 126 0>, <&gpio 105 0>;
> +
> + battery {
> + compatible = "maxim,ds2760";
Perhaps show the power-supplies property as that's the whole point to
have in DT.
> + };
> };
>
> diff --git a/Documentation/devicetree/bindings/w1/w1.txt b/Documentation/devicetree/bindings/w1/w1.txt
> new file mode 100644
> index 000000000000..6ac103f972a0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/w1/w1.txt
> @@ -0,0 +1,18 @@
> +Generic devicetree bindings for onewire (w1) busses
> +===================================================
> +
> +Onewire busses are described through nodes of their master bus controller.
> +Slave devices are listed as sub-nodes of such master devices. For now, one
> +one slave is allowed per bus master.
s/one one/only one/
> +
> +
> +Example:
> +
> + onewire {
> + compatible = "w1-gpio";
> + gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
> +
> + battery {
> + compatible = "maxim,ds2760";
> + };
> + };
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] w1: core: match sub-nodes of bus masters in devicetree
2018-06-28 7:55 [PATCH v2 0/4] Add devicetree functionality to w1 busses Daniel Mack
2018-06-28 7:55 ` [PATCH v2 1/4] dt-bindings: w1: document sub-node bindings for DS2760 Daniel Mack
@ 2018-06-28 7:55 ` Daniel Mack
2018-06-28 7:55 ` [PATCH v2 3/4] w1: ds2760: add devicetree matching glue Daniel Mack
2018-06-28 7:55 ` [PATCH v2 4/4] power: ds2760_battery: add device tree glue Daniel Mack
3 siblings, 0 replies; 8+ messages in thread
From: Daniel Mack @ 2018-06-28 7:55 UTC (permalink / raw)
To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik,
Daniel Mack
Once a new slave device is detected, match it against all sub-nodes of the
master bus controller. If a match is found, set the slave device's of_node
pointer.
Signed-off-by: Daniel Mack <daniel@zonque.org>
---
drivers/w1/w1.c | 3 +++
include/linux/w1.h | 2 ++
2 files changed, 5 insertions(+)
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index caef0e0fd817..890c038c25f8 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -26,6 +26,7 @@
#include <linux/kthread.h>
#include <linux/freezer.h>
#include <linux/hwmon.h>
+#include <linux/of.h>
#include <linux/atomic.h>
@@ -686,6 +687,8 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
sl->dev.bus = &w1_bus_type;
sl->dev.release = &w1_slave_release;
sl->dev.groups = w1_slave_groups;
+ sl->dev.of_node = of_find_matching_node(sl->master->dev.of_node,
+ sl->family->of_match_table);
dev_set_name(&sl->dev, "%02x-%012llx",
(unsigned int) sl->reg_num.family,
diff --git a/include/linux/w1.h b/include/linux/w1.h
index 694101f744c7..3111585c371f 100644
--- a/include/linux/w1.h
+++ b/include/linux/w1.h
@@ -274,6 +274,8 @@ struct w1_family {
struct w1_family_ops *fops;
+ const struct of_device_id *of_match_table;
+
atomic_t refcnt;
};
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 3/4] w1: ds2760: add devicetree matching glue
2018-06-28 7:55 [PATCH v2 0/4] Add devicetree functionality to w1 busses Daniel Mack
2018-06-28 7:55 ` [PATCH v2 1/4] dt-bindings: w1: document sub-node bindings for DS2760 Daniel Mack
2018-06-28 7:55 ` [PATCH v2 2/4] w1: core: match sub-nodes of bus masters in devicetree Daniel Mack
@ 2018-06-28 7:55 ` Daniel Mack
2018-06-28 7:55 ` [PATCH v2 4/4] power: ds2760_battery: add device tree glue Daniel Mack
3 siblings, 0 replies; 8+ messages in thread
From: Daniel Mack @ 2018-06-28 7:55 UTC (permalink / raw)
To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik,
Daniel Mack
Add an id table for ds2760 so it can be matched by the core.
Signed-off-by: Daniel Mack <daniel@zonque.org>
---
drivers/w1/slaves/w1_ds2760.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c
index 26168abfb8b8..e1726a4e4b1d 100644
--- a/drivers/w1/slaves/w1_ds2760.c
+++ b/drivers/w1/slaves/w1_ds2760.c
@@ -17,6 +17,7 @@
#include <linux/mutex.h>
#include <linux/idr.h>
#include <linux/gfp.h>
+#include <linux/of.h>
#include <linux/w1.h>
@@ -157,6 +158,13 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl)
platform_device_unregister(pdev);
}
+#ifdef CONFIG_OF
+static const struct of_device_id w1_ds2760_of_ids[] = {
+ { .compatible = "maxim,ds2760" },
+ {}
+};
+#endif
+
static struct w1_family_ops w1_ds2760_fops = {
.add_slave = w1_ds2760_add_slave,
.remove_slave = w1_ds2760_remove_slave,
@@ -166,6 +174,7 @@ static struct w1_family_ops w1_ds2760_fops = {
static struct w1_family w1_ds2760_family = {
.fid = W1_FAMILY_DS2760,
.fops = &w1_ds2760_fops,
+ .of_match_table = of_match_ptr(w1_ds2760_of_ids),
};
module_w1_family(w1_ds2760_family);
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 4/4] power: ds2760_battery: add device tree glue
2018-06-28 7:55 [PATCH v2 0/4] Add devicetree functionality to w1 busses Daniel Mack
` (2 preceding siblings ...)
2018-06-28 7:55 ` [PATCH v2 3/4] w1: ds2760: add devicetree matching glue Daniel Mack
@ 2018-06-28 7:55 ` Daniel Mack
2018-06-28 11:52 ` Sebastian Reichel
3 siblings, 1 reply; 8+ messages in thread
From: Daniel Mack @ 2018-06-28 7:55 UTC (permalink / raw)
To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik,
Daniel Mack
The w1 slave device used by this driver now has a of_node in case it
was matched against a devicetree sub-node of the bus master. This can
now be passed down to the power supply core which will parse more
properties from the node, such as 'power-supplies'.
Signed-off-by: Daniel Mack <daniel@zonque.org>
---
drivers/power/supply/ds2760_battery.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c
index ae180dc929c9..77dfdeb5fbc0 100644
--- a/drivers/power/supply/ds2760_battery.c
+++ b/drivers/power/supply/ds2760_battery.c
@@ -510,6 +510,10 @@ static int ds2760_battery_probe(struct platform_device *pdev)
char status;
int retval = 0;
struct ds2760_device_info *di;
+ struct device *w1_dev;
+
+ w1_dev = pdev->dev.parent;
+ psy_cfg.of_node = w1_dev->of_node;
di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
if (!di) {
@@ -520,7 +524,7 @@ static int ds2760_battery_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, di);
di->dev = &pdev->dev;
- di->w1_dev = pdev->dev.parent;
+ di->w1_dev = w1_dev;
di->bat_desc.name = dev_name(&pdev->dev);
di->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
di->bat_desc.properties = ds2760_battery_props;
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 4/4] power: ds2760_battery: add device tree glue
2018-06-28 7:55 ` [PATCH v2 4/4] power: ds2760_battery: add device tree glue Daniel Mack
@ 2018-06-28 11:52 ` Sebastian Reichel
2018-06-28 12:39 ` Daniel Mack
0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Reichel @ 2018-06-28 11:52 UTC (permalink / raw)
To: Daniel Mack
Cc: zbr, robh+dt, mark.rutland, szabolcs.gyurko, devicetree,
linux-kernel, linux-pm, robert.jarzmik
[-- Attachment #1: Type: text/plain, Size: 985 bytes --]
Hi,
On Thu, Jun 28, 2018 at 09:55:40AM +0200, Daniel Mack wrote:
> The w1 slave device used by this driver now has a of_node in case it
> was matched against a devicetree sub-node of the bus master. This can
> now be passed down to the power supply core which will parse more
> properties from the node, such as 'power-supplies'.
>
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
Thanks for the patch series. Having proper DT support is a nice
addition. But instead of extending the platform device hack, please
merge the w1 driver into ds2760_battery.c as it happened to the
bq27000 driver already. The intermediate platform device is completly
useless and only makes things more complicated.
Basically move all code from w1_ds2760.c into ds2760_battery.c,
drop some EXPORT_SYMBOL and make functions static instead. Then
move content from probe/remove function into add_slave/remove_slave
callbacks and drop all platform device things.
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 4/4] power: ds2760_battery: add device tree glue
2018-06-28 11:52 ` Sebastian Reichel
@ 2018-06-28 12:39 ` Daniel Mack
0 siblings, 0 replies; 8+ messages in thread
From: Daniel Mack @ 2018-06-28 12:39 UTC (permalink / raw)
To: Sebastian Reichel
Cc: zbr, robh+dt, mark.rutland, szabolcs.gyurko, devicetree,
linux-kernel, linux-pm, robert.jarzmik
On Thursday, June 28, 2018 01:52 PM, Sebastian Reichel wrote:
> Hi,
>
> On Thu, Jun 28, 2018 at 09:55:40AM +0200, Daniel Mack wrote:
>> The w1 slave device used by this driver now has a of_node in case it
>> was matched against a devicetree sub-node of the bus master. This can
>> now be passed down to the power supply core which will parse more
>> properties from the node, such as 'power-supplies'.
>>
>> Signed-off-by: Daniel Mack <daniel@zonque.org>
>> ---
>
> Thanks for the patch series. Having proper DT support is a nice
> addition. But instead of extending the platform device hack, please
> merge the w1 driver into ds2760_battery.c as it happened to the
> bq27000 driver already. The intermediate platform device is completly
> useless and only makes things more complicated.
>
> Basically move all code from w1_ds2760.c into ds2760_battery.c,
> drop some EXPORT_SYMBOL and make functions static instead. Then
> move content from probe/remove function into add_slave/remove_slave
> callbacks and drop all platform device things.
Okay, yes, that makes sense. I never understood why there are multiple
drivers for this.
Thanks,
Daniel
^ permalink raw reply [flat|nested] 8+ messages in thread