[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250806163141.00005d83@huawei.com>
Date: Wed, 6 Aug 2025 16:31:41 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Varshini Rajendran <varshini.rajendran@...rochip.com>
CC: <eugen.hristev@...aro.org>, <jic23@...nel.org>, <dlechner@...libre.com>,
<nuno.sa@...log.com>, <andy@...nel.org>, <robh@...nel.org>,
<krzk+dt@...nel.org>, <conor+dt@...nel.org>, <nicolas.ferre@...rochip.com>,
<alexandre.belloni@...tlin.com>, <claudiu.beznea@...on.dev>,
<srini@...nel.org>, <linux-iio@...r.kernel.org>,
<devicetree@...r.kernel.org>, <linux-arm-kernel@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 09/15] iio: adc: at91-sama5d2_adc: adapt the driver for
sama7d65
On Mon, 4 Aug 2025 15:32:13 +0530
Varshini Rajendran <varshini.rajendran@...rochip.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@...rochip.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;
> +}
Powered by blists - more mailing lists