This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ27421 confusion in TRM

Hi,

I am using BQ27421 for battery measurement in my project.

I am writing a driver for it. I have referred quick start guide and TRM both.

I have some confusion regarding configuration and data reading. Can someone please clarify it?

(1). In configuration flowchart given in quick start guide it is mentioned that to unseal fuel charge we need to do I2C write as follow:

           I2CWriteWord(0x00, 0x8000, 100)               

what is 100 for? delay of 100 ms or us?

(2) To read values such as SOC(state of charge) we first need to write into that register than read or just read?

In quick start guide it is mentioned as follow: 

SOC[2] = I2CReadSubCommand(0x1C, 2, 100);

and definition for I2CReadSubCommand : 

I2CWrite(0x04, 100); 

Buffer[2] = I2CRead(2, 100);

0x04 is address of SOC. so are we writing 100 in it? 

and I2CRead is most confusing , what does that mean?

I have developed driver but it always return 0. Can someone please clarify above 2 points?

Thanks.

  • Hi Maulik,


    I'll start by pointing you to this driver that can initialize the configuration data memory (DM) of ROM based gauges (like bq27421). It's uploaded here:

    https://github.com/aneeshv/linux-bq27xxx

     

    Instructions for cloning:

    git clone https://github.com/aneeshv/linux-bq27xxx.git

    branch: bq274xx-dm-init

     

    What it does:

    In addition to the regular reporting functions (Voltage(), Current(), SOC() etc.) this driver has APIs for reading and writing the DM of the gauge. These APIs are in turn used for initializing the DM of ROM based gauges.

    The initialization happens at startup(about ~65s into the the startup) After startup we poll the status of ITPOR every 6 minutes and repeat the DM initialization if it’s set. The polling happens along with the polling of other parameters such as Current(), SOC() etc and the period for this polling loop is customizable.

    The registers to initialized in the DM may be specified in the code in an array like this:

    static struct dm_reg bq274xx_dm_regs[] = {  {82, 0, 2, 1000}, /* Qmax */  {82, 5, 1, 0x81}, /* Load Select */  {82, 10, 2, 1340}, /* Design Capacity */  {82, 12, 2, 3700}, /* Design Energy */  {82, 16, 2, 3250}, /* Terminate Voltage */  {82, 27, 2, 110}, /* Taper rate */ };

    What it doesn’t:

    It doesn’t have a mechanism to save and restore Ra values and Qmax as suggested in the Quick Start Guide

  • Hi DMax,

    I am using BQ27421-G1A in one of my project which is based on Android Qualcomm processor.

    In that i have used driver suggested by u, from branch : bq274xx-dm-init.

    In that i have added compatible property adding to you driver.PFA patch(driver_change.patch) for changes i made.

    I am able to read/write using I2C, but having one issue :

    I am not able to initialize DM of ROM gauge.And having below kernel logs :

    [    5.116205] bq27x00-battery 4-0055: Gas Guage fw version is 0x0108
    [   18.136198] bq27x00-battery 4-0055: rom_mode_gauge_dm_init: INITCOMP not set after 100 seconds
    [   18.155281] bq27x00-battery 4-0055: support ver. 1.2.0 enabled

    - Also when i am try to read voltage_now reading then it gives proper voltage reading but rom_mode_gauge_dm_init functionality is being failed,

    shell@msm8916_64:/sys/class/power_supply/bq274xx-0 $ cat voltage_now           
    [ 1173.288929] bq27x00-battery 4-0055: rom_mode_gauge_dm_init: INITCOMP not set after 100 seconds
    4196000
    shell@msm8916_64:/sys/class/power_supply/bq274xx-0 $

    Any idea/pointer regarding this error ?

    Regards,

    keval.

    diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
    index c0eb3da..71b118d 100644
    --- a/drivers/power/bq27x00_battery.c
    +++ b/drivers/power/bq27x00_battery.c
    @@ -1768,9 +1768,15 @@ static const struct i2c_device_id bq27x00_id[] = {
     };
     MODULE_DEVICE_TABLE(i2c, bq27x00_id);
     
    +static struct of_device_id bq27421_match_table[] = {
    +        { .compatible = "ti,bq274xx",},
    +        { },
    +};
    +
     static struct i2c_driver bq27x00_battery_driver = {
     	.driver = {
     		.name = "bq27x00-battery",
    +		.of_match_table = bq27421_match_table,
     	},
     	.probe = bq27x00_battery_probe,
     	.remove = bq27x00_battery_remove,