From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Kurt Borja <kuurtb@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Tobias Sperling" <tobias.sperling@softing.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH v2 2/2] iio: adc: Add ti-ads1018 driver
Date: Fri, 28 Nov 2025 21:02:55 +0200 [thread overview]
Message-ID: <aSnx3zjBIbNvslba@smile.fi.intel.com> (raw)
In-Reply-To: <DEKIF0XIN34S.97S95Z0Q5SL1@gmail.com>
On Fri, Nov 28, 2025 at 12:38:44PM -0500, Kurt Borja wrote:
> On Fri Nov 28, 2025 at 4:54 AM -05, Andy Shevchenko wrote:
> > On Thu, Nov 27, 2025 at 10:37:11PM -0500, Kurt Borja wrote:
Please, remove context you are agree with, no need to keep long message
which is harder to parse for what has been asked, answered, or discussed.
That said, I assume non-commented remarks will be addressed in the next
version as suggested.
...
> >> +static unsigned long ads1018_calc_delay(struct ads1018 *ads1018)
> >> +{
> >> + const struct ads1018_chip_info *chip_info = ads1018->chip_info;
> >> + unsigned long mode = chip_info->num_data_rate_mode_to_hz - 1;
> >> + int hz = chip_info->data_rate_mode_to_hz[mode];
> >
> > Can frequency be negative?
>
> I hope not 0.0
>
> I return data_rate_mode_to_hz[] values directly in __ads1018_read_raw(),
> which uses `int *`. That's why I chose int, but I can just make it
> unsigned if that's preferred.
Keep it unsigned wherever it's possible.
...
> > static void ads1018_set_trigger_enable(struct ads1018 *ads1018)
> > {
> > spi_bus_lock(ads1018->spi->controller);
> > ads1018_read_locked(ads1018, NULL, true);
> > enable_irq(ads1018->drdy_irq);
> > }
> >
> > static void ads1018_set_trigger_disable(struct ads1018 *ads1018)
> > {
> > disable_irq(ads1018->drdy_irq);
> > ads1018_read_locked(ads1018, NULL, false);
> > spi_bus_unlock(ads1018->spi->controller);
> > }
> >
> > Or if you make _read_locked() to return the data, just ignoring it as in
> >
> > ads1018_read_locked(ads1018, ...);
>
> Sure, I like this.
I noticed that it may return also an error, with that in mind the NULL pointer
is the easiest way to go.
...
> >> +static const int ads1018_gain_table[][2] = {
> >> + ADS1018_FSR_TO_SCALE(6144, 11),
> >
> > This won't (hmm... might not? see below for the details) work on 32-bit.
> >
> >> + ADS1018_FSR_TO_SCALE(4096, 11),
> >> + ADS1018_FSR_TO_SCALE(2048, 11),
> >> + ADS1018_FSR_TO_SCALE(1024, 11),
> >> + ADS1018_FSR_TO_SCALE(512, 11),
> >> + ADS1018_FSR_TO_SCALE(256, 11),
> >> +};
> >> +
> >> +static const int ads1118_gain_table[][2] = {
> >> + ADS1018_FSR_TO_SCALE(6144, 15),
> >
> > Ditto.
> >
> >> + ADS1018_FSR_TO_SCALE(4096, 15),
> >> + ADS1018_FSR_TO_SCALE(2048, 15),
> >> + ADS1018_FSR_TO_SCALE(1024, 15),
> >> + ADS1018_FSR_TO_SCALE(512, 15),
> >> + ADS1018_FSR_TO_SCALE(256, 15),
> >> +};
> >
> > To address that you need to divide MICRO at least by 2
> > (note, by 2⁶ is also possible without loosing in precision).
> >
> > // Assuming that you want to keep the initialisers as is now:
> > #define ADS1018_FSR_TO_SCALE(_fsr, _res) \
> > { 0, ((_fsr) * (MICRO >> 6)) / BIT((_res) - 6) }
> >
> > OTOH, these all are constants, so the clever compiler (even 32-bit compiler)
> > may do it for you and won't complain as there is no overflow in the result.
> >
> > TL;DR: Try to compile this with 32-bit compiler on 32-bit machine before
> > changing as suggested.
>
> I didn't consider 32-bit here... I'll test it for v3!
Every time you have a division in the code with (potentially) bit numbers
in the numerator and/or denominator always think about 32-bit case.
...
> Ack, for everything else. Thank you, Andy!
Okay, I assumed correctly in the top, but again, please remove the unneeded
context when replying.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2025-11-28 19:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 3:37 [PATCH v2 0/2] iio: Add support for TI ADS1X18 ADCs Kurt Borja
2025-11-28 3:37 ` [PATCH v2 1/2] dt-bindings: iio: adc: Add TI ADS1018/ADS1118 Kurt Borja
2025-11-28 9:43 ` Krzysztof Kozlowski
2025-11-28 17:40 ` Kurt Borja
2025-11-28 3:37 ` [PATCH v2 2/2] iio: adc: Add ti-ads1018 driver Kurt Borja
2025-11-28 9:54 ` Andy Shevchenko
2025-11-28 10:21 ` Andy Shevchenko
2025-11-28 17:38 ` Kurt Borja
2025-11-28 19:02 ` Andy Shevchenko [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=aSnx3zjBIbNvslba@smile.fi.intel.com \
--to=andriy.shevchenko@intel.com \
--cc=Jonathan.Cameron@huawei.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=kuurtb@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=tobias.sperling@softing.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