mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Joshua Crofts <crofts@kernel.org>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
Date: Fri, 27 Nov 2026 08:34:22 +0200	[thread overview]
Message-ID: <036d044a-67ef-4716-aa0a-cdf3108c12e4@gmail.com> (raw)
In-Reply-To: <3ec029d6-d53d-4cd9-8582-a15cfd3eb4d1@kernel.org>

Thanks for the review Joshua. (I appreciate reviewing effort even though 
it may not sound like it.)

On 26/11/2026 15:31, Joshua Crofts wrote:
> On 26-Nov-26 14:23, Matti Vaittinen wrote:
> 
> ...
> 
>> diff --git a/drivers/iio/dac/rohm-bd79703.c b/drivers/iio/dac/rohm-bd79703.c
>> index 127ccc2c4a22..1d58bc1544a1 100644
>> --- a/drivers/iio/dac/rohm-bd79703.c
>> +++ b/drivers/iio/dac/rohm-bd79703.c
>> @@ -41,7 +41,9 @@ static const struct regmap_config bd79703_regmap_config = {
>>   /* Dynamic driver private data */
>>   struct bd79703_data {
>>   	struct regmap *regmap;
>> -	int vfs;
>> +	int vcc_mv;
> 
> _mV is the preferred style to denote SI unit variables.

I have discussed this before, and I disagree. Regular variables have 
been lower case since forever. Capitals have been used to scream "Note 
me, here is something unusal you need to pay attention for" (like 
macros). In my, admittably not always humble enough, opinion, the whole 
"denote SI units" is stupid. I haven't yet seen an engineer who wouldn't 
understand the meaning of vcc_mv in this context. And, to be very blunt, 
if I saw such an engineer, I would rather him stay away from the driver 
code. On the other hand, I have seen engineers who have spent long time 
with kernel code, stop reading to wonder "Hey, we have capitals here, 
what's special with this variable/member". So for me a change from 
vcc_mv to vcc_mV makes this worse.

>> +	int vfs_mv;
>> +	unsigned int num_vfs_chan;
>>   };
>>   
>>   /* Static, IC type specific data for different variants */
>> @@ -49,7 +51,11 @@ struct bd7970x_chip_data {
>>   	const char *name;
>>   	const struct iio_chan_spec *channels;
>>   	int num_channels;
>> -	bool has_vfs;
>> +	/*
>> +	 * Some ICs use VFS-pin for full-scale voltage for first N channels.
>> +	 * We need to know these channels to get correct scale
> 
> Small nit, but missing period at the end.

Thanks.

> 
>> +	 */
>> +	unsigned int num_vfs_chan;
>>   };
>>   
> 
> ...
> 
>>   static int bd79703_probe(struct spi_device *spi)
>> @@ -184,23 +206,26 @@ static int bd79703_probe(struct spi_device *spi)
>>   				     "Failed to initialize Regmap\n");
>>   
>>   	/*
>> -	 * BD79703 has a separate VFS pin, whereas the BD79700 and BD79701 use
>> -	 * VCC for their full-scale output voltage.
>> +	 * BD79702 and BD79703 have a separate VFS pin. On these ICs, the VFS
>> +	 * pin provides the full-scale output voltage for half of the channels,
>> +	 * and use VCC for the rest.
>> +	 * The BD79700 and BD79701 use VCC for their full-scale output voltage
>> +	 * for all of the channels.
>>   	 */
>> -	if (cd->has_vfs) {
>> -		ret = devm_regulator_get_enable(dev, "vcc");
>> -		if (ret)
>> -			return dev_err_probe(dev, ret, "Failed to enable VCC\n");
>> +	ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
>> +	if (ret < 0)
>> +		return dev_err_probe(dev, ret, "Failed to enable VCC\n");
>> +
>> +	data->vcc_mv = ret / 1000;
> 
> Better to do ret / (MICRO / MILLI).

This is another thing I've discussed also in the past. If you genuinely 
stop to think this, why would MICRO / MILLI be better than 1000? Which 
one brings smaller cognitional load, huh? And assigning the result to 
variable vcc_mv makes units explicit in any case. And speaking of SI 
units and scientific accuracy, what actually is MICRO? What is MILLI?

...

Micro is 10^-6! Milli is 10^-3. So, this becomes "ret / (10^-6 / 
10^-3)", which is plain incorrect. So, instead of making things better, 
this obfuscates stuff even further. So please, let's not spread this 
madness any further. (So actually, this should be 1_PER_MICRO / 
1_PER_MILLI - and that'd be even more cognitive load. When did our goal 
changed from making easy-to-understand -code back to making 
fancy-looking code, which is harder to understand, while claiming it to 
be an improvement? That's what these discussions really look to me.)

I agree on using MEGA for 1000000 and even 10 * KILO. This makes sense 
as when the amount of zeroes increases, counting them becomes harder - 
especially with old eyes like mine. But using (MICRO / MILLI) instead of 
1000, that's, in my opinion, just plain stupid. Intentional obfuscation 
of a perfectly clear thing.

I am ready to discuss these points when I submit new features, and I've 
done this quite a lot in the past with Andy ;) But with a fix for a 
pretty severe bug potentially causing unexpected voltages being driven 
out of a device - which may cause a havoc to hardware. I'd rather get 
this fixed ASAP. Maybe you can send an improvement patch with suggested 
styling "fixes" if you feel really strongly about them, and we can 
continue discussion there? I am sure Andy will also join us ;)

Yours,
   -- Matti

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

      reply	other threads:[~2026-11-27  6:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:23 Matti Vaittinen
2026-11-26 13:31 ` Joshua Crofts
2026-11-27  6:34   ` Matti Vaittinen [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=036d044a-67ef-4716-aa0a-cdf3108c12e4@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=andy@kernel.org \
    --cc=crofts@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®