Skip to contentSkip to conversation

IIO: GYRO: ADXRS450: Don't issue two messages, use two transfers

PATCH In review [email protected] 2 participants 12 messages Apr 29, 2011

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/6 IIO: GYRO: ADXRS450: Don't issue two messages, use two transfers

From: Michael Hennerich <[email protected]>

Don't issue the same message twice, use two transfers and group them together

---
 drivers/staging/iio/gyro/adxrs450_core.c |   58 ++++++++++++++---------------
 1 files changed, 28 insertions(+), 30 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +28 -30
index dcd88ff..a1a71b7 100644
@@ -40,29 +40,28 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct adxrs450_state *st = iio_dev_get_devdata(indio_dev);
 	int ret;
-	struct spi_transfer xfers = {
-		.tx_buf = st->tx,
-		.rx_buf = st->rx,
-		.bits_per_word = 8,
-		.len = 4,
+	struct spi_transfer xfers[] = {
+		{
+			.tx_buf = st->tx,
+			.bits_per_word = 8,
+			.len = 4,
+			.cs_change = 1,
+		}, {
+			.rx_buf = st->rx,
+			.bits_per_word = 8,
+			.len = 4,
+		},
 	};
-	/* Needs to send the command twice to get the wanted value */
+
 	mutex_lock(&st->buf_lock);
-	st->tx[0] = ADXRS450_READ_DATA | reg_address >> 7;
+	st->tx[0] = ADXRS450_READ_DATA | (reg_address >> 7);
 	st->tx[1] = reg_address << 1;
 	st->tx[2] = 0;
 	st->tx[3] = 0;
-	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
-	ret = spi_sync(st->us, &msg);
-	if (ret) {
-		dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
-				reg_address);
-		goto error_ret;
-	}
 
 	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
+	spi_message_add_tail(&xfers[0], &msg);
+	spi_message_add_tail(&xfers[1], &msg);
 	ret = spi_sync(st->us, &msg);
 	if (ret) {
 		dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
@@ -125,11 +124,17 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct adxrs450_state *st = iio_dev_get_devdata(indio_dev);
 	int ret;
-	struct spi_transfer xfers = {
-		.tx_buf = st->tx,
-		.rx_buf = st->rx,
-		.bits_per_word = 8,
-		.len = 4,
+	struct spi_transfer xfers[] = {
+		{
+			.tx_buf = st->tx,
+			.bits_per_word = 8,
+			.len = 4,
+			.cs_change = 1,
+		}, {
+			.rx_buf = st->rx,
+			.bits_per_word = 8,
+			.len = 4,
+		},
 	};
 
 	mutex_lock(&st->buf_lock);
@@ -139,15 +144,8 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
 	st->tx[3] = 0;
 
 	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
-	ret = spi_sync(st->us, &msg);
-	if (ret) {
-		dev_err(&st->us->dev, "Problem while reading sensor data\n");
-		goto error_ret;
-	}
-
-	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
+	spi_message_add_tail(&xfers[0], &msg);
+	spi_message_add_tail(&xfers[1], &msg);
 	ret = spi_sync(st->us, &msg);
 	if (ret) {
 		dev_err(&st->us->dev, "Problem while reading sensor data\n");

--
1.6.0.2

author maintainer
#1 lore raw

PATCH 2/6 IIO: GYRO: ADXRS450: Cleanup result extraction and update license notice

From: Michael Hennerich <[email protected]>

Cleanup result extraction and update license notice, no functional changes.

---
 drivers/staging/iio/gyro/adxrs450_core.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +4 -3
index a1a71b7..c02e3ef 100644
@@ -3,7 +3,7 @@
  *
  * Copyright 2011 Analog Devices Inc.
  *
- * Licensed under the GPL-2 or later.
+ * Licensed under the GPL-2.
  */
 
 #include <linux/interrupt.h>
@@ -69,7 +69,7 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
 		goto error_ret;
 	}
 
-	*val = (st->rx[1] & 0x1f) << 11 | st->rx[2] << 3 | (st->rx[3] & 0xe0) >> 5;
+	*val = (be32_to_cpu(*(u32 *)st->rx) >> 5) & 0xFFFF;
 
 error_ret:
 	mutex_unlock(&st->buf_lock);
@@ -152,7 +152,8 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
 		goto error_ret;
 	}
 
-	*val = (st->rx[0] & 0x03) << 14 | st->rx[1] << 6 | (st->rx[2] & 0xfc) >> 2;
+	*val = (be32_to_cpu(*(u32 *)st->rx) >> 10) & 0xFFFF;
+
 error_ret:
 	mutex_unlock(&st->buf_lock);
 	return ret;
Signature · 1 line
1.6.0.2
author maintainer
#7 lore raw

PATCH 5/6 IIO: GYRO: ADXRS450: Fix sign issues, properly shift results and limit values

In reply to [email protected]

From: Michael Hennerich <[email protected]>

RATE and QUADRATURE_CORRECTION data is formatted as a twos complement number, and therefore must be handled as type signed short.

TEMP result should be properly shifted.

Dynamic Null Correction is a 10-bit signed number.

---
 drivers/staging/iio/gyro/adxrs450_core.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +5 -5
index d73acff..e71b91c 100644
@@ -126,7 +126,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
  * @dev: device associated with child of actual iio_dev
  * @val: somewhere to pass back the value read
  **/
-static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
+static int adxrs450_spi_sensor_data(struct device *dev, s16 *val)
 {
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
@@ -217,7 +217,7 @@ static ssize_t adxrs450_read_temp(struct device *dev,
 			&t);
 	if (ret)
 		return ret;
-	return sprintf(buf, "%d\n", t);
+	return sprintf(buf, "%d\n", t >> 7);
 }
 
 static ssize_t adxrs450_read_quad(struct device *dev,
@@ -225,7 +225,7 @@ static ssize_t adxrs450_read_quad(struct device *dev,
 		char *buf)
 {
 	int ret;
-	u16 t;
+	s16 t;
 	ret = adxrs450_spi_read_reg_16(dev,
 			ADXRS450_QUAD1,
 			&t);
@@ -247,7 +247,7 @@ static ssize_t adxrs450_write_dnc(struct device *dev,
 		goto error_ret;
 	ret = adxrs450_spi_write_reg_16(dev,
 			ADXRS450_DNC1,
-			val);
+			val & 0x3FF);
 error_ret:
 	return ret ? ret : len;
 }
@@ -257,7 +257,7 @@ static ssize_t adxrs450_read_sensor_data(struct device *dev,
 		char *buf)
 {
 	int ret;
-	u16 t;
+	s16 t;
 
 	ret = adxrs450_spi_sensor_data(dev, &t);
 	if (ret)
Signature · 1 line
1.6.0.2
author maintainer
#9 lore raw

PATCH 6/6 IIO: GYRO: ADXRS450: Don't exit probe, in case the power on default is not met.

In reply to [email protected]

From: Michael Hennerich <[email protected]>

If the part get's probed twice without hard reset in between, the power on default register read-back can't be met. This shouldn't cause the second probe to fail. So warn but don't exit.

---
 drivers/staging/iio/gyro/adxrs450_core.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +3 -5
index e71b91c..7a9d7c2 100644
@@ -278,11 +278,9 @@ static int adxrs450_initial_setup(struct adxrs450_state *st)
 	ret = adxrs450_spi_initial(st, &t, 1);
 	if (ret)
 		return ret;
-	if (t != 0x01) {
-		dev_err(&st->us->dev, "The initial response is not correct!\n");
-		return -ENODEV;
-
-	}
+	if (t != 0x01)
+		dev_warn(&st->us->dev, "The initial power on response "
+			 "is not correct! Restart without reset?\n");
 
 	msleep(ADXRS450_STARTUP_DELAY);
 	ret = adxrs450_spi_initial(st, &t, 0);
Signature · 1 line
1.6.0.2
author maintainer
#3 lore raw

PATCH 3/6 IIO: GYRO: ADXRS450: Add missing parity bit generation

In reply to [email protected]

From: Michael Hennerich <[email protected]>

Add missing parity bit generation. Failure to add the parity bit caused half of the register accesses to fail.

---
 drivers/staging/iio/gyro/adxrs450_core.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +7 -0
index c02e3ef..5671276 100644
@@ -59,6 +59,9 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
 	st->tx[2] = 0;
 	st->tx[3] = 0;
 
+	if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1))
+		st->tx[3]  |= ADXRS450_P;
+
 	spi_message_init(&msg);
 	spi_message_add_tail(&xfers[0], &msg);
 	spi_message_add_tail(&xfers[1], &msg);
@@ -103,6 +106,10 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
 	st->tx[1] = reg_address << 1 | val >> 15;
 	st->tx[2] = val >> 7;
 	st->tx[3] = val << 1;
+
+	if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1))
+		st->tx[3]  |= ADXRS450_P;
+
 	spi_message_init(&msg);
 	spi_message_add_tail(&xfers, &msg);
 	ret = spi_sync(st->us, &msg);
Signature · 1 line
1.6.0.2
author maintainer
#5 lore raw

PATCH 4/6 IIO: GYRO: ADXRS450: enforce sequential transfer delay of at least 0.1ms

In reply to [email protected]

From: Michael Hennerich <[email protected]>

---
 drivers/staging/iio/gyro/adxrs450_core.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +1 -0
index 5671276..d73acff 100644
@@ -116,6 +116,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
 	if (ret)
 		dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n",
 				reg_address);
+	msleep(1); /* enforce sequential transfer delay 0.1ms */
 	mutex_unlock(&st->buf_lock);
 	return ret;
 }
Signature · 1 line
1.6.0.2
Acked-by on v1 1/6
#11 lore raw
In reply to [email protected]
Quoted 5 lines · On 04/29/11 11:58, [email protected] wrote:

From: Michael Hennerich <[email protected]>

Don't issue the same message twice, use two transfers and group them together

Quoted 99 lines
---
 drivers/staging/iio/gyro/adxrs450_core.c |   58 ++++++++++++++---------------
 1 files changed, 28 insertions(+), 30 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +28 -31
index dcd88ff..a1a71b7 100644
@@ -40,29 +40,28 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct adxrs450_state *st = iio_dev_get_devdata(indio_dev);
 	int ret;
-	struct spi_transfer xfers = {
-		.tx_buf = st->tx,
-		.rx_buf = st->rx,
-		.bits_per_word = 8,
-		.len = 4,
+	struct spi_transfer xfers[] = {
+		{
+			.tx_buf = st->tx,
+			.bits_per_word = 8,
+			.len = 4,
+			.cs_change = 1,
+		}, {
+			.rx_buf = st->rx,
+			.bits_per_word = 8,
+			.len = 4,
+		},
 	};
-	/* Needs to send the command twice to get the wanted value */
+
 	mutex_lock(&st->buf_lock);
-	st->tx[0] = ADXRS450_READ_DATA | reg_address >> 7;
+	st->tx[0] = ADXRS450_READ_DATA | (reg_address >> 7);
 	st->tx[1] = reg_address << 1;
 	st->tx[2] = 0;
 	st->tx[3] = 0;
-	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
-	ret = spi_sync(st->us, &msg);
-	if (ret) {
-		dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
-				reg_address);
-		goto error_ret;
-	}
 
 	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
+	spi_message_add_tail(&xfers[0], &msg);
+	spi_message_add_tail(&xfers[1], &msg);
 	ret = spi_sync(st->us, &msg);
 	if (ret) {
 		dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
@@ -125,11 +124,17 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct adxrs450_state *st = iio_dev_get_devdata(indio_dev);
 	int ret;
-	struct spi_transfer xfers = {
-		.tx_buf = st->tx,
-		.rx_buf = st->rx,
-		.bits_per_word = 8,
-		.len = 4,
+	struct spi_transfer xfers[] = {
+		{
+			.tx_buf = st->tx,
+			.bits_per_word = 8,
+			.len = 4,
+			.cs_change = 1,
+		}, {
+			.rx_buf = st->rx,
+			.bits_per_word = 8,
+			.len = 4,
+		},
 	};
 
 	mutex_lock(&st->buf_lock);
@@ -139,15 +144,8 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
 	st->tx[3] = 0;
 
 	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
-	ret = spi_sync(st->us, &msg);
-	if (ret) {
-		dev_err(&st->us->dev, "Problem while reading sensor data\n");
-		goto error_ret;
-	}
-
-	spi_message_init(&msg);
-	spi_message_add_tail(&xfers, &msg);
+	spi_message_add_tail(&xfers[0], &msg);
+	spi_message_add_tail(&xfers[1], &msg);
 	ret = spi_sync(st->us, &msg);
 	if (ret) {
 		dev_err(&st->us->dev, "Problem while reading sensor data\n");
--

1.6.0.2

Acked-by on v1 2/6
#2 lore raw

Re: [PATCH 2/6] IIO: GYRO: ADXRS450: Cleanup result extraction and update license notice

In reply to [email protected]
Quoted 5 lines · On 04/29/11 11:58, [email protected] wrote:

From: Michael Hennerich <[email protected]>

Cleanup result extraction and update license notice, no functional changes.

Quoted 36 lines
---
 drivers/staging/iio/gyro/adxrs450_core.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +4 -3
index a1a71b7..c02e3ef 100644
@@ -3,7 +3,7 @@
  *
  * Copyright 2011 Analog Devices Inc.
  *
- * Licensed under the GPL-2 or later.
+ * Licensed under the GPL-2.
  */
 
 #include <linux/interrupt.h>
@@ -69,7 +69,7 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
 		goto error_ret;
 	}
 
-	*val = (st->rx[1] & 0x1f) << 11 | st->rx[2] << 3 | (st->rx[3] & 0xe0) >> 5;
+	*val = (be32_to_cpu(*(u32 *)st->rx) >> 5) & 0xFFFF;
 
 error_ret:
 	mutex_unlock(&st->buf_lock);
@@ -152,7 +152,8 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
 		goto error_ret;
 	}
 
-	*val = (st->rx[0] & 0x03) << 14 | st->rx[1] << 6 | (st->rx[2] & 0xfc) >> 2;
+	*val = (be32_to_cpu(*(u32 *)st->rx) >> 10) & 0xFFFF;
+
 error_ret:
 	mutex_unlock(&st->buf_lock);
 	return ret;
Acked-by on v1 3/6
#4 lore raw

Re: [PATCH 3/6] IIO: GYRO: ADXRS450: Add missing parity bit generation

In reply to [email protected]
Quoted 4 lines · On 04/29/11 11:58, [email protected] wrote:

From: Michael Hennerich <[email protected]>

Add missing parity bit generation. Failure to add the parity bit caused half of the register accesses to fail.

oops :)

Quoted 2 lines
Quoted 29 lines
---
 drivers/staging/iio/gyro/adxrs450_core.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +7 -0
index c02e3ef..5671276 100644
@@ -59,6 +59,9 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
 	st->tx[2] = 0;
 	st->tx[3] = 0;
 
+	if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1))
+		st->tx[3]  |= ADXRS450_P;
+
 	spi_message_init(&msg);
 	spi_message_add_tail(&xfers[0], &msg);
 	spi_message_add_tail(&xfers[1], &msg);
@@ -103,6 +106,10 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
 	st->tx[1] = reg_address << 1 | val >> 15;
 	st->tx[2] = val >> 7;
 	st->tx[3] = val << 1;
+
+	if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1))
+		st->tx[3]  |= ADXRS450_P;
+
 	spi_message_init(&msg);
 	spi_message_add_tail(&xfers, &msg);
 	ret = spi_sync(st->us, &msg);
Acked-by on v1 4/6
#6 lore raw

Re: [PATCH 4/6] IIO: GYRO: ADXRS450: enforce sequential transfer delay of at least 0.1ms

In reply to [email protected]
Quoted 3 lines · On 04/29/11 11:58, [email protected] wrote:

From: Michael Hennerich <[email protected]>

Fair enough. Nasty hardware requirement of the day award goes to....

Quoted 1 line
Quoted 16 lines
---
 drivers/staging/iio/gyro/adxrs450_core.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +1 -0
index 5671276..d73acff 100644
@@ -116,6 +116,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
 	if (ret)
 		dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n",
 				reg_address);
+	msleep(1); /* enforce sequential transfer delay 0.1ms */
 	mutex_unlock(&st->buf_lock);
 	return ret;
 }
Acked-by on v1 5/6
#8 lore raw

Re: [PATCH 5/6] IIO: GYRO: ADXRS450: Fix sign issues, properly shift results and limit values

In reply to [email protected]
Quoted 10 lines · On 04/29/11 11:58, [email protected] wrote:

From: Michael Hennerich <[email protected]>

RATE and QUADRATURE_CORRECTION data is formatted as a twos complement number, and therefore must be handled as type signed short.

TEMP result should be properly shifted.

Dynamic Null Correction is a 10-bit signed number.

Quoted 53 lines
---
 drivers/staging/iio/gyro/adxrs450_core.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +5 -5
index d73acff..e71b91c 100644
@@ -126,7 +126,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
  * @dev: device associated with child of actual iio_dev
  * @val: somewhere to pass back the value read
  **/
-static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
+static int adxrs450_spi_sensor_data(struct device *dev, s16 *val)
 {
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
@@ -217,7 +217,7 @@ static ssize_t adxrs450_read_temp(struct device *dev,
 			&t);
 	if (ret)
 		return ret;
-	return sprintf(buf, "%d\n", t);
+	return sprintf(buf, "%d\n", t >> 7);
 }
 
 static ssize_t adxrs450_read_quad(struct device *dev,
@@ -225,7 +225,7 @@ static ssize_t adxrs450_read_quad(struct device *dev,
 		char *buf)
 {
 	int ret;
-	u16 t;
+	s16 t;
 	ret = adxrs450_spi_read_reg_16(dev,
 			ADXRS450_QUAD1,
 			&t);
@@ -247,7 +247,7 @@ static ssize_t adxrs450_write_dnc(struct device *dev,
 		goto error_ret;
 	ret = adxrs450_spi_write_reg_16(dev,
 			ADXRS450_DNC1,
-			val);
+			val & 0x3FF);
 error_ret:
 	return ret ? ret : len;
 }
@@ -257,7 +257,7 @@ static ssize_t adxrs450_read_sensor_data(struct device *dev,
 		char *buf)
 {
 	int ret;
-	u16 t;
+	s16 t;
 
 	ret = adxrs450_spi_sensor_data(dev, &t);
 	if (ret)
Acked-by on v1 6/6
#10 lore raw

Re: [PATCH 6/6] IIO: GYRO: ADXRS450: Don't exit probe, in case the power on default is not met.

In reply to [email protected]
Quoted 7 lines · On 04/29/11 11:58, [email protected] wrote:

From: Michael Hennerich <[email protected]>

If the part get's probed twice without hard reset in between, the power on default register read-back can't be met. This shouldn't cause the second probe to fail. So warn but don't exit.

Quoted 23 lines
---
 drivers/staging/iio/gyro/adxrs450_core.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +3 -5
index e71b91c..7a9d7c2 100644
@@ -278,11 +278,9 @@ static int adxrs450_initial_setup(struct adxrs450_state *st)
 	ret = adxrs450_spi_initial(st, &t, 1);
 	if (ret)
 		return ret;
-	if (t != 0x01) {
-		dev_err(&st->us->dev, "The initial response is not correct!\n");
-		return -ENODEV;
-
-	}
+	if (t != 0x01)
+		dev_warn(&st->us->dev, "The initial power on response "
+			 "is not correct! Restart without reset?\n");
 
 	msleep(ADXRS450_STARTUP_DELAY);
 	ret = adxrs450_spi_initial(st, &t, 0);