mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chi-Wen Weng <cwweng.linux@gmail.com>
To: jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	chernyakin.victor.j@outlook.com, cwweng@nuvoton.com,
	cwweng.linux@gmail.com
Subject: [PATCH v5 0/3] iio: adc: Add Nuvoton MA35D1 EADC support
Date: Tue, 17 Nov 2026 16:28:29 +0800	[thread overview]
Message-ID: <20261117082832.1551574-1-cwweng.linux@gmail.com> (raw)

From: Chi-Wen Weng <cwweng@nuvoton.com>

This series adds IIO support for the Enhanced Analog-to-Digital
Converter (EADC) found on Nuvoton MA35D1 SoCs.

The EADC provides eight external analog inputs which may be used as
single-ended inputs or as four fixed differential pairs: 0-4, 1-5,
2-6 and 3-7. The VBAT input is internally connected and needs no
devicetree description. It is not supported by this initial driver.

The initial driver supports direct conversion and triggered buffered
capture using sample module 0. Although the hardware provides multiple
sample modules, this version uses only sample module 0 and therefore
supports one active voltage channel per buffered scan.

The series also fixes the common ADC channel validation to reject
configurations specifying both single-channel and diff-channels. The
corresponding redundant constraints are removed from the MA35D1 binding.

A reset control is required to put the EADC into a known state at
probe and resume, and to recover from power-up failures without
clearing ADCEN while the start-up sequence is still in progress.

The series is based on Linux v7.4-rc1.

Changes in v5:
- Fix the common adc.yaml channel validation by replacing the existing
  anyOf constraint with an explicit reg requirement and a mutual-exclusion
  constraint for single-channel and diff-channels, as suggested by
  Rob Herring.
- Remove redundant channel-level validation constraints from the
  MA35D1 binding.
- Require a reset control in the binding and driver to reset the EADC
  during probe and resume and to recover from power-up failures.
- Clarify that the VBAT input is internally connected and needs no
  devicetree description.
- Do not specify the internal reference voltage in the vref-supply
  description.
- Use folded YAML scalars for prose descriptions.
- Reorganize register definitions so register addresses, fields and
  values are grouped together.
- Describe the individual INTSRC0 sample-module interrupt-enable bits
  explicitly instead of treating them as a single field.
- Add paired ADC interrupt enable and disable helpers and simplify the
  conversion error paths.
- Document the ordering used when aborting a timed-out conversion.
- Correct the comment describing PDREF.
- Remove the trivial differential sign-extension helper.
- Validate the effective scan mask in update_scan_mode() so callback
  buffers and merged masks cannot request multiple voltage channels.
  Commit the selected channel only after validation.
- Wait for PWRM.PWUPRDY after enabling the ADC.
- Use a full module reset to recover from power-up failures instead of
  clearing ADCEN before PWUPRDY is set. Preserve the original error and
  report any reset failure.
- Read DAT0 during timeout recovery to discard an unread result and
  clear stale VALID and OV flags.
- Reset the whole EADC module at the start of hardware initialization
  in both probe and resume, replacing the control-circuit reset and the
  register-by-register clearing of inherited interrupt, compare and
  trigger configuration. This also removes the access to the
  non-existent SCTL8 register.
- Split single-ended and differential channel parsing into separate
  helpers.
- Initialize local channel-tracking bitmaps directly using = { } instead
  of separate bitmap_zero() calls, as suggested by Victor Chernyakin.
- Remove the unnecessary raw variable in the triggered capture path
  and read the conversion result directly into scan.channel.
- Rework suspend and resume hardware handling around scoped mutex
  locking.
- Remove the buffer predisable callback. Every conversion path already
  leaves the ADC interrupt disabled and ADIF0 cleared, and the callback
  could access EADC registers while the clock was gated after a failed
  resume.
- Make repeated suspend handling safe after an unsuccessful resume and
  avoid unbalanced clock disable operations.
- Only call iio_device_suspend_triggering() and
  iio_device_resume_triggering() while the buffer is enabled.
  pollfunc->irq is not initialized until the pollfunc is first attached
  to a trigger, so calling them unconditionally, as v4 did, could pass
  an uninitialized IRQ number to disable_irq() and enable_irq().
- Drop the redundant clk_enabled flag pointed out by Andy Shevchenko;
  the suspended flag already tracks whether the clock is gated.
- Add a comment explaining why the EADC register map is left uncached.
- Describe the readable, writable and precious EADC registers in the
  regmap configuration.
- Apply the requested structure layout, variable scope, formatting and
  control-flow cleanups, including the if/else chain in init_vref().
- Drop the unused linux/io.h and linux/iio/trigger.h includes.
- Require at least one external channel child node.

Changes in v4:
- Use the common ADC diff-channels property to describe differential
  inputs and keep reg as the logical channel index.
- Restrict differential inputs to the four hardware-supported pairs.
- Restrict channel child nodes to the ADC properties supported by the
  MA35D1 EADC.
- Prevent single-channel and diff-channels from being specified
  together.
- Document that each single-ended input and differential input pair
  may be described only once.
- Remove interrupt-names and simplify the interrupt descriptions.
- Update the binding example to demonstrate separation of the logical
  channel index from the physical ADC inputs.
- Update channel parsing to match the revised binding semantics.
- Store physical ADC inputs in the IIO channel/channel2 fields and use
  address for the logical DT channel index.
- Reject duplicate physical single-ended inputs and differential input
  pairs.
- Use the physical positive input when programming the sample-module
  channel selection and the logical index for firmware-node channel
  translation.
- Use interrupt index 0 instead of looking up ADINT0 by name.
- Add the standard one-hot scan-mask validation callback.
- Use iio_for_each_active_channel() when selecting the buffered
  channel.
- Use a fixed scan structure for the single-channel buffered layout.
- Limit conversion results to the 12-bit ADC data width.
- Always report -ETIMEDOUT when a conversion times out.
- Make timeout recovery best effort so interrupt disable, control reset,
  IRQ synchronization and stale status cleanup are all attempted even
  if an earlier recovery step fails.
- Use devm_regulator_get_enable_read_voltage() for the optional
  external reference supply.
- Rework clock management to explicitly balance prepare/enable state
  across probe, suspend, resume, error paths and driver teardown.
- Improve suspend and resume error-path handling.
- Remove the redundant explicit REGCACHE_NONE setting.
- Split interrupt status read failures from interrupt-source checks and
  handle failures when clearing the interrupt status.
- Use symbolic definitions for the ADC resolution and differential
  scale width.
- Use cleanup guards for mutex handling in buffered capture and keep
  trigger notification outside the locked section.
- Use more specific error codes for channel capacity, duplicate channel
  definitions and out-of-range physical inputs.
- Apply the requested regmap, control-flow and coding-style cleanups.

Changes in v3:
- Document all four ADINT0 through ADINT3 hardware interrupt outputs
  and add interrupt-names.
- Document ADINT3 as the shared conversion and result-compare interrupt
  output.
- Remove the redundant minItems/maxItems constraints from the fixed
  interrupts items list.
- Rework the channel binding for the fixed differential pairs and use
  single-channel for single-ended inputs.
- Add #io-channel-cells so the EADC can be referenced by DT IIO
  consumers, and define the cell as the logical channel index.
- Add firmware-node channel translation so sparse or reordered channel
  child nodes are mapped by their logical channel index.
- Restrict unsupported generic ADC channel properties including bipolar,
  common-mode-channel, settling-time-us and oversampling-ratio.
- Explicitly configure INTPOS for end-of-conversion interrupt
  generation.
- Explicitly configure the ADINT0 sample-module source and clear unused
  sample-module routing.
- Reset the EADC control circuits during hardware initialization and
  clear inherited ADC interrupt enables, result-compare interrupt
  enables and sample-module trigger sources.
- Add timeout recovery using the EADC control-circuit reset, followed by
  IRQ synchronization and stale status/completion cleanup.
- Use iio_push_to_buffers_with_ts() for triggered buffered capture.
- Avoid mixing cleanup guards with goto paths in the trigger handler.
- Add ARCH_MA35 || COMPILE_TEST and HAS_IOMEM Kconfig dependencies.
- Drop redundant linux/bitops.h and linux/mod_devicetable.h includes.
- Use direct regmap helpers, explicit REGCACHE_NONE and
  regmap_assign_bits() where appropriate.
- Use fixed-width register offsets and kernel time/unit helpers.
- Use size_add() for channel array allocation.
- Request ADINT0 by interrupt name.
- Improve system suspend and resume handling.
- Address review comments from Jonathan Cameron, Rob Herring,
  Andy Shevchenko, Uwe Kleine-König and automated review/testing.

Changes in v2:
- Reworked the driver to use regmap.
- Added optional external reference supply support and IIO scale
  reporting.
- Added optional reset handling.
- Added externally triggered buffered capture.
- Added signed differential conversion handling.
- Added fixed differential-pair validation.
- Added system sleep support.
- Added optional DMA properties to the binding.

Patch 1 fixes the common ADC channel property validation.
Patch 2 adds the MA35D1 EADC devicetree binding.
Patch 3 adds the MA35D1 EADC IIO driver.

Chi-Wen Weng (3):
  dt-bindings: iio: adc: Fix channel property validation
  dt-bindings: iio: adc: Add Nuvoton MA35D1 EADC
  iio: adc: Add Nuvoton MA35D1 EADC driver

 .../devicetree/bindings/iio/adc/adc.yaml      |   17 +-
 .../bindings/iio/adc/nuvoton,ma35d1-eadc.yaml |  174 +++
 drivers/iio/adc/Kconfig                       |   14 +
 drivers/iio/adc/Makefile                      |    1 +
 drivers/iio/adc/ma35d1_eadc.c                 | 1036 +++++++++++++++++
 5 files changed, 1232 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/nuvoton,ma35d1-eadc.yaml
 create mode 100644 drivers/iio/adc/ma35d1_eadc.c


base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.25.1


             reply	other threads:[~2026-11-17  8:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  8:28 Chi-Wen Weng [this message]
2026-11-17  8:28 ` [PATCH v5 1/3] dt-bindings: iio: adc: Fix channel property validation Chi-Wen Weng
2026-11-17  8:28 ` [PATCH v5 2/3] dt-bindings: iio: adc: Add Nuvoton MA35D1 EADC Chi-Wen Weng
2026-11-17  8:28 ` [PATCH v5 3/3] iio: adc: Add Nuvoton MA35D1 EADC driver Chi-Wen Weng

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20261117082832.1551574-1-cwweng.linux@gmail.com \
    --to=cwweng.linux@gmail.com \
    --cc=andy@kernel.org \
    --cc=chernyakin.victor.j@outlook.com \
    --cc=conor+dt@kernel.org \
    --cc=cwweng@nuvoton.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

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

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

all inboxes | Powered by JetHome®