Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp204905pxb; Wed, 4 Nov 2020 19:52:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxh+OFw+hFmnFxZRWRQsfa1Wn/ve7ai0g5+LsUZP+pCy3MatC46oVGPlsQL5W27U7qEISWU X-Received: by 2002:a50:af65:: with SMTP id g92mr219047edd.273.1604548375364; Wed, 04 Nov 2020 19:52:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604548375; cv=none; d=google.com; s=arc-20160816; b=AbPJU8DmWJ/VzkKIoHDtled+JTv6IEGdv+2QXmv0vZJoWLvnHqFjauwlG2fqUjMpHI Zp15uW1EH/VecAMAQLWZIzC7TnOteRYGyxfl35p1OBppP6gauO6i0c77FJ3k20O3eya0 dxGEdGXUaWYoQ0PJXXtEScKHEzU+cOT5C30siAZbg7L00kyFbbz7Ezy6fFKFvAo5orHi qfvGOR2XmABuDlY9Mpsqaj4FwH9jyuVt/Q9FlJsgt3WJF0/cI7iDCV7XxujZzXYqLY3W H0I1E1EoKprnrFUL8zz9GRZ5WA4ST0uETL6rWVXVGs91Qoeg/JCcv6vk1A53nTAjlA3A cfmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version; bh=o+jm92E6XCdBmSGULTYQhcLu1HnFJsf1KTWEvMvNyvY=; b=ZLlW3ZW2G6fNljGA+7zbjwt3Qguf7EFMGcHSh1QxtWca39mj1pLiEr/Cg1r6IlFhW8 s4eaa6DXKXQGJA0ZDxxvggrmehGQuWxlFWydGAIzvcdGqvQyRD+of36eS5z0a2uOcFqK VtwShBVDqxIDHYC4KQ9yJ39yOdH4uYxXxGojmSB2/F0GH+lytj2XqGI0Q8UtF6IDQT2I qRuxgErGpxJajc45r6kteMFgsYJfUmmERTcszbxWP45YyFKYiFVhHO+jFY3Yd7cNHZjV +GQQciV7ZMBS1ok/oVXviw5Fb836wj5IKqA/rTnF/AkBZBtSjA6MksF5Kjjkjxxl4ma2 NAEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si249055ejt.298.2020.11.04.19.52.33; Wed, 04 Nov 2020 19:52:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731587AbgKEA2U (ORCPT + 99 others); Wed, 4 Nov 2020 19:28:20 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:35337 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731562AbgKEA1z (ORCPT ); Wed, 4 Nov 2020 19:27:55 -0500 X-Greylist: delayed 7358 seconds by postgrey-1.27 at vger.kernel.org; Wed, 04 Nov 2020 19:27:54 EST Received: from webmail.gandi.net (webmail15.sd4.0x35.net [10.200.201.15]) (Authenticated sender: contact@artur-rojek.eu) by relay7-d.mail.gandi.net (Postfix) with ESMTPA id 4692D20005; Thu, 5 Nov 2020 00:27:51 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Thu, 05 Nov 2020 01:27:51 +0100 From: Artur Rojek To: Paul Cercueil Cc: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , od@zcrc.me, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC In-Reply-To: References: <20201104192843.67187-1-paul@crapouillou.net> Message-ID: <1a319d53f1fd74b41056663421ef785e@artur-rojek.eu> X-Sender: contact@artur-rojek.eu User-Agent: Roundcube Webmail/1.3.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-11-05 01:09, Paul Cercueil wrote: > Hi Artur, > > Le mer. 4 nov. 2020 à 23:29, Artur Rojek 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 >>> ADC.") >>> Cc: >>> Signed-off-by: Paul Cercueil >>> --- >>> 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 > > 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