[PATCH v5 0/2] NXP SAR ADC IIO driver for s32g2/3 platforms

Daniel Lezcano
2025-10-17T16:42:49Z

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

After the V1 posting there were some discussions around the DMA code
to be converted to use the IIO DMA API [1]. Unfortunately this one is
not yet fully implemented and merged in the framework to support the
cyclic DMA. The current DMA code in the driver has been used in
production since several years and even if I agree it can be improved
with a dedicated IIO DMA API in the future, IMO, it sounds reasonable
to keep it as is until the IIO DMA API supporting the cyclic DMA is
merged. I'll be glad to convert the driver code if such an API exists
and allows to remove code inside the driver.

[1] https://lore.kernel.org/all/c30bb4b6328d15a9c213c0fa64b909035dc7bf40.camel@gmail.com/

Changelog:
* V5:
- Rebased against v6.18-rc1

** Jonathan Cameron
- Replace DRIVER_NAME macro with its literal string
- Used FIELD_MODIFY() wherever it is possible
- Complied with the 80 chars convention
- Combined two variables in a single line declaration
- Removed the 'remove' function as it is useless
- Changed s32g2_sar_adc_data structure indentation / format

* V4:
** Christophe Jaillet **
- Used dmam_alloc_coherent() instead of dma_alloc_coherent()

* V3:
** Jonathan Cameron **
- Removed specific IIO_SYSFS_TRIGGER dependency in Kconfig
- Fixed headers
- Avoided macro generic names
- Used IIO_DECLARE_BUFFER_WITH_TS
- Documented buffer and buffer_chan
- Fixed single line comment
- Commented why channel 32 is the timestamp
- Renamed __<prefixed> functions
- Factored out the raw read function to prevent nested goto in the switch
- Returned -EINVAL instead of break
- Removed explict pointer cast
- Used iio_push_to_buffers_with_ts variant
- Fixed ordering operations in postenable / predisable
- Return IRQ_HANDLED even if there is an error in the isr
- Fixed devm_add_action_or_reset() to return directly
- Used sizeof(*var) instead of sizeof(struct myvar)
- Used model name instead of dev_name()
- Used dev_err_probe() in any case in the probe function
- Fixed indentation

** David Lechner **
- Kept alphabetical order in Makefile
- Changed explicit GPL-2.0-only
- Removed clock name in when calling devm_clk_get_enabled()

** Andriy Shevchenko **
- Fixed headers ordering and added the missing ones
- Fixed constant numeric format
- Ran pahole and consolidated the nxp_sar_adc structure
- Fixed semi-column in comments and typos
- Fixed indentation
- Moved data assignment before iio_dev allocation

* V2:
- Massaged the cover letter changelog to explain the DMA
** Andriy Shevchenko **
- Added missing headers and use proper header for of.h
- Changed macro offset zero to be consistent
- Remove macros REG_ADC_MCR_NRSMPL_* as they are unused
- Changed delays macro under the form 100000 => 100 * USEC_PER_MSEC
- Replaced PAGE_SIZE by a NXP_PAGE_SIZE = SZ_4K macro
- Replaced read_poll_timeout() by readl_poll_timeout()
- Changed error pattern "error first"
- Replaced variable type 'int' to 'unsigned int'
- Fixed bug right instead of left shift, use BIT(channel)
- Returned directly from switch-case
- Used guard(spinlock_irqsave)()
- One liner function call
- Remove redundant {}
- Write default values litterals instead of temporary variables
- Changed variable name vref -> vref_mV
- Removed unneeded error message
- Used dev_err_probe() consistently
- Removed successful driver probe message
- Removed redundant blank line

** Nuno Sa **
- Replaced of_device_get_match_data() by device_get_match_data()
- Removed iio_device_unregister() because devm_iio_device_register() is used
- Removed "/* sentinel */" comment
- Removed CONFIG_PM_SLEEP defiries

** Krzysztof Kozlowski / David Lechner **
- Removed clock-names in DT bindings
- Fixed minItems by maxItems

* V1:
- Initial post

Daniel Lezcano (2):
dt-bindings: iio: adc: 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 | 63 ++
drivers/iio/adc/Kconfig | 12 +
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/nxp-sar-adc.c | 1006 +++++++++++++++++
4 files changed, 1082 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,s32g2-sar-adc.yaml
create mode 100644 drivers/iio/adc/nxp-sar-adc.c

--
2.43.0