linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC
@ 2020-11-04 19:28 Paul Cercueil
  2020-11-04 22:29 ` Artur Rojek
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Cercueil @ 2020-11-04 19:28 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Artur Rojek
  Cc: od, linux-iio, linux-kernel, Paul Cercueil, stable

The reference voltage for the battery is clearly marked as 1.2V in the
programming manual. With this fixed, the battery channel now returns
correct values.

Fixes: a515d6488505 ("IIO: Ingenic JZ47xx: Add support for JZ4770 SoC ADC.")
Cc: <stable@vger.kernel.org>
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 drivers/iio/adc/ingenic-adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c
index ecaff6a9b716..19b95905a45c 100644
--- a/drivers/iio/adc/ingenic-adc.c
+++ b/drivers/iio/adc/ingenic-adc.c
@@ -71,7 +71,7 @@
 #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS	10
 #define JZ4740_ADC_BATTERY_HIGH_VREF		(7500 * 0.986)
 #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS	12
-#define JZ4770_ADC_BATTERY_VREF			6600
+#define JZ4770_ADC_BATTERY_VREF			1200
 #define JZ4770_ADC_BATTERY_VREF_BITS		12
 
 #define JZ_ADC_IRQ_AUX			BIT(0)
-- 
2.28.0


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

* Re: [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC
  2020-11-04 19:28 [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC Paul Cercueil
@ 2020-11-04 22:29 ` Artur Rojek
  2020-11-05  0:09   ` Paul Cercueil
  0 siblings, 1 reply; 5+ messages in thread
From: Artur Rojek @ 2020-11-04 22:29 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald-Stadler, od,
	linux-iio, linux-kernel, stable

Hi Paul,

On 2020-11-04 20:28, Paul Cercueil wrote:
> The reference voltage for the battery is clearly marked as 1.2V in the
> programming manual. With this fixed, the battery channel now returns
> correct values.
> 
> Fixes: a515d6488505 ("IIO: Ingenic JZ47xx: Add support for JZ4770 SoC 
> ADC.")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  drivers/iio/adc/ingenic-adc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ingenic-adc.c 
> b/drivers/iio/adc/ingenic-adc.c
> index ecaff6a9b716..19b95905a45c 100644
> --- a/drivers/iio/adc/ingenic-adc.c
> +++ b/drivers/iio/adc/ingenic-adc.c
> @@ -71,7 +71,7 @@
>  #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS	10
>  #define JZ4740_ADC_BATTERY_HIGH_VREF		(7500 * 0.986)
>  #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS	12
> -#define JZ4770_ADC_BATTERY_VREF			6600
> +#define JZ4770_ADC_BATTERY_VREF			1200
>  #define JZ4770_ADC_BATTERY_VREF_BITS		12
> 
>  #define JZ_ADC_IRQ_AUX			BIT(0)

I thought we set it to 6600 because GCW Zero was not showing correct 
battery values at 1200.
But if you verified that 1200 works with JZ4770, then:
Acked-by: Artur Rojek <contact@artur-rojek.eu>

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

* Re: [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC
  2020-11-04 22:29 ` Artur Rojek
@ 2020-11-05  0:09   ` Paul Cercueil
  2020-11-05  0:27     ` Artur Rojek
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Cercueil @ 2020-11-05  0:09 UTC (permalink / raw)
  To: Artur Rojek
  Cc: Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald-Stadler, od,
	linux-iio, linux-kernel, stable

Hi Artur,

Le mer. 4 nov. 2020 à 23:29, Artur Rojek <contact@artur-rojek.eu> a 
écrit :
> Hi Paul,
> 
> On 2020-11-04 20:28, Paul Cercueil wrote:
>> The reference voltage for the battery is clearly marked as 1.2V in 
>> the
>> programming manual. With this fixed, the battery channel now returns
>> correct values.
>> 
>> Fixes: a515d6488505 ("IIO: Ingenic JZ47xx: Add support for JZ4770 
>> SoC \x7fADC.")
>> Cc: <stable@vger.kernel.org>
>> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>> ---
>>  drivers/iio/adc/ingenic-adc.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/iio/adc/ingenic-adc.c 
>> \x7fb/drivers/iio/adc/ingenic-adc.c
>> index ecaff6a9b716..19b95905a45c 100644
>> --- a/drivers/iio/adc/ingenic-adc.c
>> +++ b/drivers/iio/adc/ingenic-adc.c
>> @@ -71,7 +71,7 @@
>>  #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS	10
>>  #define JZ4740_ADC_BATTERY_HIGH_VREF		(7500 * 0.986)
>>  #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS	12
>> -#define JZ4770_ADC_BATTERY_VREF			6600
>> +#define JZ4770_ADC_BATTERY_VREF			1200
>>  #define JZ4770_ADC_BATTERY_VREF_BITS		12
>> 
>>  #define JZ_ADC_IRQ_AUX			BIT(0)
> 
> I thought we set it to 6600 because GCW Zero was not showing correct 
> battery values at 1200.
> But if you verified that 1200 works with JZ4770, then:
> Acked-by: Artur Rojek <contact@artur-rojek.eu>

Yes, IIRC we were trying to figure out the range and settled with 
[-3.3V,+3.3V] since it would give "plausible" values but which were 
never quite right. The doc does say that the voltage is (hw_val / 4096) 
* 1.2V, but also says that the ADC operated with 3.3V power supply, I 
guess we got confused. We never considered the battery could not be 
connected directly to the ADC's VBAT pin, so a 1.2V reference didn't 
make sense at that time. I guess we need to learn about electronics :)

It turns out the battery is connected to the VBAT pin with a 1 MOhm 
resistor, and the VBAT pin is also pulled low with a 332 kOhm resistor. 
So a fully charged battery with 4.2V reads as (4.2V * 332000) / 
(1332000) = 1.05V, which totally fits in a [0V,+1.2V] range.

With that same 4.2V battery I get a hardware value of about 3584, and 
(3584 / 4096) * 1.2V == 1.05V, which matches the value computed above. 
So the battery reading looks accurate this time.

Cheers,
-Paul



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

* Re: [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC
  2020-11-05  0:09   ` Paul Cercueil
@ 2020-11-05  0:27     ` Artur Rojek
  2020-11-08 15:34       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Artur Rojek @ 2020-11-05  0:27 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald-Stadler, od,
	linux-iio, linux-kernel, stable

On 2020-11-05 01:09, Paul Cercueil wrote:
> Hi Artur,
> 
> Le mer. 4 nov. 2020 à 23:29, Artur Rojek <contact@artur-rojek.eu> a 
> écrit :
>> Hi Paul,
>> 
>> On 2020-11-04 20:28, Paul Cercueil wrote:
>>> The reference voltage for the battery is clearly marked as 1.2V in 
>>> the
>>> programming manual. With this fixed, the battery channel now returns
>>> correct values.
>>> 
>>> Fixes: a515d6488505 ("IIO: Ingenic JZ47xx: Add support for JZ4770 SoC 
>>> \x7fADC.")
>>> Cc: <stable@vger.kernel.org>
>>> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>> ---
>>>  drivers/iio/adc/ingenic-adc.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>> 
>>> diff --git a/drivers/iio/adc/ingenic-adc.c 
>>> \x7fb/drivers/iio/adc/ingenic-adc.c
>>> index ecaff6a9b716..19b95905a45c 100644
>>> --- a/drivers/iio/adc/ingenic-adc.c
>>> +++ b/drivers/iio/adc/ingenic-adc.c
>>> @@ -71,7 +71,7 @@
>>>  #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS	10
>>>  #define JZ4740_ADC_BATTERY_HIGH_VREF		(7500 * 0.986)
>>>  #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS	12
>>> -#define JZ4770_ADC_BATTERY_VREF			6600
>>> +#define JZ4770_ADC_BATTERY_VREF			1200
>>>  #define JZ4770_ADC_BATTERY_VREF_BITS		12
>>> 
>>>  #define JZ_ADC_IRQ_AUX			BIT(0)
>> 
>> I thought we set it to 6600 because GCW Zero was not showing correct 
>> battery values at 1200.
>> But if you verified that 1200 works with JZ4770, then:
>> Acked-by: Artur Rojek <contact@artur-rojek.eu>
> 
> Yes, IIRC we were trying to figure out the range and settled with
> [-3.3V,+3.3V] since it would give "plausible" values but which were
> never quite right. The doc does say that the voltage is (hw_val /
> 4096) * 1.2V, but also says that the ADC operated with 3.3V power
> supply, I guess we got confused. We never considered the battery could
> not be connected directly to the ADC's VBAT pin, so a 1.2V reference
> didn't make sense at that time. I guess we need to learn about
> electronics :)
Yes we do :)
> 
> It turns out the battery is connected to the VBAT pin with a 1 MOhm
> resistor, and the VBAT pin is also pulled low with a 332 kOhm
> resistor. So a fully charged battery with 4.2V reads as (4.2V *
> 332000) / (1332000) = 1.05V, which totally fits in a [0V,+1.2V] range.
> 
> With that same 4.2V battery I get a hardware value of about 3584, and
> (3584 / 4096) * 1.2V == 1.05V, which matches the value computed above.
> So the battery reading looks accurate this time.
Excellent! Thanks for the detailed explanation.

Cheers,
Artur
> 
> Cheers,
> -Paul

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

* Re: [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC
  2020-11-05  0:27     ` Artur Rojek
@ 2020-11-08 15:34       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2020-11-08 15:34 UTC (permalink / raw)
  To: Artur Rojek
  Cc: Paul Cercueil, Lars-Peter Clausen, Peter Meerwald-Stadler, od,
	linux-iio, linux-kernel, stable

On Thu, 05 Nov 2020 01:27:51 +0100
Artur Rojek <contact@artur-rojek.eu> wrote:

> On 2020-11-05 01:09, Paul Cercueil wrote:
> > Hi Artur,
> > 
> > Le mer. 4 nov. 2020 à 23:29, Artur Rojek <contact@artur-rojek.eu> a 
> > écrit :  
> >> Hi Paul,
> >> 
> >> On 2020-11-04 20:28, Paul Cercueil wrote:  
> >>> The reference voltage for the battery is clearly marked as 1.2V in 
> >>> the
> >>> programming manual. With this fixed, the battery channel now returns
> >>> correct values.
> >>> 
> >>> Fixes: a515d6488505 ("IIO: Ingenic JZ47xx: Add support for JZ4770 SoC 
> >>> \x7fADC.")
> >>> Cc: <stable@vger.kernel.org>
> >>> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> >>> ---
> >>>  drivers/iio/adc/ingenic-adc.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>> 
> >>> diff --git a/drivers/iio/adc/ingenic-adc.c 
> >>> \x7fb/drivers/iio/adc/ingenic-adc.c
> >>> index ecaff6a9b716..19b95905a45c 100644
> >>> --- a/drivers/iio/adc/ingenic-adc.c
> >>> +++ b/drivers/iio/adc/ingenic-adc.c
> >>> @@ -71,7 +71,7 @@
> >>>  #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS	10
> >>>  #define JZ4740_ADC_BATTERY_HIGH_VREF		(7500 * 0.986)
> >>>  #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS	12
> >>> -#define JZ4770_ADC_BATTERY_VREF			6600
> >>> +#define JZ4770_ADC_BATTERY_VREF			1200
> >>>  #define JZ4770_ADC_BATTERY_VREF_BITS		12
> >>> 
> >>>  #define JZ_ADC_IRQ_AUX			BIT(0)  
> >> 
> >> I thought we set it to 6600 because GCW Zero was not showing correct 
> >> battery values at 1200.
> >> But if you verified that 1200 works with JZ4770, then:
> >> Acked-by: Artur Rojek <contact@artur-rojek.eu>  
> > 
> > Yes, IIRC we were trying to figure out the range and settled with
> > [-3.3V,+3.3V] since it would give "plausible" values but which were
> > never quite right. The doc does say that the voltage is (hw_val /
> > 4096) * 1.2V, but also says that the ADC operated with 3.3V power
> > supply, I guess we got confused. We never considered the battery could
> > not be connected directly to the ADC's VBAT pin, so a 1.2V reference
> > didn't make sense at that time. I guess we need to learn about
> > electronics :)  
> Yes we do :)
> > 
> > It turns out the battery is connected to the VBAT pin with a 1 MOhm
> > resistor, and the VBAT pin is also pulled low with a 332 kOhm
> > resistor. So a fully charged battery with 4.2V reads as (4.2V *
> > 332000) / (1332000) = 1.05V, which totally fits in a [0V,+1.2V] range.
> > 
> > With that same 4.2V battery I get a hardware value of about 3584, and
> > (3584 / 4096) * 1.2V == 1.05V, which matches the value computed above.
> > So the battery reading looks accurate this time.  
> Excellent! Thanks for the detailed explanation.

Applied to the fixes-togreg branch of iio.git

Thanks,

Jonathan

> 
> Cheers,
> Artur
> > 
> > Cheers,
> > -Paul  


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

end of thread, other threads:[~2020-11-08 15:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04 19:28 [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC Paul Cercueil
2020-11-04 22:29 ` Artur Rojek
2020-11-05  0:09   ` Paul Cercueil
2020-11-05  0:27     ` Artur Rojek
2020-11-08 15:34       ` Jonathan Cameron

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).