Re: [PATCH v2] meson saradc: add iio device attrib to switch channel 7 mux

From: andy . shevchenko
Date: Mon May 29 2023 - 19:33:29 EST


Mon, May 29, 2023 at 01:31:40AM +0300, George Stark kirjoitti:
> On 5/28/23 13:46, Andy Shevchenko wrote:
> > On Sun, May 28, 2023 at 12:48:54AM +0300, George Stark wrote:

...

> > > + if (index >= ARRAY_SIZE(chan7_vol))
> > > + index = ARRAY_SIZE(chan7_vol) - 1;
> > I think this is incorrect and prone to error in the future in case this array
> > will be extended. What I would expect is to return something like "unknown".
>
> I agree this part is unclean. Actually the register's last 3 (out of 8)
> possible values are stand for the same mux input "ch7_input". So
> theoretically we can read from register a value out of array bounds. There
> should be a comment at least.

You can add there in the array to extend it up to 8 entries, so it will be
clear. And for the rest you will return unknown / unsupported / etc.

...

> > > +static const char * const chan7_vol[] = {
> > > + "gnd",
> > > + "vdd/4",
> > > + "vdd/2",
> > > + "vdd*3/4",
> > > + "vdd",
> > > + "ch7_input",
> > > +};

> About the question of naming mux inputs from the other letter (vdd/2 vs
> 0.5Vdd etc).
> While I fully agree with you that point is better than slash but mixing
> letter cases... should we?

What's wrong with that?

> e.g. this is how iio_info output looks like now:
> ...
>             voltage7:  (input)
>             3 channel-specific attributes found:
>                 attr  0: mean_raw value: 0
>                 attr  1: raw value: 1
>                 attr  2: scale value: 0.439453125
>         4 device-specific attributes found:
>                 attr  0: chan7_mux value: gnd
>                 attr  1: chan7_mux_available value: gnd vdd/4 vdd/2 vdd*3/4
> vdd ch7_input
>                 attr  2: current_timestamp_clock value: realtime
>
>                 attr  3: waiting_for_supplier value: 0
>
> or naming with Jonathan's approach
> /sys/devices/platform/soc/fe000000.bus/fe002c00.adc/iio:device0/in_voltage_0.5vdd_raw

See the alternative I proposed is to have _ delimiter. But that might make
parsing a bit harder in user space.

--
With Best Regards,
Andy Shevchenko