linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bq2415x_charger: fix max battery regulation voltage
@ 2013-10-02 10:24 Alexandre Belloni
  2013-10-15 13:56 ` Pali Rohár
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2013-10-02 10:24 UTC (permalink / raw)
  To: Anton Vorontsov
  Cc: linux-kernel, Pali Rohár, David Woodhouse, Alexandre Belloni

As per the datasheets, maximum battery regulation voltage is 4440mV.

The formula is (voltage - offset) / step, so the maximum value is:
(4440 - 3500) / 20 = 47

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/power/bq2415x_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 0727f92..0aa643e 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -607,7 +607,7 @@ static int bq2415x_set_battery_regulation_voltage(struct bq2415x_device *bq,
 
 	if (val < 0)
 		val = 0;
-	else if (val > 94) /* FIXME: Max is 94 or 122 ? Set max value ? */
+	else if (val > 47)
 		return -EINVAL;
 
 	return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val,
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] bq2415x_charger: fix max battery regulation voltage
  2013-10-02 10:24 [PATCH] bq2415x_charger: fix max battery regulation voltage Alexandre Belloni
@ 2013-10-15 13:56 ` Pali Rohár
  2013-10-15 14:54   ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Pali Rohár @ 2013-10-15 13:56 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Anton Vorontsov, linux-kernel, David Woodhouse

[-- Attachment #1: Type: Text/Plain, Size: 1297 bytes --]

On Wednesday 02 October 2013 12:24:22 Alexandre Belloni wrote:
> As per the datasheets, maximum battery regulation voltage is
> 4440mV.
> 
> The formula is (voltage - offset) / step, so the maximum value
> is: (4440 - 3500) / 20 = 47
> 
> Signed-off-by: Alexandre Belloni
> <alexandre.belloni@free-electrons.com> ---
>  drivers/power/bq2415x_charger.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/bq2415x_charger.c
> b/drivers/power/bq2415x_charger.c index 0727f92..0aa643e
> 100644
> --- a/drivers/power/bq2415x_charger.c
> +++ b/drivers/power/bq2415x_charger.c
> @@ -607,7 +607,7 @@ static int
> bq2415x_set_battery_regulation_voltage(struct bq2415x_device
> *bq,
> 
>  	if (val < 0)
>  		val = 0;
> -	else if (val > 94) /* FIXME: Max is 94 or 122 ? Set max
> value ? */ +	else if (val > 47)
>  		return -EINVAL;
> 
>  	return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val,

Right, max is 47 (101111) and not 94 (1011110). But if you set 
all six registers to 1 then you get 63 (111111) and not 122.

I do not know from where I got above bad values, but you should 
add comment to code that according to datasheet max value is 
4440mV (101111) and not 4760mV (111111).

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] bq2415x_charger: fix max battery regulation voltage
  2013-10-15 13:56 ` Pali Rohár
@ 2013-10-15 14:54   ` Alexandre Belloni
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2013-10-15 14:54 UTC (permalink / raw)
  To: Pali Rohár; +Cc: Anton Vorontsov, linux-kernel, David Woodhouse


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 15/10/2013 15:56, Pali Rohár wrote:
> On Wednesday 02 October 2013 12:24:22 Alexandre Belloni wrote:
>> As per the datasheets, maximum battery regulation voltage is
>> 4440mV.
>>
>> The formula is (voltage - offset) / step, so the maximum value
>> is: (4440 - 3500) / 20 = 47
>>
>> Signed-off-by: Alexandre Belloni
>> <alexandre.belloni@free-electrons.com> ---
>>  drivers/power/bq2415x_charger.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/power/bq2415x_charger.c
>> b/drivers/power/bq2415x_charger.c index 0727f92..0aa643e
>> 100644
>> --- a/drivers/power/bq2415x_charger.c
>> +++ b/drivers/power/bq2415x_charger.c
>> @@ -607,7 +607,7 @@ static int
>> bq2415x_set_battery_regulation_voltage(struct bq2415x_device
>> *bq,
>>
>>      if (val < 0)
>>          val = 0;
>> -    else if (val > 94) /* FIXME: Max is 94 or 122 ? Set max
>> value ? */ +    else if (val > 47)
>>          return -EINVAL;
>>
>>      return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val,
>
> Right, max is 47 (101111) and not 94 (1011110). But if you set
> all six registers to 1 then you get 63 (111111) and not 122.
>
> I do not know from where I got above bad values, but you should
> add comment to code that according to datasheet max value is
> 4440mV (101111) and not 4760mV (111111).
>
You probably missed the division by 2. BTW, I much prefer int val = (mV
- 3500) / 20;
which is clearer: offset is 3500mV and step is 20mV. I find your
calculation quite weird ;)

I'll send V2 with a comment then. Thank you for your review.

- -- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQIcBAEBCAAGBQJSXVcWAAoJEKbNnwlvZCyzfiUQAKkLAbJlnQpNx+CG+tIzb36Q
3/hRTHMb+/Mrr0Db90OPqmJoItVH5WRsf/sRo+6990C95/PNdraM2a/Tibkz+3iD
rww0I01a73w3LBW5tWyN8kj/0iAQFX6h1fzv6dmeAvwZqTk/w7mfm5jv1fjcPYXI
UkTlPSBbH91YnTG9fqVjgpAYxVC64/eGJPMR6sfMnQ/zOWrX7ihGSEbEt8t4s4cX
ouwT5hHu2MmP5WY5IQKJ92+jx4nJsmtuI6HXEQwYPTnCUE8UbQHyezORTQB3cA7H
k0n1ha2SdwMqRkJGxr2T+NFTv1NCD5p72k34kWJPIeF7aFs51i8OiGUskPSBDK89
G9+8zxiD+8dK4B6RqXkq297AgRaNJm9+Ju30r2lrI/NhHocEWsWai+K0L2TF2Oag
4iEdwoQ9BHapcM4jVp2Ik5Oxg7I3909xR0rfWzCGvASPEZseXtgZWYsxZdGy/mZT
+hYaQYmOwV16FWxP+vSMWQPqW477E0q773j8ArnDx4gSta6+FTxfFeMYOFwF3leQ
FltSuDsKxVtip3Rzg77nbMdx6yTkWPvVgWH72grxSYaNYjQY2+pWhTXYOo2hZYzv
Ljr24qvYfzPiMpzMBFZDrm8SZ9LTKHsuKaLgLPTiHrJi+jS9aRK8avgYYNyyiVRP
60UKJwXam6LOq9/qW0eb
=n54z
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] bq2415x_charger: fix max battery regulation voltage
  2013-10-16 14:09 ` Alexandre Belloni
@ 2013-10-25 23:25   ` Anton Vorontsov
  0 siblings, 0 replies; 6+ messages in thread
From: Anton Vorontsov @ 2013-10-25 23:25 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: linux-kernel, Pali Rohár, David Woodhouse

On Wed, Oct 16, 2013 at 04:09:40PM +0200, Alexandre Belloni wrote:
> I forgot to add this is a v2 and I just added a comment.
> 
> On 16/10/2013 16:08, Alexandre Belloni wrote:
> > As per the datasheets, maximum battery regulation voltage is 4440mV.
> >
> > The formula is (voltage - offset) / step, so the maximum value is:
> > (4440 - 3500) / 20 = 47
> >
> > Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

Applied, thanks!

Anton

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] bq2415x_charger: fix max battery regulation voltage
  2013-10-16 14:08 Alexandre Belloni
@ 2013-10-16 14:09 ` Alexandre Belloni
  2013-10-25 23:25   ` Anton Vorontsov
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2013-10-16 14:09 UTC (permalink / raw)
  To: Alexandre Belloni, Anton Vorontsov
  Cc: linux-kernel, Pali Rohár, David Woodhouse

Hi,

I forgot to add this is a v2 and I just added a comment.

On 16/10/2013 16:08, Alexandre Belloni wrote:
> As per the datasheets, maximum battery regulation voltage is 4440mV.
>
> The formula is (voltage - offset) / step, so the maximum value is:
> (4440 - 3500) / 20 = 47
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
>  drivers/power/bq2415x_charger.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
> index 0727f92..df893dd 100644
> --- a/drivers/power/bq2415x_charger.c
> +++ b/drivers/power/bq2415x_charger.c
> @@ -605,9 +605,13 @@ static int bq2415x_set_battery_regulation_voltage(struct bq2415x_device *bq,
>  {
>  	int val = (mV/10 - 350) / 2;
>  
> +	/*
> +	 * According to datasheet, maximum battery regulation voltage is
> +	 * 4440mV which is b101111 = 47.
> +	 */
>  	if (val < 0)
>  		val = 0;
> -	else if (val > 94) /* FIXME: Max is 94 or 122 ? Set max value ? */
> +	else if (val > 47)
>  		return -EINVAL;
>  
>  	return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val,


-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] bq2415x_charger: fix max battery regulation voltage
@ 2013-10-16 14:08 Alexandre Belloni
  2013-10-16 14:09 ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2013-10-16 14:08 UTC (permalink / raw)
  To: Anton Vorontsov
  Cc: linux-kernel, Pali Rohár, David Woodhouse, Alexandre Belloni

As per the datasheets, maximum battery regulation voltage is 4440mV.

The formula is (voltage - offset) / step, so the maximum value is:
(4440 - 3500) / 20 = 47

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/power/bq2415x_charger.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 0727f92..df893dd 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -605,9 +605,13 @@ static int bq2415x_set_battery_regulation_voltage(struct bq2415x_device *bq,
 {
 	int val = (mV/10 - 350) / 2;
 
+	/*
+	 * According to datasheet, maximum battery regulation voltage is
+	 * 4440mV which is b101111 = 47.
+	 */
 	if (val < 0)
 		val = 0;
-	else if (val > 94) /* FIXME: Max is 94 or 122 ? Set max value ? */
+	else if (val > 47)
 		return -EINVAL;
 
 	return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val,
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-10-25 23:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-02 10:24 [PATCH] bq2415x_charger: fix max battery regulation voltage Alexandre Belloni
2013-10-15 13:56 ` Pali Rohár
2013-10-15 14:54   ` Alexandre Belloni
2013-10-16 14:08 Alexandre Belloni
2013-10-16 14:09 ` Alexandre Belloni
2013-10-25 23:25   ` Anton Vorontsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).