| From: |
| Stefan Popa <stefan.popa-AT-analog.com> |
| To: |
| Jonathan Cameron <jic23-AT-kernel.org> |
| Subject: |
| [PATCH v3 0/2] iio: adc: add MAX40080 current-sense amplifier driver |
| Date: |
| Wed, 15 Jul 2026 09:36:15 +0300 |
| Message-ID: |
| <20260715063652.368501-1-stefan.popa@analog.com> |
| Cc: |
| <linux-iio-AT-vger.kernel.org>, Andy Shevchenko <andriy.shevchenko-AT-linux.intel.com>, David Lechner <dlechner-AT-baylibre.com>, Nuno Sa <nuno.sa-AT-analog.com>, Rob Herring <robh-AT-kernel.org>, "Krzysztof Kozlowski" <krzk+dt-AT-kernel.org>, Conor Dooley <conor+dt-AT-kernel.org>, "Siratul Islam" <siratul.islam-AT-linux.dev>, Uwe Kleine-König <u.kleine-koenig-AT-baylibre.com>, Ciprian Hegbeli <ciprian.hegbeli-AT-analog.com>, <devicetree-AT-vger.kernel.org>, <linux-kernel-AT-vger.kernel.org>, Stefan Popa <stefan.popa-AT-analog.com> |
| Archive-link: |
| Article |
This series adds support for the Maxim MAX40080, a bidirectional
current-sense amplifier with an integrated 12-bit ADC and an I2C/SMBus
interface. It measures the voltage across an external shunt resistor and
the input bus voltage.
The driver operates in direct (INDIO_DIRECT_MODE) mode. Each raw read
triggers a single on-demand conversion (SMBus Quick Command) and reads
back the matched current/voltage pair, so results are always fresh. It
exposes the current and voltage channels with raw and scale attributes,
a configurable oversampling (digital averaging) ratio, and PEC-protected
register access. The two selectable current-sense ranges are exposed
through scale/scale_available; the current scale is derived from the
shunt-resistor-micro-ohms device-tree property.
Tested on hardware with four MAX40080 devices on an I2C bus.
Regarding Andy's question about *iv being updated even on error in
read_poll_timeout: yes, this is intentional. The poll loop must update
*iv on each iteration to check the valid bit. On timeout (conversion
never completes), *iv contains the last-read value with the valid bit
still clear, but the caller always checks the return value first —
"if (ret) return ret;" prevents any use of the stale data.
Changes in v3:
- Remove mod_devicetable.h include (Andy, Uwe's rework)
- Use lowercase _mV suffix for unit defines: MAX40080_INTER_VREF_mV,
MAX40080_CSA_50mV_GAIN, MAX40080_CSA_10mV_GAIN (Andy)
- Remove MAX40080_NUM_RANGES macro, use ARRAY_SIZE() directly (Andy)
- Fix reversed xmas tree ordering in get_oversampling_ratio() (Andy)
- Split semantically different variable declarations in
set_oversampling_ratio() and max40080_init() (Andy)
- Join *val, *val2, long mask on same line in read_raw signature (Andy)
- Use const int * cast in read_avail (Andy)
- Join FIFO_CFG write onto single line in max40080_init() (Andy)
- Return i2c_smbus_write_word_data() directly at end of
max40080_init() (Andy)
- Use device_property_present() pattern for optional shunt-resistor
property (Andy)
- Make vdd-supply required in DT bindings (Conor)
- Restore i2c_set_clientdata() needed for PM resume (Sashiko)
- Add bounds check in get_oversampling_ratio() for hardware register
values outside expected range (Sashiko)
Changes in v2:
- Add vdd-supply and interrupts properties to the binding (David)
- Add types.h and time.h includes (Andy)
- Use USEC_PER_MSEC for poll timeout readability (Andy)
- Use 1 * MICRO for default shunt resistor (Andy)
- Rename field macros to include register name, e.g. MAX40080_CFG_MODE_MSK
(Jonathan, David)
- Add indexed defines for RANGE field values and use in gain array
(Jonathan)
- Use array lookup in get_oversampling_ratio instead of formula (Andy)
- Use switch statement for chan->type in read_raw (David)
- Simplify update_bits: one-liner RMW, return write directly (Andy)
- Add local client variable in trigger_measurement (Andy)
- Add braces to for loops and use C99 loop variables (Siratul, Andy)
- Flip if/else in reg_access, separate declaration from assignment (Andy)
- Add .name= in i2c_device_id (David, Siratul)
- Reorder declarations to reverse christmas tree (Siratul)
- Return directly from oversampling case in write_raw (Andy)
- Add blank lines before return in read_avail (Siratul)
- Add Co-developed-by tag for Ciprian (Andy)
- Use Link: tag for datasheet URL in commit message
Stefan Popa (2):
dt-bindings: iio: adc: add maxim,max40080
iio: adc: add MAX40080 current-sense amplifier driver
.../bindings/iio/adc/maxim,max40080.yaml | 64 ++
MAINTAINERS | 9 +
drivers/iio/adc/Kconfig | 11 +
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/max40080.c | 630 ++++++++++++++++++
5 files changed, 715 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/adc/maxim,max40080.yaml
create mode 100644 drivers/iio/adc/max40080.c
--
2.53.0