From: Mike Looijmans <mike.looijmans@topic.nl>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
Caleb Connolly <caleb.connolly@linaro.org>,
ChiYuan Huang <cy_huang@richtek.com>,
ChiaEn Wu <chiaen_wu@richtek.com>,
Cosmin Tanislav <demonsingur@gmail.com>,
Ibrahim Tilki <Ibrahim.Tilki@analog.com>,
Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Marcus Folkesson <marcus.folkesson@gmail.com>,
Ramona Bolboaca <ramona.bolboaca@analog.com>,
William Breathitt Gray <william.gray@linaro.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] iio: adc: Add TI ADS1100 and ADS1000
Date: Mon, 6 Mar 2023 15:44:23 +0100 [thread overview]
Message-ID: <8a1dc110-97fe-a9c8-ce53-918f403a16eb@topic.nl> (raw)
In-Reply-To: <ZAXqwaKA3Uh6TH2q@smile.fi.intel.com>
Met vriendelijke groet / kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands
T: +31 (0) 499 33 69 69
E: mike.looijmans@topicproducts.com
W: www.topic.nl
Please consider the environment before printing this e-mail
On 06-03-2023 14:29, Andy Shevchenko wrote:
> On Mon, Mar 06, 2023 at 02:13:12PM +0100, Mike Looijmans wrote:
>> The ADS1100 is a 16-bit ADC (at 8 samples per second).
>> The ADS1000 is similar, but has a fixed data rate.
> ...
>
>> + microvolts = regulator_get_voltage(data->reg_vdd);
>> + /*
>> + * val2 is in 'micro' units, n = val2 / 1000000
>> + * result must be millivolts, d = microvolts / 1000
>> + * the full-scale value is d/n, corresponds to 2^15,
>> + * hence the gain = (d / n) >> 15, factoring out the 1000 and moving the
>> + * bitshift so everything fits in 32-bits yields this formula.
>> + */
>> + gain = ((microvolts + BIT(14)) >> 15) * 1000 / val2;
> Perhaps adding MICROVOLT_PER_MILLIVOLT (to units.h) and use it here?
Would that require a separate patch?
I fear that would get feedback like "why not MICROCOULOB_PER_MILLICOULOMB".
If I fill in the equation then that "1000" is actually
MICROVOLT_PER_MICROVOLT_PER_MILLIVOLT, which would evaluate to simply
"MILLIVOLT".
>
> Besides that it's seems like
>
> microvolts = regulator_get_voltage(data->reg_vdd);
> gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) *
> MICROVOLT_PER_MILLIVOLT / val2;
Yeah, the DIV_ROUNDUP_CLOSEST is more readable.
>> + if (gain <= 0 || gain > 8)
>> + return -EINVAL;
> As I commented out in the previous discussion (please, give a chance to the
> reviewers to answer before issuing a new version of the series) this better
> to be
>
> if (gain < BIT(0) || gain > BIT(3))
>
> which will show the nature of power of two implicitly.
>
>> + regval = ffs(gain) - 1;
>> + ads1100_set_config_bits(data, ADS1100_PGA_MASK, regval);
> Can be unified in one line.
Combining it all, I'd arrive at this code:
gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) * MILLI / val2;
if (gain < BIT(0) || gain > BIT(3))
return -EINVAL;
ads1100_set_config_bits(data, ADS1100_PGA_MASK, ffs(gain) - 1);
>> + return 0;
>> +}
> ...
>
>> + return ads1100_set_config_bits(
>> + data, ADS1100_DR_MASK,
>> + FIELD_PREP(ADS1100_DR_MASK, i));
> Wrong indentation.
> Please, check all your code for this kind of issues.
>
I always run it through checkpatch.pl but that didn't report on this
indentation.
A bit of digging in the scripts directory yields "Lindent". Feeding my
file to that indeed changes those lines (and some others too). I'll run
my next patch through that.
--
Mike Looijmans
next prev parent reply other threads:[~2023-03-06 14:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.fd3967b4-1646-4b17-a426-66ee84660804@emailsignatures365.codetwo.com>
2023-03-06 13:13 ` [PATCH v4 1/2] dt-bindings: " Mike Looijmans
[not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.0270109b-145d-4024-b8ff-05d54be2ad97@emailsignatures365.codetwo.com>
2023-03-06 13:13 ` [PATCH v4 2/2] " Mike Looijmans
2023-03-06 13:29 ` Andy Shevchenko
2023-03-06 14:44 ` Mike Looijmans [this message]
2023-03-06 14:58 ` 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=8a1dc110-97fe-a9c8-ce53-918f403a16eb@topic.nl \
--to=mike.looijmans@topic.nl \
--cc=Ibrahim.Tilki@analog.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=caleb.connolly@linaro.org \
--cc=chiaen_wu@richtek.com \
--cc=cy_huang@richtek.com \
--cc=demonsingur@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcus.folkesson@gmail.com \
--cc=ramona.bolboaca@analog.com \
--cc=william.gray@linaro.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
all inboxes | Powered by JetHome®