]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: add power and energy measurement modifiers
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Mon, 8 Sep 2025 07:35:22 +0000 (07:35 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 13 Sep 2025 12:47:19 +0000 (13:47 +0100)
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

Signal quality modifiers:
- IIO_MOD_RMS: Root Mean Square value

Additionally adds:
- IIO_CHAN_INFO_POWERFACTOR: Power factor channel info type for
  representing the ratio of active power to apparent power

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

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Documentation/ABI/testing/sysfs-bus-iio
drivers/iio/industrialio-core.c
include/linux/iio/types.h
include/uapi/linux/iio/types.h
tools/iio/iio_event_monitor.c

index 2fb2cea4b19249743398b1ff0b538b03ced0340b..78da68826307f448ae3837e54e07604efe18685b 100644 (file)
@@ -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:       linux-iio@vger.kernel.org
+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:       linux-iio@vger.kernel.org
 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:       linux-iio@vger.kernel.org
+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:       linux-iio@vger.kernel.org
@@ -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:       linux-iio@vger.kernel.org
 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:       linux-iio@vger.kernel.org
+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
index 4ff2c44f9324fb89b8239a0ac1e90c287ad7f5e0..88c3d585a1bd0c602df7fb15581fbad923e1e983 100644 (file)
@@ -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
index ad2761efcc8315e1f9907d2a7159447fb463333e..34eebad12d2c21029cc3ba820365cbb8022a90b4 100644 (file)
@@ -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_ */
index 3c3cc1497a1e0e9d7868edf02327dea2b63e5c66..6d269b8442713475c776ed705a56e0bc9c82c5cc 100644 (file)
@@ -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 {
index d26aff649f3f112031a22bfe80b92d27b2169200..03ca33869ce850c74ad6eb77b6173093ebbe0ac0 100644 (file)
@@ -141,6 +141,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",
 };
 
 static bool event_is_known(struct iio_event_data *event)
@@ -240,6 +244,10 @@ static bool event_is_known(struct iio_event_data *event)
        case IIO_MOD_PM4:
        case IIO_MOD_PM10:
        case IIO_MOD_O2:
+       case IIO_MOD_RMS:
+       case IIO_MOD_ACTIVE:
+       case IIO_MOD_REACTIVE:
+       case IIO_MOD_APPARENT:
                break;
        default:
                return false;