Skip to content

Commit 5eda355

Browse files
larsclausenjic23
authored andcommitted
staging:iio:adis16400: Preallocate transfer message
Similar to like we already did for the generic adis library preallocate and pre-construct the SPI transfer message for the adis16400. For devices which do not support burst mode sampling does not differ from other adis devices and so we use the generic functions of the adis library in this case. In burst mode we can only sample all channels at once, so use the IIO cores demux facility instead of doing this manually. Signed-off-by: Lars-Peter Clausen <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 599acfb commit 5eda355

File tree

3 files changed

+128
-176
lines changed

3 files changed

+128
-176
lines changed

drivers/staging/iio/imu/adis16400.h

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,27 +190,14 @@ ssize_t adis16400_read_data_from_ring(struct device *dev,
190190
char *buf);
191191

192192

193-
int adis16400_configure_ring(struct iio_dev *indio_dev);
194-
void adis16400_unconfigure_ring(struct iio_dev *indio_dev);
193+
int adis16400_update_scan_mode(struct iio_dev *indio_dev,
194+
const unsigned long *scan_mask);
195+
irqreturn_t adis16400_trigger_handler(int irq, void *p);
195196

196197
#else /* CONFIG_IIO_BUFFER */
197198

198-
static inline ssize_t
199-
adis16400_read_data_from_ring(struct device *dev,
200-
struct device_attribute *attr,
201-
char *buf)
202-
{
203-
return 0;
204-
}
205-
206-
static int adis16400_configure_ring(struct iio_dev *indio_dev)
207-
{
208-
return 0;
209-
}
210-
211-
static inline void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
212-
{
213-
}
199+
#define adis16400_update_scan_mode NULL
200+
#define adis16400_trigger_handler NULL
214201

215202
#endif /* CONFIG_IIO_BUFFER */
216203

drivers/staging/iio/imu/adis16400_core.c

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
384384
IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
385385
.address = (addr), \
386386
.scan_index = (si), \
387-
.scan_type = IIO_ST('u', (bits), 16, 0), \
387+
.scan_type = { \
388+
.sign = 'u', \
389+
.realbits = (bits), \
390+
.storagebits = 16, \
391+
.shift = 0, \
392+
.endianness = IIO_BE, \
393+
}, \
388394
}
389395

390396
#define ADIS16400_SUPPLY_CHAN(addr, bits) \
@@ -403,7 +409,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
403409
IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
404410
.address = addr, \
405411
.scan_index = ADIS16400_SCAN_GYRO_ ## mod, \
406-
.scan_type = IIO_ST('s', (bits), 16, 0), \
412+
.scan_type = { \
413+
.sign = 's', \
414+
.realbits = (bits), \
415+
.storagebits = 16, \
416+
.shift = 0, \
417+
.endianness = IIO_BE, \
418+
}, \
407419
}
408420

409421
#define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \
@@ -416,7 +428,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
416428
IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
417429
.address = (addr), \
418430
.scan_index = ADIS16400_SCAN_ACC_ ## mod, \
419-
.scan_type = IIO_ST('s', (bits), 16, 0), \
431+
.scan_type = { \
432+
.sign = 's', \
433+
.realbits = (bits), \
434+
.storagebits = 16, \
435+
.shift = 0, \
436+
.endianness = IIO_BE, \
437+
}, \
420438
}
421439

422440
#define ADIS16400_MAGN_CHAN(mod, addr, bits) { \
@@ -428,7 +446,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
428446
IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
429447
.address = (addr), \
430448
.scan_index = ADIS16400_SCAN_MAGN_ ## mod, \
431-
.scan_type = IIO_ST('s', (bits), 16, 0), \
449+
.scan_type = { \
450+
.sign = 's', \
451+
.realbits = (bits), \
452+
.storagebits = 16, \
453+
.shift = 0, \
454+
.endianness = IIO_BE, \
455+
}, \
432456
}
433457

434458
#define ADIS16400_MOD_TEMP_NAME_X "x"
@@ -446,7 +470,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
446470
IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
447471
.address = (addr), \
448472
.scan_index = ADIS16350_SCAN_TEMP_ ## mod, \
449-
.scan_type = IIO_ST('s', (bits), 16, 0), \
473+
.scan_type = { \
474+
.sign = 's', \
475+
.realbits = (bits), \
476+
.storagebits = 16, \
477+
.shift = 0, \
478+
.endianness = IIO_BE, \
479+
}, \
450480
}
451481

452482
#define ADIS16400_TEMP_CHAN(addr, bits) { \
@@ -458,7 +488,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
458488
IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
459489
.address = (addr), \
460490
.scan_index = ADIS16350_SCAN_TEMP_X, \
461-
.scan_type = IIO_ST('s', (bits), 16, 0), \
491+
.scan_type = { \
492+
.sign = 's', \
493+
.realbits = (bits), \
494+
.storagebits = 16, \
495+
.shift = 0, \
496+
.endianness = IIO_BE, \
497+
}, \
462498
}
463499

464500
#define ADIS16400_INCLI_CHAN(mod, addr, bits) { \
@@ -469,7 +505,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
469505
IIO_CHAN_INFO_SCALE_SHARED_BIT, \
470506
.address = (addr), \
471507
.scan_index = ADIS16300_SCAN_INCLI_ ## mod, \
472-
.scan_type = IIO_ST('s', (bits), 16, 0), \
508+
.scan_type = { \
509+
.sign = 's', \
510+
.realbits = (bits), \
511+
.storagebits = 16, \
512+
.shift = 0, \
513+
.endianness = IIO_BE, \
514+
}, \
473515
}
474516

475517
static const struct iio_chan_spec adis16400_channels[] = {
@@ -625,6 +667,12 @@ static const struct iio_info adis16400_info = {
625667
.read_raw = &adis16400_read_raw,
626668
.write_raw = &adis16400_write_raw,
627669
.attrs = &adis16400_attribute_group,
670+
.update_scan_mode = adis16400_update_scan_mode,
671+
};
672+
673+
static const unsigned long adis16400_burst_scan_mask[] = {
674+
~0UL,
675+
0,
628676
};
629677

630678
static const char * const adis16400_status_error_msgs[] = {
@@ -696,35 +744,30 @@ static int adis16400_probe(struct spi_device *spi)
696744
indio_dev->info = &adis16400_info;
697745
indio_dev->modes = INDIO_DIRECT_MODE;
698746

747+
if (!(st->variant->flags & ADIS16400_NO_BURST))
748+
indio_dev->available_scan_masks = adis16400_burst_scan_mask;
749+
699750
ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data);
700751
if (ret)
701752
goto error_free_dev;
702753

703-
ret = adis16400_configure_ring(indio_dev);
754+
ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev,
755+
adis16400_trigger_handler);
704756
if (ret)
705757
goto error_free_dev;
706758

707-
if (spi->irq) {
708-
ret = adis_probe_trigger(&st->adis, indio_dev);
709-
if (ret)
710-
goto error_unreg_ring_funcs;
711-
}
712-
713759
/* Get the device into a sane initial state */
714760
ret = adis16400_initial_setup(indio_dev);
715761
if (ret)
716-
goto error_remove_trigger;
762+
goto error_cleanup_buffer;
717763
ret = iio_device_register(indio_dev);
718764
if (ret)
719-
goto error_remove_trigger;
765+
goto error_cleanup_buffer;
720766

721767
return 0;
722768

723-
error_remove_trigger:
724-
if (spi->irq)
725-
adis_remove_trigger(&st->adis);
726-
error_unreg_ring_funcs:
727-
adis16400_unconfigure_ring(indio_dev);
769+
error_cleanup_buffer:
770+
adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
728771
error_free_dev:
729772
iio_device_free(indio_dev);
730773
error_ret:
@@ -740,9 +783,7 @@ static int adis16400_remove(struct spi_device *spi)
740783
iio_device_unregister(indio_dev);
741784
adis16400_stop_device(indio_dev);
742785

743-
if (spi->irq)
744-
adis_remove_trigger(&st->adis);
745-
adis16400_unconfigure_ring(indio_dev);
786+
adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
746787

747788
iio_device_free(indio_dev);
748789

0 commit comments

Comments
 (0)