Re: Fwd: [PATCH] bq27x00_battery: Some fixes

From: Pali RohÃr
Date: Mon Jan 31 2011 - 13:00:48 EST


2011/1/31 Rodolfo Giometti <giometti@xxxxxxxxxxxx>:
> On Mon, Jan 31, 2011 at 04:54:17PM +0300, Anton Vorontsov wrote:
>> The same is for this patch.
>>
>> Comments, Reviewed-by or Acked-by?
>>
>> p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time()
>> Â Â Âfix to a separate patch.
>>
>> ----- Forwarded message from Pali RohÃr <pali.rohar@xxxxxxxxx> -----
>>
>> Date: Wed, 26 Jan 2011 21:42:39 +0100
>> From: Pali RohÃr <pali.rohar@xxxxxxxxx>
>> To: Anton Vorontsov <cbouatmailru@xxxxxxxxx>
>> Cc: David Woodhouse <dwmw2@xxxxxxxxxxxxx>
>> Subject: Re: [PATCH] bq27x00_battery
>>
>> This patch fix reporting correct (devided by resistor sense) values on
>> bq27000/bq27200 batteries.
>>
>> Signed-off-by: Pali RohÃr <pali.rohar@xxxxxxxxx>
>> Tested-by: Pali RohÃr <pali.rohar@xxxxxxxxx>
>>
>> --- a/drivers/power/bq27x00_battery.c 2011-01-26 21:30:40.000000000 +0100
>> +++ b/drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100
>> @@ -37,10 +37,11 @@
>> Â#define BQ27x00_REG_TTF Â Â Â Â Â Â Â Â Â Â Â0x18
>> Â#define BQ27x00_REG_TTECP Â Â Â Â Â Â0x26
>>
>> +#define BQ27000_RS Â Â Â Â Â Â Â Â Â 20 /* Resistor sense */
>> Â#define BQ27000_REG_RSOC Â Â Â Â Â Â 0x0B /* Relative State-of-Charge */
>> Â#define BQ27000_FLAG_CHGS Â Â Â Â Â ÂBIT(7)
>>
>> -#define BQ27500_REG_SOC Â Â Â Â Â Â Â Â Â Â Â0x2c
>> +#define BQ27500_REG_SOC Â Â Â Â Â Â Â Â Â Â Â0x2C
>> Â#define BQ27500_FLAG_DSC Â Â Â Â Â Â BIT(0)
>> Â#define BQ27500_FLAG_FC Â Â Â Â Â Â Â Â Â Â ÂBIT(9)
>>
>> @@ -112,7 +113,7 @@ static int bq27x00_battery_temperature(s
>> Â}
>>
>> Â/*
>> - * Return the battery Voltage in milivolts
>> + * Return the battery Voltage in ÂV
>> Â * Or < 0 if something fails.
>> Â */
>> Âstatic int bq27x00_battery_voltage(struct bq27x00_device_info *di)
>> @@ -130,7 +131,7 @@ static int bq27x00_battery_voltage(struc
>> Â}
>
> Ok, but I think we should change the function name adding _mV...
>
>>
>> Â/*
>> - * Return the battery average current
>> + * Return the battery average current in ÂA
>> Â * Note that current can be negative signed as well
>> Â * Or 0 if something fails.
>> Â */
>> @@ -149,6 +150,7 @@ static int bq27x00_battery_current(struc
>> Â Â Â if (di->chip == BQ27500) {
>> Â Â Â Â Â Â Â /* bq27500 returns signed value */
>> Â Â Â Â Â Â Â curr = (int)(s16)curr;
>> + Â Â Â Â Â Â curr *= 1000;
>> Â Â Â } else {
>> Â Â Â Â Â Â Â ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
>> Â Â Â Â Â Â Â if (ret < 0) {
>> @@ -159,9 +161,10 @@ static int bq27x00_battery_current(struc
>> Â Â Â Â Â Â Â Â Â Â Â dev_dbg(di->dev, "negative current!\n");
>> Â Â Â Â Â Â Â Â Â Â Â curr = -curr;
>> Â Â Â Â Â Â Â }
>> + Â Â Â Â Â Â curr = curr * 3570 / BQ27000_RS;
>> Â Â Â }
>>
>> - Â Â return curr * 1000;
>> + Â Â return curr;
>> Â}
>
> And here _mA.
>
>> Â/*
>> @@ -233,7 +236,7 @@ static int bq27x00_battery_time(struct b
>> Â Â Â }
>>
>> Â Â Â if (tval == 65535)
>> - Â Â Â Â Â Â return -ENODATA;
>> + Â Â Â Â Â Â tval = 0;
>>
>> Â Â Â val->intval = tval * 60;
>> Â Â Â return 0;
>>
>> ----- End forwarded message -----
>
> Ciao,
>
> Rodolfo
>
> --
>
> GNU/Linux Solutions         Âe-mail: giometti@xxxxxxxxxxxx
> Linux Device Driver             Âgiometti@xxxxxxxx
> Embedded Systems           phone: Â+39 349 2432127
> UNIX programming           skype: Ârodolfo.giometti
> Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
>

Why rename to _mA/_mV? Functions return values in ÂA/ÂV (units from
Documentation/power/power_supply_class.txt)

--
Pali RohÃr
pali.rohar@xxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/