Skip to contentSkip to conversation

iio: adc: add support for ADE9000 Energy Monitoring IC

PATCH Superseded Antoniu Miclaus 6 participants 14 messages Aug 22, 2025 – Aug 26, 2025

Subsystems (5)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Antoniu Miclaus

author maintainer
#0 lore raw

v5 cover iio: adc: add support for ADE9000 Energy Monitoring IC

This patch series adds support for the Analog Devices ADE9000, a highly accurate, fully integrated, multiphase energy and power quality monitoring device. The ADE9000 is capable of measuring energy consumption and power quality parameters in industrial and commercial applications.

The series includes:

1. New IIO modifiers for power and energy measurement devices, including support for active/reactive/apparent power, RMS masurements.

2. Device tree bindings for the ADE9000, supporting waveform buffer configuration, phase configuration, and trigger settings.

3. Complete driver implementation supporting:
- Multi-phase energy measurement (3-phase support)
- Power quality monitoring (voltage swell/dip detection)
- Waveform buffer capture with configurable triggering
- Energy accumulation with configurable time windows
- IIO buffer interface for continuous data streaming
- Event-based notifications for power quality events

The driver provides a comprehensive interface for energy monitoring applications through the IIO framework, enabling userspace applications to monitor power consumption, quality, and waveform data.

The driver will be extended in the future to support multiple parts such as ade9039.

Antoniu Miclaus (6):
iio: add IIO_ALTCURRENT channel type
iio: add power and energy measurement modifiers
dt-bindings: iio: adc: add ade9000
iio: adc: add ade9000 support
docs: iio: add documentation for ade9000 driver
Documentation: ABI: iio: add sinc4+lp

 Documentation/ABI/testing/sysfs-bus-iio       |   30 +
 .../bindings/iio/adc/adi,ade9000.yaml         |   97 +
 Documentation/iio/ade9000.rst                 |  286 +++
 Documentation/iio/index.rst                   |    1 +
 drivers/iio/adc/Kconfig                       |   19 +
 drivers/iio/adc/Makefile                      |    1 +
 drivers/iio/adc/ade9000.c                     | 2011 +++++++++++++++++
 drivers/iio/industrialio-core.c               |    6 +
 include/linux/iio/types.h                     |    1 +
 include/uapi/linux/iio/types.h                |    5 +
 tools/iio/iio_event_monitor.c                 |    2 +
 11 files changed, 2459 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml
 create mode 100644 Documentation/iio/ade9000.rst
 create mode 100644 drivers/iio/adc/ade9000.c
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v5 1/6 iio: add IIO_ALTCURRENT channel type

Add support for IIO_ALTCURRENT channel type to distinguish AC current measurements from DC current measurements. This follows the same pattern as IIO_VOLTAGE and IIO_ALTVOLTAGE.

---
no changes in v5.

 drivers/iio/industrialio-core.c | 1 +
 include/uapi/linux/iio/types.h  | 1 +
 tools/iio/iio_event_monitor.c   | 2 ++
 3 files changed, 4 insertions(+)
drivers/iio/industrialio-core.c +1 -0
index f13c3aa470d7..8c9098668772 100644
@@ -97,6 +97,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_COLORTEMP] = "colortemp",
 	[IIO_CHROMATICITY] = "chromaticity",
 	[IIO_ATTENTION] = "attention",
+	[IIO_ALTCURRENT] = "altcurrent",
 };
 
 static const char * const iio_modifier_names[] = {
include/uapi/linux/iio/types.h +1 -0
index 3eb0821af7a4..3c3cc1497a1e 100644
@@ -52,6 +52,7 @@ enum iio_chan_type {
 	IIO_COLORTEMP,
 	IIO_CHROMATICITY,
 	IIO_ATTENTION,
+	IIO_ALTCURRENT,
 };
 
 enum iio_modifier {
tools/iio/iio_event_monitor.c +2 -0
index eab7b082f19d..d26aff649f3f 100644
@@ -64,6 +64,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_COLORTEMP] = "colortemp",
 	[IIO_CHROMATICITY] = "chromaticity",
 	[IIO_ATTENTION] = "attention",
+	[IIO_ALTCURRENT] = "altcurrent",
 };
 
 static const char * const iio_ev_type_text[] = {
@@ -187,6 +188,7 @@ static bool event_is_known(struct iio_event_data *event)
 	case IIO_COLORTEMP:
 	case IIO_CHROMATICITY:
 	case IIO_ATTENTION:
+	case IIO_ALTCURRENT:
 		break;
 	default:
 		return false;
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v5 2/6 iio: add power and energy measurement modifiers

In reply to Antoniu Miclaus

Add new IIO modifiers to support power and energy measurement devices:

Power modifiers:
- IIO_MOD_ACTIVE: Real power consumed by the load
- IIO_MOD_REACTIVE: Power that oscillates between source and load
- IIO_MOD_APPARENT: Magnitude of complex power
- IIO_MOD_FUND_REACTIVE: Reactive power at fundamental frequency
- IIO_MOD_FACTOR: Power factor (ratio of active to apparent power)

Signal quality modifiers:
- IIO_MOD_RMS: Root Mean Square value

These modifiers enable proper representation of power measurement devices like energy meters and power analyzers.

---
no changes in v5.

 Documentation/ABI/testing/sysfs-bus-iio | 29 +++++++++++++++++++++++++
 drivers/iio/industrialio-core.c         |  5 +++++
 include/linux/iio/types.h               |  1 +
 include/uapi/linux/iio/types.h          |  4 ++++
 4 files changed, 39 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +29 -0
index 2fb2cea4b192..78da68826307 100644
@@ -167,7 +167,18 @@ Description:
 		is required is a consistent labeling.  Units after application
 		of scale and offset are millivolts.
 
+What:		/sys/bus/iio/devices/iio:deviceX/in_altvoltageY_rms_raw
+KernelVersion:	6.18
+Contact:	[email protected]
+Description:
+		Raw (unscaled) Root Mean Square (RMS) voltage measurement from
+		channel Y. Units after application of scale and offset are
+		millivolts.
+
 What:		/sys/bus/iio/devices/iio:deviceX/in_powerY_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_powerY_active_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_powerY_reactive_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_powerY_apparent_raw
 KernelVersion:	4.5
 Contact:	[email protected]
 Description:
@@ -176,6 +187,13 @@ Description:
 		unique to allow association with event codes. Units after
 		application of scale and offset are milliwatts.
 
+What:		/sys/bus/iio/devices/iio:deviceX/in_powerY_powerfactor
+KernelVersion:	6.18
+Contact:	[email protected]
+Description:
+		Power factor measurement from channel Y. Power factor is the
+		ratio of active power to apparent power. The value is unitless.
+
 What:		/sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw
 KernelVersion:	3.2
 Contact:	[email protected]
@@ -1569,6 +1587,9 @@ Description:
 
 What:		/sys/.../iio:deviceX/in_energy_input
 What:		/sys/.../iio:deviceX/in_energy_raw
+What:		/sys/.../iio:deviceX/in_energyY_active_raw
+What:		/sys/.../iio:deviceX/in_energyY_reactive_raw
+What:		/sys/.../iio:deviceX/in_energyY_apparent_raw
 KernelVersion:	4.0
 Contact:	[email protected]
 Description:
@@ -1707,6 +1728,14 @@ Description:
 		component of the signal while the 'q' channel contains the quadrature
 		component.
 
+What:		/sys/bus/iio/devices/iio:deviceX/in_altcurrentY_rms_raw
+KernelVersion:	6.18
+Contact:	[email protected]
+Description:
+		Raw (unscaled no bias removal etc.) Root Mean Square (RMS) current
+		measurement from channel Y. Units after application of scale and
+		offset are milliamps.
+
 What:		/sys/.../iio:deviceX/in_energy_en
 What:		/sys/.../iio:deviceX/in_distance_en
 What:		/sys/.../iio:deviceX/in_velocity_sqrt(x^2+y^2+z^2)_en
drivers/iio/industrialio-core.c +5 -0
index 8c9098668772..9e372ed38552 100644
@@ -153,6 +153,10 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_PITCH] = "pitch",
 	[IIO_MOD_YAW] = "yaw",
 	[IIO_MOD_ROLL] = "roll",
+	[IIO_MOD_RMS] = "rms",
+	[IIO_MOD_ACTIVE] = "active",
+	[IIO_MOD_REACTIVE] = "reactive",
+	[IIO_MOD_APPARENT] = "apparent",
 };
 
 /* relies on pairs of these shared then separate */
@@ -190,6 +194,7 @@ static const char * const iio_chan_info_postfix[] = {
 	[IIO_CHAN_INFO_ZEROPOINT] = "zeropoint",
 	[IIO_CHAN_INFO_TROUGH] = "trough_raw",
 	[IIO_CHAN_INFO_CONVDELAY] = "convdelay",
+	[IIO_CHAN_INFO_POWERFACTOR] = "powerfactor",
 };
 /**
  * iio_device_id() - query the unique ID for the device
include/linux/iio/types.h +1 -0
index ad2761efcc83..34eebad12d2c 100644
@@ -70,6 +70,7 @@ enum iio_chan_info_enum {
 	IIO_CHAN_INFO_ZEROPOINT,
 	IIO_CHAN_INFO_TROUGH,
 	IIO_CHAN_INFO_CONVDELAY,
+	IIO_CHAN_INFO_POWERFACTOR,
 };
 
 #endif /* _IIO_TYPES_H_ */
include/uapi/linux/iio/types.h +4 -0
index 3c3cc1497a1e..6d269b844271 100644
@@ -109,6 +109,10 @@ enum iio_modifier {
 	IIO_MOD_ROLL,
 	IIO_MOD_LIGHT_UVA,
 	IIO_MOD_LIGHT_UVB,
+	IIO_MOD_RMS,
+	IIO_MOD_ACTIVE,
+	IIO_MOD_REACTIVE,
+	IIO_MOD_APPARENT,
 };
 
 enum iio_event_type {
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH v5 3/6 dt-bindings: iio: adc: add ade9000

In reply to Antoniu Miclaus

Add devicetree bindings support for ade9000.

---
changes in v5:
- remove clock-output-names property (simplified clock output)
- make interrupts, reset-gpios, and interrupt-names optional (removed from required list)
- improve interrupt-names description to allow any subset of irq0, irq1, dready
- fix typo in description ("ADE9000 s a" -> "ADE9000 is a")
- fix spacing in description ("analog-to- digital" -> "analog-to-digital")
- uncomment clock example in device tree example

 .../bindings/iio/adc/adi,ade9000.yaml         | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +97 -0
new file mode 100644
index 000000000000..a1513ad41651
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2025 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ade9000.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADE9000 High Performance, Polyphase Energy Metering driver
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+  The ADE9000 is a highly accurate, fully integrated, multiphase energy and power
+  quality monitoring device. Superior analog performance and a digital signal
+  processing (DSP) core enable accurate energy monitoring over a wide dynamic
+  range. An integrated high end reference ensures low drift over temperature
+  with a combined drift of less than ±25 ppm/°C maximum for the entire channel
+  including a programmable gain amplifier (PGA) and an analog-to-digital
+  converter (ADC).
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf
+
+$ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - adi,ade9000
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 20000000
+
+  interrupts:
+    maxItems: 3
+
+  interrupt-names:
+    description: Optional interrupt names. Any subset of irq0, irq1, dready.
+    maxItems: 3
+
+  reset-gpios:
+    description:
+      Must be the device tree identifier of the RESET pin. As the line is
+      active low, it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  vdd-supply: true
+
+  vref-supply: true
+
+  clocks:
+    description: External clock source when not using crystal
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: clkin
+
+  "#clock-cells":
+    description:
+      ADE9000 can provide clock output via CLKOUT pin with external buffer.
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+          compatible = "adi,ade9000";
+          reg = <0>;
+          spi-max-frequency = <7000000>;
+
+          #clock-cells = <0>;
+          reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+          interrupts = <2 IRQ_TYPE_EDGE_FALLING>, <3 IRQ_TYPE_EDGE_FALLING>, <4 IRQ_TYPE_EDGE_FALLING>;
+          interrupt-names = "irq0", "irq1", "dready";
+          interrupt-parent = <&gpio>;
+          clocks = <&ext_clock_24576khz>;
+          clock-names = "clkin";
+          vdd-supply = <&vdd_reg>;
+      };
+    };
Signature · 1 line
2.43.0
maintainer
#4 lore raw

Re: [PATCH v5 3/6] dt-bindings: iio: adc: add ade9000

Quoted 3 lines · On Fri, 22 Aug 2025 16:01:52 +0000 Antoniu Miclaus…

Add devicetree bindings support for ade9000.

one minor thing inline.

Quoted 49 lines

---
changes in v5:
- remove clock-output-names property (simplified clock output)
- make interrupts, reset-gpios, and interrupt-names optional (removed from required list)
- improve interrupt-names description to allow any subset of irq0, irq1, dready
- fix typo in description ("ADE9000 s a" -> "ADE9000 is a")
- fix spacing in description ("analog-to- digital" -> "analog-to-digital")
- uncomment clock example in device tree example

 .../bindings/iio/adc/adi,ade9000.yaml         | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +31 -0
new file mode 100644
index 000000000000..a1513ad41651
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2025 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ade9000.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADE9000 High Performance, Polyphase Energy Metering driver
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+  The ADE9000 is a highly accurate, fully integrated, multiphase energy and power
+  quality monitoring device. Superior analog performance and a digital signal
+  processing (DSP) core enable accurate energy monitoring over a wide dynamic
+  range. An integrated high end reference ensures low drift over temperature
+  with a combined drift of less than ±25 ppm/°C maximum for the entire channel
+  including a programmable gain amplifier (PGA) and an analog-to-digital
+  converter (ADC).
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf
+
+$ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - adi,ade9000
+
+  reg:

Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml line 41

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +10 -0
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 20000000
+
+  interrupts:
+    maxItems: 3
+
+  interrupt-names:
+    description: Optional interrupt names. Any subset of irq0, irq1, dready.

The binding should enforce that list of possible values. Lots of examples in tree. Basically an enum combined with maxItems / minItems to say 1 to 3 of them. I'm not sure if that is latest preferred way of doing this though.

Quoted 56 lines
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +56 -0
+    maxItems: 3
+
+  reset-gpios:
+    description:
+      Must be the device tree identifier of the RESET pin. As the line is
+      active low, it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  vdd-supply: true
+
+  vref-supply: true
+
+  clocks:
+    description: External clock source when not using crystal
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: clkin
+
+  "#clock-cells":
+    description:
+      ADE9000 can provide clock output via CLKOUT pin with external buffer.
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+          compatible = "adi,ade9000";
+          reg = <0>;
+          spi-max-frequency = <7000000>;
+
+          #clock-cells = <0>;
+          reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+          interrupts = <2 IRQ_TYPE_EDGE_FALLING>, <3 IRQ_TYPE_EDGE_FALLING>, <4 IRQ_TYPE_EDGE_FALLING>;
+          interrupt-names = "irq0", "irq1", "dready";
+          interrupt-parent = <&gpio>;
+          clocks = <&ext_clock_24576khz>;
+          clock-names = "clkin";
+          vdd-supply = <&vdd_reg>;
+      };
+    };
maintainer
#5 lore raw

Re: [PATCH v5 3/6] dt-bindings: iio: adc: add ade9000

In reply to Antoniu Miclaus
Quoted 21 lines · Antoniu Miclaus

Add devicetree bindings support for ade9000.

---
changes in v5:
- remove clock-output-names property (simplified clock output)
- make interrupts, reset-gpios, and interrupt-names optional (removed from required list)
- improve interrupt-names description to allow any subset of irq0, irq1, dready
- fix typo in description ("ADE9000 s a" -> "ADE9000 is a")
- fix spacing in description ("analog-to- digital" -> "analog-to-digital")
- uncomment clock example in device tree example

 .../bindings/iio/adc/adi,ade9000.yaml         | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +0 -0
new file mode 100644
index 000000000000..a1513ad41651

Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml line 8

Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +8 -0
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2025 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ade9000.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADE9000 High Performance, Polyphase Energy Metering driver

Binding is for some h/w device, not a driver.

Quoted 24 lines
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +24 -0
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+  The ADE9000 is a highly accurate, fully integrated, multiphase energy and power
+  quality monitoring device. Superior analog performance and a digital signal
+  processing (DSP) core enable accurate energy monitoring over a wide dynamic
+  range. An integrated high end reference ensures low drift over temperature
+  with a combined drift of less than ±25 ppm/°C maximum for the entire channel
+  including a programmable gain amplifier (PGA) and an analog-to-digital
+  converter (ADC).
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf
+
+$ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - adi,ade9000
+
+  reg:
+    maxItems: 1

Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml line 42

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +10 -0
+
+  spi-max-frequency:
+    maximum: 20000000
+
+  interrupts:
+    maxItems: 3
+
+  interrupt-names:
+    description: Optional interrupt names. Any subset of irq0, irq1, dready.
+    maxItems: 3

This doesn't work for a subset.

Quoted 58 lines
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml new file +55 -0
+
+  reset-gpios:
+    description:
+      Must be the device tree identifier of the RESET pin. As the line is
+      active low, it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  vdd-supply: true
+
+  vref-supply: true
+
+  clocks:
+    description: External clock source when not using crystal
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: clkin
+
+  "#clock-cells":
+    description:
+      ADE9000 can provide clock output via CLKOUT pin with external buffer.
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+          compatible = "adi,ade9000";
+          reg = <0>;
+          spi-max-frequency = <7000000>;
+
+          #clock-cells = <0>;
+          reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+          interrupts = <2 IRQ_TYPE_EDGE_FALLING>, <3 IRQ_TYPE_EDGE_FALLING>, <4 IRQ_TYPE_EDGE_FALLING>;
+          interrupt-names = "irq0", "irq1", "dready";
+          interrupt-parent = <&gpio>;
+          clocks = <&ext_clock_24576khz>;
+          clock-names = "clkin";
+          vdd-supply = <&vdd_reg>;
+      };
+    };
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH v5 4/6 iio: adc: add ade9000 support

In reply to Antoniu Miclaus

Add driver support for the ade9000. highly accurate, fully integrated, multiphase energy and power quality monitoring device.

---
changes in v5:
- replace IIO_CHAN_INFO_HARDWAREGAIN with IIO_CHAN_INFO_CALIBSCALE for gain registers
- replace IIO_CHAN_INFO_OFFSET with IIO_CHAN_INFO_CALIBBIAS for power channel calibration offsets
- change IIO_CHAN_INFO_SAMP_FREQ to IIO_CHAN_INFO_FREQUENCY for line frequency
- add shared PGA scale and frequency configuration via info_mask_shared_by_all
- remove per-channel HARDWAREGAIN and SAMP_FREQ from voltage channels
- simplify power channel attributes
- make interrupts optional (driver works without IRQs but with reduced functionality)
- remove unnecessary parentheses from return statements with bitwise operations
- use dev_err_probe() for consistent error handling and improve error messages
- add local device variables to reduce repetitive dereferencing
- remove unnecessary reinit_completion() and spi_set_drvdata() calls
- fix software reset to return immediately instead of waiting for completion
- move init_completion() before IRQ setup to avoid race conditions
- add devm_mutex_init() for proper mutex initialization
- simplify clock output registration (use fixed "clkout" name instead of generated names)
- improve code clarity with comments
- update frequency validation logic (50Hz/60Hz switch statement instead of ternary)
- reorganize probe function structure and variable initialization order

 drivers/iio/adc/Kconfig   |   19 +
 drivers/iio/adc/Makefile  |    1 +
 drivers/iio/adc/ade9000.c | 2011 +++++++++++++++++++++++++++++++++++++
 3 files changed, 2031 insertions(+)
 create mode 100644 drivers/iio/adc/ade9000.c
drivers/iio/adc/Kconfig +19 -0
index 6de2abad0197..53bdd34a5899 100644
@@ -507,6 +507,25 @@ config AD9467
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad9467.
 
+config ADE9000
+	tristate "Analog Devices ADE9000 Multiphase Energy, and Power Quality Monitoring IC Driver"
+	depends on SPI
+	select REGMAP_SPI
+	select IIO_BUFFER
+	select IIO_KFIFO_BUF
+	help
+	  Say yes here to build support for the Analog Devices ADE9000,
+	  a highly accurate, multiphase energy and power quality monitoring
+	  integrated circuit.
+
+	  The device features high-precision analog-to-digital converters
+	  and digital signal processing to compute RMS values, power factor,
+	  frequency, and harmonic analysis. It supports SPI communication
+	  and provides buffered data output through the IIO framework.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called ade9000.
+
 config ADI_AXI_ADC
 	tristate "Analog Devices Generic AXI ADC IP core driver"
 	depends on MICROBLAZE || NIOS2 || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_INTEL_SOCFPGA || COMPILE_TEST
drivers/iio/adc/Makefile +1 -0
index 1c6ca5fd4b6d..e3ef416a3b5b 100644
@@ -46,6 +46,7 @@ obj-$(CONFIG_AD7944) += ad7944.o
 obj-$(CONFIG_AD7949) += ad7949.o
 obj-$(CONFIG_AD799X) += ad799x.o
 obj-$(CONFIG_AD9467) += ad9467.o
+obj-$(CONFIG_ADE9000) += ade9000.o
 obj-$(CONFIG_ADI_AXI_ADC) += adi-axi-adc.o
 obj-$(CONFIG_ASPEED_ADC) += aspeed_adc.o
 obj-$(CONFIG_AT91_ADC) += at91_adc.o
drivers/iio/adc/ade9000.c new file +2011 -0

2,011 lines not on this page · raw message

Signature · 1 line
2.43.0
build bot
#7 lore raw

Re: [PATCH v5 4/6] iio: adc: add ade9000 support

BCC: [email protected] CC: [email protected] In-Reply-To: <[email protected]> References: <[email protected]> TO: Antoniu…

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Antoniu Miclaus <[email protected]>
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
CC: Antoniu Miclaus <[email protected]>

Hi Antoniu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on robh/for-next linus/master v6.17-rc2 next-20250822] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Antoniu-Miclaus/iio-add-IIO_ALTCURRENT-channel-type/20250823-001017
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20250822160157.5092-5-antoniu.miclaus%40analog.com
patch subject: [PATCH v5 4/6] iio: adc: add ade9000 support

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: arm-randconfig-r072-20250824 (https://download.01.org/0day-ci/archive/20250825/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 8.5.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

New smatch warnings:
drivers/iio/adc/ade9000.c:1009 ade9000_irq1_thread() warn: right shifting more than type allows 16 vs 20 drivers/iio/adc/ade9000.c:1505 ade9000_write_event_config() error: uninitialized symbol 'tmp'. drivers/iio/adc/ade9000.c:1554 ade9000_write_event_config() error: uninitialized symbol 'interrupts'.

Old smatch warnings:
drivers/iio/adc/ade9000.c:1018 ade9000_irq1_thread() warn: right shifting more than type allows 16 vs 20 drivers/iio/adc/ade9000.c:1027 ade9000_irq1_thread() warn: right shifting more than type allows 16 vs 20 drivers/iio/adc/ade9000.c:1036 ade9000_irq1_thread() warn: right shifting more than type allows 16 vs 20 drivers/iio/adc/ade9000.c:1045 ade9000_irq1_thread() warn: right shifting more than type allows 16 vs 20 drivers/iio/adc/ade9000.c:1054 ade9000_irq1_thread() warn: right shifting more than type allows 16 vs 20 drivers/iio/adc/ade9000.c:1507 ade9000_write_event_config() error: uninitialized symbol 'tmp'. drivers/iio/adc/ade9000.c:1524 ade9000_write_event_config() error: uninitialized symbol 'tmp'. drivers/iio/adc/ade9000.c:1527 ade9000_write_event_config() error: uninitialized symbol 'tmp'. drivers/iio/adc/ade9000.c:1546 ade9000_write_event_config() error: uninitialized symbol 'tmp'. drivers/iio/adc/ade9000.c:1549 ade9000_write_event_config() error: uninitialized symbol 'tmp'.

vim +1009 drivers/iio/adc/ade9000.c

b695e630eecec70 Antoniu Miclaus 2025-08-22   878  
b695e630eecec70 Antoniu Miclaus 2025-08-22   879  static irqreturn_t ade9000_irq1_thread(int irq, void *data)
b695e630eecec70 Antoniu Miclaus 2025-08-22   880  {
b695e630eecec70 Antoniu Miclaus 2025-08-22   881  	struct iio_dev *indio_dev = data;
b695e630eecec70 Antoniu Miclaus 2025-08-22   882  	struct ade9000_state *st = iio_priv(indio_dev);
b695e630eecec70 Antoniu Miclaus 2025-08-22   883  	unsigned int bit = ADE9000_ST1_CROSSING_FIRST;
b695e630eecec70 Antoniu Miclaus 2025-08-22   884  	s64 timestamp = iio_get_time_ns(indio_dev);
b695e630eecec70 Antoniu Miclaus 2025-08-22   885  	u32 handled_irq = 0;
b695e630eecec70 Antoniu Miclaus 2025-08-22   886  	u32 interrupts;
b695e630eecec70 Antoniu Miclaus 2025-08-22   887  	u32 result;
b695e630eecec70 Antoniu Miclaus 2025-08-22   888  	u32 status;
b695e630eecec70 Antoniu Miclaus 2025-08-22   889  	u32 tmp;
b695e630eecec70 Antoniu Miclaus 2025-08-22   890  	unsigned long interrupt_bits;
b695e630eecec70 Antoniu Miclaus 2025-08-22   891  	int ret;
b695e630eecec70 Antoniu Miclaus 2025-08-22   892  
b695e630eecec70 Antoniu Miclaus 2025-08-22   893  	if (!completion_done(&st->reset_completion)) {
b695e630eecec70 Antoniu Miclaus 2025-08-22   894  		ret = regmap_read(st->regmap, ADE9000_REG_STATUS1, &result);
b695e630eecec70 Antoniu Miclaus 2025-08-22   895  		if (ret) {
b695e630eecec70 Antoniu Miclaus 2025-08-22   896  			dev_err(&st->spi->dev, "IRQ1 read status fail\n");
b695e630eecec70 Antoniu Miclaus 2025-08-22   897  			return ret;
b695e630eecec70 Antoniu Miclaus 2025-08-22   898  		}
b695e630eecec70 Antoniu Miclaus 2025-08-22   899  
b695e630eecec70 Antoniu Miclaus 2025-08-22   900  		if (result & ADE9000_ST1_RSTDONE_BIT)
b695e630eecec70 Antoniu Miclaus 2025-08-22   901  			complete(&st->reset_completion);
b695e630eecec70 Antoniu Miclaus 2025-08-22   902  		else
b695e630eecec70 Antoniu Miclaus 2025-08-22   903  			dev_err(&st->spi->dev, "Error testing reset done\n");
b695e630eecec70 Antoniu Miclaus 2025-08-22   904  
b695e630eecec70 Antoniu Miclaus 2025-08-22   905  		return IRQ_HANDLED;
b695e630eecec70 Antoniu Miclaus 2025-08-22   906  	}
b695e630eecec70 Antoniu Miclaus 2025-08-22   907  
b695e630eecec70 Antoniu Miclaus 2025-08-22   908  	ret = regmap_read(st->regmap, ADE9000_REG_STATUS1, &status);
b695e630eecec70 Antoniu Miclaus 2025-08-22   909  	if (ret) {
b695e630eecec70 Antoniu Miclaus 2025-08-22   910  		dev_err(&st->spi->dev, "IRQ1 read status fail\n");
b695e630eecec70 Antoniu Miclaus 2025-08-22   911  		return IRQ_HANDLED;
b695e630eecec70 Antoniu Miclaus 2025-08-22   912  	}
b695e630eecec70 Antoniu Miclaus 2025-08-22   913  
b695e630eecec70 Antoniu Miclaus 2025-08-22   914  	ret = regmap_read(st->regmap, ADE9000_REG_MASK1, &interrupts);
b695e630eecec70 Antoniu Miclaus 2025-08-22   915  	if (ret) {
b695e630eecec70 Antoniu Miclaus 2025-08-22   916  		dev_err(&st->spi->dev, "IRQ1 read status fail\n");
b695e630eecec70 Antoniu Miclaus 2025-08-22   917  		return IRQ_HANDLED;
b695e630eecec70 Antoniu Miclaus 2025-08-22   918  	}
b695e630eecec70 Antoniu Miclaus 2025-08-22   919  
b695e630eecec70 Antoniu Miclaus 2025-08-22   920  	interrupt_bits = interrupts;
b695e630eecec70 Antoniu Miclaus 2025-08-22   921  	for_each_set_bit_from(bit, &interrupt_bits,
b695e630eecec70 Antoniu Miclaus 2025-08-22   922  			      ADE9000_ST1_CROSSING_DEPTH){
b695e630eecec70 Antoniu Miclaus 2025-08-22   923  		tmp = status & BIT(bit);
b695e630eecec70 Antoniu Miclaus 2025-08-22   924  
b695e630eecec70 Antoniu Miclaus 2025-08-22   925  		switch (tmp) {
b695e630eecec70 Antoniu Miclaus 2025-08-22   926  		case ADE9000_ST1_ZXVA_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   927  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   928  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22   929  							    ADE9000_ST1_ZXVA_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   930  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   931  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   932  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   933  			handled_irq |= ADE9000_ST1_ZXVA_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   934  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   935  		case ADE9000_ST1_ZXTOVA_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   936  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   937  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22   938  							    ADE9000_ST1_ZXTOVA_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   939  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   940  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   941  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   942  			handled_irq |= ADE9000_ST1_ZXTOVA_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   943  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   944  		case ADE9000_ST1_ZXIA_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   945  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   946  				       IIO_UNMOD_EVENT_CODE(IIO_CURRENT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   947  							    ADE9000_ST1_ZXIA_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   948  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   949  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   950  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   951  			handled_irq |= ADE9000_ST1_ZXIA_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   952  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   953  		case ADE9000_ST1_ZXVB_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   954  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   955  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22   956  							    ADE9000_ST1_ZXVB_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   957  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   958  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   959  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   960  			handled_irq |= ADE9000_ST1_ZXVB_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   961  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   962  		case ADE9000_ST1_ZXTOVB_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   963  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   964  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22   965  							    ADE9000_ST1_ZXTOVB_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   966  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   967  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   968  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   969  			handled_irq |= ADE9000_ST1_ZXTOVB_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   970  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   971  		case ADE9000_ST1_ZXIB_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   972  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   973  				       IIO_UNMOD_EVENT_CODE(IIO_CURRENT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   974  							    ADE9000_ST1_ZXIB_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   975  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   976  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   977  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   978  			handled_irq |= ADE9000_ST1_ZXIB_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   979  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   980  		case ADE9000_ST1_ZXVC_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   981  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   982  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22   983  							    ADE9000_ST1_ZXVC_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   984  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   985  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   986  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   987  			handled_irq |= ADE9000_ST1_ZXVC_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   988  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   989  		case ADE9000_ST1_ZXTOVC_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   990  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22   991  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22   992  							    ADE9000_ST1_ZXTOVC_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22   993  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22   994  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22   995  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22   996  			handled_irq |= ADE9000_ST1_ZXTOVC_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22   997  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22   998  		case ADE9000_ST1_ZXIC_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22   999  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1000  				       IIO_UNMOD_EVENT_CODE(IIO_CURRENT,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1001  							    ADE9000_ST1_ZXIC_BIT,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1002  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1003  							    IIO_EV_DIR_EITHER),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1004  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1005  			handled_irq |= ADE9000_ST1_ZXIC_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1006  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1007  		case ADE9000_ST1_SWELLA_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1008  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22 @1009  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1010  							    ADE9000_ST1_SWELLA_BIT >> 20,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1011  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1012  							    IIO_EV_DIR_RISING),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1013  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1014  			handled_irq |= ADE9000_ST1_SWELLA_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1015  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1016  		case ADE9000_ST1_SWELLB_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1017  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1018  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1019  							    ADE9000_ST1_SWELLB_BIT >> 20,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1020  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1021  							    IIO_EV_DIR_RISING),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1022  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1023  			handled_irq |= ADE9000_ST1_SWELLB_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1024  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1025  		case ADE9000_ST1_SWELLC_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1026  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1027  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1028  							    ADE9000_ST1_SWELLC_BIT >> 20,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1029  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1030  							    IIO_EV_DIR_RISING),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1031  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1032  			handled_irq |= ADE9000_ST1_SWELLC_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1033  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1034  		case ADE9000_ST1_DIPA_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1035  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1036  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1037  							    ADE9000_ST1_DIPA_BIT >> 20,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1038  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1039  							    IIO_EV_DIR_FALLING),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1040  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1041  			handled_irq |= ADE9000_ST1_DIPA_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1042  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1043  		case ADE9000_ST1_DIPB_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1044  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1045  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1046  							    ADE9000_ST1_DIPB_BIT >> 20,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1047  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1048  							    IIO_EV_DIR_FALLING),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1049  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1050  			handled_irq |= ADE9000_ST1_DIPB_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1051  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1052  		case ADE9000_ST1_DIPC_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1053  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1054  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1055  							    ADE9000_ST1_DIPC_BIT >> 20,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1056  							    IIO_EV_TYPE_THRESH,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1057  							    IIO_EV_DIR_FALLING),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1058  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1059  			handled_irq |= ADE9000_ST1_DIPC_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1060  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1061  		case ADE9000_ST1_SEQERR_BIT:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1062  			iio_push_event(indio_dev,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1063  				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1064  							    ADE9000_ST1_SEQERR_BIT >> 12,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1065  							    IIO_EV_TYPE_CHANGE,
b695e630eecec70 Antoniu Miclaus 2025-08-22  1066  							    IIO_EV_DIR_NONE),
b695e630eecec70 Antoniu Miclaus 2025-08-22  1067  				       timestamp);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1068  			handled_irq |= ADE9000_ST1_SEQERR_BIT;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1069  			break;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1070  		default:
b695e630eecec70 Antoniu Miclaus 2025-08-22  1071  			return IRQ_HANDLED;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1072  		}
b695e630eecec70 Antoniu Miclaus 2025-08-22  1073  	}
b695e630eecec70 Antoniu Miclaus 2025-08-22  1074  
b695e630eecec70 Antoniu Miclaus 2025-08-22  1075  	ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, handled_irq);
b695e630eecec70 Antoniu Miclaus 2025-08-22  1076  	if (ret)
b695e630eecec70 Antoniu Miclaus 2025-08-22  1077  		return ret;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1078  
b695e630eecec70 Antoniu Miclaus 2025-08-22  1079  	return IRQ_HANDLED;
b695e630eecec70 Antoniu Miclaus 2025-08-22  1080  }
b695e630eecec70 Antoniu Miclaus 2025-08-22  1081  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#8 lore raw

Re: [PATCH v5 4/6] iio: adc: add ade9000 support

In reply to Antoniu Miclaus
kernel test robot noticed the following build errors:

Hi Antoniu,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v6.17-rc3 next-20250822] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Antoniu-Miclaus/iio-add-IIO_ALTCURRENT-channel-type/20250823-001017
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20250822160157.5092-5-antoniu.miclaus%40analog.com
patch subject: [PATCH v5 4/6] iio: adc: add ade9000 support
config: i386-randconfig-r123-20250824 (https://download.01.org/0day-ci/archive/20250825/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250825/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "devm_clk_register" [drivers/iio/adc/ade9000.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#9 lore raw

Re: [PATCH v5 4/6] iio: adc: add ade9000 support

In reply to Antoniu Miclaus

Hi Antoniu,

This is still not a complete review, though, if going to re-spin, you may consider changing a few minor things.

Quoted 6 lines · Antoniu Miclaus

Add driver support for the ade9000. highly accurate, fully integrated, multiphase energy and power quality monitoring device.

---

...

drivers/iio/adc/ade9000.c line 291

Quoted 8 lines
drivers/iio/adc/ade9000.c new file +8 -0
+#define ADE9000_PHASE_B_POS_BIT		BIT(5)
+#define ADE9000_PHASE_C_POS_BIT		BIT(6)
+
+#define ADE9000_MAX_PHASE_NR		3
+#define AD9000_CHANNELS_PER_PHASE	10
+
+#define ADE9000_ADDR_ADJUST(addr, chan)					\
+	(((chan) == 0 ? 0 : (chan) == 1 ? 2 : 4) << 4 | (addr))

Found it a bit hard to understand the reason why this macro is like that. I wonder if a comment to help understand it but not sure. Also, couldn't come up with any suggestion for an alternative. Guess this device's register layout is just a bit unusual.

Quoted 1 line

+

...

drivers/iio/adc/ade9000.c line 379

Quoted 6 lines
drivers/iio/adc/ade9000.c new file +6 -0
+static int ade9000_filter_type_get(struct iio_dev *indio_dev,
+				   const struct iio_chan_spec *chan)
+{
+	struct ade9000_state *st = iio_priv(indio_dev);
+	u32 val;
+	int ret, i;

nitpicking:
unsigned int i;
?

Quoted 15 lines
drivers/iio/adc/ade9000.c new file +15 -0
+
+	ret = regmap_read(st->regmap, ADE9000_REG_WFB_CFG, &val);
+	if (ret)
+		return ret;
+
+	val = FIELD_GET(ADE9000_WF_SRC_MASK, val);
+
+	for (i = 0; i < ARRAY_SIZE(ade9000_filter_type_values); i++) {
+		if (ade9000_filter_type_values[i] == val)
+			return i;
+	}
+
+	return -EINVAL;
+}
+

...

drivers/iio/adc/ade9000.c line 430

Quoted 11 lines
drivers/iio/adc/ade9000.c new file +11 -0
+static const struct iio_enum ade9000_filter_type_enum = {
+	.items = ade9000_filter_type_items,
+	.num_items = ARRAY_SIZE(ade9000_filter_type_items),
+	.get = ade9000_filter_type_get,
+	.set = ade9000_filter_type_set,
+};
+
+static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
+	IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ade9000_filter_type_enum),
+	IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL, &ade9000_filter_type_enum),
+	{}

nitpicking: these sentinels have been standardized to use a space between the brackets

	{ }

https://lore.kernel.org/linux-iio/20250411-iio-sentinel-normalization-v1-1-d293de3e3d93@baylibre.com/

Quoted 2 lines
(quoted diff) +2 -0
+};
+

...

drivers/iio/adc/ade9000.c line 459

Quoted 9 lines
drivers/iio/adc/ade9000.c new file +9 -0
+
+#define ADE9000_VOLTAGE_CHANNEL(num) {					\
+	.type = IIO_VOLTAGE,						\
+	.channel = num,							\
+	.address = ADE9000_ADDR_ADJUST(ADE9000_REG_AV_PCF, num),	\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
+			      BIT(IIO_CHAN_INFO_SCALE) |		\
+			      BIT(IIO_CHAN_INFO_CALIBSCALE) |		\
+			      BIT(IIO_CHAN_INFO_CALIBSCALE) |		\

duplicated IIO_CHAN_INFO_CALIBSCALE ?

Quoted 14 lines
drivers/iio/adc/ade9000.c new file +14 -0
+			      BIT(IIO_CHAN_INFO_FREQUENCY),		\
+	.event_spec = ade9000_events,					\
+	.num_event_specs = ARRAY_SIZE(ade9000_events),			\
+	.scan_index = num + 1,	/* interleave with current channels */	\
+	.indexed = 1,							\
+	.scan_type = {							\
+		.sign = 's',						\
+		.realbits = 32,						\
+		.storagebits = 32,					\
+		.endianness = IIO_BE,					\
+	},								\
+	.ext_info = ade9000_ext_info,					\
+}
+

...

Quoted 7 lines
drivers/iio/adc/ade9000.c new file +7 -0
+		case ADE9000_ST1_SEQERR_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_SEQERR_BIT >> 12,
+							    IIO_EV_TYPE_CHANGE,
+							    IIO_EV_DIR_NONE),
+				       timestamp);

drivers/iio/adc/ade9000.c line 1077

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+			handled_irq |= ADE9000_ST1_SEQERR_BIT;
+			break;
+		default:
+			return IRQ_HANDLED;
+		}
+	}
+
+	ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, handled_irq);
+	if (ret)
+		return ret;

maybe

	if (ret)
		dev_err(&st->spi->dev, "IRQ1 write status1 fail\n");

	return IRQ_HANDLED;

?
So the IRQ always gets handled.

drivers/iio/adc/ade9000.c line 776

Quoted 4 lines
drivers/iio/adc/ade9000.c new file +4 -0
+
+	return IRQ_HANDLED;
+}
+

Best regards,
Marcelo

maintainer
#10 lore raw

Re: [PATCH v5 4/6] iio: adc: add ade9000 support

In reply to Antoniu Miclaus
Quoted 5 lines · On Fri, 22 Aug 2025 16:01:53 +0000 Antoniu Miclaus…

Add driver support for the ade9000. highly accurate, fully integrated, multiphase energy and power quality monitoring device.

Various comments inline.

Thanks,

Jonathan

drivers/iio/adc/ade9000.c line 135

Quoted 12 lines
drivers/iio/adc/ade9000.c new file +5 -0
new file mode 100644
index 000000000000..41f766e00de0
@@ -0,0 +1,2011 @@
 
+/* Peak and overcurrent detection disabled */
+#define ADE9000_CONFIG3			0x0000
+
+/*
+ * 50Hz operation, 3P4W Wye configuration, signed accumulation

No idea what a 3P4W Wye configuration is...
Spell that out.

drivers/iio/adc/ade9000.c line 329

Quoted 9 lines

+ * Clear bit 8 i.e. ACCMODE=0x00xx for 50Hz operation
+ * ACCMODE=0x0x9x for 3Wire delta when phase B is used as reference
+ */

drivers/iio/adc/ade9000.c new file +4 -0
+
+static const struct iio_event_spec ade9000_events[] = {
+	{
+		/* Energy ready event - datasheet: EGYRDY interrupt */

I'll address these alongside the docs.

Quoted 38 lines
drivers/iio/adc/ade9000.c new file +37 -0
+		.type = IIO_EV_TYPE_MAG,
+		.dir = IIO_EV_DIR_NONE, /* Non-directional event */
+		.mask_shared_by_all = BIT(IIO_EV_INFO_ENABLE),
+	},
+	{
+		/* Sequence error event - datasheet: SEQERR interrupt */
+		.type = IIO_EV_TYPE_CHANGE,
+		.dir = IIO_EV_DIR_NONE, /* Non-directional event */
+		.mask_shared_by_all = BIT(IIO_EV_INFO_ENABLE),
+	},
+	{
+		/* Threshold events - datasheet: zero crossing timeout, sag/swell */
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_NONE, /* Timeout events (ZXTOUT register) */
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE), /* Per-channel enable */
+		.mask_shared_by_all = BIT(IIO_EV_INFO_VALUE), /* Shared threshold value */
+	},
+	{
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_EITHER,
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+	},
+	{
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_RISING, /* for swell */
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+		.mask_shared_by_all = BIT(IIO_EV_INFO_VALUE),
+	},
+	{
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_FALLING, /* for dip */
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+		.mask_shared_by_all = BIT(IIO_EV_INFO_VALUE),
+	},
+};
 
+#define ADE9000_POWER_ACTIVE_CHANNEL(num) {				\
+	.type = IIO_POWER,						\

drivers/iio/adc/ade9000.c

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+	.channel = num,							\
+	.address = ADE9000_ADDR_ADJUST(ADE9000_REG_AWATT, num),		\
+	.channel2 = IIO_MOD_ACTIVE,					\
+	.modified = 1,							\
+	.indexed = 1,							\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
+			      BIT(IIO_CHAN_INFO_SCALE) |		\
+			      BIT(IIO_CHAN_INFO_CALIBBIAS) |		\
+			      BIT(IIO_CHAN_INFO_CALIBSCALE) |		\
+			      BIT(IIO_CHAN_INFO_POWERFACTOR),		\

You have power factor documented as in_power0_powerfactor which is not what this will generate. Check the ABI docs vs what the driver generates closely.

Quoted 16 lines
drivers/iio/adc/ade9000.c new file +13 -0
+	.scan_index = -1						\
+}
 
 
 
+static int ade9000_spi_write_reg(void *context, unsigned int reg,
+				 unsigned int val)
+{
+	struct ade9000_state *st = context;
+	u16 addr;
+	int ret, len;
+
+	guard(mutex)(&st->lock);
+
+	addr = FIELD_PREP(ADE9000_REG_ADDR_MASK, reg);
+	put_unaligned_be16(addr, st->tx);

drivers/iio/adc/ade9000.c line 655

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+
+	if (reg > ADE9000_REG_RUN && reg < ADE9000_REG_VERSION) {
+		put_unaligned_be16(val, &st->tx[2]);
+		len = 4;
+	} else {
+		put_unaligned_be32(val, &st->tx[2]);
+		len = 6;
+	}
+
+	ret = spi_write(st->spi, st->tx, len);

See below. I'd make this spi_write_then_read() and use local variables + a read size of 0.

Quoted 17 lines
drivers/iio/adc/ade9000.c new file +17 -0
+	if (ret)
+		dev_err(&st->spi->dev, "problem when writing register 0x%x\n", reg);
+
+	return ret;
+}
+
+static int ade9000_spi_read_reg(void *context, unsigned int reg,
+				unsigned int *val)
+{
+	struct ade9000_state *st = context;
+	u16 addr;
+	int ret, rx_len;
+
+	guard(mutex)(&st->lock);
+
+	addr = FIELD_PREP(ADE9000_REG_ADDR_MASK, reg) |
+	       ADE9000_REG_READ_BIT_MASK;

drivers/iio/adc/ade9000.c line 682

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+
+	put_unaligned_be16(addr, st->tx);
+
+	/* Skip CRC bytes - only read actual data */
+	if (reg > ADE9000_REG_RUN && reg < ADE9000_REG_VERSION)
+		rx_len = 2;
+	else
+		rx_len = 4;
+
+	ret = spi_write_then_read(st->spi, st->tx, 2, st->rx, rx_len);

Using write then read doesn't need to use a DMA safe buffer (it is documented as always bouncing the data) so you could use variables on the stack to keep the data local for read_reg.
Could also use write_then_read with a zero size read to allow the same in *spi_write_reg()

Quoted 24 lines
drivers/iio/adc/ade9000.c new file +23 -0
+	if (ret) {
+		dev_err(&st->spi->dev, "error reading register 0x%x\n", reg);
+		return ret;
+	}
+
+	if (reg > ADE9000_REG_RUN && reg < ADE9000_REG_VERSION)
+		*val = get_unaligned_be16(st->rx);
+	else
+		*val = get_unaligned_be32(st->rx);
+
+	return 0;
+}
 
+
+static int ade9000_configure_scan(struct iio_dev *indio_dev, u32 wfb_addr)
+{
+	struct ade9000_state *st = iio_priv(indio_dev);
+	u16 addr;
+
+	addr = FIELD_PREP(ADE9000_REG_ADDR_MASK, wfb_addr) |
+	       ADE9000_REG_READ_BIT_MASK;
+
+	put_unaligned_be16(addr, st->tx_buff);
+

drivers/iio/adc/ade9000.c line 729

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+	st->xfer[0].tx_buf = &st->tx_buff[0];
+	st->xfer[0].len = 2;
+
+	st->xfer[1].rx_buf = st->rx_buff.byte;
+
+	/* Always use streaming mode */
+	st->xfer[1].len = (st->wfb_nr_samples / 2) * 4;
+
+	spi_message_init_with_transfers(&st->spi_msg, st->xfer, ARRAY_SIZE(st->xfer));
+	return 0;

Never fails, return type of void to make that clear.

drivers/iio/adc/ade9000.c line 886

Quoted 12 lines
drivers/iio/adc/ade9000.c new file +9 -0
+}
 
 
 
+static irqreturn_t ade9000_irq1_thread(int irq, void *data)
+{
+	struct iio_dev *indio_dev = data;
+	struct ade9000_state *st = iio_priv(indio_dev);
+	unsigned int bit = ADE9000_ST1_CROSSING_FIRST;
+	s64 timestamp = iio_get_time_ns(indio_dev);
+	u32 handled_irq = 0;
+	u32 interrupts;
	u32 interrupts, result, status, tmp;

drivers/iio/adc/ade9000.c line 897

Quoted 11 lines
drivers/iio/adc/ade9000.c new file +11 -0
+	u32 result;
+	u32 status;
+	u32 tmp;
+	unsigned long interrupt_bits;
+	int ret;
+
+	if (!completion_done(&st->reset_completion)) {
+		ret = regmap_read(st->regmap, ADE9000_REG_STATUS1, &result);
+		if (ret) {
+			dev_err(&st->spi->dev, "IRQ1 read status fail\n");
+			return ret;

Don't return errno in an irq thread handler. They aren't irqreturn_t

Quoted 19 lines
drivers/iio/adc/ade9000.c new file +19 -0
+		}
+
+		if (result & ADE9000_ST1_RSTDONE_BIT)
+			complete(&st->reset_completion);
+		else
+			dev_err(&st->spi->dev, "Error testing reset done\n");
+
+		return IRQ_HANDLED;
+	}
+
+	ret = regmap_read(st->regmap, ADE9000_REG_STATUS1, &status);
+	if (ret) {
+		dev_err(&st->spi->dev, "IRQ1 read status fail\n");
+		return IRQ_HANDLED;
+	}
+
+	ret = regmap_read(st->regmap, ADE9000_REG_MASK1, &interrupts);
+	if (ret) {
+		dev_err(&st->spi->dev, "IRQ1 read status fail\n");

drivers/iio/adc/ade9000.c line 926

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+		return IRQ_HANDLED;
+	}
+
+	interrupt_bits = interrupts;
+	for_each_set_bit_from(bit, &interrupt_bits,
+			      ADE9000_ST1_CROSSING_DEPTH){
+		tmp = status & BIT(bit);
+
+		switch (tmp) {
+		case ADE9000_ST1_ZXVA_BIT:

There are a lot of these, maybe a lookup table with event code and field in handled_irq? Use a marker like no event code to indicate the bits we don't handle.

drivers/iio/adc/ade9000.c line 933

Quoted 7 lines
drivers/iio/adc/ade9000.c new file +7 -0
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_ZXVA_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXVA_BIT;

These are all the same as handled_irq |= tmp; ?
maybe can take that out of the switch statement?

If you do a lookup table on bit, that will end up even nicer.

Quoted 172 lines
drivers/iio/adc/ade9000.c new file +171 -0
+			break;
+		case ADE9000_ST1_ZXTOVA_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_ZXTOVA_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXTOVA_BIT;
+			break;
+		case ADE9000_ST1_ZXIA_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_CURRENT,
+							    ADE9000_ST1_ZXIA_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXIA_BIT;
+			break;
+		case ADE9000_ST1_ZXVB_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_ZXVB_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXVB_BIT;
+			break;
+		case ADE9000_ST1_ZXTOVB_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_ZXTOVB_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXTOVB_BIT;
+			break;
+		case ADE9000_ST1_ZXIB_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_CURRENT,
+							    ADE9000_ST1_ZXIB_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXIB_BIT;
+			break;
+		case ADE9000_ST1_ZXVC_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_ZXVC_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXVC_BIT;
+			break;
+		case ADE9000_ST1_ZXTOVC_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_ZXTOVC_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXTOVC_BIT;
+			break;
+		case ADE9000_ST1_ZXIC_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_CURRENT,
+							    ADE9000_ST1_ZXIC_BIT,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_EITHER),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_ZXIC_BIT;
+			break;
+		case ADE9000_ST1_SWELLA_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_SWELLA_BIT >> 20,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_RISING),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_SWELLA_BIT;
+			break;
+		case ADE9000_ST1_SWELLB_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_SWELLB_BIT >> 20,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_RISING),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_SWELLB_BIT;
+			break;
+		case ADE9000_ST1_SWELLC_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_SWELLC_BIT >> 20,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_RISING),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_SWELLC_BIT;
+			break;
+		case ADE9000_ST1_DIPA_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_DIPA_BIT >> 20,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_FALLING),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_DIPA_BIT;
+			break;
+		case ADE9000_ST1_DIPB_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_DIPB_BIT >> 20,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_FALLING),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_DIPB_BIT;
+			break;
+		case ADE9000_ST1_DIPC_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_DIPC_BIT >> 20,
+							    IIO_EV_TYPE_THRESH,
+							    IIO_EV_DIR_FALLING),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_DIPC_BIT;
+			break;
+		case ADE9000_ST1_SEQERR_BIT:
+			iio_push_event(indio_dev,
+				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
+							    ADE9000_ST1_SEQERR_BIT >> 12,
+							    IIO_EV_TYPE_CHANGE,
+							    IIO_EV_DIR_NONE),
+				       timestamp);
+			handled_irq |= ADE9000_ST1_SEQERR_BIT;
+			break;
+		default:
+			return IRQ_HANDLED;
+		}
+	}
+
+	ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, handled_irq);
+	if (ret)
+		return ret;
+
+	return IRQ_HANDLED;
+}
 
+
+static int ade9000_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val,
+			    int *val2,
+			    long mask)
+{
+	struct ade9000_state *st = iio_priv(indio_dev);
+	unsigned int reg, measured;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_FREQUENCY:
+		if (chan->type == IIO_VOLTAGE) {
+			int period_reg;
+			int period;
+
+			switch (chan->channel) {
+			case ADE9000_PHASE_A_NR:
+				period_reg = ADE9000_REG_APERIOD;
+				break;
+			case ADE9000_PHASE_B_NR:
+				period_reg = ADE9000_REG_BPERIOD;
+				break;

drivers/iio/adc/ade9000.c line 1127

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+			case ADE9000_PHASE_C_NR:
+				period_reg = ADE9000_REG_CPERIOD;
+				break;
+			default:
+				return -EINVAL;
+			}
+			ret = regmap_read(st->regmap, period_reg, &period);
+			if (ret)
+				return ret;
+			*val = 4000 * 65536;

Why this particular multiplier? Maybe a spec reference.

Quoted 50 lines
drivers/iio/adc/ade9000.c new file +50 -0
+			*val2 = period + 1;
+			return IIO_VAL_FRACTIONAL;
+		}
+
+		ret = regmap_read(st->regmap, ADE9000_REG_ACCMODE, &reg);
+		if (ret)
+			return ret;
+		*val = (reg & ADE9000_ACCMODE_60HZ) ? 60 : 50;
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_RAW:
+		if (chan->type == IIO_ENERGY) {
+			u16 lo_reg = chan->address;
+
+			ret = regmap_bulk_read(st->regmap, lo_reg,
+					       st->bulk_read_buf, 2);
+			if (ret)
+				return ret;
+
+			*val = st->bulk_read_buf[0];  /* Lower 32 bits */
+			*val2 = st->bulk_read_buf[1]; /* Upper 32 bits */
+			return IIO_VAL_INT_64;
+		}
+
+		ret = iio_device_claim_direct(indio_dev);
+		if (ret)
+			return ret;
+
+		ret = regmap_read(st->regmap, chan->address, &measured);
+		iio_device_release_direct(indio_dev);
+		if (ret)
+			return ret;
+
+		*val = measured;
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_POWERFACTOR:
+		ret = iio_device_claim_direct(indio_dev);
+		if (ret)
+			return ret;
+
+		/* Map power channel to corresponding power factor register */
+		reg = ADE9000_ADDR_ADJUST(ADE9000_REG_APF, chan->channel);
+		ret = regmap_read(st->regmap, reg, &measured);
+		iio_device_release_direct(indio_dev);
+		if (ret)
+			return ret;
+
+		*val = measured;
+

drivers/iio/adc/ade9000.c line 1187

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		if (chan->info_mask_shared_by_all) {
+			/* Shared PGA gain read - only for channel with shared frequency */
+			ret = regmap_read(st->regmap, ADE9000_REG_PGA_GAIN, &reg);
+			if (ret)
+				return ret;
+			*val = min(1 << ((reg >> (8 + chan->channel)) & GENMASK(1, 0)), 4);
+			return IIO_VAL_INT;

return, so no need for else to follow.

same for later else ifs

Quoted 36 lines
drivers/iio/adc/ade9000.c new file +36 -0
+		} else if (chan->type == IIO_CURRENT || chan->type == IIO_VOLTAGE ||
+			   chan->type == IIO_ALTVOLTAGE) {
+			switch (chan->address) {
+			case ADE9000_REG_AI_PCF:
+			case ADE9000_REG_AV_PCF:
+			case ADE9000_REG_BI_PCF:
+			case ADE9000_REG_BV_PCF:
+			case ADE9000_REG_CI_PCF:
+			case ADE9000_REG_CV_PCF:
+				*val = 1;
+				*val2 = ADE9000_PCF_FULL_SCALE_CODES;
+				return IIO_VAL_FRACTIONAL;
+			case ADE9000_REG_AIRMS:
+			case ADE9000_REG_AVRMS:
+			case ADE9000_REG_BIRMS:
+			case ADE9000_REG_BVRMS:
+			case ADE9000_REG_CIRMS:
+			case ADE9000_REG_CVRMS:
+				*val = 1;
+				*val2 = ADE9000_RMS_FULL_SCALE_CODES;
+				return IIO_VAL_FRACTIONAL;
+			default:
+				return -EINVAL;
+			}
+		} else if (chan->type == IIO_POWER) {
+			*val = 1;
+			*val2 = ADE9000_WATT_FULL_SCALE_CODES;
+			return IIO_VAL_FRACTIONAL;
+		} else {
+			return -EINVAL;
+		}
+		break;
+	default:
+		return -EINVAL;
+	}
+}

drivers/iio/adc/ade9000.c line 1233

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+
+static int ade9000_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int val,
+			     int val2,
+			     long mask)
+{
+	struct ade9000_state *st = iio_priv(indio_dev);
+	u32 addr;
+	u32 tmp;	
	u32 addr, tmp;

saves us a line for no lost of readability.

Quoted 15 lines
drivers/iio/adc/ade9000.c new file +13 -0
+
+	switch (mask) {
+	case IIO_CHAN_INFO_FREQUENCY:
 
+}
 
+static int ade9000_read_event_config(struct iio_dev *indio_dev,
+				     const struct iio_chan_spec *chan,
+				     enum iio_event_type type,
+				     enum iio_event_direction dir)
+{
+	struct ade9000_state *st = iio_priv(indio_dev);
+	u32 interrupts0, interrupts1, number;
+	int ret;
+

drivers/iio/adc/ade9000.c line 1368

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+	ret = regmap_read(st->regmap, ADE9000_REG_MASK0, &interrupts0);
+	if (ret)
+		return ret;
+
+	ret = regmap_read(st->regmap, ADE9000_REG_MASK1, &interrupts1);
+	if (ret)
+		return ret;
+
+	if (type == IIO_EV_TYPE_MAG)
+		return interrupts0 & ADE9000_ST0_EGYRDY;

Might as well do that before reading interrupts1. Save a bit of bus traffic without complicating the code. Even better, only read interrupts0 at all if type == IIO_EV_TYPE_MAG.

Quoted 64 lines
drivers/iio/adc/ade9000.c new file +64 -0
+
+	if (type == IIO_EV_TYPE_CHANGE)
+		return interrupts1 & ADE9000_ST1_SEQERR_BIT;
+
+	number = chan->channel;
+
+	switch (number) {
+	case ADE9000_PHASE_A_NR:
+		if (chan->type == IIO_VOLTAGE) {
+			if (dir == IIO_EV_DIR_EITHER)
+				return interrupts1 & ADE9000_ST1_ZXVA_BIT;
+			if (dir == IIO_EV_DIR_NONE)
+				return interrupts1 & ADE9000_ST1_ZXTOVA_BIT;
+			if (dir == IIO_EV_DIR_RISING)
+				return interrupts1 & ADE9000_ST1_SWELLA_BIT;
+			if (dir == IIO_EV_DIR_FALLING)
+				return interrupts1 & ADE9000_ST1_DIPA_BIT;
+		} else if (chan->type == IIO_CURRENT) {
+			return interrupts1 & ADE9000_ST1_ZXIA_BIT;
+		}
+		break;
+	case ADE9000_PHASE_B_NR:
+		if (chan->type == IIO_VOLTAGE) {
+			if (dir == IIO_EV_DIR_EITHER)
+				return interrupts1 & ADE9000_ST1_ZXVB_BIT;
+			if (dir == IIO_EV_DIR_NONE)
+				return interrupts1 & ADE9000_ST1_ZXTOVB_BIT;
+			if (dir == IIO_EV_DIR_RISING)
+				return interrupts1 & ADE9000_ST1_SWELLB_BIT;
+			if (dir == IIO_EV_DIR_FALLING)
+				return interrupts1 & ADE9000_ST1_DIPB_BIT;
+		} else if (chan->type == IIO_CURRENT) {
+			return interrupts1 & ADE9000_ST1_ZXIB_BIT;
+		}
+		break;
+	case ADE9000_PHASE_C_NR:
+		if (chan->type == IIO_VOLTAGE) {
+			if (dir == IIO_EV_DIR_EITHER)
+				return interrupts1 & ADE9000_ST1_ZXVC_BIT;
+			if (dir == IIO_EV_DIR_NONE)
+				return interrupts1 & ADE9000_ST1_ZXTOVC_BIT;
+			if (dir == IIO_EV_DIR_RISING)
+				return interrupts1 & ADE9000_ST1_SWELLC_BIT;
+			if (dir == IIO_EV_DIR_FALLING)
+				return interrupts1 & ADE9000_ST1_DIPC_BIT;
+		} else if (chan->type == IIO_CURRENT) {
+			return interrupts1 & ADE9000_ST1_ZXIC_BIT;
+		}
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int ade9000_write_event_config(struct iio_dev *indio_dev,
+				      const struct iio_chan_spec *chan,
+				      enum iio_event_type type,
+				      enum iio_event_direction dir,
+				      bool state)
+{
+	struct ade9000_state *st = iio_priv(indio_dev);
+	u32 interrupts, tmp;

drivers/iio/adc/ade9000.c line 1442

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+	int ret;
+
+	/* Clear all pending events in STATUS1 register (write 1 to clear) */
+	ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, GENMASK(31, 0));
+	if (ret)
+		return ret;
+
+	if (type == IIO_EV_TYPE_MAG) {
+		ret = regmap_update_bits(st->regmap, ADE9000_REG_STATUS0,
+					 ADE9000_ST0_EGYRDY, ADE9000_ST0_EGYRDY);

regmap_set_bits() exists for this case.

drivers/iio/adc/ade9000.c line 1446

Quoted 4 lines
drivers/iio/adc/ade9000.c new file +4 -0
+		if (ret)
+			return ret;
+		return regmap_update_bits(st->regmap, ADE9000_REG_MASK0,
+					 ADE9000_ST0_EGYRDY,

MASK and field don't seem to match even wrt to which register they are in.

Having fixed that regmap_assign_bits() probably useufl here.

drivers/iio/adc/ade9000.c line 1453

Quoted 7 lines
drivers/iio/adc/ade9000.c new file +7 -0
+					 state ? ADE9000_ST1_SEQERR_BIT : 0);
+	}
+
+	if (type == IIO_EV_TYPE_CHANGE)
+		return regmap_update_bits(st->regmap, ADE9000_REG_MASK1,
+					 ADE9000_ST1_SEQERR_BIT,
+					 state ? ADE9000_ST1_SEQERR_BIT : 0);
		return regmap_assign_bits(st->regmap, ADE9000_REG_MASK1,
					  ADE9000_ST1_SEQERR_BIT, state);

is a little simpler and avoids chance of register / field mismatch like above.

Quoted 92 lines
drivers/iio/adc/ade9000.c new file +92 -0
+
+	if (dir == IIO_EV_DIR_EITHER) {
+		static const struct {
+			u32 irq;
+			u32 wfb_trg;
+		} trig_arr[6] = {
+			{
+				.irq = ADE9000_ST1_ZXVA_BIT,
+				.wfb_trg = ADE9000_WFB_TRG_ZXVA_BIT
+			}, {
+				.irq = ADE9000_ST1_ZXIA_BIT,
+				.wfb_trg = ADE9000_WFB_TRG_ZXIA_BIT
+			}, {
+				.irq = ADE9000_ST1_ZXVB_BIT,
+				.wfb_trg = ADE9000_WFB_TRG_ZXVB_BIT
+			}, {
+				.irq = ADE9000_ST1_ZXIB_BIT,
+				.wfb_trg = ADE9000_WFB_TRG_ZXIB_BIT
+			}, {
+				.irq = ADE9000_ST1_ZXVC_BIT,
+				.wfb_trg = ADE9000_WFB_TRG_ZXVC_BIT
+			}, {
+				.irq = ADE9000_ST1_ZXIC_BIT,
+				.wfb_trg = ADE9000_WFB_TRG_ZXIC_BIT
+			},
+		};
+		if (state) {
+			interrupts |= trig_arr[chan->channel * 2 + chan->type].irq;
+			st->wfb_trg |= trig_arr[chan->channel * 2 + chan->type].wfb_trg;
+		} else {
+			interrupts &= ~trig_arr[chan->channel * 2 + chan->type].irq;
+			st->wfb_trg &= ~trig_arr[chan->channel * 2 + chan->type].wfb_trg;
+		}
+	}
+
+	if (dir == IIO_EV_DIR_NONE) {
+		switch (chan->channel) {
+		case ADE9000_PHASE_A_NR:
+			tmp |= ADE9000_ST1_ZXTOVA_BIT;
+			break;
+		case ADE9000_PHASE_B_NR:
+			tmp |= ADE9000_ST1_ZXTOVB_BIT;
+			break;
+		case ADE9000_PHASE_C_NR:
+			tmp |= ADE9000_ST1_ZXTOVC_BIT;
+			break;
+		default:
+			break;
+		}
+
+		if (state)
+			interrupts |= tmp;
+		else
+			interrupts &= ~tmp;
+	} else if (dir == IIO_EV_DIR_RISING) {
+		switch (chan->channel) {
+		case ADE9000_PHASE_A_NR:
+			tmp |= ADE9000_ST1_SWELLA_BIT;
+			break;
+		case ADE9000_PHASE_B_NR:
+			tmp |= ADE9000_ST1_SWELLB_BIT;
+			break;
+		case ADE9000_PHASE_C_NR:
+			tmp |= ADE9000_ST1_SWELLC_BIT;
+			break;
+		default:
+			break;
+		}
+
+		if (state) {
+			interrupts |= tmp;
+			st->wfb_trg |= ADE9000_WFB_TRG_SWELL_BIT;
+		} else {
+			interrupts &= ~tmp;
+			st->wfb_trg &= ~ADE9000_WFB_TRG_SWELL_BIT;
+		}
+	} else if (dir == IIO_EV_DIR_FALLING) {
+		switch (chan->channel) {
+		case ADE9000_PHASE_A_NR:
+			tmp |= ADE9000_ST1_DIPA_BIT;
+			break;
+		case ADE9000_PHASE_B_NR:
+			tmp |= ADE9000_ST1_DIPB_BIT;
+			break;
+		case ADE9000_PHASE_C_NR:
+			tmp |= ADE9000_ST1_DIPC_BIT;
+			break;
+		default:
+			break;
+		}
+
+		if (state) {

drivers/iio/adc/ade9000.c line 1555

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+			interrupts |= tmp;
+			st->wfb_trg |= ADE9000_WFB_TRG_DIP_BIT;
+		} else {
+			interrupts &= ~tmp;
+			st->wfb_trg &= ~ADE9000_WFB_TRG_DIP_BIT;
+		}
+	}
+
+	return regmap_update_bits(st->regmap, ADE9000_REG_MASK1, interrupts,
+				  interrupts);

return regmap_set_bits()

check the rest of the driver for places where these clear/set/assign regmap functions can simplifiy things.

Quoted 14 lines
drivers/iio/adc/ade9000.c new file +12 -0
+}
 
 
+static int ade9000_reset(struct ade9000_state *st)
+{
+	struct device *dev = &st->spi->dev;
+	struct gpio_desc *gpio_reset;
+	int ret;
+
+	gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpio_reset))
+		return PTR_ERR(gpio_reset);
+
+	if (gpio_reset) {

drivers/iio/adc/ade9000.c line 1786

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+		fsleep(10);
+		gpiod_set_value_cansleep(gpio_reset, 0);
+		fsleep(50000);
+	} else {
+		ret = regmap_update_bits(st->regmap, ADE9000_REG_CONFIG1,
+					 ADE9000_SWRST_BIT, ADE9000_SWRST_BIT);
+		if (ret)
+			return ret;
+		fsleep(90);
+		return 0;

This code structure is more complex than it needs to be. There is no sharing of the code that follows between the if / else so either drag that into the if (gpio_reset) branch and return early or flip the logic and do the if (!gpio_reset) first allowing the fsleep(10) gpio_set_value_cansleep() etc to be indented less. That is

	if (gpio_reset) {
		fsleep(10);
		gpiod_set_value_cansleep(gpio_reset, 0);
		fsleep(50000);
		if (!wait_for_completion_timeout(&st->reset_completion,
						 msecs_to_jiffies(1000))) {
			dev_err(dev, "Reset timeout after 1s\n");
			return -ETIMEDOUT;
		}

		return 0;
	}

	ret = regmap_update_bits(st->regmap, ADE9000_REG_CONFIG1,
				 ADE9000_SWRST_BIT, ADE9000_SWRST_BIT);
	if (ret)
		return ret;
	fsleep(90);

	return 0;

Or the other way around.

Quoted 10 lines
drivers/iio/adc/ade9000.c new file +10 -0
+	}
+
+	if (!wait_for_completion_timeout(&st->reset_completion,
+					 msecs_to_jiffies(1000))) {
+		dev_err(dev, "Reset timeout after 1s\n");
+		return -ETIMEDOUT;
+	}
+
+	return 0;
+}
author maintainer
#11 lore raw

PATCH v5 5/6 docs: iio: add documentation for ade9000 driver

In reply to Antoniu Miclaus

Add documentation for ade9000 driver which describes the driver device files and shows how the user may use the ABI for various scenarios (configuration, measurement, etc.).

---
 Documentation/iio/ade9000.rst | 286 ++++++++++++++++++++++++++++++++++
 Documentation/iio/index.rst   |   1 +
 2 files changed, 287 insertions(+)
 create mode 100644 Documentation/iio/ade9000.rst
Documentation/iio/ade9000.rst new file +286 -0
new file mode 100644
index 000000000000..fcb4a36c0282
@@ -0,0 +1,286 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===============
+ADE9000 driver
+===============
+
+This driver supports Analog Device's ADE9000 energy measurement IC on SPI bus.
+
+1. Supported devices
+====================
+
+* `ADE9000 <https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf>`_
+
+The ADE9000 is a highly accurate, fully integrated, multiphase energy and power
+quality monitoring device. Superior analog performance and a digital signal
+processing (DSP) core enable accurate energy monitoring over a wide dynamic
+range. An integrated high end reference ensures low drift over temperature
+with a combined drift of less than ±25 ppm/°C maximum for the entire channel
+including a programmable gain amplifier (PGA) and an analog-to-digital
+converter (ADC).
+
+2. Device attributes
+====================
+
+Power and energy measurements are provided for voltage, current, active power,
+reactive power, apparent power, and power factor across three phases.
+
+Each IIO device has a device folder under ``/sys/bus/iio/devices/iio:deviceX``,
+where X is the IIO index of the device. Under these folders reside a set of
+device files, depending on the characteristics and features of the hardware
+device in question. These files are consistently generalized and documented in
+the IIO ABI documentation.
+
+The following tables show the ADE9000 related device files, found in the
+specific device folder path ``/sys/bus/iio/devices/iio:deviceX``.
+
++---------------------------------------------------+----------------------------------------------------------+
+| Current measurement related device files          | Description                                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_raw                               | Raw current measurement for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_scale                             | Scale for current channels.                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_calibscale                        | Calibration gain for current channels (AIGAIN reg).      |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_offset                            | Offset correction for current channels (IRMSOS reg).     |
++---------------------------------------------------+----------------------------------------------------------+
+| in_altcurrent[0-2]_rms_raw                        | RMS current measurement for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+
++---------------------------------------------------+----------------------------------------------------------+
+| Voltage measurement related device files          | Description                                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_raw                               | Raw voltage measurement for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_scale                             | Scale for voltage channels.                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_calibscale                        | Calibration gain for voltage channels (AVGAIN reg).      |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_offset                            | Offset correction for voltage channels (VRMSOS reg).     |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_frequency                         | Measured line frequency for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_altvoltage[0-2]_rms_raw                        | RMS voltage measurement for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+
++---------------------------------------------------+----------------------------------------------------------+
+| Power measurement related device files            | Description                                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_raw                                 | Raw active power measurement for phases A, B, C.         |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_active_raw                          | Active power measurement for phases A, B, C.             |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_reactive_raw                        | Reactive power measurement for phases A, B, C.           |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_apparent_raw                        | Apparent power measurement for phases A, B, C.           |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_powerfactor                         | Power factor for phases A, B, C.                         |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_scale                               | Scale for power channels.                                |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_calibscale                          | Calibration gain for power channels (APGAIN reg).        |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_calibbias                           | Calibration offset for power channels (xWATTOS regs).    |
++---------------------------------------------------+----------------------------------------------------------+
+
++---------------------------------------------------+----------------------------------------------------------+
+| Energy measurement related device files           | Description                                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_energy[0-2]_raw                                | Raw energy measurement for phases A, B, C.               |
++---------------------------------------------------+----------------------------------------------------------+
+| in_energy[0-2]_scale                              | Scale for energy channels.                               |
++---------------------------------------------------+----------------------------------------------------------+
+
++------------------------------+------------------------------------------------------------------+
+| Shared device attributes     | Description                                                      |
++------------------------------+------------------------------------------------------------------+
+| name                         | Name of the IIO device.                                          |
++------------------------------+------------------------------------------------------------------+
+| frequency                    | System line frequency configuration (50Hz/60Hz).                |
++------------------------------+------------------------------------------------------------------+
+| scale                        | Shared PGA gain setting (1x, 2x, 4x) affecting all channels.   |
++------------------------------+------------------------------------------------------------------+
+
+3. Calibration and scaling
+===========================
+
+The ADE9000 provides multiple levels of gain and offset correction:
+
+**PGA Gain (shared)**
+  The programmable gain amplifier affects the analog input stage for all channels.
+  Controlled via the shared ``scale`` attribute with values 1, 2, or 4.
+
+**Calibration Gain (per-channel)**
+  Fine-tuning calibration gains applied in the digital domain for each channel type.
+  Controlled via ``calibscale`` attributes (AIGAIN, AVGAIN, APGAIN registers).
+
+**Calibration Offset (per-channel)**
+  Hardware calibration offsets applied by the device for power measurements.
+  Controlled via ``calibbias`` attributes for power channels.
+
+**Correction Offsets (per-channel)**
+  RMS offset corrections for current and voltage measurements.
+  Controlled via ``offset`` attributes (IRMSOS, VRMSOS registers).
+
+4. Event attributes
+===================
+
+The ADE9000 provides various interrupts that are mapped to IIO events.
+Event functionality is only available if the corresponding interrupts are
+connected in the device tree.
+
++---------------------------------------------------+----------------------------------------------------------+
+| IIO Event Attribute                               | ADE9000 Datasheet Equivalent                             |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_either_en                      | Zero crossing detection interrupt (ZXVA)                 |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_rising_en                      | Swell detection interrupt (SWELLA)                       |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_falling_en                     | Sag/dip detection interrupt (DIPA)                       |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_none_en                        | Zero crossing timeout interrupt (ZXTOVA)                 |
++---------------------------------------------------+----------------------------------------------------------+
+| events_mag_none_en                                | Energy ready interrupt (EGYRDY)                          |
++---------------------------------------------------+----------------------------------------------------------+
+| events_change_none_en                             | Sequence error interrupt (SEQERR)                        |
++---------------------------------------------------+----------------------------------------------------------+
+| events_thresh_none_value                          | Zero crossing timeout threshold (ZXTOUT register)        |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_falling_value                  | Sag/dip threshold (DIP_LVL register)                     |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_rising_value                   | Swell threshold (SWELL_LVL register)                     |
++---------------------------------------------------+----------------------------------------------------------+
+
+Event directions:
+- ``rising``: Upper threshold crossing (swell detection)
+- ``falling``: Lower threshold crossing (sag/dip detection)
+- ``either``: Any threshold crossing (zero crossing detection)
+- ``none``: Timeout or non-directional events
+
+**Note**: Event attributes are only available if the corresponding interrupts
+(irq0, irq1, dready) are specified in the device tree. The driver works without
+interrupts but with reduced functionality.
+
+5. Device buffers
+=================
+
+This driver supports IIO buffers for waveform capture. Buffer functionality
+requires the dready interrupt to be connected.
+
+The device supports capturing voltage and current waveforms for power quality
+analysis. The waveform buffer can be configured to capture data from different
+channel combinations.
+
+Supported channel combinations for buffered capture:
+- Phase A: voltage and current (IA + VA)
+- Phase B: voltage and current (IB + VB)
+- Phase C: voltage and current (IC + VC)
+- All phases: all voltage and current channels
+- Individual channels: IA, VA, IB, VB, IC, VC
+
+Usage examples
+--------------
+
+Enable waveform capture for Phase A:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_current0_en
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_voltage0_en
+
+Set buffer length and enable:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> echo 100 > buffer/length
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > buffer/enable
+
+6. Clock output
+===============
+
+The ADE9000 can provide a clock output via the CLKOUT pin when using an external
+crystal/clock source. This feature is enabled by specifying ``#clock-cells = <0>``
+in the device tree. The output clock will be registered as "clkout" and can be
+referenced by other devices.
+
+7. Usage examples
+=================
+
+Show device name:
+
+.. code-block:: bash
+
+	root:/sys/bus/iio/devices/iio:device0> cat name
+        ade9000
+
+Read voltage measurements:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_raw
+        12345
+        root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_scale
+        0.000030517
+
+- Phase A voltage = in_voltage0_raw * in_voltage0_scale = 0.3769 V
+
+Read power measurements:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> cat in_power0_active_raw
+        5678
+        root:/sys/bus/iio/devices/iio:device0> cat in_power0_scale
+        0.000244140
+
+- Phase A active power = in_power0_active_raw * in_power0_scale = 1.386 W
+
+Configure PGA gain (affects all channels):
+
+.. code-block:: bash
+
+        # Set PGA gain to 2x
+        root:/sys/bus/iio/devices/iio:device0> echo 2 > scale
+        # Read current gain setting
+        root:/sys/bus/iio/devices/iio:device0> cat scale
+        2
+
+Configure line frequency:
+
+.. code-block:: bash
+
+        # Set to 60Hz operation
+        root:/sys/bus/iio/devices/iio:device0> echo 60 > frequency
+        # Read current frequency setting
+        root:/sys/bus/iio/devices/iio:device0> cat frequency
+        60
+
+Configure calibration gains:
+
+.. code-block:: bash
+
+        # Set current channel 0 calibration gain
+        root:/sys/bus/iio/devices/iio:device0> echo 0x800000 > in_current0_calibscale
+        # Set voltage channel 0 calibration gain
+        root:/sys/bus/iio/devices/iio:device0> echo 0x7FFFFF > in_voltage0_calibscale
+
+Configure voltage event thresholds (requires interrupts):
+
+.. code-block:: bash
+
+        # Set sag detection threshold
+        root:/sys/bus/iio/devices/iio:device0> echo 180000 > events/in_voltage0_thresh_falling_value
+        # Enable sag detection
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_voltage0_thresh_falling_en
+
+        # Set swell detection threshold
+        root:/sys/bus/iio/devices/iio:device0> echo 260000 > events/in_voltage0_thresh_rising_value
+        # Enable swell detection
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_voltage0_thresh_rising_en
+
+8. IIO Interfacing Tools
+========================
+
+See ``Documentation/iio/iio_tools.rst`` for the description of the available IIO
+interfacing tools.
\ No newline at end of file
Documentation/iio/index.rst +1 -0
index c106402a91f7..792c815286f4 100644
@@ -28,6 +28,7 @@ Industrial I/O Kernel Drivers
    ad7606
    ad7625
    ad7944
+   ade9000
    adis16475
    adis16480
    adis16550
Signature · 1 line
2.43.0
maintainer
#12 lore raw

Re: [PATCH v5 5/6] docs: iio: add documentation for ade9000 driver

Quoted 53 lines · On Fri, 22 Aug 2025 16:01:54 +0000 Antoniu Miclaus…

Add documentation for ade9000 driver which describes the driver device files and shows how the user may use the ABI for various scenarios (configuration, measurement, etc.).

---
 Documentation/iio/ade9000.rst | 286 ++++++++++++++++++++++++++++++++++
 Documentation/iio/index.rst   |   1 +
 2 files changed, 287 insertions(+)
 create mode 100644 Documentation/iio/ade9000.rst
Documentation/iio/ade9000.rst new file +36 -0
new file mode 100644
index 000000000000..fcb4a36c0282
@@ -0,0 +1,286 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===============
+ADE9000 driver
+===============
+
+This driver supports Analog Device's ADE9000 energy measurement IC on SPI bus.
+
+1. Supported devices
+====================
+
+* `ADE9000 <https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf>`_
+
+The ADE9000 is a highly accurate, fully integrated, multiphase energy and power
+quality monitoring device. Superior analog performance and a digital signal
+processing (DSP) core enable accurate energy monitoring over a wide dynamic
+range. An integrated high end reference ensures low drift over temperature
+with a combined drift of less than ±25 ppm/°C maximum for the entire channel
+including a programmable gain amplifier (PGA) and an analog-to-digital
+converter (ADC).
+
+2. Device attributes
+====================
+
+Power and energy measurements are provided for voltage, current, active power,
+reactive power, apparent power, and power factor across three phases.
+
+Each IIO device has a device folder under ``/sys/bus/iio/devices/iio:deviceX``,
+where X is the IIO index of the device. Under these folders reside a set of
+device files, depending on the characteristics and features of the hardware
+device in question. These files are consistently generalized and documented in
+the IIO ABI documentation.
+
+The following tables show the ADE9000 related device files, found in the
+specific device folder path ``/sys/bus/iio/devices/iio:deviceX``.
+

Documentation/iio/ade9000.rst line 46

Quoted 10 lines
Documentation/iio/ade9000.rst new file +10 -0
++---------------------------------------------------+----------------------------------------------------------+
+| Current measurement related device files          | Description                                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_raw                               | Raw current measurement for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_scale                             | Scale for current channels.                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_calibscale                        | Calibration gain for current channels (AIGAIN reg).      |
++---------------------------------------------------+----------------------------------------------------------+
+| in_current[0-2]_offset                            | Offset correction for current channels (IRMSOS reg).     |

So this is not an offset of the _raw reading above. I.e. userspace should do (_raw + _offset) * _scale I think? Even for the RMS calc there is a 2^15 multiplier involved.

So think this one needs a rethink. Definitely a calibbias not an offset as it's not something for userspace to apply but rather a calibration tweak. Possibly something new is needed to indicate this only affects the RMS calculation. I'm open to suggestions on how to do that.

Documentation/iio/ade9000.rst line 48

Quoted 2 lines
Documentation/iio/ade9000.rst new file +2 -0
++---------------------------------------------------+----------------------------------------------------------+
+| in_altcurrent[0-2]_rms_raw                        | RMS current measurement for phases A, B, C.              |

Add something kernel on the calc, particularly the influence of what you currently have as offset above. That is not obvious.

Documentation/iio/ade9000.rst line 60

Quoted 12 lines
Documentation/iio/ade9000.rst new file +12 -0
++---------------------------------------------------+----------------------------------------------------------+
+
++---------------------------------------------------+----------------------------------------------------------+
+| Voltage measurement related device files          | Description                                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_raw                               | Raw voltage measurement for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_scale                             | Scale for voltage channels.                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_calibscale                        | Calibration gain for voltage channels (AVGAIN reg).      |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_offset                            | Offset correction for voltage channels (VRMSOS reg).     |

As above.

Quoted 8 lines
Documentation/iio/ade9000.rst new file +8 -0
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage[0-2]_frequency                         | Measured line frequency for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_altvoltage[0-2]_rms_raw                        | RMS voltage measurement for phases A, B, C.              |
++---------------------------------------------------+----------------------------------------------------------+
+
++---------------------------------------------------+----------------------------------------------------------+
+| Power measurement related device files            | Description                                              |

Documentation/iio/ade9000.rst line 78

Quoted 10 lines
Documentation/iio/ade9000.rst new file +10 -0
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_raw                                 | Raw active power measurement for phases A, B, C.         |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_active_raw                          | Active power measurement for phases A, B, C.             |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_reactive_raw                        | Reactive power measurement for phases A, B, C.           |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_apparent_raw                        | Apparent power measurement for phases A, B, C.           |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_powerfactor                         | Power factor for phases A, B, C.                         |

Currently I'm fairly sure this is _active_powerfactor which is not where it should be. please check this doc again vs attributes on the running driver.

Quoted 15 lines
Documentation/iio/ade9000.rst new file +15 -0
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_scale                               | Scale for power channels.                                |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_calibscale                          | Calibration gain for power channels (APGAIN reg).        |
++---------------------------------------------------+----------------------------------------------------------+
+| in_power[0-2]_calibbias                           | Calibration offset for power channels (xWATTOS regs).    |
++---------------------------------------------------+----------------------------------------------------------+
+
++---------------------------------------------------+----------------------------------------------------------+
+| Energy measurement related device files           | Description                                              |
++---------------------------------------------------+----------------------------------------------------------+
+| in_energy[0-2]_raw                                | Raw energy measurement for phases A, B, C.               |
++---------------------------------------------------+----------------------------------------------------------+
+| in_energy[0-2]_scale                              | Scale for energy channels.                               |
++---------------------------------------------------+----------------------------------------------------------+

Documentation/iio/ade9000.rst line 103

Quoted 10 lines
Documentation/iio/ade9000.rst new file +10 -0
+
++------------------------------+------------------------------------------------------------------+
+| Shared device attributes     | Description                                                      |
++------------------------------+------------------------------------------------------------------+
+| name                         | Name of the IIO device.                                          |
++------------------------------+------------------------------------------------------------------+
+| frequency                    | System line frequency configuration (50Hz/60Hz).                |
++------------------------------+------------------------------------------------------------------+
+| scale                        | Shared PGA gain setting (1x, 2x, 4x) affecting all channels.   |
++------------------------------+------------------------------------------------------------------+

Looks like something odd with formatting in the table here.

Quoted 11 lines
Documentation/iio/ade9000.rst new file +11 -0
+
+3. Calibration and scaling
+===========================
+
+The ADE9000 provides multiple levels of gain and offset correction:
+
+**PGA Gain (shared)**
+  The programmable gain amplifier affects the analog input stage for all channels.
+  Controlled via the shared ``scale`` attribute with values 1, 2, or 4.
+
+**Calibration Gain (per-channel)**

Documentation/iio/ade9000.rst line 124

Quoted 10 lines
Documentation/iio/ade9000.rst new file +10 -0
+  Fine-tuning calibration gains applied in the digital domain for each channel type.
+  Controlled via ``calibscale`` attributes (AIGAIN, AVGAIN, APGAIN registers).
+
+**Calibration Offset (per-channel)**
+  Hardware calibration offsets applied by the device for power measurements.
+  Controlled via ``calibbias`` attributes for power channels.
+
+**Correction Offsets (per-channel)**
+  RMS offset corrections for current and voltage measurements.
+  Controlled via ``offset`` attributes (IRMSOS, VRMSOS registers).

As per the above - these only affect RMS not the direct measurements so need a rethink.

Quoted 4 lines
Documentation/iio/ade9000.rst new file +4 -0
+
+4. Event attributes
+===================
+

Documentation/iio/ade9000.rst line 138

Quoted 10 lines
Documentation/iio/ade9000.rst new file +10 -0
+The ADE9000 provides various interrupts that are mapped to IIO events.
+Event functionality is only available if the corresponding interrupts are
+connected in the device tree.
+
++---------------------------------------------------+----------------------------------------------------------+
+| IIO Event Attribute                               | ADE9000 Datasheet Equivalent                             |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_either_en                      | Zero crossing detection interrupt (ZXVA)                 |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_rising_en                      | Swell detection interrupt (SWELLA)                       |

These seem to be on something to do with RMS not the main voltage channel. They aren't indicating the peak went out of range but rather the RMS value did. Given RMS is a channel modifier, maybe in_voltage0_rms_thresh_rising is enough? Does the RMS half cycle update change how we should represent this? I'm not sure and looking for inputs from others more familiar with energy meters. I had to dig to find what RMS 1/2 was.

Documentation/iio/ade9000.rst line 142

Quoted 4 lines
Documentation/iio/ade9000.rst new file +4 -0
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_falling_en                     | Sag/dip detection interrupt (DIPA)                       |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_none_en                        | Zero crossing timeout interrupt (ZXTOVA)                 |

Not seeing how a timeout maps to a threshold without a direction. This is a failure to see an event for some time. The 'for sometime' could be done with a period control but I'm not sure on what. Maybe a new event direction in_voltage0_notthresh_either_en to say a threshold was not crossed?

Documentation/iio/ade9000.rst line 144

Quoted 2 lines
Documentation/iio/ade9000.rst new file +2 -0
++---------------------------------------------------+----------------------------------------------------------+
+| events_mag_none_en                                | Energy ready interrupt (EGYRDY)                          |

Not an event in IIO terms. Could map this to a trigger as it's indicating a data update of small set of the channels. However we'd have to deal with buffering on our slowest channel.
Do we need to support a dataready on something so slow? Just poll it enough?

Also what is the events_ prefix here?

Documentation/iio/ade9000.rst line 146

Quoted 2 lines
Documentation/iio/ade9000.rst new file +2 -0
++---------------------------------------------------+----------------------------------------------------------+
+| events_change_none_en                             | Sequence error interrupt (SEQERR)                        |

Why this mapping? If this is an error condition then maybe use the EV_TYPE_FAULT and add something alongside the openwire support we have already upstream.

Documentation/iio/ade9000.rst line 148

Quoted 2 lines
Documentation/iio/ade9000.rst new file +2 -0
++---------------------------------------------------+----------------------------------------------------------+
+| events_thresh_none_value                          | Zero crossing timeout threshold (ZXTOUT register)        |

I'd group these so the _value entries come right next the _en entries as then we can consider them together.

This smells like period which we already have for events when they need to be true for a 'while'. Note the units though so you'll have to deal with mapping to those.

Quoted 129 lines
Documentation/iio/ade9000.rst new file +129 -0
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_falling_value                  | Sag/dip threshold (DIP_LVL register)                     |
++---------------------------------------------------+----------------------------------------------------------+
+| in_voltage0_thresh_rising_value                   | Swell threshold (SWELL_LVL register)                     |
++---------------------------------------------------+----------------------------------------------------------+
+
+Event directions:
+- ``rising``: Upper threshold crossing (swell detection)
+- ``falling``: Lower threshold crossing (sag/dip detection)
+- ``either``: Any threshold crossing (zero crossing detection)
+- ``none``: Timeout or non-directional events
+
+**Note**: Event attributes are only available if the corresponding interrupts
+(irq0, irq1, dready) are specified in the device tree. The driver works without
+interrupts but with reduced functionality.
+
+5. Device buffers
+=================
+
+This driver supports IIO buffers for waveform capture. Buffer functionality
+requires the dready interrupt to be connected.
+
+The device supports capturing voltage and current waveforms for power quality
+analysis. The waveform buffer can be configured to capture data from different
+channel combinations.
+
+Supported channel combinations for buffered capture:
+- Phase A: voltage and current (IA + VA)
+- Phase B: voltage and current (IB + VB)
+- Phase C: voltage and current (IC + VC)
+- All phases: all voltage and current channels
+- Individual channels: IA, VA, IB, VB, IC, VC
+
+Usage examples
+--------------
+
+Enable waveform capture for Phase A:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_current0_en
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_voltage0_en
+
+Set buffer length and enable:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> echo 100 > buffer/length
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > buffer/enable
+
+6. Clock output
+===============
+
+The ADE9000 can provide a clock output via the CLKOUT pin when using an external
+crystal/clock source. This feature is enabled by specifying ``#clock-cells = <0>``
+in the device tree. The output clock will be registered as "clkout" and can be
+referenced by other devices.
+
+7. Usage examples
+=================
+
+Show device name:
+
+.. code-block:: bash
+
+	root:/sys/bus/iio/devices/iio:device0> cat name
+        ade9000
+
+Read voltage measurements:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_raw
+        12345
+        root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_scale
+        0.000030517
+
+- Phase A voltage = in_voltage0_raw * in_voltage0_scale = 0.3769 V
+
+Read power measurements:
+
+.. code-block:: bash
+
+        root:/sys/bus/iio/devices/iio:device0> cat in_power0_active_raw
+        5678
+        root:/sys/bus/iio/devices/iio:device0> cat in_power0_scale
+        0.000244140
+
+- Phase A active power = in_power0_active_raw * in_power0_scale = 1.386 W
+
+Configure PGA gain (affects all channels):
+
+.. code-block:: bash
+
+        # Set PGA gain to 2x
+        root:/sys/bus/iio/devices/iio:device0> echo 2 > scale
+        # Read current gain setting
+        root:/sys/bus/iio/devices/iio:device0> cat scale
+        2
+
+Configure line frequency:
+
+.. code-block:: bash
+
+        # Set to 60Hz operation
+        root:/sys/bus/iio/devices/iio:device0> echo 60 > frequency
+        # Read current frequency setting
+        root:/sys/bus/iio/devices/iio:device0> cat frequency
+        60
+
+Configure calibration gains:
+
+.. code-block:: bash
+
+        # Set current channel 0 calibration gain
+        root:/sys/bus/iio/devices/iio:device0> echo 0x800000 > in_current0_calibscale
+        # Set voltage channel 0 calibration gain
+        root:/sys/bus/iio/devices/iio:device0> echo 0x7FFFFF > in_voltage0_calibscale
+
+Configure voltage event thresholds (requires interrupts):
+
+.. code-block:: bash
+
+        # Set sag detection threshold
+        root:/sys/bus/iio/devices/iio:device0> echo 180000 > events/in_voltage0_thresh_falling_value
+        # Enable sag detection
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_voltage0_thresh_falling_en
+
+        # Set swell detection threshold

Documentation/iio/ade9000.rst line 286

Quoted 10 lines
Documentation/iio/ade9000.rst new file +9 -0
+        root:/sys/bus/iio/devices/iio:device0> echo 260000 > events/in_voltage0_thresh_rising_value
+        # Enable swell detection
+        root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_voltage0_thresh_rising_en
+
+8. IIO Interfacing Tools
+========================
+
+See ``Documentation/iio/iio_tools.rst`` for the description of the available IIO
+interfacing tools.
\ No newline at end of file

fix that.

Quoted 12 lines
Documentation/iio/index.rst +1 -0
index c106402a91f7..792c815286f4 100644
@@ -28,6 +28,7 @@ Industrial I/O Kernel Drivers
    ad7606
    ad7625
    ad7944
+   ade9000
    adis16475
    adis16480
    adis16550
author maintainer
#13 lore raw

PATCH v5 6/6 Documentation: ABI: iio: add sinc4+lp

In reply to Antoniu Miclaus

Add new filter type to the sysfs-bus-iio ABI documentation:
- "sinc4+lp" for Sinc4 + Low Pass Filter

---
no changes in v5.

 Documentation/ABI/testing/sysfs-bus-iio | 1 +
 1 file changed, 1 insertion(+)
Documentation/ABI/testing/sysfs-bus-iio +1 -0
index 78da68826307..cb300135b4c4 100644
@@ -2319,6 +2319,7 @@ Description:
 		  time.
 		* "sinc4" - Sinc 4. Excellent noise performance. Long
 		  1st conversion time.
+		* "sinc4+lp" - Sinc4 + Low Pass Filter.
 		* "sinc4+sinc1" - Sinc4 + averaging by 8. Low 1st conversion
 		  time.
 		* "sinc5" - The digital sinc5 filter. Excellent noise
Signature · 1 line
2.43.0