From: David Lechner <dlechner@baylibre.com>
To: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Cc: "Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ad7124: fix temperature channel
Date: Wed, 24 Sep 2025 08:22:21 -0500 [thread overview]
Message-ID: <f8af47c8-b2e4-45b6-8c2d-36f952327d00@baylibre.com> (raw)
In-Reply-To: <aNPrlIYGrB8oSsfL@debian-BULLSEYE-live-builder-AMD64>
On 9/24/25 8:01 AM, Marcelo Schmitt wrote:
> Hi,
>
> On 09/23, 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).
>
> Would
> 'Fix temperature channel not working due to gain and offset not being
> initialized to their default values.'
> be a more accurate description?
>
>
>>
>> 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 <dlechner@baylibre.com>
>> ---
> ...
>> 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.
> I think it would be more accurate to just say the offset and callibscale
> for temperature channel need to be at default values for the data sheet's
> equation for the temperature sensor to be accurate.
This is true for all channels, not just the temperature channel and
there is an existing comment (partially visible above) that says
something like this already.
>
>
>> + */
>> + if (indio_dev->channels[i].type != IIO_VOLTAGE)
>> + continue;
>> +
>> /*
>> * Full-scale calibration isn't supported at gain 1, so skip in
>> * that case. Note that untypically full-scale calibration has
>
> Maybe, instead of moving the 'if(... IIO_VOLTAGE)' check, this could alternatively
> be set when initializing the temperature channel at ad7124_parse_channel_config().
>
> if (num_channels < AD7124_MAX_CHANNELS) {
> st->channels[num_channels] = (struct ad7124_channel) {
> .nr = num_channels,
> .ain = FIELD_PREP(AD7124_CHANNEL_AINP, AD7124_CHANNEL_AINx_TEMPSENSOR) |
> FIELD_PREP(AD7124_CHANNEL_AINM, AD7124_CHANNEL_AINx_AVSS),
> .cfg = {
> .bipolar = true,
> + .calibration_offset = 0x800000,
> + .calibration_gain = st->gain_default,
st->gain_default has not been initialized at this point, so this would
not work without more rearranging.
> },
> };
>
> chan[num_channels] = (struct iio_chan_spec) {
> .type = IIO_TEMP,
>
>
> Nevertheless, the current fix looks good to me as it is, so
> Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
>
>>
>> ---
>> base-commit: 411e8b72c181e4f49352c12ced0fd8426eb683aa
>> change-id: 20250923-iio-adc-ad7124-fix-temperature-channel-5900f7302886
>>
>> Best regards,
>> --
>> David Lechner <dlechner@baylibre.com>
>>
>>
prev parent reply other threads:[~2025-09-24 13:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 20:18 David Lechner
2025-09-24 11:03 ` Uwe Kleine-König
2025-09-24 13:17 ` David Lechner
2025-09-24 14:33 ` Uwe Kleine-König
2025-09-24 13:01 ` Marcelo Schmitt
2025-09-24 13:22 ` David Lechner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f8af47c8-b2e4-45b6-8c2d-36f952327d00@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=nuno.sa@analog.com \
--cc=u.kleine-koenig@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®