Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1391339
| From | Crestez Dan Leonard <leonard.crestez@intel.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/7] iio: inv_mpu6050: Do burst reads using spi/i2c directly |
| Date | 2016-04-29 21:10 +0200 |
| Message-ID | <rtlXA-2Jp-13@gated-at.bofh.it> (permalink) |
| References | <rtlXz-2Jp-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Using regmap_read_bulk is wrong because it assumes that a range of
registers is being read. In our case reading from the fifo register will
return multiple values but this is *not* auto-increment.
This currently works by accident.
Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 33 ++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
index d070062..8455af0 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
@@ -21,6 +21,7 @@
#include <linux/interrupt.h>
#include <linux/kfifo.h>
#include <linux/poll.h>
+#include <linux/spi/spi.h>
#include "inv_mpu_iio.h"
static void inv_clear_kfifo(struct inv_mpu6050_state *st)
@@ -128,6 +129,13 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
u16 fifo_count;
s64 timestamp;
+ struct device *regmap_dev = regmap_get_device(st->map);
+ struct i2c_client *i2c;
+ struct spi_device *spi = NULL;
+
+ i2c = i2c_verify_client(regmap_dev);
+ spi = i2c ? NULL: to_spi_device(regmap_dev);
+
mutex_lock(&indio_dev->mlock);
if (!(st->chip_config.accl_fifo_enable |
st->chip_config.gyro_fifo_enable))
@@ -160,10 +168,27 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
fifo_count / bytes_per_datum + INV_MPU6050_TIME_STAMP_TOR)
goto flush_fifo;
while (fifo_count >= bytes_per_datum) {
- result = regmap_bulk_read(st->map, st->reg->fifo_r_w,
- data, bytes_per_datum);
- if (result)
- goto flush_fifo;
+ /*
+ * We need to do a large burst read from a single register.
+ *
+ * regmap_read_bulk assumes that multiple registers are
+ * involved but in our case st->reg->fifo_r_w + 1 is something
+ * completely unrelated.
+ */
+ if (spi) {
+ u8 cmd = st->reg->fifo_r_w | 0x80;
+ result = spi_write_then_read(spi,
+ &cmd, 1,
+ data, bytes_per_datum);
+ if (result)
+ goto flush_fifo;
+ } else {
+ result = i2c_smbus_read_i2c_block_data(i2c,
+ st->reg->fifo_r_w,
+ bytes_per_datum, data);
+ if (result != bytes_per_datum)
+ goto flush_fifo;
+ }
result = kfifo_out(&st->timestamps, ×tamp, 1);
/* when there is no timestamp, put timestamp as 0 */
--
2.5.5
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC 0/7] iio: inv_mpu6050: Support i2c master and external readings Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
[RFC 5/7] iio: inv_mpu6050: Add support for auxiliary I2C master Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
Re: [RFC 5/7] iio: inv_mpu6050: Add support for auxiliary I2C master Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:40 +0200
Re: [RFC 5/7] iio: inv_mpu6050: Add support for auxiliary I2C master Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-05-05 14:40 +0200
Re: [RFC 5/7] iio: inv_mpu6050: Add support for auxiliary I2C master Rob Herring <robh+dt@kernel.org> - 2016-05-05 15:20 +0200
Re: [RFC 5/7] iio: inv_mpu6050: Add support for auxiliary I2C master Peter Rosin <peda@axentia.se> - 2016-05-02 17:40 +0200
[PATCH 4/7] iio: inv_mpu6050: Cache non-volatile bits of user_ctrl Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
Re: [PATCH 4/7] iio: inv_mpu6050: Cache non-volatile bits of user_ctrl Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:40 +0200
[PATCH 6/7] iio: inv_mpu6050: Check channel configuration on preenable Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
Re: [PATCH 6/7] iio: inv_mpu6050: Check channel configuration on preenable Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:30 +0200
Re: [PATCH 6/7] iio: inv_mpu6050: Check channel configuration on preenable Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-05-03 15:10 +0200
Re: [PATCH 6/7] iio: inv_mpu6050: Check channel configuration on preenable Jonathan Cameron <jic23@kernel.org> - 2016-05-04 16:40 +0200
Re: [PATCH 6/7] iio: inv_mpu6050: Check channel configuration on preenable Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-05-04 17:40 +0200
Re: [PATCH 6/7] iio: inv_mpu6050: Check channel configuration on preenable Jonathan Cameron <jic23@jic23.retrosnub.co.uk> - 2016-05-04 20:30 +0200
[PATCH 1/7] iio: inv_mpu6050: Do burst reads using spi/i2c directly Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
Re: [PATCH 1/7] iio: inv_mpu6050: Do burst reads using spi/i2c directly Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:30 +0200
Re: [PATCH 1/7] iio: inv_mpu6050: Do burst reads using spi/i2c directly Mark Brown <broonie@kernel.org> - 2016-05-02 17:30 +0200
[RFC 7/7] iio: inv_mpu6050: Add support for external sensors Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
Re: [RFC 7/7] iio: inv_mpu6050: Add support for external sensors Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:40 +0200
[PATCH 3/7] iio: inv_mpu6050: Only toggle DATA_RDY_EN in inv_reset_fifo Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
Re: [PATCH 3/7] iio: inv_mpu6050: Only toggle DATA_RDY_EN in inv_reset_fifo Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:30 +0200
[PATCH 2/7] iio: inv_mpu6050: Initial regcache support Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-29 21:10 +0200
Re: [PATCH 2/7] iio: inv_mpu6050: Initial regcache support Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:40 +0200
Re: [RFC 0/7] iio: inv_mpu6050: Support i2c master and external readings Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:40 +0200
Re: [RFC 0/7] iio: inv_mpu6050: Support i2c master and external readings Mark Brown <broonie@kernel.org> - 2016-05-02 17:30 +0200
Re: [RFC 0/7] iio: inv_mpu6050: Support i2c master and external readings Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-05-03 13:30 +0200
Re: [RFC 0/7] iio: inv_mpu6050: Support i2c master and external readings Mark Brown <broonie@kernel.org> - 2016-05-03 13:40 +0200
csiph-web