power: support for Texas Instruments BQ27x00 battery managers.
PATCH 1/1 power: support for Texas Instruments BQ27x00 battery managers.
The driver supports both HDQ (BQ27000) and I2C (BQ27200) chip version.
--- drivers/power/Kconfig | 21 ++ drivers/power/Makefile | 1 + drivers/power/bq27x00_battery.c | 511 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 533 insertions(+), 0 deletions(-) create mode 100644 drivers/power/bq27x00_battery.c
drivers/power/Kconfig +21 -0
@@ -49,4 +49,25 @@ config BATTERY_OLPC help Say Y to enable support for the battery on the OLPC laptop. +config BATTERY_BQ27x00 + tristate "BQ27x00 battery driver" + help + Say Y here to enable support for batteries with BQ27000 or + BQ27200 chip. + +config BATTERY_BQ27000 + bool "BQ27000 battery driver" + depends on BATTERY_BQ27x00 + select W1 + select W1_SLAVE_BQ27000 + help + Say Y here to enable support for batteries with BQ27000(HDQ) chip. + +config BATTERY_BQ27200 + bool "BQ27200 battery driver" + depends on BATTERY_BQ27x00 + select I2C + help + Say Y here to enable support for batteries with BQ27200(I2C) chip. + endif # POWER_SUPPLY
drivers/power/Makefile +1 -0
@@ -20,3 +20,4 @@ obj-$(CONFIG_APM_POWER) += apm_power.o obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o +obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o
drivers/power/bq27x00_battery.c new file +511 -0
511 lines not on this page · raw message
Signature · 1 line
1.5.4.3
A message that is not in the archive (sent off-list or not yet received): 20080619233411.GA27198@zarina
Hello,
before answering to other questions I'd like solve the following issue.
Quoted 17 lines · Anton Vorontsov
To avoid these ifdefs, I would suggest you to reconsider the model of this driver. How about:
-
drivers/power/bq27x00_battery.c:Registers two
platform_drivers, first is "bq27200-bat" (I2C) and second is "bq27000-bat" (W1). Both are using the same probe and remove methods. This driver will simply registerpower_supplyand will do all battery logic, separated from the underlaying bus.(Two platform drivers are used simply because underlaying I2C/W1 drivers will not know each other, thus will not able to pass uniqe platform_device.id in case of single driver).
-
include/linux/bq27x00-battery.h:
Quoted 8 lines
Declares
structbq27x00_access_methods{
/** dev argument is I2C or W1 device, battery driver will use * platform_device->dev.parent to pass the dev argument. */ int (*read)(struct device *dev, u8 reg, int *rt_value, int b_single);};
Where this function should be defined? Can you explain better what you mean?
Quoted 7 lines
-
drivers/i2c/chips/bq27200.c:This driver will do all I2C stuff, and then will register "bq27200-bat" platform device, with .platform_data pointed to the allocated and filled "struct
bq27x00_access_methods".
Quoted 7 lines
-
drivers/w1/slaves/bq27000.c:This driver will do all W1 stuff, and then will register "bq27000-bat" platform device, with .platform_data pointed to the allocated and filled "struct
bq27x00_access_methods".Will this (not) work?
As you can see at the top of the file I based this work an previour work by Texas Instruments people which never goes into linux vanilla but lives into linux-omap tree. I just fixed some basic issue which prevent the driver to compile and work properly and repropose the driver here.
My hardware just uses the I2C chip version so I cannot test the W1 one at all. If you agree I can remove the W1 code and provide the bq27200.c driver only.
Maybe, as you suggested above, we can try to write the code in order that a future W1 driver writer can write few lines. :)
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti
On Fri, Jun 20, 2008 at 08:13:45AM +0200, Rodolfo Giometti wrote:
[..]
Quoted 26 lines
Quoted 17 lines
To avoid these ifdefs, I would suggest you to reconsider the model of this driver. How about:
-
drivers/power/bq27x00_battery.c:Registers two
platform_drivers, first is "bq27200-bat" (I2C) and second is "bq27000-bat" (W1). Both are using the same probe and remove methods. This driver will simply registerpower_supplyand will do all battery logic, separated from the underlaying bus.(Two platform drivers are used simply because underlaying I2C/W1 drivers will not know each other, thus will not able to pass uniqe platform_device.id in case of single driver).
-
include/linux/bq27x00-battery.h:Quoted 8 lines
Declares
structbq27x00_access_methods{
/** dev argument is I2C or W1 device, battery driver will use * platform_device->dev.parent to pass the dev argument. */ int (*read)(struct device *dev, u8 reg, int *rt_value, int b_single);};
Quoted 2 lines
Where this function should be defined? Can you explain better what you mean?
Here is the patch to show the idea. I only tested it to build, so no guaranties that it will work on the actual hardware. :-)
This patch should be separated: one patch is for I2C subsystem maintainer (drivers/i2c/* changes) and another (drivers/power/* + include/linux/bq27x00.h) is for me.
drivers/i2c/chips/Kconfig | 9 + drivers/i2c/chips/Makefile | 1 drivers/i2c/chips/bq27200.c | 167 +++++++++++++++++++++++++ drivers/power/Kconfig | 10 + drivers/power/Makefile | 1 drivers/power/bq27x00_battery.c | 259 ++++++++++++++++++++++++++++++++++++++++ include/linux/bq27x00.h | 28 ++++ 7 files changed, 475 insertions(+)
drivers/i2c/chips/Kconfig +9 -0
@@ -129,6 +129,15 @@ config SENSORS_TSL2550 This driver can also be built as a module. If so, the module will be called tsl2550. +config BATTERY_BQ27200 + tristate "BQ27200 I2C battery driver" + default y if BATTERY_BQ27x00 + help + Say Y here to enable support for batteries with BQ27200 I2C chip. + + Note: you'll also need to select BATTERY_BQ27x00 driver to get + userspace interface for this chip. + config MENELAUS bool "TWL92330/Menelaus PM chip" depends on I2C=y && ARCH_OMAP24XX
drivers/i2c/chips/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o obj-$(CONFIG_TPS65010) += tps65010.o obj-$(CONFIG_MENELAUS) += menelaus.o +obj-$(CONFIG_BATTERY_BQ27200) += bq27200.o obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
drivers/i2c/chips/bq27200.c new file +167 -0
167 lines not on this page · raw message
drivers/power/Kconfig +10 -0
@@ -49,4 +49,14 @@ config BATTERY_OLPC help Say Y to enable support for the battery on the OLPC laptop. +config BATTERY_BQ27x00 + tristate "BQ27x00 battery monitor driver" + help + Say Y here to enable support for common userspace interface for + batteries with BQ27000 or BQ27200 chips inside. + + NOTE: this driver only provides userspace interface for these + chips, you need to select BQ27x00 chip variant, I2C or W1, + as found in the appropriate menus. + endif # POWER_SUPPLY
drivers/power/Makefile +1 -0
@@ -20,3 +20,4 @@ obj-$(CONFIG_APM_POWER) += apm_power.o obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o +obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o
drivers/power/bq27x00_battery.c new file +259 -0
259 lines not on this page · raw message
include/linux/bq27x00.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* BQ27x00 battery monitors +* +* Copyright (C) 2008 Rodolfo Giometti <[email protected]> +* Copyright (C) 2008 Eurotech S.p.A. <[email protected]> +* +* Based on a previous work by Copyright (C) 2008 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef __LINUX_BQ27x00_H +#define __LINUX_BQ27x00_H + +#include <linux/types.h> +#include <linux/device.h> + +struct bq27x00_access_methods { +int (*read)(struct device *dev,u8 reg,int *rt_value,int b_single); +}; + +#endif /* __LINUX_BQ27x00_H */
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line · Rodolfo Giometti
Sorry for the long delay... I was very busy in these days! :'(
No problem. ;-)
Quoted 23 lines · Anton Vorontsov
Quoted 7 lines
Here is the patch to show the idea. I only tested it to build, so no guaranties that it will work on the actual hardware. :-)
This patch should be separated: one patch is for I2C subsystem maintainer (
drivers/i2c/*changes) and another (drivers/power/*+include/linux/bq27x00.h) is for me.On my system I need to specify 2 battery chips into the platform specific file as follow (file is
arch/arm/mach-pxa/wr1100.c):static struct i2c_board_info __initdata wr1100_i2c_mux_devices[] = { { I2C_BOARD_INFO("bq27200", 0x55), }, }; i2c_register_board_info(2, wr1100_i2c_mux_devices, ARRAY_SIZE(wr1100_i2c_mux_devices)); i2c_register_board_info(3, wr1100_i2c_mux_devices, ARRAY_SIZE(wr1100_i2c_mux_devices));
Quoted 1 line
By using your solution I cannot use this code, is that right?
Why not? I think there should be no problem.
[...]
Quoted 3 lines
if you agree, I prefere resend my
patch without the #ifdef and the w1 support (since I cannot test it at all) but living the possibility to add that support later.
Yes, that would be also fine.
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 18 lines · Anton Vorontsov
Quoted 18 lines · Anton Vorontsov
Quoted 7 lines
Here is the patch to show the idea. I only tested it to build, so no guaranties that it will work on the actual hardware. :-)
This patch should be separated: one patch is for I2C subsystem maintainer (
drivers/i2c/*changes) and another (drivers/power/*+include/linux/bq27x00.h) is for me.On my system I need to specify 2 battery chips into the platform specific file as follow (file is
arch/arm/mach-pxa/wr1100.c):static struct i2c_board_info __initdata wr1100_i2c_mux_devices[] = { { I2C_BOARD_INFO("bq27200", 0x55), }, };
Quoted 8 lines
Quoted 6 lines
i2c_register_board_info(2, wr1100_i2c_mux_devices, ARRAY_SIZE(wr1100_i2c_mux_devices)); i2c_register_board_info(3, wr1100_i2c_mux_devices, ARRAY_SIZE(wr1100_i2c_mux_devices));By using your solution I cannot use this code, is that right?
Why not? I think there should be no problem.
The platform_driver_register() conflicts with i2c_add_driver(), doesn't it? O_o
Quoted 6 lines
[...]
Quoted 3 lines
if you agree, I prefere resend my
patch without the #ifdef and the w1 support (since I cannot test it at all) but living the possibility to add that support later.Yes, that would be also fine.
Ok, since I cannot test the w1 subsystem at all, is better I provide only tested code. :)
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti