[PATCH v3 5/5] meson saradc: support reading from channel 7 mux inputs

Andy Shevchenko andriy.shevchenko at linux.intel.com
Wed Jun 28 03:06:00 PDT 2023


On Wed, Jun 28, 2023 at 01:37:18AM +0300, George Stark wrote:
> Add iio channel for every channel 7 mux input.
> Meson saradc channel 7 is connected to a mux that can switch channel
> input to well-known sources like Vdd, GND and several Vdd dividers.

...

> +static enum meson_sar_adc_chan7_mux_sel chan7_mux_values[] = {
> +	CHAN7_MUX_VSS,
> +	CHAN7_MUX_VDD_DIV4,
> +	CHAN7_MUX_VDD_DIV2,
> +	CHAN7_MUX_VDD_MUL3_DIV4,
> +	CHAN7_MUX_VDD,
> +};
> +
> +static const char * const chan7_mux_names[] = {
> +	"gnd",
> +	"0.25vdd",
> +	"0.5vdd",
> +	"0.75vdd",
> +	"vdd",

For the sake of robustness you can assign like this

	[CHAN7_MUX_VDD_DIV2] = "0.5vdd",

>  };

...

> -	if (chan->type == IIO_VOLTAGE)
> -		return sprintf(label, "channel-%d\n", chan->channel);
> +	if (chan->type == IIO_VOLTAGE) {

> +		if (chan->channel <= NUM_CHAN_7)

I believe you can get rid of this conditional and make diff less ping-pong-ish,
  see below.

> +			return sprintf(label, "channel-%d\n", chan->channel);
> +		if (chan->channel >= NUM_MUX_0_VSS)
> +			return sprintf(label, "%s\n",
> +				chan7_mux_names[chan->channel - NUM_MUX_0_VSS]);
> +	}


	if (chan->type == IIO_VOLTAGE && chan->channel >= NUM_MUX_0_VSS)
		return sprintf(label, "%s\n", chan7_mux_names[chan->channel - NUM_MUX_0_VSS]);

	if (chan->type == IIO_VOLTAGE)
		return sprintf(label, "channel-%d\n", chan->channel);


-- 
With Best Regards,
Andy Shevchenko





More information about the linux-amlogic mailing list