Skip to content

Commit 550268c

Browse files
Jonathan Camerongregkh
authored andcommitted
staging:iio: scrap scan_count and ensure all drivers use active_scan_mask
Obviously drivers should only use this for pushing to buffers. They need buffer->scan_mask for pulling from them post demux. Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Acked-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 1612244 commit 550268c

19 files changed

Lines changed: 100 additions & 77 deletions

‎drivers/staging/iio/accel/adis16201_ring.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
7474
return -ENOMEM;
7575
}
7676

77-
if (ring->scan_count)
78-
if (adis16201_read_ring_data(indio_dev, st->rx) >= 0)
79-
for (; i < ring->scan_count; i++)
80-
data[i] = be16_to_cpup(
81-
(__be16 *)&(st->rx[i*2]));
77+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)
78+
&& adis16201_read_ring_data(indio_dev, st->rx) >= 0)
79+
for (; i < bitmap_weight(indio_dev->active_scan_mask,
80+
indio_dev->masklength); i++)
81+
data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
8282

8383
/* Guaranteed to be aligned with 8 byte boundary */
8484
if (ring->scan_timestamp)

‎drivers/staging/iio/accel/adis16203_ring.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)
7474
return -ENOMEM;
7575
}
7676

77-
if (ring->scan_count)
78-
if (adis16203_read_ring_data(&indio_dev->dev, st->rx) >= 0)
79-
for (; i < ring->scan_count; i++)
80-
data[i] = be16_to_cpup(
81-
(__be16 *)&(st->rx[i*2]));
77+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
78+
adis16203_read_ring_data(&indio_dev->dev, st->rx) >= 0)
79+
for (; i < bitmap_weight(indio_dev->active_scan_mask,
80+
indio_dev->masklength); i++)
81+
data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
8282

8383
/* Guaranteed to be aligned with 8 byte boundary */
8484
if (ring->scan_timestamp)

‎drivers/staging/iio/accel/adis16204_ring.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
7171
return -ENOMEM;
7272
}
7373

74-
if (ring->scan_count)
75-
if (adis16204_read_ring_data(&indio_dev->dev, st->rx) >= 0)
76-
for (; i < ring->scan_count; i++)
77-
data[i] = be16_to_cpup(
78-
(__be16 *)&(st->rx[i*2]));
74+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
75+
adis16204_read_ring_data(&indio_dev->dev, st->rx) >= 0)
76+
for (; i < bitmap_weight(indio_dev->active_scan_mask,
77+
indio_dev->masklength); i++)
78+
data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
7979

8080
/* Guaranteed to be aligned with 8 byte boundary */
8181
if (ring->scan_timestamp)

‎drivers/staging/iio/accel/adis16209_ring.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)
7272
return -ENOMEM;
7373
}
7474

75-
if (ring->scan_count &&
75+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
7676
adis16209_read_ring_data(&indio_dev->dev, st->rx) >= 0)
77-
for (; i < ring->scan_count; i++)
77+
for (; i < bitmap_weight(indio_dev->active_scan_mask,
78+
indio_dev->masklength); i++)
7879
data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
7980

8081
/* Guaranteed to be aligned with 8 byte boundary */

‎drivers/staging/iio/accel/adis16240_ring.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)
6969
return -ENOMEM;
7070
}
7171

72-
if (ring->scan_count &&
72+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
7373
adis16240_read_ring_data(&indio_dev->dev, st->rx) >= 0)
74-
for (; i < ring->scan_count; i++)
74+
for (; i < bitmap_weight(indio_dev->active_scan_mask,
75+
indio_dev->masklength); i++)
7576
data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
7677

7778
/* Guaranteed to be aligned with 8 byte boundary */

‎drivers/staging/iio/accel/lis3l02dq_ring.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,21 @@ static const u8 read_all_tx_array[] = {
8787
**/
8888
static int lis3l02dq_read_all(struct iio_dev *indio_dev, u8 *rx_array)
8989
{
90-
struct iio_buffer *buffer = indio_dev->buffer;
9190
struct lis3l02dq_state *st = iio_priv(indio_dev);
9291
struct spi_transfer *xfers;
9392
struct spi_message msg;
9493
int ret, i, j = 0;
9594

96-
xfers = kcalloc((buffer->scan_count) * 2, sizeof(*xfers), GFP_KERNEL);
95+
xfers = kcalloc(bitmap_weight(indio_dev->active_scan_mask,
96+
indio_dev->masklength) * 2,
97+
sizeof(*xfers), GFP_KERNEL);
9798
if (!xfers)
9899
return -ENOMEM;
99100

100101
mutex_lock(&st->buf_lock);
101102

102103
for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++)
103-
if (test_bit(i, buffer->scan_mask)) {
104+
if (test_bit(i, indio_dev->active_scan_mask)) {
104105
/* lower byte */
105106
xfers[j].tx_buf = st->tx + 2*j;
106107
st->tx[2*j] = read_all_tx_array[i*4];
@@ -128,7 +129,8 @@ static int lis3l02dq_read_all(struct iio_dev *indio_dev, u8 *rx_array)
128129
* values in alternate bytes
129130
*/
130131
spi_message_init(&msg);
131-
for (j = 0; j < buffer->scan_count * 2; j++)
132+
for (j = 0; j < bitmap_weight(indio_dev->active_scan_mask,
133+
indio_dev->masklength) * 2; j++)
132134
spi_message_add_tail(&xfers[j], &msg);
133135

134136
ret = spi_sync(st->us, &msg);
@@ -144,14 +146,16 @@ static int lis3l02dq_get_buffer_element(struct iio_dev *indio_dev,
144146
int ret, i;
145147
u8 *rx_array ;
146148
s16 *data = (s16 *)buf;
149+
int scan_count = bitmap_weight(indio_dev->active_scan_mask,
150+
indio_dev->masklength);
147151

148-
rx_array = kzalloc(4 * (indio_dev->buffer->scan_count), GFP_KERNEL);
152+
rx_array = kzalloc(4 * scan_count, GFP_KERNEL);
149153
if (rx_array == NULL)
150154
return -ENOMEM;
151155
ret = lis3l02dq_read_all(indio_dev, rx_array);
152156
if (ret < 0)
153157
return ret;
154-
for (i = 0; i < indio_dev->buffer->scan_count; i++)
158+
for (i = 0; i < scan_count; i++)
155159
data[i] = combine_8_to_16(rx_array[i*4+1],
156160
rx_array[i*4+3]);
157161
kfree(rx_array);
@@ -174,7 +178,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
174178
return -ENOMEM;
175179
}
176180

177-
if (buffer->scan_count)
181+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
178182
len = lis3l02dq_get_buffer_element(indio_dev, data);
179183

180184
/* Guaranteed to be aligned with 8 byte boundary */
@@ -362,17 +366,17 @@ static int lis3l02dq_buffer_postenable(struct iio_dev *indio_dev)
362366
if (ret)
363367
goto error_ret;
364368

365-
if (iio_scan_mask_query(indio_dev->buffer, 0)) {
369+
if (test_bit(0, indio_dev->active_scan_mask)) {
366370
t |= LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE;
367371
oneenabled = true;
368372
} else
369373
t &= ~LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE;
370-
if (iio_scan_mask_query(indio_dev->buffer, 1)) {
374+
if (test_bit(1, indio_dev->active_scan_mask)) {
371375
t |= LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE;
372376
oneenabled = true;
373377
} else
374378
t &= ~LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE;
375-
if (iio_scan_mask_query(indio_dev->buffer, 2)) {
379+
if (test_bit(2, indio_dev->active_scan_mask)) {
376380
t |= LIS3L02DQ_REG_CTRL_1_AXES_Z_ENABLE;
377381
oneenabled = true;
378382
} else

‎drivers/staging/iio/adc/ad7192.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,14 @@ static int ad7192_ring_preenable(struct iio_dev *indio_dev)
479479
size_t d_size;
480480
unsigned channel;
481481

482-
if (!ring->scan_count)
482+
if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
483483
return -EINVAL;
484484

485-
channel = find_first_bit(ring->scan_mask, indio_dev->masklength);
485+
channel = find_first_bit(indio_dev->active_scan_mask,
486+
indio_dev->masklength);
486487

487-
d_size = ring->scan_count *
488+
d_size = bitmap_weight(indio_dev->active_scan_mask,
489+
indio_dev->masklength) *
488490
indio_dev->channels[0].scan_type.storagebits / 8;
489491

490492
if (ring->scan_timestamp) {
@@ -544,7 +546,7 @@ static irqreturn_t ad7192_trigger_handler(int irq, void *p)
544546
s64 dat64[2];
545547
s32 *dat32 = (s32 *)dat64;
546548

547-
if (ring->scan_count)
549+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
548550
__ad7192_read_reg(st, 1, 1, AD7192_REG_DATA,
549551
dat32,
550552
indio_dev->channels[0].scan_type.realbits/8);

‎drivers/staging/iio/adc/ad7298_ring.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ static int ad7298_ring_preenable(struct iio_dev *indio_dev)
6161
size_t d_size;
6262
int i, m;
6363
unsigned short command;
64-
65-
d_size = ring->scan_count * (AD7298_STORAGE_BITS / 8);
64+
int scan_count = bitmap_weight(indio_dev->active_scan_mask,
65+
indio_dev->masklength);
66+
d_size = scan_count * (AD7298_STORAGE_BITS / 8);
6667

6768
if (ring->scan_timestamp) {
6869
d_size += sizeof(s64);
@@ -79,7 +80,7 @@ static int ad7298_ring_preenable(struct iio_dev *indio_dev)
7980
command = AD7298_WRITE | st->ext_ref;
8081

8182
for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1)
82-
if (test_bit(i, ring->scan_mask))
83+
if (test_bit(i, indio_dev->active_scan_mask))
8384
command |= m;
8485

8586
st->tx_buf[0] = cpu_to_be16(command);
@@ -96,7 +97,7 @@ static int ad7298_ring_preenable(struct iio_dev *indio_dev)
9697
spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg);
9798
spi_message_add_tail(&st->ring_xfer[1], &st->ring_msg);
9899

99-
for (i = 0; i < ring->scan_count; i++) {
100+
for (i = 0; i < scan_count; i++) {
100101
st->ring_xfer[i + 2].rx_buf = &st->rx_buf[i];
101102
st->ring_xfer[i + 2].len = 2;
102103
st->ring_xfer[i + 2].cs_change = 1;
@@ -134,7 +135,8 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
134135
&time_ns, sizeof(time_ns));
135136
}
136137

137-
for (i = 0; i < ring->scan_count; i++)
138+
for (i = 0; i < bitmap_weight(indio_dev->active_scan_mask,
139+
indio_dev->masklength); i++)
138140
buf[i] = be16_to_cpu(st->rx_buf[i]);
139141

140142
indio_dev->buffer->access->store_to(ring, (u8 *)buf, time_ns);

‎drivers/staging/iio/adc/ad7476_ring.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ static int ad7476_ring_preenable(struct iio_dev *indio_dev)
5656
struct ad7476_state *st = iio_priv(indio_dev);
5757
struct iio_buffer *ring = indio_dev->buffer;
5858

59-
st->d_size = ring->scan_count *
59+
st->d_size = bitmap_weight(indio_dev->active_scan_mask,
60+
indio_dev->masklength) *
6061
st->chip_info->channel[0].scan_type.storagebits / 8;
6162

6263
if (ring->scan_timestamp) {

‎drivers/staging/iio/adc/ad7793.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,15 @@ static int ad7793_ring_preenable(struct iio_dev *indio_dev)
342342
size_t d_size;
343343
unsigned channel;
344344

345-
if (!ring->scan_count)
345+
if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
346346
return -EINVAL;
347347

348-
channel = find_first_bit(ring->scan_mask,
348+
channel = find_first_bit(indio_dev->active_scan_mask,
349349
indio_dev->masklength);
350350

351-
d_size = ring->scan_count *
352-
indio_dev->channels[0].scan_type.storagebits / 8;
351+
d_size = bitmap_weight(indio_dev->active_scan_mask,
352+
indio_dev->masklength) *
353+
indio_dev->channels[0].scan_type.storagebits / 8;
353354

354355
if (ring->scan_timestamp) {
355356
d_size += sizeof(s64);
@@ -411,7 +412,7 @@ static irqreturn_t ad7793_trigger_handler(int irq, void *p)
411412
s64 dat64[2];
412413
s32 *dat32 = (s32 *)dat64;
413414

414-
if (ring->scan_count)
415+
if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
415416
__ad7793_read_reg(st, 1, 1, AD7793_REG_DATA,
416417
dat32,
417418
indio_dev->channels[0].scan_type.realbits/8);

0 commit comments

Comments
 (0)