From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A16722069E for ; Wed, 24 Sep 2025 13:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758719847; cv=none; b=PrVTd4Cp3L5vkiLtEq3fnIH80l7l0KiXdc2BBPI0BKycgZHL7s5booahYCV1MsxhSVB4pROCE//Oi2TFdJyqjIhNE9IqbTGWstFj8A4sHBwb7rGb0/1jGD6xU4r1h1kUe3k7oEk0iG1d5vs7igGVSIBFbdo25YmTseOrgcIdvGc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758719847; c=relaxed/simple; bh=nNlhZ3ky71IFd+n9wOyeaZgybeewKfw/SvYwsc4rOOM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NTAzWIPphUdpQS4+HW92spp5bS3Ek2gpthplN1xO6CS87FERj5Gt/O3JT08ZbrJ5j7ncIKhqUbLhAAbOcOwJajFOQEvX/sXcAS2uSM9DT8nmwIZXkxYY1w8UxxeuyINdl3Nwud9wBTegDDxH8zKSAU18ssWCQif/N/d0MPWILWw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=xF6sm1Vj; arc=none smtp.client-ip=209.85.161.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="xF6sm1Vj" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-6218fc7c6b7so1603453eaf.1 for ; Wed, 24 Sep 2025 06:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1758719844; x=1759324644; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=TfzpwQgTHBHYqzRqbLUeQn97RlK5vix1IohjUgnZb8Q=; b=xF6sm1VjFVBtynlSmllYUAtJqUECS0e+rseikvsdgU2AgGLBUqlyjYn09J432Iwo5Y 7fKfZguYR9lJ44G5TP9pew8fHVtORer6osKsKz0BXC6uUWb4O4EqNxnc4Se1tQRwxPJ/ ClY9aK3PNYcLeg3sQqX+65jdkeSho+d/oAUp9ISRTxOo0UZxeckFym7dCcNTGCycZqdC qkqzp2j9xihzqbDgqPANdDJ28Kisa2UPJ1MXL3p0mxPGp0RF2OgIhyNakqRYpkiwUlRq B1//4aTTq3B3afAGyvCG1tmLTTqKs0RUpJtomFBWHH5l4pcaAT5kmxwUsNoEE690l55R mISg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758719844; x=1759324644; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TfzpwQgTHBHYqzRqbLUeQn97RlK5vix1IohjUgnZb8Q=; b=ezWevXy1kFXqAa9jpC3wIGUgnfKLGXkKzJwd+GzVsQ9j9V31zxWxjPYhcnRJQePpvx cG9DBddAHh4Yktc23Pu2zqm+eoSg+CqhMEvVTouV+pXK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f:163b:88d with SMTP id 5614622812f47-43f2d2dbd80mr3060029b6e.18.1758719844018; Wed, 24 Sep 2025 06:17:24 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:1d00:5b03:6cc2:9ec:21f2? ([2600:8803:e7e4:1d00:5b03:6cc2:9ec:21f2]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-344ccf031c7sm3446523fac.24.2025.09.24.06.17.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Sep 2025 06:17:23 -0700 (PDT) Message-ID: <9e20ce95-a401-46ca-94aa-bd4488b45025@baylibre.com> Date: Wed, 24 Sep 2025 08:17:21 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iio: adc: ad7124: fix temperature channel To: =?UTF-8?Q?Uwe_Kleine-K=C3=B6nig?= Cc: Michael Hennerich , Jonathan Cameron , =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20250923-iio-adc-ad7124-fix-temperature-channel-v1-1-e421c98c0d72@baylibre.com> Content-Language: en-US From: David Lechner In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 9/24/25 6:03 AM, Uwe Kleine-König wrote: > Hello David, > > On Tue, Sep 23, 2025 at 03:18:02PM -0500, David Lechner wrote: >> Fix temperature channel not working due to gain and offset not being >> initialized. This was causing the raw temperature readings to be always >> 8388608 (0x800000). >> >> To fix it, we just make sure the gain and offset values are set to the >> default values and still return early without doing an internal >> calibration. >> >> While here, add a comment explaining why we don't bother calibrating >> the temperature channel. >> >> Fixes: 47036a03a303 ("iio: adc: ad7124: Implement internal calibration at probe time") >> Signed-off-by: David Lechner >> --- >> drivers/iio/adc/ad7124.c | 11 +++++++---- >> 1 file changed, 7 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c >> index 374e39736584f55c1290db3e257dff2c60f884d2..94d90a63987c0f9886586db0c4bc1690855be2c1 100644 >> --- a/drivers/iio/adc/ad7124.c >> +++ b/drivers/iio/adc/ad7124.c >> @@ -1518,10 +1518,6 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio >> int ret, i; >> >> for (i = 0; i < st->num_channels; i++) { >> - >> - if (indio_dev->channels[i].type != IIO_VOLTAGE) >> - continue; >> - >> /* >> * For calibration the OFFSET register should hold its reset default >> * value. For the GAIN register there is no such requirement but >> @@ -1531,6 +1527,13 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio >> st->channels[i].cfg.calibration_offset = 0x800000; >> st->channels[i].cfg.calibration_gain = st->gain_default; >> >> + /* >> + * Only the main voltage input channels are important enough >> + * to be automatically calibrated here. >> + */ >> + if (indio_dev->channels[i].type != IIO_VOLTAGE) >> + continue; >> + > > I don't understand a detail of the problem. The commit log suggests that > there is a general problem, but looking at the patch I suspect there is > only a problem if at probe time the OFFSET and GAIN register for the > temperature channel are different from their reset default setting. What I failed to mention is that st->channels[i].cfg.calibration_offset and st->channels[i].cfg.calibration_gain are zero-initialized. And that these values are later programmed into the ADC. Programming these to zero is what caused reading the raw value value to always return a fixed value because the real value got multiplied by 0 in the ADC. Is that enough to clear it up? > > I think the patch is fine, but if my understanding is right the commit > log is more dramatic than the issue really is, as it needs some fiddling > with the ADC's registers between poweron and driver loading to trigger. > > Best regards > Uwe