Letux Kernel

Issue 716: bq27xxx driver - reprogram design capacity from DT if needed

Reported by Nikolaus Schaller, Apr 9, 2016

The Pyra has a bq27621 fuel gauge chip. This assumes a nominal 
capacity by design of 2450 mAh.

The Pyra battery has 6000 mAh which should be defined in the device 
tree node of the bq27621 chip (or a battery subnode).

To fix the calculations of empty/full battery the driver

http://lxr.free-electrons.com/source/drivers/power/bq27xxx_battery.c

should reprogram the bq27621 chip during probing (or if it finds a 
mismatch of registers 0x3C and 0x3D).

The procedure to update the DESIGN_CAPACITY register is described 
here:

http://www.ti.com/lit/ug/sluuad4c/sluuad4c.pdf

see section "3.1 Data Memory Parameter Update Example" on 
page 12.

A good solution appears to be to patch

http://lxr.free-electrons.com/source/drivers/power/bq27xxx_battery.c#
L714

by adding a check if the design capacity matches a DT node entry and 
try a reprogram on mismatch.

Comment 1 by Nikolaus Schaller, Apr 18, 2016

Labels: Device:Pyra, Device: GTA04A5

Comment 2 by Nikolaus Schaller, Apr 22, 2016

Labels: Device:Pyra Device:GTA04A5 Device:Pyra, Device: GTA04A5

Comment 3 by Nikolaus Schaller, Aug 9, 2016

Summary: bq27xxx driver - reprogram design capacity from DT if needed

Comment 4 by Nikolaus Schaller, Nov 15, 2016

There is a code fragment that detects a discrepancy but does not yet 
reprogram the chip as described above:

http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/
work/hns/power/bq27xxx

Comment 5 by Nikolaus Schaller, Jan 8, 2017

writing to the bus needs to extend the access_methods:

http://lxr.free-electrons.com/source/include/linux/power/bq27xxx_batt
ery.h#L32

and platform data (check if we really need this if only i2c devices 
can be re-programmed):

http://lxr.free-electrons.com/source/drivers/w1/slaves/w1_bq27000.c#L
42

we certainly need to add a write_i2c function

http://lxr.free-electrons.com/source/drivers/power/supply/bq27xxx_bat
tery_i2c.c#L36
Labels: Type:Enhancement Type:Defect

Comment 6 by Nikolaus Schaller, Jan 13, 2017

Has been added to feature branch:
http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/
work/hns/power/bq27xxx

Unfortunately trying to bring the chip into programming mode fails:

root@letux:~# dmesg|fgrep bq27
[    6.586310] bq27xxx-battery 1-0055: support ver. 1.2.0 enabled
[    6.595440] bq27xxx-battery 1-0055: mismatch in battery capacity: 
1340000 instead of 6000000
[    6.595446] bq27xxx_battery_i2c_write 00 8000 => wr 0x00 0x00 
0x80 [2]
[    6.595836] bq27xxx_battery_i2c_write 00 8000 => wr 0x00 0x00 
0x80 [2]
[    6.596509] bq27xxx_battery_i2c_write 00 0013 => wr 0x00 0x13 
0x00 [2]
[    7.610639] bq27xxx-battery 1-0055: unable to switch to 
programming mode (timeout)
root@letux:~# 

Another thing not implemented is to check for a "battery" 
subnode which defines the battery capacity (and potentially other 
parameters).
Labels: Device:GTA04A5
Status: Accepted
Owner: hns

Comment 7 by Nikolaus Schaller, Jul 16, 2017

It seems as if a solution arrived upstream in 4.13-rc1:

http://elixir.free-electrons.com/linux/v4.13-rc1/source/include/linux
/power_supply.h#L302

For details and examples how to set up the DT see:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/co
mmit/?id=e2517f3bb44b1ac3772858f4bca0be05d36f492d

So we do no longer need to develop our own driver patches. Just need 
to update the DT.
Labels: Priority:Medium Priority:Critical

Comment 8 by Nikolaus Schaller, Jul 18, 2017

First rough test with letux-4.13-rc1 shows:

bq27xxx-battery 1-0055: data memory update not supported for chip

This comes because di->dm_regs == NULL. So something is wrong or 
missing.

Mainly I do not understand how di->dm_regs is intended to be set. 
I have not found any code setting the pointer. Not even in 
linux-next.

Comment 9 by Grazvydas Ignotas, Aug 28, 2017

I've fixed the reprogramming itself, code available here:
https://dev.pyra-handheld.com/notaz/pyra-kernel/commits/pyra-4.10

I can send it as patches, if needed.

Comment 10 by Nikolaus Schaller, Aug 29, 2017

Fixed with new 4.13-rc7 + patches from LKML:

http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/
work/hns/power/bq27xxx-v2
Status: Fixed

Created: 8 years 6 months ago by Nikolaus Schaller

Updated: 7 years 1 month ago

Status: Fixed

Owner: Nikolaus Schaller

Followed by: 1 person

Labels:
Priority:Medium
Type:Enhancement
Device:Pyra