Skip to content

Commit a8acb4d

Browse files
committed
Merge tag 'iio-fixes-for-4.1b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: Second round of fixes for IIO in the 4.1 cycle. * twl6030-gpadc - Drop a bonus space from the modalias. * adis16400 - Report pressure channel scale (not much use without it) - Use different channel indices for the two voltage channels (ABI) - Compute the san mask from the channel indices instead of using ~0UL as we now care about extra bits being set. - Fix burst mode due to rx buffer not being intialized and wrong tx buffer type being set. Also had the wrong transfer length. All in all it didn't work, now it does ;) - adis16448 has additional registers in burst mode so we skip over them to make it work.
2 parents e260818 + e5d7321 commit a8acb4d

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

drivers/iio/adc/twl6030-gpadc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ static struct platform_driver twl6030_gpadc_driver = {
10011001

10021002
module_platform_driver(twl6030_gpadc_driver);
10031003

1004-
MODULE_ALIAS("platform: " DRIVER_NAME);
1004+
MODULE_ALIAS("platform:" DRIVER_NAME);
10051005
MODULE_AUTHOR("Balaji T K <[email protected]>");
10061006
MODULE_AUTHOR("Graeme Gregory <[email protected]>");
10071007
MODULE_AUTHOR("Oleksandr Kozaruk <[email protected]");

drivers/iio/imu/adis16400.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
#define ADIS16400_NO_BURST BIT(1)
140140
#define ADIS16400_HAS_SLOW_MODE BIT(2)
141141
#define ADIS16400_HAS_SERIAL_NUMBER BIT(3)
142+
#define ADIS16400_BURST_DIAG_STAT BIT(4)
142143

143144
struct adis16400_state;
144145

@@ -165,6 +166,7 @@ struct adis16400_state {
165166
int filt_int;
166167

167168
struct adis adis;
169+
unsigned long avail_scan_mask[2];
168170
};
169171

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

drivers/iio/imu/adis16400_buffer.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,38 @@ int adis16400_update_scan_mode(struct iio_dev *indio_dev,
1818
{
1919
struct adis16400_state *st = iio_priv(indio_dev);
2020
struct adis *adis = &st->adis;
21-
uint16_t *tx;
21+
unsigned int burst_length;
22+
u8 *tx;
2223

2324
if (st->variant->flags & ADIS16400_NO_BURST)
2425
return adis_update_scan_mode(indio_dev, scan_mask);
2526

2627
kfree(adis->xfer);
2728
kfree(adis->buffer);
2829

30+
/* All but the timestamp channel */
31+
burst_length = (indio_dev->num_channels - 1) * sizeof(u16);
32+
if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
33+
burst_length += sizeof(u16);
34+
2935
adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
3036
if (!adis->xfer)
3137
return -ENOMEM;
3238

33-
adis->buffer = kzalloc(indio_dev->scan_bytes + sizeof(u16),
34-
GFP_KERNEL);
39+
adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
3540
if (!adis->buffer)
3641
return -ENOMEM;
3742

38-
tx = adis->buffer + indio_dev->scan_bytes;
39-
43+
tx = adis->buffer + burst_length;
4044
tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD);
4145
tx[1] = 0;
4246

4347
adis->xfer[0].tx_buf = tx;
4448
adis->xfer[0].bits_per_word = 8;
4549
adis->xfer[0].len = 2;
46-
adis->xfer[1].tx_buf = tx;
50+
adis->xfer[1].rx_buf = adis->buffer;
4751
adis->xfer[1].bits_per_word = 8;
48-
adis->xfer[1].len = indio_dev->scan_bytes;
52+
adis->xfer[1].len = burst_length;
4953

5054
spi_message_init(&adis->msg);
5155
spi_message_add_tail(&adis->xfer[0], &adis->msg);
@@ -61,6 +65,7 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
6165
struct adis16400_state *st = iio_priv(indio_dev);
6266
struct adis *adis = &st->adis;
6367
u32 old_speed_hz = st->adis.spi->max_speed_hz;
68+
void *buffer;
6469
int ret;
6570

6671
if (!adis->buffer)
@@ -81,7 +86,12 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
8186
spi_setup(st->adis.spi);
8287
}
8388

84-
iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
89+
if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
90+
buffer = adis->buffer + sizeof(u16);
91+
else
92+
buffer = adis->buffer;
93+
94+
iio_push_to_buffers_with_timestamp(indio_dev, buffer,
8595
pf->timestamp);
8696

8797
iio_trigger_notify_done(indio_dev->trig);

drivers/iio/imu/adis16400_core.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
405405
*val = st->variant->temp_scale_nano / 1000000;
406406
*val2 = (st->variant->temp_scale_nano % 1000000);
407407
return IIO_VAL_INT_PLUS_MICRO;
408+
case IIO_PRESSURE:
409+
/* 20 uBar = 0.002kPascal */
410+
*val = 0;
411+
*val2 = 2000;
412+
return IIO_VAL_INT_PLUS_MICRO;
408413
default:
409414
return -EINVAL;
410415
}
@@ -454,10 +459,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
454459
}
455460
}
456461

457-
#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \
462+
#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si, chn) { \
458463
.type = IIO_VOLTAGE, \
459464
.indexed = 1, \
460-
.channel = 0, \
465+
.channel = chn, \
461466
.extend_name = name, \
462467
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
463468
BIT(IIO_CHAN_INFO_SCALE), \
@@ -474,10 +479,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
474479
}
475480

476481
#define ADIS16400_SUPPLY_CHAN(addr, bits) \
477-
ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY)
482+
ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY, 0)
478483

479484
#define ADIS16400_AUX_ADC_CHAN(addr, bits) \
480-
ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC)
485+
ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC, 1)
481486

482487
#define ADIS16400_GYRO_CHAN(mod, addr, bits) { \
483488
.type = IIO_ANGL_VEL, \
@@ -773,7 +778,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
773778
.channels = adis16448_channels,
774779
.num_channels = ARRAY_SIZE(adis16448_channels),
775780
.flags = ADIS16400_HAS_PROD_ID |
776-
ADIS16400_HAS_SERIAL_NUMBER,
781+
ADIS16400_HAS_SERIAL_NUMBER |
782+
ADIS16400_BURST_DIAG_STAT,
777783
.gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */
778784
.accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */
779785
.temp_scale_nano = 73860000, /* 0.07386 C */
@@ -791,11 +797,6 @@ static const struct iio_info adis16400_info = {
791797
.debugfs_reg_access = adis_debugfs_reg_access,
792798
};
793799

794-
static const unsigned long adis16400_burst_scan_mask[] = {
795-
~0UL,
796-
0,
797-
};
798-
799800
static const char * const adis16400_status_error_msgs[] = {
800801
[ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
801802
[ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
@@ -843,6 +844,20 @@ static const struct adis_data adis16400_data = {
843844
BIT(ADIS16400_DIAG_STAT_POWER_LOW),
844845
};
845846

847+
static void adis16400_setup_chan_mask(struct adis16400_state *st)
848+
{
849+
const struct adis16400_chip_info *chip_info = st->variant;
850+
unsigned i;
851+
852+
for (i = 0; i < chip_info->num_channels; i++) {
853+
const struct iio_chan_spec *ch = &chip_info->channels[i];
854+
855+
if (ch->scan_index >= 0 &&
856+
ch->scan_index != ADIS16400_SCAN_TIMESTAMP)
857+
st->avail_scan_mask[0] |= BIT(ch->scan_index);
858+
}
859+
}
860+
846861
static int adis16400_probe(struct spi_device *spi)
847862
{
848863
struct adis16400_state *st;
@@ -866,8 +881,10 @@ static int adis16400_probe(struct spi_device *spi)
866881
indio_dev->info = &adis16400_info;
867882
indio_dev->modes = INDIO_DIRECT_MODE;
868883

869-
if (!(st->variant->flags & ADIS16400_NO_BURST))
870-
indio_dev->available_scan_masks = adis16400_burst_scan_mask;
884+
if (!(st->variant->flags & ADIS16400_NO_BURST)) {
885+
adis16400_setup_chan_mask(st);
886+
indio_dev->available_scan_masks = st->avail_scan_mask;
887+
}
871888

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

0 commit comments

Comments
 (0)