Skip to contentSkip to conversation

power: support for Texas Instruments BQ27x00 battery managers.

PATCH In review Rodolfo Giometti 2 participants 2 messages Aug 1, 2008 – Aug 13, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: support for Texas Instruments BQ27x00 battery managers.

From: Rodolfo Giometti <[email protected]>

These battery managers came in two different packages: one for I2C busses (BQ27200) and one for HDQ busses (BQ27000).

This driver currently supports only the I2C chip version but the code is designed in order to easily allow the HDQ chip version integration.

---
 drivers/power/Kconfig           |   13 ++
 drivers/power/Makefile          |    1 +
 drivers/power/bq27x00_battery.c |  391 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 405 insertions(+), 0 deletions(-)
 create mode 100644 drivers/power/bq27x00_battery.c
drivers/power/Kconfig +13 -0
index 4d17d38..ed03358 100644
@@ -55,4 +55,17 @@ config BATTERY_PALMTX
 	help
 	  Say Y to enable support for the battery in Palm T|X.
 
+config BATTERY_BQ27x00
+	tristate "BQ27x00 battery driver"
+	help
+	  Say Y here to enable support for batteries with BQ27000 or
+	  BQ27200 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
index 6f43a54..f8ea935 100644
@@ -21,3 +21,4 @@ obj-$(CONFIG_BATTERY_DS2760)	+= ds2760_battery.o
 obj-$(CONFIG_BATTERY_PMU)	+= pmu_battery.o
 obj-$(CONFIG_BATTERY_OLPC)	+= olpc_battery.o
 obj-$(CONFIG_BATTERY_PALMTX)	+= palmtx_battery.o
+obj-$(CONFIG_BATTERY_BQ27x00)	+= bq27x00_battery.o
drivers/power/bq27x00_battery.c new file +391 -0

391 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#1 lore raw
Quoted 11 lines · On Fri, 1 Aug 2008 11:53:55 +0200 Rodolfo Giometti <[email protected]>…

From: Rodolfo Giometti <[email protected]>

These battery managers came in two different packages: one for I2C busses (BQ27200) and one for HDQ busses (BQ27000).

This driver currently supports only the I2C chip version but the code is designed in order to easily allow the HDQ chip version integration.

...

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* If the system has several batteries we need a different name for each
+ * of them...
+ */
+DEFINE_IDR(battery_id);
+DEFINE_MUTEX(battery_mutex);

These should be static.

Quoted 18 lines

...

(quoted diff) +15 -0
+static int bq27200_battery_probe(struct i2c_client *client,
+					const struct i2c_device_id *id)
+{
+	char *name;
+	struct bq27x00_device_info *di;
+	struct bq27x00_access_methods *bus;
+	int num, retval = 0;
+
+	/* Get new ID for the new battery device */
+	retval = idr_pre_get(&battery_id, GFP_KERNEL);
+	if (retval == 0)
+		return -ENOMEM;
+	mutex_lock(&battery_mutex);
+	retval = idr_get_new(&battery_id, client, &num);
+	mutex_unlock(&battery_mutex);

Review

Quoted 10 lines
(quoted diff) +10 -0
+	if (retval < 0)
+		return retval;
+
+	name = kmalloc(16, GFP_KERNEL);
+	if (!name) {
+		dev_err(&client->dev, "failed to allocate device name\n");
+		retval = -ENOMEM;
+		goto batt_failed_1;
+	}
+	sprintf(name, "bq27200-%d", num);

Use kasprintf()

Review

Quoted 8 lines
(quoted diff) +8 -0
+	di = kzalloc(sizeof(*di), GFP_KERNEL);
+	if (!di) {
+		dev_err(&client->dev, "failed to allocate device info data\n");
+		retval = -ENOMEM;
+		goto batt_failed_2;
+	}
+	di->id = num;
+

Please review:

From: Andrew Morton <[email protected]>

ERROR: space prohibited before that ':' (ctx:WxE)
#227: FILE: drivers/power/bq27x00_battery.c:175:
+ case POWER_SUPPLY_PROP_VOLTAGE_NOW :
^

ERROR: space prohibited before that ':' (ctx:WxE)
#228: FILE: drivers/power/bq27x00_battery.c:176:
+ case POWER_SUPPLY_PROP_PRESENT :
^

ERROR: space prohibited before that ':' (ctx:WxE)
#235: FILE: drivers/power/bq27x00_battery.c:183:
+ case POWER_SUPPLY_PROP_CURRENT_NOW :
^

ERROR: space prohibited before that ':' (ctx:WxE)
#240: FILE: drivers/power/bq27x00_battery.c:188:
+ case POWER_SUPPLY_PROP_CAPACITY :
^

ERROR: space prohibited before that ':' (ctx:WxE)
#245: FILE: drivers/power/bq27x00_battery.c:193:
+ case POWER_SUPPLY_PROP_TEMP :
^

total: 5 errors, 0 warnings, 412 lines checked

./patches/power-support-for-texas-instruments-bq27x00-battery-managers.patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Please run checkpatch prior to sending patches

Cc Anton Vorontsov <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Rodolfo Giometti <[email protected]>

---

 drivers/power/bq27x00_battery.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff -puN drivers/power/Kconfig~power-support-for-texas-instruments-bq27x00-battery-managers-checkpatch-fixes drivers/power/Kconfig diff -puN drivers/power/Makefile~power-support-for-texas-instruments-bq27x00-battery-managers-checkpatch-fixes drivers/power/Makefile

drivers/power/bq27x00_battery.c renamed from drivers/power/bq27x00_battery.c~power-support-for-texas-instruments-bq27x00-battery-managers-checkpatch-fixes +5 -5
diff -puN drivers/power/bq27x00_battery.c~power-support-for-texas-instruments-bq27x00-battery-managers-checkpatch-fixes drivers/power/bq27x00_battery.c
@@ -172,25 +172,25 @@ static int bq27x00_battery_get_property(
 	struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
 
 	switch (psp) {
-	case POWER_SUPPLY_PROP_VOLTAGE_NOW :
-	case POWER_SUPPLY_PROP_PRESENT :
+	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+	case POWER_SUPPLY_PROP_PRESENT:
 		val->intval = bq27x00_battery_voltage(di);
 		if (psp == POWER_SUPPLY_PROP_PRESENT)
 			val->intval = val->intval <= 0 ? 0 : 1;
 
 		break;
 
-	case POWER_SUPPLY_PROP_CURRENT_NOW :
+	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		val->intval = bq27x00_battery_current(di);
 
 		break;
 
-	case POWER_SUPPLY_PROP_CAPACITY :
+	case POWER_SUPPLY_PROP_CAPACITY:
 		val->intval = bq27x00_battery_rsoc(di);
 
 		break;
 
-	case POWER_SUPPLY_PROP_TEMP :
+	case POWER_SUPPLY_PROP_TEMP:
 		val->intval = bq27x00_battery_temperature(di);
 
 		break;

_

From: Andrew Morton <[email protected]>

- make things static

- use kasprintf()

Cc Anton Vorontsov <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Rodolfo Giometti <[email protected]>

---

 drivers/power/bq27x00_battery.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff -puN drivers/power/Kconfig~power-support-for-texas-instruments-bq27x00-battery-managers-tweaks drivers/power/Kconfig diff -puN drivers/power/Makefile~power-support-for-texas-instruments-bq27x00-battery-managers-tweaks drivers/power/Makefile

drivers/power/bq27x00_battery.c renamed from drivers/power/bq27x00_battery.c~power-support-for-texas-instruments-bq27x00-battery-managers-tweaks +3 -4
diff -puN drivers/power/bq27x00_battery.c~power-support-for-texas-instruments-bq27x00-battery-managers-tweaks drivers/power/bq27x00_battery.c
@@ -40,8 +40,8 @@
 /* If the system has several batteries we need a different name for each
  * of them...
  */
-DEFINE_IDR(battery_id);
-DEFINE_MUTEX(battery_mutex);
+static DEFINE_IDR(battery_id);
+static DEFINE_MUTEX(battery_mutex);
 
 struct bq27x00_device_info;
 struct bq27x00_access_methods {
@@ -275,13 +275,12 @@ static int bq27200_battery_probe(struct 
 	if (retval < 0)
 		return retval;
 
-	name = kmalloc(16, GFP_KERNEL);
+	name = kasprintf(GFP_KERNEL, "bq27200-%d", num);
 	if (!name) {
 		dev_err(&client->dev, "failed to allocate device name\n");
 		retval = -ENOMEM;
 		goto batt_failed_1;
 	}
-	sprintf(name, "bq27200-%d", num);
 
 	di = kzalloc(sizeof(*di), GFP_KERNEL);
 	if (!di) {

_