All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Varshini Rajendran <varshini.rajendran@microchip.com>
Cc: <eugen.hristev@linaro.org>, <jic23@kernel.org>,
	<dlechner@baylibre.com>, <nuno.sa@analog.com>, <andy@kernel.org>,
	<robh@kernel.org>, <krzk+dt@kernel.org>, <conor+dt@kernel.org>,
	<nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>,
	<claudiu.beznea@tuxon.dev>, <srini@kernel.org>,
	<linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 04/15] iio: adc: at91-sama5d2_adc: update calibration index, validation condition
Date: Wed, 6 Aug 2025 16:26:24 +0100	[thread overview]
Message-ID: <20250806162624.000044ce@huawei.com> (raw)
In-Reply-To: <20250804100219.63325-5-varshini.rajendran@microchip.com>

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

> Add additional condition for validating the calibration data read from
> the OTP through nvmem device interface. Adjust the calibration indexes
> of sama7g5 according to the buffer received from the OTP memory.
Changing those indexes looks to me like either this was broken previously
or we are supporting something new (possibly at the expense of the older
support)

Or is this 'broken' by patch 2 and you are fixing it up here?
If so we normally try not to do that sort of change in multiple steps
because the patches may go via different trees and potentially only
part of it make it to upstream in a particular cycle.

Messy though it is, if you need to change indexes because something
broke doe it all in one patch.

> 
> Signed-off-by: Varshini Rajendran <varshini.rajendran@microchip.com>
> ---
>  drivers/iio/adc/at91-sama5d2_adc.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
> index c3450246730e..d952109a64a9 100644
> --- a/drivers/iio/adc/at91-sama5d2_adc.c
> +++ b/drivers/iio/adc/at91-sama5d2_adc.c
> @@ -445,6 +445,14 @@ static const struct at91_adc_reg_layout sama7g5_layout = {
>  #define at91_adc_writel(st, reg, val)					\
>  	writel_relaxed(val, (st)->base + (st)->soc_info.platform->layout->reg)
>  
> +/*
> + * The calibration data has a TAG to recognize the packet
> + * The tag has a constant value "ACST" with the ASCII
> + * equivalent 0x41435354. This is used to validate the
> + * calibration data obtained from the OTP.
> + */
> +#define AT91_TEMP_CALIB_TAG	0x41435354

Could we treat it as a string and do a strcmp?  Main advantage
is this comment may become unneeded if the code is clear enough.

> +
>  /**
>   * struct at91_adc_platform - at91-sama5d2 platform information struct
>   * @layout:		pointer to the reg layout struct
> @@ -504,10 +512,10 @@ struct at91_adc_temp_sensor_clb {
>   * @AT91_ADC_TS_CLB_IDX_MAX: max index for temperature calibration packet in OTP
>   */
>  enum at91_adc_ts_clb_idx {
> -	AT91_ADC_TS_CLB_IDX_P1 = 2,
> -	AT91_ADC_TS_CLB_IDX_P4 = 5,
> -	AT91_ADC_TS_CLB_IDX_P6 = 7,
> -	AT91_ADC_TS_CLB_IDX_MAX = 19,
> +	AT91_ADC_TS_CLB_IDX_P1 = 1,
> +	AT91_ADC_TS_CLB_IDX_P4 = 4,
> +	AT91_ADC_TS_CLB_IDX_P6 = 6,
> +	AT91_ADC_TS_CLB_IDX_MAX = 18,
>  };
>  
>  /* Temperature sensor calibration - Vtemp voltage sensitivity to temperature. */
> @@ -2281,7 +2289,7 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st,
>  		dev_err(dev, "Failed to read calibration data!\n");
>  		return PTR_ERR(buf);
>  	}
> -	if (len < AT91_ADC_TS_CLB_IDX_MAX * 4) {
> +	if (len < AT91_ADC_TS_CLB_IDX_MAX * 4  || buf[0] != AT91_TEMP_CALIB_TAG) {
>  		dev_err(dev, "Invalid calibration data!\n");
>  		ret = -EINVAL;
>  		goto free_buf;
Not related to this patch, but this would be excellent place to deploy __free
u32 *buf __free(kfree) = nvmem_cell_read(temp_calib, &len);

then can directly return on error here and drop the kfree(buf) below.





  parent reply	other threads:[~2025-08-06 15:42 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 10:02 [PATCH 00/15] Add thermal management support for sama7d65 Varshini Rajendran
2025-08-04 10:02 ` [PATCH 01/15] ARM: dts: microchip: sama7d65: add cpu opps Varshini Rajendran
2025-08-04 10:02 ` [PATCH 02/15] nvmem: microchip-otpc: rework to access packets based on tag Varshini Rajendran
2025-08-04 13:05   ` Andy Shevchenko
2025-08-04 17:49   ` kernel test robot
2025-08-05  6:50   ` Krzysztof Kozlowski
2025-09-14 15:42   ` Claudiu Beznea
2025-08-04 10:02 ` [PATCH 03/15] dt-bindings: microchip-otpc: update dt node example Varshini Rajendran
2025-08-05  6:49   ` Krzysztof Kozlowski
2025-08-04 10:02 ` [PATCH 04/15] iio: adc: at91-sama5d2_adc: update calibration index, validation condition Varshini Rajendran
2025-08-04 13:11   ` Andy Shevchenko
2025-08-06 15:26   ` Jonathan Cameron [this message]
2025-09-14 15:43   ` Claudiu Beznea
2025-08-04 10:02 ` [PATCH 05/15] ARM: dts: microchip: sama7g5: add packet tag as offset for calib Varshini Rajendran
2025-08-05  6:51   ` Krzysztof Kozlowski
2025-08-04 10:02 ` [PATCH 06/15] dt-bindings: nvmem: microchip-otpc: remove stride details Varshini Rajendran
2025-08-05  6:54   ` Krzysztof Kozlowski
2025-08-04 10:02 ` [PATCH 07/15] iio: adc: at91-sama5d2_adc: add temp init function as callback Varshini Rajendran
2025-08-04 13:13   ` Andy Shevchenko
2025-08-04 10:02 ` [PATCH 08/15] dt-bindings: iio: adc: at91-sama5d2: document sama7d65 Varshini Rajendran
2025-08-05  6:55   ` Krzysztof Kozlowski
2025-08-04 10:02 ` [PATCH 09/15] iio: adc: at91-sama5d2_adc: adapt the driver for sama7d65 Varshini Rajendran
2025-08-04 13:19   ` Andy Shevchenko
2025-08-06 15:31   ` Jonathan Cameron
2025-08-04 10:02 ` [PATCH 10/15] ARM: dts: microchip: sama7d65: add node for the ADC Varshini Rajendran
2025-08-04 10:02 ` [PATCH 11/15] dt-bindings: microchip-otpc: document sama7d65 Varshini Rajendran
2025-08-05  6:53   ` Krzysztof Kozlowski
2025-08-04 10:02 ` [PATCH 12/15] ARM: dts: microchip: sama7d65: add otpc node Varshini Rajendran
2025-08-04 10:02 ` [PATCH 13/15] ARM: dts: microchip: sama7d65: add cells for temperature calibration Varshini Rajendran
2025-08-04 10:02 ` [PATCH 14/15] ARM: dts: microchip: sama7d65: add temperature sensor Varshini Rajendran
2025-08-04 10:02 ` [PATCH 15/15] ARM: dts: microchip: sama7d65: add thermal zones node Varshini Rajendran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250806162624.000044ce@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy@kernel.org \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eugen.hristev@linaro.org \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --cc=srini@kernel.org \
    --cc=varshini.rajendran@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.