Re: [PATCH v5 2/2] iio: adc: add Axiado SARADC driver

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-kernel,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-iio
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
On Mon, Aug 10, 2026 at 07:49:36AM -0700, Petar Stepanovic wrote:
> Add support for the SARADC controller found on Axiado AX3000 and
> AX3005 SoCs.
> 
> The driver supports single-shot voltage reads through the IIO
> subsystem. The number of available input channels is selected from
> the SoC match data, allowing AX3000 and AX3005 variants to use the
> same driver.

...

> +/* MANUAL_CTRL register fields */

^^^

> +#define AX_SARADC_MANUAL_CTRL_ENABLE	BIT(0)
> +#define AX_SARADC_MANUAL_CTRL_CH_SEL_MASK	GENMASK(4, 1)
> +
> +#define AX_RESOLUTION_BITS	10
> +#define AX_SARADC_CONV_CYCLES	13
> +#define AX_SARADC_CONV_DELAY_MARGIN_US	10
> +
> +struct axiado_saradc {
> +	struct regmap *regmap;
> +	struct mutex lock; /* Serializes ADC conversions. */

Choose the same style for all single-line comments (here is a period present
while in the above, for instance, there is none).

> +	unsigned long clk_rate;
> +	int vref_uV;
> +};

...

> +static int axiado_saradc_conversion(struct axiado_saradc *info,
> +				    struct iio_chan_spec const *chan, int *val)
> +{
> +	unsigned long usecs;
> +	unsigned int regval;
> +	int ret;
> +
> +	guard(mutex)(&info->lock);
> +
> +	/* Select the channel to be used and trigger conversion */
> +	ret = regmap_write(info->regmap, AX_SARADC_MANUAL_CTRL_REG,
> +			   AX_SARADC_MANUAL_CTRL_ENABLE |
> +			   FIELD_PREP(AX_SARADC_MANUAL_CTRL_CH_SEL_MASK, chan->channel));
> +	if (ret)
> +		return ret;
> +
> +	/* Hardware requires 13 conversion cycles at clk_rate */

> +	usecs = DIV_ROUND_UP(AX_SARADC_CONV_CYCLES * USEC_PER_SEC,
> +			     info->clk_rate);

I think it's okay to have this on a single line (83 characters).

> +	fsleep(usecs + AX_SARADC_CONV_DELAY_MARGIN_US);
> +
> +	ret = regmap_read(info->regmap, AX_SARADC_DOUT_REG, &regval);
> +
> +	/* Best effort to stop manual conversion. */
> +	regmap_write(info->regmap, AX_SARADC_MANUAL_CTRL_REG, 0);
> +
> +	if (ret)
> +		return ret;
> +
> +	*val = regval & GENMASK(AX_RESOLUTION_BITS - 1, 0);
> +
> +	return 0;
> +}

...

> +	soc_data = device_get_match_data(dev);
> +	if (!soc_data)
> +		return dev_err_probe(dev, -EINVAL, "failed to get match data\n");

-ENODATA

-- 
With Best Regards,
Andy Shevchenko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.