Skip to content

Commit 70da020

Browse files
amiclausjic23
authored andcommitted
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>
1 parent f15bc37 commit 70da020

5 files changed

Lines changed: 47 additions & 0 deletions

File tree

Documentation/ABI/testing/sysfs-bus-iio

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,18 @@ Description:
167167
is required is a consistent labeling. Units after application
168168
of scale and offset are millivolts.
169169

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+
170178
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
171182
KernelVersion: 4.5
172183
Contact: linux-iio@vger.kernel.org
173184
Description:
@@ -176,6 +187,13 @@ Description:
176187
unique to allow association with event codes. Units after
177188
application of scale and offset are milliwatts.
178189

190+
What: /sys/bus/iio/devices/iio:deviceX/in_powerY_powerfactor
191+
KernelVersion: 6.18
192+
Contact: linux-iio@vger.kernel.org
193+
Description:
194+
Power factor measurement from channel Y. Power factor is the
195+
ratio of active power to apparent power. The value is unitless.
196+
179197
What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw
180198
KernelVersion: 3.2
181199
Contact: linux-iio@vger.kernel.org
@@ -1569,6 +1587,9 @@ Description:
15691587

15701588
What: /sys/.../iio:deviceX/in_energy_input
15711589
What: /sys/.../iio:deviceX/in_energy_raw
1590+
What: /sys/.../iio:deviceX/in_energyY_active_raw
1591+
What: /sys/.../iio:deviceX/in_energyY_reactive_raw
1592+
What: /sys/.../iio:deviceX/in_energyY_apparent_raw
15721593
KernelVersion: 4.0
15731594
Contact: linux-iio@vger.kernel.org
15741595
Description:
@@ -1707,6 +1728,14 @@ Description:
17071728
component of the signal while the 'q' channel contains the quadrature
17081729
component.
17091730

1731+
What: /sys/bus/iio/devices/iio:deviceX/in_altcurrentY_rms_raw
1732+
KernelVersion: 6.18
1733+
Contact: linux-iio@vger.kernel.org
1734+
Description:
1735+
Raw (unscaled no bias removal etc.) Root Mean Square (RMS) current
1736+
measurement from channel Y. Units after application of scale and
1737+
offset are milliamps.
1738+
17101739
What: /sys/.../iio:deviceX/in_energy_en
17111740
What: /sys/.../iio:deviceX/in_distance_en
17121741
What: /sys/.../iio:deviceX/in_velocity_sqrt(x^2+y^2+z^2)_en

drivers/iio/industrialio-core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ static const char * const iio_modifier_names[] = {
153153
[IIO_MOD_PITCH] = "pitch",
154154
[IIO_MOD_YAW] = "yaw",
155155
[IIO_MOD_ROLL] = "roll",
156+
[IIO_MOD_RMS] = "rms",
157+
[IIO_MOD_ACTIVE] = "active",
158+
[IIO_MOD_REACTIVE] = "reactive",
159+
[IIO_MOD_APPARENT] = "apparent",
156160
};
157161

158162
/* relies on pairs of these shared then separate */
@@ -190,6 +194,7 @@ static const char * const iio_chan_info_postfix[] = {
190194
[IIO_CHAN_INFO_ZEROPOINT] = "zeropoint",
191195
[IIO_CHAN_INFO_TROUGH] = "trough_raw",
192196
[IIO_CHAN_INFO_CONVDELAY] = "convdelay",
197+
[IIO_CHAN_INFO_POWERFACTOR] = "powerfactor",
193198
};
194199
/**
195200
* iio_device_id() - query the unique ID for the device

include/linux/iio/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum iio_chan_info_enum {
7070
IIO_CHAN_INFO_ZEROPOINT,
7171
IIO_CHAN_INFO_TROUGH,
7272
IIO_CHAN_INFO_CONVDELAY,
73+
IIO_CHAN_INFO_POWERFACTOR,
7374
};
7475

7576
#endif /* _IIO_TYPES_H_ */

include/uapi/linux/iio/types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ enum iio_modifier {
109109
IIO_MOD_ROLL,
110110
IIO_MOD_LIGHT_UVA,
111111
IIO_MOD_LIGHT_UVB,
112+
IIO_MOD_RMS,
113+
IIO_MOD_ACTIVE,
114+
IIO_MOD_REACTIVE,
115+
IIO_MOD_APPARENT,
112116
};
113117

114118
enum iio_event_type {

tools/iio/iio_event_monitor.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ static const char * const iio_modifier_names[] = {
141141
[IIO_MOD_PITCH] = "pitch",
142142
[IIO_MOD_YAW] = "yaw",
143143
[IIO_MOD_ROLL] = "roll",
144+
[IIO_MOD_RMS] = "rms",
145+
[IIO_MOD_ACTIVE] = "active",
146+
[IIO_MOD_REACTIVE] = "reactive",
147+
[IIO_MOD_APPARENT] = "apparent",
144148
};
145149

146150
static bool event_is_known(struct iio_event_data *event)
@@ -240,6 +244,10 @@ static bool event_is_known(struct iio_event_data *event)
240244
case IIO_MOD_PM4:
241245
case IIO_MOD_PM10:
242246
case IIO_MOD_O2:
247+
case IIO_MOD_RMS:
248+
case IIO_MOD_ACTIVE:
249+
case IIO_MOD_REACTIVE:
250+
case IIO_MOD_APPARENT:
243251
break;
244252
default:
245253
return false;

0 commit comments

Comments
 (0)