Partially revert "staging:iio:gyro:adxrs450 make more use of spi_read and spi_write."
Subsystems (4)
PATCH 1/11 Partially revert "staging:iio:gyro:adxrs450 make more use of spi_read and spi_write."
This partially reverts commit cb4496876f03631eff913b3c608c964d48d61eb9. There is no apparent reason why we should split a transaction which consists out of multiple transfers into multiple transactions each having one transfer. While this works it introduces a bunch of unnecessary context switch and additional setup costs.
--- drivers/staging/iio/gyro/adxrs450_core.c | 48 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +34 -14
@@ -34,8 +34,21 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,u8 reg_address, u16 *val) { + struct spi_message msg;struct adxrs450_state *st =iio_priv (indio_dev);int ret; +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); st->tx[0 ] =ADXRS450_READ_DATA | (reg_address >>7 );
@@ -46,13 +59,10 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,if (!(hweight32 (be32_to_cpu (*(u32 *)st->tx)) &1 )) st->tx[3 ] |=ADXRS450_P ; - ret =spi_write (st->us, st->tx,4 ); -if (ret) { -dev_err (&st->us->dev,"problem while reading 16 bit register 0x%02x\n" , - reg_address); - goto error_ret; - } - ret =spi_read (st->us, st->rx,4 ); +spi_message_init (&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" , reg_address);
@@ -105,8 +115,21 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,**/ static int adxrs450_spi_sensor_data (struct iio_dev *indio_dev,s16 *val) { +struct spi_message msg;struct adxrs450_state *st =iio_priv (indio_dev);int ret; +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); st->tx[0 ] =ADXRS450_SENSOR_DATA ;
@@ -114,13 +137,10 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) st->tx[2 ] =0 ; st->tx[3 ] =0 ; - ret =spi_write (st->us, st->tx,4 ); -if (ret) { -dev_err (&st->us->dev,"Problem while reading sensor data\n" ); - goto error_ret; - } - - ret =spi_read (st->us, st->rx,4 ); +spi_message_init (&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" ); goto error_ret;
Signature · 1 line
1.8.0
PATCH 2/11 staging:iio:adxrs450: Make transfer buffers __be32
Fixes the following sparse warnings:
drivers/staging/iio/gyro/adxrs450_core.c:46:15: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:62:17: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:89:15: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:129:17: warning: cast to restricted __be32 drivers/staging/iio/gyro/adxrs450_core.c:168:16: warning: cast to restricted __be32
--- drivers/staging/iio/gyro/adxrs450.h | 10 ++--- drivers/staging/iio/gyro/adxrs450_core.c | 66 +++++++++++++++----------------- 2 files changed, 35 insertions(+), 41 deletions(-)
drivers/staging/iio/gyro/adxrs450.h +5 -5
@@ -4,9 +4,9 @@#define ADXRS450_STARTUP_DELAY 50/* ms */ /* The MSB for the spi commands */ -#define ADXRS450_SENSOR_DATA 0x20 -#define ADXRS450_WRITE_DATA 0x40 -#define ADXRS450_READ_DATA 0x80 +#define ADXRS450_SENSOR_DATA (0x20 << 24) +#define ADXRS450_WRITE_DATA (0x40 << 24) +#define ADXRS450_READ_DATA (0x80 << 24)#define ADXRS450_RATE1 0x00/* Rate Registers */ #define ADXRS450_TEMP1 0x02/* Temperature Registers */
@@ -54,8 +54,8 @@ enum {struct adxrs450_state {struct spi_device *us;struct mutex buf_lock; -u8 tx[ADXRS450_MAX_RX ]____cacheline_aligned ; -u8 rx[ADXRS450_MAX_TX ]; +__be32 tx____cacheline_aligned ; +__be32 rx; };
drivers/staging/iio/gyro/adxrs450_core.c +30 -36
140 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 3/11 staging:iio:adxrs450: Perform sign extension for the calibbias register
In reply to Lars-Peter ClausenThe calibbias (DNC) register contains a 10-bit twos complement value. Perform a proper sign extension when reading the register, otherwise negative will incorrectly be displayed as large positive values.
--- drivers/staging/iio/gyro/adxrs450_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/gyro/adxrs450_core.c +1 -1
@@ -326,7 +326,7 @@ static int adxrs450_read_raw(struct iio_dev *indio_dev, ret =adxrs450_spi_read_reg_16 (indio_dev,ADXRS450_DNC1 , &t);if (ret)break ; - *val = t; + *val =sign_extend32 (t,9 ); ret =IIO_VAL_INT ;break ;default :
Signature · 1 line
1.8.0
PATCH 4/11 staging:iio:adxrs450: Reject out of range calibscale values
In reply to Lars-Peter ClausenInstead of silently discarding the upper bits reject out of range values for the calibscale property.
--- drivers/staging/iio/gyro/adxrs450_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +3 -2
@@ -258,9 +258,10 @@ static int adxrs450_write_raw(struct iio_dev *indio_dev,int ret;switch (mask) {case IIO_CHAN_INFO_CALIBBIAS : +if (val <-0x400 || val >=0x400 ) +return -EINVAL ; ret =adxrs450_spi_write_reg_16 (indio_dev, -ADXRS450_DNC1 , - val &0x3FF ); +ADXRS450_DNC1 , val);break ;default : ret = -EINVAL ;
Signature · 1 line
1.8.0
PATCH 5/11 staging:iio:adxrs450: Don't spam the bootlog
In reply to Lars-Peter ClausenDon't spam the bootlog with the devices part id and serial number.
--- drivers/staging/iio/gyro/adxrs450_core.c | 14 -------------- 1 file changed, 14 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +0 -14
@@ -231,20 +231,6 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev)dev_err (&st->us->dev,"The device is not in normal status!\n" );return -EINVAL ; } - ret =adxrs450_spi_read_reg_16 (indio_dev,ADXRS450_PID1 , &data); -if (ret) -return ret; -dev_info (&st->us->dev,"The Part ID is 0x%x\n" , data); - - ret =adxrs450_spi_read_reg_16 (indio_dev,ADXRS450_SNL , &data); -if (ret) -return ret; - t = data; - ret =adxrs450_spi_read_reg_16 (indio_dev,ADXRS450_SNH , &data); -if (ret) -return ret; - t |= data <<16 ; -dev_info (&st->us->dev,"The Serial Number is 0x%x\n" , t);return 0 ; }
Signature · 1 line
1.8.0
PATCH 6/11 staging:iio:adxrs450: Reflow overlong lines
In reply to Lars-Peter ClausenReflow two lines to meet the 80 characters per line limit.
Fixes the following checkpatch warnings:
WARNING: line over 80 characters
#29: FILE: staging/iio/gyro/adxrs450_core.c:29:
+ * @reg_address: the address of the lower of the two registers,which should be an even address,
WARNING: line over 80 characters
#81: FILE: staging/iio/gyro/adxrs450_core.c:81:
+ * @reg_address: the address of the lower of the two registers,which should be an even address,
--- drivers/staging/iio/gyro/adxrs450_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +4 -4
@@ -26,8 +26,8 @@/** * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair * @dev: device associated with child of actual iio_dev -* @reg_address: the address of the lower of the two registers,which should be an even address, -* Second register's address is reg_address + 1. +* @reg_address: the address of the lower of the two registers, which should be +* an even address, the second register's address is reg_address + 1. * @val: somewhere to pass back the value read **/ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,
@@ -78,8 +78,8 @@ error_ret:/** * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair * @dev: device associated with child of actual actual iio_dev -* @reg_address: the address of the lower of the two registers,which should be an even address, -* Second register's address is reg_address + 1. +* @reg_address: the address of the lower of the two registers,which should be +* an even address, the second register's address is reg_address + 1. * @val: value to be written. **/ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,
Signature · 1 line
1.8.0
PATCH 7/11 staging:iio:adxrs450: Don't split string across multiple lines
In reply to Lars-Peter ClausenThis is one of the exceptions to the 80 chars per line rule since breaking the string in half it badly affects the grep-ability.
Fixes the following checkpatch warning:
WARNING: quoted string split across lines #203: FILE: staging/iio/gyro/adxrs450_core.c:203: + dev_warn(&st->us->dev, "The initial power on response " + "is not correct! Restart without reset?\n");
--- drivers/staging/iio/gyro/adxrs450_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +1 -2
@@ -199,8 +199,7 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev)if (ret)return ret;if (t !=0x01 ) -dev_warn (&st->us->dev,"The initial power on response " -"is not correct! Restart without reset?\n" ); +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.8.0
PATCH 8/11 staging:iio:adxrs450: Use usleep_range for the sequential transfer dealy
In reply to Lars-Peter ClausenThe adxrs450 requires a delay of at least 0.1 ms between register writes. Using msleep() for such small delays is not recommended. So use usleep_range instead.
Fixes the following checkpatch warning:
WARNING: msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt + msleep(1);
--- drivers/staging/iio/gyro/adxrs450_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/gyro/adxrs450_core.c +1 -1
@@ -101,7 +101,7 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_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 */ +usleep_range (100 ,1000 );/* enforce sequential transfer delay 0.1ms */ mutex_unlock (&st->buf_lock);return ret; }
Signature · 1 line
1.8.0
PATCH 9/11 staging:iio:adxrs450: Fixup kernel doc comments
In reply to Lars-Peter ClausenFix the name of the iio_device parameter for a few functions and add documentation for one missing function parameter.
--- drivers/staging/iio/gyro/adxrs450_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/iio/gyro/adxrs450_core.c +4 -3
@@ -25,7 +25,7 @@/** * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair -* @dev: device associated with child of actual iio_dev +* @indio_dev: device associated with child of actual iio_dev * @reg_address: the address of the lower of the two registers, which should be * an even address, the second register's address is reg_address + 1. * @val: somewhere to pass back the value read
@@ -77,7 +77,7 @@ error_ret:/** * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair -* @dev: device associated with child of actual actual iio_dev +* @indio_dev: device associated with child of actual actual iio_dev * @reg_address: the address of the lower of the two registers,which should be * an even address, the second register's address is reg_address + 1. * @val: value to be written.
@@ -108,7 +108,7 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,/** * adxrs450_spi_sensor_data() - read 2 bytes sensor data -* @dev: device associated with child of actual iio_dev +* @indio_dev: device associated with child of actual iio_dev * @val: somewhere to pass back the value read **/ static int adxrs450_spi_sensor_data (struct iio_dev *indio_dev,s16 *val)
@@ -152,6 +152,7 @@ error_ret:* adxrs450_spi_initial() - use for initializing procedure. * @st: device instance specific data * @val: somewhere to pass back the value read +* @chk: Whether to perform fault check **/ static int adxrs450_spi_initial (struct adxrs450_state *st,u32 *val,char chk)
Signature · 1 line
1.8.0
PATCH 10/11 staging:iio:adxrs450: Move header file contents to main file
In reply to Lars-Peter ClausenThe contents of the adxrs450 header file is not used outside the main drivers file, so just move the contents from the header file into the drivers main file. Also rename the adxrs450 driver file from adxrs450_core.c to adxrs450.c.
---
drivers/staging/iio/gyro/Makefile | 1 -
.../iio/gyro/{adxrs450_core.c => adxrs450.c} | 58 +++++++++++++++++++-
drivers/staging/iio/gyro/adxrs450.h | 62 ----------------------
3 files changed, 57 insertions(+), 64 deletions(-)
rename drivers/staging/iio/gyro/{adxrs450_core.c => adxrs450.c} (86%)
delete mode 100644 drivers/staging/iio/gyro/adxrs450.hdrivers/staging/iio/gyro/Makefile +0 -1
@@ -8,5 +8,4 @@ obj-$(CONFIG_ADIS16060) += adis16060.o adis16260-y := adis16260_core.o obj-$(CONFIG_ADIS16260) += adis16260.o -adxrs450-y := adxrs450_core.o obj-$(CONFIG_ADXRS450) += adxrs450.o
drivers/staging/iio/gyro/adxrs450.c renamed from drivers/staging/iio/gyro/adxrs450_core.c +57 -1
64 lines not on this page · raw message
drivers/staging/iio/gyro/adxrs450.h deleted +0 -62
62 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 11/11 staging:iio: Move adxrs450 driver out of staging
In reply to Lars-Peter ClausenThe adxrs450 is in a reasonable shape now. It follows the IIO ABI and non of the standard code checker tools report any issue, so move it out of staging.
---
drivers/iio/gyro/Kconfig | 10 ++++++++++
drivers/iio/gyro/Makefile | 1 +
drivers/{staging => }/iio/gyro/adxrs450.c | 0
drivers/staging/iio/gyro/Kconfig | 10 ----------
drivers/staging/iio/gyro/Makefile | 2 --
5 files changed, 11 insertions(+), 12 deletions(-)
rename drivers/{staging => }/iio/gyro/adxrs450.c (100%)drivers/iio/gyro/Kconfig +10 -0
@@ -26,6 +26,16 @@ config ADIS16136 Say yes here to build support for the Analog Devices ADIS16133, ADIS16135, ADIS16136 gyroscope devices. +config ADXRS450 + tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADXRS450 and ADXRS453 + programmable digital output gyroscope. + + This driver can also be built as a module. If so, the module + will be called adxrs450. + config HID_SENSOR_GYRO_3D depends on HID_SENSOR_HUB select IIO_BUFFER
drivers/iio/gyro/Makefile +1 -0
@@ -5,4 +5,5 @@ obj-$(CONFIG_ADIS16080) += adis16080.o obj-$(CONFIG_ADIS16130) += adis16130.o obj-$(CONFIG_ADIS16136) += adis16136.o +obj-$(CONFIG_ADXRS450) += adxrs450.o obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
drivers/iio/gyro/adxrs450.c renamed from drivers/staging/iio/gyro/adxrs450.c +0 -0
drivers/staging/iio/gyro/Kconfig +0 -10
@@ -22,14 +22,4 @@ config ADIS16260 This driver can also be built as a module. If so, the module will be called adis16260. -config ADXRS450 - tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver" - depends on SPI - help - Say yes here to build support for Analog Devices ADXRS450 and ADXRS453 - programmable digital output gyroscope. - - This driver can also be built as a module. If so, the module - will be called adxrs450. - endmenu
drivers/staging/iio/gyro/Makefile +0 -2
@@ -7,5 +7,3 @@ obj-$(CONFIG_ADIS16060) += adis16060.o adis16260-y := adis16260_core.o obj-$(CONFIG_ADIS16260) += adis16260.o - -obj-$(CONFIG_ADXRS450) += adxrs450.o
Signature · 1 line
1.8.0
Jonathan Cameron
maintainerQuoted 7 lines · Lars-Peter Clausen
This partially reverts commit
cb4496876f03631eff913b3c608c964d48d61eb9. There is no apparent reason why we should split a transaction which consists out of multiple transfers into multiple transactions each having one transfer. While this works it introduces a bunch of unnecessary context switch and additional setup costs.Signed-off-by Lars-Peter Clausen <[email protected]>
Whole series applied to togreg branch of iio.git.
Thanks,
Quoted 89 lines
--- drivers/staging/iio/gyro/adxrs450_core.c | 48 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-)drivers/staging/iio/gyro/adxrs450_core.c +34
-14@@ -34,8 +34,21 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,u8 reg_address, u16 *val) { + struct spi_message msg;struct adxrs450_state *st =iio_priv (indio_dev);int ret; +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); st->tx[0 ] =ADXRS450_READ_DATA | (reg_address >>7 );@@ -46,13 +59,10 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,if (!(hweight32 (be32_to_cpu (*(u32 *)st->tx)) &1 )) st->tx[3 ] |=ADXRS450_P ; - ret =spi_write (st->us, st->tx,4 ); -if (ret) { -dev_err (&st->us->dev,"problem while reading 16 bit register 0x%02x\n" , - reg_address); - goto error_ret; - } - ret =spi_read (st->us, st->rx,4 ); +spi_message_init (&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" , reg_address);@@ -105,8 +115,21 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,**/ static int adxrs450_spi_sensor_data (struct iio_dev *indio_dev,s16 *val) { +struct spi_message msg;struct adxrs450_state *st =iio_priv (indio_dev);int ret; +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); st->tx[0 ] =ADXRS450_SENSOR_DATA ;@@ -114,13 +137,10 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) st->tx[2 ] =0 ; st->tx[3 ] =0 ; - ret =spi_write (st->us, st->tx,4 ); -if (ret) { -dev_err (&st->us->dev,"Problem while reading sensor data\n" ); - goto error_ret; - } - - ret =spi_read (st->us, st->rx,4 ); +spi_message_init (&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" ); goto error_ret;