Add devicetree functionality to w1 busses and ds2760
Subsystems (3)
v3 cover Add devicetree functionality to w1 busses and ds2760
This patch set contains four patches that bring devicetree functionality to w1 bus masters and slaves in general. As an example, the ds2760 driver is made aware of devicetree probing. 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. To add devicetree functionality, 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.
The series also contains a patch that merges the w1 slave driver for the ds2760 battery monitor into its only user, the ds2760 supply driver. The indirection with two drivers never had any benefit, and here is a good opportunity to clean this up.
Patch #1 adds some DT bindings documentation
Patch #2 adds the call to of_find_matching_node() Patch #3 merges the w1 slave and the supply driver for ds2760 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.
Changelog:
v2 → v3:
* Fixed a typo in the documentation and added more real-world example for the bindings. Pointed out by Rob Herring.
Daniel Mack (4):
dt-bindings: w1: document generic onewire and DS2760 bindings
w1: core: match sub-nodes of bus masters in devicetree
power: supply: ds2760_battery: merge ds2760 supply driver with its w1
slave companion
power: supply: ds2760_battery: add devicetree probing
.../bindings/power/supply/maxim,ds2760.txt | 29 ++ .../devicetree/bindings/w1/w1-gpio.txt | 11 +- Documentation/devicetree/bindings/w1/w1.txt | 25 ++ drivers/power/supply/Kconfig | 2 +- drivers/power/supply/ds2760_battery.c | 351 +++++++++++++----- drivers/w1/slaves/Kconfig | 12 - drivers/w1/slaves/Makefile | 1 - drivers/w1/slaves/w1_ds2760.c | 175 --------- drivers/w1/slaves/w1_ds2760.h | 59 --- drivers/w1/w1.c | 3 + include/linux/w1.h | 2 + 11 files changed, 329 insertions(+), 341 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt create mode 100644 Documentation/devicetree/bindings/w1/w1.txt delete mode 100644 drivers/w1/slaves/w1_ds2760.c delete mode 100644 drivers/w1/slaves/w1_ds2760.h
Signature · 1 line
2.17.1
PATCH v3 1/4 dt-bindings: w1: document generic onewire and DS2760 bindings
This patch adds 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.
--- .../bindings/power/supply/maxim,ds2760.txt | 29 +++++++++++++++++++ .../devicetree/bindings/w1/w1-gpio.txt | 11 +++++-- Documentation/devicetree/bindings/w1/w1.txt | 25 ++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt create mode 100644 Documentation/devicetree/bindings/w1/w1.txt
Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt new file +29 -0
@@ -0,0 +1,29 @@ +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. +- maxim,pmod-enabled: This boolean property enables the DS2760 to enter + sleep mode when the DQ line goes low for greater + than 2 seconds and leave sleep Mode when the DQ + line goes high. +- maxim,cache-time: Time im milliseconds to cache the data for. When + this time expires, the values are read again from + the hardware. Defaults to 1000. +- maxim,rated-capacity: The rated capacity of the battery, in mAh. + If not specified, the value stored in the + non-volatile chip memory is used. +- maxim,current-accumulator: + The current accumulator value in mAh. + If not specified, the value stored in the + non-volatile chip memory is used.
Documentation/devicetree/bindings/w1/w1-gpio.txt +8 -3
@@ -13,10 +13,15 @@ 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 { + onewire { compatible = "w1-gpio"; - gpios = <&gpio 126 0>, <&gpio 105 0>; - }; + gpios = <&gpio 0 GPIO_ACTIVE_HIGH>; + battery { + // ... + }; + };
Documentation/devicetree/bindings/w1/w1.txt new file +25 -0
@@ -0,0 +1,25 @@ +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, only +one slave is allowed per bus master. + + +Example: + + charger: charger { + compatible = "gpio-charger"; + charger-type = "mains"; + gpios = <&gpio 1 GPIO_ACTIVE_LOW>; + }; + + onewire@0 { + compatible = "w1-gpio"; + gpios = <&gpio 100 0>, <&gpio 101 0>; + + battery { + compatible = "maxim,ds2760"; + power-supplies = <&charger>; + }; + };
Signature · 1 line
2.17.1
Rob Herring
maintainerRe: [PATCH v3 1/4] dt-bindings: w1: document generic onewire and DS2760 bindings
Quoted 7 lines · Daniel Mack
This patch adds 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]>--- .../bindings/power/supply/maxim,ds2760.txt | 29 +++++++++++++++++++
This has grown enough now, you should probably make it a separate patch.
Quoted 22 lines
.../devicetree/bindings/w1/w1-gpio.txt | 11 +++++-- Documentation/devicetree/bindings/w1/w1.txt | 25 ++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt create mode 100644 Documentation/devicetree/bindings/w1/w1.txtDocumentation/devicetree/bindings/power/supply/maxim,ds2760.txt new file +10
-0@@ -0,0 +1,29 @@ +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:
Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt line 20
Quoted 10 lines
Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt new file +10
-0+- compatible: must be "maxim,ds2760" + +Optional properties: +- power-supplies: Refers to one or more power supplies connected to + this battery. +- maxim,pmod-enabled: This boolean property enables the DS2760 to enter + sleep mode when the DQ line goes low for greater + than 2 seconds and leave sleep Mode when the DQ + line goes high. +- maxim,cache-time: Time im milliseconds to cache the data for. When
Add unit suffix as defined in property-units.txt.
Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt line 23
Quoted 3 lines
Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt new file +3
-0+ this time expires, the values are read again from + the hardware. Defaults to 1000. +- maxim,rated-capacity: The rated capacity of the battery, in mAh.
Seems like this should be common.
Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt line 29
Quoted 6 lines
Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt new file +6
-0+ If not specified, the value stored in the + non-volatile chip memory is used. +- maxim,current-accumulator: + The current accumulator value in mAh. + If not specified, the value stored in the + non-volatile chip memory is used.
This would be updated periodically while running and then restored after a power cycle or reboot to maintain the battery level across power cycle? I don't think that belongs in DT as we don't really define whether a DT can be updated persistently.
Quoted 36 lines
Documentation/devicetree/bindings/w1/w1-gpio.txt +8
-3@@ -13,10 +13,15 @@ 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 { + onewire { compatible = "w1-gpio"; - gpios = <&gpio 126 0>, <&gpio 105 0>; - }; + gpios = <&gpio 0 GPIO_ACTIVE_HIGH>; + battery { + // ... + }; + };Documentation/devicetree/bindings/w1/w1.txt new file +7
-0@@ -0,0 +1,25 @@ +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, only +one slave is allowed per bus master. +
Documentation/devicetree/bindings/w1/w1.txt line 17
Quoted 10 lines
Documentation/devicetree/bindings/w1/w1.txt new file +10
-0+ +Example: + + charger: charger { + compatible = "gpio-charger"; + charger-type = "mains"; + gpios = <&gpio 1 GPIO_ACTIVE_LOW>; + }; + + onewire@0 {
Drop the unit-address.
Quoted 11 lines
Documentation/devicetree/bindings/w1/w1.txt new file +8
-0+ compatible = "w1-gpio"; + gpios = <&gpio 100 0>, <&gpio 101 0>; + + battery { + compatible = "maxim,ds2760"; + power-supplies = <&charger>; + }; + };Signature · 1 line
2.17.1
Re: [PATCH v3 1/4] dt-bindings: w1: document generic onewire and DS2760 bindings
Quoted 11 lines · Rob Herring
Quoted 7 lines · Daniel Mack
This patch adds 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]>--- .../bindings/power/supply/maxim,ds2760.txt | 29 +++++++++++++++++++This has grown enough now, you should probably make it a separate patch.
Right, will do.
Thanks for all the reviews, Rob. Much appreciated. Will send a v4.
Daniel
PATCH v3 2/4 w1: core: match sub-nodes of bus masters in devicetree
In reply to Daniel MackOnce 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.
--- drivers/w1/w1.c | 3 +++ include/linux/w1.h | 2 ++ 2 files changed, 5 insertions(+)
drivers/w1/w1.c +3 -0
@@ -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,
include/linux/w1.h +2 -0
@@ -274,6 +274,8 @@ struct w1_family {struct w1_family_ops *fops; +const struct of_device_id *of_match_table; +atomic_t refcnt; };
Signature · 1 line
2.17.1
PATCH v3 3/4 power: supply: ds2760_battery: merge ds2760 supply driver with its w1 slave companion
In reply to Daniel MackThis patch removes the w1 slave driver that used to register the w1 family and instanciate a platform device at runtime. The code now lives in the supply driver instead to avoid that level of indirection.
The old device name "ds2760-battery.0" is preserved, so userspace applications can access the same virtual device nodes as before.
Note that because the w1 core does not currently have a framework for suspend/resume, the driver now registers a PM notifier callback.
--- drivers/power/supply/Kconfig | 2 +- drivers/power/supply/ds2760_battery.c | 321 ++++++++++++++++++-------- drivers/w1/slaves/Kconfig | 12 - drivers/w1/slaves/Makefile | 1 - drivers/w1/slaves/w1_ds2760.c | 175 -------------- drivers/w1/slaves/w1_ds2760.h | 59 ----- 6 files changed, 232 insertions(+), 338 deletions(-) delete mode 100644 drivers/w1/slaves/w1_ds2760.c delete mode 100644 drivers/w1/slaves/w1_ds2760.h
drivers/power/supply/Kconfig +1 -1
@@ -92,7 +92,7 @@ config BATTERY_CPCAP config BATTERY_DS2760 tristate "DS2760 battery driver (HP iPAQ & others)" - depends on W1 && W1_SLAVE_DS2760 + depends on W1 help Say Y here to enable support for batteries with ds2760 chip.
drivers/power/supply/ds2760_battery.c +231 -90
441 lines not on this page · raw message
drivers/w1/slaves/Kconfig +0 -12
@@ -100,18 +100,6 @@ config W1_SLAVE_DS2438 Say Y here if you want to use a 1-wire DS2438 Smart Battery Monitor device support -config W1_SLAVE_DS2760 - tristate "Dallas 2760 battery monitor chip (HP iPAQ & others)" - help - If you enable this you will have the DS2760 battery monitor - chip support. - - The battery monitor chip is used in many batteries/devices - as the one who is responsible for charging/discharging/monitoring - Li+ batteries. - - If you are unsure, say N. - config W1_SLAVE_DS2780 tristate "Dallas 2780 battery monitor chip" help
drivers/w1/slaves/Makefile +0 -1
@@ -14,7 +14,6 @@ obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o obj-$(CONFIG_W1_SLAVE_DS2805) += w1_ds2805.o obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o obj-$(CONFIG_W1_SLAVE_DS2438) += w1_ds2438.o -obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o obj-$(CONFIG_W1_SLAVE_DS2781) += w1_ds2781.o obj-$(CONFIG_W1_SLAVE_DS28E04) += w1_ds28e04.o
drivers/w1/slaves/w1_ds2760.c deleted +0 -175
175 lines not on this page · raw message
drivers/w1/slaves/w1_ds2760.h deleted +0 -59
59 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 4/4 power: supply: ds2760_battery: add devicetree probing
In reply to Daniel MackAdd a matching table for devicetree probing, and optionally set the module parameter variables from DT properties.
--- drivers/power/supply/ds2760_battery.c | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
drivers/power/supply/ds2760_battery.c +31 -1
@@ -29,6 +29,7 @@#include <linux/power_supply.h> #include <linux/suspend.h> #include <linux/w1.h> +#include <linux/of.h> static unsigned int cache_time =1000 ;module_param (cache_time, uint,0644 );
@@ -705,6 +706,27 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) psy_cfg.drv_data = di; +if (dev->of_node) { +u32 tmp; + + psy_cfg.of_node = dev->of_node; + +if (!of_property_read_bool (dev->of_node,"maxim,pmod-enabled" )) + pmod_enabled = true; + +if (!of_property_read_u32 (dev->of_node, +"maxim,cache-time" , &tmp)) + cache_time = tmp; + +if (!of_property_read_u32 (dev->of_node, +"maxim,rated-capacity" , &tmp)) + rated_capacity = tmp /10 ;/* property is in mAh */ + +if (!of_property_read_u32 (dev->of_node, +"maxim,current-accumulator" , &tmp)) + current_accum = tmp; + } + di->charge_status =POWER_SUPPLY_STATUS_UNKNOWN ; sl->family_data = di;
@@ -719,7 +741,7 @@ static int w1_ds2760_add_slave(struct w1_slave *sl)ds2760_battery_write_status (di, status); -/* set rated capacity from module param */ +/* set rated capacity from module param or device tree */ if (rated_capacity)ds2760_battery_write_rated_capacity (di, rated_capacity);
@@ -769,6 +791,13 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl)power_supply_unregister (di->bat); } +#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,
@@ -778,6 +807,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);
Signature · 1 line
2.17.1