* [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
@ 2026-11-26 13:23 Matti Vaittinen
2026-11-26 13:31 ` Joshua Crofts
2026-11-28 3:53 ` Jonathan Cameron
0 siblings, 2 replies; 12+ messages in thread
From: Matti Vaittinen @ 2026-11-26 13:23 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 6502 bytes --]
From: Matti Vaittinen <mazziesaccount@gmail.com>
The BD79702 and BD79703 have a VFS pin which can be used to supply a
full-scale voltage to be output with maximum DAC word. The driver
assumes this voltage is the full-scale voltage for all of the DAC
channels. This, however, is not true.
The VFS-pin voltage is only used for the first half of the channels. Eg.
on BD79703, channels AO1 and AO2 use VFS, AO3 and, AO4 use the VCC.
Similarly, the BD79703 channels AO1, AO2, and, AO3 use VFS, AO4, AO5, and
AO6 use the VCC.
Fix the driver to use correct full-scale voltages (VCC instead of VFS) on
the last channels of the BD79702 and BD79703. The BD79700 and BD79701
logic should not be changed.
NOTE: This change is visible to the user-space, it makes the scale a
per-channel property so the sysFS file out_voltage_scale gets replaced
by per-channel variants out_voltageN_scale
Fixes: af6aca656a85 ("iio: dac: Support ROHM BD79703 DAC")
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
drivers/iio/dac/rohm-bd79703.c | 77 ++++++++++++++++++++++------------
1 file changed, 51 insertions(+), 26 deletions(-)
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;
+ 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
+ */
+ unsigned int num_vfs_chan;
};
static int bd79703_read_raw(struct iio_dev *idev,
@@ -61,7 +67,11 @@ static int bd79703_read_raw(struct iio_dev *idev,
if (mask != IIO_CHAN_INFO_SCALE)
return -EINVAL;
- *val = data->vfs / 1000;
+ if (data->num_vfs_chan > chan->channel)
+ *val = data->vfs_mv;
+ else
+ *val = data->vcc_mv;
+
*val2 = BD79703_DAC_BITS;
return IIO_VAL_FRACTIONAL_LOG2;
@@ -88,16 +98,26 @@ static const struct iio_info bd79703_info = {
};
#define BD79703_CHAN_ADDR(_chan, _addr) { \
+ .type = IIO_VOLTAGE, \
+ .indexed = 1, \
+ .output = 1, \
+ .channel = (_chan), \
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+ BIT(IIO_CHAN_INFO_SCALE), \
+ .address = (_addr), \
+}
+
+#define BD79703_CHAN(_chan) { \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.output = 1, \
.channel = (_chan), \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
- .address = (_addr), \
+ .address = (_chan) + 1, \
}
-#define BD79703_CHAN(_chan) BD79703_CHAN_ADDR((_chan), (_chan) + 1)
+#define BD79703_CHAN_VFS(_chan) BD79703_CHAN_ADDR((_chan), (_chan) + 1)
static const struct iio_chan_spec bd79700_channels[] = {
BD79703_CHAN(0),
@@ -115,6 +135,8 @@ static const struct iio_chan_spec bd79701_channels[] = {
* and 3, but to the channels 0, 1, 4, 5. So the addressing used with SPI
* accesses is 1, 2, 5 and 6 for them. Thus, they're not constant offset to
* the channel number as with other IC variants.
+ *
+ * Furthermore, the BD79702 and BD79703 can have different scale for channels.
*/
static const struct iio_chan_spec bd79702_channels[] = {
BD79703_CHAN_ADDR(0, 1),
@@ -124,40 +146,40 @@ static const struct iio_chan_spec bd79702_channels[] = {
};
static const struct iio_chan_spec bd79703_channels[] = {
- BD79703_CHAN(0),
- BD79703_CHAN(1),
- BD79703_CHAN(2),
- BD79703_CHAN(3),
- BD79703_CHAN(4),
- BD79703_CHAN(5),
+ BD79703_CHAN_VFS(0),
+ BD79703_CHAN_VFS(1),
+ BD79703_CHAN_VFS(2),
+ BD79703_CHAN_VFS(3),
+ BD79703_CHAN_VFS(4),
+ BD79703_CHAN_VFS(5),
};
static const struct bd7970x_chip_data bd79700_chip_data = {
.name = "bd79700",
.channels = bd79700_channels,
.num_channels = ARRAY_SIZE(bd79700_channels),
- .has_vfs = false,
+ .num_vfs_chan = 0,
};
static const struct bd7970x_chip_data bd79701_chip_data = {
.name = "bd79701",
.channels = bd79701_channels,
.num_channels = ARRAY_SIZE(bd79701_channels),
- .has_vfs = false,
+ .num_vfs_chan = 0,
};
static const struct bd7970x_chip_data bd79702_chip_data = {
.name = "bd79702",
.channels = bd79702_channels,
.num_channels = ARRAY_SIZE(bd79702_channels),
- .has_vfs = true,
+ .num_vfs_chan = 2,
};
static const struct bd7970x_chip_data bd79703_chip_data = {
.name = "bd79703",
.channels = bd79703_channels,
.num_channels = ARRAY_SIZE(bd79703_channels),
- .has_vfs = true,
+ .num_vfs_chan = 3,
};
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;
+ if (cd->num_vfs_chan > 0) {
ret = devm_regulator_get_enable_read_voltage(dev, "vfs");
if (ret < 0)
return dev_err_probe(dev, ret, "Failed to get Vfs\n");
- } else {
- ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
- if (ret < 0)
- return dev_err_probe(dev, ret, "Failed to get VCC\n");
+
+ data->vfs_mv = ret / 1000;
+ data->num_vfs_chan = cd->num_vfs_chan;
}
- data->vfs = ret;
idev->channels = cd->channels;
idev->num_channels = cd->num_channels;
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.56.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-26 13:23 [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages Matti Vaittinen
@ 2026-11-26 13:31 ` Joshua Crofts
2026-11-27 6:34 ` Matti Vaittinen
2026-11-28 3:53 ` Jonathan Cameron
1 sibling, 1 reply; 12+ messages in thread
From: Joshua Crofts @ 2026-11-26 13:31 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
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.
> + 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.
> + */
> + 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).
>
> + if (cd->num_vfs_chan > 0) {
> ret = devm_regulator_get_enable_read_voltage(dev, "vfs");
> if (ret < 0)
> return dev_err_probe(dev, ret, "Failed to get Vfs\n");
> - } else {
> - ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
> - if (ret < 0)
> - return dev_err_probe(dev, ret, "Failed to get VCC\n");
> +
> + data->vfs_mv = ret / 1000;
Same here.
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-26 13:31 ` Joshua Crofts
@ 2026-11-27 6:34 ` Matti Vaittinen
2026-11-27 11:03 ` Andy Shevchenko
0 siblings, 1 reply; 12+ messages in thread
From: Matti Vaittinen @ 2026-11-27 6:34 UTC (permalink / raw)
To: Joshua Crofts
Cc: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
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! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-27 6:34 ` Matti Vaittinen
@ 2026-11-27 11:03 ` Andy Shevchenko
2026-11-27 11:46 ` Matti Vaittinen
0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2026-11-27 11:03 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Joshua Crofts, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On Fri, Nov 27, 2026 at 08:34:22AM +0200, Matti Vaittinen wrote:
> On 26/11/2026 15:31, Joshua Crofts wrote:
> > On 26-Nov-26 14:23, Matti Vaittinen wrote:
...
> > > + 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.
And I disagree with your argumentation because the scope of discussion here is
more than just millivolts. We have (in practice!) already a problem with mHz
versus MHz. Yes, in real life. So, that's why it's better to follow SI for all
SI registered units and stop messing with the multipliers.
> > > + int vfs_mv;
...
> > > + 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?
Then what prevents you from adding a new multiplier to units.h?
...
> 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.
Because kernel does not work in float, it works in integer space. We don't
have fractions without keeping a multiplier in mind. I do not consider this
a madness.
> (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 ;)
Yep, with my full disagreement with you :-)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-27 11:03 ` Andy Shevchenko
@ 2026-11-27 11:46 ` Matti Vaittinen
2026-11-27 12:08 ` Andy Shevchenko
0 siblings, 1 reply; 12+ messages in thread
From: Matti Vaittinen @ 2026-11-27 11:46 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Joshua Crofts, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On 27/11/2026 13:03, Andy Shevchenko wrote:
> On Fri, Nov 27, 2026 at 08:34:22AM +0200, Matti Vaittinen wrote:
>> On 26/11/2026 15:31, Joshua Crofts wrote:
>>> On 26-Nov-26 14:23, Matti Vaittinen wrote:
>
> ...
>
>>>> + 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.
>
> And I disagree with your argumentation because the scope of discussion here is
> more than just millivolts. We have (in practice!) already a problem with mHz
> versus MHz. Yes, in real life.
I see no mHz or MHz here.
> So, that's why it's better to follow SI for all
> SI registered units and stop messing with the multipliers.
No. There is zero reason to use capitals in variable/member names when
intent is clear. It only hurts reading with zero real benefits.
>>>> + int vfs_mv;
>
> ...
>
>>>> + 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?
>
> Then what prevents you from adding a new multiplier to units.h?
>
> ...
>
>> 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.
>
> Because kernel does not work in float, it works in integer space.
This does not mean Milli is same as Kilo. You were the one who ask for
accuracy above (even though it really just breaks the known convention),
and here you demand obfuscation.
> We don't
> have fractions without keeping a multiplier in mind. I do not consider this
> a madness.
swapping 1000 to (MICRO / MILLI) - where micro and milli arent what they
are supposed to be - is madeness to me.
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-27 11:46 ` Matti Vaittinen
@ 2026-11-27 12:08 ` Andy Shevchenko
2026-11-27 15:57 ` Andy Shevchenko
2026-11-30 7:01 ` Matti Vaittinen
0 siblings, 2 replies; 12+ messages in thread
From: Andy Shevchenko @ 2026-11-27 12:08 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Joshua Crofts, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On Fri, Nov 27, 2026 at 01:46:12PM +0200, Matti Vaittinen wrote:
> On 27/11/2026 13:03, Andy Shevchenko wrote:
> > On Fri, Nov 27, 2026 at 08:34:22AM +0200, Matti Vaittinen wrote:
> > > On 26/11/2026 15:31, Joshua Crofts wrote:
> > > > On 26-Nov-26 14:23, Matti Vaittinen wrote:
...
> > > > > + 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.
> >
> > And I disagree with your argumentation because the scope of discussion here is
> > more than just millivolts. We have (in practice!) already a problem with mHz
> > versus MHz. Yes, in real life.
>
> I see no mHz or MHz here.
That's why I pointed that the issue is broader than just millivolts _here_.
FWIW, mHz is in drivers/iio/imu/st_lsm6dsx/.
> > So, that's why it's better to follow SI for all
> > SI registered units and stop messing with the multipliers.
>
> No. There is zero reason to use capitals in variable/member names when
> intent is clear. It only hurts reading with zero real benefits.
It's clear for *you* or somebody else who is not the first day in IIO
development, always put yourself into the position of unprepared reader.
SI is known for much longer than computer even exist.
> > > > > + int vfs_mv;
...
> > > > > + 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?
> >
> > Then what prevents you from adding a new multiplier to units.h?
No answer?
...
> > > 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.
> >
> > Because kernel does not work in float, it works in integer space.
>
> This does not mean Milli is same as Kilo. You were the one who ask for
> accuracy above (even though it really just breaks the known convention), and
> here you demand obfuscation.
Yeah, it would be nice to have the stricter rules about this, but I see the
problems it may lead to. For the given case we transform the value in MICRO
volts to a MILLI volts using a ratio MICRO / MILLI. I consider that much easier
to read in the code and _understand_ what's going on.
> > We don't have fractions without keeping a multiplier in mind. I do not
> > consider this a madness.
>
> swapping 1000 to (MICRO / MILLI) - where micro and milli arent what they are
> supposed to be - is madeness to me.
And opposite to me as we may admit.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-27 12:08 ` Andy Shevchenko
@ 2026-11-27 15:57 ` Andy Shevchenko
2026-11-30 7:06 ` Matti Vaittinen
2026-11-30 7:01 ` Matti Vaittinen
1 sibling, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2026-11-27 15:57 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Joshua Crofts, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On Fri, Nov 27, 2026 at 02:08:51PM +0200, Andy Shevchenko wrote:
> On Fri, Nov 27, 2026 at 01:46:12PM +0200, Matti Vaittinen wrote:
> > On 27/11/2026 13:03, Andy Shevchenko wrote:
...
> > No. There is zero reason to use capitals in variable/member names when
> > intent is clear. It only hurts reading with zero real benefits.
>
> It's clear for *you* or somebody else who is not the first day in IIO
> development, always put yourself into the position of unprepared reader.
> SI is known for much longer than computer even exist.
Correction: SI as a modern system is known from 1960 (updated in 2019),
but the early prototype was published in 1901 and extended in 1921. The
whole idea began in 1875 on conference in Paris for the standard metre
and kilogram.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-27 15:57 ` Andy Shevchenko
@ 2026-11-30 7:06 ` Matti Vaittinen
0 siblings, 0 replies; 12+ messages in thread
From: Matti Vaittinen @ 2026-11-30 7:06 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Joshua Crofts, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On 27/11/2026 17:57, Andy Shevchenko wrote:
> On Fri, Nov 27, 2026 at 02:08:51PM +0200, Andy Shevchenko wrote:
>> On Fri, Nov 27, 2026 at 01:46:12PM +0200, Matti Vaittinen wrote:
>>> On 27/11/2026 13:03, Andy Shevchenko wrote:
>
> ...
>
>>> No. There is zero reason to use capitals in variable/member names when
>>> intent is clear. It only hurts reading with zero real benefits.
>>
>> It's clear for *you* or somebody else who is not the first day in IIO
>> development, always put yourself into the position of unprepared reader.
>> SI is known for much longer than computer even exist.
>
> Correction: SI as a modern system is known from 1960 (updated in 2019),
> but the early prototype was published in 1901 and extended in 1921. The
> whole idea began in 1875 on conference in Paris for the standard metre
> and kilogram.
Thanks for the history lesson :) I didn't know about this. While I
consider the age of SI system being 100% irrelevant to the naming vcc_mv
Vs vcc_mV - it is still interesting little fact.
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-27 12:08 ` Andy Shevchenko
2026-11-27 15:57 ` Andy Shevchenko
@ 2026-11-30 7:01 ` Matti Vaittinen
2026-11-30 14:34 ` Andy Shevchenko
1 sibling, 1 reply; 12+ messages in thread
From: Matti Vaittinen @ 2026-11-30 7:01 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Joshua Crofts, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On 27/11/2026 14:08, Andy Shevchenko wrote:
> On Fri, Nov 27, 2026 at 01:46:12PM +0200, Matti Vaittinen wrote:
>> On 27/11/2026 13:03, Andy Shevchenko wrote:
>>> On Fri, Nov 27, 2026 at 08:34:22AM +0200, Matti Vaittinen wrote:
>>>> On 26/11/2026 15:31, Joshua Crofts wrote:
>>>>> On 26-Nov-26 14:23, Matti Vaittinen wrote:
>
> ...
>
>>>>>> + 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.
>>>
>>> And I disagree with your argumentation because the scope of discussion here is
>>> more than just millivolts. We have (in practice!) already a problem with mHz
>>> versus MHz. Yes, in real life.
>>
>> I see no mHz or MHz here.
>
> That's why I pointed that the issue is broader than just millivolts _here_.
> FWIW, mHz is in drivers/iio/imu/st_lsm6dsx/.
If the problem is with the mHz vs MHz - why adding weird variables
elsewhere? In my opinion, we should avoid blindly following general
"rules of thumb". And we definitely shouldn't invent such out of very
specific cases.
>>> So, that's why it's better to follow SI for all
>>> SI registered units and stop messing with the multipliers.
>>
>> No. There is zero reason to use capitals in variable/member names when
>> intent is clear. It only hurts reading with zero real benefits.
>
> It's clear for *you* or somebody else who is not the first day in IIO
> development, always put yourself into the position of unprepared reader.
If you consider someone coming outside of IIO (but someone who has spent
time in-kernel) - it is likely seeing upper-case variable makes them
rise their eyebrows. And no, VCC is not used only in IIO. VCC is pretty
much used with a wide variety of electronics. Besides, I don't buy your
claim that "vcc_mV" would make the meaning of variable any more known
for someone who does not come from IIO than vcc_mv does. To me this
claim sounds just plain silly. If you know vcc is a voltage, then mv
-suffix is really obvious. If you don't know it is voltage, then mV -
suffix won't help. I really have a feeling this is very made-up solution
to a made-up problem.
To me, (I don't claim this is how things are, this is how it seems to
me) comments like this are a symptom of: "I want to show I am a Very
Capable Experienced Kernel Developer and I want to feel important"
attitude, rather than "I genuinely believe this is an important
improvement to the contribution, and I want to help the author to
improve". Please note, this does not mean I didn't appreciate your
reviews. I do value many of your findings, you tend to add also some
very valuable comments.
> SI is known for much longer than computer even exist.
>
>>>>>> + int vfs_mv;
>
> ...
>
>>>>>> + 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?
>>>
>>> Then what prevents you from adding a new multiplier to units.h?
>
> No answer?
I think I've said it also earlier. In my opinion, we should not
obfuscate 1000 with a define. To me, 1000 is as clear as it gets. If we
have a define, then there is always a chance it means something else -
unless we go and see the define. Like in case of MILLI and KILO, MICRO
and MEGA.
> ...
>
>>>> 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.
>>>
>>> Because kernel does not work in float, it works in integer space.
>>
>> This does not mean Milli is same as Kilo. You were the one who ask for
>> accuracy above (even though it really just breaks the known convention), and
>> here you demand obfuscation.
>
> Yeah, it would be nice to have the stricter rules about this, but I see the
> problems it may lead to. For the given case we transform the value in MICRO
> volts to a MILLI volts using a ratio MICRO / MILLI. I consider that much easier
> to read in the code and _understand_ what's going on.
I understand the intention of explaining the transformation from micro
to milli, but I genuinely think this is a very failed attempt. We are
reading code, not documentation, and if code says:
ret / (MICRO / MILLI);
it says we are dividing ret by a value, which is MICRO / MILLI. In order
to understand what resulting ret is going to be, one must dig out what
the MICRO and MILLI are. This is extra step for anyone who does not know
what they are, and also an unnecessary (although simple) computation for
anyone who know what they are. It really is not a documentation but
obfuscation. For unit conversion, one would logically expect to see
_multiplication_ by the ratio (which, of course, would not work here as
MICRO and MILLI aren't what they are supposed to be). This is just
obfuscation to ... Somebody else, who is the first day in IIO
development. Please, always put yourself into the position of unprepared
reader.
In my opinion, if the transformation really requires documentation, use
real values and add a comment.
vcc_mv = ret / 1000; /* uV to mV */
Do NOT add some strange inverse unit division with bad defines.
Now, when one considers if a comment would be needed in above code,
seeing the 'ret' value comes from regulator API and goes into vcc_mv ...
In my opinion, this really is not something that would need a comment.
>>> We don't have fractions without keeping a multiplier in mind. I do not
>>> consider this a madness.
>>
>> swapping 1000 to (MICRO / MILLI) - where micro and milli arent what they are
>> supposed to be - is madeness to me.
>
> And opposite to me as we may admit.
I admit :)
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-30 7:01 ` Matti Vaittinen
@ 2026-11-30 14:34 ` Andy Shevchenko
0 siblings, 0 replies; 12+ messages in thread
From: Andy Shevchenko @ 2026-11-30 14:34 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Joshua Crofts, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On Mon, Nov 30, 2026 at 09:01:07AM +0200, Matti Vaittinen wrote:
> On 27/11/2026 14:08, Andy Shevchenko wrote:
> > On Fri, Nov 27, 2026 at 01:46:12PM +0200, Matti Vaittinen wrote:
> > > On 27/11/2026 13:03, Andy Shevchenko wrote:
> > > > On Fri, Nov 27, 2026 at 08:34:22AM +0200, Matti Vaittinen wrote:
> > > > > On 26/11/2026 15:31, Joshua Crofts wrote:
> > > > > > On 26-Nov-26 14:23, Matti Vaittinen wrote:
...
> > > > > > > + 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.
> > > >
> > > > And I disagree with your argumentation because the scope of discussion here is
> > > > more than just millivolts. We have (in practice!) already a problem with mHz
> > > > versus MHz. Yes, in real life.
> > >
> > > I see no mHz or MHz here.
> >
> > That's why I pointed that the issue is broader than just millivolts _here_.
> > FWIW, mHz is in drivers/iio/imu/st_lsm6dsx/.
>
> If the problem is with the mHz vs MHz - why adding weird variables
> elsewhere? In my opinion, we should avoid blindly following general "rules
> of thumb". And we definitely shouldn't invent such out of very specific
> cases.
Then we will end up with different SI units when we apply different style to
them.
> > > > So, that's why it's better to follow SI for all
> > > > SI registered units and stop messing with the multipliers.
> > >
> > > No. There is zero reason to use capitals in variable/member names when
> > > intent is clear. It only hurts reading with zero real benefits.
> >
> > It's clear for *you* or somebody else who is not the first day in IIO
> > development, always put yourself into the position of unprepared reader.
>
> If you consider someone coming outside of IIO (but someone who has spent
> time in-kernel) - it is likely seeing upper-case variable makes them rise
> their eyebrows. And no, VCC is not used only in IIO. VCC is pretty much used
> with a wide variety of electronics. Besides, I don't buy your claim that
> "vcc_mV" would make the meaning of variable any more known for someone who
> does not come from IIO than vcc_mv does. To me this claim sounds just plain
> silly. If you know vcc is a voltage, then mv -suffix is really obvious. If
> you don't know it is voltage, then mV - suffix won't help. I really have a
> feeling this is very made-up solution to a made-up problem.
Vcc can be in Volts, millivolts, microvolts, and so on. We add unit suffices
for readability to understand the order of the values and give more meaning
to the expressions like
vref_mV = 5;
Then we have different suffices based on SI + registered multipliers and how
they are represented in the physical world. Yes, it's not that much a problem
as we take it standalone (for isolated driver and isolated case), but in general
it's a deviation in style.
> To me, (I don't claim this is how things are, this is how it seems to me)
> comments like this are a symptom of: "I want to show I am a Very Capable
> Experienced Kernel Developer and I want to feel important" attitude, rather
> than "I genuinely believe this is an important improvement to the
> contribution, and I want to help the author to improve". Please note, this
> does not mean I didn't appreciate your reviews. I do value many of your
> findings, you tend to add also some very valuable comments.
I understand the frustration, but I'm for the common style, like a standard
at least in the borders of a single subsystem. What you are saying about
individual approach based on the SI in use I disagree with, because it would
lead to potential misinterpretations.
> > SI is known for much longer than computer even exist.
> >
> > > > > > > + int vfs_mv;
...
> > > > > > > + 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?
> > > >
> > > > Then what prevents you from adding a new multiplier to units.h?
> >
> > No answer?
>
> I think I've said it also earlier. In my opinion, we should not obfuscate
> 1000 with a define. To me, 1000 is as clear as it gets. If we have a define,
> then there is always a chance it means something else - unless we go and see
> the define. Like in case of MILLI and KILO, MICRO and MEGA.
It requires an additional cognitive work to get the order of the value kept in
'ret'. With (MICRO / MILLI) it's easier to understand (as it's read as 'we got
value in microSOMETHING and we convert it to milliSOMETHING).
...
> > > > > 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.
> > > >
> > > > Because kernel does not work in float, it works in integer space.
> > >
> > > This does not mean Milli is same as Kilo. You were the one who ask for
> > > accuracy above (even though it really just breaks the known convention), and
> > > here you demand obfuscation.
> >
> > Yeah, it would be nice to have the stricter rules about this, but I see the
> > problems it may lead to. For the given case we transform the value in MICRO
> > volts to a MILLI volts using a ratio MICRO / MILLI. I consider that much easier
> > to read in the code and _understand_ what's going on.
>
> I understand the intention of explaining the transformation from micro to
> milli, but I genuinely think this is a very failed attempt. We are reading
> code, not documentation, and if code says:
>
> ret / (MICRO / MILLI);
>
> it says we are dividing ret by a value, which is MICRO / MILLI. In order to
> understand what resulting ret is going to be, one must dig out what the
> MICRO and MILLI are.
Everybody understands what are they. The same argument as you used about 'mv'
versus 'mV' above.
> This is extra step for anyone who does not know what
> they are, and also an unnecessary (although simple) computation for anyone
> who know what they are. It really is not a documentation but obfuscation.
> For unit conversion, one would logically expect to see _multiplication_ by
> the ratio (which, of course, would not work here as MICRO and MILLI aren't
> what they are supposed to be). This is just obfuscation to ... Somebody
> else, who is the first day in IIO development. Please, always put yourself
> into the position of unprepared reader.
>
> In my opinion, if the transformation really requires documentation, use real
> values and add a comment.
>
> vcc_mv = ret / 1000; /* uV to mV */
>
> Do NOT add some strange inverse unit division with bad defines.
Yes, this is the main point of our disagreement. So, I think we can go thru
applying the multiplier in the units.h as MICROVOLT_PER_MILLIVOLT and then
it will follow the pattern that is used *a lot* in the kernel for other things.
> Now, when one considers if a comment would be needed in above code, seeing
> the 'ret' value comes from regulator API and goes into vcc_mv ... In my
> opinion, this really is not something that would need a comment.
>
> > > > We don't have fractions without keeping a multiplier in mind. I do not
> > > > consider this a madness.
> > >
> > > swapping 1000 to (MICRO / MILLI) - where micro and milli arent what they are
> > > supposed to be - is madeness to me.
> >
> > And opposite to me as we may admit.
>
> I admit :)
...
With all arguments being said, I do not think we can productively and effectively
continue this discussion. Let's just not waist our time on this anymore and do
something more useful. Do you agree?
Especially taking into account that Jonathan is okay with your style and AFAICS
he applied this already.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-26 13:23 [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages Matti Vaittinen
2026-11-26 13:31 ` Joshua Crofts
@ 2026-11-28 3:53 ` Jonathan Cameron
2026-11-30 8:28 ` Matti Vaittinen
1 sibling, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2026-11-28 3:53 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On Thu, 26 Nov 2026 15:23:10 +0200
Matti Vaittinen <matti.vaittinen@linux.dev> wrote:
> From: Matti Vaittinen <mazziesaccount@gmail.com>
>
> The BD79702 and BD79703 have a VFS pin which can be used to supply a
> full-scale voltage to be output with maximum DAC word. The driver
> assumes this voltage is the full-scale voltage for all of the DAC
> channels. This, however, is not true.
>
> The VFS-pin voltage is only used for the first half of the channels. Eg.
> on BD79703, channels AO1 and AO2 use VFS, AO3 and, AO4 use the VCC.
> Similarly, the BD79703 channels AO1, AO2, and, AO3 use VFS, AO4, AO5, and
> AO6 use the VCC.
>
> Fix the driver to use correct full-scale voltages (VCC instead of VFS) on
> the last channels of the BD79702 and BD79703. The BD79700 and BD79701
> logic should not be changed.
>
> NOTE: This change is visible to the user-space, it makes the scale a
> per-channel property so the sysFS file out_voltage_scale gets replaced
> by per-channel variants out_voltageN_scale
>
> Fixes: af6aca656a85 ("iio: dac: Support ROHM BD79703 DAC")
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Enjoy the side discussion. I'm going to take the expedient path and
just merge this. Applied to the fixes-togreg branch of iio.git.
This wins one of those awards for generally odd things to build
in hardware.
Thanks
Jonathan
> ---
> drivers/iio/dac/rohm-bd79703.c | 77 ++++++++++++++++++++++------------
> 1 file changed, 51 insertions(+), 26 deletions(-)
>
> 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;
> + 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
> + */
> + unsigned int num_vfs_chan;
> };
>
> static int bd79703_read_raw(struct iio_dev *idev,
> @@ -61,7 +67,11 @@ static int bd79703_read_raw(struct iio_dev *idev,
> if (mask != IIO_CHAN_INFO_SCALE)
> return -EINVAL;
>
> - *val = data->vfs / 1000;
> + if (data->num_vfs_chan > chan->channel)
> + *val = data->vfs_mv;
> + else
> + *val = data->vcc_mv;
> +
> *val2 = BD79703_DAC_BITS;
>
> return IIO_VAL_FRACTIONAL_LOG2;
> @@ -88,16 +98,26 @@ static const struct iio_info bd79703_info = {
> };
>
> #define BD79703_CHAN_ADDR(_chan, _addr) { \
> + .type = IIO_VOLTAGE, \
> + .indexed = 1, \
> + .output = 1, \
> + .channel = (_chan), \
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> + BIT(IIO_CHAN_INFO_SCALE), \
> + .address = (_addr), \
> +}
> +
> +#define BD79703_CHAN(_chan) { \
> .type = IIO_VOLTAGE, \
> .indexed = 1, \
> .output = 1, \
> .channel = (_chan), \
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
> - .address = (_addr), \
> + .address = (_chan) + 1, \
> }
>
> -#define BD79703_CHAN(_chan) BD79703_CHAN_ADDR((_chan), (_chan) + 1)
> +#define BD79703_CHAN_VFS(_chan) BD79703_CHAN_ADDR((_chan), (_chan) + 1)
>
> static const struct iio_chan_spec bd79700_channels[] = {
> BD79703_CHAN(0),
> @@ -115,6 +135,8 @@ static const struct iio_chan_spec bd79701_channels[] = {
> * and 3, but to the channels 0, 1, 4, 5. So the addressing used with SPI
> * accesses is 1, 2, 5 and 6 for them. Thus, they're not constant offset to
> * the channel number as with other IC variants.
> + *
> + * Furthermore, the BD79702 and BD79703 can have different scale for channels.
> */
> static const struct iio_chan_spec bd79702_channels[] = {
> BD79703_CHAN_ADDR(0, 1),
> @@ -124,40 +146,40 @@ static const struct iio_chan_spec bd79702_channels[] = {
> };
>
> static const struct iio_chan_spec bd79703_channels[] = {
> - BD79703_CHAN(0),
> - BD79703_CHAN(1),
> - BD79703_CHAN(2),
> - BD79703_CHAN(3),
> - BD79703_CHAN(4),
> - BD79703_CHAN(5),
> + BD79703_CHAN_VFS(0),
> + BD79703_CHAN_VFS(1),
> + BD79703_CHAN_VFS(2),
> + BD79703_CHAN_VFS(3),
> + BD79703_CHAN_VFS(4),
> + BD79703_CHAN_VFS(5),
> };
>
> static const struct bd7970x_chip_data bd79700_chip_data = {
> .name = "bd79700",
> .channels = bd79700_channels,
> .num_channels = ARRAY_SIZE(bd79700_channels),
> - .has_vfs = false,
> + .num_vfs_chan = 0,
> };
>
> static const struct bd7970x_chip_data bd79701_chip_data = {
> .name = "bd79701",
> .channels = bd79701_channels,
> .num_channels = ARRAY_SIZE(bd79701_channels),
> - .has_vfs = false,
> + .num_vfs_chan = 0,
> };
>
> static const struct bd7970x_chip_data bd79702_chip_data = {
> .name = "bd79702",
> .channels = bd79702_channels,
> .num_channels = ARRAY_SIZE(bd79702_channels),
> - .has_vfs = true,
> + .num_vfs_chan = 2,
> };
>
> static const struct bd7970x_chip_data bd79703_chip_data = {
> .name = "bd79703",
> .channels = bd79703_channels,
> .num_channels = ARRAY_SIZE(bd79703_channels),
> - .has_vfs = true,
> + .num_vfs_chan = 3,
> };
>
> 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;
>
> + if (cd->num_vfs_chan > 0) {
> ret = devm_regulator_get_enable_read_voltage(dev, "vfs");
> if (ret < 0)
> return dev_err_probe(dev, ret, "Failed to get Vfs\n");
> - } else {
> - ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
> - if (ret < 0)
> - return dev_err_probe(dev, ret, "Failed to get VCC\n");
> +
> + data->vfs_mv = ret / 1000;
> + data->num_vfs_chan = cd->num_vfs_chan;
> }
> - data->vfs = ret;
>
> idev->channels = cd->channels;
> idev->num_channels = cd->num_channels;
>
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
2026-11-28 3:53 ` Jonathan Cameron
@ 2026-11-30 8:28 ` Matti Vaittinen
0 siblings, 0 replies; 12+ messages in thread
From: Matti Vaittinen @ 2026-11-30 8:28 UTC (permalink / raw)
To: Jonathan Cameron, Matti Vaittinen
Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel
On 28/11/2026 05:53, Jonathan Cameron wrote:
> On Thu, 26 Nov 2026 15:23:10 +0200
> Matti Vaittinen <matti.vaittinen@linux.dev> wrote:
>
>> From: Matti Vaittinen <mazziesaccount@gmail.com>
>>
>> The BD79702 and BD79703 have a VFS pin which can be used to supply a
>> full-scale voltage to be output with maximum DAC word. The driver
>> assumes this voltage is the full-scale voltage for all of the DAC
>> channels. This, however, is not true.
>>
>> The VFS-pin voltage is only used for the first half of the channels. Eg.
>> on BD79703, channels AO1 and AO2 use VFS, AO3 and, AO4 use the VCC.
>> Similarly, the BD79703 channels AO1, AO2, and, AO3 use VFS, AO4, AO5, and
>> AO6 use the VCC.
>>
>> Fix the driver to use correct full-scale voltages (VCC instead of VFS) on
>> the last channels of the BD79702 and BD79703. The BD79700 and BD79701
>> logic should not be changed.
>>
>> NOTE: This change is visible to the user-space, it makes the scale a
>> per-channel property so the sysFS file out_voltage_scale gets replaced
>> by per-channel variants out_voltageN_scale
>>
>> Fixes: af6aca656a85 ("iio: dac: Support ROHM BD79703 DAC")
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> Enjoy the side discussion. I'm going to take the expedient path and
> just merge this. Applied to the fixes-togreg branch of iio.git.
Thanks for applying the fix!
> This wins one of those awards for generally odd things to build
> in hardware.
I kind of understand the idea of the HW design. It allows having two
different scale outputs from single IC. For example, 0-3V and 0-5V,
while having all the DAC steps available for both scales. There may be
designs which benefit from this.
But I agree it is odd, and it totally caught me off guard. I only
noticed this when started adding support for the series of next
generation DAC ICs, bd7971[0-3]. They have the same design. It does not
really help that data-sheets do not explicitly say the VCC is used as a
full-scale voltage for some of the outputs. I just happened to notice
the VFS pin was actually said to be full-scale voltage for AO1, AO2 and
AO3 on a device having 6 channels. The full-scale voltage for the rest
of the outputs just weren't mentioned at all.
Then, one of the block diagrams did have VCC written to a box for some
AOs and VFS for others, but at least I missed this when I wrote drivers
for BD7970x. Oh, and I used same voltage for VCC and VFS in my test
setups :rolleyes:
Well, I confirmed this from the HQ designers - hopefully the fix does
not come too late to some of the users... This had a real chance of
frying-up something :|
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-11-30 14:34 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 13:23 [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages Matti Vaittinen
2026-11-26 13:31 ` Joshua Crofts
2026-11-27 6:34 ` Matti Vaittinen
2026-11-27 11:03 ` Andy Shevchenko
2026-11-27 11:46 ` Matti Vaittinen
2026-11-27 12:08 ` Andy Shevchenko
2026-11-27 15:57 ` Andy Shevchenko
2026-11-30 7:06 ` Matti Vaittinen
2026-11-30 7:01 ` Matti Vaittinen
2026-11-30 14:34 ` Andy Shevchenko
2026-11-28 3:53 ` Jonathan Cameron
2026-11-30 8:28 ` Matti Vaittinen
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®