Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: add power and energy measurement modifiers

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>

authored by

Antoniu Miclaus and committed by
Jonathan Cameron
70da0206 f15bc37d

+47
+29
Documentation/ABI/testing/sysfs-bus-iio
··· 167 167 is required is a consistent labeling. Units after application 168 168 of scale and offset are millivolts. 169 169 170 + What: /sys/bus/iio/devices/iio:deviceX/in_altvoltageY_rms_raw 171 + KernelVersion: 6.18 172 + Contact: linux-iio@vger.kernel.org 173 + Description: 174 + Raw (unscaled) Root Mean Square (RMS) voltage measurement from 175 + channel Y. Units after application of scale and offset are 176 + millivolts. 177 + 170 178 What: /sys/bus/iio/devices/iio:deviceX/in_powerY_raw 179 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_active_raw 180 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_reactive_raw 181 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_apparent_raw 171 182 KernelVersion: 4.5 172 183 Contact: linux-iio@vger.kernel.org 173 184 Description: ··· 186 175 channel Y. The number must always be specified and 187 176 unique to allow association with event codes. Units after 188 177 application of scale and offset are milliwatts. 178 + 179 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_powerfactor 180 + KernelVersion: 6.18 181 + Contact: linux-iio@vger.kernel.org 182 + Description: 183 + Power factor measurement from channel Y. Power factor is the 184 + ratio of active power to apparent power. The value is unitless. 189 185 190 186 What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw 191 187 KernelVersion: 3.2 ··· 1587 1569 1588 1570 What: /sys/.../iio:deviceX/in_energy_input 1589 1571 What: /sys/.../iio:deviceX/in_energy_raw 1572 + What: /sys/.../iio:deviceX/in_energyY_active_raw 1573 + What: /sys/.../iio:deviceX/in_energyY_reactive_raw 1574 + What: /sys/.../iio:deviceX/in_energyY_apparent_raw 1590 1575 KernelVersion: 4.0 1591 1576 Contact: linux-iio@vger.kernel.org 1592 1577 Description: ··· 1727 1706 channels refer to the same signal. The 'i' channel contains the in-phase 1728 1707 component of the signal while the 'q' channel contains the quadrature 1729 1708 component. 1709 + 1710 + What: /sys/bus/iio/devices/iio:deviceX/in_altcurrentY_rms_raw 1711 + KernelVersion: 6.18 1712 + Contact: linux-iio@vger.kernel.org 1713 + Description: 1714 + Raw (unscaled no bias removal etc.) Root Mean Square (RMS) current 1715 + measurement from channel Y. Units after application of scale and 1716 + offset are milliamps. 1730 1717 1731 1718 What: /sys/.../iio:deviceX/in_energy_en 1732 1719 What: /sys/.../iio:deviceX/in_distance_en
+5
drivers/iio/industrialio-core.c
··· 153 153 [IIO_MOD_PITCH] = "pitch", 154 154 [IIO_MOD_YAW] = "yaw", 155 155 [IIO_MOD_ROLL] = "roll", 156 + [IIO_MOD_RMS] = "rms", 157 + [IIO_MOD_ACTIVE] = "active", 158 + [IIO_MOD_REACTIVE] = "reactive", 159 + [IIO_MOD_APPARENT] = "apparent", 156 160 }; 157 161 158 162 /* relies on pairs of these shared then separate */ ··· 194 190 [IIO_CHAN_INFO_ZEROPOINT] = "zeropoint", 195 191 [IIO_CHAN_INFO_TROUGH] = "trough_raw", 196 192 [IIO_CHAN_INFO_CONVDELAY] = "convdelay", 193 + [IIO_CHAN_INFO_POWERFACTOR] = "powerfactor", 197 194 }; 198 195 /** 199 196 * iio_device_id() - query the unique ID for the device
+1
include/linux/iio/types.h
··· 70 70 IIO_CHAN_INFO_ZEROPOINT, 71 71 IIO_CHAN_INFO_TROUGH, 72 72 IIO_CHAN_INFO_CONVDELAY, 73 + IIO_CHAN_INFO_POWERFACTOR, 73 74 }; 74 75 75 76 #endif /* _IIO_TYPES_H_ */
+4
include/uapi/linux/iio/types.h
··· 109 109 IIO_MOD_ROLL, 110 110 IIO_MOD_LIGHT_UVA, 111 111 IIO_MOD_LIGHT_UVB, 112 + IIO_MOD_RMS, 113 + IIO_MOD_ACTIVE, 114 + IIO_MOD_REACTIVE, 115 + IIO_MOD_APPARENT, 112 116 }; 113 117 114 118 enum iio_event_type {
+8
tools/iio/iio_event_monitor.c
··· 141 141 [IIO_MOD_PITCH] = "pitch", 142 142 [IIO_MOD_YAW] = "yaw", 143 143 [IIO_MOD_ROLL] = "roll", 144 + [IIO_MOD_RMS] = "rms", 145 + [IIO_MOD_ACTIVE] = "active", 146 + [IIO_MOD_REACTIVE] = "reactive", 147 + [IIO_MOD_APPARENT] = "apparent", 144 148 }; 145 149 146 150 static bool event_is_known(struct iio_event_data *event) ··· 244 240 case IIO_MOD_PM4: 245 241 case IIO_MOD_PM10: 246 242 case IIO_MOD_O2: 243 + case IIO_MOD_RMS: 244 + case IIO_MOD_ACTIVE: 245 + case IIO_MOD_REACTIVE: 246 + case IIO_MOD_APPARENT: 247 247 break; 248 248 default: 249 249 return false;