devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Cc: Jonathan Santos <Jonathan.Santos@analog.com>,
	linux-iio@vger.kernel.org,  devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Michael.Hennerich@analog.com,
	jic23@kernel.org, dlechner@baylibre.com,  nuno.sa@analog.com,
	andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
	 conor+dt@kernel.org, jonath4nns@gmail.com
Subject: Re: [PATCH 4/4] iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family
Date: Tue, 19 Aug 2025 23:09:51 +0300	[thread overview]
Message-ID: <CAHp75VepJCCk9zJ6g9tO__FP5jq4EiCtf4mwYGuFf9BO3auJYg@mail.gmail.com> (raw)
In-Reply-To: <aKTNEP7pNY9ZbrPe@debian-BULLSEYE-live-builder-AMD64>

On Tue, Aug 19, 2025 at 10:14 PM Marcelo Schmitt
<marcelo.schmitt1@gmail.com> wrote:
> On 08/12, Jonathan Santos wrote:
> > Add support for ADAQ7767/68/69-1 series, which includes PGIA and

...

> > +static int ad7768_calc_pga_gain(struct ad7768_state *st, int gain_int,
> > +                             int gain_fract, int precision)
> > +{
> > +     u64 gain_nano, tmp;
> > +     int gain_idx;
> > +
> > +     precision--;
> This is odd out of context.
> Also, it only applies to ADCs that provide output codes in two's complement
> format. See comment below.
>
>
> > +     gain_nano = gain_int * NANO + gain_fract;
> > +     if (gain_nano < 0 || gain_nano > ADAQ776X_GAIN_MAX_NANO)
> I've seen some build tools complain about comparisons like gain_nano < 0 with
> gain_nano being u64. Since that's unsigned, it can never be < 0. And in the
> context of gain/attenuation, we know gain_nano shall never be negative.
> Would just drop the gain_nano < 0 comparison. Or maybe clamp() the value?

in_range() can be used as well.

> > +             return -EINVAL;
> > +
> > +     tmp = DIV_ROUND_CLOSEST_ULL(gain_nano << precision, NANO);
> > +     gain_nano = DIV_ROUND_CLOSEST_ULL(st->vref_uv, tmp);
> > +     if (st->chip->has_variable_aaf)
> > +             /* remove the AAF gain from the overall gain */
> > +             gain_nano = DIV_ROUND_CLOSEST_ULL(gain_nano *  MILLI,
> > +                                               ad7768_aaf_gains[st->aaf_gain]);
> > +     tmp = st->chip->num_pga_modes;
> > +     gain_idx = find_closest(gain_nano, st->chip->pga_gains, tmp);
> > +
> > +     return gain_idx;
> > +}

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2025-08-19 20:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13  2:48 [PATCH 0/4] Add support for ADAQ776x-1 ADC Family Jonathan Santos
2025-08-13  2:48 ` [PATCH 1/4] dt-bindings: iio: adc: ad7768-1: add new supported parts Jonathan Santos
2025-08-13  8:27   ` Krzysztof Kozlowski
2025-08-13 22:39     ` Jonathan Santos
2025-08-14  6:03       ` Krzysztof Kozlowski
2025-08-16 13:12         ` Jonathan Cameron
2025-08-18 21:04           ` Jonathan Santos
2025-08-19  6:39             ` Krzysztof Kozlowski
2025-08-19 18:01               ` Marcelo Schmitt
2025-08-13  2:48 ` [PATCH 2/4] iio: adc: ad7768-1: introduce chip info for future multidevice support Jonathan Santos
2025-08-13 10:37   ` Andy Shevchenko
2025-08-16 13:16   ` Jonathan Cameron
2025-08-13  2:49 ` [PATCH 3/4] iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage Jonathan Santos
2025-08-13 10:39   ` Andy Shevchenko
2025-08-13 14:50   ` David Lechner
2025-08-14  6:43   ` Nuno Sá
2025-08-19 18:06   ` Marcelo Schmitt
2025-08-13  2:49 ` [PATCH 4/4] iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family Jonathan Santos
2025-08-13 12:16   ` Andy Shevchenko
2025-08-13 23:21   ` kernel test robot
2025-08-14  6:55   ` Nuno Sá
2025-08-18 21:53     ` Jonathan Santos
2025-08-19 19:14   ` Marcelo Schmitt
2025-08-19 20:09     ` Andy Shevchenko [this message]
2025-08-14  6:42 ` [PATCH 0/4] Add " Nuno Sá

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=CAHp75VepJCCk9zJ6g9tO__FP5jq4EiCtf4mwYGuFf9BO3auJYg@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=Jonathan.Santos@analog.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=jonath4nns@gmail.com \
    --cc=krzk+dt@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=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).