From: "Nuno Sá" <noname.nuno@gmail.com>
To: Marcelo Schmitt <marcelo.schmitt@analog.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: jic23@kernel.org, lars@metafoo.de, Michael.Hennerich@analog.com,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
marcelo.schmitt1@gmail.com
Subject: Re: [PATCH v1 6/7] iio: adc: ad4170: Add support for internal temperature sensor
Date: Thu, 10 Apr 2025 11:03:41 +0100 [thread overview]
Message-ID: <8c785dcda6d22a4a50a2d3994248c33fee69031f.camel@gmail.com> (raw)
In-Reply-To: <33ed56211aed85df1bcb86d5fea83991441dbec0.1744200264.git.marcelo.schmitt@analog.com>
On Wed, 2025-04-09 at 09:26 -0300, Marcelo Schmitt wrote:
> The AD4170 has an internal temperature sensor that can be read using the
> ADC. Whenever possible, configure an IIO channel to provide the chip's
> temperature.
>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
> ---
One minor nit... Otherwise looks good:
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> drivers/iio/adc/ad4170.c | 72 ++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 69 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ad4170.c b/drivers/iio/adc/ad4170.c
> index b382e7f3dbe0..d204f8ca840f 100644
> --- a/drivers/iio/adc/ad4170.c
> +++ b/drivers/iio/adc/ad4170.c
> @@ -922,6 +922,27 @@ static const struct iio_chan_spec ad4170_channel_template
> = {
> },
> };
>
> +static const struct iio_chan_spec ad4170_temp_channel_template = {
> + .type = IIO_TEMP,
> + .indexed = 0,
> + .channel = 17,
> + .channel2 = 17,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE) |
> + BIT(IIO_CHAN_INFO_OFFSET) |
> + BIT(IIO_CHAN_INFO_CALIBSCALE) |
> + BIT(IIO_CHAN_INFO_CALIBBIAS) |
> + BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .scan_type = {
> + .sign = 's',
> + .realbits = 24,
> + .storagebits = 32,
> + .shift = 8,
> + .endianness = IIO_BE,
> + },
> +};
> +
> /*
> * Receives the number of a multiplexed AD4170 input (ain_n), and stores the
> * voltage (in µV) of the specified input into ain_voltage. If the input
> number
> @@ -1209,9 +1230,27 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
> return ret;
> case IIO_CHAN_INFO_SCALE:
> pga = FIELD_GET(AD4170_AFE_PGA_GAIN_MSK, setup->afe);
> - *val = chan_info->scale_tbl[pga][0];
> - *val2 = chan_info->scale_tbl[pga][1];
> - return IIO_VAL_INT_PLUS_NANO;
> + switch (chan->type) {
> + case IIO_VOLTAGE:
> + *val = chan_info->scale_tbl[pga][0];
> + *val2 = chan_info->scale_tbl[pga][1];
> + return IIO_VAL_INT_PLUS_NANO;
> +
> + case IIO_TEMP:
> + /*
> + * The scale_tbl converts output codes to mV units so
> + * multiply by MILLI to make the factor convert to
> µV.
> + * Then, apply the temperature sensor change
> sensitivity
> + * of 477 μV/K. Finally, multiply the result by MILLI
> + * again to comply with milli degrees Celsius IIO
> ABI.
> + */
> + *val = 0; /* The scale integer part is always 0. */
Hmm this comment does not add much...
> + *val2 = DIV_ROUND_CLOSEST(chan_info-
> >scale_tbl[pga][1] * MILLI,
> + 477) * MILLI;
> + return IIO_VAL_INT_PLUS_NANO;
> + default:
> + return -EINVAL;
> + }
> case IIO_CHAN_INFO_OFFSET:
> pga = FIELD_GET(AD4170_AFE_PGA_GAIN_MSK, setup->afe);
> *val = chan_info->offset_tbl[pga];
> @@ -1855,12 +1894,39 @@ static int ad4170_parse_channels(struct iio_dev
> *indio_dev)
> if (num_channels > AD4170_MAX_CHANNELS)
> return dev_err_probe(dev, -EINVAL, "Too many channels\n");
>
> + /* Add one for temperature */
> + num_channels = min(num_channels + 1, AD4170_MAX_CHANNELS);
> +
> device_for_each_child_node_scoped(dev, child) {
> ret = ad4170_parse_channel_node(indio_dev, child,
> chan_num++);
> if (ret)
> return ret;
> }
>
> + /*
> + * Add internal temperature sensor channel if the maximum number of
> + * channels has not been reached.
> + */
> + if (num_channels < AD4170_MAX_CHANNELS) {
> + struct ad4170_setup *setup = &st->chan_infos[chan_num].setup;
> +
> + st->chans[chan_num] = ad4170_temp_channel_template;
> + st->chans[chan_num].address = chan_num;
> + st->chans[chan_num].scan_index = chan_num;
> +
> + st->chan_infos[chan_num].setup_num = AD4170_INVALID_SETUP;
> + st->chan_infos[chan_num].initialized = true;
> +
> + setup->afe |= FIELD_PREP(AD4170_AFE_REF_SELECT_MSK,
> + AD4170_REF_AVDD);
> +
> + ret = ad4170_get_input_range(st, &st->chans[chan_num],
> chan_num,
> + AD4170_REF_AVDD);
> + if (ret < 0)
> + return dev_err_probe(dev, ret, "Invalid input
> config\n");
> +
> + st->chan_infos[chan_num].input_range_uv = ret;
> + }
> indio_dev->num_channels = num_channels;
> indio_dev->channels = st->chans;
> return 0;
next prev parent reply other threads:[~2025-04-10 10:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 12:23 [PATCH v1 0/7] iio: adc: Add support for AD4170 series of ADCs Marcelo Schmitt
2025-04-09 12:24 ` [PATCH v1 1/7] dt-bindings: iio: adc: Add AD4170 Marcelo Schmitt
2025-04-11 15:47 ` Rob Herring
2025-04-12 16:07 ` Jonathan Cameron
2025-04-09 12:24 ` [PATCH v1 2/7] iio: adc: Add basic support for AD4170 Marcelo Schmitt
2025-04-10 6:31 ` Nuno Sá
2025-04-11 15:38 ` Marcelo Schmitt
2025-04-12 16:19 ` Jonathan Cameron
2025-04-12 18:26 ` Andy Shevchenko
2025-04-14 14:01 ` Marcelo Schmitt
2025-04-12 16:47 ` Jonathan Cameron
2025-04-14 12:13 ` Marcelo Schmitt
2025-04-14 18:42 ` Jonathan Cameron
2025-04-09 12:25 ` [PATCH v1 3/7] iio: adc: ad4170: Add support for buffered data capture Marcelo Schmitt
2025-04-10 9:32 ` Nuno Sá
2025-04-09 12:25 ` [PATCH v1 4/7] iio: adc: ad4170: Add clock provider support Marcelo Schmitt
2025-04-10 9:40 ` Nuno Sá
2025-04-09 12:25 ` [PATCH v1 5/7] iio: adc: ad4170: Add GPIO controller support Marcelo Schmitt
2025-04-10 9:53 ` Nuno Sá
2025-04-14 14:11 ` Marcelo Schmitt
2025-04-14 14:24 ` Andy Shevchenko
2025-04-09 12:26 ` [PATCH v1 6/7] iio: adc: ad4170: Add support for internal temperature sensor Marcelo Schmitt
2025-04-10 10:03 ` Nuno Sá [this message]
2025-04-09 12:26 ` [PATCH v1 7/7] iio: adc: ad4170: Add support for weigh scale and RTD sensors Marcelo Schmitt
2025-04-10 10:39 ` Nuno Sá
2025-04-14 15:38 ` Marcelo Schmitt
2025-04-14 17:24 ` Andy Shevchenko
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=8c785dcda6d22a4a50a2d3994248c33fee69031f.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=marcelo.schmitt@analog.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).