ds2782_battery: add support for ds2786 battery gas gauge
PATCH v3 1/1 ds2782_battery: add support for ds2786 battery gas gauge
From: Yulia Vilensky <[email protected]>
v2 changes:
* add ds278x_platform_data
* address Anton comments
v3 changes:
* use ds278x_get_temp for both ds2782 and ds2786
* update math as per Ryan comments
--- drivers/power/Kconfig | 4 +- drivers/power/ds2782_battery.c | 184 +++++++++++++++++++++++++++++----------- include/linux/ds2782_battery.h | 8 ++ 3 files changed, 146 insertions(+), 50 deletions(-) create mode 100644 include/linux/ds2782_battery.h
drivers/power/Kconfig +2 -2
@@ -65,10 +65,10 @@ config BATTERY_DS2760 Say Y here to enable support for batteries with ds2760 chip. config BATTERY_DS2782 - tristate "DS2782 standalone gas-gauge" + tristate "DS2782/DS2786 standalone gas-gauge" depends on I2C help - Say Y here to enable support for the DS2782 standalone battery + Say Y here to enable support for the DS2782/DS2786 standalone battery gas-gauge. config BATTERY_PMU
drivers/power/ds2782_battery.c +136 -48
373 lines not on this page · raw message
include/linux/ds2782_battery.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef __LINUX_DS2782_BATTERY_H +#define __LINUX_DS2782_BATTERY_H + +struct ds278x_platform_data { +int rsns; +}; + +#endif
Signature · 1 line
1.6.6.2
Anton Vorontsov
AppliedQuoted 11 lines · Mike Rapoport
From: Yulia Vilensky <[email protected]>
v2 changes:
* addds278x_platform_data
* address Anton comments
v3 changes:
* useds278x_get_tempfor both ds2782 and ds2786
* update math as per Ryan commentsSigned-off-by Yulia Vilensky <[email protected]>Signed-off-by Mike Rapoport <[email protected]>
Thanks, applied to battery-2.6 with the following change (we shouldn't compare pointers and integers):
drivers/power/ds2782_battery.c +1 -1
@@ -325,7 +325,7 @@ static int ds278x_battery_probe(struct i2c_client *client,* ds2786 should have the sense resistor value set * in the platform data */ -if (id->driver_data ==1 && pdata ==0 ) { +if (id->driver_data ==1 && !pdata) {dev_err (&client->dev,"missing platform data for ds2786\n" );return -EINVAL ; }
----
Btw, I don't quite like the 'if (id->driver_data == 1)' stuff. How about the following patch on top?
Quoted 1 line
From
acf917d3880465b76875f671ee450a8fdff62c9fMon Sep 17 00:00:00 2001
From: Anton Vorontsov <[email protected]>
Date: Mon, 26 Apr 2010 22:10:52 +0400
Subject: [PATCH] ds2782_battery: Get rid of magic numbers in driver_data
Constructions like 'if (id->driver_data == 1)' look quite weird. This patch introduces 'enum ds278x_num_id', which makes things much more understandable, i.e. 'if (id->driver_data == DS2786)'.
--- drivers/power/ds2782_battery.c | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-)
drivers/power/ds2782_battery.c +11 -6
@@ -300,13 +300,18 @@ static int ds278x_battery_remove(struct i2c_client *client)return 0 ; } +enum ds278x_num_id { +DS2782 =0 , +DS2786 , +}; +static struct ds278x_battery_ops ds278x_ops[] = { - [0 ] = { + [DS2782 ] = { .get_current = ds2782_get_current, .get_voltage = ds2782_get_voltage, .get_capacity = ds2782_get_capacity, }, - [1 ] = { + [DS2786 ] = { .get_current = ds2786_get_current, .get_voltage = ds2786_get_voltage, .get_capacity = ds2786_get_capacity,
@@ -325,7 +330,7 @@ static int ds278x_battery_probe(struct i2c_client *client,* ds2786 should have the sense resistor value set * in the platform data */ -if (id->driver_data ==1 && !pdata) { +if (id->driver_data ==DS2786 && !pdata) {dev_err (&client->dev,"missing platform data for ds2786\n" );return -EINVAL ; }
@@ -355,7 +360,7 @@ static int ds278x_battery_probe(struct i2c_client *client, goto fail_name; } -if (id->driver_data ==1 ) +if (id->driver_data ==DS2786 ) info->rsns = pdata->rsns;i2c_set_clientdata (client, info);
@@ -385,8 +390,8 @@ fail_id: }static const struct i2c_device_id ds278x_id[] = { - {"ds2782" ,0 }, - {"ds2786" ,1 }, + {"ds2782" ,DS2782 }, + {"ds2786" ,DS2786 }, {}, };
Signature · 1 line
1.7.0.5
Mike Rapoport
Acked-byQuoted 4 lines · Anton Vorontsov
Btw, I don't quite like the 'if (
id->driver_data== 1)' stuff. How about the following patch on top?
Quoted 8 lines
From
acf917d3880465b76875f671ee450a8fdff62c9fMon Sep 17 00:00:00 2001
From: Anton Vorontsov <[email protected]>
Date: Mon, 26 Apr 2010 22:10:52 +0400
Subject: [PATCH]ds2782_battery: Get rid of magic numbers indriver_dataConstructions like 'if (
id->driver_data== 1)' look quite weird. This patch introduces 'enumds278x_num_id', which makes things much more understandable, i.e. 'if (id->driver_data== DS2786)'.
agree
Quoted 1 line
Signed-off-by Anton Vorontsov <[email protected]>
Quoted 67 lines
---
drivers/power/ds2782_battery.c | 17 +++++++++++------1 files changed, 11 insertions(+), 6 deletions(-)drivers/power/ds2782_battery.c +11
-7@@ -300,13 +300,18 @@ static int ds278x_battery_remove(struct i2c_client *client) return 0; } +enum ds278x_num_id { + DS2782 = 0, + DS2786, +}; + static struct ds278x_battery_ops ds278x_ops[] = { - [0] = { + [DS2782] = { .get_current = ds2782_get_current, .get_voltage = ds2782_get_voltage, .get_capacity = ds2782_get_capacity, }, - [1] = { + [DS2786] = { .get_current = ds2786_get_current, .get_voltage = ds2786_get_voltage, .get_capacity = ds2786_get_capacity,@@ -325,7 +330,7 @@ static int ds278x_battery_probe(struct i2c_client *client,* ds2786 should have the sense resistor value set * in the platform data */ - if (id->driver_data == 1 && !pdata) { + if (id->driver_data == DS2786 && !pdata) { dev_err(&client->dev, "missing platform data for ds2786\n"); return -EINVAL; }@@ -355,7 +360,7 @@ static int ds278x_battery_probe(struct i2c_client *client, goto fail_name; } - if (id->driver_data == 1) + if (id->driver_data == DS2786) info->rsns = pdata->rsns; i2c_set_clientdata(client, info);@@ -385,8 +390,8 @@ fail_id: } static const struct i2c_device_id ds278x_id[] = { - {"ds2782", 0}, - {"ds2786", 1}, + {"ds2782", DS2782}, + {"ds2786", DS2786}, {}, }; --1.7.0.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Sincerely Yours, Mike.
Anton Vorontsov
AppliedQuoted 14 lines · Mike Rapoport
Quoted 4 lines · Anton Vorontsov
Btw, I don't quite like the 'if (
id->driver_data== 1)' stuff. How about the following patch on top?Quoted 8 lines
From
acf917d3880465b76875f671ee450a8fdff62c9fMon Sep 17 00:00:00 2001
From: Anton Vorontsov <[email protected]>
Date: Mon, 26 Apr 2010 22:10:52 +0400
Subject: [PATCH]ds2782_battery: Get rid of magic numbers indriver_dataConstructions like 'if (
id->driver_data== 1)' look quite weird. This patch introduces 'enumds278x_num_id', which makes things much more understandable, i.e. 'if (id->driver_data== DS2786)'.
Quoted 5 lines
agree
Quoted 1 line
Signed-off-by Anton Vorontsov <[email protected]>Acked-by Mike Rapoport <[email protected]>
Thanks! Applied.
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2