Skip to contentSkip to conversation

Hi all,

PATCH Superseded Andrew F. Davis 3 participants 6 messages Mar 16, 2017 – Mar 20, 2017

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#4 lore raw

PATCH 2/2 power: supply: bq27xxx: move platform driver code into bq27xxx_battery_hdq.c

In reply to Andrew F. Davis

When the BQ27xxx driver was originally written the w1 subsystem only allowed device drivers for w1 attached devices to live in the w1 subsystem. Kernel driver subsystems expect that the driver for a device live in the directory of the subsystem for which it implements functionality, not in the directory of the bus that it is attached. To work around this, the BQ27xxx driver was implemented as a platform device driver and the interface driver would instantiate this device from within the w1 directory, then pass a w1 read callback as platform data.

As we can now have the w1 interface driver in the power/supply directory (like we do already with the i2c interface driver) we can remove this middle-layer platform driver.

---
 drivers/power/supply/bq27xxx_battery.c     | 104 ------------
 drivers/power/supply/bq27xxx_battery_hdq.c | 250 ++++++++++++++++-------------
 include/linux/power/bq27xxx_battery.h      |  17 --
 3 files changed, 135 insertions(+), 236 deletions(-)

rewrite drivers/power/supply/bq27xxx_battery_hdq.c (72%)

drivers/power/supply/bq27xxx_battery.c +0 -104
index 398801a21b86..07ef6f3242f3 100644
@@ -1408,110 +1408,6 @@ void bq27xxx_battery_teardown(struct bq27xxx_device_info *di)
 }
 EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown);
 
-static int bq27xxx_battery_platform_read(struct bq27xxx_device_info *di, u8 reg,
-					 bool single)
-{
-	struct device *dev = di->dev;
-	struct bq27xxx_platform_data *pdata = dev->platform_data;
-	unsigned int timeout = 3;
-	int upper, lower;
-	int temp;
-
-	if (!single) {
-		/* Make sure the value has not changed in between reading the
-		 * lower and the upper part */
-		upper = pdata->read(dev, reg + 1);
-		do {
-			temp = upper;
-			if (upper < 0)
-				return upper;
-
-			lower = pdata->read(dev, reg);
-			if (lower < 0)
-				return lower;
-
-			upper = pdata->read(dev, reg + 1);
-		} while (temp != upper && --timeout);
-
-		if (timeout == 0)
-			return -EIO;
-
-		return (upper << 8) | lower;
-	}
-
-	return pdata->read(dev, reg);
-}
-
-static int bq27xxx_battery_platform_probe(struct platform_device *pdev)
-{
-	struct bq27xxx_device_info *di;
-	struct bq27xxx_platform_data *pdata = pdev->dev.platform_data;
-
-	if (!pdata) {
-		dev_err(&pdev->dev, "no platform_data supplied\n");
-		return -EINVAL;
-	}
-
-	if (!pdata->read) {
-		dev_err(&pdev->dev, "no hdq read callback supplied\n");
-		return -EINVAL;
-	}
-
-	if (!pdata->chip) {
-		dev_err(&pdev->dev, "no device supplied\n");
-		return -EINVAL;
-	}
-
-	di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
-	if (!di)
-		return -ENOMEM;
-
-	platform_set_drvdata(pdev, di);
-
-	di->dev = &pdev->dev;
-	di->chip = pdata->chip;
-	di->name = pdata->name ?: dev_name(&pdev->dev);
-	di->bus.read = bq27xxx_battery_platform_read;
-
-	return bq27xxx_battery_setup(di);
-}
-
-static int bq27xxx_battery_platform_remove(struct platform_device *pdev)
-{
-	struct bq27xxx_device_info *di = platform_get_drvdata(pdev);
-
-	bq27xxx_battery_teardown(di);
-
-	return 0;
-}
-
-static const struct platform_device_id bq27xxx_battery_platform_id_table[] = {
-	{ "bq27000-battery", },
-	{ /* sentinel */ }
-};
-MODULE_DEVICE_TABLE(platform, bq27xxx_battery_platform_id_table);
-
-#ifdef CONFIG_OF
-static const struct of_device_id bq27xxx_battery_platform_of_match_table[] = {
-	{ .compatible = "ti,bq27000" },
-	{},
-};
-MODULE_DEVICE_TABLE(of, bq27xxx_battery_platform_of_match_table);
-#endif
-
-static struct platform_driver bq27xxx_battery_platform_driver = {
-	.probe	= bq27xxx_battery_platform_probe,
-	.remove = bq27xxx_battery_platform_remove,
-	.driver = {
-		.name = "bq27000-battery",
-		.of_match_table = of_match_ptr(bq27xxx_battery_platform_of_match_table),
-	},
-	.id_table = bq27xxx_battery_platform_id_table,
-};
-module_platform_driver(bq27xxx_battery_platform_driver);
-
-MODULE_ALIAS("platform:bq27000-battery");
-
 MODULE_AUTHOR("Rodolfo Giometti <[email protected]>");
 MODULE_DESCRIPTION("BQ27xxx battery monitor driver");
 MODULE_LICENSE("GPL");
drivers/power/supply/bq27xxx_battery_hdq.c +135 -115

250 lines not on this page · raw message

include/linux/power/bq27xxx_battery.h +0 -17
index b312bcef53da..28c4a4ec3993 100644
@@ -20,23 +20,6 @@ enum bq27xxx_chip {
 	BQ27421, /* bq27421, bq27425, bq27441, bq27621 */
 };
 
-/**
- * struct bq27xxx_plaform_data - Platform data for bq27xxx devices
- * @name: Name of the battery.
- * @chip: Chip class number of this device.
- * @read: HDQ read callback.
- *	This function should provide access to the HDQ bus the battery is
- *	connected to.
- *	The first parameter is a pointer to the battery device, the second the
- *	register to be read. The return value should either be the content of
- *	the passed register or an error value.
- */
-struct bq27xxx_platform_data {
-	const char *name;
-	enum bq27xxx_chip chip;
-	int (*read)(struct device *dev, unsigned int);
-};
-
 struct bq27xxx_device_info;
 struct bq27xxx_access_methods {
 	int (*read)(struct bq27xxx_device_info *di, u8 reg, bool single);
Signature · 1 line
2.11.0
#0 lore raw

cover Hi all,

To finish the work started in this patch[0] we needed to reorganize the 1-wire subsystem a bit, this is done here[1]. After that is taken this series can remove the need for a platform driver for supporting 1-wire connected BQ27xxx devices.

Thanks,
Andrew

[0] https://patchwork.kernel.org/patch/7684371/
[1] https://lkml.org/lkml/2017/3/16/604

Andrew F. Davis (2):
power: supply: move HDQ interface for bq27xxx from w1 to power/supply
power: supply: bq27xxx: move platform driver code into
bq27xxx_battery_hdq.c

 drivers/power/supply/Kconfig               |   9 ++
 drivers/power/supply/Makefile              |   1 +
 drivers/power/supply/bq27xxx_battery.c     | 104 ----------------------
 drivers/power/supply/bq27xxx_battery_hdq.c | 135 +++++++++++++++++++++++++++++
 drivers/w1/slaves/Kconfig                  |   6 --
 drivers/w1/slaves/Makefile                 |   1 -
 drivers/w1/slaves/w1_bq27000.c             | 117 -------------------------
 include/linux/power/bq27xxx_battery.h      |  17 ----
 8 files changed, 145 insertions(+), 245 deletions(-)
 create mode 100644 drivers/power/supply/bq27xxx_battery_hdq.c
 delete mode 100644 drivers/w1/slaves/w1_bq27000.c
Signature · 1 line
2.11.0
#2 lore raw

Hmm, subject got messed up, should be:

[PATCH 0/2] Remove BQ27xxx platform interface

Quoted 28 lines · Andrew F. Davis

To finish the work started in this patch[0] we needed to reorganize the 1-wire subsystem a bit, this is done here[1]. After that is taken this series can remove the need for a platform driver for supporting 1-wire connected BQ27xxx devices.

Thanks,
Andrew

[0] https://patchwork.kernel.org/patch/7684371/
[1] https://lkml.org/lkml/2017/3/16/604

Andrew F. Davis (2):
power: supply: move HDQ interface for bq27xxx from w1 to power/supply
power: supply: bq27xxx: move platform driver code into
bq27xxx_battery_hdq.c

 drivers/power/supply/Kconfig               |   9 ++
 drivers/power/supply/Makefile              |   1 +
 drivers/power/supply/bq27xxx_battery.c     | 104 ----------------------
 drivers/power/supply/bq27xxx_battery_hdq.c | 135 +++++++++++++++++++++++++++++
 drivers/w1/slaves/Kconfig                  |   6 --
 drivers/w1/slaves/Makefile                 |   1 -
 drivers/w1/slaves/w1_bq27000.c             | 117 -------------------------
 include/linux/power/bq27xxx_battery.h      |  17 ----
 8 files changed, 145 insertions(+), 245 deletions(-)
 create mode 100644 drivers/power/supply/bq27xxx_battery_hdq.c
 delete mode 100644 drivers/w1/slaves/w1_bq27000.c
#1 lore raw

PATCH 1/2 power: supply: move HDQ interface for bq27xxx from w1 to power/supply

In reply to Andrew F. Davis

The HDQ interface driver should be in this folder just like the I2C interface driver. Move this driver out of drivers/w1/slave and into drivers/power/supply.

---
 drivers/power/supply/Kconfig                                     | 9 +++++++++
 drivers/power/supply/Makefile                                    | 1 +
 .../slaves/w1_bq27000.c => power/supply/bq27xxx_battery_hdq.c}   | 2 --
 drivers/w1/slaves/Kconfig                                        | 6 ------
 drivers/w1/slaves/Makefile                                       | 1 -
 5 files changed, 10 insertions(+), 9 deletions(-)
 rename drivers/{w1/slaves/w1_bq27000.c => power/supply/bq27xxx_battery_hdq.c} (98%)
drivers/power/supply/Kconfig +9 -0
index da54ac88f068..51fffe67b571 100644
@@ -184,6 +184,15 @@ config BATTERY_BQ27XXX_I2C
 	  Say Y here to enable support for batteries with BQ27xxx chips
 	  connected over an I2C bus.
 
+config BATTERY_BQ27XXX_HDQ
+	tristate "BQ27xxx HDQ support"
+	depends on BATTERY_BQ27XXX
+	depends on W1
+	default y
+	help
+	  Say Y here to enable support for batteries with BQ27xxx chips
+	  connected over an HDQ bus.
+
 config BATTERY_DA9030
 	tristate "DA9030 battery driver"
 	depends on PMIC_DA903X
drivers/power/supply/Makefile +1 -0
index 3789a2c06fdf..48ce539f16a2 100644
@@ -35,6 +35,7 @@ obj-$(CONFIG_BATTERY_SBS)	+= sbs-battery.o
 obj-$(CONFIG_CHARGER_SBS)	+= sbs-charger.o
 obj-$(CONFIG_BATTERY_BQ27XXX)	+= bq27xxx_battery.o
 obj-$(CONFIG_BATTERY_BQ27XXX_I2C) += bq27xxx_battery_i2c.o
+obj-$(CONFIG_BATTERY_BQ27XXX_HDQ) += bq27xxx_battery_hdq.o
 obj-$(CONFIG_BATTERY_DA9030)	+= da9030_battery.o
 obj-$(CONFIG_BATTERY_DA9052)	+= da9052-battery.o
 obj-$(CONFIG_CHARGER_DA9150)	+= da9150-charger.o
drivers/power/supply/bq27xxx_battery_hdq.c renamed from drivers/w1/slaves/w1_bq27000.c +0 -2
similarity index 98%
rename from drivers/w1/slaves/w1_bq27000.c
rename to drivers/power/supply/bq27xxx_battery_hdq.c
index 8046ac45381a..f4df67eb9d2c 100644
@@ -1,6 +1,4 @@
 /*
- * drivers/w1/slaves/w1_bq27000.c
- *
  * Copyright (C) 2007 Texas Instruments, Inc.
  *
  * This file is licensed under the terms of the GNU General Public License
drivers/w1/slaves/Kconfig +0 -6
index 0ef9f2663dbd..8488a4eb04bd 100644
@@ -134,10 +134,4 @@ config W1_SLAVE_DS28E04
 
 	  If you are unsure, say N.
 
-config W1_SLAVE_BQ27000
-	tristate "BQ27000 slave support"
-	help
-	  Say Y here if you want to use a hdq
-	  bq27000 slave support.
-
 endmenu
drivers/w1/slaves/Makefile +0 -1
index b4a358955ef9..e6b0c403ea77 100644
@@ -14,5 +14,4 @@ obj-$(CONFIG_W1_SLAVE_DS2433)	+= w1_ds2433.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_BQ27000)	+= w1_bq27000.o
 obj-$(CONFIG_W1_SLAVE_DS28E04)	+= w1_ds28e04.o
Signature · 1 line
2.11.0
#3 lore raw
In reply to Andrew F. Davis

Looks good, you can add my Acked-by.

Quoted 15 lines · On Thursday 16 March 2017 17:07:06 Andrew F. Davis wrote:

Hmm, subject got messed up, should be:

[PATCH 0/2] Remove BQ27xxx platform interface

Quoted 10 lines · Andrew F. Davis

To finish the work started in this patch[0] we needed to reorganize the 1-wire subsystem a bit, this is done here[1]. After that is taken this series can remove the need for a platform driver for supporting 1-wire connected BQ27xxx devices.

Thanks,
Andrew

[0] https://patchwork.kernel.org/patch/7684371/
[1] https://lkml.org/lkml/2017/3/16/604

Signature · 2 lines
Pali Rohár
[email protected]
maintainer Acked-by on the v1 series
#5 lore raw
In reply to Andrew F. Davis

Hi,

Quoted 16 lines · Andrew F. Davis

To finish the work started in this patch[0] we needed to reorganize the 1-wire subsystem a bit, this is done here[1]. After that is taken this series can remove the need for a platform driver for supporting 1-wire connected BQ27xxx devices.

Thanks,
Andrew

[0] https://patchwork.kernel.org/patch/7684371/
[1] https://lkml.org/lkml/2017/3/16/604

Andrew F. Davis (2):
power: supply: move HDQ interface for bq27xxx from w1 to power/supply
power: supply: bq27xxx: move platform driver code into
bq27xxx_battery_hdq.c

Quoted 11 lines
 drivers/power/supply/Kconfig               |   9 ++
 drivers/power/supply/Makefile              |   1 +
 drivers/power/supply/bq27xxx_battery.c     | 104 ----------------------
 drivers/power/supply/bq27xxx_battery_hdq.c | 135 +++++++++++++++++++++++++++++
 drivers/w1/slaves/Kconfig                  |   6 --
 drivers/w1/slaves/Makefile                 |   1 -
 drivers/w1/slaves/w1_bq27000.c             | 117 -------------------------
 include/linux/power/bq27xxx_battery.h      |  17 ----
 8 files changed, 145 insertions(+), 245 deletions(-)
 create mode 100644 drivers/power/supply/bq27xxx_battery_hdq.c
 delete mode 100644 drivers/w1/slaves/w1_bq27000.c

-- Sebastian