Skip to content

Commit c2a8b62

Browse files
Paul Cercueiljic23
Paul Cercueil
authored andcommitted
iio: adis16400: Compute the scan mask from channel indices
We unfortunately can't use ~0UL for the scan mask to indicate that the only valid scan mask is all channels selected. The IIO core needs the exact mask to work correctly and not a super-set of it. So calculate the masked based on the channels that are available for a particular device. Signed-off-by: Paul Cercueil <paul.cercueil@analog.com> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Fixes: 5eda355 ("staging:iio:adis16400: Preallocate transfer message") Cc: <stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 7323d59 commit c2a8b62

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

drivers/iio/imu/adis16400.h

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct adis16400_state {
165165
int filt_int;
166166

167167
struct adis adis;
168+
unsigned long avail_scan_mask[2];
168169
};
169170

170171
/* At the moment triggers are only used for ring buffer

drivers/iio/imu/adis16400_core.c

+18-7
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,6 @@ static const struct iio_info adis16400_info = {
796796
.debugfs_reg_access = adis_debugfs_reg_access,
797797
};
798798

799-
static const unsigned long adis16400_burst_scan_mask[] = {
800-
~0UL,
801-
0,
802-
};
803-
804799
static const char * const adis16400_status_error_msgs[] = {
805800
[ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
806801
[ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
@@ -848,6 +843,20 @@ static const struct adis_data adis16400_data = {
848843
BIT(ADIS16400_DIAG_STAT_POWER_LOW),
849844
};
850845

846+
static void adis16400_setup_chan_mask(struct adis16400_state *st)
847+
{
848+
const struct adis16400_chip_info *chip_info = st->variant;
849+
unsigned i;
850+
851+
for (i = 0; i < chip_info->num_channels; i++) {
852+
const struct iio_chan_spec *ch = &chip_info->channels[i];
853+
854+
if (ch->scan_index >= 0 &&
855+
ch->scan_index != ADIS16400_SCAN_TIMESTAMP)
856+
st->avail_scan_mask[0] |= BIT(ch->scan_index);
857+
}
858+
}
859+
851860
static int adis16400_probe(struct spi_device *spi)
852861
{
853862
struct adis16400_state *st;
@@ -871,8 +880,10 @@ static int adis16400_probe(struct spi_device *spi)
871880
indio_dev->info = &adis16400_info;
872881
indio_dev->modes = INDIO_DIRECT_MODE;
873882

874-
if (!(st->variant->flags & ADIS16400_NO_BURST))
875-
indio_dev->available_scan_masks = adis16400_burst_scan_mask;
883+
if (!(st->variant->flags & ADIS16400_NO_BURST)) {
884+
adis16400_setup_chan_mask(st);
885+
indio_dev->available_scan_masks = st->avail_scan_mask;
886+
}
876887

877888
ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data);
878889
if (ret)

0 commit comments

Comments
 (0)