From: "Kurt Borja" <kuurtb@gmail.com>
To: "Andy Shevchenko" <andriy.shevchenko@intel.com>,
"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 v4 2/2] iio: adc: Add ti-ads1018 driver
Date: Wed, 03 Dec 2025 06:54:46 -0500 [thread overview]
Message-ID: <DEOK8E55YR0L.3ST80EKZ08QE8@gmail.com> (raw)
In-Reply-To: <aS_7xrMwW42qolG4@smile.fi.intel.com>
On Wed Dec 3, 2025 at 3:58 AM -05, Andy Shevchenko wrote:
> On Tue, Dec 02, 2025 at 11:56:19PM -0500, Kurt Borja wrote:
>> Add ti-ads1018 driver for Texas Instruments ADS1018 and ADS1118 SPI
>> analog-to-digital converters.
>>
>> These chips' MOSI pin is shared with a data-ready interrupt. Defining
>> this interrupt in devicetree is optional, therefore we only create an
>> IIO trigger if one is found.
>>
>> Handling this interrupt requires some considerations. When enabling the
>> trigger the CS line is tied low (active), thus we need to hold
>> spi_bus_lock() too, to avoid state corruption. This is done inside the
>> set_trigger_state() callback, to let users use other triggers without
>> wasting a bus lock.
>
> ...
>
>> +/**
>> + * ADS1018_FSR_TO_SCALE - Converts FSR into scale
>> + * @_fsr: Full-scale range in millivolts
>> + * @_res: ADC resolution
>> + *
>> + * The macro is crafted to avoid potential overflows on 32-bit machines. This
>> + * imposes restrictions on the possible values for @_fsr (less than 274878),
>
>> + * and @_res (greater than or equal to 6 bits).
>
> This is actually incorrect. See below.
I'll fix this!
>
>> + * Return: Scale in IIO_VAL_INT_PLUS_NANO format
>> + */
>> +#define ADS1018_FSR_TO_SCALE(_fsr, _res) \
>> + { 0, ((_fsr) * (MICRO >> 6)) / (BIT((_res) - 1) >> 6) }
>
> This is different from what I suggested. But I think I was mistaken with
> the parentheses and thought that you are dividing on the mask-like value.
>
> If the current version correct by the result, first of all, the limitation for
The calculation is correct because I sum one in all cases bellow
(advertised resolution).
> @_res is 7 and not 6. And second, it can be rewritten in a simpler form.
>
> { 0, ((_fsr) * (MICRO >> 6)) >> ((_res) - 6 - 1) }
I wanted to use (>> 6) in the numerator and denominator to make it clear
it cancels out. But that (- 6) is equivalent so I can change it.
>
> Please, check it again.
Thanks!
--
~ Kurt
prev parent reply other threads:[~2025-12-03 11:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-03 4:56 [PATCH v4 0/2] iio: Add support for TI ADS1X18 ADCs Kurt Borja
2025-12-03 4:56 ` [PATCH v4 1/2] dt-bindings: iio: adc: Add TI ADS1018/ADS1118 Kurt Borja
2025-12-03 4:56 ` [PATCH v4 2/2] iio: adc: Add ti-ads1018 driver Kurt Borja
2025-12-03 8:58 ` Andy Shevchenko
2025-12-03 11:54 ` Kurt Borja [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=DEOK8E55YR0L.3ST80EKZ08QE8@gmail.com \
--to=kuurtb@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andriy.shevchenko@intel.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=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;
as well as URLs for NNTP newsgroup(s).