Skip to content

Commit 0ee8546

Browse files
spandruvadajic23
authored andcommitted
IIO: core: Modify scan element type
The current scan element type uses the following format: [be|le]:[s|u]bits/storagebits[>>shift]. To specify multiple elements in this type, added a repeat value. So new format is: [be|le]:[s|u]bits/storagebitsXr[>>shift]. Here r is specifying how may times, real/storage bits are repeating. When X is value is 0 or 1, then repeat value is not used in the format, and it will be same as existing format. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 9fbfb4b commit 0ee8546

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

‎drivers/iio/industrialio-buffer.c‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,16 @@ static ssize_t iio_show_fixed_type(struct device *dev,
150150
type = IIO_BE;
151151
#endif
152152
}
153-
return sprintf(buf, "%s:%c%d/%d>>%u\n",
153+
if (this_attr->c->scan_type.repeat > 1)
154+
return sprintf(buf, "%s:%c%d/%dX%d>>%u\n",
155+
iio_endian_prefix[type],
156+
this_attr->c->scan_type.sign,
157+
this_attr->c->scan_type.realbits,
158+
this_attr->c->scan_type.storagebits,
159+
this_attr->c->scan_type.repeat,
160+
this_attr->c->scan_type.shift);
161+
else
162+
return sprintf(buf, "%s:%c%d/%d>>%u\n",
154163
iio_endian_prefix[type],
155164
this_attr->c->scan_type.sign,
156165
this_attr->c->scan_type.realbits,
@@ -475,14 +484,22 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
475484
for_each_set_bit(i, mask,
476485
indio_dev->masklength) {
477486
ch = iio_find_channel_from_si(indio_dev, i);
478-
length = ch->scan_type.storagebits / 8;
487+
if (ch->scan_type.repeat > 1)
488+
length = ch->scan_type.storagebits / 8 *
489+
ch->scan_type.repeat;
490+
else
491+
length = ch->scan_type.storagebits / 8;
479492
bytes = ALIGN(bytes, length);
480493
bytes += length;
481494
}
482495
if (timestamp) {
483496
ch = iio_find_channel_from_si(indio_dev,
484497
indio_dev->scan_index_timestamp);
485-
length = ch->scan_type.storagebits / 8;
498+
if (ch->scan_type.repeat > 1)
499+
length = ch->scan_type.storagebits / 8 *
500+
ch->scan_type.repeat;
501+
else
502+
length = ch->scan_type.storagebits / 8;
486503
bytes = ALIGN(bytes, length);
487504
bytes += length;
488505
}
@@ -959,7 +976,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
959976
indio_dev->masklength,
960977
in_ind + 1);
961978
ch = iio_find_channel_from_si(indio_dev, in_ind);
962-
length = ch->scan_type.storagebits/8;
979+
if (ch->scan_type.repeat > 1)
980+
length = ch->scan_type.storagebits / 8 *
981+
ch->scan_type.repeat;
982+
else
983+
length = ch->scan_type.storagebits / 8;
963984
/* Make sure we are aligned */
964985
in_loc += length;
965986
if (in_loc % length)
@@ -971,7 +992,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
971992
goto error_clear_mux_table;
972993
}
973994
ch = iio_find_channel_from_si(indio_dev, in_ind);
974-
length = ch->scan_type.storagebits/8;
995+
if (ch->scan_type.repeat > 1)
996+
length = ch->scan_type.storagebits / 8 *
997+
ch->scan_type.repeat;
998+
else
999+
length = ch->scan_type.storagebits / 8;
9751000
if (out_loc % length)
9761001
out_loc += length - out_loc % length;
9771002
if (in_loc % length)
@@ -992,7 +1017,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
9921017
}
9931018
ch = iio_find_channel_from_si(indio_dev,
9941019
indio_dev->scan_index_timestamp);
995-
length = ch->scan_type.storagebits/8;
1020+
if (ch->scan_type.repeat > 1)
1021+
length = ch->scan_type.storagebits / 8 *
1022+
ch->scan_type.repeat;
1023+
else
1024+
length = ch->scan_type.storagebits / 8;
9961025
if (out_loc % length)
9971026
out_loc += length - out_loc % length;
9981027
if (in_loc % length)

‎include/linux/iio/iio.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ struct iio_event_spec {
177177
* shift: Shift right by this before masking out
178178
* realbits.
179179
* endianness: little or big endian
180+
* repeat: Number of times real/storage bits
181+
* repeats. When the repeat element is
182+
* more than 1, then the type element in
183+
* sysfs will show a repeat value.
184+
* Otherwise, the number of repetitions is
185+
* omitted.
180186
* @info_mask_separate: What information is to be exported that is specific to
181187
* this channel.
182188
* @info_mask_shared_by_type: What information is to be exported that is shared
@@ -219,6 +225,7 @@ struct iio_chan_spec {
219225
u8 realbits;
220226
u8 storagebits;
221227
u8 shift;
228+
u8 repeat;
222229
enum iio_endian endianness;
223230
} scan_type;
224231
long info_mask_separate;

0 commit comments

Comments
 (0)