Re: [PATCH v2 8/8] iio: adc: rzt2h: Add support for RZ/V2H(P) SoC

From: Andy Shevchenko

Date: Tue Oct 13 2026 - 15:02:23 EST


On Fri, Oct 09, 2026 at 07:41:22PM +0100, Prabhakar wrote:

> Add support for the ADC found on the Renesas RZ/V2H(P) SoC, which shares
> the RZ/T2H ADC IP but differs in channel count, sampling, calibration and
> resolution support.
>
> The RZ/V2H(P) ADC provides 8 channels, has a fixed conversion time of
> 20 ADCLK cycles, does not support calibration, and supports selectable
> 12-bit and 8-bit conversion resolution.

...

> +static int rzt2h_adc_write_scale(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2)
> +{
> + struct rzt2h_adc *adc = iio_priv(indio_dev);
> + unsigned int i;
> + u64 scale;
> + u32 rem;
> +
> + if (!(adc->chip_info->features & RZT2H_ADC_FEATURE_RES_SELECT))
> + return -EINVAL;
> +
> + for (i = 0; i < chan->num_ext_scan_type; i++) {
> + scale = (u64)RZT2H_ADC_VREF_mV * NANO >>
> + chan->ext_scan_type[i].realbits;
> + if (div_u64_rem(scale, NANO, &rem) == val && rem == val2)
> + break;

Hmm... AFAICT we can use multiplication as the result of the division is just
used to compare.

> + }
> + if (i == chan->num_ext_scan_type)
> + return -EINVAL;
> +
> + /* The scan type changes with the resolution. */
> + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> + if (IIO_DEV_ACQUIRE_FAILED(claim))
> + return -EBUSY;
> +
> + adc->resolution = i;
> +
> + return 0;
> +}

...

> + ret = reset_control_assert(adc->rstc);
> + if (ret)
> + pwrseq_enable(adc->pwrseq);
>
> - return reset_control_assert(adc->rstc);
> + return ret;

Hmm... If it was added in the previous patches, add with unfolded check and
explain in the comments that the code done this way to avoid churn in the
future changes.

--
With Best Regards,
Andy Shevchenko