Added LTC2941/LTC2943 Battery Gauge Driver
PATCH v2 1/1 Added LTC2941/LTC2943 Battery Gauge Driver
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
v2: Fix units of measurement: uV, uA and centidegrees.
--- drivers/power/Kconfig | 7 + drivers/power/Makefile | 1 + drivers/power/ltc2941-battery-gauge.c | 497 +++++++++++++++++++++++++++++++++ 3 files changed, 505 insertions(+) create mode 100644 drivers/power/ltc2941-battery-gauge.c
drivers/power/Kconfig +7 -0
@@ -382,6 +382,13 @@ config CHARGER_TPS65090 Say Y here to enable support for battery charging with TPS65090 PMIC chips. +config BATTERY_GAUGE_LTC2941 + tristate "LTC2941/LTC2943 Battery Gauge Driver" + depends on I2C + help + Say Y here to include support for LTC2941 and LTC2943 Battery Gauge + IC. + config AB8500_BM bool "AB8500 Battery Management Driver" depends on AB8500_CORE && AB8500_GPADC
drivers/power/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o +obj-$(CONFIG_BATTERY_GAUGE_LTC2941) += ltc2941-battery-gauge.o obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
drivers/power/ltc2941-battery-gauge.c new file +497 -0
497 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 1/1 Add LTC2941/LTC2943 Battery Gauge Driver
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
v2: Fix units of measurement: uV, uA and centidegrees.
v3: Correctly set configuration register. Allow negative values
for the sense resistor.
--- drivers/power/Kconfig | 7 + drivers/power/Makefile | 1 + drivers/power/ltc2941-battery-gauge.c | 524 +++++++++++++++++++++++++++++++++ 3 files changed, 532 insertions(+) create mode 100644 drivers/power/ltc2941-battery-gauge.c
drivers/power/Kconfig +7 -0
@@ -382,6 +382,13 @@ config CHARGER_TPS65090 Say Y here to enable support for battery charging with TPS65090 PMIC chips. +config BATTERY_GAUGE_LTC2941 + tristate "LTC2941/LTC2943 Battery Gauge Driver" + depends on I2C + help + Say Y here to include support for LTC2941 and LTC2943 Battery Gauge + IC. + config AB8500_BM bool "AB8500 Battery Management Driver" depends on AB8500_CORE && AB8500_GPADC
drivers/power/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o +obj-$(CONFIG_BATTERY_GAUGE_LTC2941) += ltc2941-battery-gauge.o obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
drivers/power/ltc2941-battery-gauge.c new file +524 -0
524 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v4 1/1 Add LTC2941/LTC2943 Battery Gauge Driver
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
v2: Fix units of measurement: uV, uA and centidegrees.
v3: Correctly set configuration register. Allow negative values
for the sense resistor.
v4: Run checkpatch.pl and fix all errors and warnings.
--- drivers/power/Kconfig | 8 + drivers/power/Makefile | 1 + drivers/power/ltc2941-battery-gauge.c | 547 +++++++++++++++++++++++++++++++++ 3 files changed, 556 insertions(+) create mode 100644 drivers/power/ltc2941-battery-gauge.c
drivers/power/Kconfig +8 -0
@@ -382,6 +382,14 @@ config CHARGER_TPS65090 Say Y here to enable support for battery charging with TPS65090 PMIC chips. +config BATTERY_GAUGE_LTC2941 + tristate "LTC2941/LTC2943 Battery Gauge Driver" + depends on I2C + help + Say Y here to include support for LTC2941 and LTC2943 Battery + Gauge IC. The driver reports the charge count continuously, and + measures the voltage and temperature every 10 seconds. + config AB8500_BM bool "AB8500 Battery Management Driver" depends on AB8500_CORE && AB8500_GPADC
drivers/power/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o +obj-$(CONFIG_BATTERY_GAUGE_LTC2941) += ltc2941-battery-gauge.o obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
drivers/power/ltc2941-battery-gauge.c new file +547 -0
547 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH v4] Add LTC2941/LTC2943 Battery Gauge Driver
Hi,
Quoted 25 lines · Mike Looijmans
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
v2: Fix units of measurement: uV, uA and centidegrees.
v3: Correctly set configuration register. Allow negative values
for the sense resistor.
v4: Run checkpatch.pl and fix all errors and warnings.Signed-off-by Mike Looijmans <[email protected]>---
[...]drivers/power/ltc2941-battery-gauge.c new file +8
-0+ np =of_node_get (client->dev.of_node); + +/* r_sense can be negative, when sense+ is connected to the battery +* instead of the sense-. This results in reversed measurements. */ + ret =of_property_read_u32 (np,"resistor-sense" , &r_sense); +if (ret <0 ) { +dev_err (&client->dev, +"Could not find resistor-sense in devicetree\n" );
drivers/power/ltc2941-battery-gauge.c line 432
Quoted 10 lines
drivers/power/ltc2941-battery-gauge.c new file +10
-0+ goto fail_name; + } + info->r_sense = r_sense; + + ret =of_property_read_u32 (np,"prescaler-exponent" , &prescaler_exp); +if (ret <0 ) { +dev_err (&client->dev, +"PrescalerExponent not in devicetree, assume max\n" ); + prescaler_exp =LTC2941_MAX_PRESCALER_EXP ; + }
The device tree properties are not documented. Please document them in a separate patch and Cc devicetree binding maintainers.
Apart from that the properties should be vendor prefixed (e.g. "lltc,resistor-sense").
-- Sebastian
Re: [PATCH v4] Add LTC2941/LTC2943 Battery Gauge Driver
Quoted 42 lines · Sebastian Reichel
Hi,
Quoted 25 lines · Mike Looijmans
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
v2: Fix units of measurement: uV, uA and centidegrees.
v3: Correctly set configuration register. Allow negative values
for the sense resistor.
v4: Run checkpatch.pl and fix all errors and warnings.Signed-off-by Mike Looijmans <[email protected]>---
[...]drivers/power/ltc2941-battery-gauge.c new file +8
-0+ np =of_node_get (client->dev.of_node); + +/* r_sense can be negative, when sense+ is connected to the battery +* instead of the sense-. This results in reversed measurements. */ + ret =of_property_read_u32 (np,"resistor-sense" , &r_sense); +if (ret <0 ) { +dev_err (&client->dev, +"Could not find resistor-sense in devicetree\n" );drivers/power/ltc2941-battery-gauge.c line 432
Quoted 10 lines
drivers/power/ltc2941-battery-gauge.c new file +10
-0+ goto fail_name; + } + info->r_sense = r_sense; + + ret =of_property_read_u32 (np,"prescaler-exponent" , &prescaler_exp); +if (ret <0 ) { +dev_err (&client->dev, +"PrescalerExponent not in devicetree, assume max\n" ); + prescaler_exp =LTC2941_MAX_PRESCALER_EXP ; + }The device tree properties are not documented. Please document them in a separate patch and Cc devicetree binding maintainers.
Quoted 2 lines
Apart from that the properties should be vendor prefixed (e.g. "lltc,resistor-sense").
Thanks for your feedback. I will post the requested changes asap.
Met vriendelijke groet / kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Systems Eindhovenseweg 32-C, NL-5683 KH Best Postbus 440, NL-5680 AK Best
Telefoon: (+31) (0) 499 33 69 79
Telefax: (+31) (0) 499 33 69 70
E-mail: [email protected]
Website: www.topic.nl
Please consider the environment before printing this e-mail
Topic zoekt gedreven (embedded) software specialisten!
http://topic.nl/vacatures/topic-zoekt-software-engineers/
PATCH 1/1 Add LTC2941/LTC2943 Battery Gauge Driver
In reply to Sebastian ReichelBoth the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
v2: Fix units of measurement: uV, uA and centidegrees.
v3: Correctly set configuration register. Allow negative values
for the sense resistor.
v4: Run checkpatch.pl and fix all errors and warnings.
v5: Prefix "lltc," to devicetree properties.
--- drivers/power/Kconfig | 8 + drivers/power/Makefile | 1 + drivers/power/ltc2941-battery-gauge.c | 548 +++++++++++++++++++++++++++++++++ 3 files changed, 557 insertions(+) create mode 100644 drivers/power/ltc2941-battery-gauge.c
drivers/power/Kconfig +8 -0
@@ -382,6 +382,14 @@ config CHARGER_TPS65090 Say Y here to enable support for battery charging with TPS65090 PMIC chips. +config BATTERY_GAUGE_LTC2941 + tristate "LTC2941/LTC2943 Battery Gauge Driver" + depends on I2C + help + Say Y here to include support for LTC2941 and LTC2943 Battery + Gauge IC. The driver reports the charge count continuously, and + measures the voltage and temperature every 10 seconds. + config AB8500_BM bool "AB8500 Battery Management Driver" depends on AB8500_CORE && AB8500_GPADC
drivers/power/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o +obj-$(CONFIG_BATTERY_GAUGE_LTC2941) += ltc2941-battery-gauge.o obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
drivers/power/ltc2941-battery-gauge.c new file +548 -0
548 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH] Add LTC2941/LTC2943 Battery Gauge Driver
Hi,
Quoted 7 lines · Mike Looijmans
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
Applied with .owner field removed.
-- Sebastian
Re: [PATCH] Add LTC2941/LTC2943 Battery Gauge Driver
Quoted 8 lines · Sebastian Reichel
Hi,
Quoted 5 lines · Mike Looijmans
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
Quoted 7 lines
Quoted 2 lines
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
Applied with .owner field removed.
-- Sebastian
Hello,
We found a bug in the LTC2941 driver (typo, it says "58" in the formula which should be "85") just yesterday. I couldn't find it in mainline yet, I'll post a patch to fix it.
Met vriendelijke groet / kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Systems Eindhovenseweg 32-C, NL-5683 KH Best Postbus 440, NL-5680 AK Best
Telefoon: (+31) (0) 499 33 69 79
Telefax: (+31) (0) 499 33 69 70
E-mail: [email protected]
Website: www.topic.nl
Please consider the environment before printing this e-mail
Visit us at Embedded World 2015 Nuernberg, 24.02.2015 till 26.02.2015, Hall 1, stand number 136.
https://www.embedded-world.de/de/ausstellerprodukte/?focus=edb3exhibitor&focus2=14017667&focus3=embwld15&highlight=topic
Re: [PATCH] Add LTC2941/LTC2943 Battery Gauge Driver
Quoted 14 lines · Mike Looijmans
Quoted 13 lines · Sebastian Reichel
Hi,
Quoted 7 lines · Mike Looijmans
Both the LTC2941 and LTC2943 measure battery capacity. The LTC2943 is compatible with the LTC2941, it adds voltage and temperature monitoring, and uses a slightly different conversion formula for the charge counter.
To avoid confusion with e.g. the LTC2945, the driver is called LTC2941 instead of LTC294X.
Applied with .owner field removed.
Quoted 8 lines
Quoted 2 lines
-- Sebastian
Hello,
We found a bug in the LTC2941 driver (typo, it says "58" in the formula which should be "85") just yesterday. I couldn't find it in mainline yet, I'll post a patch to fix it.
pull request has already been sent:
https://lkml.org/lkml/2015/2/9/373
I will send your patch as fix during -rc cycle.
-- Sebastian
PATCH 1/1 Add devicetree binding documentation for the LTC2941/LTC2943 driver
In reply to Sebastian ReichelThis adds the devicetree binding documentation for the LTC2941 and LTC2943 driver. These are I2C connected battery gas gauge ICs.
--- .../devicetree/bindings/power/ltc2941.txt | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/ltc2941.txt
Documentation/devicetree/bindings/power/ltc2941.txt new file +27 -0
@@ -0,0 +1,27 @@ +binding for LTC2941 and LTC2943 battery gauges + +Both the LTC2941 and LTC2943 measure battery capacity. +The LTC2943 is compatible with the LTC2941, it adds voltage and +temperature monitoring, and uses a slightly different conversion +formula for the charge counter. + +Required properties: +- compatible: Should contain "ltc2941" or "ltc2943" which also indicates the + type of I2C chip attached. +- reg: The 7-bit I2C address. +- lltc,resistor-sense: The sense resistor value in milli-ohms. Can be a 32-bit + negative value when the battery has been connected to the wrong end of the + resistor. +- lltc,prescaler-exponent: The prescaler exponent as explained in the datasheet. + This determines the range and accuracy of the gauge. The value is programmed + into the chip only if it differs from the current setting. The setting is + lost when the battery is disconnected. + +Example from the Topic Miami Florida board: + + fuelgauge: ltc2943@64 { + compatible = "ltc2943"; + reg = <0x64>; + lltc,resistor-sense = <15>; + lltc,prescaler-exponent = <5>; /* 2^(2*5) = 1024 */ + };
Signature · 1 line
1.7.9.5
Sebastian Reichel
AppliedRe: [PATCH] Add devicetree binding documentation for the LTC2941/LTC2943 driver
Hi,
Quoted 2 lines · Mike Looijmans
This adds the devicetree binding documentation for the LTC2941 and LTC2943 driver. These are I2C connected battery gas gauge ICs.
Thanks, applied.
-- Sebastian
Re: [PATCH v4] Add LTC2941/LTC2943 Battery Gauge Driver
In reply to Mike LooijmansHi!
drivers/power/ltc2941-battery-gauge.c line 6
Quoted 8 lines
+++
b/drivers/power/ltc2941-battery-gauge.cdrivers/power/ltc2941-battery-gauge.c new file +6
-0@@ -0,0 +1,547 @@ +/* +* I2C client/driver for the Linear Technology LTC2941 and LTC2943 +* Battery Gas Gauge IC +* +* Copyright (C) 2014 Topic Embedded Systems +*
NOrmally GPL notice would go here.
drivers/power/ltc2941-battery-gauge.c line 9
Quoted 3 lines
drivers/power/ltc2941-battery-gauge.c new file +3
-0+* Author: Auryn Verwegen +* Author: Mike Looijmans +*/
Do you want to add yourself as a maintainers?
Quoted 5 lines
drivers/power/ltc2941-battery-gauge.c new file +5
-0+{ +int ret; +struct i2c_msg msgs[2 ] = { }; +u8 reg_start = reg; +
drivers/power/ltc2941-battery-gauge.c line 105
Quoted 10 lines
drivers/power/ltc2941-battery-gauge.c new file +10
-0+ msgs[0 ].addr = client->addr; + msgs[0 ].len =1 ; + msgs[0 ].buf = ®_start; + + msgs[1 ].addr = client->addr; + msgs[1 ].len = num_regs; + msgs[1 ].buf = buf; + msgs[1 ].flags =I2C_M_RD ; + + ret =i2c_transfer (client->adapter, &msgs[0 ],2 );
Here you send byte from kernel stack to i2c device. I'd add msg[0].flags = 0.
drivers/power/ltc2941-battery-gauge.c line 161
Quoted 6 lines
drivers/power/ltc2941-battery-gauge.c new file +6
-0+ ret =ltc294x_write_regs (info->client, +LTC294X_REG_CONTROL , &control,1 ); +if (ret <0 ) { +dev_err (&info->client->dev, +"Could not write register\n" ); + goto error_exit;
return ret; No need to goto when you have nothing to clean up.
drivers/power/ltc2941-battery-gauge.c line 206
Quoted 11 lines
drivers/power/ltc2941-battery-gauge.c new file +10
-0+ } + } + +return 0 ; + +error_exit: +return ret; +} +if (info->Qlsb <0 ) + value +=0xFFFF ;
q_lsb?
drivers/power/ltc2941-battery-gauge.c line 229
Quoted 8 lines
drivers/power/ltc2941-battery-gauge.c new file +8
-0+ dataw[0 ] =I16_MSB (value); + dataw[1 ] =I16_LSB (value); + ret =ltc294x_write_regs (info->client, +LTC294X_REG_ACC_CHARGE_MSB , &dataw[0 ],2 ); +if (ret <0 ) + goto error_exit; +/* Enable analog section */ +error_exit:
Interesting use of goto... remove?
drivers/power/ltc2941-battery-gauge.c line 430
Quoted 4 lines
drivers/power/ltc2941-battery-gauge.c new file +4
-0+ ret =of_property_read_u32 (np,"prescaler-exponent" , &prescaler_exp); +if (ret <0 ) { +dev_err (&client->dev, +"PrescalerExponent not in devicetree, assume max\n" );
assuming?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html