Skip to contentSkip to conversation

NXP SAR ADC IIO driver for s32g2/3 platforms

PATCH Superseded Daniel Lezcano 8 participants 27 messages Sep 3, 2025 – Sep 10, 2025

Subsystems (2)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover NXP SAR ADC IIO driver for s32g2/3 platforms

The S32G2 and S32G3 platforms have a couple of successive approximation register (SAR) ADCs with eight channels and 12-bit resolution. These changes provide the driver support for these ADCs and the bindings describing them.

The driver is derived from the BSP driver version. It has been partly rewritten to conform to upstream criteria.

https://github.com/nxp-auto-linux/linux/blob/release/bsp44.0-6.6.85-rt/drivers/iio/adc/s32cc_adc.c

Daniel Lezcano (2):
dt-bindings: iio: Add the NXP SAR ADC for s32g2/3 platforms
iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

 .../bindings/iio/adc/nxp,s32g2-sar-adc.yaml   |   68 ++
 drivers/iio/adc/Kconfig                       |   13 +
 drivers/iio/adc/Makefile                      |    1 +
 drivers/iio/adc/nxp-sar-adc.c                 | 1046 +++++++++++++++++
 4 files changed, 1128 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml
 create mode 100644 drivers/iio/adc/nxp-sar-adc.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 dt-bindings: iio: adc: Add the NXP SAR ADC for s32g2/3 platforms

The s32g2 and s32g3 NXP platforms have two instances of a Successive Approximation Register ADC. It supports the raw, trigger and scan modes which involves the DMA. Add their descriptions.

---
 .../bindings/iio/adc/nxp,s32g2-sar-adc.yaml   | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml
Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml new file +68 -0
new file mode 100644
index 000000000000..dc6ec240f816
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/nxp,s32g2-sar-adc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP Successive Approximation ADC
+
+description:
+  The NXP SAR ADC provides fast and accurate analog-to-digital
+  conversion using the Successive Approximation Register (SAR) method.
+  It has 12-bit resolution with 8 input channels. Conversions can be
+  launched in software or using hardware triggers. It supports
+  continuous and one-shot modes with separate registers.
+
+maintainers:
+  - Daniel Lezcano <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - const: nxp,s32g2-sar-adc
+      - items:
+          - const: nxp,s32g3-sar-adc
+          - const: nxp,s32g2-sar-adc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 1
+
+  clock-names:
+    minItems: 1
+
+  dmas:
+    minItems: 1
+
+  dma-names:
+    const: rx
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - dmas
+  - dma-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    adc@401f8000 {
+        compatible = "nxp,s32g2-sar-adc";
+        reg = <0x401f8000 0x1000>;
+        interrupts = <GIC_SPI 70 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clks 0x41>;
+        clock-names = "adc";
+        dmas = <&edma0 0 32>;
+        dma-names = "rx";
+    };
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] dt-bindings: iio: adc: Add the NXP SAR ADC for s32g2/3 platforms

Quoted 10 lines · Daniel Lezcano

The s32g2 and s32g3 NXP platforms have two instances of a Successive Approximation Register ADC. It supports the raw, trigger and scan modes which involves the DMA. Add their descriptions.

---
 .../bindings/iio/adc/nxp,s32g2-sar-adc.yaml   | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml
reviewer
#3 lore raw

Re: [PATCH v1 1/2] dt-bindings: iio: adc: Add the NXP SAR ADC for s32g2/3 platforms

In reply to Daniel Lezcano

On 9/3/25 5:27 AM, Daniel Lezcano wrote:

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+  clock-names:
+    minItems: 1

Usually if there is only 1 clock, we don't bother with clock-names.

If we keep clock names though, I think it should be:

clock-names:
items:
const: adc

Since that is the only allowed name.

Although the reference manual calls this the "bus" clock, so that might be a better name.

Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml new file +13 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    adc@401f8000 {
+        compatible = "nxp,s32g2-sar-adc";
+        reg = <0x401f8000 0x1000>;
+        interrupts = <GIC_SPI 70 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clks 0x41>;
+        clock-names = "adc";
+        dmas = <&edma0 0 32>;
+        dma-names = "rx";
+    };
#4 lore raw

Re: [PATCH v1 1/2] dt-bindings: iio: adc: Add the NXP SAR ADC for s32g2/3 platforms

In reply to Daniel Lezcano
Quoted 7 lines · Daniel Lezcano
Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml new file +7 -0
+
+properties:
+  compatible:
+    oneOf:
+      - const: nxp,s32g2-sar-adc
+      - items:
+          - const: nxp,s32g3-sar-adc

Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml line 34

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml new file +10 -0
+          - const: nxp,s32g2-sar-adc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 1

Wrong constraint, look at other properties here. maxItems

Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml line 37

Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml new file +3 -0
+
+  clock-names:
+    minItems: 1

Missing constraints, just drop entire clock-names.

Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml line 40

Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml new file +3 -0
+
+  dmas:
+    minItems: 1

Also needs fixes.

Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml line 52

Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml new file +12 -0
+
+  dma-names:
+    const: rx
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - dmas
+  - dma-names

Best regards,
Krzysztof

#5 lore raw

PATCH 2/2 iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

In reply to Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

---
 drivers/iio/adc/Kconfig       |   13 +
 drivers/iio/adc/Makefile      |    1 +
 drivers/iio/adc/nxp-sar-adc.c | 1046 +++++++++++++++++++++++++++++++++
 3 files changed, 1060 insertions(+)
 create mode 100644 drivers/iio/adc/nxp-sar-adc.c
drivers/iio/adc/Kconfig +13 -0
index 6de2abad0197..4c2473a1fa20 100644
@@ -1168,6 +1168,19 @@ config NPCM_ADC
 	  This driver can also be built as a module. If so, the module
 	  will be called npcm_adc.
 
+config NXP_SAR_ADC
+	tristate "NXP S32G SAR-ADC driver"
+	depends on ARCH_S32 || COMPILE_TEST
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select IIO_SYSFS_TRIGGER
+	help
+	  Say yes here to build support for S32G platforms
+	  analog-to-digital converter.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called nxp_sar_adc.
+
 config PAC1921
 	tristate "Microchip Technology PAC1921 driver"
 	depends on I2C
drivers/iio/adc/Makefile +1 -0
index 1c6ca5fd4b6d..d1d939753bcc 100644
@@ -119,6 +119,7 @@ obj-$(CONFIG_RN5T618_ADC) += rn5t618-adc.o
 obj-$(CONFIG_ROHM_BD79124) += rohm-bd79124.o
 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
 obj-$(CONFIG_RZG2L_ADC) += rzg2l_adc.o
+obj-$(CONFIG_NXP_SAR_ADC) += nxp-sar-adc.o
 obj-$(CONFIG_SC27XX_ADC) += sc27xx_adc.o
 obj-$(CONFIG_SD_ADC_MODULATOR) += sd_adc_modulator.o
 obj-$(CONFIG_SOPHGO_CV1800B_ADC) += sophgo-cv1800b-adc.o
drivers/iio/adc/nxp-sar-adc.c new file +1046 -0

1,046 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 34 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

Quoted 1 line

---

Hi David,

Just some minor review for now...

Quoted 7 lines

 drivers/iio/adc/Kconfig       |   13 + drivers/iio/adc/Makefile      |    1 + drivers/iio/adc/nxp-sar-adc.c | 1046 +++++++++++++++++++++++++++++++++

 3 files changed, 1060 insertions(+)

 create mode 100644 drivers/iio/adc/nxp-sar-adc.c

...

Quoted 8 lines
(quoted diff) +2 -0
+
+static int nxp_sar_adc_dma_probe(struct device *dev, struct nxp_sar_adc

*info)

drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+{
+	struct device *dev_dma;
+	int ret;
+	u8 *rx_buf;
+

drivers/iio/adc/nxp-sar-adc.c line 843

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	info->dma_chan = devm_dma_request_chan(dev, "rx");
+	if (IS_ERR(info->dma_chan))
+		return PTR_ERR(info->dma_chan);
+
+	dev_dma = info->dma_chan->device->dev;
+	rx_buf = dma_alloc_coherent(dev_dma, NXP_SAR_ADC_DMA_BUFF_SZ,
+				    &info->rx_dma_buf, GFP_KERNEL);
+	if (!rx_buf)
+		return -ENOMEM;
+

The above needs some discussion at the very least. Have you considered the IIO DMA buffer interface? It should be extendable to accommodate any particularity of your usecase (or we should at least discuss it).

With it, you also gain a userspace interface where you can actually share DMA buffers in a zero copy fashion. You can also share these buffers with USB gadgets. For instance, with libiio, you would be able to fetch samples from your host machine (through USB) in a very fast way (zero copy between IIO and USB).

Setting up DMA to then "having" to push it to a SW buffer and needing a syscall to retrieve the data seems counter-productive.

Quoted 23 lines
drivers/iio/adc/nxp-sar-adc.c new file +23 -0
+	info->dma_buf.buf = rx_buf;
+
+	info->dma_config.direction = DMA_DEV_TO_MEM;
+	info->dma_config.src_addr_width = NXP_SAR_ADC_DMA_SAMPLE_SZ;
+	info->dma_config.src_maxburst = 1;
+
+	ret = devm_add_action_or_reset(dev, nxp_sar_adc_dma_remove, info);
+	if (ret) {
+		nxp_sar_adc_dma_remove(info);
+		return ret;
+	}
+
+	return 0;
+}
+
+/*
+ * The documentation describes the reset values for the
+ * registers. However some registers do not have these values after a
+ * reset. It is a not desirable situation. In some other SoC family
+ * documentation NXP recommend to not assume the default values are
+ * set and to initialize the registers conforming to the documentation
+ * reset information to prevent this situation. Assume the same rule
+ * applies here as there is a discrepancy between what is read from

drivers/iio/adc/nxp-sar-adc.c line 876

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+ * the registers at reset time and the documentation.
+ */
+static void nxp_sar_adc_set_default_values(struct nxp_sar_adc *info)
+{
+	const u32 mcr_default	= 0x00003901;
+	const u32 msr_default	= 0x00000001;
+	const u32 ctr_default	= 0x00000014;
+	const u32 cimr_default	= 0x00000000;
+	const u32 ncmr_default	= 0x00000000;
+

const does not really bring much here. I would rather have them as #defines.

Quoted 18 lines
drivers/iio/adc/nxp-sar-adc.c new file +18 -0
+	writel(mcr_default, REG_ADC_MCR(info->regs));
+	writel(msr_default, REG_ADC_MSR(info->regs));
+	writel(ctr_default, REG_ADC_CTR0(info->regs));
+	writel(ctr_default, REG_ADC_CTR1(info->regs));
+	writel(cimr_default, REG_ADC_CIMR0(info->regs));
+	writel(cimr_default, REG_ADC_CIMR1(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR0(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR1(info->regs));
+}
+
+static int nxp_sar_adc_probe(struct platform_device *pdev)
+{
+	const struct nxp_sar_adc_data *data;
+	struct nxp_sar_adc *info;
+	struct iio_dev *indio_dev;
+	struct resource *mem;
+	struct device *dev = &pdev->dev;
+	int irq;

drivers/iio/adc/nxp-sar-adc.c line 904

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(struct nxp_sar_adc));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	info = iio_priv(indio_dev);
+
+	data = of_device_get_match_data(dev);
+

device_get_match_data()

Quoted 54 lines
drivers/iio/adc/nxp-sar-adc.c new file +15 -0
+	info->vref = data->vref;
+
+	info->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
+	if (IS_ERR(info->regs))
+		return dev_err_probe(dev, PTR_ERR(info->regs),
+				     "failed to get and remap resource");
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return dev_err_probe(dev, irq, "no irq resource\n");
+
+	ret = devm_request_irq(dev, irq, nxp_sar_adc_isr, 0,
+			       dev_name(dev), indio_dev);
+	if (ret < 0)
+		dev_err_probe(dev, ret, "failed requesting irq, irq = %d\n",

irq);

drivers/iio/adc/nxp-sar-adc.c new file +37 -0
+
+	info->regs_phys = mem->start;
+	spin_lock_init(&info->lock);
+
+	info->clk = devm_clk_get_enabled(dev, "adc");
+	if (IS_ERR(info->clk))
+		return dev_err_probe(dev, PTR_ERR(info->clk),
+				     "failed to get the clock\n");
+
+	platform_set_drvdata(pdev, indio_dev);
+
+	init_completion(&info->completion);
+
+	indio_dev->name = dev_name(dev);
+	indio_dev->info = &nxp_sar_adc_iio_info;
+	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+	indio_dev->channels = nxp_sar_adc_iio_channels;
+	indio_dev->num_channels = ARRAY_SIZE(nxp_sar_adc_iio_channels);
+
+	nxp_sar_adc_set_default_values(info);
+
+	ret = nxp_sar_adc_calibration(info);
+	if (ret) {
+		dev_err(dev, "Calibration failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = nxp_sar_adc_dma_probe(dev, info);
+	if (ret) {
+		dev_err(dev, "Failed to initialize the dma\n");
+		return ret;
+	}
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &iio_pollfunc_store_time,
+					      &nxp_sar_adc_trigger_handler,
+					     

&iio_triggered_buffer_setup_ops);

drivers/iio/adc/nxp-sar-adc.c line 964

Quoted 8 lines
drivers/iio/adc/nxp-sar-adc.c new file +8 -0
+	if (ret < 0) {
+		dev_err(dev, "Couldn't initialise the buffer\n");
+		return ret;
+	}
+
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret) {
+		dev_err(dev, "Couldn't register the device.\n");

dev_err_probe(). Ditto for all other places.

drivers/iio/adc/nxp-sar-adc.c line 968

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +4 -0
+		return ret;
+	}
+
+	dev_info(dev, "Device initialized successfully.\n");

dev_dbg() if you want to keep it but kind of useless IMHO.

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+	return 0;
+}
+
+static void nxp_sar_adc_remove(struct platform_device *pdev)
+{

drivers/iio/adc/nxp-sar-adc.c line 984

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct nxp_sar_adc *info = iio_priv(indio_dev);
+
+	nxp_sar_adc_stop_conversion(info);
+	nxp_sar_adc_channels_disable(info, REG_ADC_CH_MASK);
+	nxp_sar_adc_dma_channels_disable(info, REG_ADC_CH_MASK);
+	nxp_sar_adc_dma_cfg(info, false);
+	nxp_sar_adc_disable(info);
+	dmaengine_terminate_sync(info->dma_chan);
+	iio_device_unregister(indio_dev);

You're using devm_iio_device_register().

Quoted 37 lines
drivers/iio/adc/nxp-sar-adc.c new file +36 -0
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int nxp_sar_adc_suspend(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct nxp_sar_adc *info = iio_priv(indio_dev);
+
+	info->pwdn = nxp_sar_adc_disable(info);
+	info->inpsamp = nxp_sar_adc_conversion_timing_get(info);
+
+	clk_disable_unprepare(info->clk);
+
+	return 0;
+}
+
+static int nxp_sar_adc_resume(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct nxp_sar_adc *info = iio_priv(indio_dev);
+	int ret;
+
+	ret = clk_prepare_enable(info->clk);
+	if (ret)
+		return ret;
+
+	nxp_sar_adc_conversion_timing_set(info, info->inpsamp);
+
+	if (!info->pwdn)
+		nxp_sar_adc_enable(info);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(nxp_sar_adc_pm_ops, nxp_sar_adc_suspend,

nxp_sar_adc_resume);

drivers/iio/adc/nxp-sar-adc.c line 1026

Quoted 6 lines
drivers/iio/adc/nxp-sar-adc.c new file +6 -0
+
+static const struct nxp_sar_adc_data s32g2_sar_adc_data = { .vref = 1800 };
+
+static const struct of_device_id nxp_sar_adc_match[] = {
+	{ .compatible = "nxp,s32g2-sar-adc", .data = &s32g2_sar_adc_data },
+	{ /* sentinel */ }

No need for the comment. Kind of obvious :)

drivers/iio/adc/nxp-sar-adc.c line 1036

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+};
+MODULE_DEVICE_TABLE(of, nxp_sar_adc_match);
+
+static struct platform_driver nxp_sar_adc_driver = {
+	.probe          = nxp_sar_adc_probe,
+	.remove         = nxp_sar_adc_remove,
+	.driver         = {
+		.name   = DRIVER_NAME,
+		.of_match_table = nxp_sar_adc_match,
+#ifdef CONFIG_PM_SLEEP

You should not need the above. Look at pm_ptr() and friends.

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+		.pm     = &nxp_sar_adc_pm_ops,
+#endif
+	},
+};
+
+module_platform_driver(nxp_sar_adc_driver);
+
+MODULE_AUTHOR("NXP");
+MODULE_DESCRIPTION("NXP SAR-ADC driver");
+MODULE_LICENSE("GPL");
#7 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Hi Nuno,

Quoted 37 lines · Nuno Sá
Quoted 34 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

Quoted 1 line

---

Quoted 1 line

Hi David,

s/David/Daniel/ :)

Quoted 1 line

Just some minor review for now...

Whow, thanks for fast review !

[ ... ]

Quoted 22 lines
Quoted 7 lines

+static int nxp_sar_adc_dma_probe(struct device *dev, struct nxp_sar_adc *info)

drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+{
+	struct device *dev_dma;
+	int ret;
+	u8 *rx_buf;
+

drivers/iio/adc/nxp-sar-adc.c line 843

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	info->dma_chan = devm_dma_request_chan(dev, "rx");
+	if (IS_ERR(info->dma_chan))
+		return PTR_ERR(info->dma_chan);
+
+	dev_dma = info->dma_chan->device->dev;
+	rx_buf = dma_alloc_coherent(dev_dma, NXP_SAR_ADC_DMA_BUFF_SZ,
+				    &info->rx_dma_buf, GFP_KERNEL);
+	if (!rx_buf)
+		return -ENOMEM;
+

The above needs some discussion at the very least. Have you considered the IIO DMA buffer interface? It should be extendable to accommodate any particularity of your usecase (or we should at least discuss it).

Quoted 7 lines

With it, you also gain a userspace interface where you can actually share DMA buffers in a zero copy fashion. You can also share these buffers with USB gadgets. For instance, with libiio, you would be able to fetch samples from your host machine (through USB) in a very fast way (zero copy between IIO and USB).

Setting up DMA to then "having" to push it to a SW buffer and needing a syscall to retrieve the data seems counter-productive.

I'm not very used to dma. If there is a better implementation to put in place I'll be glad to take any suggestion to understand the approach.

Is there any driver using the IIO DMA buffer interface I can refer to ?

[ ... ]

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#8 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

In reply to Nuno Sá
Quoted 37 lines · On Wed, 03 Sep 2025 12:20:39 +0100 Nuno Sá <[email protected]> wrote:
Quoted 34 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

Quoted 1 line

---

Quoted 3 lines

Hi David,

Just some minor review for now...

A couple of follow ups (ignoring the DMA buf as others are better than I am to comment on that!)

Quoted 12 lines
Quoted 12 lines
drivers/iio/adc/nxp-sar-adc.c new file +12 -0
+/*
+ * The documentation describes the reset values for the
+ * registers. However some registers do not have these values after a
+ * reset. It is a not desirable situation. In some other SoC family
+ * documentation NXP recommend to not assume the default values are
+ * set and to initialize the registers conforming to the documentation
+ * reset information to prevent this situation. Assume the same rule
+ * applies here as there is a discrepancy between what is read from
+ * the registers at reset time and the documentation.
+ */
+static void nxp_sar_adc_set_default_values(struct nxp_sar_adc *info)
+{
Quoted 8 lines

drivers/iio/adc/nxp-sar-adc.c line 876

Quoted 6 lines
drivers/iio/adc/nxp-sar-adc.c new file +6 -0
+	const u32 mcr_default	= 0x00003901;
+	const u32 msr_default	= 0x00000001;
+	const u32 ctr_default	= 0x00000014;
+	const u32 cimr_default	= 0x00000000;
+	const u32 ncmr_default	= 0x00000000;
+  

const does not really bring much here. I would rather have them as #defines.

Unless they can be broken down into meaningful fields I'd not bother with defines. Just put the values in the writel() as their meaning is clear from what is being registered.

Quoted 11 lines
Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+	writel(mcr_default, REG_ADC_MCR(info->regs));
+	writel(msr_default, REG_ADC_MSR(info->regs));
+	writel(ctr_default, REG_ADC_CTR0(info->regs));
+	writel(ctr_default, REG_ADC_CTR1(info->regs));
+	writel(cimr_default, REG_ADC_CIMR0(info->regs));
+	writel(cimr_default, REG_ADC_CIMR1(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR0(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR1(info->regs));
+}
Quoted 12 lines

drivers/iio/adc/nxp-sar-adc.c line 1036

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+};
+MODULE_DEVICE_TABLE(of, nxp_sar_adc_match);
+
+static struct platform_driver nxp_sar_adc_driver = {
+	.probe          = nxp_sar_adc_probe,
+	.remove         = nxp_sar_adc_remove,
+	.driver         = {
+		.name   = DRIVER_NAME,
+		.of_match_table = nxp_sar_adc_match,
+#ifdef CONFIG_PM_SLEEP  

You should not need the above. Look at pm_ptr() and friends.

Further to that, DEFINE_SIMPLE_DEV_PM_OPS() and drop the guards around the functions. The trick here is that it exposes the functions to the compiler but lets it figure out they aren't actually used and drop them. All with out ifdef or __maybe_unused etc.

Quoted 12 lines
Quoted 11 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+		.pm     = &nxp_sar_adc_pm_ops,
+#endif
+	},
+};
+
+module_platform_driver(nxp_sar_adc_driver);
+
+MODULE_AUTHOR("NXP");
+MODULE_DESCRIPTION("NXP SAR-ADC driver");
+MODULE_LICENSE("GPL");  
#9 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

In reply to Nuno Sá

Hi Nuno,

Quoted 36 lines · Nuno Sá
Quoted 35 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

---

[ ... ]

Quoted 11 lines

The above needs some discussion at the very least. Have you considered the IIO DMA buffer interface? It should be extendable to accommodate any particularity of your usecase (or we should at least discuss it).

With it, you also gain a userspace interface where you can actually share DMA buffers in a zero copy fashion. You can also share these buffers with USB gadgets. For instance, with libiio, you would be able to fetch samples from your host machine (through USB) in a very fast way (zero copy between IIO and USB).

Setting up DMA to then "having" to push it to a SW buffer and needing a syscall to retrieve the data seems counter-productive.

I've read a bit about the DMA engine. It is unclear how to use it and there are very few examples in the different drivers to refer to.

This proposed driver supports the RAW, BUFFER and TRIGGERED.

Shall I create an IIO device with the modes:

indio_dev->modes =
INDIO_DIRECT_MODE |
INDIO_BUFFER_HARDWARE |
INDIO_BUFFER_TRIGGERED

And then use:

devm_iio_triggered_buffer_setup()

and

devm_iio_dmaengine_buffer_setup_with_handle

?

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
reviewer
#10 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 55 lines · Daniel Lezcano

Hi Nuno,

Quoted 36 lines · Nuno Sá
Quoted 35 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

---

[ ... ]

Quoted 11 lines

The above needs some discussion at the very least. Have you considered the IIO DMA buffer interface? It should be extendable to accommodate any particularity of your usecase (or we should at least discuss it).

With it, you also gain a userspace interface where you can actually share DMA buffers in a zero copy fashion. You can also share these buffers with USB gadgets. For instance, with libiio, you would be able to fetch samples from your host machine (through USB) in a very fast way (zero copy between IIO and USB).

Setting up DMA to then "having" to push it to a SW buffer and needing a syscall to retrieve the data seems counter-productive.

Quoted 8 lines

I've read a bit about the DMA engine. It is unclear how to use it and there are very few examples in the different drivers to refer to.

This proposed driver supports the RAW, BUFFER and TRIGGERED.

Shall I create an IIO device with the modes:

indio_dev->modes =
    INDIO_DIRECT_MODE |

Only INDIO_DIRECT_MODE needs to be set here.

Quoted 6 lines

    INDIO_BUFFER_HARDWARE |
    INDIO_BUFFER_TRIGGERED

And then use:

devm_iio_triggered_buffer_setup()

Yes, use this and it will add INDIO_BUFFER_TRIGGERED to the flags.

Quoted 4 lines

and

devm_iio_dmaengine_buffer_setup_with_handle

Likewise, this will add INDIO_BUFFER_HARDWARE.

And you likely only need to call devm_iio_dmaengine_buffer_setup() which will save some boilerplate code.

Quoted 5 lines

?

#11 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 77 lines · David Lechner
Quoted 55 lines · Daniel Lezcano

Hi Nuno,

Quoted 36 lines · Nuno Sá
Quoted 35 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

---

[ ... ]

Quoted 11 lines

The above needs some discussion at the very least. Have you considered the IIO DMA buffer interface? It should be extendable to accommodate any particularity of your usecase (or we should at least discuss it).

With it, you also gain a userspace interface where you can actually share DMA buffers in a zero copy fashion. You can also share these buffers with USB gadgets. For instance, with libiio, you would be able to fetch samples from your host machine (through USB) in a very fast way (zero copy between IIO and USB).

Setting up DMA to then "having" to push it to a SW buffer and needing a syscall to retrieve the data seems counter-productive.

Quoted 8 lines

I've read a bit about the DMA engine. It is unclear how to use it and there are very few examples in the different drivers to refer to.

This proposed driver supports the RAW, BUFFER and TRIGGERED.

Shall I create an IIO device with the modes:

indio_dev->modes =
    INDIO_DIRECT_MODE |

Only INDIO_DIRECT_MODE needs to be set here.

Quoted 6 lines

    INDIO_BUFFER_HARDWARE |
    INDIO_BUFFER_TRIGGERED

And then use:

devm_iio_triggered_buffer_setup()

Yes, use this and it will add INDIO_BUFFER_TRIGGERED to the flags.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

and

devm_iio_dmaengine_buffer_setup_with_handle

Likewise, this will add INDIO_BUFFER_HARDWARE.

And you likely only need to call devm_iio_dmaengine_buffer_setup() which will save some boilerplate code.

What is still unclear for me is the trigger and the dma modes.

If the dma engine is supported, I should use devm_iio_dmaengine_buffer_setup_with_handle(), but will the trigger mode be supported also automatically (I don't see a clear answer in the documentation neither in the drivers) ?

If not, shall I call devm_iio_triggered_buffer_setup() and devm_iio_dmaengine_buffer_setup_with_handle() ?

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
reviewer
#12 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 84 lines · Daniel Lezcano
Quoted 83 lines · David Lechner
Quoted 55 lines · Daniel Lezcano

Hi Nuno,

Quoted 36 lines · Nuno Sá
Quoted 35 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

---

[ ... ]

Quoted 11 lines

The above needs some discussion at the very least. Have you considered the IIO DMA buffer interface? It should be extendable to accommodate any particularity of your usecase (or we should at least discuss it).

With it, you also gain a userspace interface where you can actually share DMA buffers in a zero copy fashion. You can also share these buffers with USB gadgets. For instance, with libiio, you would be able to fetch samples from your host machine (through USB) in a very fast way (zero copy between IIO and USB).

Setting up DMA to then "having" to push it to a SW buffer and needing a syscall to retrieve the data seems counter-productive.

Quoted 8 lines

I've read a bit about the DMA engine. It is unclear how to use it and there are very few examples in the different drivers to refer to.

This proposed driver supports the RAW, BUFFER and TRIGGERED.

Shall I create an IIO device with the modes:

indio_dev->modes =
     INDIO_DIRECT_MODE |

Only INDIO_DIRECT_MODE needs to be set here.

Quoted 6 lines

     INDIO_BUFFER_HARDWARE |
     INDIO_BUFFER_TRIGGERED

And then use:

devm_iio_triggered_buffer_setup()

Yes, use this and it will add INDIO_BUFFER_TRIGGERED to the flags.

Quoted 4 lines

and

devm_iio_dmaengine_buffer_setup_with_handle

Likewise, this will add INDIO_BUFFER_HARDWARE.

Quoted 9 lines
Quoted 2 lines

And you likely only need to call devm_iio_dmaengine_buffer_setup() which will save some boilerplate code.

What is still unclear for me is the trigger and the dma modes.

If the dma engine is supported, I should use devm_iio_dmaengine_buffer_setup_with_handle(), but will the trigger mode be supported also automatically (I don't see a clear answer in the documentation neither in the drivers) ?

If not, shall I call devm_iio_triggered_buffer_setup() and devm_iio_dmaengine_buffer_setup_with_handle() ?

Taking a step back, what sort of real-world uses cases do you need to support? Or are you just trying to implement everything that the ADC can do? The latter can be a bit risky because you might end making something where you can't do a buffered read and a single channel read at the same time, but later find out you have a real-world application that needs to do this.

It looks like it would be possible to implement buffered reads in lots of ways. IIO devices can have more than one buffer per device so we can add more in the future if we need to. So I would just drop the DMA part of the implementation for now and implement the basic triggered buffer using MCR[NSTART] and ECH (End of Chain) interrupt request and just reading data from the ICDR registers.

I would wait to have a real-world application that requires DMA to decide the best way to implement that. There are lots of possibilities, like does it need an external trigger or is continuous mode good enough? Does it need to be cyclic (something the IIO subsystem doesn't really support yet) or not. Is exact sample timing important or do we just need a big buffer? These questions we can't really answer without a specific application to use it.

#13 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

Quoted 12 lines

Taking a step back, what sort of real-world uses cases do you need to support? Or are you just trying to implement everything that the ADC can do? The latter can be a bit risky because you might end making something where you can't do a buffered read and a single channel read at the same time, but later find out you have a real-world application that needs to do this.

It looks like it would be possible to implement buffered reads in lots of ways. IIO devices can have more than one buffer per device so we can add more in the future if we need to. So I would just drop the DMA part of the implementation for now and implement the basic triggered buffer using MCR[NSTART] and ECH (End of Chain) interrupt request and just reading data from the ICDR registers.

Quoted 6 lines

I would wait to have a real-world application that requires DMA to decide the best way to implement that. There are lots of possibilities, like does it need an external trigger or is continuous mode good enough? Does it need to be cyclic (something the IIO subsystem doesn't really support yet) or not. Is exact sample timing important or do we just need a big buffer? These questions we can't really answer without a specific application to use it.

In the case of this IP, the use cases are in the automotive context. The system running on the APU is supposed to monitor at high rate (or not) the different channels which can be connected to any device the integrator choose to use.

For this reason, the driver should be able to support the different modes because the integrator of the car computer can decide to monitor the devices connected to the different channels differently.

Said differently, we need these modes because the capture depends on what the integrator decide to connect to the different channels. That could be a real high rate sampling, or triggered with a dedicated global timer on the system or just read the value at a low rate. We just know all these use cases exist.

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
reviewer
#14 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 31 lines · Daniel Lezcano
Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

Quoted 12 lines

Taking a step back, what sort of real-world uses cases do you need to support? Or are you just trying to implement everything that the ADC can do? The latter can be a bit risky because you might end making something where you can't do a buffered read and a single channel read at the same time, but later find out you have a real-world application that needs to do this.

It looks like it would be possible to implement buffered reads in lots of ways. IIO devices can have more than one buffer per device so we can add more in the future if we need to. So I would just drop the DMA part of the implementation for now and implement the basic triggered buffer using MCR[NSTART] and ECH (End of Chain) interrupt request and just reading data from the ICDR registers.

Quoted 6 lines

I would wait to have a real-world application that requires DMA to decide the best way to implement that. There are lots of possibilities, like does it need an external trigger or is continuous mode good enough? Does it need to be cyclic (something the IIO subsystem doesn't really support yet) or not. Is exact sample timing important or do we just need a big buffer? These questions we can't really answer without a specific application to use it.

In the case of this IP, the use cases are in the automotive context. The system running on the APU is supposed to monitor at high rate (or not) the different channels which can be connected to any device the integrator choose to use.

For this reason, the driver should be able to support the different modes because the integrator of the car computer can decide to monitor the devices connected to the different channels differently.

Said differently, we need these modes because the capture depends on what the integrator decide to connect to the different channels.

...

Quoted 1 line

We just know all these use cases exist.

Changing the order here a bit:

Quoted 1 line

or just read the value at a low rate.

For this, I think reading _raw attributes/in-kernel APIs/INDIO_BUFFER_TRIGGERED (no DMA) covers these use cases.

Quoted 1 line

That could be a real high rate sampling,

For this, devm_iio_dmaengine_buffer_setup() should work with continuous mode to sample as fast as possible.

In both of the above a sampling_frequency attribute would control the prescalar of the ADC bus clock to give some control over the hardware sampling rate. There is no IIO trigger device in this case.

Quoted 1 line

or triggered with a dedicated global timer on the system

For this one, we would want a trigger-sources = <&timer>; property in the devicetree to connect the timer trigger to the ADC. This would probably trigger a DMA transfer if precise timing is important. In this case, it might make sense to have a buffer/sampling_frequency attribute to control the timer. There wouldn't need to be a separate IIO trigger device in this case either.

#15 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 27 lines · David Lechner
Quoted 26 lines · Daniel Lezcano
Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

Quoted 18 lines

Taking a step back, what sort of real-world uses cases do you need to support? Or are you just trying to implement everything that the ADC can do? The latter can be a bit risky because you might end making something where you can't do a buffered read and a single channel read at the same time, but later find out you have a real-world application that needs to do this.

It looks like it would be possible to implement buffered reads in lots of ways. IIO devices can have more than one buffer per device so we can add more in the future if we need to. So I would just drop the DMA part of the implementation for now and implement the basic triggered buffer using MCR[NSTART] and ECH (End of Chain) interrupt request and just reading data from the ICDR registers.

I would wait to have a real-world application that requires DMA to decide the best way to implement that. There are lots of possibilities, like does it need an external trigger or is continuous mode good enough? Does it need to be cyclic (something the IIO subsystem doesn't really support yet) or not. Is exact sample timing important or do we just need a big buffer? These questions we can't really answer without a specific application to use it.

Quoted 7 lines
Quoted 5 lines

In the case of this IP, the use cases are in the automotive context. The system running on the APU is supposed to monitor at high rate (or not) the different channels which can be connected to any device the integrator choose to use.

For this reason, the driver should be able to support the different modes because the integrator of the car computer can decide to monitor the devices connected to the different channels differently.

Said differently, we need these modes because the capture depends on what the integrator decide to connect to the different channels.

...

Quoted 1 line

We just know all these use cases exist.

The submitted driver supports the three modes.

Nuno asked to use the IIO dma engine API.

However there is few information and examples with the API and I failed to use the devm_iio_dmaengine_buffer_setup_with_handle() function.

AFAICT, devm_iio_dmaengine_buffer_setup_ext() can not be used because dma_slave_config() is not called, thus the src_addr is not set.

Is there any example somewhere, documentation or guidance to use the API?

Thanks

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
reviewer
#16 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 43 lines · Daniel Lezcano
Quoted 27 lines · David Lechner
Quoted 26 lines · Daniel Lezcano
Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

Quoted 18 lines

Taking a step back, what sort of real-world uses cases do you need to support? Or are you just trying to implement everything that the ADC can do? The latter can be a bit risky because you might end making something where you can't do a buffered read and a single channel read at the same time, but later find out you have a real-world application that needs to do this.

It looks like it would be possible to implement buffered reads in lots of ways. IIO devices can have more than one buffer per device so we can add more in the future if we need to. So I would just drop the DMA part of the implementation for now and implement the basic triggered buffer using MCR[NSTART] and ECH (End of Chain) interrupt request and just reading data from the ICDR registers.

I would wait to have a real-world application that requires DMA to decide the best way to implement that. There are lots of possibilities, like does it need an external trigger or is continuous mode good enough? Does it need to be cyclic (something the IIO subsystem doesn't really support yet) or not. Is exact sample timing important or do we just need a big buffer? These questions we can't really answer without a specific application to use it.

Quoted 7 lines
Quoted 5 lines

In the case of this IP, the use cases are in the automotive context. The system running on the APU is supposed to monitor at high rate (or not) the different channels which can be connected to any device the integrator choose to use.

For this reason, the driver should be able to support the different modes because the integrator of the car computer can decide to monitor the devices connected to the different channels differently.

Said differently, we need these modes because the capture depends on what the integrator decide to connect to the different channels.

...

Quoted 1 line

We just know all these use cases exist.

The submitted driver supports the three modes.

Nuno asked to use the IIO dma engine API.

However there is few information and examples with the API and I failed to use the devm_iio_dmaengine_buffer_setup_with_handle() function.

Quoted 9 lines

AFAICT, devm_iio_dmaengine_buffer_setup_ext() can not be used because dma_slave_config() is not called, thus the src_addr is not set.

Is there any example somewhere, documentation or guidance to use the API?

Thanks

  -- Daniel

Unfortunately, not really. Until the last few years, there wasn't really any users of these APIs. I added devm_iio_dmaengine_buffer_setup_with_handle() for the SPI offloading work I did recently. The only reason it had to be added is because we needed to get the DMA handle from a different devicetree node from the ADC's node. Since this device has dmas and dma-names in the devicetree, then if devm_iio_dmaengine_buffer_setup[_ext]() doesn't work with that, then it might have other problems (assumptions made for a specific use case) than just not calling dma_slave_config().

I think maybe Nuno and certainly I are guilty of trying to offer you advice without looking deeply enough into what you already submitted. :-/

I see now that what you are doing with the DMA looks more like other SoC ADCs (AT91/STM32/AM335x) which is quite different from how the iio_dmaengine_buffer stuff works, e.g. cyclic vs. not. So unless you are interested in evolving the iio_dmaengine_buffer code to be more general to handle this case as well, it might not be the right tool for the job currently.

#17 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Hi *Daniel* (sorry for that :)),

Quoted 85 lines · David Lechner
Quoted 64 lines · Daniel Lezcano
Quoted 46 lines · David Lechner
Quoted 45 lines · Daniel Lezcano
Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

Quoted 21 lines

Taking a step back, what sort of real-world uses cases do you need to support?
Or are you just trying to implement everything that the ADC can do? The latter
can be a bit risky because you might end making something where you can't do
a buffered read and a single channel read at the same time, but later find out
you have a real-world application that needs to do this.

It looks like it would be possible to implement buffered reads in lots of ways.
IIO devices can have more than one buffer per device so we can add more in the
future if we need to. So I would just drop the DMA part of the implementation
for now and implement the basic triggered buffer using MCR[NSTART] and ECH
(End of Chain) interrupt request and just reading data from the ICDR registers.

Quoted 11 lines

I would wait to have a real-world application that requires DMA to decide the
best way to implement that. There are lots of possibilities, like does it need
an external trigger or is continuous mode good enough? Does it need to be cyclic
(something the IIO subsystem doesn't really support yet) or not. Is exact sample
timing important or do we just need a big buffer? These questions we can't
really answer without a specific application to use it.

In the case of this IP, the use cases are in the automotive context. The system running on the APU is supposed to monitor at high rate (or not) the different channels which can be connected to any device the integrator choose to use.

Quoted 8 lines
Quoted 6 lines

For this reason, the driver should be able to support the different modes because the integrator of the car computer can decide to monitor the devices connected to the different channels differently.

Said differently, we need these modes because the capture depends on what the integrator decide to connect to the different channels.

...

Quoted 1 line

We just know all these use cases exist.

The submitted driver supports the three modes.

Nuno asked to use the IIO dma engine API.

However there is few information and examples with the API and I failed to use the devm_iio_dmaengine_buffer_setup_with_handle() function.

Quoted 10 lines

AFAICT, devm_iio_dmaengine_buffer_setup_ext() can not be used because dma_slave_config() is not called, thus the src_addr is not set.

Is there any example somewhere, documentation or guidance to use the API?

Thanks

  -- Daniel

Unfortunately, not really. Until the last few years, there wasn't really any users of these APIs. I added devm_iio_dmaengine_buffer_setup_with_handle() for the SPI offloading work I did recently. The only reason it had to be added is because we needed to get the DMA handle from a different devicetree node from the ADC's node. Since this device has dmas and dma-names in the devicetree, then if devm_iio_dmaengine_buffer_setup[_ext]() doesn't work with that, then it might have other problems (assumptions made for a specific use case) than just not calling dma_slave_config().

Quoted 3 lines

I think maybe Nuno and certainly I are guilty of trying to offer you advice without looking deeply enough into what you already submitted. :-/

Yes, I pretty much just asked for (at least) some discussion about this and see if we could use what we already have in IIO.

Quoted 3 lines

I see now that what you are doing with the DMA looks more like other SoC ADCs (AT91/STM32/AM335x) which is quite different from how the iio_dmaengine_buffer stuff works, e.g. cyclic vs. not. So unless you are interested in evolving

Supporting cyclic should be fairly easy (Paul left it almost prepared for it) and do I have some patches already. I'm just waiting on having something accepted on the ADI DMA IP driver (dmaengine) before sending the IIO patches I already have.

Quoted 2 lines

the iio_dmaengine_buffer code to be more general to handle this case as well, it might not be the right tool for the job currently.

I think for the STM (IIRC) case they "open" coded it because the IIO DMA support we had at the time (if any) was more "rudimentary" - (no real zero copy interface with userspace for example). But yeah, it seems there are some gaps for your usecase so as David said, you would need to be interested in evolving the IIO DMA API to accommodate your needs. Again, if nicely integrated you would gain some nice "improvements" in performance (not having to use the fileio interface for reading the buffers) for "free".

As for dma_slave_config(), you're right and we have no usecase needing that setup and TBH, I did not looked or have any idea (atm) on how to do it. That said, I'll be here to help and contribute if you decide to try and follow the IIO DMA buffer API.

- Nuno Sá

#18 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 12 lines · Nuno Sá

Hi *Daniel* (sorry for that :)),

Quoted 9 lines · David Lechner
Quoted 8 lines · Daniel Lezcano
Quoted 7 lines · David Lechner
Quoted 6 lines · Daniel Lezcano
Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

[ ... ]

Quoted 36 lines
Quoted 9 lines

Unfortunately, not really. Until the last few years, there wasn't really any users of these APIs. I added devm_iio_dmaengine_buffer_setup_with_handle() for the SPI offloading work I did recently. The only reason it had to be added is because we needed to get the DMA handle from a different devicetree node from the ADC's node. Since this device has dmas and dma-names in the devicetree, then if devm_iio_dmaengine_buffer_setup[_ext]() doesn't work with that, then it might have other problems (assumptions made for a specific use case) than just not calling dma_slave_config().

Quoted 3 lines

I think maybe Nuno and certainly I are guilty of trying to offer you advice without looking deeply enough into what you already submitted. :-/

Yes, I pretty much just asked for (at least) some discussion about this and see if we could use what we already have in IIO.

Quoted 3 lines

I see now that what you are doing with the DMA looks more like other SoC ADCs (AT91/STM32/AM335x) which is quite different from how the iio_dmaengine_buffer stuff works, e.g. cyclic vs. not. So unless you are interested in evolving

Supporting cyclic should be fairly easy (Paul left it almost prepared for it) and do I have some patches already. I'm just waiting on having something accepted on the ADI DMA IP driver (dmaengine) before sending the IIO patches I already have.

Quoted 2 lines

the iio_dmaengine_buffer code to be more general to handle this case as well, it might not be the right tool for the job currently.

I think for the STM (IIRC) case they "open" coded it because the IIO DMA support we had at the time (if any) was more "rudimentary" - (no real zero copy interface with userspace for example). But yeah, it seems there are some gaps for your usecase so as David said, you would need to be interested in evolving the IIO DMA API to accommodate your needs. Again, if nicely integrated you would gain some nice "improvements" in performance (not having to use the fileio interface for reading the buffers) for "free".

Quoted 4 lines

As for dma_slave_config(), you're right and we have no usecase needing that setup and TBH, I did not looked or have any idea (atm) on how to do it. That said, I'll be here to help and contribute if you decide to try and follow the IIO DMA buffer API.

I would be glad to help improving the IIO DMA but I don't have enough bandwidth ATM. I was hoping to get this driver merged for v6.18 which is the next LTS AFAICT. Is it something possible by taking into account all the comments without improving the DMA code ?

Do you have a pointer to Paul's series and the patches you mentioned above ? I can give a try when having some spare time

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#19 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 73 lines · Daniel Lezcano
Quoted 12 lines · Nuno Sá

Hi *Daniel* (sorry for that :)),

Quoted 9 lines · David Lechner
Quoted 8 lines · Daniel Lezcano
Quoted 7 lines · David Lechner
Quoted 6 lines · Daniel Lezcano
Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

[ ... ]

Quoted 51 lines
Quoted 13 lines

Unfortunately, not really. Until the last few years, there wasn't really any users of these APIs. I added devm_iio_dmaengine_buffer_setup_with_handle()
for the SPI offloading work I did recently. The only reason it had to be added is because we needed to get the DMA handle from a different devicetree
node from the ADC's node. Since this device has dmas and dma-names in the devicetree, then if devm_iio_dmaengine_buffer_setup[_ext]() doesn't work
with that, then it might have other problems (assumptions made for a specific
use case) than just not calling dma_slave_config().

Quoted 4 lines

I think maybe Nuno and certainly I are guilty of trying to offer you advice
without looking deeply enough into what you already submitted. :-/

Yes, I pretty much just asked for (at least) some discussion about this and see
if we could use what we already have in IIO.

Quoted 5 lines

I see now that what you are doing with the DMA looks more like other SoC ADCs
(AT91/STM32/AM335x) which is quite different from how the iio_dmaengine_buffer
stuff works, e.g. cyclic vs. not. So unless you are interested in evolving

Supporting cyclic should be fairly easy (Paul left it almost prepared for it)
and do I have some patches already. I'm just waiting on having something accepted on the ADI DMA IP driver (dmaengine) before sending the IIO patches I
already have.

Quoted 3 lines

the iio_dmaengine_buffer code to be more general to handle this case as well,
it might not be the right tool for the job currently.

I think for the STM (IIRC) case they "open" coded it because the IIO DMA support
we had at the time (if any) was more "rudimentary" - (no real zero copy interface with userspace for example). But yeah, it seems there are some gaps
for your usecase so as David said, you would need to be interested in evolving
the IIO DMA API to accommodate your needs. Again, if nicely integrated you would
gain some nice "improvements" in performance (not having to use the fileio interface for reading the buffers) for "free".

Quoted 5 lines

As for dma_slave_config(), you're right and we have no usecase needing that setup and TBH, I did not looked or have any idea (atm) on how to do it. That said, I'll be here to help and contribute if you decide to try and follow the
IIO DMA buffer API.

Quoted 5 lines

I would be glad to help improving the IIO DMA but I don't have enough bandwidth ATM. I was hoping to get this driver merged for v6.18 which is the next LTS AFAICT. Is it something possible by taking into account all the comments without improving the DMA code ?

No personal problem with that. But ultimately that is up to Jonathan :)

Quoted 4 lines

Do you have a pointer to Paul's series and the patches you mentioned above ? I can give a try when having some spare time

Here is the DMABUF work from Paul [1]. But I do not think this is of much use for you (as an in kernel consumer) but it is still interesting :).

My own patches are in here [2] but you have out of tree "noise" in there [2]. At ADI tree we had some legacy "high speed" implementation that we're still supporting (eventually it will go away and we will sync completely with the upstream solution). I was hopping for this [3] to land first before sending the IIO bits but I'm having some issues with lack of bandwidth (I guess) from the DMA maintainer. They are not really dependent on each other so I might send the IIO stuff soon enough.

One last comment about dma_slave_config(). That should be easy to go around with devm_iio_dmaengine_buffer_setup_with_handle(). I mean, we canl do all the DMA chan request in the consumer driver (which would allow to easily call dma_slave_config() when needed) and pass the DMA handle to IIO with the API David introduced. In the future, given enough users, we could introduce an helper in the IIO code and it would be easy to "convert" the driver. Now, if you do need to do something special in the DMA termination callback, we would definitely need to add the mechanism for that. In the ADI tree we do have a way for a custom DMA submit operation [4] but we never had a proper upstreamable user for it :(

Anyways, just some thoughts if you or someone else ever have the time for this :)

[1]: https://lore.kernel.org/linux-iio/[email protected]/
[2]: https://github.com/analogdevicesinc/linux/commit/a1f64e5e7927d1d96da08245cce35ba9e08a5f52
[3]: https://lore.kernel.org/dmaengine/[email protected]/
[4]: https://github.com/analogdevicesinc/linux/blob/main/drivers/iio/buffer/industrialio-buffer-dma.c#L1214

- Nuno Sá

maintainer
#20 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 74 lines · On Wed, 10 Sep 2025 12:57:19 +0100 Nuno Sá <[email protected]> wrote:
Quoted 73 lines · Daniel Lezcano
Quoted 12 lines · Nuno Sá

Hi *Daniel* (sorry for that :)),

Quoted 9 lines · David Lechner
Quoted 8 lines · Daniel Lezcano
Quoted 7 lines · David Lechner
Quoted 6 lines · Daniel Lezcano
Quoted 3 lines · David Lechner
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · David Lechner

On 9/4/25 12:40 PM, Daniel Lezcano wrote:

[ ... ]

[ ... ]

Quoted 56 lines
Quoted 13 lines

Unfortunately, not really. Until the last few years, there wasn't really any users of these APIs. I added devm_iio_dmaengine_buffer_setup_with_handle()
for the SPI offloading work I did recently. The only reason it had to be added is because we needed to get the DMA handle from a different devicetree
node from the ADC's node. Since this device has dmas and dma-names in the devicetree, then if devm_iio_dmaengine_buffer_setup[_ext]() doesn't work
with that, then it might have other problems (assumptions made for a specific
use case) than just not calling dma_slave_config().

Quoted 4 lines

I think maybe Nuno and certainly I are guilty of trying to offer you advice
without looking deeply enough into what you already submitted. :-/

Yes, I pretty much just asked for (at least) some discussion about this and see
if we could use what we already have in IIO.

Quoted 5 lines

I see now that what you are doing with the DMA looks more like other SoC ADCs
(AT91/STM32/AM335x) which is quite different from how the iio_dmaengine_buffer
stuff works, e.g. cyclic vs. not. So unless you are interested in evolving

Supporting cyclic should be fairly easy (Paul left it almost prepared for it)
and do I have some patches already. I'm just waiting on having something accepted on the ADI DMA IP driver (dmaengine) before sending the IIO patches I
already have.

Quoted 3 lines

the iio_dmaengine_buffer code to be more general to handle this case as well,
it might not be the right tool for the job currently.

I think for the STM (IIRC) case they "open" coded it because the IIO DMA support
we had at the time (if any) was more "rudimentary" - (no real zero copy interface with userspace for example). But yeah, it seems there are some gaps
for your usecase so as David said, you would need to be interested in evolving
the IIO DMA API to accommodate your needs. Again, if nicely integrated you would
gain some nice "improvements" in performance (not having to use the fileio interface for reading the buffers) for "free".

As for dma_slave_config(), you're right and we have no usecase needing that setup and TBH, I did not looked or have any idea (atm) on how to do it. That said, I'll be here to help and contribute if you decide to try and follow the
IIO DMA buffer API.

Quoted 7 lines
Quoted 5 lines

I would be glad to help improving the IIO DMA but I don't have enough bandwidth ATM. I was hoping to get this driver merged for v6.18 which is the next LTS AFAICT. Is it something possible by taking into account all the comments without improving the DMA code ?

No personal problem with that. But ultimately that is up to Jonathan :)

I'm fine with a device doing DMA that isn't using the DMA buffer interface. That is, basically what you have here. The only risk is walking ourselves into a corner of having to maintain compatibility if later on the zero copy performance is needed.

We can solve that, but today I don't recall us having any devices offering both interfaces.

Quoted 38 lines
Quoted 5 lines

Do you have a pointer to Paul's series and the patches you mentioned above ? I can give a try when having some spare time

Here is the DMABUF work from Paul [1]. But I do not think this is of much use for you (as an in kernel consumer) but it is still interesting :).

My own patches are in here [2] but you have out of tree "noise" in there [2]. At ADI tree we had some legacy "high speed" implementation that we're still supporting (eventually it will go away and we will sync completely with the upstream solution). I was hopping for this [3] to land first before sending the IIO bits but I'm having some issues with lack of bandwidth (I guess) from the DMA maintainer. They are not really dependent on each other so I might send the IIO stuff soon enough.

One last comment about dma_slave_config(). That should be easy to go around with devm_iio_dmaengine_buffer_setup_with_handle(). I mean, we canl do all the DMA chan request in the consumer driver (which would allow to easily call dma_slave_config() when needed) and pass the DMA handle to IIO with the API David introduced. In the future, given enough users, we could introduce an helper in the IIO code and it would be easy to "convert" the driver. Now, if you do need to do something special in the DMA termination callback, we would definitely need to add the mechanism for that. In the ADI tree we do have a way for a custom DMA submit operation [4] but we never had a proper upstreamable user for it :(

Anyways, just some thoughts if you or someone else ever have the time for this :)

[1]: https://lore.kernel.org/linux-iio/[email protected]/
[2]: https://github.com/analogdevicesinc/linux/commit/a1f64e5e7927d1d96da08245cce35ba9e08a5f52
[3]: https://lore.kernel.org/dmaengine/[email protected]/
[4]: https://github.com/analogdevicesinc/linux/blob/main/drivers/iio/buffer/industrialio-buffer-dma.c#L1214

- Nuno Sá

#21 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

In reply to Daniel Lezcano
Quoted 24 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

...

Quoted 1 line

+#include <linux/circ_buf.h>

Why not kfifo?

drivers/iio/adc/nxp-sar-adc.c line 16

Quoted 6 lines
drivers/iio/adc/nxp-sar-adc.c new file +6 -0
+#include <linux/clk.h>
+#include <linux/completion.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmaengine.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>

+ match.h and more are missing...

drivers/iio/adc/nxp-sar-adc.c line 19

Quoted 4 lines
drivers/iio/adc/nxp-sar-adc.c new file +3 -0
+#include <linux/module.h>
 
+#include <linux/of_irq.h>
+#include <linux/of_platform.h>

Misuse of headers, and please make driver agnostic. There is none OF specifics in the code AFAICT.

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>

...

drivers/iio/adc/nxp-sar-adc.c line 37

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+/* Main Configuration Register */
+#define REG_ADC_MCR(__base)		(__base)

Useless macro. Perhaps (looking the others) this should be ((__base) + 0x00) which makes much more sense.

...

drivers/iio/adc/nxp-sar-adc.c line 45

Quoted 3 lines
drivers/iio/adc/nxp-sar-adc.c new file +3 -0
+#define REG_ADC_MCR_NRSMPL_32		BIT(11)
+#define REG_ADC_MCR_NRSMPL_128		BIT(12)
+#define REG_ADC_MCR_NRSMPL_512		(BIT(11) | BIT(12))

These are not bits, please use them in a form of 0, 1, 2, 3 and why not using bitfield.h?

...

drivers/iio/adc/nxp-sar-adc.c line 103

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+#define NXP_SAR_ADC_CONV_TIMEOUT_MS	100
+#define NXP_SAR_ADC_CAL_TIMEOUT_US	100000

(100 * USEC_PER_MSEC)

Quoted 1 line

+#define NXP_SAR_ADC_WAIT_US 2000

(2 * USEC_PER_MSEC)

...

Quoted 1 line

+#define NXP_SAR_ADC_DMA_BUFF_SZ (PAGE_SIZE * NXP_SAR_ADC_DMA_SAMPLE_SZ)

Oh, PAGE_SIZE is not good to use. I believe this HW is not tolerant to any page size. (Note, we made similar mistake in Intel IPU3 camera driver, which is now fixed)

...

drivers/iio/adc/nxp-sar-adc.c line 143

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	/* Protect circular buffers access. */
+	spinlock_t lock;

+ spinlock.h

drivers/iio/adc/nxp-sar-adc.c line 149

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+	/*
+	 * Save and restore context
+	 */
+	u32 inpsamp;
+	u32 pwdn;

+ types.h

...

drivers/iio/adc/nxp-sar-adc.c line 215

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+		ndelay(div64_u64(NSEC_PER_SEC, clk_get_rate(info->clk) * 3U));

+ delay.h

Actually + math64.h (no need to include math.h which I mentioned elsewhere).

...

drivers/iio/adc/nxp-sar-adc.c line 243

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+static inline int nxp_sar_adc_calibration_wait(void __iomem *base)
+{
+	u32 msr, ret;
+
+	ret = read_poll_timeout(readl, msr, !(msr & REG_ADC_MSR_CALBUSY),

Why not readl_poll_timeout()?

drivers/iio/adc/nxp-sar-adc.c line 251

Quoted 8 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+				NXP_SAR_ADC_WAIT_US,
+				NXP_SAR_ADC_CAL_TIMEOUT_US,
+				true, REG_ADC_MSR(base));
+	if (ret)
+		return ret;
 
+	if (!(msr & REG_ADC_MSR_CALFAIL))
+		return 0;

I would expect standard pattern — "errors first", but here either works.

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	/*
+	 * If the calibration fails, the status register bit must be
+	 * cleared
+	 */
+	msr &= ~REG_ADC_MSR_CALFAIL;
+
+	writel(msr, REG_ADC_MSR(base));
+
+	return -EAGAIN;
+}

...

drivers/iio/adc/nxp-sar-adc.c line 326

Quoted 3 lines
drivers/iio/adc/nxp-sar-adc.c new file +3 -0
+{
+	struct nxp_sar_adc *info = iio_priv(indio_dev);
+	int i, ret;

Why is 'i' signed?

Quoted 17 lines
drivers/iio/adc/nxp-sar-adc.c new file +17 -0
+
+	for (i = 0; i < info->channels_used; i++) {
+		ret = nxp_sar_adc_read_data(info, info->buffered_chan[i]);
+		if (ret < 0) {
+			nxp_sar_adc_read_notify(info);
+			return;
+		}
+
+		info->buffer[i] = ret;
+	}
+
+	nxp_sar_adc_read_notify(info);
+	iio_push_to_buffers_with_timestamp(indio_dev,
+					   info->buffer,
+					   iio_get_time_ns(indio_dev));
+	iio_trigger_notify_done(indio_dev->trig);
+}

...

drivers/iio/adc/nxp-sar-adc.c line 455

Quoted 7 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+	/*
+	 * On disable, we have to wait for the transaction to finish.
+	 * ADC does not abort the transaction if a chain conversion
+	 * is in progress.
+	 * Wait for the worst case scenario - 80 ADC clk cycles.
+	 */
+	ndelay(div64_u64(NSEC_PER_SEC, clk_get_rate(info->clk)) * 80U);

Could it possible go wrong and with low rate clocks (kHz:ish) this will go into lo-o-o-o-ng *atomic* delay?

Quoted 1 line

+}

...

drivers/iio/adc/nxp-sar-adc.c line 488

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+		nxp_sar_adc_channels_enable(info, 1 >> chan->channel);

1 >> ?!? Did you want BIT(channel)? Or simply channel != 0?

...

Quoted 15 lines
drivers/iio/adc/nxp-sar-adc.c new file +15 -0
+static int sar_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
+			 int val, int val2, long mask)
+{
+	struct nxp_sar_adc *info = iio_priv(indio_dev);
+	u32 inpsamp;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		/*
+		 * Configures the sample period duration in terms of
+		 * the SAR controller clock. The minimum acceptable
+		 * value is 8. Configuring to a value lower than 8
+		 * sets the sample period to 8 cycles.  We read the
+		 * clock value and divide by the sampling timing which
+		 * gives us the number of cycles expected. The value

drivers/iio/adc/nxp-sar-adc.c line 562

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+		 * is 8 bits wide, consequently the max value is 0xFF
+		 */
+		inpsamp = clk_get_rate(info->clk) / val - NXP_SAR_ADC_CONV_TIME;
+		nxp_sar_adc_conversion_timing_set(info, inpsamp);
+		break;
+	default:
+		return -EINVAL;
+	}
 
+	return 0;

Return directly from switch-case.

Quoted 1 line

+}

...

Quoted 7 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+static void nxp_sar_adc_dma_cb(void *data)
+{
+	struct nxp_sar_adc *info = iio_priv((struct iio_dev *)data);
+	struct iio_dev *indio_dev = data;
+	struct dma_tx_state state;
+	struct circ_buf *dma_buf;
+	struct device *dev_dma;

drivers/iio/adc/nxp-sar-adc.c line 580

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+	unsigned long flags;
+	u32 *dma_samples;
+	s64 timestamp;
+	int idx, ret;
+
+	dma_buf = &info->dma_buf;
+	dma_samples = (u32 *)dma_buf->buf;
+	dev_dma = info->dma_chan->device->dev;
 
+	spin_lock_irqsave(&info->lock, flags);

Why not guard()() from cleanup.h?

drivers/iio/adc/nxp-sar-adc.c line 582

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	dmaengine_tx_status(info->dma_chan,
+			    info->cookie, &state);

Perfectly one line. No return check?

Quoted 47 lines
drivers/iio/adc/nxp-sar-adc.c new file +47 -0
+	dma_sync_single_for_cpu(dev_dma, info->rx_dma_buf,
+				NXP_SAR_ADC_DMA_BUFF_SZ, DMA_FROM_DEVICE);
+	/* Current head position */
+	dma_buf->head = (NXP_SAR_ADC_DMA_BUFF_SZ - state.residue) /
+			NXP_SAR_ADC_DMA_SAMPLE_SZ;
+
+	/* If everything transferred, avoid an off by one error. */
+	if (!state.residue)
+		dma_buf->head--;
+
+	/* Something went wrong and nothing transferred. */
+	if (state.residue == NXP_SAR_ADC_DMA_BUFF_SZ)
+		goto out;
+
+	/* Make sure that head is multiple of info->channels_used */
+	dma_buf->head -= dma_buf->head % info->channels_used;
+
+	/* dma_buf->tail != dma_buf->head condition will become false
+	 * because dma_buf->tail will be incremented with 1.
+	 */
+	while (dma_buf->tail != dma_buf->head) {
+		idx = dma_buf->tail % info->channels_used;
+		info->buffer[idx] = dma_samples[dma_buf->tail];
+		dma_buf->tail = (dma_buf->tail + 1) % NXP_SAR_ADC_DMA_SAMPLE_CNT;
+		if (idx != info->channels_used - 1)
+			continue;
+
+		/* iio_push_to_buffers_with_timestamp should not be called
+		 * with dma_samples as parameter. The samples will be smashed
+		 * if timestamp is enabled.
+		 */
+		timestamp = iio_get_time_ns(indio_dev);
+		ret = iio_push_to_buffers_with_timestamp(indio_dev,
+							 info->buffer,
+							 timestamp);
+		if (ret < 0 && ret != -EBUSY)
+			dev_err_ratelimited(&indio_dev->dev,
+					    "failed to push iio buffer: %d",
+					    ret);
+	}
+
+	dma_buf->tail = dma_buf->head;
+out:
+	dma_sync_single_for_device(dev_dma, info->rx_dma_buf,
+				   NXP_SAR_ADC_DMA_BUFF_SZ, DMA_FROM_DEVICE);
+	spin_unlock_irqrestore(&info->lock, flags);
+}

...

Quoted 9 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+	/*
+	 * The SAR-ADC has two groups of channels.
+	 *
+	 *	- Group #0:
+	 *	* bit 0-7  : channel 0 -> channel 7
+	 *	* bit 8-31 : reserved
+	 *
+	 *	- Group #32:
+	 *	* bit 0-7  : Internal

drivers/iio/adc/nxp-sar-adc.c line 755

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	 *	* bit 8-31 : reserved
+	 *
+	 * The 8 channels from group #0 are used in this driver for
+	 * ADC as described when declaring the IIO device and the
+	 * mapping is the same. That means the active_scan_mask can be
+	 * used directly to write the channel interrupt mask.
+	 */
+	nxp_sar_adc_channels_enable(info, *indio_dev->active_scan_mask);
+
+	for_each_set_bit(channel, indio_dev->active_scan_mask, NXP_SAR_ADC_NR_CHANNELS) {

+ bitops.h

drivers/iio/adc/nxp-sar-adc.c line 757

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+		info->buffered_chan[info->channels_used++] = channel;
+	}

{} are redundant.

...

Quoted 20 lines
drivers/iio/adc/nxp-sar-adc.c new file +20 -0
+static int nxp_sar_adc_dma_probe(struct device *dev, struct nxp_sar_adc *info)
+{
+	struct device *dev_dma;
+	int ret;
+	u8 *rx_buf;
+
+	info->dma_chan = devm_dma_request_chan(dev, "rx");
+	if (IS_ERR(info->dma_chan))
+		return PTR_ERR(info->dma_chan);
+
+	dev_dma = info->dma_chan->device->dev;
+	rx_buf = dma_alloc_coherent(dev_dma, NXP_SAR_ADC_DMA_BUFF_SZ,
+				    &info->rx_dma_buf, GFP_KERNEL);
+	if (!rx_buf)
+		return -ENOMEM;
+
+	info->dma_buf.buf = rx_buf;
+
+	info->dma_config.direction = DMA_DEV_TO_MEM;
+	info->dma_config.src_addr_width = NXP_SAR_ADC_DMA_SAMPLE_SZ;

drivers/iio/adc/nxp-sar-adc.c line 856

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+	info->dma_config.src_maxburst = 1;
+
+	ret = devm_add_action_or_reset(dev, nxp_sar_adc_dma_remove, info);
+	if (ret) {
+		nxp_sar_adc_dma_remove(info);
 
+		return ret;
+	}
+
+	return 0;
	return ret;
Quoted 1 line

+}

...

Quoted 7 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+/*
+ * The documentation describes the reset values for the
+ * registers. However some registers do not have these values after a
+ * reset. It is a not desirable situation. In some other SoC family
+ * documentation NXP recommend to not assume the default values are
+ * set and to initialize the registers conforming to the documentation
+ * reset information to prevent this situation. Assume the same rule

drivers/iio/adc/nxp-sar-adc.c line 875

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+ * applies here as there is a discrepancy between what is read from
+ * the registers at reset time and the documentation.
+ */
+static void nxp_sar_adc_set_default_values(struct nxp_sar_adc *info)
+{
+	const u32 mcr_default	= 0x00003901;
+	const u32 msr_default	= 0x00000001;
+	const u32 ctr_default	= 0x00000014;
+	const u32 cimr_default	= 0x00000000;
+	const u32 ncmr_default	= 0x00000000;

What is the purpose of having these constant to be temporary variables in the code?

Quoted 9 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+	writel(mcr_default, REG_ADC_MCR(info->regs));
+	writel(msr_default, REG_ADC_MSR(info->regs));
+	writel(ctr_default, REG_ADC_CTR0(info->regs));
+	writel(ctr_default, REG_ADC_CTR1(info->regs));
+	writel(cimr_default, REG_ADC_CIMR0(info->regs));
+	writel(cimr_default, REG_ADC_CIMR1(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR0(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR1(info->regs));
+}

...

Quoted 7 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+static int nxp_sar_adc_probe(struct platform_device *pdev)
+{
+	const struct nxp_sar_adc_data *data;
+	struct nxp_sar_adc *info;
+	struct iio_dev *indio_dev;
+	struct resource *mem;
+	struct device *dev = &pdev->dev;

drivers/iio/adc/nxp-sar-adc.c line 903

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+	int irq;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(struct nxp_sar_adc));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	info = iio_priv(indio_dev);
 
+	data = of_device_get_match_data(dev);

We have an agnostic alternative in property.h.

drivers/iio/adc/nxp-sar-adc.c line 905

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+	info->vref = data->vref;

vref_uV / vref_mV in both cases?

drivers/iio/adc/nxp-sar-adc.c line 914

Quoted 9 lines
drivers/iio/adc/nxp-sar-adc.c new file +8 -0
+	info->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
+	if (IS_ERR(info->regs))
+		return dev_err_probe(dev, PTR_ERR(info->regs),
+				     "failed to get and remap resource");
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
 
+		return dev_err_probe(dev, irq, "no irq resource\n");

No need, it prints message if fails.

Quoted 19 lines
drivers/iio/adc/nxp-sar-adc.c new file +17 -0
+	ret = devm_request_irq(dev, irq, nxp_sar_adc_isr, 0,
+			       dev_name(dev), indio_dev);
+	if (ret < 0)
+		dev_err_probe(dev, ret, "failed requesting irq, irq = %d\n", irq);
+
+	info->regs_phys = mem->start;
+	spin_lock_init(&info->lock);
+
+	info->clk = devm_clk_get_enabled(dev, "adc");
+	if (IS_ERR(info->clk))
+		return dev_err_probe(dev, PTR_ERR(info->clk),
+				     "failed to get the clock\n");
 
+	platform_set_drvdata(pdev, indio_dev);
 
+	init_completion(&info->completion);
+
+	indio_dev->name = dev_name(dev);
+	indio_dev->info = &nxp_sar_adc_iio_info;

drivers/iio/adc/nxp-sar-adc.c line 944

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+	indio_dev->channels = nxp_sar_adc_iio_channels;
+	indio_dev->num_channels = ARRAY_SIZE(nxp_sar_adc_iio_channels);
+
+	nxp_sar_adc_set_default_values(info);
+
+	ret = nxp_sar_adc_calibration(info);
+	if (ret) {
+		dev_err(dev, "Calibration failed: %d\n", ret);
+		return ret;

Be consistent. It looks like driver is written by 2+ people who do not communicate with each other.

		return dev_err_probe(...);
Quoted 14 lines
drivers/iio/adc/nxp-sar-adc.c new file +14 -0
+	}
+
+	ret = nxp_sar_adc_dma_probe(dev, info);
+	if (ret) {
+		dev_err(dev, "Failed to initialize the dma\n");
+		return ret;
+	}
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &iio_pollfunc_store_time,
+					      &nxp_sar_adc_trigger_handler,
+					      &iio_triggered_buffer_setup_ops);
+	if (ret < 0) {
+		dev_err(dev, "Couldn't initialise the buffer\n");

drivers/iio/adc/nxp-sar-adc.c line 968

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+		return ret;
+	}
+
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret) {
+		dev_err(dev, "Couldn't register the device.\n");
+		return ret;
+	}
 
+	dev_info(dev, "Device initialized successfully.\n");

Noise. This should be dropped.

Quoted 4 lines
drivers/iio/adc/nxp-sar-adc.c new file +3 -0
+	return 0;
+}
 
+};

...

Quoted 1 line

+

Redundant blank line.

Quoted 1 line

+module_platform_driver(nxp_sar_adc_driver);

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#22 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Hi Andy,

thank you for the review

Quoted 26 lines · Andy Shevchenko
Quoted 20 lines · Daniel Lezcano

From: Stefan-Gabriel Mirea <[email protected]>

The NXP S32G2 and S32G3 platforms integrate a successive approximation register (SAR) ADC. Two instances are available, each providing 8 multiplexed input channels with 12-bit resolution. The conversion rate is up to 1 Msps depending on the configuration and sampling window.

The SAR ADC supports raw, buffer, and trigger modes. It can operate in both single-shot and continuous conversion modes, with optional hardware triggering through the cross-trigger unit (CTU) or external events. An internal prescaler allows adjusting the sampling clock, while per-channel programmable sampling times provide fine-grained trade-offs between accuracy and latency. Automatic calibration is performed at probe time to minimize offset and gain errors.

The driver is derived from the BSP implementation and has been partly rewritten to comply with upstream requirements. For this reason, all contributors are listed as co-developers, while the author refers to the initial BSP driver file creator.

Quoted 4 lines

All modes have been validated on the S32G274-RDB2 platform using an externally generated square wave captured by the ADC. Tests covered buffered streaming via IIO, trigger synchronization, and accuracy verification against a precision laboratory signal source.

Quoted 5 lines

...

Quoted 1 line

+#include <linux/circ_buf.h>

Why not kfifo?

Are you suggesting to use kfifo instead of the circular buffer in the code ?

Quoted 22 lines

drivers/iio/adc/nxp-sar-adc.c line 16

Quoted 6 lines
drivers/iio/adc/nxp-sar-adc.c new file +6 -0
+#include <linux/clk.h>
+#include <linux/completion.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmaengine.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>

+ match.h and more are missing...

drivers/iio/adc/nxp-sar-adc.c line 19

Quoted 4 lines
drivers/iio/adc/nxp-sar-adc.c new file +3 -0
+#include <linux/module.h>
 
+#include <linux/of_irq.h>
+#include <linux/of_platform.h>

Misuse of headers, and please make driver agnostic. There is none OF specifics in the code AFAICT.

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>

...

Quoted 5 lines

drivers/iio/adc/nxp-sar-adc.c line 37

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+/* Main Configuration Register */
+#define REG_ADC_MCR(__base)		(__base)

Useless macro. Perhaps (looking the others) this should be ((__base) + 0x00) which makes much more sense.

Sure

Quoted 9 lines

drivers/iio/adc/nxp-sar-adc.c line 45

Quoted 3 lines
drivers/iio/adc/nxp-sar-adc.c new file +3 -0
+#define REG_ADC_MCR_NRSMPL_32		BIT(11)
+#define REG_ADC_MCR_NRSMPL_128		BIT(12)
+#define REG_ADC_MCR_NRSMPL_512		(BIT(11) | BIT(12))

These are not bits, please use them in a form of 0, 1, 2, 3 and why not using bitfield.h?

...

Quoted 8 lines

drivers/iio/adc/nxp-sar-adc.c line 103

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+#define NXP_SAR_ADC_CONV_TIMEOUT_MS	100
+#define NXP_SAR_ADC_CAL_TIMEOUT_US	100000

(100 * USEC_PER_MSEC)

Quoted 1 line

+#define NXP_SAR_ADC_WAIT_US 2000

(2 * USEC_PER_MSEC)

Why is this more understandable than the raw value ?

Quoted 5 lines
Quoted 2 lines

+#define NXP_SAR_ADC_DMA_BUFF_SZ (PAGE_SIZE * NXP_SAR_ADC_DMA_SAMPLE_SZ)

Oh, PAGE_SIZE is not good to use. I believe this HW is not tolerant to any page size. (Note, we made similar mistake in Intel IPU3 camera driver, which is now fixed)

Is it acceptable to put a hardcoded 4096 value ?

Quoted 39 lines

...

drivers/iio/adc/nxp-sar-adc.c line 143

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	/* Protect circular buffers access. */
+	spinlock_t lock;

+ spinlock.h

drivers/iio/adc/nxp-sar-adc.c line 149

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+	/*
+	 * Save and restore context
+	 */
+	u32 inpsamp;
+	u32 pwdn;

+ types.h

...

drivers/iio/adc/nxp-sar-adc.c line 215

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+		ndelay(div64_u64(NSEC_PER_SEC, clk_get_rate(info->clk) * 3U));

+ delay.h

Actually + math64.h (no need to include math.h which I mentioned elsewhere).

...

drivers/iio/adc/nxp-sar-adc.c line 243

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+static inline int nxp_sar_adc_calibration_wait(void __iomem *base)
+{
+	u32 msr, ret;
+
+	ret = read_poll_timeout(readl, msr, !(msr & REG_ADC_MSR_CALBUSY),

Why not readl_poll_timeout()?

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+				NXP_SAR_ADC_WAIT_US,
+				NXP_SAR_ADC_CAL_TIMEOUT_US,
+				true, REG_ADC_MSR(base));
+	if (ret)
+		return ret;
Quoted 4 lines

drivers/iio/adc/nxp-sar-adc.c line 251

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	if (!(msr & REG_ADC_MSR_CALFAIL))
+		return 0;

I would expect standard pattern — "errors first", but here either works.

Does it mean this chunk of code can be preserved or do you prefer an error block followed with a return 0 ?

Quoted 39 lines
Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+	/*
+	 * If the calibration fails, the status register bit must be
+	 * cleared
+	 */
+	msr &= ~REG_ADC_MSR_CALFAIL;
+
+	writel(msr, REG_ADC_MSR(base));
+
+	return -EAGAIN;
+}

...

drivers/iio/adc/nxp-sar-adc.c line 326

Quoted 3 lines
drivers/iio/adc/nxp-sar-adc.c new file +3 -0
+{
+	struct nxp_sar_adc *info = iio_priv(indio_dev);
+	int i, ret;

Why is 'i' signed?

Quoted 17 lines
drivers/iio/adc/nxp-sar-adc.c new file +17 -0
+
+	for (i = 0; i < info->channels_used; i++) {
+		ret = nxp_sar_adc_read_data(info, info->buffered_chan[i]);
+		if (ret < 0) {
+			nxp_sar_adc_read_notify(info);
+			return;
+		}
+
+		info->buffer[i] = ret;
+	}
+
+	nxp_sar_adc_read_notify(info);
+	iio_push_to_buffers_with_timestamp(indio_dev,
+					   info->buffer,
+					   iio_get_time_ns(indio_dev));
+	iio_trigger_notify_done(indio_dev->trig);
+}

...

Quoted 10 lines

drivers/iio/adc/nxp-sar-adc.c line 455

Quoted 7 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+	/*
+	 * On disable, we have to wait for the transaction to finish.
+	 * ADC does not abort the transaction if a chain conversion
+	 * is in progress.
+	 * Wait for the worst case scenario - 80 ADC clk cycles.
+	 */
+	ndelay(div64_u64(NSEC_PER_SEC, clk_get_rate(info->clk)) * 80U);

Could it possible go wrong and with low rate clocks (kHz:ish) this will go into lo-o-o-o-ng *atomic* delay?

It is the ADC clock where we need to wait for 80 cycles. The lowest clock rate is 40MHz, but on this platform it is 80MHz IIRC. This routine is called only when the capture finishes. Except I'm missing something, this scenario should not happen.

Quoted 7 lines
Quoted 1 line

+}

...

drivers/iio/adc/nxp-sar-adc.c line 488

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+		nxp_sar_adc_channels_enable(info, 1 >> chan->channel);

1 >> ?!? Did you want BIT(channel)? Or simply channel != 0?

Yeah, BIT(chan->channel) is better

Quoted 16 lines
Quoted 15 lines
drivers/iio/adc/nxp-sar-adc.c new file +15 -0
+static void nxp_sar_adc_dma_cb(void *data)
+{
+	struct nxp_sar_adc *info = iio_priv((struct iio_dev *)data);
+	struct iio_dev *indio_dev = data;
+	struct dma_tx_state state;
+	struct circ_buf *dma_buf;
+	struct device *dev_dma;
+	unsigned long flags;
+	u32 *dma_samples;
+	s64 timestamp;
+	int idx, ret;
+
+	dma_buf = &info->dma_buf;
+	dma_samples = (u32 *)dma_buf->buf;
+	dev_dma = info->dma_chan->device->dev;
Quoted 3 lines

drivers/iio/adc/nxp-sar-adc.c line 580

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+	spin_lock_irqsave(&info->lock, flags);

Why not guard()() from cleanup.h?

sure

Quoted 4 lines

drivers/iio/adc/nxp-sar-adc.c line 582

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	dmaengine_tx_status(info->dma_chan,
+			    info->cookie, &state);

Perfectly one line. No return check?

Ok, will see if the IIO DMA API has an impact on this portion of code before checking the return code. However, the status is often ignored in the other drivers.

[ ... ]

Quoted 12 lines
Quoted 12 lines
drivers/iio/adc/nxp-sar-adc.c new file +12 -0
+/*
+ * The documentation describes the reset values for the
+ * registers. However some registers do not have these values after a
+ * reset. It is a not desirable situation. In some other SoC family
+ * documentation NXP recommend to not assume the default values are
+ * set and to initialize the registers conforming to the documentation
+ * reset information to prevent this situation. Assume the same rule
+ * applies here as there is a discrepancy between what is read from
+ * the registers at reset time and the documentation.
+ */
+static void nxp_sar_adc_set_default_values(struct nxp_sar_adc *info)
+{
Quoted 8 lines

drivers/iio/adc/nxp-sar-adc.c line 875

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+	const u32 mcr_default	= 0x00003901;
+	const u32 msr_default	= 0x00000001;
+	const u32 ctr_default	= 0x00000014;
+	const u32 cimr_default	= 0x00000000;
+	const u32 ncmr_default	= 0x00000000;

What is the purpose of having these constant to be temporary variables in the code?

The purpose is to group everything in a single function. As the default values are only used in this function, creating the macros where we have to roll up and down to check their values seemed to me pointless. But if you prefer macros, it is fine I can convert them.

Quoted 28 lines
Quoted 9 lines
drivers/iio/adc/nxp-sar-adc.c new file +9 -0
+	writel(mcr_default, REG_ADC_MCR(info->regs));
+	writel(msr_default, REG_ADC_MSR(info->regs));
+	writel(ctr_default, REG_ADC_CTR0(info->regs));
+	writel(ctr_default, REG_ADC_CTR1(info->regs));
+	writel(cimr_default, REG_ADC_CIMR0(info->regs));
+	writel(cimr_default, REG_ADC_CIMR1(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR0(info->regs));
+	writel(ncmr_default, REG_ADC_NCMR1(info->regs));
+}

...

Quoted 15 lines
drivers/iio/adc/nxp-sar-adc.c new file +15 -0
+static int nxp_sar_adc_probe(struct platform_device *pdev)
+{
+	const struct nxp_sar_adc_data *data;
+	struct nxp_sar_adc *info;
+	struct iio_dev *indio_dev;
+	struct resource *mem;
+	struct device *dev = &pdev->dev;
+	int irq;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(struct nxp_sar_adc));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	info = iio_priv(indio_dev);
Quoted 7 lines

drivers/iio/adc/nxp-sar-adc.c line 903

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+	data = of_device_get_match_data(dev);

We have an agnostic alternative in property.h.

drivers/iio/adc/nxp-sar-adc.c line 905

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+	info->vref = data->vref;

vref_uV / vref_mV in both cases?

Good suggestion, it makes sense

Quoted 36 lines

drivers/iio/adc/nxp-sar-adc.c line 914

Quoted 9 lines
drivers/iio/adc/nxp-sar-adc.c new file +8 -0
+	info->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
+	if (IS_ERR(info->regs))
+		return dev_err_probe(dev, PTR_ERR(info->regs),
+				     "failed to get and remap resource");
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
 
+		return dev_err_probe(dev, irq, "no irq resource\n");

No need, it prints message if fails.

Quoted 24 lines
drivers/iio/adc/nxp-sar-adc.c new file +22 -0
+	ret = devm_request_irq(dev, irq, nxp_sar_adc_isr, 0,
+			       dev_name(dev), indio_dev);
+	if (ret < 0)
+		dev_err_probe(dev, ret, "failed requesting irq, irq = %d\n", irq);
+
+	info->regs_phys = mem->start;
+	spin_lock_init(&info->lock);
+
+	info->clk = devm_clk_get_enabled(dev, "adc");
+	if (IS_ERR(info->clk))
+		return dev_err_probe(dev, PTR_ERR(info->clk),
+				     "failed to get the clock\n");
 
+	platform_set_drvdata(pdev, indio_dev);
 
+	init_completion(&info->completion);
+
+	indio_dev->name = dev_name(dev);
+	indio_dev->info = &nxp_sar_adc_iio_info;
+	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+	indio_dev->channels = nxp_sar_adc_iio_channels;
+	indio_dev->num_channels = ARRAY_SIZE(nxp_sar_adc_iio_channels);
+
+	nxp_sar_adc_set_default_values(info);
Quoted 8 lines

drivers/iio/adc/nxp-sar-adc.c line 944

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+
+	ret = nxp_sar_adc_calibration(info);
+	if (ret) {
+		dev_err(dev, "Calibration failed: %d\n", ret);
+		return ret;

Be consistent. It looks like driver is written by 2+ people who do not communicate with each other.

Indeed ... :)

Quoted 23 lines
Quoted 22 lines
drivers/iio/adc/nxp-sar-adc.c new file +22 -0
+	}
+
+	ret = nxp_sar_adc_dma_probe(dev, info);
+	if (ret) {
+		dev_err(dev, "Failed to initialize the dma\n");
+		return ret;
+	}
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &iio_pollfunc_store_time,
+					      &nxp_sar_adc_trigger_handler,
+					      &iio_triggered_buffer_setup_ops);
+	if (ret < 0) {
+		dev_err(dev, "Couldn't initialise the buffer\n");
+		return ret;
+	}
+
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret) {
+		dev_err(dev, "Couldn't register the device.\n");
+		return ret;
+	}
Quoted 3 lines

drivers/iio/adc/nxp-sar-adc.c line 968

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+	dev_info(dev, "Device initialized successfully.\n");

Noise. This should be dropped.

Ok, thanks again for the review

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#23 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 2 lines · Daniel Lezcano
Quoted 1 line · Andy Shevchenko

On Wed, Sep 03, 2025 at 12:27:56PM +0200, Daniel Lezcano wrote:

...

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+#include <linux/circ_buf.h>

Why not kfifo?

Are you suggesting to use kfifo instead of the circular buffer in the code ?

Asking, due to relatively recent move in the whole serial subsystem.

...

Quoted 9 lines
Quoted 7 lines
Quoted 1 line

+#define NXP_SAR_ADC_CAL_TIMEOUT_US 100000

(100 * USEC_PER_MSEC)

Quoted 1 line

+#define NXP_SAR_ADC_WAIT_US 2000

(2 * USEC_PER_MSEC)

Why is this more understandable than the raw value ?

Because instead of counting 0:s and checking the suffix, I can immediately read from the value like:

"This is 2 milliseconds in microseconds units."

It's more understandable and robust against possible typos.

...

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+#define NXP_SAR_ADC_DMA_BUFF_SZ (PAGE_SIZE * NXP_SAR_ADC_DMA_SAMPLE_SZ)

Oh, PAGE_SIZE is not good to use. I believe this HW is not tolerant to any page size. (Note, we made similar mistake in Intel IPU3 camera driver, which is now fixed)

Is it acceptable to put a hardcoded 4096 value ?

Sure, define it like HW page size

/* This ADC relies on the page size to be 4kB */
NXP_SAR_PAGE_SIZE 0x1000 // or SZ_4K, or ...

...

Quoted 10 lines
Quoted 10 lines

drivers/iio/adc/nxp-sar-adc.c line 243

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+	ret = read_poll_timeout(readl, msr, !(msr & REG_ADC_MSR_CALBUSY),

Why not readl_poll_timeout()?

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+				NXP_SAR_ADC_WAIT_US,
+				NXP_SAR_ADC_CAL_TIMEOUT_US,
+				true, REG_ADC_MSR(base));
+	if (ret)
+		return ret;
Quoted 7 lines
Quoted 4 lines

drivers/iio/adc/nxp-sar-adc.c line 251

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	if (!(msr & REG_ADC_MSR_CALFAIL))
+		return 0;

I would expect standard pattern — "errors first", but here either works.

Does it mean this chunk of code can be preserved or do you prefer an error block followed with a return 0 ?

Up to you. Only the question above (readl_poll_timeout() use) stays unanswered so far.

...

Quoted 11 lines
Quoted 10 lines

drivers/iio/adc/nxp-sar-adc.c line 455

Quoted 7 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+	/*
+	 * On disable, we have to wait for the transaction to finish.
+	 * ADC does not abort the transaction if a chain conversion
+	 * is in progress.
+	 * Wait for the worst case scenario - 80 ADC clk cycles.
+	 */
+	ndelay(div64_u64(NSEC_PER_SEC, clk_get_rate(info->clk)) * 80U);

Could it possible go wrong and with low rate clocks (kHz:ish) this will go into lo-o-o-o-ng *atomic* delay?

Quoted 4 lines

It is the ADC clock where we need to wait for 80 cycles. The lowest clock rate is 40MHz, but on this platform it is 80MHz IIRC. This routine is called only when the capture finishes. Except I'm missing something, this scenario should not happen.

So, you guarantee that clk_get_rate() never returns, let's say 1000, right? (Personally I don't see how it's possible to guarantee...)

...

Quoted 5 lines
Quoted 3 lines

drivers/iio/adc/nxp-sar-adc.c line 488

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+		nxp_sar_adc_channels_enable(info, 1 >> chan->channel);

1 >> ?!? Did you want BIT(channel)? Or simply channel != 0?

Yeah, BIT(chan->channel) is better

But is the above a bug in the original proposal or not? I mean one wanted left instead of right shift.

...

Quoted 8 lines
Quoted 4 lines

drivers/iio/adc/nxp-sar-adc.c line 582

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	dmaengine_tx_status(info->dma_chan,
+			    info->cookie, &state);

Perfectly one line. No return check?

Ok, will see if the IIO DMA API has an impact on this portion of code before checking the return code. However, the status is often ignored in the other drivers.

...which doesn't mean it's a good example to follow.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#24 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · Andy Shevchenko

On Wed, Sep 03, 2025 at 12:27:56PM +0200, Daniel Lezcano wrote:

[ ... ]

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

drivers/iio/adc/nxp-sar-adc.c line 243

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+	ret = read_poll_timeout(readl, msr, !(msr & REG_ADC_MSR_CALBUSY),

Why not readl_poll_timeout()?

drivers/iio/adc/nxp-sar-adc.c line 251

Quoted 8 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+				NXP_SAR_ADC_WAIT_US,
+				NXP_SAR_ADC_CAL_TIMEOUT_US,
+				true, REG_ADC_MSR(base));
+	if (ret)
+		return ret;
 
+	if (!(msr & REG_ADC_MSR_CALFAIL))
+		return 0;

I would expect standard pattern — "errors first", but here either works.

Quoted 5 lines
Quoted 2 lines

Does it mean this chunk of code can be preserved or do you prefer an error block followed with a return 0 ?

Up to you. Only the question above (readl_poll_timeout() use) stays unanswered so far.

It is a typo, it should be readl_poll_timeout() as you suggested

[ ... ]

Thanks

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#25 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · Andy Shevchenko

On Wed, Sep 03, 2025 at 12:27:56PM +0200, Daniel Lezcano wrote:

[ ... ]

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

drivers/iio/adc/nxp-sar-adc.c line 488

Quoted 1 line
drivers/iio/adc/nxp-sar-adc.c new file +1 -0
+		nxp_sar_adc_channels_enable(info, 1 >> chan->channel);

1 >> ?!? Did you want BIT(channel)? Or simply channel != 0?

Yeah, BIT(chan->channel) is better

But is the above a bug in the original proposal or not? I mean one wanted left instead of right shift.

It is actually a bug, you are right it should have been left shift

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

drivers/iio/adc/nxp-sar-adc.c line 582

Quoted 2 lines
drivers/iio/adc/nxp-sar-adc.c new file +2 -0
+	dmaengine_tx_status(info->dma_chan,
+			    info->cookie, &state);

Perfectly one line. No return check?

Ok, will see if the IIO DMA API has an impact on this portion of code before checking the return code. However, the status is often ignored in the other drivers.

...which doesn't mean it's a good example to follow.

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#26 lore raw

Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms

In reply to Daniel Lezcano

drivers/iio/adc/nxp-sar-adc.c line 18

Quoted 5 lines · Daniel Lezcano
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+#include <linux/dmaengine.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_irq.h>

Unused header

Quoted 1 line

+#include <linux/of_platform.h>

This as well. OTOH, you actually miss the header you use - of.h.

Quoted 19 lines
drivers/iio/adc/nxp-sar-adc.c new file +19 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
+
+/* This will be the driver name the kernel reports */
+#define DRIVER_NAME "nxp-sar-adc"
+
+/* SAR ADC registers */
+#define REG_ADC_CDR(__base, __channel)	(((__base) + 0x100) + ((__channel) * 0x4))
+
+#define REG_ADC_CDR_CDATA_MASK		GENMASK(11, 0)
+#define REG_ADC_CDR_VALID		BIT(19)
+
+/* Main Configuration Register */
+#define REG_ADC_MCR(__base)		(__base)
+

...

Quoted 7 lines
drivers/iio/adc/nxp-sar-adc.c new file +7 -0
+	indio_dev->name = dev_name(dev);
+	indio_dev->info = &nxp_sar_adc_iio_info;
+	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+	indio_dev->channels = nxp_sar_adc_iio_channels;
+	indio_dev->num_channels = ARRAY_SIZE(nxp_sar_adc_iio_channels);
+
+	nxp_sar_adc_set_default_values(info);

drivers/iio/adc/nxp-sar-adc.c line 949

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+
+	ret = nxp_sar_adc_calibration(info);
+	if (ret) {
+		dev_err(dev, "Calibration failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = nxp_sar_adc_dma_probe(dev, info);
+	if (ret) {
+		dev_err(dev, "Failed to initialize the dma\n");

return dev_err_probe

drivers/iio/adc/nxp-sar-adc.c line 959

Quoted 10 lines
drivers/iio/adc/nxp-sar-adc.c new file +10 -0
+		return ret;
+	}
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &iio_pollfunc_store_time,
+					      &nxp_sar_adc_trigger_handler,
+					      &iio_triggered_buffer_setup_ops);
+	if (ret < 0) {
+		dev_err(dev, "Couldn't initialise the buffer\n");
+		return ret;

return dev_err_probe. No need to print ENOMEM errors.

drivers/iio/adc/nxp-sar-adc.c line 964

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c new file +5 -0
+	}
+
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret) {
+		dev_err(dev, "Couldn't register the device.\n");

return dev_err_probe

drivers/iio/adc/nxp-sar-adc.c line 968

Quoted 4 lines
drivers/iio/adc/nxp-sar-adc.c new file +4 -0
+		return ret;
+	}
+
+	dev_info(dev, "Device initialized successfully.\n");

Drivers should be silent on success and kernel already gives you information that device probed (or did not).

Drop.

Best regards,
Krzysztof