[PATCH v8 5/5] docs: iio: add documentation for MAX34417 driver
From: Neil Armstrong
Date: Mon Nov 30 2026 - 11:31:02 EST
The ABI is complex enough to require an ABI documentation
to understand which properties are available in CAM mode
and how they behave depending on the selected mode.
Suggested-by: Jonathan Cameron <jic23@xxxxxxxxxx>
Signed-off-by: Neil Armstrong <neil.armstrong@xxxxxxxxxx>
---
Documentation/iio/index.rst | 1 +
Documentation/iio/max34417.rst | 131 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 132 insertions(+)
diff --git a/Documentation/iio/index.rst b/Documentation/iio/index.rst
index 8376c73c29f1..604d5c314014 100644
--- a/Documentation/iio/index.rst
+++ b/Documentation/iio/index.rst
@@ -46,3 +46,4 @@ Industrial I/O Kernel Drivers
ep93xx_adc
open-sensor-fusion
opt4060
+ max34417
diff --git a/Documentation/iio/max34417.rst b/Documentation/iio/max34417.rst
new file mode 100644
index 000000000000..bdfbeebbe133
--- /dev/null
+++ b/Documentation/iio/max34417.rst
@@ -0,0 +1,131 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+===============
+MAX34417 driver
+===============
+
+ADC driver for the Analog Devices `MAX34417 <https://www.analog.com/en/products/max34417.html>`_
+Four-Channel High Dynamic Range Power Accumulator. The module name is
+``max34417``.
+
+Device attributes
+=================
+
+All four channels (``0`` to ``3``) are always exposed in sysfs. Shunt resistor
+values (``shunt-resistor-micro-ohms``, defaulting to 1000 uOhms) and channel
+labels (``label``, defaulting to ``channelX``) are configured via devicetree
+(see ``Documentation/devicetree/bindings/iio/adc/adi,max34417.yaml``).
+
+Because the device operates in either Single-shot mode or Continuous
+Accumulation Mode (CAM), certain attributes are mutually exclusive and return
+``-EINVAL`` when accessed in the wrong mode:
+
+.. flat-table::
+ :header-rows: 1
+
+ * - Attribute
+ - Availability
+ - Description
+
+ * - ``in_energy_en``
+ - Always
+ - Shared enable (``0`` or ``1``) toggling CAM across all four channels.
+
+ * - ``in_voltage[0-3]_raw``
+ - Always
+ - Raw instantaneous voltage measurement.
+
+ * - ``in_voltage[0-3]_scale``
+ - Always
+ - Voltage scale (``raw * scale`` gives millivolts).
+
+ * - ``in_power[0-3]_raw``
+ - Single-shot only (``in_energy_en=0``)
+ - Single-shot power measurement. Returns ``-EINVAL`` in CAM.
+
+ * - ``in_power[0-3]_average_raw``
+ - CAM only (``in_energy_en=1``)
+ - Average power accumulated since CAM was enabled. Returns ``-EINVAL``
+ when not in CAM.
+
+ * - ``in_power[0-3]_scale``
+ - Always
+ - Power scale (``raw * scale`` gives milliwatts).
+
+ * - ``in_energy[0-3]_raw``
+ - CAM only (``in_energy_en=1``)
+ - Energy accumulated since CAM was enabled. Returns ``-EINVAL`` when not
+ in CAM.
+
+ * - ``in_energy[0-3]_scale``
+ - Always
+ - Energy scale at 1536 SPS (``raw * scale`` gives Joules).
+
+ * - ``in_*[0-3]_label``
+ - Always
+ - Channel label for voltage, power, and energy channels.
+
+Operating modes
+===============
+
+Single-shot mode (``in_energy_en = 0``, default)
+------------------------------------------------
+
+Reading ``in_voltageX_raw`` or ``in_powerX_raw`` triggers a single hardware
+measurement cycle (enforcing the 1 ms minimum interval between ``UPDATE``
+commands) and returns the result. ``in_powerX_average_raw`` and
+``in_energyX_raw`` return ``-EINVAL``.
+
+Continuous Accumulation Mode (``in_energy_en = 1``)
+---------------------------------------------------
+
+Writing ``1`` to ``in_energy_en`` enables autonomous sampling across all four
+channels at 1536 SPS. ``in_powerX_raw`` returns ``-EINVAL``.
+
+Because the hardware ``UPDATE`` command transfers and resets the internal 56-bit
+accumulators and 24-bit sample counter for all four channels simultaneously,
+reading any ``in_voltageX_raw``, ``in_powerX_average_raw``, or
+``in_energyX_raw`` attribute causes the driver to read all hardware accumulators
+and add them to 64-bit software accumulators:
+
+* ``in_energyX_raw`` reports the software-accumulated power sum.
+* ``in_powerX_average_raw`` reports the software-accumulated power sum divided
+ by the software-accumulated sample count.
+
+Writing ``0`` to ``in_energy_en`` disables CAM and resets all software
+accumulators, counters, and overflow states.
+
+Overflow behavior in CAM
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+* **Hardware saturation:** The 56-bit hardware accumulators saturate and halt
+ after ~4.55 hours at full-scale power without an ``UPDATE``. At least one
+ channel must be read within this window to transfer data to software and
+ clear any hardware ``OVF`` flag.
+* **Software overflow:** The 64-bit software accumulators hold up to ~48.53 days
+ of full-scale data. If any software accumulator or the sample counter
+ overflows, ``in_powerX_average_raw`` and ``in_energyX_raw`` return
+ ``-EOVERFLOW`` (while ``in_voltageX_raw`` remains functional) until
+ ``in_energy_en`` is written ``0``.
+
+Usage examples
+==============
+
+Single-shot readout (``in_energy_en`` is ``0``):
+
+.. code-block:: bash
+
+ $ cd /sys/bus/iio/devices/iio:device0
+ $ cat in_voltage0_raw in_voltage0_scale
+ $ cat in_power0_raw in_power0_scale
+
+Continuous accumulation readout:
+
+.. code-block:: bash
+
+ $ cd /sys/bus/iio/devices/iio:device0
+ $ echo 1 > in_energy_en
+ $ # run workload (read at least once every 4.5 hours)
+ $ cat in_energy0_raw in_energy0_scale
+ $ cat in_power0_average_raw in_power0_scale
+ $ echo 0 > in_energy_en
--
2.34.1