[PATCH 1/4] iio: adc: ade9000: parameterise the reactive power channel

From: Antoniu Miclaus

Date: Mon Oct 12 2026 - 07:26:03 EST


The channel array is declared once by ADE9000_DECLARE_CHANNELS() and
specialised per part through the altvoltage_rms argument, which lets parts
without dip/swell hardware drop those events. Some parts in the family do
not compute total reactive power at all and have no AVAR register, so they
need to drop the reactive power channel as well.

Add a second argument that selects the reactive power entry and introduce
the ADE9000_POWER_REACTIVE_ENTRY()/ADE9000_NO_POWER_REACTIVE_ENTRY() pair
for it. The entry macros include their own trailing comma so that the
variant for parts lacking the register can expand to nothing.

No functional change: the preprocessed ade9000_channels and
ade9078_channels tables are unchanged.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@xxxxxxxxxx>
---
drivers/iio/adc/ade9000.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ade9000.c b/drivers/iio/adc/ade9000.c
index e0113b62a261..03b69556b62f 100644
--- a/drivers/iio/adc/ade9000.c
+++ b/drivers/iio/adc/ade9000.c
@@ -561,6 +561,15 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
.scan_index = -1 \
}

+/*
+ * The entry macros below carry their own trailing comma so that parts without
+ * a total reactive power register can expand to nothing.
+ */
+#define ADE9000_POWER_REACTIVE_ENTRY(num) \
+ ADE9000_POWER_REACTIVE_CHANNEL(num),
+
+#define ADE9000_NO_POWER_REACTIVE_ENTRY(num)
+
#define ADE9000_POWER_APPARENT_CHANNEL(num) { \
.type = IIO_POWER, \
.channel = num, \
@@ -618,8 +627,10 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
/*
* Declare a full channel array. @altvoltage_rms picks the RMS voltage channel
* variant so parts without dip/swell hardware (e.g. ADE9078) omit those events.
+ * @power_reactive picks the total reactive power entry so parts that only
+ * compute fundamental reactive power omit that channel.
*/
-#define ADE9000_DECLARE_CHANNELS(_name, altvoltage_rms) \
+#define ADE9000_DECLARE_CHANNELS(_name, altvoltage_rms, power_reactive) \
static const struct iio_chan_spec _name[] = { \
/* Phase A channels */ \
ADE9000_CURRENT_CHANNEL(ADE9000_PHASE_A_NR), \
@@ -627,7 +638,7 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
ADE9000_ALTCURRENT_RMS_CHANNEL(ADE9000_PHASE_A_NR), \
altvoltage_rms(ADE9000_PHASE_A_NR), \
ADE9000_POWER_ACTIVE_CHANNEL(ADE9000_PHASE_A_NR), \
- ADE9000_POWER_REACTIVE_CHANNEL(ADE9000_PHASE_A_NR), \
+ power_reactive(ADE9000_PHASE_A_NR) \
ADE9000_POWER_APPARENT_CHANNEL(ADE9000_PHASE_A_NR), \
ADE9000_ENERGY_ACTIVE_CHANNEL(ADE9000_PHASE_A_NR, \
ADE9000_REG_AWATTHR_LO), \
@@ -642,7 +653,7 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
ADE9000_ALTCURRENT_RMS_CHANNEL(ADE9000_PHASE_B_NR), \
altvoltage_rms(ADE9000_PHASE_B_NR), \
ADE9000_POWER_ACTIVE_CHANNEL(ADE9000_PHASE_B_NR), \
- ADE9000_POWER_REACTIVE_CHANNEL(ADE9000_PHASE_B_NR), \
+ power_reactive(ADE9000_PHASE_B_NR) \
ADE9000_POWER_APPARENT_CHANNEL(ADE9000_PHASE_B_NR), \
ADE9000_ENERGY_ACTIVE_CHANNEL(ADE9000_PHASE_B_NR, \
ADE9000_REG_BWATTHR_LO), \
@@ -657,7 +668,7 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
ADE9000_ALTCURRENT_RMS_CHANNEL(ADE9000_PHASE_C_NR), \
altvoltage_rms(ADE9000_PHASE_C_NR), \
ADE9000_POWER_ACTIVE_CHANNEL(ADE9000_PHASE_C_NR), \
- ADE9000_POWER_REACTIVE_CHANNEL(ADE9000_PHASE_C_NR), \
+ power_reactive(ADE9000_PHASE_C_NR) \
ADE9000_POWER_APPARENT_CHANNEL(ADE9000_PHASE_C_NR), \
ADE9000_ENERGY_ACTIVE_CHANNEL(ADE9000_PHASE_C_NR, \
ADE9000_REG_CWATTHR_LO), \
@@ -668,8 +679,10 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
ADE9000_POWER_FACTOR_CHANNEL(ADE9000_PHASE_C_NR), \
}

-ADE9000_DECLARE_CHANNELS(ade9000_channels, ADE9000_ALTVOLTAGE_RMS_CHANNEL);
-ADE9000_DECLARE_CHANNELS(ade9078_channels, ADE9000_ALTVOLTAGE_RMS_CHANNEL_NO_EVENTS);
+ADE9000_DECLARE_CHANNELS(ade9000_channels, ADE9000_ALTVOLTAGE_RMS_CHANNEL,
+ ADE9000_POWER_REACTIVE_ENTRY);
+ADE9000_DECLARE_CHANNELS(ade9078_channels, ADE9000_ALTVOLTAGE_RMS_CHANNEL_NO_EVENTS,
+ ADE9000_POWER_REACTIVE_ENTRY);

/*
* Full-scale codes referred from the respective datasheets. These are the
--
2.43.0