All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] iio: adis16400 fixes
@ 2015-05-15 15:18 Lars-Peter Clausen
  2015-05-15 15:18 ` [PATCH 1/5] iio: adis16400: Report pressure channel scale Lars-Peter Clausen
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2015-05-15 15:18 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Lars-Peter Clausen

Hi,

This series has a couple of fixes for the adis16400 driver, mostly
concerned with the handling of the burst mode which is used by some devices
when running buffered mode.

- Lars

Lars-Peter Clausen (2):
  iio: adis16400: Report pressure channel scale
  iio: adis16400: Fix burst transfer for adis16448

Paul Cercueil (3):
  iio: adis16400: Use != channel indices for the two voltage channels
  iio: adis16400: Compute the scan mask from channel indices
  iio: adis16400: Fix burst mode

 drivers/iio/imu/adis16400.h        |  2 ++
 drivers/iio/imu/adis16400_buffer.c | 26 ++++++++++++++++--------
 drivers/iio/imu/adis16400_core.c   | 41 +++++++++++++++++++++++++++-----------
 3 files changed, 49 insertions(+), 20 deletions(-)

-- 
1.8.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/5] iio: adis16400: Report pressure channel scale
  2015-05-15 15:18 [PATCH 0/5] iio: adis16400 fixes Lars-Peter Clausen
@ 2015-05-15 15:18 ` Lars-Peter Clausen
  2015-05-16  9:56   ` Jonathan Cameron
  2015-05-15 15:18 ` [PATCH 2/5] iio: adis16400: Use != channel indices for the two voltage channels Lars-Peter Clausen
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Lars-Peter Clausen @ 2015-05-15 15:18 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Lars-Peter Clausen

Add the scale for the pressure channel, which is currently missing.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Fixes: 76ada52f7f5d ("iio:adis16400: Add support for the adis16448")
---
 drivers/iio/imu/adis16400_core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index fa795dc..8de6427 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -405,6 +405,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 			*val = st->variant->temp_scale_nano / 1000000;
 			*val2 = (st->variant->temp_scale_nano % 1000000);
 			return IIO_VAL_INT_PLUS_MICRO;
+		case IIO_PRESSURE:
+			/* 20 uBar = 0.002kPascal */
+			*val = 0;
+			*val2 = 2000;
+			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/5] iio: adis16400: Use != channel indices for the two voltage channels
  2015-05-15 15:18 [PATCH 0/5] iio: adis16400 fixes Lars-Peter Clausen
  2015-05-15 15:18 ` [PATCH 1/5] iio: adis16400: Report pressure channel scale Lars-Peter Clausen
@ 2015-05-15 15:18 ` Lars-Peter Clausen
  2015-05-16  9:57   ` Jonathan Cameron
  2015-05-15 15:18 ` [PATCH 3/5] iio: adis16400: Compute the scan mask from channel indices Lars-Peter Clausen
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Lars-Peter Clausen @ 2015-05-15 15:18 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Paul Cercueil, Lars-Peter Clausen

From: Paul Cercueil <paul.cercueil@analog.com>

Previously, the two voltage channels had the same ID, which didn't cause
conflicts in sysfs only because one channel is named and the other isn't;
this is still violating the spec though, two indexed channels should never
have the same index.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/imu/adis16400_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index 8de6427..7b63788 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -459,10 +459,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 	}
 }
 
-#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \
+#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si, chn) { \
 	.type = IIO_VOLTAGE, \
 	.indexed = 1, \
-	.channel = 0, \
+	.channel = chn, \
 	.extend_name = name, \
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
 		BIT(IIO_CHAN_INFO_SCALE), \
@@ -479,10 +479,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 }
 
 #define ADIS16400_SUPPLY_CHAN(addr, bits) \
-	ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY)
+	ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY, 0)
 
 #define ADIS16400_AUX_ADC_CHAN(addr, bits) \
-	ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC)
+	ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC, 1)
 
 #define ADIS16400_GYRO_CHAN(mod, addr, bits) { \
 	.type = IIO_ANGL_VEL, \
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/5] iio: adis16400: Compute the scan mask from channel indices
  2015-05-15 15:18 [PATCH 0/5] iio: adis16400 fixes Lars-Peter Clausen
  2015-05-15 15:18 ` [PATCH 1/5] iio: adis16400: Report pressure channel scale Lars-Peter Clausen
  2015-05-15 15:18 ` [PATCH 2/5] iio: adis16400: Use != channel indices for the two voltage channels Lars-Peter Clausen
@ 2015-05-15 15:18 ` Lars-Peter Clausen
  2015-05-16  9:59   ` Jonathan Cameron
  2015-05-15 15:18 ` [PATCH 4/5] iio: adis16400: Fix burst mode Lars-Peter Clausen
  2015-05-15 15:18 ` [PATCH 5/5] iio: adis16400: Fix burst transfer for adis16448 Lars-Peter Clausen
  4 siblings, 1 reply; 11+ messages in thread
From: Lars-Peter Clausen @ 2015-05-15 15:18 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Paul Cercueil, Lars-Peter Clausen

From: Paul Cercueil <paul.cercueil@analog.com>

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: 5eda3550a3cc ("staging:iio:adis16400: Preallocate transfer message")
---
 drivers/iio/imu/adis16400.h      |  1 +
 drivers/iio/imu/adis16400_core.c | 25 ++++++++++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h
index 0916bf6..1e8fd2e 100644
--- a/drivers/iio/imu/adis16400.h
+++ b/drivers/iio/imu/adis16400.h
@@ -165,6 +165,7 @@ struct adis16400_state {
 	int				filt_int;
 
 	struct adis adis;
+	unsigned long avail_scan_mask[2];
 };
 
 /* At the moment triggers are only used for ring buffer
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index 7b63788..7b06e058 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -796,11 +796,6 @@ static const struct iio_info adis16400_info = {
 	.debugfs_reg_access = adis_debugfs_reg_access,
 };
 
-static const unsigned long adis16400_burst_scan_mask[] = {
-	~0UL,
-	0,
-};
-
 static const char * const adis16400_status_error_msgs[] = {
 	[ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
 	[ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
@@ -848,6 +843,20 @@ static const struct adis_data adis16400_data = {
 		BIT(ADIS16400_DIAG_STAT_POWER_LOW),
 };
 
+static void adis16400_setup_chan_mask(struct adis16400_state *st)
+{
+	const struct adis16400_chip_info *chip_info = st->variant;
+	unsigned i;
+
+	for (i = 0; i < chip_info->num_channels; i++) {
+		const struct iio_chan_spec *ch = &chip_info->channels[i];
+
+		if (ch->scan_index >= 0 &&
+		    ch->scan_index != ADIS16400_SCAN_TIMESTAMP)
+			st->avail_scan_mask[0] |= BIT(ch->scan_index);
+	}
+}
+
 static int adis16400_probe(struct spi_device *spi)
 {
 	struct adis16400_state *st;
@@ -871,8 +880,10 @@ static int adis16400_probe(struct spi_device *spi)
 	indio_dev->info = &adis16400_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	if (!(st->variant->flags & ADIS16400_NO_BURST))
-		indio_dev->available_scan_masks = adis16400_burst_scan_mask;
+	if (!(st->variant->flags & ADIS16400_NO_BURST)) {
+		adis16400_setup_chan_mask(st);
+		indio_dev->available_scan_masks = st->avail_scan_mask;
+	}
 
 	ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data);
 	if (ret)
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/5] iio: adis16400: Fix burst mode
  2015-05-15 15:18 [PATCH 0/5] iio: adis16400 fixes Lars-Peter Clausen
                   ` (2 preceding siblings ...)
  2015-05-15 15:18 ` [PATCH 3/5] iio: adis16400: Compute the scan mask from channel indices Lars-Peter Clausen
@ 2015-05-15 15:18 ` Lars-Peter Clausen
  2015-05-16 10:00   ` Jonathan Cameron
  2015-05-15 15:18 ` [PATCH 5/5] iio: adis16400: Fix burst transfer for adis16448 Lars-Peter Clausen
  4 siblings, 1 reply; 11+ messages in thread
From: Lars-Peter Clausen @ 2015-05-15 15:18 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Paul Cercueil, Lars-Peter Clausen

From: Paul Cercueil <paul.cercueil@analog.com>

There are a few issues with the burst mode support. For one we don't setup
the rx buffer, so the buffer will never be filled and all samples will read
as the zero. Furthermore the tx buffer has the wrong type, which means the
driver sends the wrong command and not the right data is returned.

The final issue is that in burst mode all channels are transferred. Hence
the length of the transfer length should be the number of hardware
channels * 2 bytes. Currently the driver uses indio_dev->scan_bytes for
this. But if the timestamp channel is enabled the scan_bytes will be larger
than the burst length. Fix this by just calculating the burst length based
on the number of hardware channels.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Fixes: 5eda3550a3cc ("staging:iio:adis16400: Preallocate transfer message")
---
 drivers/iio/imu/adis16400_buffer.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/imu/adis16400_buffer.c b/drivers/iio/imu/adis16400_buffer.c
index 6e727ff..629ae84 100644
--- a/drivers/iio/imu/adis16400_buffer.c
+++ b/drivers/iio/imu/adis16400_buffer.c
@@ -18,7 +18,8 @@ int adis16400_update_scan_mode(struct iio_dev *indio_dev,
 {
 	struct adis16400_state *st = iio_priv(indio_dev);
 	struct adis *adis = &st->adis;
-	uint16_t *tx;
+	unsigned int burst_length;
+	u8 *tx;
 
 	if (st->variant->flags & ADIS16400_NO_BURST)
 		return adis_update_scan_mode(indio_dev, scan_mask);
@@ -26,26 +27,27 @@ int adis16400_update_scan_mode(struct iio_dev *indio_dev,
 	kfree(adis->xfer);
 	kfree(adis->buffer);
 
+	/* All but the timestamp channel */
+	burst_length = (indio_dev->num_channels - 1) * sizeof(u16);
+
 	adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
 	if (!adis->xfer)
 		return -ENOMEM;
 
-	adis->buffer = kzalloc(indio_dev->scan_bytes + sizeof(u16),
-		GFP_KERNEL);
+	adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
 	if (!adis->buffer)
 		return -ENOMEM;
 
-	tx = adis->buffer + indio_dev->scan_bytes;
-
+	tx = adis->buffer + burst_length;
 	tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD);
 	tx[1] = 0;
 
 	adis->xfer[0].tx_buf = tx;
 	adis->xfer[0].bits_per_word = 8;
 	adis->xfer[0].len = 2;
-	adis->xfer[1].tx_buf = tx;
+	adis->xfer[1].rx_buf = adis->buffer;
 	adis->xfer[1].bits_per_word = 8;
-	adis->xfer[1].len = indio_dev->scan_bytes;
+	adis->xfer[1].len = burst_length;
 
 	spi_message_init(&adis->msg);
 	spi_message_add_tail(&adis->xfer[0], &adis->msg);
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/5] iio: adis16400: Fix burst transfer for adis16448
  2015-05-15 15:18 [PATCH 0/5] iio: adis16400 fixes Lars-Peter Clausen
                   ` (3 preceding siblings ...)
  2015-05-15 15:18 ` [PATCH 4/5] iio: adis16400: Fix burst mode Lars-Peter Clausen
@ 2015-05-15 15:18 ` Lars-Peter Clausen
  2015-05-16 10:01   ` Jonathan Cameron
  4 siblings, 1 reply; 11+ messages in thread
From: Lars-Peter Clausen @ 2015-05-15 15:18 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Lars-Peter Clausen

The adis16448, unlike the other chips in this family, in addition to the
hardware channels also sends out the DIAG_STAT register in burst mode
before them. Handle that case by skipping over the first 2 bytes before we
pass the received data to the buffer.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Fixes: 76ada52f7f5d ("iio:adis16400: Add support for the adis16448")
---
 drivers/iio/imu/adis16400.h        |  1 +
 drivers/iio/imu/adis16400_buffer.c | 10 +++++++++-
 drivers/iio/imu/adis16400_core.c   |  3 ++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h
index 1e8fd2e..73b189c 100644
--- a/drivers/iio/imu/adis16400.h
+++ b/drivers/iio/imu/adis16400.h
@@ -139,6 +139,7 @@
 #define ADIS16400_NO_BURST		BIT(1)
 #define ADIS16400_HAS_SLOW_MODE		BIT(2)
 #define ADIS16400_HAS_SERIAL_NUMBER	BIT(3)
+#define ADIS16400_BURST_DIAG_STAT	BIT(4)
 
 struct adis16400_state;
 
diff --git a/drivers/iio/imu/adis16400_buffer.c b/drivers/iio/imu/adis16400_buffer.c
index 629ae84..90c24a2 100644
--- a/drivers/iio/imu/adis16400_buffer.c
+++ b/drivers/iio/imu/adis16400_buffer.c
@@ -29,6 +29,8 @@ int adis16400_update_scan_mode(struct iio_dev *indio_dev,
 
 	/* All but the timestamp channel */
 	burst_length = (indio_dev->num_channels - 1) * sizeof(u16);
+	if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
+		burst_length += sizeof(u16);
 
 	adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
 	if (!adis->xfer)
@@ -63,6 +65,7 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
 	struct adis16400_state *st = iio_priv(indio_dev);
 	struct adis *adis = &st->adis;
 	u32 old_speed_hz = st->adis.spi->max_speed_hz;
+	void *buffer;
 	int ret;
 
 	if (!adis->buffer)
@@ -83,7 +86,12 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
 		spi_setup(st->adis.spi);
 	}
 
-	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
+	if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
+		buffer = adis->buffer + sizeof(u16);
+	else
+		buffer = adis->buffer;
+
+	iio_push_to_buffers_with_timestamp(indio_dev, buffer,
 		pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index 7b06e058..2fd68f22 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -778,7 +778,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.channels = adis16448_channels,
 		.num_channels = ARRAY_SIZE(adis16448_channels),
 		.flags = ADIS16400_HAS_PROD_ID |
-				ADIS16400_HAS_SERIAL_NUMBER,
+				ADIS16400_HAS_SERIAL_NUMBER |
+				ADIS16400_BURST_DIAG_STAT,
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */
 		.temp_scale_nano = 73860000, /* 0.07386 C */
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] iio: adis16400: Report pressure channel scale
  2015-05-15 15:18 ` [PATCH 1/5] iio: adis16400: Report pressure channel scale Lars-Peter Clausen
@ 2015-05-16  9:56   ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2015-05-16  9:56 UTC (permalink / raw)
  To: Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald; +Cc: linux-iio

On 15/05/15 16:18, Lars-Peter Clausen wrote:
> Add the scale for the pressure channel, which is currently missing.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Fixes: 76ada52f7f5d ("iio:adis16400: Add support for the adis16448")
Applied to the fixes branch of iio.git and marked for stable.
> ---
>  drivers/iio/imu/adis16400_core.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
> index fa795dc..8de6427 100644
> --- a/drivers/iio/imu/adis16400_core.c
> +++ b/drivers/iio/imu/adis16400_core.c
> @@ -405,6 +405,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
>  			*val = st->variant->temp_scale_nano / 1000000;
>  			*val2 = (st->variant->temp_scale_nano % 1000000);
>  			return IIO_VAL_INT_PLUS_MICRO;
> +		case IIO_PRESSURE:
> +			/* 20 uBar = 0.002kPascal */
> +			*val = 0;
> +			*val2 = 2000;
> +			return IIO_VAL_INT_PLUS_MICRO;
>  		default:
>  			return -EINVAL;
>  		}
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5] iio: adis16400: Use != channel indices for the two voltage channels
  2015-05-15 15:18 ` [PATCH 2/5] iio: adis16400: Use != channel indices for the two voltage channels Lars-Peter Clausen
@ 2015-05-16  9:57   ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2015-05-16  9:57 UTC (permalink / raw)
  To: Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Paul Cercueil

On 15/05/15 16:18, Lars-Peter Clausen wrote:
> From: Paul Cercueil <paul.cercueil@analog.com>
> 
> Previously, the two voltage channels had the same ID, which didn't cause
> conflicts in sysfs only because one channel is named and the other isn't;
> this is still violating the spec though, two indexed channels should never
> have the same index.
> 
> Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to fixes-togreg branch, marked for stable.
> ---
>  drivers/iio/imu/adis16400_core.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
> index 8de6427..7b63788 100644
> --- a/drivers/iio/imu/adis16400_core.c
> +++ b/drivers/iio/imu/adis16400_core.c
> @@ -459,10 +459,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
>  	}
>  }
>  
> -#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \
> +#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si, chn) { \
>  	.type = IIO_VOLTAGE, \
>  	.indexed = 1, \
> -	.channel = 0, \
> +	.channel = chn, \
>  	.extend_name = name, \
>  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
>  		BIT(IIO_CHAN_INFO_SCALE), \
> @@ -479,10 +479,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
>  }
>  
>  #define ADIS16400_SUPPLY_CHAN(addr, bits) \
> -	ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY)
> +	ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY, 0)
>  
>  #define ADIS16400_AUX_ADC_CHAN(addr, bits) \
> -	ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC)
> +	ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC, 1)
>  
>  #define ADIS16400_GYRO_CHAN(mod, addr, bits) { \
>  	.type = IIO_ANGL_VEL, \
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/5] iio: adis16400: Compute the scan mask from channel indices
  2015-05-15 15:18 ` [PATCH 3/5] iio: adis16400: Compute the scan mask from channel indices Lars-Peter Clausen
@ 2015-05-16  9:59   ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2015-05-16  9:59 UTC (permalink / raw)
  To: Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Paul Cercueil

On 15/05/15 16:18, Lars-Peter Clausen wrote:
> From: Paul Cercueil <paul.cercueil@analog.com>
> 
> 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: 5eda3550a3cc ("staging:iio:adis16400: Preallocate transfer message")
Applied to the fixes-togreg branch, marked for stable.
> ---
>  drivers/iio/imu/adis16400.h      |  1 +
>  drivers/iio/imu/adis16400_core.c | 25 ++++++++++++++++++-------
>  2 files changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h
> index 0916bf6..1e8fd2e 100644
> --- a/drivers/iio/imu/adis16400.h
> +++ b/drivers/iio/imu/adis16400.h
> @@ -165,6 +165,7 @@ struct adis16400_state {
>  	int				filt_int;
>  
>  	struct adis adis;
> +	unsigned long avail_scan_mask[2];
>  };
>  
>  /* At the moment triggers are only used for ring buffer
> diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
> index 7b63788..7b06e058 100644
> --- a/drivers/iio/imu/adis16400_core.c
> +++ b/drivers/iio/imu/adis16400_core.c
> @@ -796,11 +796,6 @@ static const struct iio_info adis16400_info = {
>  	.debugfs_reg_access = adis_debugfs_reg_access,
>  };
>  
> -static const unsigned long adis16400_burst_scan_mask[] = {
> -	~0UL,
> -	0,
> -};
> -
>  static const char * const adis16400_status_error_msgs[] = {
>  	[ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
>  	[ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
> @@ -848,6 +843,20 @@ static const struct adis_data adis16400_data = {
>  		BIT(ADIS16400_DIAG_STAT_POWER_LOW),
>  };
>  
> +static void adis16400_setup_chan_mask(struct adis16400_state *st)
> +{
> +	const struct adis16400_chip_info *chip_info = st->variant;
> +	unsigned i;
> +
> +	for (i = 0; i < chip_info->num_channels; i++) {
> +		const struct iio_chan_spec *ch = &chip_info->channels[i];
> +
> +		if (ch->scan_index >= 0 &&
> +		    ch->scan_index != ADIS16400_SCAN_TIMESTAMP)
> +			st->avail_scan_mask[0] |= BIT(ch->scan_index);
> +	}
> +}
> +
>  static int adis16400_probe(struct spi_device *spi)
>  {
>  	struct adis16400_state *st;
> @@ -871,8 +880,10 @@ static int adis16400_probe(struct spi_device *spi)
>  	indio_dev->info = &adis16400_info;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  
> -	if (!(st->variant->flags & ADIS16400_NO_BURST))
> -		indio_dev->available_scan_masks = adis16400_burst_scan_mask;
> +	if (!(st->variant->flags & ADIS16400_NO_BURST)) {
> +		adis16400_setup_chan_mask(st);
> +		indio_dev->available_scan_masks = st->avail_scan_mask;
> +	}
>  
>  	ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data);
>  	if (ret)
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] iio: adis16400: Fix burst mode
  2015-05-15 15:18 ` [PATCH 4/5] iio: adis16400: Fix burst mode Lars-Peter Clausen
@ 2015-05-16 10:00   ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2015-05-16 10:00 UTC (permalink / raw)
  To: Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald
  Cc: linux-iio, Paul Cercueil

On 15/05/15 16:18, Lars-Peter Clausen wrote:
> From: Paul Cercueil <paul.cercueil@analog.com>
> 
> There are a few issues with the burst mode support. For one we don't setup
> the rx buffer, so the buffer will never be filled and all samples will read
> as the zero. Furthermore the tx buffer has the wrong type, which means the
> driver sends the wrong command and not the right data is returned.
> 
> The final issue is that in burst mode all channels are transferred. Hence
> the length of the transfer length should be the number of hardware
> channels * 2 bytes. Currently the driver uses indio_dev->scan_bytes for
> this. But if the timestamp channel is enabled the scan_bytes will be larger
> than the burst length. Fix this by just calculating the burst length based
> on the number of hardware channels.
> 
> Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Fixes: 5eda3550a3cc ("staging:iio:adis16400: Preallocate transfer message")
Yikes, just goes to show I haven't plugged in the test device I have for quite
some time!

Anyhow, applied to the fixes-togreg branch of iio.git. Marked for stable.
> ---
>  drivers/iio/imu/adis16400_buffer.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/imu/adis16400_buffer.c b/drivers/iio/imu/adis16400_buffer.c
> index 6e727ff..629ae84 100644
> --- a/drivers/iio/imu/adis16400_buffer.c
> +++ b/drivers/iio/imu/adis16400_buffer.c
> @@ -18,7 +18,8 @@ int adis16400_update_scan_mode(struct iio_dev *indio_dev,
>  {
>  	struct adis16400_state *st = iio_priv(indio_dev);
>  	struct adis *adis = &st->adis;
> -	uint16_t *tx;
> +	unsigned int burst_length;
> +	u8 *tx;
>  
>  	if (st->variant->flags & ADIS16400_NO_BURST)
>  		return adis_update_scan_mode(indio_dev, scan_mask);
> @@ -26,26 +27,27 @@ int adis16400_update_scan_mode(struct iio_dev *indio_dev,
>  	kfree(adis->xfer);
>  	kfree(adis->buffer);
>  
> +	/* All but the timestamp channel */
> +	burst_length = (indio_dev->num_channels - 1) * sizeof(u16);
> +
>  	adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
>  	if (!adis->xfer)
>  		return -ENOMEM;
>  
> -	adis->buffer = kzalloc(indio_dev->scan_bytes + sizeof(u16),
> -		GFP_KERNEL);
> +	adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
>  	if (!adis->buffer)
>  		return -ENOMEM;
>  
> -	tx = adis->buffer + indio_dev->scan_bytes;
> -
> +	tx = adis->buffer + burst_length;
>  	tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD);
>  	tx[1] = 0;
>  
>  	adis->xfer[0].tx_buf = tx;
>  	adis->xfer[0].bits_per_word = 8;
>  	adis->xfer[0].len = 2;
> -	adis->xfer[1].tx_buf = tx;
> +	adis->xfer[1].rx_buf = adis->buffer;
>  	adis->xfer[1].bits_per_word = 8;
> -	adis->xfer[1].len = indio_dev->scan_bytes;
> +	adis->xfer[1].len = burst_length;
>  
>  	spi_message_init(&adis->msg);
>  	spi_message_add_tail(&adis->xfer[0], &adis->msg);
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 5/5] iio: adis16400: Fix burst transfer for adis16448
  2015-05-15 15:18 ` [PATCH 5/5] iio: adis16400: Fix burst transfer for adis16448 Lars-Peter Clausen
@ 2015-05-16 10:01   ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2015-05-16 10:01 UTC (permalink / raw)
  To: Lars-Peter Clausen, Hartmut Knaack, Peter Meerwald; +Cc: linux-iio

On 15/05/15 16:18, Lars-Peter Clausen wrote:
> The adis16448, unlike the other chips in this family, in addition to the
> hardware channels also sends out the DIAG_STAT register in burst mode
> before them. Handle that case by skipping over the first 2 bytes before we
> pass the received data to the buffer.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Fixes: 76ada52f7f5d ("iio:adis16400: Add support for the adis16448")
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan
> ---
>  drivers/iio/imu/adis16400.h        |  1 +
>  drivers/iio/imu/adis16400_buffer.c | 10 +++++++++-
>  drivers/iio/imu/adis16400_core.c   |  3 ++-
>  3 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h
> index 1e8fd2e..73b189c 100644
> --- a/drivers/iio/imu/adis16400.h
> +++ b/drivers/iio/imu/adis16400.h
> @@ -139,6 +139,7 @@
>  #define ADIS16400_NO_BURST		BIT(1)
>  #define ADIS16400_HAS_SLOW_MODE		BIT(2)
>  #define ADIS16400_HAS_SERIAL_NUMBER	BIT(3)
> +#define ADIS16400_BURST_DIAG_STAT	BIT(4)
>  
>  struct adis16400_state;
>  
> diff --git a/drivers/iio/imu/adis16400_buffer.c b/drivers/iio/imu/adis16400_buffer.c
> index 629ae84..90c24a2 100644
> --- a/drivers/iio/imu/adis16400_buffer.c
> +++ b/drivers/iio/imu/adis16400_buffer.c
> @@ -29,6 +29,8 @@ int adis16400_update_scan_mode(struct iio_dev *indio_dev,
>  
>  	/* All but the timestamp channel */
>  	burst_length = (indio_dev->num_channels - 1) * sizeof(u16);
> +	if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
> +		burst_length += sizeof(u16);
>  
>  	adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
>  	if (!adis->xfer)
> @@ -63,6 +65,7 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
>  	struct adis16400_state *st = iio_priv(indio_dev);
>  	struct adis *adis = &st->adis;
>  	u32 old_speed_hz = st->adis.spi->max_speed_hz;
> +	void *buffer;
>  	int ret;
>  
>  	if (!adis->buffer)
> @@ -83,7 +86,12 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
>  		spi_setup(st->adis.spi);
>  	}
>  
> -	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
> +	if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
> +		buffer = adis->buffer + sizeof(u16);
> +	else
> +		buffer = adis->buffer;
> +
> +	iio_push_to_buffers_with_timestamp(indio_dev, buffer,
>  		pf->timestamp);
>  
>  	iio_trigger_notify_done(indio_dev->trig);
> diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
> index 7b06e058..2fd68f22 100644
> --- a/drivers/iio/imu/adis16400_core.c
> +++ b/drivers/iio/imu/adis16400_core.c
> @@ -778,7 +778,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
>  		.channels = adis16448_channels,
>  		.num_channels = ARRAY_SIZE(adis16448_channels),
>  		.flags = ADIS16400_HAS_PROD_ID |
> -				ADIS16400_HAS_SERIAL_NUMBER,
> +				ADIS16400_HAS_SERIAL_NUMBER |
> +				ADIS16400_BURST_DIAG_STAT,
>  		.gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */
>  		.accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */
>  		.temp_scale_nano = 73860000, /* 0.07386 C */
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-05-16 10:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-15 15:18 [PATCH 0/5] iio: adis16400 fixes Lars-Peter Clausen
2015-05-15 15:18 ` [PATCH 1/5] iio: adis16400: Report pressure channel scale Lars-Peter Clausen
2015-05-16  9:56   ` Jonathan Cameron
2015-05-15 15:18 ` [PATCH 2/5] iio: adis16400: Use != channel indices for the two voltage channels Lars-Peter Clausen
2015-05-16  9:57   ` Jonathan Cameron
2015-05-15 15:18 ` [PATCH 3/5] iio: adis16400: Compute the scan mask from channel indices Lars-Peter Clausen
2015-05-16  9:59   ` Jonathan Cameron
2015-05-15 15:18 ` [PATCH 4/5] iio: adis16400: Fix burst mode Lars-Peter Clausen
2015-05-16 10:00   ` Jonathan Cameron
2015-05-15 15:18 ` [PATCH 5/5] iio: adis16400: Fix burst transfer for adis16448 Lars-Peter Clausen
2015-05-16 10:01   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.