From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=68.232.153.233 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796195137; b=KQIXn3q98T6wJ/SSepqocEb2PVMqxoOVZH0Yw93/EvR7SCh8fApFO78b0XqE8RcR+4um mMYyFCP9Y3fX8Q6cE9NDBmSSCfCN2D9XATf0qhqx5vEVrw6ECudahiH25/dGxub7CWpNb gq2AL0ngxNo1JvklmYroyDrs7t5884DxNHEnUOaWyI4rSYSjwr1buGqXJIzE7bxGkxl1m Q3lfPtQD2vGcst/tOVKps27G3o3Gdl5NroHxOtFPtdLZK9/jSBnQeHUUMPS4HNExarXe7 MqNXX0h9ynpl1VcRc/8bf3GgyMee+/HZZKmq1lWlTHl2GihD3v+V7cuNXRfI2OotFWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796195137; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-Amp-Result:Received:Received:Received:From:To:CC: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type; bh=zZmb7mSlQDfoiRYIa1i+b4S6pkEhNr1dYaLSoVVbx+8=; b=H32h/OXJSryuVQwzZSr5gO/n9lep2UU/oMjsQBixaRSx06zwADSuQsWOsOtBQd8UGOv6 zrYcDNM5QULn2PV6yfuAL0G5sUT127qVnWEd96aWKAByCOw3nqmhAoI6fqOTf4/WT9TVy DMfzonr9a4dR82yKb2p9Qp14/w0/O1EzH7H5TD0crRq+dapIn7hXsKRX8IR/d8cbBKnkh 1Wv7b7z6dj3g3XMf5Um8XdpUqlF3EkScBisTR5+5CAcOalhMW7V9H9ssZks0cSUcBNnqJ Px471Jjr5+eK0KMRzMOEEFnCwtCzBYFuKb4rU+WIegqAmR2xtwa/BcLMYX2LL+qpBpw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=TYs5uU4i; arc=none smtp.remote-ip=68.232.153.233 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3EA6606A322; Wed, 2 Dec 2026 07:05:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D3EA6606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=TYs5uU4i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1796195136; x=1827731136; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VoYN94zKbxyyu1yQhyBbuORRV9ZyYTcZcx7/ASd6g7Q=; b=TYs5uU4itAe9yRf0bBW+tf+AfQN0lOvmZ8F3ibCEC4BqMGfzQWJf72u/ jZsC9UecYksth/f6Pw2uNyDySRluzVfHEj08Ze0vmX7Ty4hzzf3H5zEJ7 dFCYbHC0XkFv4W6gYq2MS+K6czePZaHnMEUXwYd82KmhGGphvN1NxSliC 2mLSZKFGACxlTmj+7q99GiI120Jz30vJytbUDQ9LWgxOfFoOlErGkPwqP SL4Q3Bh/A92luV6+lwfPAVm08bP38n6fPwvmJ8agTBg5d6UESU3zv7gxf 0ciprTMYusLXlDoq20/dm1bw/psTZpuOTl3l9E+ReLe5e4K0IR3U7mjyZ g==; X-CSE-ConnectionGUID: 1FH2iYAzQ0C8BCc87c711Q== X-CSE-MsgGUID: 4gl2XoTeT3qRGs0oeehS7A== X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="78212713" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 00:05:35 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.87.151) by chn-vm-ex1.mchp-main.com (10.10.87.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.57; Wed, 2 Dec 2026 00:05:34 -0700 Received: from che-ll-i67070a.microchip.com (10.10.85.11) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Wed, 2 Dec 2026 00:05:28 -0700 From: Varshini Rajendran To: Jonathan Cameron , Srinivas Kandagatla , Claudiu Beznea CC: Eugen Hristev , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , "Krzysztof Kozlowski" , Conor Dooley , "Nicolas Ferre" , Alexandre Belloni , , , , , Subject: [PATCH v7 05/18] iio: adc: at91-sama5d2_adc: rework temp calibration layout handling Date: Wed, 2 Dec 2026 12:34:43 +0530 Message-ID: <20261202070458.87970-6-varshini.rajendran@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202070458.87970-1-varshini.rajendran@microchip.com> References: <20261202070458.87970-1-varshini.rajendran@microchip.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Extend support to handle different temperature calibration layouts. Add a temperature calibration data layout structure to describe indexes of the factors P1, P4, P6, tag, minimum length of the packet and the scaling factors for P1 (p1_scale) which are SoC-specific instead of the older non scalable id structure. This helps handle the differences in the same function flow and prepare the calibration data to be applied. Reviewed-by: Eugen Hristev Signed-off-by: Varshini Rajendran --- drivers/iio/adc/at91-sama5d2_adc.c | 63 +++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index 52d2bdff3203..24746a916be5 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -444,6 +445,24 @@ 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) +/** + * struct at91_adc_temp_calib_layout - temperature calibration packet layout + * @tag_idx: index of Packet tag in the NVMEM cell buffer + * @p1_idx: index of FT1_TEMP, equivalent to P1 in the NVMEM cell buffer + * @p4_idx: index of FT1_VPAT, equivalent to P4 in the NVMEM cell buffer + * @p6_idx: index of FT2_VBG, equivalent to P6 in the NVMEM cell buffer + * @min_len: minimum number of u32 words expected in the NVMEM cell buffer + * @p1_scale: scaling factor applied to P1 to convert to millicelcius + */ +struct at91_adc_temp_calib_layout { + unsigned int tag_idx; + unsigned int p1_idx; + unsigned int p4_idx; + unsigned int p6_idx; + unsigned int min_len; + struct u32_fract p1_scale; +}; + /** * struct at91_adc_platform - at91-sama5d2 platform information struct * @layout: pointer to the reg layout struct @@ -462,6 +481,7 @@ static const struct at91_adc_reg_layout sama7g5_layout = { * @oversampling_avail_no: number of available oversampling values * @chan_realbits: realbits for registered channels * @temp_chan: temperature channel index + * @temp_calib_layout: temperature calibration packet layout * @temp_sensor: temperature sensor supported */ struct at91_adc_platform { @@ -479,6 +499,7 @@ struct at91_adc_platform { unsigned int oversampling_avail_no; unsigned int chan_realbits; unsigned int temp_chan; + const struct at91_adc_temp_calib_layout *temp_calib_layout; bool temp_sensor; }; @@ -495,18 +516,13 @@ struct at91_adc_temp_sensor_clb { u32 p6; }; -/** - * enum at91_adc_ts_clb_idx - calibration indexes in NVMEM buffer - * @AT91_ADC_TS_CLB_IDX_P1: index for P1 - * @AT91_ADC_TS_CLB_IDX_P4: index for P4 - * @AT91_ADC_TS_CLB_IDX_P6: index for P6 - * @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, +static const struct at91_adc_temp_calib_layout sama7g5_temp_calib = { + .tag_idx = 1, + .p1_idx = 2, + .p4_idx = 5, + .p6_idx = 7, + .min_len = 19, + .p1_scale = { .numerator = 1000, .denominator = 1 }, }; /* Temperature sensor calibration - Vtemp voltage sensitivity to temperature. */ @@ -744,6 +760,7 @@ static const struct at91_adc_platform sama7g5_platform = { .chan_realbits = 16, .temp_sensor = true, .temp_chan = AT91_SAMA7G5_ADC_TEMP_CHANNEL, + .temp_calib_layout = &sama7g5_temp_calib, }; static int at91_adc_chan_xlate(struct iio_dev *indio_dev, int chan) @@ -2252,12 +2269,19 @@ static int at91_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; + const struct at91_adc_temp_calib_layout *layout; size_t len; int ret = 0; if (!st->soc_info.platform->temp_sensor) return 0; + layout = st->soc_info.platform->temp_calib_layout; + if (!layout) + return -ENODEV; + if (!layout->p1_scale.denominator) + return -EINVAL; + /* Get the calibration data from NVMEM. */ struct nvmem_cell *temp_calib __free(nvmem_cell_put) = nvmem_cell_get(dev, "temperature_calib"); @@ -2273,20 +2297,23 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st, return dev_err_probe(dev, PTR_ERR(buf), "Failed to read calibration data!\n"); - if (len < AT91_ADC_TS_CLB_IDX_MAX * sizeof(*buf)) { + if (len < layout->min_len * sizeof(*buf)) { dev_err(dev, "Invalid calibration data!\n"); return -EINVAL; } /* Store calibration data for later use. */ - clb->p1 = buf[AT91_ADC_TS_CLB_IDX_P1]; - clb->p4 = buf[AT91_ADC_TS_CLB_IDX_P4]; - clb->p6 = buf[AT91_ADC_TS_CLB_IDX_P6]; + clb->p1 = buf[layout->p1_idx]; + clb->p4 = buf[layout->p4_idx]; + clb->p6 = buf[layout->p6_idx]; /* - * We prepare here the conversion to milli to avoid doing it on hotpath. + * Here we prepare the conversion to milli to avoid doing it on hotpath. + * The p1 value is multiplied and divided with a scaling factor as per + * the SoC storage format described by per-platform calibration layout. */ - clb->p1 = clb->p1 * 1000; + clb->p1 *= layout->p1_scale.numerator; + clb->p1 /= layout->p1_scale.denominator; return 0; } -- 2.43.0