2018-06-28 10:47:02

by Daniel Mack

[permalink] [raw]
Subject: [PATCH v2 0/4] Add devicetree functionality to w1 busses

This patch set contains four small patches that bring devicetree
functionality to w1 bus masters and slaves in general. As an example,
the DS2760 driver is made aware of devicetree nodes as an example.
Other drivers can easily be ported later.

W1 masters scan their bus in order to discover slave devices. Once
one is found, a driver matching the family of the device is instanciated
which handles it.

All that's needed for now is a call to of_find_matching_node() when
a slave device is attached, so the corresponding of_node pointer is
set. For devices such as the DS2760, another driver is probed which
can access the w1 slave through dev->parent.

Patch #1 adds some DT bindings documentation
Patch #2 adds the call to of_find_matching_node()
Patch #3 implements the match table for the DS2760 w1 slave
Patch #4 makes the DS2760 supply driver aware of DT environments

This works fine on a PXA3xx based board with a battery attached to
the w1-gpio bus master controller.

Daniel Mack (4):
dt-bindings: w1: document sub-node bindings for DS2760
w1: core: match sub-nodes of bus masters in devicetree
w1: ds2760: add devicetree matching glue
power: ds2760_battery: add device tree glue

.../devicetree/bindings/w1/maxim,ds2760.txt | 15 +++++++++++++++
.../devicetree/bindings/w1/w1-gpio.txt | 6 ++++++
Documentation/devicetree/bindings/w1/w1.txt | 18 ++++++++++++++++++
drivers/power/supply/ds2760_battery.c | 6 +++++-
drivers/w1/slaves/w1_ds2760.c | 9 +++++++++
drivers/w1/w1.c | 3 +++
include/linux/w1.h | 2 ++
7 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/w1/maxim,ds2760.txt
create mode 100644 Documentation/devicetree/bindings/w1/w1.txt

--
2.17.1



2018-06-28 08:13:15

by Daniel Mack

[permalink] [raw]
Subject: [PATCH v2 2/4] w1: core: match sub-nodes of bus masters in devicetree

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 <[email protected]>
---
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


2018-06-28 10:46:54

by Daniel Mack

[permalink] [raw]
Subject: [PATCH v2 1/4] dt-bindings: w1: document sub-node bindings for DS2760

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 <[email protected]>
---
.../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


2018-06-28 10:46:55

by Daniel Mack

[permalink] [raw]
Subject: [PATCH v2 4/4] power: ds2760_battery: add device tree glue

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 <[email protected]>
---
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


2018-06-28 10:47:09

by Daniel Mack

[permalink] [raw]
Subject: [PATCH v2 3/4] w1: ds2760: add devicetree matching glue

Add an id table for ds2760 so it can be matched by the core.

Signed-off-by: Daniel Mack <[email protected]>
---
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


2018-06-28 12:33:38

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH v2 4/4] power: ds2760_battery: add device tree glue

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 <[email protected]>
> ---

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


Attachments:
(No filename) (985.00 B)
signature.asc (849.00 B)
Download all attachments

2018-06-28 12:50:11

by Daniel Mack

[permalink] [raw]
Subject: Re: [PATCH v2 4/4] power: ds2760_battery: add device tree glue

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 <[email protected]>
>> ---
>
> 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


2018-07-03 23:17:52

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] dt-bindings: w1: document sub-node bindings for DS2760

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 <[email protected]>
> ---
> .../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
>