IIO: core: Modify scan element type
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Mon, 28 Apr 2014 23:51:00 +0000 (00:51 +0100)
committerJonathan Cameron <jic23@kernel.org>
Tue, 29 Apr 2014 21:07:11 +0000 (22:07 +0100)
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>
drivers/iio/industrialio-buffer.c
include/linux/iio/iio.h

index e472cff6eeae38168331bf8b13a6583e9756842e..36b1ae92e2392b5e8b59032fe9df02a8ee2aebf4 100644 (file)
@@ -150,7 +150,16 @@ static ssize_t iio_show_fixed_type(struct device *dev,
                type = IIO_BE;
 #endif
        }
-       return sprintf(buf, "%s:%c%d/%d>>%u\n",
+       if (this_attr->c->scan_type.repeat > 1)
+               return sprintf(buf, "%s:%c%d/%dX%d>>%u\n",
+                      iio_endian_prefix[type],
+                      this_attr->c->scan_type.sign,
+                      this_attr->c->scan_type.realbits,
+                      this_attr->c->scan_type.storagebits,
+                      this_attr->c->scan_type.repeat,
+                      this_attr->c->scan_type.shift);
+               else
+                       return sprintf(buf, "%s:%c%d/%d>>%u\n",
                       iio_endian_prefix[type],
                       this_attr->c->scan_type.sign,
                       this_attr->c->scan_type.realbits,
@@ -475,14 +484,22 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
        for_each_set_bit(i, mask,
                         indio_dev->masklength) {
                ch = iio_find_channel_from_si(indio_dev, i);
-               length = ch->scan_type.storagebits / 8;
+               if (ch->scan_type.repeat > 1)
+                       length = ch->scan_type.storagebits / 8 *
+                               ch->scan_type.repeat;
+               else
+                       length = ch->scan_type.storagebits / 8;
                bytes = ALIGN(bytes, length);
                bytes += length;
        }
        if (timestamp) {
                ch = iio_find_channel_from_si(indio_dev,
                                              indio_dev->scan_index_timestamp);
-               length = ch->scan_type.storagebits / 8;
+               if (ch->scan_type.repeat > 1)
+                       length = ch->scan_type.storagebits / 8 *
+                               ch->scan_type.repeat;
+               else
+                       length = ch->scan_type.storagebits / 8;
                bytes = ALIGN(bytes, length);
                bytes += length;
        }
@@ -959,7 +976,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
                                               indio_dev->masklength,
                                               in_ind + 1);
                        ch = iio_find_channel_from_si(indio_dev, in_ind);
-                       length = ch->scan_type.storagebits/8;
+                       if (ch->scan_type.repeat > 1)
+                               length = ch->scan_type.storagebits / 8 *
+                                       ch->scan_type.repeat;
+                       else
+                               length = ch->scan_type.storagebits / 8;
                        /* Make sure we are aligned */
                        in_loc += length;
                        if (in_loc % length)
@@ -971,7 +992,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
                        goto error_clear_mux_table;
                }
                ch = iio_find_channel_from_si(indio_dev, in_ind);
-               length = ch->scan_type.storagebits/8;
+               if (ch->scan_type.repeat > 1)
+                       length = ch->scan_type.storagebits / 8 *
+                               ch->scan_type.repeat;
+               else
+                       length = ch->scan_type.storagebits / 8;
                if (out_loc % length)
                        out_loc += length - out_loc % length;
                if (in_loc % length)
@@ -992,7 +1017,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
                }
                ch = iio_find_channel_from_si(indio_dev,
                        indio_dev->scan_index_timestamp);
-               length = ch->scan_type.storagebits/8;
+               if (ch->scan_type.repeat > 1)
+                       length = ch->scan_type.storagebits / 8 *
+                               ch->scan_type.repeat;
+               else
+                       length = ch->scan_type.storagebits / 8;
                if (out_loc % length)
                        out_loc += length - out_loc % length;
                if (in_loc % length)
index 5629c92eeadfe93e1a7ea466feb9c34d2e4668cf..ccde91725f98c3b28212dc91400ec2ee5a71a686 100644 (file)
@@ -177,6 +177,12 @@ struct iio_event_spec {
  *                     shift:          Shift right by this before masking out
  *                                     realbits.
  *                     endianness:     little or big endian
+ *                     repeat:         Number of times real/storage bits
+ *                                     repeats. When the repeat element is
+ *                                     more than 1, then the type element in
+ *                                     sysfs will show a repeat value.
+ *                                     Otherwise, the number of repetitions is
+ *                                     omitted.
  * @info_mask_separate: What information is to be exported that is specific to
  *                     this channel.
  * @info_mask_shared_by_type: What information is to be exported that is shared
@@ -219,6 +225,7 @@ struct iio_chan_spec {
                u8      realbits;
                u8      storagebits;
                u8      shift;
+               u8      repeat;
                enum iio_endian endianness;
        } scan_type;
        long                    info_mask_separate;