linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: inv_mpu6050: test whoami against invalid values and do it first
@ 2017-05-12 12:45 Jean-Baptiste Maneyrol
  2017-05-14 14:49 ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Jean-Baptiste Maneyrol @ 2017-05-12 12:45 UTC (permalink / raw)
  To: linux-iio@vger.kernel.org

SPI bus is never generating error during transfer, so a simple way to check
if a chip is correctly connected on a SPI bus is to check a fixed value lik=
e
whoami against valid values. 0x00 or 0xff can never happened. It is better
to do this test first since if there is a problem with a DTS and an incorre=
ct
chip is wired instead, a write can be more damaging than a read.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/i=
nv_mpu6050/inv_mpu_core.c
index 96dabbd..42fb135 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -774,23 +774,28 @@ static int inv_check_and_setup_chip(struct inv_mpu605=
0_state *st)
 	st->hw  =3D &hw_info[st->chip_type];
 	st->reg =3D hw_info[st->chip_type].reg;
=20
-	/* reset to make sure previous state are not there */
-	result =3D regmap_write(st->map, st->reg->pwr_mgmt_1,
-			      INV_MPU6050_BIT_H_RESET);
-	if (result)
-		return result;
-	msleep(INV_MPU6050_POWER_UP_TIME);
-
 	/* check chip self-identification */
 	result =3D regmap_read(st->map, INV_MPU6050_REG_WHOAMI, &regval);
 	if (result)
 		return result;
 	if (regval !=3D st->hw->whoami) {
+		if (regval =3D=3D 0x00 || regval =3D=3D 0xff) {
+			dev_err(regmap_get_device(st->map),
+					"invalid whoami probably io error\n");
+			return -EIO;
+		}
 		dev_warn(regmap_get_device(st->map),
 				"whoami mismatch got %#02x expected %#02hhx for %s\n",
 				regval, st->hw->whoami, st->hw->name);
 	}
=20
+	/* reset to make sure previous state are not there */
+	result =3D regmap_write(st->map, st->reg->pwr_mgmt_1,
+			      INV_MPU6050_BIT_H_RESET);
+	if (result)
+		return result;
+	msleep(INV_MPU6050_POWER_UP_TIME);
+
 	/*
 	 * toggle power state. After reset, the sleep bit could be on
 	 * or off depending on the OTP settings. Toggling power would
--=20
1.9.1=

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-05-21 11:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-12 12:45 [PATCH] iio: imu: inv_mpu6050: test whoami against invalid values and do it first Jean-Baptiste Maneyrol
2017-05-14 14:49 ` Jonathan Cameron
2017-05-15  8:42   ` Jean-Baptiste Maneyrol
2017-05-16 18:06     ` Jonathan Cameron
2017-05-17 15:03       ` Jean-Baptiste Maneyrol
2017-05-21 11:43         ` Jonathan Cameron

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).