[PATCH 09/15] iio: adc: at91-sama5d2_adc: adapt the driver for sama7d65

Jonathan Cameron Jonathan.Cameron at huawei.com
Wed Aug 6 08:31:41 PDT 2025


On Mon, 4 Aug 2025 15:32:13 +0530
Varshini Rajendran <varshini.rajendran at microchip.com> wrote:

> Add support to sama7d65 ADC. The differences are highlighted with the
> compatible. The init and parsing of the temperature sensor and
> calibration indexes are the main differences.
> 
> Signed-off-by: Varshini Rajendran <varshini.rajendran at microchip.com>
...

>  static int at91_adc_chan_xlate(struct iio_dev *indio_dev, int chan)
>  {
>  	int i;
> @@ -2319,6 +2360,56 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st,
>  	return ret;
>  }
>  
> +static int at91_sama7d65_adc_temp_sensor_init(struct at91_adc_state *st,
> +					      struct device *dev)
> +{
> +	struct at91_adc_temp_sensor_clb *clb = &st->soc_info.temp_sensor_clb;
> +	struct nvmem_cell *temp_calib;
> +	u32 *buf = NULL;

As per earlier comment and I see Andy raised it as well. __free()
magic dust is useful here.

> +	size_t len;
> +	int ret = 0;
> +
> +	if (!st->soc_info.platform->temp_sensor)
> +		return 0;
> +
> +	/* Get the calibration data from NVMEM. */
> +	temp_calib = devm_nvmem_cell_get(dev, "temperature_calib");
> +	if (IS_ERR(temp_calib)) {
> +		ret = PTR_ERR(temp_calib);
> +		if (ret != -ENOENT)
> +			dev_err(dev, "Failed to get temperature_calib cell!\n");
> +		return ret;
> +	}
> +
> +	buf = nvmem_cell_read(temp_calib, &len);
> +	if (IS_ERR(buf)) {
> +		dev_err(dev, "Failed to read calibration data!\n");
> +		return PTR_ERR(buf);
> +	}
> +
> +	if (len < AT91_SAMA7D65_ADC_TS_CLB_IDX_MAX * sizeof(u32) ||
> +	    buf[0] != AT91_TEMP_CALIB_TAG) {
> +		dev_err(dev, "Invalid calibration data!\n");
> +		ret = -EINVAL;
> +		goto free_buf;
> +	}
> +
> +	/* Store calibration data for later use. */
> +	clb->p1 = buf[AT91_SAMA7D65_ADC_TS_CLB_IDX_P1];
> +	clb->p4 = buf[AT91_SAMA7D65_ADC_TS_CLB_IDX_P4];
> +	clb->p6 = buf[AT91_SAMA7D65_ADC_TS_CLB_IDX_P6];

only these indexes and the MAX check above make this different from
the existing function.  Maybe we could just store those instead
of a function pointer in the device type specific structure.

> +
> +	/*
> +	 * We prepare here the conversion to milli from micro to avoid
> +	 * doing it on hotpath.
> +	 */
> +	clb->p1 = clb->p1 / 1000;
> +
> +free_buf:
> +	kfree(buf);
> +	return ret;
> +}



More information about the linux-arm-kernel mailing list