driver, iio, mpuxxx: increase spi speed to 20Mhz when read sensor data
authorZorro Liu <lyx@rock-chips.com>
Thu, 16 Jun 2016 09:56:50 +0000 (17:56 +0800)
committerZorro Liu <lyx@rock-chips.com>
Thu, 16 Jun 2016 09:59:59 +0000 (17:59 +0800)
Change-Id: Ic8088d26ba87386d39014e6ca25f1b43865af914
Signed-off-by: Zorro Liu <lyx@rock-chips.com>
drivers/staging/iio/imu/inv_mpu/inv_mpu_spi.c

index 410bbd9a26cb5e1627e96db30fff46bded1796b4..5642d2715020647b11354034456bee182283ce24 100644 (file)
@@ -43,6 +43,7 @@ static int inv_spi_read(struct inv_mpu_iio_s *st, u8 reg, int len, u8 *data)
        struct spi_message msg;
        int res;
        u8 d[2];
+       struct spi_device *spi = to_spi_device(st->dev);
        struct spi_transfer xfers[] = {
                {
                        .tx_buf = d,
@@ -61,10 +62,15 @@ static int inv_spi_read(struct inv_mpu_iio_s *st, u8 reg, int len, u8 *data)
 
        d[0] = (reg | INV_SPI_READ);
 
+       if ((reg == REG_FIFO_R_W) || (reg == FIFO_COUNT_BYTE))
+               spi->max_speed_hz = 20000000;
+       else
+               spi->max_speed_hz = 1000000;
+
        spi_message_init(&msg);
        spi_message_add_tail(&xfers[0], &msg);
        spi_message_add_tail(&xfers[1], &msg);
-       res = spi_sync(to_spi_device(st->dev), &msg);
+       res = spi_sync(spi, &msg);
 
        return res;
 }
@@ -74,6 +80,7 @@ static int inv_spi_single_write(struct inv_mpu_iio_s *st, u8 reg, u8 data)
        struct spi_message msg;
        int res;
        u8 d[2];
+       struct spi_device *spi = to_spi_device(st->dev);
        struct spi_transfer xfers = {
                .tx_buf = d,
                .bits_per_word = 8,
@@ -82,6 +89,7 @@ static int inv_spi_single_write(struct inv_mpu_iio_s *st, u8 reg, u8 data)
 
        d[0] = reg;
        d[1] = data;
+       spi->max_speed_hz = 1000000;
        spi_message_init(&msg);
        spi_message_add_tail(&xfers, &msg);
        res = spi_sync(to_spi_device(st->dev), &msg);