Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp107549pxb; Wed, 4 Nov 2020 16:11:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVSvx2xlWZUVo4rY30JXk7pbGcoGa7mNfu01dDyxVQwk0Jfw86YbmtlVa4Jr5XcQ9B9pJR X-Received: by 2002:a17:906:3fc5:: with SMTP id k5mr649555ejj.158.1604535098145; Wed, 04 Nov 2020 16:11:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604535098; cv=none; d=google.com; s=arc-20160816; b=jKCncdHC665WiAAj1RpOagpsOMmEAo/Z90blwYd56sQmokhpLvT3FBmF+Ph9Cda2Yr KijP0JGXuocP7RzsokB6bAtY0wisLVGbVwKwc2QY0GT2sRVp+Rj7aMgcrlQ/oHas4hTw zTaf6BKud/SpU8hpN9YQT+e2g7ouFH79gFefkVHkaeXz+3a9hUHFUVuszkTfstsDLvXk 1EhUs2CFro/UonkqacWmfnrE8jinOOpmnGDCQ3KO/9xJbom0ioxZdf7+XaebCoEBg9xF /uYP+Lpt5EVsS7x5Aiqf8P0IkMSuVlQvV8n/PxeQ9e9N1k1HvSPDoyisWJOQhbdd20h4 bnYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:cc:to:subject:from:date; bh=hAUfVKJFhmgs8Wz6Jb0ZxqYZTfiA2hPw5FnCmVvvbr4=; b=jbclwLWYw6zNwYflx8PPI6sVmIyV5tLcpfOpo9gIqxw7LQO5PgB1w+IyMSNLMGmejk ZktalEdWSApokxgJhp7cdMH4rjoID6mcTjS64ArMqiD47PN1t6CRzklr1YJVA6UzWFco Z8lDyeHSCa5ZwMTrbYS3BaWOb+iEG+doA034X7KR7qAyrRAWHsybD5dyit2+1NO+amgU y3tFdHOYqGTatH5wyuUFnEtazwPGO8XgnRi3RwetNJjGdUnhC5GoUNoGZvmLRTRAfzIB IG68bADuhoYPGuc6mUeEuCCGmbIQ/w7seHLYGrG6UlQ7HqYI0YOGQscYwbt1dzaf9/co /8tA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si2350837eds.235.2020.11.04.16.11.15; Wed, 04 Nov 2020 16:11:38 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732879AbgKEAJc convert rfc822-to-8bit (ORCPT + 99 others); Wed, 4 Nov 2020 19:09:32 -0500 Received: from aposti.net ([89.234.176.197]:50840 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728323AbgKEAJb (ORCPT ); Wed, 4 Nov 2020 19:09:31 -0500 Date: Thu, 05 Nov 2020 00:09:15 +0000 From: Paul Cercueil Subject: Re: [PATCH] iio/adc: ingenic: Fix battery VREF for JZ4770 SoC To: Artur Rojek 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 Message-Id: In-Reply-To: References: <20201104192843.67187-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 :) 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