mbox series

[v3,00/10] Add support for AD4170 series of ADCs

Message ID cover.1747083143.git.marcelo.schmitt@analog.com
Headers show
Series Add support for AD4170 series of ADCs | expand

Message

Marcelo Schmitt May 13, 2025, 12:32 p.m. UTC
Hello,

Thank you to all reviewers of v1 and v2.
Hope I've been able to sort out all issues raised and incorporate all
improvement suggestions in v3. Despite splitting some parts out of the base
driver, that's still not a small patch. I understand that it may take more than
usual to receive reviews for this series. Thank you.

There is actually one thing left that I'd like to improve which is the support
for negative/bipolar voltage references. Though, that will lead to changes in
the regulator subsystem/framework which would bloat this series even more.
If possible, I'd like to do that on a separate patch set.


This patch set adds support for Analog Devices AD4170 and similar sigma-delta ADCs.

Patch 1 adds device tree documentation for the parts.
Patch 2 adds basic device support.
Patch 3 adds support for calibration scale.
Patch 4 adds support for calibration bias.
Patch 5 adds support for sample frequency along with filter type configuration.
Patch 6 adds support for buffered ADC reading.
Patch 7 adds clock provider support
Patch 8 adds GPIO controller support.
Patch 9 adds internal temperature sensor support.
Patch 10 adds support for external RTD and bridge circuit sensors.

Change log v2 -> v3

[device tree changes]
- Removed unneeded allOf.
- Removed occurences of adi,sensor-type type re-declaration.
- Created type for the AD4170 channels, allowing to avoid dt doc repetition.

[General IIO driver changes]
- Fixed issues reported by 0-DAY kernel test robot.
- Used pahole to reorder ad4170_state fields for better cache line alignment.
- Replaced all occurrences of `int i` by `unsigned int i`.
- Replaced all `if (ret < 0)` by `if (ret)` whenever appropriate.

[Basic driver patch]
- Updated Copyright year.
- Separated handling of channel setup cases for better understanding of code flow.
- Now comparing setups field by field instead of using memcmp().
- Disable channel on ad4170_read_sample() error path.
- Reinit completion before entering single conversion mode.
- Organized ad4170_sinc3_filt_fs_tbl.
- Used clamp to simplify configuration value checking.
- Returned earlier whenever possible.
- Used HZ_PER_KHZ/MHZ.
- Declared internal voltage reference constant AD4170_INT_REF_2_5V
- Many other minor code style and readability improvements.

[New patch - Add support for calibration scale/gain]
[New patch - Add support for calibration bian/offset]
[New patch - Add support for adjustable sample frequency]

[Buffered capture patch]
- Made validate_scan_mask() return false if no channel enabled (bitmap_weight() == 0).
- Use local variable device pointer to simplify trigger setup and better wrap lines.
- Tidy up buffer declaration, function returns, comments, and other minor things.
- Fixed data handling in trigger handler which I hadn't noticed to became buggy
  after xfter buffer type was changed from __be32 to u8 array.

[CLOCK provider patch]
- Applied minor changes according to v2 review.
- Avoid unmet dependencies by depending on COMMON_CLK rather than selecting that.
- Brought early external clock defines from early patches to this one.
- Picked up a review tag from v1 review that I failed to include in v2.

[GPIO controller patch]
- Defined masks for updating GPIO mode register.
- Replaced regmap_clear/set_bits() by regmap_update_bits() to set GPIO direction.
- Removed GPIO direction check before setting GPIO output values.
- Made use of regmap_assign_bits() to set GPIO output reg bits.
- Made value to be set as GPIO output state be either 0 or 1.
- No longer locking on state mutex on GPIO set since GPIO output should not
  conflict with other direct mode functionality (e.g. single-shot read).

[Internal temperature sensor patch]
- Wrapped line according to logical approach.

[External sensor patch]
- Added trailing comma to ad4170_iout_current_ua_tbl array.
- Simplified AD4170_CURRENT_SRC_REG constants with macros.
- Used temporary variable to keep logical line wrapping of vbias calculation.
- Dropped ad4170_find_table_index() after open coding both uses of that.
- Extracted pin validation to reduce indentation.
- Inverted ad4170_setup_bridge() logic to reduce indentation.
- Used GPIO register masks to convey reg write meanings in ad4170_setup_bridge().
- Reworked ad4170_setup_current_src() to make it readable.

Link to v2: https://lore.kernel.org/linux-iio/cover.1745841276.git.marcelo.schmitt@analog.com/


Change log v1 -> v2

[IIO driver changes]
- Call gpio_set() at begining of gpio_direction_output() instead of at the end of it.
- Return -EPERM if try to set a GPIO configured for input.
- Now locking on state mutex before setting output GPIO values.
- Used gpiochio init_valid_mask() to only init available GPIOs.
- Replaced 3 regmap configs by regmap with custom reg_read/write implementation.
- Improved to support more than one extarnal sensor connected.
- A few other minor improvements.

[device tree changes]
- Referenced adc.yaml from sensor-node.
- Merged property descriptions to reduce doc duplication.
- Every child node type is now in the example.
- Better described sensor-type property with a list of possible types.
- Updated adi,excitation-pins description to cover a use case I had overlooked.
- Added default to interrupt-names and to clock-names.
- Dropped '|' from descriptions when not needed.
- Added extra example

Link to v1: https://lore.kernel.org/linux-iio/cover.1744200264.git.marcelo.schmitt@analog.com/


Thanks,
Marcelo


Ana-Maria Cusco (1):
  iio: adc: Add basic support for AD4170

Marcelo Schmitt (9):
  dt-bindings: iio: adc: Add AD4170
  iio: adc: ad4170: Add support for calibration gain
  iio: adc: ad4170: Add support for calibration bias
  iio: adc: ad4170: Add digital filter and sample frequency config
    support
  iio: adc: ad4170: Add support for buffered data capture
  iio: adc: ad4170: Add clock provider support
  iio: adc: ad4170: Add GPIO controller support
  iio: adc: ad4170: Add support for internal temperature sensor
  iio: adc: ad4170: Add support for weigh scale and RTD sensors

 .../bindings/iio/adc/adi,ad4170.yaml          |  544 +++
 MAINTAINERS                                   |    8 +
 drivers/iio/adc/Kconfig                       |   16 +
 drivers/iio/adc/Makefile                      |    1 +
 drivers/iio/adc/ad4170.c                      | 2921 +++++++++++++++++
 5 files changed, 3490 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4170.yaml
 create mode 100644 drivers/iio/adc/ad4170.c


base-commit: d820bea88e277acc38b011fde9a8dc9f5310a6b9