diff mbox series

[v4,6/6] iio: accel: fxls8962af: fix errata bug E3 - I2C burst reads

Message ID 20210429122806.3814330-6-sean@geanix.com (mailing list archive)
State New, archived
Headers show
Series [v4,1/6] iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers | expand

Commit Message

Sean Nyekjaer April 29, 2021, 12:28 p.m. UTC
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>
---
Changes from RFC:
 - using i2c_verify_client() to detect if hw is connected on I2C bus

 drivers/iio/accel/fxls8962af-core.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

Andy Shevchenko April 30, 2021, 9:14 a.m. UTC | #1
On Thu, Apr 29, 2021 at 3:28 PM Sean Nyekjaer <sean@geanix.com> wrote:
>
> When flushing the hw fifo there is a bug in the I2C that prevents burst
> reads of more than one sample pair.

...

> -       ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB, buffer,
> -                             total_length);
> +       if (i2c_verify_client(dev)) {
> +               /*
> +                * 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);
> +                       if (ret < 0)
> +                               goto out;
> +               }

Can you rather create a separate function called
fxls8962af_i2c_raw_read_errata3() and use it here by simply

  if (i2c)
    ret = fxls8962af_i2c_raw_read_errata3();
  else
    ret = regmap_raw_read();

?

> +       } else {
> +               ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB, buffer,
> +                                     total_length);
> +       }
diff mbox series

Patch

diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c
index 2e863ef71a7d..e45c9e88bf6e 100644
--- a/drivers/iio/accel/fxls8962af-core.c
+++ b/drivers/iio/accel/fxls8962af-core.c
@@ -14,6 +14,7 @@ 
 
 #include <linux/bits.h>
 #include <linux/bitfield.h>
+#include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/of_irq.h>
 #include <linux/pm_runtime.h>
@@ -631,11 +632,28 @@  static int fxls8962af_fifo_transfer(struct fxls8962af_data *data,
 {
 	struct device *dev = regmap_get_device(data->regmap);
 	int sample_length = 3 * sizeof(*buffer);
-	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 (i2c_verify_client(dev)) {
+		/*
+		 * 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);
+			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);