linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/5] Add devicetree functionality to w1 busses and ds2760
@ 2018-07-06  5:35 Daniel Mack
  2018-07-06  5:35 ` [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings Daniel Mack
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Daniel Mack @ 2018-07-06  5:35 UTC (permalink / raw)
  To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
  Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik, Daniel Mack

This patch set contains five 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 and #2 add DT bindings documentation
Patch #3 adds the call to of_find_matching_node()
Patch #4 merges the w1 slave and the supply driver for ds2760
Patch #5 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:

v3 → v4:
* Property name cleanups
* Dropped maxim,current-accumulator property
* Split 1st patch of v3 in two

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


Daniel Mack (5):
  dt-bindings: w1: document generic onewire bindings
  dt-bindings: w1: document bindings for ds2760 battery monitor
  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    |  26 ++
 .../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         | 348 +++++++++++++-----
 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, 323 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

-- 
2.17.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings
  2018-07-06  5:35 [PATCH v4 0/5] Add devicetree functionality to w1 busses and ds2760 Daniel Mack
@ 2018-07-06  5:35 ` Daniel Mack
  2018-07-11 15:01   ` Rob Herring
  2018-07-06  5:35 ` [PATCH v4 2/5] dt-bindings: w1: document bindings for ds2760 battery monitor Daniel Mack
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Daniel Mack @ 2018-07-06  5:35 UTC (permalink / raw)
  To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
  Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik, Daniel Mack

This patch adds a generic w1 bindings document that describes how w1
slave deviceses are grouped under master nodes. It also augments the
existing w1-gpio.txt document a bit.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 .../devicetree/bindings/w1/w1-gpio.txt        | 11 +++++---
 Documentation/devicetree/bindings/w1/w1.txt   | 25 +++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/w1/w1.txt

diff --git a/Documentation/devicetree/bindings/w1/w1-gpio.txt b/Documentation/devicetree/bindings/w1/w1-gpio.txt
index 6e09c35d9f1a..3d6554eac240 100644
--- a/Documentation/devicetree/bindings/w1/w1-gpio.txt
+++ b/Documentation/devicetree/bindings/w1/w1-gpio.txt
@@ -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 {
+			// ...
+		};
+	};
diff --git a/Documentation/devicetree/bindings/w1/w1.txt b/Documentation/devicetree/bindings/w1/w1.txt
new file mode 100644
index 000000000000..05f26b27d898
--- /dev/null
+++ b/Documentation/devicetree/bindings/w1/w1.txt
@@ -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 {
+		compatible = "w1-gpio";
+		gpios = <&gpio 100 0>, <&gpio 101 0>;
+
+		battery {
+			compatible = "maxim,ds2760";
+			power-supplies = <&charger>;
+		};
+	};
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 2/5] dt-bindings: w1: document bindings for ds2760 battery monitor
  2018-07-06  5:35 [PATCH v4 0/5] Add devicetree functionality to w1 busses and ds2760 Daniel Mack
  2018-07-06  5:35 ` [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings Daniel Mack
@ 2018-07-06  5:35 ` Daniel Mack
  2018-07-11 15:02   ` Rob Herring
  2018-07-06  5:35 ` [PATCH v4 3/5] w1: core: match sub-nodes of bus masters in devicetree Daniel Mack
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Daniel Mack @ 2018-07-06  5:35 UTC (permalink / raw)
  To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
  Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik, Daniel Mack

This patch adds the devicetree bindings for Maxim's ds2760 battery
monitors.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 .../bindings/power/supply/maxim,ds2760.txt    | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt

diff --git a/Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt b/Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt
new file mode 100644
index 000000000000..55967a0bee11
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt
@@ -0,0 +1,26 @@
+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-ms:	Time im milliseconds to cache the data for. When
+			this time expires, the values are read again from
+			the hardware. Defaults to 1000.
+- rated-capacity-microamp-hours:
+			The rated capacity of the battery, in mAh.
+			If not specified, the value stored in the
+			non-volatile chip memory is used.
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 3/5] w1: core: match sub-nodes of bus masters in devicetree
  2018-07-06  5:35 [PATCH v4 0/5] Add devicetree functionality to w1 busses and ds2760 Daniel Mack
  2018-07-06  5:35 ` [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings Daniel Mack
  2018-07-06  5:35 ` [PATCH v4 2/5] dt-bindings: w1: document bindings for ds2760 battery monitor Daniel Mack
@ 2018-07-06  5:35 ` Daniel Mack
  2018-07-06 13:52   ` Sebastian Reichel
  2018-07-06  5:35 ` [PATCH v4 4/5] power: supply: ds2760_battery: merge ds2760 supply driver with its w1 slave companion Daniel Mack
  2018-07-06  5:35 ` [PATCH v4 5/5] power: supply: ds2760_battery: add devicetree probing Daniel Mack
  4 siblings, 1 reply; 15+ messages in thread
From: Daniel Mack @ 2018-07-06  5:35 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] 15+ messages in thread

* [PATCH v4 4/5] power: supply: ds2760_battery: merge ds2760 supply driver with its w1 slave companion
  2018-07-06  5:35 [PATCH v4 0/5] Add devicetree functionality to w1 busses and ds2760 Daniel Mack
                   ` (2 preceding siblings ...)
  2018-07-06  5:35 ` [PATCH v4 3/5] w1: core: match sub-nodes of bus masters in devicetree Daniel Mack
@ 2018-07-06  5:35 ` Daniel Mack
  2018-07-06 13:36   ` Sebastian Reichel
  2018-07-06  5:35 ` [PATCH v4 5/5] power: supply: ds2760_battery: add devicetree probing Daniel Mack
  4 siblings, 1 reply; 15+ messages in thread
From: Daniel Mack @ 2018-07-06  5:35 UTC (permalink / raw)
  To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
  Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik, Daniel Mack

This 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.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 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

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index 428b426842f4..518a88c4adfa 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -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.
 
diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c
index ae180dc929c9..aa406a7c65a1 100644
--- a/drivers/power/supply/ds2760_battery.c
+++ b/drivers/power/supply/ds2760_battery.c
@@ -27,9 +27,63 @@
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 #include <linux/power_supply.h>
-
+#include <linux/suspend.h>
 #include <linux/w1.h>
-#include "../../w1/slaves/w1_ds2760.h"
+
+static unsigned int cache_time = 1000;
+module_param(cache_time, uint, 0644);
+MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
+
+static bool pmod_enabled;
+module_param(pmod_enabled, bool, 0644);
+MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
+
+static unsigned int rated_capacity;
+module_param(rated_capacity, uint, 0644);
+MODULE_PARM_DESC(rated_capacity, "rated battery capacity, 10*mAh or index");
+
+static unsigned int current_accum;
+module_param(current_accum, uint, 0644);
+MODULE_PARM_DESC(current_accum, "current accumulator value");
+
+#define W1_FAMILY_DS2760		0x30
+
+/* Known commands to the DS2760 chip */
+#define W1_DS2760_SWAP			0xAA
+#define W1_DS2760_READ_DATA		0x69
+#define W1_DS2760_WRITE_DATA		0x6C
+#define W1_DS2760_COPY_DATA		0x48
+#define W1_DS2760_RECALL_DATA		0xB8
+#define W1_DS2760_LOCK			0x6A
+
+/* Number of valid register addresses */
+#define DS2760_DATA_SIZE		0x40
+
+#define DS2760_PROTECTION_REG		0x00
+
+#define DS2760_STATUS_REG		0x01
+#define DS2760_STATUS_IE		(1 << 2)
+#define DS2760_STATUS_SWEN		(1 << 3)
+#define DS2760_STATUS_RNAOP		(1 << 4)
+#define DS2760_STATUS_PMOD		(1 << 5)
+
+#define DS2760_EEPROM_REG		0x07
+#define DS2760_SPECIAL_FEATURE_REG	0x08
+#define DS2760_VOLTAGE_MSB		0x0c
+#define DS2760_VOLTAGE_LSB		0x0d
+#define DS2760_CURRENT_MSB		0x0e
+#define DS2760_CURRENT_LSB		0x0f
+#define DS2760_CURRENT_ACCUM_MSB	0x10
+#define DS2760_CURRENT_ACCUM_LSB	0x11
+#define DS2760_TEMP_MSB			0x18
+#define DS2760_TEMP_LSB			0x19
+#define DS2760_EEPROM_BLOCK0		0x20
+#define DS2760_ACTIVE_FULL		0x20
+#define DS2760_EEPROM_BLOCK1		0x30
+#define DS2760_STATUS_WRITE_REG		0x31
+#define DS2760_RATED_CAPACITY		0x32
+#define DS2760_CURRENT_OFFSET_BIAS	0x33
+#define DS2760_ACTIVE_EMPTY		0x3b
 
 struct ds2760_device_info {
 	struct device *dev;
@@ -55,28 +109,113 @@ struct ds2760_device_info {
 	int full_counter;
 	struct power_supply *bat;
 	struct power_supply_desc bat_desc;
-	struct device *w1_dev;
 	struct workqueue_struct *monitor_wqueue;
 	struct delayed_work monitor_work;
 	struct delayed_work set_charged_work;
+	struct notifier_block pm_notifier;
 };
 
-static unsigned int cache_time = 1000;
-module_param(cache_time, uint, 0644);
-MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
+static int w1_ds2760_io(struct device *dev, char *buf, int addr, size_t count,
+			int io)
+{
+	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
 
-static bool pmod_enabled;
-module_param(pmod_enabled, bool, 0644);
-MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
+	if (!dev)
+		return 0;
 
-static unsigned int rated_capacity;
-module_param(rated_capacity, uint, 0644);
-MODULE_PARM_DESC(rated_capacity, "rated battery capacity, 10*mAh or index");
+	mutex_lock(&sl->master->bus_mutex);
 
-static unsigned int current_accum;
-module_param(current_accum, uint, 0644);
-MODULE_PARM_DESC(current_accum, "current accumulator value");
+	if (addr > DS2760_DATA_SIZE || addr < 0) {
+		count = 0;
+		goto out;
+	}
+	if (addr + count > DS2760_DATA_SIZE)
+		count = DS2760_DATA_SIZE - addr;
+
+	if (!w1_reset_select_slave(sl)) {
+		if (!io) {
+			w1_write_8(sl->master, W1_DS2760_READ_DATA);
+			w1_write_8(sl->master, addr);
+			count = w1_read_block(sl->master, buf, count);
+		} else {
+			w1_write_8(sl->master, W1_DS2760_WRITE_DATA);
+			w1_write_8(sl->master, addr);
+			w1_write_block(sl->master, buf, count);
+			/* XXX w1_write_block returns void, not n_written */
+		}
+	}
+
+out:
+	mutex_unlock(&sl->master->bus_mutex);
+
+	return count;
+}
+
+static int w1_ds2760_read(struct device *dev,
+			  char *buf, int addr,
+			  size_t count)
+{
+	return w1_ds2760_io(dev, buf, addr, count, 0);
+}
+
+static int w1_ds2760_write(struct device *dev,
+			   char *buf,
+			   int addr, size_t count)
+{
+	return w1_ds2760_io(dev, buf, addr, count, 1);
+}
 
+static int w1_ds2760_eeprom_cmd(struct device *dev, int addr, int cmd)
+{
+	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
+
+	if (!dev)
+		return -EINVAL;
+
+	mutex_lock(&sl->master->bus_mutex);
+
+	if (w1_reset_select_slave(sl) == 0) {
+		w1_write_8(sl->master, cmd);
+		w1_write_8(sl->master, addr);
+	}
+
+	mutex_unlock(&sl->master->bus_mutex);
+	return 0;
+}
+
+static int w1_ds2760_store_eeprom(struct device *dev, int addr)
+{
+	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_COPY_DATA);
+}
+
+static int w1_ds2760_recall_eeprom(struct device *dev, int addr)
+{
+	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_RECALL_DATA);
+}
+
+static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj,
+			     struct bin_attribute *bin_attr, char *buf,
+			     loff_t off, size_t count)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	return w1_ds2760_read(dev, buf, off, count);
+}
+
+static BIN_ATTR_RO(w1_slave, DS2760_DATA_SIZE);
+
+static struct bin_attribute *w1_ds2760_bin_attrs[] = {
+	&bin_attr_w1_slave,
+	NULL,
+};
+
+static const struct attribute_group w1_ds2760_group = {
+	.bin_attrs = w1_ds2760_bin_attrs,
+};
+
+static const struct attribute_group *w1_ds2760_groups[] = {
+	&w1_ds2760_group,
+	NULL,
+};
 /* Some batteries have their rated capacity stored a N * 10 mAh, while
  * others use an index into this table. */
 static int rated_capacities[] = {
@@ -138,10 +277,10 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)
 		count = DS2760_TEMP_LSB - start + 1;
 	}
 
-	ret = w1_ds2760_read(di->w1_dev, di->raw + start, start, count);
+	ret = w1_ds2760_read(di->dev, di->raw + start, start, count);
 	if (ret != count) {
 		dev_warn(di->dev, "call to w1_ds2760_read failed (0x%p)\n",
-			 di->w1_dev);
+			 di->dev);
 		return 1;
 	}
 
@@ -242,7 +381,7 @@ static void ds2760_battery_set_current_accum(struct ds2760_device_info *di,
 	acr[0] = acr_val >> 8;
 	acr[1] = acr_val & 0xff;
 
-	if (w1_ds2760_write(di->w1_dev, acr, DS2760_CURRENT_ACCUM_MSB, 2) < 2)
+	if (w1_ds2760_write(di->dev, acr, DS2760_CURRENT_ACCUM_MSB, 2) < 2)
 		dev_warn(di->dev, "ACR write failed\n");
 }
 
@@ -297,9 +436,9 @@ static void ds2760_battery_write_status(struct ds2760_device_info *di,
 	if (status == di->raw[DS2760_STATUS_REG])
 		return;
 
-	w1_ds2760_write(di->w1_dev, &status, DS2760_STATUS_WRITE_REG, 1);
-	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
-	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
+	w1_ds2760_write(di->dev, &status, DS2760_STATUS_WRITE_REG, 1);
+	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
+	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
 }
 
 static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di,
@@ -308,9 +447,9 @@ static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di,
 	if (rated_capacity == di->raw[DS2760_RATED_CAPACITY])
 		return;
 
-	w1_ds2760_write(di->w1_dev, &rated_capacity, DS2760_RATED_CAPACITY, 1);
-	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
-	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
+	w1_ds2760_write(di->dev, &rated_capacity, DS2760_RATED_CAPACITY, 1);
+	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
+	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
 }
 
 static void ds2760_battery_write_active_full(struct ds2760_device_info *di,
@@ -325,9 +464,9 @@ static void ds2760_battery_write_active_full(struct ds2760_device_info *di,
 	    tmp[1] == di->raw[DS2760_ACTIVE_FULL + 1])
 		return;
 
-	w1_ds2760_write(di->w1_dev, tmp, DS2760_ACTIVE_FULL, sizeof(tmp));
-	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK0);
-	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK0);
+	w1_ds2760_write(di->dev, tmp, DS2760_ACTIVE_FULL, sizeof(tmp));
+	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK0);
+	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK0);
 
 	/* Write to the di->raw[] buffer directly - the DS2760_ACTIVE_FULL
 	 * values won't be read back by ds2760_battery_read_status() */
@@ -383,9 +522,9 @@ static void ds2760_battery_set_charged_work(struct work_struct *work)
 
 	dev_dbg(di->dev, "%s: bias = %d\n", __func__, bias);
 
-	w1_ds2760_write(di->w1_dev, &bias, DS2760_CURRENT_OFFSET_BIAS, 1);
-	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
-	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
+	w1_ds2760_write(di->dev, &bias, DS2760_CURRENT_OFFSET_BIAS, 1);
+	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
+	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
 
 	/* Write to the di->raw[] buffer directly - the CURRENT_OFFSET_BIAS
 	 * value won't be read back by ds2760_battery_read_status() */
@@ -504,24 +643,55 @@ static enum power_supply_property ds2760_battery_props[] = {
 	POWER_SUPPLY_PROP_CAPACITY,
 };
 
-static int ds2760_battery_probe(struct platform_device *pdev)
+static int ds2760_pm_notifier(struct notifier_block *notifier,
+			      unsigned long pm_event,
+			      void *unused)
+{
+	struct ds2760_device_info *di =
+		container_of(notifier, struct ds2760_device_info, pm_notifier);
+
+	switch (pm_event) {
+	case PM_HIBERNATION_PREPARE:
+	case PM_SUSPEND_PREPARE:
+		di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
+		break;
+
+	case PM_POST_RESTORE:
+	case PM_POST_HIBERNATION:
+	case PM_POST_SUSPEND:
+		di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
+		power_supply_changed(di->bat);
+		mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
+
+		break;
+
+	case PM_RESTORE_PREPARE:
+	default:
+		break;
+	}
+
+	return NOTIFY_DONE;
+}
+
+static int w1_ds2760_add_slave(struct w1_slave *sl)
 {
 	struct power_supply_config psy_cfg = {};
-	char status;
-	int retval = 0;
 	struct ds2760_device_info *di;
+	struct device *dev = &sl->dev;
+	int retval = 0;
+	char name[32];
+	char status;
 
-	di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
+	di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL);
 	if (!di) {
 		retval = -ENOMEM;
 		goto di_alloc_failed;
 	}
 
-	platform_set_drvdata(pdev, di);
+	snprintf(name, sizeof(name), "ds2760-battery.%d", dev->id);
 
-	di->dev				= &pdev->dev;
-	di->w1_dev			= pdev->dev.parent;
-	di->bat_desc.name		= dev_name(&pdev->dev);
+	di->dev				= dev;
+	di->bat_desc.name		= name;
 	di->bat_desc.type		= POWER_SUPPLY_TYPE_BATTERY;
 	di->bat_desc.properties		= ds2760_battery_props;
 	di->bat_desc.num_properties	= ARRAY_SIZE(ds2760_battery_props);
@@ -533,10 +703,12 @@ static int ds2760_battery_probe(struct platform_device *pdev)
 	di->bat_desc.external_power_changed =
 				  ds2760_battery_external_power_changed;
 
-	psy_cfg.drv_data		= di;
+	psy_cfg.drv_data = di;
 
 	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
 
+	sl->family_data = di;
+
 	/* enable sleep mode feature */
 	ds2760_battery_read_status(di);
 	status = di->raw[DS2760_STATUS_REG];
@@ -556,7 +728,7 @@ static int ds2760_battery_probe(struct platform_device *pdev)
 	if (current_accum)
 		ds2760_battery_set_current_accum(di, current_accum);
 
-	di->bat = power_supply_register(&pdev->dev, &di->bat_desc, &psy_cfg);
+	di->bat = power_supply_register(dev, &di->bat_desc, &psy_cfg);
 	if (IS_ERR(di->bat)) {
 		dev_err(di->dev, "failed to register battery\n");
 		retval = PTR_ERR(di->bat);
@@ -566,14 +738,16 @@ static int ds2760_battery_probe(struct platform_device *pdev)
 	INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work);
 	INIT_DELAYED_WORK(&di->set_charged_work,
 			  ds2760_battery_set_charged_work);
-	di->monitor_wqueue = alloc_ordered_workqueue(dev_name(&pdev->dev),
-						     WQ_MEM_RECLAIM);
+	di->monitor_wqueue = alloc_ordered_workqueue(name, WQ_MEM_RECLAIM);
 	if (!di->monitor_wqueue) {
 		retval = -ESRCH;
 		goto workqueue_failed;
 	}
 	queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ * 1);
 
+	di->pm_notifier.notifier_call = ds2760_pm_notifier;
+	register_pm_notifier(&di->pm_notifier);
+
 	goto success;
 
 workqueue_failed:
@@ -584,65 +758,32 @@ static int ds2760_battery_probe(struct platform_device *pdev)
 	return retval;
 }
 
-static int ds2760_battery_remove(struct platform_device *pdev)
+static void w1_ds2760_remove_slave(struct w1_slave *sl)
 {
-	struct ds2760_device_info *di = platform_get_drvdata(pdev);
+	struct ds2760_device_info *di = sl->family_data;
 
+	unregister_pm_notifier(&di->pm_notifier);
 	cancel_delayed_work_sync(&di->monitor_work);
 	cancel_delayed_work_sync(&di->set_charged_work);
 	destroy_workqueue(di->monitor_wqueue);
 	power_supply_unregister(di->bat);
-
-	return 0;
-}
-
-#ifdef CONFIG_PM
-
-static int ds2760_battery_suspend(struct platform_device *pdev,
-				  pm_message_t state)
-{
-	struct ds2760_device_info *di = platform_get_drvdata(pdev);
-
-	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
-
-	return 0;
-}
-
-static int ds2760_battery_resume(struct platform_device *pdev)
-{
-	struct ds2760_device_info *di = platform_get_drvdata(pdev);
-
-	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
-	power_supply_changed(di->bat);
-
-	mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
-
-	return 0;
 }
 
-#else
-
-#define ds2760_battery_suspend NULL
-#define ds2760_battery_resume NULL
-
-#endif /* CONFIG_PM */
-
-MODULE_ALIAS("platform:ds2760-battery");
-
-static struct platform_driver ds2760_battery_driver = {
-	.driver = {
-		.name = "ds2760-battery",
-	},
-	.probe	  = ds2760_battery_probe,
-	.remove   = ds2760_battery_remove,
-	.suspend  = ds2760_battery_suspend,
-	.resume	  = ds2760_battery_resume,
+static struct w1_family_ops w1_ds2760_fops = {
+	.add_slave	= w1_ds2760_add_slave,
+	.remove_slave	= w1_ds2760_remove_slave,
+	.groups		= w1_ds2760_groups,
 };
 
-module_platform_driver(ds2760_battery_driver);
+static struct w1_family w1_ds2760_family = {
+	.fid		= W1_FAMILY_DS2760,
+	.fops		= &w1_ds2760_fops,
+};
+module_w1_family(w1_ds2760_family);
 
-MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>, "
 	      "Matt Reimer <mreimer@vpop.net>, "
 	      "Anton Vorontsov <cbou@mail.ru>");
-MODULE_DESCRIPTION("ds2760 battery driver");
+MODULE_DESCRIPTION("1-wire Driver Dallas 2760 battery monitor chip");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2760));
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
index 7931231d8e80..e22fdeddada1 100644
--- a/drivers/w1/slaves/Kconfig
+++ b/drivers/w1/slaves/Kconfig
@@ -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
diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile
index d5f4f4d5b9e5..eab29f151413 100644
--- a/drivers/w1/slaves/Makefile
+++ b/drivers/w1/slaves/Makefile
@@ -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
diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c
deleted file mode 100644
index 26168abfb8b8..000000000000
--- a/drivers/w1/slaves/w1_ds2760.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * 1-Wire implementation for the ds2760 chip
- *
- * Copyright © 2004-2005, Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
- *
- * Use consistent with the GNU GPL is permitted,
- * provided that this copyright notice is
- * preserved in its entirety in all copies and derived works.
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/device.h>
-#include <linux/types.h>
-#include <linux/platform_device.h>
-#include <linux/mutex.h>
-#include <linux/idr.h>
-#include <linux/gfp.h>
-
-#include <linux/w1.h>
-
-#include "w1_ds2760.h"
-
-#define W1_FAMILY_DS2760	0x30
-
-static int w1_ds2760_io(struct device *dev, char *buf, int addr, size_t count,
-			int io)
-{
-	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
-
-	if (!dev)
-		return 0;
-
-	mutex_lock(&sl->master->bus_mutex);
-
-	if (addr > DS2760_DATA_SIZE || addr < 0) {
-		count = 0;
-		goto out;
-	}
-	if (addr + count > DS2760_DATA_SIZE)
-		count = DS2760_DATA_SIZE - addr;
-
-	if (!w1_reset_select_slave(sl)) {
-		if (!io) {
-			w1_write_8(sl->master, W1_DS2760_READ_DATA);
-			w1_write_8(sl->master, addr);
-			count = w1_read_block(sl->master, buf, count);
-		} else {
-			w1_write_8(sl->master, W1_DS2760_WRITE_DATA);
-			w1_write_8(sl->master, addr);
-			w1_write_block(sl->master, buf, count);
-			/* XXX w1_write_block returns void, not n_written */
-		}
-	}
-
-out:
-	mutex_unlock(&sl->master->bus_mutex);
-
-	return count;
-}
-
-int w1_ds2760_read(struct device *dev, char *buf, int addr, size_t count)
-{
-	return w1_ds2760_io(dev, buf, addr, count, 0);
-}
-EXPORT_SYMBOL(w1_ds2760_read);
-
-int w1_ds2760_write(struct device *dev, char *buf, int addr, size_t count)
-{
-	return w1_ds2760_io(dev, buf, addr, count, 1);
-}
-EXPORT_SYMBOL(w1_ds2760_write);
-
-static int w1_ds2760_eeprom_cmd(struct device *dev, int addr, int cmd)
-{
-	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
-
-	if (!dev)
-		return -EINVAL;
-
-	mutex_lock(&sl->master->bus_mutex);
-
-	if (w1_reset_select_slave(sl) == 0) {
-		w1_write_8(sl->master, cmd);
-		w1_write_8(sl->master, addr);
-	}
-
-	mutex_unlock(&sl->master->bus_mutex);
-	return 0;
-}
-
-int w1_ds2760_store_eeprom(struct device *dev, int addr)
-{
-	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_COPY_DATA);
-}
-EXPORT_SYMBOL(w1_ds2760_store_eeprom);
-
-int w1_ds2760_recall_eeprom(struct device *dev, int addr)
-{
-	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_RECALL_DATA);
-}
-EXPORT_SYMBOL(w1_ds2760_recall_eeprom);
-
-static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj,
-			     struct bin_attribute *bin_attr, char *buf,
-			     loff_t off, size_t count)
-{
-	struct device *dev = container_of(kobj, struct device, kobj);
-	return w1_ds2760_read(dev, buf, off, count);
-}
-
-static BIN_ATTR_RO(w1_slave, DS2760_DATA_SIZE);
-
-static struct bin_attribute *w1_ds2760_bin_attrs[] = {
-	&bin_attr_w1_slave,
-	NULL,
-};
-
-static const struct attribute_group w1_ds2760_group = {
-	.bin_attrs = w1_ds2760_bin_attrs,
-};
-
-static const struct attribute_group *w1_ds2760_groups[] = {
-	&w1_ds2760_group,
-	NULL,
-};
-
-static int w1_ds2760_add_slave(struct w1_slave *sl)
-{
-	int ret;
-	struct platform_device *pdev;
-
-	pdev = platform_device_alloc("ds2760-battery", PLATFORM_DEVID_AUTO);
-	if (!pdev)
-		return -ENOMEM;
-	pdev->dev.parent = &sl->dev;
-
-	ret = platform_device_add(pdev);
-	if (ret)
-		goto pdev_add_failed;
-
-	dev_set_drvdata(&sl->dev, pdev);
-
-	return 0;
-
-pdev_add_failed:
-	platform_device_put(pdev);
-
-	return ret;
-}
-
-static void w1_ds2760_remove_slave(struct w1_slave *sl)
-{
-	struct platform_device *pdev = dev_get_drvdata(&sl->dev);
-
-	platform_device_unregister(pdev);
-}
-
-static struct w1_family_ops w1_ds2760_fops = {
-	.add_slave    = w1_ds2760_add_slave,
-	.remove_slave = w1_ds2760_remove_slave,
-	.groups       = w1_ds2760_groups,
-};
-
-static struct w1_family w1_ds2760_family = {
-	.fid = W1_FAMILY_DS2760,
-	.fops = &w1_ds2760_fops,
-};
-module_w1_family(w1_ds2760_family);
-
-MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>");
-MODULE_DESCRIPTION("1-wire Driver Dallas 2760 battery monitor chip");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2760));
diff --git a/drivers/w1/slaves/w1_ds2760.h b/drivers/w1/slaves/w1_ds2760.h
deleted file mode 100644
index 24168c94eeae..000000000000
--- a/drivers/w1/slaves/w1_ds2760.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 1-Wire implementation for the ds2760 chip
- *
- * Copyright © 2004-2005, Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
- *
- * Use consistent with the GNU GPL is permitted,
- * provided that this copyright notice is
- * preserved in its entirety in all copies and derived works.
- *
- */
-
-#ifndef __w1_ds2760_h__
-#define __w1_ds2760_h__
-
-/* Known commands to the DS2760 chip */
-#define W1_DS2760_SWAP			0xAA
-#define W1_DS2760_READ_DATA		0x69
-#define W1_DS2760_WRITE_DATA		0x6C
-#define W1_DS2760_COPY_DATA		0x48
-#define W1_DS2760_RECALL_DATA		0xB8
-#define W1_DS2760_LOCK			0x6A
-
-/* Number of valid register addresses */
-#define DS2760_DATA_SIZE		0x40
-
-#define DS2760_PROTECTION_REG		0x00
-
-#define DS2760_STATUS_REG		0x01
-#define DS2760_STATUS_IE		(1 << 2)
-#define DS2760_STATUS_SWEN		(1 << 3)
-#define DS2760_STATUS_RNAOP		(1 << 4)
-#define DS2760_STATUS_PMOD		(1 << 5)
-
-#define DS2760_EEPROM_REG		0x07
-#define DS2760_SPECIAL_FEATURE_REG	0x08
-#define DS2760_VOLTAGE_MSB		0x0c
-#define DS2760_VOLTAGE_LSB		0x0d
-#define DS2760_CURRENT_MSB		0x0e
-#define DS2760_CURRENT_LSB		0x0f
-#define DS2760_CURRENT_ACCUM_MSB	0x10
-#define DS2760_CURRENT_ACCUM_LSB	0x11
-#define DS2760_TEMP_MSB			0x18
-#define DS2760_TEMP_LSB			0x19
-#define DS2760_EEPROM_BLOCK0		0x20
-#define DS2760_ACTIVE_FULL		0x20
-#define DS2760_EEPROM_BLOCK1		0x30
-#define DS2760_STATUS_WRITE_REG		0x31
-#define DS2760_RATED_CAPACITY		0x32
-#define DS2760_CURRENT_OFFSET_BIAS	0x33
-#define DS2760_ACTIVE_EMPTY		0x3b
-
-extern int w1_ds2760_read(struct device *dev, char *buf, int addr,
-			  size_t count);
-extern int w1_ds2760_write(struct device *dev, char *buf, int addr,
-			   size_t count);
-extern int w1_ds2760_store_eeprom(struct device *dev, int addr);
-extern int w1_ds2760_recall_eeprom(struct device *dev, int addr);
-
-#endif /* !__w1_ds2760_h__ */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 5/5] power: supply: ds2760_battery: add devicetree probing
  2018-07-06  5:35 [PATCH v4 0/5] Add devicetree functionality to w1 busses and ds2760 Daniel Mack
                   ` (3 preceding siblings ...)
  2018-07-06  5:35 ` [PATCH v4 4/5] power: supply: ds2760_battery: merge ds2760 supply driver with its w1 slave companion Daniel Mack
@ 2018-07-06  5:35 ` Daniel Mack
  2018-07-06 13:43   ` Sebastian Reichel
  4 siblings, 1 reply; 15+ messages in thread
From: Daniel Mack @ 2018-07-06  5:35 UTC (permalink / raw)
  To: zbr, robh+dt, mark.rutland, szabolcs.gyurko
  Cc: sre, devicetree, linux-kernel, linux-pm, robert.jarzmik, Daniel Mack

Add a matching table for devicetree probing, and optionally set the module
parameter variables from DT properties.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 drivers/power/supply/ds2760_battery.c | 29 ++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c
index aa406a7c65a1..11bed88a89fa 100644
--- a/drivers/power/supply/ds2760_battery.c
+++ b/drivers/power/supply/ds2760_battery.c
@@ -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,24 @@ 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-ms", &tmp))
+			cache_time = tmp;
+
+		if (!of_property_read_u32(dev->of_node,
+					  "rated-capacity-microamp-hours",
+					  &tmp))
+			rated_capacity = tmp / 10; /* property is in mAh */
+	}
+
 	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
 
 	sl->family_data = di;
@@ -719,7 +738,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 +788,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 +804,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] 15+ messages in thread

* Re: [PATCH v4 4/5] power: supply: ds2760_battery: merge ds2760 supply driver with its w1 slave companion
  2018-07-06  5:35 ` [PATCH v4 4/5] power: supply: ds2760_battery: merge ds2760 supply driver with its w1 slave companion Daniel Mack
@ 2018-07-06 13:36   ` Sebastian Reichel
  0 siblings, 0 replies; 15+ messages in thread
From: Sebastian Reichel @ 2018-07-06 13:36 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: 26210 bytes --]

Hi,

On Fri, Jul 06, 2018 at 07:35:51AM +0200, Daniel Mack wrote:
> This 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.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---

Acked-for-power-supply: Sebastian Reichel <sebastian.reichel@collabora.co.uk>

-- Sebastian

>  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
> 
> diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
> index 428b426842f4..518a88c4adfa 100644
> --- a/drivers/power/supply/Kconfig
> +++ b/drivers/power/supply/Kconfig
> @@ -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.
>  
> diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c
> index ae180dc929c9..aa406a7c65a1 100644
> --- a/drivers/power/supply/ds2760_battery.c
> +++ b/drivers/power/supply/ds2760_battery.c
> @@ -27,9 +27,63 @@
>  #include <linux/slab.h>
>  #include <linux/platform_device.h>
>  #include <linux/power_supply.h>
> -
> +#include <linux/suspend.h>
>  #include <linux/w1.h>
> -#include "../../w1/slaves/w1_ds2760.h"
> +
> +static unsigned int cache_time = 1000;
> +module_param(cache_time, uint, 0644);
> +MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
> +
> +static bool pmod_enabled;
> +module_param(pmod_enabled, bool, 0644);
> +MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
> +
> +static unsigned int rated_capacity;
> +module_param(rated_capacity, uint, 0644);
> +MODULE_PARM_DESC(rated_capacity, "rated battery capacity, 10*mAh or index");
> +
> +static unsigned int current_accum;
> +module_param(current_accum, uint, 0644);
> +MODULE_PARM_DESC(current_accum, "current accumulator value");
> +
> +#define W1_FAMILY_DS2760		0x30
> +
> +/* Known commands to the DS2760 chip */
> +#define W1_DS2760_SWAP			0xAA
> +#define W1_DS2760_READ_DATA		0x69
> +#define W1_DS2760_WRITE_DATA		0x6C
> +#define W1_DS2760_COPY_DATA		0x48
> +#define W1_DS2760_RECALL_DATA		0xB8
> +#define W1_DS2760_LOCK			0x6A
> +
> +/* Number of valid register addresses */
> +#define DS2760_DATA_SIZE		0x40
> +
> +#define DS2760_PROTECTION_REG		0x00
> +
> +#define DS2760_STATUS_REG		0x01
> +#define DS2760_STATUS_IE		(1 << 2)
> +#define DS2760_STATUS_SWEN		(1 << 3)
> +#define DS2760_STATUS_RNAOP		(1 << 4)
> +#define DS2760_STATUS_PMOD		(1 << 5)
> +
> +#define DS2760_EEPROM_REG		0x07
> +#define DS2760_SPECIAL_FEATURE_REG	0x08
> +#define DS2760_VOLTAGE_MSB		0x0c
> +#define DS2760_VOLTAGE_LSB		0x0d
> +#define DS2760_CURRENT_MSB		0x0e
> +#define DS2760_CURRENT_LSB		0x0f
> +#define DS2760_CURRENT_ACCUM_MSB	0x10
> +#define DS2760_CURRENT_ACCUM_LSB	0x11
> +#define DS2760_TEMP_MSB			0x18
> +#define DS2760_TEMP_LSB			0x19
> +#define DS2760_EEPROM_BLOCK0		0x20
> +#define DS2760_ACTIVE_FULL		0x20
> +#define DS2760_EEPROM_BLOCK1		0x30
> +#define DS2760_STATUS_WRITE_REG		0x31
> +#define DS2760_RATED_CAPACITY		0x32
> +#define DS2760_CURRENT_OFFSET_BIAS	0x33
> +#define DS2760_ACTIVE_EMPTY		0x3b
>  
>  struct ds2760_device_info {
>  	struct device *dev;
> @@ -55,28 +109,113 @@ struct ds2760_device_info {
>  	int full_counter;
>  	struct power_supply *bat;
>  	struct power_supply_desc bat_desc;
> -	struct device *w1_dev;
>  	struct workqueue_struct *monitor_wqueue;
>  	struct delayed_work monitor_work;
>  	struct delayed_work set_charged_work;
> +	struct notifier_block pm_notifier;
>  };
>  
> -static unsigned int cache_time = 1000;
> -module_param(cache_time, uint, 0644);
> -MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
> +static int w1_ds2760_io(struct device *dev, char *buf, int addr, size_t count,
> +			int io)
> +{
> +	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
>  
> -static bool pmod_enabled;
> -module_param(pmod_enabled, bool, 0644);
> -MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
> +	if (!dev)
> +		return 0;
>  
> -static unsigned int rated_capacity;
> -module_param(rated_capacity, uint, 0644);
> -MODULE_PARM_DESC(rated_capacity, "rated battery capacity, 10*mAh or index");
> +	mutex_lock(&sl->master->bus_mutex);
>  
> -static unsigned int current_accum;
> -module_param(current_accum, uint, 0644);
> -MODULE_PARM_DESC(current_accum, "current accumulator value");
> +	if (addr > DS2760_DATA_SIZE || addr < 0) {
> +		count = 0;
> +		goto out;
> +	}
> +	if (addr + count > DS2760_DATA_SIZE)
> +		count = DS2760_DATA_SIZE - addr;
> +
> +	if (!w1_reset_select_slave(sl)) {
> +		if (!io) {
> +			w1_write_8(sl->master, W1_DS2760_READ_DATA);
> +			w1_write_8(sl->master, addr);
> +			count = w1_read_block(sl->master, buf, count);
> +		} else {
> +			w1_write_8(sl->master, W1_DS2760_WRITE_DATA);
> +			w1_write_8(sl->master, addr);
> +			w1_write_block(sl->master, buf, count);
> +			/* XXX w1_write_block returns void, not n_written */
> +		}
> +	}
> +
> +out:
> +	mutex_unlock(&sl->master->bus_mutex);
> +
> +	return count;
> +}
> +
> +static int w1_ds2760_read(struct device *dev,
> +			  char *buf, int addr,
> +			  size_t count)
> +{
> +	return w1_ds2760_io(dev, buf, addr, count, 0);
> +}
> +
> +static int w1_ds2760_write(struct device *dev,
> +			   char *buf,
> +			   int addr, size_t count)
> +{
> +	return w1_ds2760_io(dev, buf, addr, count, 1);
> +}
>  
> +static int w1_ds2760_eeprom_cmd(struct device *dev, int addr, int cmd)
> +{
> +	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
> +
> +	if (!dev)
> +		return -EINVAL;
> +
> +	mutex_lock(&sl->master->bus_mutex);
> +
> +	if (w1_reset_select_slave(sl) == 0) {
> +		w1_write_8(sl->master, cmd);
> +		w1_write_8(sl->master, addr);
> +	}
> +
> +	mutex_unlock(&sl->master->bus_mutex);
> +	return 0;
> +}
> +
> +static int w1_ds2760_store_eeprom(struct device *dev, int addr)
> +{
> +	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_COPY_DATA);
> +}
> +
> +static int w1_ds2760_recall_eeprom(struct device *dev, int addr)
> +{
> +	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_RECALL_DATA);
> +}
> +
> +static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj,
> +			     struct bin_attribute *bin_attr, char *buf,
> +			     loff_t off, size_t count)
> +{
> +	struct device *dev = container_of(kobj, struct device, kobj);
> +	return w1_ds2760_read(dev, buf, off, count);
> +}
> +
> +static BIN_ATTR_RO(w1_slave, DS2760_DATA_SIZE);
> +
> +static struct bin_attribute *w1_ds2760_bin_attrs[] = {
> +	&bin_attr_w1_slave,
> +	NULL,
> +};
> +
> +static const struct attribute_group w1_ds2760_group = {
> +	.bin_attrs = w1_ds2760_bin_attrs,
> +};
> +
> +static const struct attribute_group *w1_ds2760_groups[] = {
> +	&w1_ds2760_group,
> +	NULL,
> +};
>  /* Some batteries have their rated capacity stored a N * 10 mAh, while
>   * others use an index into this table. */
>  static int rated_capacities[] = {
> @@ -138,10 +277,10 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)
>  		count = DS2760_TEMP_LSB - start + 1;
>  	}
>  
> -	ret = w1_ds2760_read(di->w1_dev, di->raw + start, start, count);
> +	ret = w1_ds2760_read(di->dev, di->raw + start, start, count);
>  	if (ret != count) {
>  		dev_warn(di->dev, "call to w1_ds2760_read failed (0x%p)\n",
> -			 di->w1_dev);
> +			 di->dev);
>  		return 1;
>  	}
>  
> @@ -242,7 +381,7 @@ static void ds2760_battery_set_current_accum(struct ds2760_device_info *di,
>  	acr[0] = acr_val >> 8;
>  	acr[1] = acr_val & 0xff;
>  
> -	if (w1_ds2760_write(di->w1_dev, acr, DS2760_CURRENT_ACCUM_MSB, 2) < 2)
> +	if (w1_ds2760_write(di->dev, acr, DS2760_CURRENT_ACCUM_MSB, 2) < 2)
>  		dev_warn(di->dev, "ACR write failed\n");
>  }
>  
> @@ -297,9 +436,9 @@ static void ds2760_battery_write_status(struct ds2760_device_info *di,
>  	if (status == di->raw[DS2760_STATUS_REG])
>  		return;
>  
> -	w1_ds2760_write(di->w1_dev, &status, DS2760_STATUS_WRITE_REG, 1);
> -	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
> -	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
> +	w1_ds2760_write(di->dev, &status, DS2760_STATUS_WRITE_REG, 1);
> +	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
> +	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
>  }
>  
>  static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di,
> @@ -308,9 +447,9 @@ static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di,
>  	if (rated_capacity == di->raw[DS2760_RATED_CAPACITY])
>  		return;
>  
> -	w1_ds2760_write(di->w1_dev, &rated_capacity, DS2760_RATED_CAPACITY, 1);
> -	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
> -	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
> +	w1_ds2760_write(di->dev, &rated_capacity, DS2760_RATED_CAPACITY, 1);
> +	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
> +	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
>  }
>  
>  static void ds2760_battery_write_active_full(struct ds2760_device_info *di,
> @@ -325,9 +464,9 @@ static void ds2760_battery_write_active_full(struct ds2760_device_info *di,
>  	    tmp[1] == di->raw[DS2760_ACTIVE_FULL + 1])
>  		return;
>  
> -	w1_ds2760_write(di->w1_dev, tmp, DS2760_ACTIVE_FULL, sizeof(tmp));
> -	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK0);
> -	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK0);
> +	w1_ds2760_write(di->dev, tmp, DS2760_ACTIVE_FULL, sizeof(tmp));
> +	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK0);
> +	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK0);
>  
>  	/* Write to the di->raw[] buffer directly - the DS2760_ACTIVE_FULL
>  	 * values won't be read back by ds2760_battery_read_status() */
> @@ -383,9 +522,9 @@ static void ds2760_battery_set_charged_work(struct work_struct *work)
>  
>  	dev_dbg(di->dev, "%s: bias = %d\n", __func__, bias);
>  
> -	w1_ds2760_write(di->w1_dev, &bias, DS2760_CURRENT_OFFSET_BIAS, 1);
> -	w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
> -	w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
> +	w1_ds2760_write(di->dev, &bias, DS2760_CURRENT_OFFSET_BIAS, 1);
> +	w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
> +	w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1);
>  
>  	/* Write to the di->raw[] buffer directly - the CURRENT_OFFSET_BIAS
>  	 * value won't be read back by ds2760_battery_read_status() */
> @@ -504,24 +643,55 @@ static enum power_supply_property ds2760_battery_props[] = {
>  	POWER_SUPPLY_PROP_CAPACITY,
>  };
>  
> -static int ds2760_battery_probe(struct platform_device *pdev)
> +static int ds2760_pm_notifier(struct notifier_block *notifier,
> +			      unsigned long pm_event,
> +			      void *unused)
> +{
> +	struct ds2760_device_info *di =
> +		container_of(notifier, struct ds2760_device_info, pm_notifier);
> +
> +	switch (pm_event) {
> +	case PM_HIBERNATION_PREPARE:
> +	case PM_SUSPEND_PREPARE:
> +		di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
> +		break;
> +
> +	case PM_POST_RESTORE:
> +	case PM_POST_HIBERNATION:
> +	case PM_POST_SUSPEND:
> +		di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
> +		power_supply_changed(di->bat);
> +		mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
> +
> +		break;
> +
> +	case PM_RESTORE_PREPARE:
> +	default:
> +		break;
> +	}
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static int w1_ds2760_add_slave(struct w1_slave *sl)
>  {
>  	struct power_supply_config psy_cfg = {};
> -	char status;
> -	int retval = 0;
>  	struct ds2760_device_info *di;
> +	struct device *dev = &sl->dev;
> +	int retval = 0;
> +	char name[32];
> +	char status;
>  
> -	di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
> +	di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL);
>  	if (!di) {
>  		retval = -ENOMEM;
>  		goto di_alloc_failed;
>  	}
>  
> -	platform_set_drvdata(pdev, di);
> +	snprintf(name, sizeof(name), "ds2760-battery.%d", dev->id);
>  
> -	di->dev				= &pdev->dev;
> -	di->w1_dev			= pdev->dev.parent;
> -	di->bat_desc.name		= dev_name(&pdev->dev);
> +	di->dev				= dev;
> +	di->bat_desc.name		= name;
>  	di->bat_desc.type		= POWER_SUPPLY_TYPE_BATTERY;
>  	di->bat_desc.properties		= ds2760_battery_props;
>  	di->bat_desc.num_properties	= ARRAY_SIZE(ds2760_battery_props);
> @@ -533,10 +703,12 @@ static int ds2760_battery_probe(struct platform_device *pdev)
>  	di->bat_desc.external_power_changed =
>  				  ds2760_battery_external_power_changed;
>  
> -	psy_cfg.drv_data		= di;
> +	psy_cfg.drv_data = di;
>  
>  	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
>  
> +	sl->family_data = di;
> +
>  	/* enable sleep mode feature */
>  	ds2760_battery_read_status(di);
>  	status = di->raw[DS2760_STATUS_REG];
> @@ -556,7 +728,7 @@ static int ds2760_battery_probe(struct platform_device *pdev)
>  	if (current_accum)
>  		ds2760_battery_set_current_accum(di, current_accum);
>  
> -	di->bat = power_supply_register(&pdev->dev, &di->bat_desc, &psy_cfg);
> +	di->bat = power_supply_register(dev, &di->bat_desc, &psy_cfg);
>  	if (IS_ERR(di->bat)) {
>  		dev_err(di->dev, "failed to register battery\n");
>  		retval = PTR_ERR(di->bat);
> @@ -566,14 +738,16 @@ static int ds2760_battery_probe(struct platform_device *pdev)
>  	INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work);
>  	INIT_DELAYED_WORK(&di->set_charged_work,
>  			  ds2760_battery_set_charged_work);
> -	di->monitor_wqueue = alloc_ordered_workqueue(dev_name(&pdev->dev),
> -						     WQ_MEM_RECLAIM);
> +	di->monitor_wqueue = alloc_ordered_workqueue(name, WQ_MEM_RECLAIM);
>  	if (!di->monitor_wqueue) {
>  		retval = -ESRCH;
>  		goto workqueue_failed;
>  	}
>  	queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ * 1);
>  
> +	di->pm_notifier.notifier_call = ds2760_pm_notifier;
> +	register_pm_notifier(&di->pm_notifier);
> +
>  	goto success;
>  
>  workqueue_failed:
> @@ -584,65 +758,32 @@ static int ds2760_battery_probe(struct platform_device *pdev)
>  	return retval;
>  }
>  
> -static int ds2760_battery_remove(struct platform_device *pdev)
> +static void w1_ds2760_remove_slave(struct w1_slave *sl)
>  {
> -	struct ds2760_device_info *di = platform_get_drvdata(pdev);
> +	struct ds2760_device_info *di = sl->family_data;
>  
> +	unregister_pm_notifier(&di->pm_notifier);
>  	cancel_delayed_work_sync(&di->monitor_work);
>  	cancel_delayed_work_sync(&di->set_charged_work);
>  	destroy_workqueue(di->monitor_wqueue);
>  	power_supply_unregister(di->bat);
> -
> -	return 0;
> -}
> -
> -#ifdef CONFIG_PM
> -
> -static int ds2760_battery_suspend(struct platform_device *pdev,
> -				  pm_message_t state)
> -{
> -	struct ds2760_device_info *di = platform_get_drvdata(pdev);
> -
> -	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
> -
> -	return 0;
> -}
> -
> -static int ds2760_battery_resume(struct platform_device *pdev)
> -{
> -	struct ds2760_device_info *di = platform_get_drvdata(pdev);
> -
> -	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
> -	power_supply_changed(di->bat);
> -
> -	mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
> -
> -	return 0;
>  }
>  
> -#else
> -
> -#define ds2760_battery_suspend NULL
> -#define ds2760_battery_resume NULL
> -
> -#endif /* CONFIG_PM */
> -
> -MODULE_ALIAS("platform:ds2760-battery");
> -
> -static struct platform_driver ds2760_battery_driver = {
> -	.driver = {
> -		.name = "ds2760-battery",
> -	},
> -	.probe	  = ds2760_battery_probe,
> -	.remove   = ds2760_battery_remove,
> -	.suspend  = ds2760_battery_suspend,
> -	.resume	  = ds2760_battery_resume,
> +static struct w1_family_ops w1_ds2760_fops = {
> +	.add_slave	= w1_ds2760_add_slave,
> +	.remove_slave	= w1_ds2760_remove_slave,
> +	.groups		= w1_ds2760_groups,
>  };
>  
> -module_platform_driver(ds2760_battery_driver);
> +static struct w1_family w1_ds2760_family = {
> +	.fid		= W1_FAMILY_DS2760,
> +	.fops		= &w1_ds2760_fops,
> +};
> +module_w1_family(w1_ds2760_family);
>  
> -MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>, "
>  	      "Matt Reimer <mreimer@vpop.net>, "
>  	      "Anton Vorontsov <cbou@mail.ru>");
> -MODULE_DESCRIPTION("ds2760 battery driver");
> +MODULE_DESCRIPTION("1-wire Driver Dallas 2760 battery monitor chip");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2760));
> diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
> index 7931231d8e80..e22fdeddada1 100644
> --- a/drivers/w1/slaves/Kconfig
> +++ b/drivers/w1/slaves/Kconfig
> @@ -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
> diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile
> index d5f4f4d5b9e5..eab29f151413 100644
> --- a/drivers/w1/slaves/Makefile
> +++ b/drivers/w1/slaves/Makefile
> @@ -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
> diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c
> deleted file mode 100644
> index 26168abfb8b8..000000000000
> --- a/drivers/w1/slaves/w1_ds2760.c
> +++ /dev/null
> @@ -1,175 +0,0 @@
> -/*
> - * 1-Wire implementation for the ds2760 chip
> - *
> - * Copyright © 2004-2005, Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
> - *
> - * Use consistent with the GNU GPL is permitted,
> - * provided that this copyright notice is
> - * preserved in its entirety in all copies and derived works.
> - *
> - */
> -
> -#include <linux/kernel.h>
> -#include <linux/module.h>
> -#include <linux/device.h>
> -#include <linux/types.h>
> -#include <linux/platform_device.h>
> -#include <linux/mutex.h>
> -#include <linux/idr.h>
> -#include <linux/gfp.h>
> -
> -#include <linux/w1.h>
> -
> -#include "w1_ds2760.h"
> -
> -#define W1_FAMILY_DS2760	0x30
> -
> -static int w1_ds2760_io(struct device *dev, char *buf, int addr, size_t count,
> -			int io)
> -{
> -	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
> -
> -	if (!dev)
> -		return 0;
> -
> -	mutex_lock(&sl->master->bus_mutex);
> -
> -	if (addr > DS2760_DATA_SIZE || addr < 0) {
> -		count = 0;
> -		goto out;
> -	}
> -	if (addr + count > DS2760_DATA_SIZE)
> -		count = DS2760_DATA_SIZE - addr;
> -
> -	if (!w1_reset_select_slave(sl)) {
> -		if (!io) {
> -			w1_write_8(sl->master, W1_DS2760_READ_DATA);
> -			w1_write_8(sl->master, addr);
> -			count = w1_read_block(sl->master, buf, count);
> -		} else {
> -			w1_write_8(sl->master, W1_DS2760_WRITE_DATA);
> -			w1_write_8(sl->master, addr);
> -			w1_write_block(sl->master, buf, count);
> -			/* XXX w1_write_block returns void, not n_written */
> -		}
> -	}
> -
> -out:
> -	mutex_unlock(&sl->master->bus_mutex);
> -
> -	return count;
> -}
> -
> -int w1_ds2760_read(struct device *dev, char *buf, int addr, size_t count)
> -{
> -	return w1_ds2760_io(dev, buf, addr, count, 0);
> -}
> -EXPORT_SYMBOL(w1_ds2760_read);
> -
> -int w1_ds2760_write(struct device *dev, char *buf, int addr, size_t count)
> -{
> -	return w1_ds2760_io(dev, buf, addr, count, 1);
> -}
> -EXPORT_SYMBOL(w1_ds2760_write);
> -
> -static int w1_ds2760_eeprom_cmd(struct device *dev, int addr, int cmd)
> -{
> -	struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
> -
> -	if (!dev)
> -		return -EINVAL;
> -
> -	mutex_lock(&sl->master->bus_mutex);
> -
> -	if (w1_reset_select_slave(sl) == 0) {
> -		w1_write_8(sl->master, cmd);
> -		w1_write_8(sl->master, addr);
> -	}
> -
> -	mutex_unlock(&sl->master->bus_mutex);
> -	return 0;
> -}
> -
> -int w1_ds2760_store_eeprom(struct device *dev, int addr)
> -{
> -	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_COPY_DATA);
> -}
> -EXPORT_SYMBOL(w1_ds2760_store_eeprom);
> -
> -int w1_ds2760_recall_eeprom(struct device *dev, int addr)
> -{
> -	return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_RECALL_DATA);
> -}
> -EXPORT_SYMBOL(w1_ds2760_recall_eeprom);
> -
> -static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj,
> -			     struct bin_attribute *bin_attr, char *buf,
> -			     loff_t off, size_t count)
> -{
> -	struct device *dev = container_of(kobj, struct device, kobj);
> -	return w1_ds2760_read(dev, buf, off, count);
> -}
> -
> -static BIN_ATTR_RO(w1_slave, DS2760_DATA_SIZE);
> -
> -static struct bin_attribute *w1_ds2760_bin_attrs[] = {
> -	&bin_attr_w1_slave,
> -	NULL,
> -};
> -
> -static const struct attribute_group w1_ds2760_group = {
> -	.bin_attrs = w1_ds2760_bin_attrs,
> -};
> -
> -static const struct attribute_group *w1_ds2760_groups[] = {
> -	&w1_ds2760_group,
> -	NULL,
> -};
> -
> -static int w1_ds2760_add_slave(struct w1_slave *sl)
> -{
> -	int ret;
> -	struct platform_device *pdev;
> -
> -	pdev = platform_device_alloc("ds2760-battery", PLATFORM_DEVID_AUTO);
> -	if (!pdev)
> -		return -ENOMEM;
> -	pdev->dev.parent = &sl->dev;
> -
> -	ret = platform_device_add(pdev);
> -	if (ret)
> -		goto pdev_add_failed;
> -
> -	dev_set_drvdata(&sl->dev, pdev);
> -
> -	return 0;
> -
> -pdev_add_failed:
> -	platform_device_put(pdev);
> -
> -	return ret;
> -}
> -
> -static void w1_ds2760_remove_slave(struct w1_slave *sl)
> -{
> -	struct platform_device *pdev = dev_get_drvdata(&sl->dev);
> -
> -	platform_device_unregister(pdev);
> -}
> -
> -static struct w1_family_ops w1_ds2760_fops = {
> -	.add_slave    = w1_ds2760_add_slave,
> -	.remove_slave = w1_ds2760_remove_slave,
> -	.groups       = w1_ds2760_groups,
> -};
> -
> -static struct w1_family w1_ds2760_family = {
> -	.fid = W1_FAMILY_DS2760,
> -	.fops = &w1_ds2760_fops,
> -};
> -module_w1_family(w1_ds2760_family);
> -
> -MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>");
> -MODULE_DESCRIPTION("1-wire Driver Dallas 2760 battery monitor chip");
> -MODULE_LICENSE("GPL");
> -MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2760));
> diff --git a/drivers/w1/slaves/w1_ds2760.h b/drivers/w1/slaves/w1_ds2760.h
> deleted file mode 100644
> index 24168c94eeae..000000000000
> --- a/drivers/w1/slaves/w1_ds2760.h
> +++ /dev/null
> @@ -1,59 +0,0 @@
> -/*
> - * 1-Wire implementation for the ds2760 chip
> - *
> - * Copyright © 2004-2005, Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
> - *
> - * Use consistent with the GNU GPL is permitted,
> - * provided that this copyright notice is
> - * preserved in its entirety in all copies and derived works.
> - *
> - */
> -
> -#ifndef __w1_ds2760_h__
> -#define __w1_ds2760_h__
> -
> -/* Known commands to the DS2760 chip */
> -#define W1_DS2760_SWAP			0xAA
> -#define W1_DS2760_READ_DATA		0x69
> -#define W1_DS2760_WRITE_DATA		0x6C
> -#define W1_DS2760_COPY_DATA		0x48
> -#define W1_DS2760_RECALL_DATA		0xB8
> -#define W1_DS2760_LOCK			0x6A
> -
> -/* Number of valid register addresses */
> -#define DS2760_DATA_SIZE		0x40
> -
> -#define DS2760_PROTECTION_REG		0x00
> -
> -#define DS2760_STATUS_REG		0x01
> -#define DS2760_STATUS_IE		(1 << 2)
> -#define DS2760_STATUS_SWEN		(1 << 3)
> -#define DS2760_STATUS_RNAOP		(1 << 4)
> -#define DS2760_STATUS_PMOD		(1 << 5)
> -
> -#define DS2760_EEPROM_REG		0x07
> -#define DS2760_SPECIAL_FEATURE_REG	0x08
> -#define DS2760_VOLTAGE_MSB		0x0c
> -#define DS2760_VOLTAGE_LSB		0x0d
> -#define DS2760_CURRENT_MSB		0x0e
> -#define DS2760_CURRENT_LSB		0x0f
> -#define DS2760_CURRENT_ACCUM_MSB	0x10
> -#define DS2760_CURRENT_ACCUM_LSB	0x11
> -#define DS2760_TEMP_MSB			0x18
> -#define DS2760_TEMP_LSB			0x19
> -#define DS2760_EEPROM_BLOCK0		0x20
> -#define DS2760_ACTIVE_FULL		0x20
> -#define DS2760_EEPROM_BLOCK1		0x30
> -#define DS2760_STATUS_WRITE_REG		0x31
> -#define DS2760_RATED_CAPACITY		0x32
> -#define DS2760_CURRENT_OFFSET_BIAS	0x33
> -#define DS2760_ACTIVE_EMPTY		0x3b
> -
> -extern int w1_ds2760_read(struct device *dev, char *buf, int addr,
> -			  size_t count);
> -extern int w1_ds2760_write(struct device *dev, char *buf, int addr,
> -			   size_t count);
> -extern int w1_ds2760_store_eeprom(struct device *dev, int addr);
> -extern int w1_ds2760_recall_eeprom(struct device *dev, int addr);
> -
> -#endif /* !__w1_ds2760_h__ */
> -- 
> 2.17.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 5/5] power: supply: ds2760_battery: add devicetree probing
  2018-07-06  5:35 ` [PATCH v4 5/5] power: supply: ds2760_battery: add devicetree probing Daniel Mack
@ 2018-07-06 13:43   ` Sebastian Reichel
  0 siblings, 0 replies; 15+ messages in thread
From: Sebastian Reichel @ 2018-07-06 13:43 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: 2689 bytes --]

Hi,

On Fri, Jul 06, 2018 at 07:35:52AM +0200, Daniel Mack wrote:
> Add a matching table for devicetree probing, and optionally set the module
> parameter variables from DT properties.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---

Acked-for-power-supply: Sebastian Reichel <sebastian.reichel@collabora.co.uk>

-- Sebastian

>  drivers/power/supply/ds2760_battery.c | 29 ++++++++++++++++++++++++++-
>  1 file changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c
> index aa406a7c65a1..11bed88a89fa 100644
> --- a/drivers/power/supply/ds2760_battery.c
> +++ b/drivers/power/supply/ds2760_battery.c
> @@ -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,24 @@ 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-ms", &tmp))
> +			cache_time = tmp;
> +
> +		if (!of_property_read_u32(dev->of_node,
> +					  "rated-capacity-microamp-hours",
> +					  &tmp))
> +			rated_capacity = tmp / 10; /* property is in mAh */
> +	}
> +
>  	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
>  
>  	sl->family_data = di;
> @@ -719,7 +738,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 +788,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 +804,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
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 3/5] w1: core: match sub-nodes of bus masters in devicetree
  2018-07-06  5:35 ` [PATCH v4 3/5] w1: core: match sub-nodes of bus masters in devicetree Daniel Mack
@ 2018-07-06 13:52   ` Sebastian Reichel
  2018-07-06 14:51     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 15+ messages in thread
From: Sebastian Reichel @ 2018-07-06 13:52 UTC (permalink / raw)
  To: Evgeniy Polyakov, Greg Kroah-Hartman
  Cc: Daniel Mack, robh+dt, mark.rutland, szabolcs.gyurko, devicetree,
	linux-kernel, linux-pm, robert.jarzmik

[-- Attachment #1: Type: text/plain, Size: 1748 bytes --]

Hi Greg & Evgeniy,

I suggest, that I take this patch and the DT bindings together
with the power-supply changes, once the bindings have been
reviewed by Rob (Herring). I will prepare an immutable branch,
that can be pulled into w1 as needed. Are you fine with this?

-- Sebastian

On Fri, Jul 06, 2018 at 07:35:50AM +0200, Daniel Mack wrote:
> 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
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 3/5] w1: core: match sub-nodes of bus masters in devicetree
  2018-07-06 13:52   ` Sebastian Reichel
@ 2018-07-06 14:51     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 15+ messages in thread
From: Greg Kroah-Hartman @ 2018-07-06 14:51 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Evgeniy Polyakov, Daniel Mack, robh+dt, mark.rutland,
	szabolcs.gyurko, devicetree, linux-kernel, linux-pm,
	robert.jarzmik

On Fri, Jul 06, 2018 at 03:52:05PM +0200, Sebastian Reichel wrote:
> Hi Greg & Evgeniy,
> 
> I suggest, that I take this patch and the DT bindings together
> with the power-supply changes, once the bindings have been
> reviewed by Rob (Herring). I will prepare an immutable branch,
> that can be pulled into w1 as needed. Are you fine with this?

You can take it, no need to mess with me :)

greg k-h

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings
  2018-07-06  5:35 ` [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings Daniel Mack
@ 2018-07-11 15:01   ` Rob Herring
  2018-07-18 12:40     ` Daniel Mack
  0 siblings, 1 reply; 15+ messages in thread
From: Rob Herring @ 2018-07-11 15:01 UTC (permalink / raw)
  To: Daniel Mack
  Cc: zbr, mark.rutland, szabolcs.gyurko, sre, devicetree,
	linux-kernel, linux-pm, robert.jarzmik

On Fri, Jul 06, 2018 at 07:35:48AM +0200, Daniel Mack wrote:
> This patch adds a generic w1 bindings document that describes how w1
> slave deviceses are grouped under master nodes. It also augments the
> existing w1-gpio.txt document a bit.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
>  .../devicetree/bindings/w1/w1-gpio.txt        | 11 +++++---
>  Documentation/devicetree/bindings/w1/w1.txt   | 25 +++++++++++++++++++
>  2 files changed, 33 insertions(+), 3 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/w1/w1.txt

Reviewed-by: Rob Herring <robh@kernel.org>

Note that this will conflict with a unit-address fix that I have queued 
up for 4.18 (will send this week).

> 
> diff --git a/Documentation/devicetree/bindings/w1/w1-gpio.txt b/Documentation/devicetree/bindings/w1/w1-gpio.txt
> index 6e09c35d9f1a..3d6554eac240 100644
> --- a/Documentation/devicetree/bindings/w1/w1-gpio.txt
> +++ b/Documentation/devicetree/bindings/w1/w1-gpio.txt
> @@ -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 {
> +			// ...
> +		};
> +	};
> diff --git a/Documentation/devicetree/bindings/w1/w1.txt b/Documentation/devicetree/bindings/w1/w1.txt
> new file mode 100644
> index 000000000000..05f26b27d898
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/w1/w1.txt
> @@ -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 {
> +		compatible = "w1-gpio";
> +		gpios = <&gpio 100 0>, <&gpio 101 0>;
> +
> +		battery {
> +			compatible = "maxim,ds2760";
> +			power-supplies = <&charger>;
> +		};
> +	};
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 2/5] dt-bindings: w1: document bindings for ds2760 battery monitor
  2018-07-06  5:35 ` [PATCH v4 2/5] dt-bindings: w1: document bindings for ds2760 battery monitor Daniel Mack
@ 2018-07-11 15:02   ` Rob Herring
  0 siblings, 0 replies; 15+ messages in thread
From: Rob Herring @ 2018-07-11 15:02 UTC (permalink / raw)
  To: Daniel Mack
  Cc: zbr, mark.rutland, szabolcs.gyurko, sre, devicetree,
	linux-kernel, linux-pm, robert.jarzmik

On Fri, Jul 06, 2018 at 07:35:49AM +0200, Daniel Mack wrote:
> This patch adds the devicetree bindings for Maxim's ds2760 battery
> monitors.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
>  .../bindings/power/supply/maxim,ds2760.txt    | 26 +++++++++++++++++++
>  1 file changed, 26 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/power/supply/maxim,ds2760.txt

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings
  2018-07-11 15:01   ` Rob Herring
@ 2018-07-18 12:40     ` Daniel Mack
  2018-07-20 15:10       ` Rob Herring
  0 siblings, 1 reply; 15+ messages in thread
From: Daniel Mack @ 2018-07-18 12:40 UTC (permalink / raw)
  To: Rob Herring
  Cc: zbr, mark.rutland, szabolcs.gyurko, sre, devicetree,
	linux-kernel, linux-pm, robert.jarzmik

On Wednesday, July 11, 2018 05:01 PM, Rob Herring wrote:
> On Fri, Jul 06, 2018 at 07:35:48AM +0200, Daniel Mack wrote:
>> This patch adds a generic w1 bindings document that describes how w1
>> slave deviceses are grouped under master nodes. It also augments the
>> existing w1-gpio.txt document a bit.
>>
>> Signed-off-by: Daniel Mack <daniel@zonque.org>
>> ---
>>   .../devicetree/bindings/w1/w1-gpio.txt        | 11 +++++---
>>   Documentation/devicetree/bindings/w1/w1.txt   | 25 +++++++++++++++++++
>>   2 files changed, 33 insertions(+), 3 deletions(-)
>>   create mode 100644 Documentation/devicetree/bindings/w1/w1.txt
> 
> Reviewed-by: Rob Herring <robh@kernel.org>
> 
> Note that this will conflict with a unit-address fix that I have queued
> up for 4.18 (will send this week).

How would we best handle this? Sebastian, are you going to apply this 
series, and add a note to the PR for 4.19 on how to resolve the conflict?


Thanks everyone!
Daniel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings
  2018-07-18 12:40     ` Daniel Mack
@ 2018-07-20 15:10       ` Rob Herring
  2018-07-22 22:01         ` Sebastian Reichel
  0 siblings, 1 reply; 15+ messages in thread
From: Rob Herring @ 2018-07-20 15:10 UTC (permalink / raw)
  To: Daniel Mack
  Cc: zbr, Mark Rutland, szabolcs.gyurko, Sebastian Reichel,
	devicetree, linux-kernel, open list:THERMAL, Robert Jarzmik

On Wed, Jul 18, 2018 at 6:40 AM Daniel Mack <daniel@zonque.org> wrote:
>
> On Wednesday, July 11, 2018 05:01 PM, Rob Herring wrote:
> > On Fri, Jul 06, 2018 at 07:35:48AM +0200, Daniel Mack wrote:
> >> This patch adds a generic w1 bindings document that describes how w1
> >> slave deviceses are grouped under master nodes. It also augments the
> >> existing w1-gpio.txt document a bit.
> >>
> >> Signed-off-by: Daniel Mack <daniel@zonque.org>
> >> ---
> >>   .../devicetree/bindings/w1/w1-gpio.txt        | 11 +++++---
> >>   Documentation/devicetree/bindings/w1/w1.txt   | 25 +++++++++++++++++++
> >>   2 files changed, 33 insertions(+), 3 deletions(-)
> >>   create mode 100644 Documentation/devicetree/bindings/w1/w1.txt
> >
> > Reviewed-by: Rob Herring <robh@kernel.org>
> >
> > Note that this will conflict with a unit-address fix that I have queued
> > up for 4.18 (will send this week).
>
> How would we best handle this? Sebastian, are you going to apply this
> series, and add a note to the PR for 4.19 on how to resolve the conflict?

Either 4.18-rc6 or my devicetree-fixes-for-4.18 tag (based on rc1) can
be pulled in. Or just note the conflict. It is trivial enough.

Rob

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings
  2018-07-20 15:10       ` Rob Herring
@ 2018-07-22 22:01         ` Sebastian Reichel
  0 siblings, 0 replies; 15+ messages in thread
From: Sebastian Reichel @ 2018-07-22 22:01 UTC (permalink / raw)
  To: Rob Herring
  Cc: Daniel Mack, zbr, Mark Rutland, szabolcs.gyurko, devicetree,
	linux-kernel, open list:THERMAL, Robert Jarzmik

[-- Attachment #1: Type: text/plain, Size: 1663 bytes --]

Hi,

On Fri, Jul 20, 2018 at 09:10:36AM -0600, Rob Herring wrote:
> On Wed, Jul 18, 2018 at 6:40 AM Daniel Mack <daniel@zonque.org> wrote:
> >
> > On Wednesday, July 11, 2018 05:01 PM, Rob Herring wrote:
> > > On Fri, Jul 06, 2018 at 07:35:48AM +0200, Daniel Mack wrote:
> > >> This patch adds a generic w1 bindings document that describes how w1
> > >> slave deviceses are grouped under master nodes. It also augments the
> > >> existing w1-gpio.txt document a bit.
> > >>
> > >> Signed-off-by: Daniel Mack <daniel@zonque.org>
> > >> ---
> > >>   .../devicetree/bindings/w1/w1-gpio.txt        | 11 +++++---
> > >>   Documentation/devicetree/bindings/w1/w1.txt   | 25 +++++++++++++++++++
> > >>   2 files changed, 33 insertions(+), 3 deletions(-)
> > >>   create mode 100644 Documentation/devicetree/bindings/w1/w1.txt
> > >
> > > Reviewed-by: Rob Herring <robh@kernel.org>
> > >
> > > Note that this will conflict with a unit-address fix that I have queued
> > > up for 4.18 (will send this week).
> >
> > How would we best handle this? Sebastian, are you going to apply this
> > series, and add a note to the PR for 4.19 on how to resolve the conflict?
> 
> Either 4.18-rc6 or my devicetree-fixes-for-4.18 tag (based on rc1) can
> be pulled in. Or just note the conflict. It is trivial enough.

This looks simple enough to just add a note to my pull request. I
prepared a immutable branch based on 4.18-rc1, which contains this
series and merged it into the power supply subsystem. You can get
it here:

https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git/tag/?h=ds2760-for-v4.19-signed

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-07-22 22:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-06  5:35 [PATCH v4 0/5] Add devicetree functionality to w1 busses and ds2760 Daniel Mack
2018-07-06  5:35 ` [PATCH v4 1/5] dt-bindings: w1: document generic onewire bindings Daniel Mack
2018-07-11 15:01   ` Rob Herring
2018-07-18 12:40     ` Daniel Mack
2018-07-20 15:10       ` Rob Herring
2018-07-22 22:01         ` Sebastian Reichel
2018-07-06  5:35 ` [PATCH v4 2/5] dt-bindings: w1: document bindings for ds2760 battery monitor Daniel Mack
2018-07-11 15:02   ` Rob Herring
2018-07-06  5:35 ` [PATCH v4 3/5] w1: core: match sub-nodes of bus masters in devicetree Daniel Mack
2018-07-06 13:52   ` Sebastian Reichel
2018-07-06 14:51     ` Greg Kroah-Hartman
2018-07-06  5:35 ` [PATCH v4 4/5] power: supply: ds2760_battery: merge ds2760 supply driver with its w1 slave companion Daniel Mack
2018-07-06 13:36   ` Sebastian Reichel
2018-07-06  5:35 ` [PATCH v4 5/5] power: supply: ds2760_battery: add devicetree probing Daniel Mack
2018-07-06 13:43   ` Sebastian Reichel

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).