devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Nyekjaer <sean@geanix.com>
To: jic23@kernel.org, linux-iio@vger.kernel.org,
	andy.shevchenko@gmail.com, lars@metafoo.de, Nuno.Sa@analog.com,
	robh+dt@kernel.org, devicetree@vger.kernel.org
Cc: Sean Nyekjaer <sean@geanix.com>
Subject: [RFC PATCH 4/4] iio: accel: fxls8962af: fix errata bug E3 - I2C burst reads
Date: Wed, 28 Apr 2021 10:22:03 +0200	[thread overview]
Message-ID: <20210428082203.3587022-4-sean@geanix.com> (raw)
In-Reply-To: <20210428082203.3587022-1-sean@geanix.com>

When flushing the hw fifo there is a bug in the I2C that prevents burst
reads of more than one sample pair.

Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
This series depends on "iio: accel: add support for
FXLS8962AF/FXLS8964AF accelerometers"

 drivers/iio/accel/fxls8962af-core.c | 27 +++++++++++++++++++++++----
 drivers/iio/accel/fxls8962af-i2c.c  |  2 +-
 drivers/iio/accel/fxls8962af-spi.c  |  2 +-
 drivers/iio/accel/fxls8962af.h      |  2 +-
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c
index 2bd5c6d76b63..fad9e756d313 100644
--- a/drivers/iio/accel/fxls8962af-core.c
+++ b/drivers/iio/accel/fxls8962af-core.c
@@ -149,6 +149,7 @@ struct fxls8962af_data {
 		__le16 channels[3];
 		s64 ts __aligned(8);
 	} scan;
+	bool i2c_device;
 	int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
 	struct iio_mount_matrix orientation;
 };
@@ -684,11 +685,27 @@ static int fxls8962af_fifo_transfer(struct fxls8962af_data *data,
 {
 	struct device *dev = regmap_get_device(data->regmap);
 	int sample_length = 3 * 2;
-	int ret;
+	int ret, i;
 	int total_length = samples * sample_length;
 
-	ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB, buffer,
-			      total_length);
+	if (data->i2c_device) {
+		/* Due to errata bug:
+		 * E3: FIFO burst read operation error using I2C interface
+		 * We have to avoid burst reads on I2C..
+		 */
+		for (i = 0; i < samples; i++) {
+			ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB,
+					      &buffer[i * sample_length],
+					      sample_length);
+			if (ret < 0)
+				goto out;
+		}
+	} else {
+		ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB, buffer,
+				      total_length);
+	}
+
+ out:
 	if (ret < 0)
 		dev_err(dev, "Error transferring data from fifo: %d\n", ret);
 
@@ -899,7 +916,8 @@ static int fxls8962af_irq_setup(struct iio_dev *indio_dev, int irq)
 	return ret;
 }
 
-int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
+int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq,
+			  bool i2c_device)
 {
 	struct fxls8962af_data *data;
 	struct iio_dev *indio_dev;
@@ -913,6 +931,7 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
 	data = iio_priv(indio_dev);
 	dev_set_drvdata(dev, indio_dev);
 	data->regmap = regmap;
+	data->i2c_device = i2c_device;
 
 	ret = iio_read_mount_matrix(dev, "mount-matrix", &data->orientation);
 	if (ret)
diff --git a/drivers/iio/accel/fxls8962af-i2c.c b/drivers/iio/accel/fxls8962af-i2c.c
index cba12160a714..03bd7ef285d0 100644
--- a/drivers/iio/accel/fxls8962af-i2c.c
+++ b/drivers/iio/accel/fxls8962af-i2c.c
@@ -24,7 +24,7 @@ static int fxls8962af_probe(struct i2c_client *client)
 		return PTR_ERR(regmap);
 	}
 
-	return fxls8962af_core_probe(&client->dev, regmap, client->irq);
+	return fxls8962af_core_probe(&client->dev, regmap, client->irq, true);
 }
 
 static const struct i2c_device_id fxls8962af_id[] = {
diff --git a/drivers/iio/accel/fxls8962af-spi.c b/drivers/iio/accel/fxls8962af-spi.c
index cb971b76d135..77186220f6dc 100644
--- a/drivers/iio/accel/fxls8962af-spi.c
+++ b/drivers/iio/accel/fxls8962af-spi.c
@@ -24,7 +24,7 @@ static int fxls8962af_probe(struct spi_device *spi)
 		return PTR_ERR(regmap);
 	}
 
-	return fxls8962af_core_probe(&spi->dev, regmap, spi->irq);
+	return fxls8962af_core_probe(&spi->dev, regmap, spi->irq, false);
 }
 
 static const struct of_device_id fxls8962af_spi_of_match[] = {
diff --git a/drivers/iio/accel/fxls8962af.h b/drivers/iio/accel/fxls8962af.h
index b67572c3ef06..e428163926b7 100644
--- a/drivers/iio/accel/fxls8962af.h
+++ b/drivers/iio/accel/fxls8962af.h
@@ -13,7 +13,7 @@ enum {
 	fxls8964af,
 };
 
-int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq);
+int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq, bool i2c_device);
 int fxls8962af_core_remove(struct device *dev);
 
 extern const struct dev_pm_ops fxls8962af_pm_ops;
-- 
2.31.0


  parent reply	other threads:[~2021-04-28  8:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28  8:22 [RFC PATCH 1/4] dt-bindings: iio: accel: fxls8962af: add interrupt options Sean Nyekjaer
2021-04-28  8:22 ` [RFC PATCH 2/4] iio: accel: fxls8962af: add interrupt support Sean Nyekjaer
2021-04-28 14:26   ` Jonathan Cameron
2021-04-29  8:58   ` Lars-Peter Clausen
2021-04-29  9:35     ` Andy Shevchenko
2021-04-29  9:37       ` Lars-Peter Clausen
2021-04-29 11:35         ` Andy Shevchenko
2021-04-29 19:19           ` Lars-Peter Clausen
2021-04-30  8:54             ` Andy Shevchenko
2021-04-28  8:22 ` [RFC PATCH 3/4] iio: accel: fxls8962af: add hw buffered sampling Sean Nyekjaer
2021-04-28 11:05   ` Sean Nyekjaer
2021-04-28 13:53     ` Jonathan Cameron
2021-04-28 16:32   ` Jonathan Cameron
2021-04-29  7:40     ` Sean Nyekjaer
2021-04-29 14:52       ` Jonathan Cameron
2021-04-28  8:22 ` Sean Nyekjaer [this message]
2021-04-28 11:24   ` [RFC PATCH 4/4] iio: accel: fxls8962af: fix errata bug E3 - I2C burst reads Andy Shevchenko
2021-04-28 11:37     ` Sean Nyekjaer
2021-04-28 13:56 ` [RFC PATCH 1/4] dt-bindings: iio: accel: fxls8962af: add interrupt options Jonathan Cameron
2021-05-03 19:21 ` Rob Herring

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=20210428082203.3587022-4-sean@geanix.com \
    --to=sean@geanix.com \
    --cc=Nuno.Sa@analog.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /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).