From: Crestez Dan Leonard <leonard.crestez@intel.com>
To: Jonathan Cameron <jic23@kernel.org>, linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Daniel Baluta <daniel.baluta@intel.com>,
Crestez Dan Leonard <leonard.crestez@intel.com>,
Ge Gao <ggao@invensense.com>, Peter Rosin <peda@axentia.se>,
linux-i2c@vger.kernel.org, Wolfram Sang <wsa@the-dreams.de>,
devicetree@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Kumar Gala <galak@codeaurora.org>
Subject: [PATCH v2 1/7] iio: inv_mpu6050: Do burst reads using spi/i2c directly
Date: Wed, 18 May 2016 18:00:48 +0300 [thread overview]
Message-ID: <b4ba111a1e33f60ed4d3d21421c3250243d40fba.1463582011.git.leonard.crestez@intel.com> (raw)
In-Reply-To: <cover.1463582011.git.leonard.crestez@intel.com>
In-Reply-To: <cover.1463582011.git.leonard.crestez@intel.com>
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
next prev parent reply other threads:[~2016-05-18 15:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-18 15:00 [PATCH v2 0/7] iio: inv_mpu6050: Support i2c master and external readings Crestez Dan Leonard
2016-05-18 15:00 ` Crestez Dan Leonard [this message]
2016-05-29 16:05 ` [PATCH v2 1/7] iio: inv_mpu6050: Do burst reads using spi/i2c directly Jonathan Cameron
2016-05-18 15:00 ` [PATCH v2 2/7] iio: inv_mpu6050: Initial regcache support Crestez Dan Leonard
2016-05-20 2:34 ` Matt Ranostay
[not found] ` <CAKzfze8dDENOvaDf_VH8MRy-HEmCu3q_aGEzD+GYR7B1Ob2rBw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-05-20 6:39 ` Peter Rosin
2016-05-20 11:01 ` Crestez Dan Leonard
2016-05-29 15:27 ` Jonathan Cameron
2016-05-18 15:00 ` [PATCH v2 3/7] iio: inv_mpu6050: Only toggle DATA_RDY_EN in inv_reset_fifo Crestez Dan Leonard
[not found] ` <37946b54fbedeb258f12413a09683c18a8825290.1463582011.git.leonard.crestez-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-05-29 15:29 ` Jonathan Cameron
2016-05-18 15:00 ` [PATCH v2 4/7] iio: inv_mpu6050: Cache non-volatile bits of user_ctrl Crestez Dan Leonard
2016-05-29 15:30 ` Jonathan Cameron
2016-05-18 15:00 ` [RFC v2 5/7] iio: inv_mpu6050: Add support for auxiliary I2C master Crestez Dan Leonard
[not found] ` <2aa92f6390bdb58362755ce9d61f3260f4d77e64.1463582011.git.leonard.crestez-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-05-18 23:46 ` Rob Herring
2016-05-18 15:00 ` [PATCH v2 6/7] iio: inv_mpu6050: Reformat sample for active scan mask Crestez Dan Leonard
2016-05-29 15:47 ` Jonathan Cameron
[not found] ` <14d4a757-f60a-40c0-03b4-c36d1b22d30e-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-05-30 13:44 ` Crestez Dan Leonard
[not found] ` <49c4a235-29fd-aa55-d9d2-8ead5cefd737-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-05-30 21:42 ` Jonathan Cameron
2016-05-31 8:56 ` Crestez Dan Leonard
2016-05-31 16:33 ` Jonathan Cameron
2016-05-18 15:00 ` [RFC v2 7/7] iio: inv_mpu6050: Expose channels from slave sensors Crestez Dan Leonard
2016-05-18 23:49 ` Rob Herring
[not found] ` <fcfd42dc5de104d7535b4181171d9f931d820597.1463582011.git.leonard.crestez-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-05-29 16:03 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b4ba111a1e33f60ed4d3d21421c3250243d40fba.1463582011.git.leonard.crestez@intel.com \
--to=leonard.crestez@intel.com \
--cc=daniel.baluta@intel.com \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=ggao@invensense.com \
--cc=ijc+devicetree@hellion.org.uk \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pawel.moll@arm.com \
--cc=peda@axentia.se \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).