Skip to contentSkip to conversation

iio: accel: adxl367: fix DEVID read after reset

PATCH In review Cosmin Tanislav 3 participants 6 messages Feb 7, 2024 – Feb 25, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 iio: accel: adxl367: fix DEVID read after reset

regmap_read_poll_timeout() will not sleep before reading, causing the first read to return -ENXIO on I2C, since the chip does not respond to it while it is being reset.

The datasheet specifies that a soft reset operation has a latency of 7.5ms.

Add a 15ms sleep between reset and reading the DEVID register, and switch to a simple regmap_read() call.

---
 drivers/iio/accel/adxl367.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iio/accel/adxl367.c +6 -2
index 834ee6d63947..210228affb80 100644
@@ -1368,9 +1368,11 @@ static int adxl367_verify_devid(struct adxl367_state *st)
 	unsigned int val;
 	int ret;
 
-	ret = regmap_read_poll_timeout(st->regmap, ADXL367_REG_DEVID, val,
-				       val == ADXL367_DEVID_AD, 1000, 10000);
+	ret = regmap_read(st->regmap, ADXL367_REG_DEVID, &val);
 	if (ret)
+		return dev_err_probe(st->dev, ret, "Failed to read dev id\n");
+
+	if (val != ADXL367_DEVID_AD)
 		return dev_err_probe(st->dev, -ENODEV,
 				     "Invalid dev id 0x%02X, expected 0x%02X\n",
 				     val, ADXL367_DEVID_AD);
@@ -1449,6 +1451,8 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
 	if (ret)
 		return ret;
 
+	fsleep(15000);
+
 	ret = adxl367_verify_devid(st);
 	if (ret)
 		return ret;
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 iio: accel: adxl367: fix I2C FIFO data register

As specified in the datasheet, the I2C FIFO data register is 0x18, not 0x42. 0x42 was used by mistake when adapting the ADXL372 driver.

Fix this mistake.

---
 drivers/iio/accel/adxl367_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/adxl367_i2c.c +1 -1
index b595fe94f3a3..62c74bdc0d77 100644
@@ -11,7 +11,7 @@
 
 #include "adxl367.h"
 
-#define ADXL367_I2C_FIFO_DATA	0x42
+#define ADXL367_I2C_FIFO_DATA	0x18
 
 struct adxl367_i2c_state {
 	struct regmap *regmap;
Signature · 1 line
2.43.0
Reviewed-by Nuno Sa on v1 2/2
#2 lore raw

Re: [PATCH 2/2] iio: accel: adxl367: fix I2C FIFO data register

Quoted 8 lines · Cosmin Tanislav

As specified in the datasheet, the I2C FIFO data register is 0x18, not 0x42. 0x42 was used by mistake when adapting the ADXL372 driver.

Fix this mistake.

---

This needs a Fixes: tag. With that:

Quoted 16 lines

 drivers/iio/accel/adxl367_i2c.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/adxl367_i2c.c +0 -0
index b595fe94f3a3..62c74bdc0d77 100644
@@ -11,7 +11,7 @@


 #include "adxl367.h"

drivers/iio/accel/adxl367_i2c.c +1 -1
-#define ADXL367_I2C_FIFO_DATA	0x42
+#define ADXL367_I2C_FIFO_DATA	0x18


 struct adxl367_i2c_state {
  struct regmap *regmap;

Reviewed-by Nuno Sa on v1 1/2
#5 lore raw
In reply to Cosmin Tanislav
Quoted 4 lines · Cosmin Tanislav

regmap_read_poll_timeout() will not sleep before reading, causing the first read to return -ENXIO on I2C, since the chip does not respond to it while it is being reset.

Quoted 8 lines

The datasheet specifies that a soft reset operation has a latency of 7.5ms.

Add a 15ms sleep between reset and reading the DEVID register, and switch to a simple regmap_read() call.

---

This likely needs a Fixes: tag as well. With that,

Quoted 34 lines

 drivers/iio/accel/adxl367.c | 8 ++++++--

 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iio/accel/adxl367.c +0 -0
index 834ee6d63947..210228affb80 100644
@@ -1368,9 +1368,11 @@ static int adxl367_verify_devid(struct adxl367_state
 *st)
  	unsigned int val;
  	int ret;

drivers/iio/accel/adxl367.c +1 -2
-	ret = regmap_read_poll_timeout(st->regmap, ADXL367_REG_DEVID, val,
-				       val == ADXL367_DEVID_AD, 1000, 10000);
+	ret = regmap_read(st->regmap, ADXL367_REG_DEVID, &val);

  if (ret)

drivers/iio/accel/adxl367.c +1 -0
+		return dev_err_probe(st->dev, ret, "Failed to read dev

id\n");

drivers/iio/accel/adxl367.c +2 -0
+
+	if (val != ADXL367_DEVID_AD)

  return dev_err_probe(st->dev, -ENODEV, "Invalid dev id 0x%02X, expected 0x%02X\n",
       val, ADXL367_DEVID_AD);

drivers/iio/accel/adxl367.c +0 -0
@@ -1449,6 +1451,8 @@ int adxl367_probe(struct device *dev, const struct
 adxl367_ops *ops,
  	if (ret)
  		return ret;

drivers/iio/accel/adxl367.c +2 -0
+	fsleep(15000);
+

  ret = adxl367_verify_devid(st);
  if (ret)
  return ret;

maintainer
#3 lore raw

Re: [PATCH 2/2] iio: accel: adxl367: fix I2C FIFO data register

In reply to Nuno Sá
Quoted 4 lines · On Wed, 07 Feb 2024 10:08:38 +0100 Nuno Sá <[email protected]> wrote:
Quoted 3 lines · Cosmin Tanislav

As specified in the datasheet, the I2C FIFO data register is 0x18, not 0x42. 0x42 was used by mistake when adapting the ADXL372 driver.

For future reference (not worth a v2): You could wrap a little longer - 75 chars is fine normally for commit messages.

Quoted 9 lines
Quoted 5 lines

Fix this mistake.

---

This needs a Fixes: tag. With that:

Fine to just reply to each of these emails with an appropriate fixes tag - no need for a v2.

Quoted 18 lines
Quoted 17 lines

 drivers/iio/accel/adxl367_i2c.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/adxl367_i2c.c +0 -0
index b595fe94f3a3..62c74bdc0d77 100644
@@ -11,7 +11,7 @@


 #include "adxl367.h"

drivers/iio/accel/adxl367_i2c.c +1 -1
-#define ADXL367_I2C_FIFO_DATA	0x42
+#define ADXL367_I2C_FIFO_DATA	0x18


 struct adxl367_i2c_state {
  struct regmap *regmap;

maintainer
#4 lore raw

Re: [PATCH 2/2] iio: accel: adxl367: fix I2C FIFO data register

Quoted 12 lines · On Sat, 10 Feb 2024 16:57:47 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines · On Wed, 07 Feb 2024 10:08:38 +0100 Nuno Sá <[email protected]> wrote:
Quoted 3 lines · Cosmin Tanislav

As specified in the datasheet, the I2C FIFO data register is 0x18, not 0x42. 0x42 was used by mistake when adapting the ADXL372 driver.

For future reference (not worth a v2): You could wrap a little longer - 75 chars is fine normally for commit messages.

Quoted 3 lines
Quoted 3 lines

Fix this mistake.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

---

This needs a Fixes: tag. With that:

Fine to just reply to each of these emails with an appropriate fixes tag - no need for a v2.

Given these were still in my queue waiting for a fixes tag, I went looking.

Fixes cbab791c5e2a ("iio: accel: add ADXL367 driver")

Both patches added and both applied to the fixes-togreg branch of iio.git

Thanks

Jonathan

Quoted 21 lines
Quoted 19 lines
Quoted 18 lines

 drivers/iio/accel/adxl367_i2c.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/adxl367_i2c.c +0 -0
index b595fe94f3a3..62c74bdc0d77 100644
@@ -11,7 +11,7 @@


 #include "adxl367.h"

drivers/iio/accel/adxl367_i2c.c +1 -1
-#define ADXL367_I2C_FIFO_DATA	0x42
+#define ADXL367_I2C_FIFO_DATA	0x18


 struct adxl367_i2c_state {
  struct regmap *regmap;