diff options
author | Jean-Baptiste Maneyrol <JManeyrol@invensense.com> | 2017-06-06 10:29:52 +0000 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2017-06-13 21:18:17 +0100 |
commit | 881b556f6cf22d37be9340f293f2db10ce7ae8bf (patch) | |
tree | d30612bea0a08e2c77fb9e2bf6fa09d43de438f0 /drivers/iio | |
parent | 0483fff4d0ae0c7cd4cddb121983352bd2b3aad9 (diff) | |
download | op-kernel-dev-881b556f6cf22d37be9340f293f2db10ce7ae8bf.zip op-kernel-dev-881b556f6cf22d37be9340f293f2db10ce7ae8bf.tar.gz |
iio: imu: inv_mpu6050: test whoami first and against all known values
SPI bus is never generating error during transfer, so to check if
a chip is correctly connected on a SPI bus we enforce whoami check
to be correct. In this way we can assure SPI probe is failing if
there is no chip connected.
Note that this is really papering over boards that claim the device
is there when it isn't. Not a bad thing to cope with, but not
necessarily stable material.
Fixes: cec0154556f8 ("iio: inv_mpu6050: Check WHO_AM_I register on probe")
Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 60732e9..eea4576 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -777,27 +777,42 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) { int result; unsigned int regval; + int i; st->hw = &hw_info[st->chip_type]; st->reg = hw_info[st->chip_type].reg; - /* reset to make sure previous state are not there */ - result = 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 = regmap_read(st->map, INV_MPU6050_REG_WHOAMI, ®val); if (result) return result; if (regval != st->hw->whoami) { - dev_warn(regmap_get_device(st->map), - "whoami mismatch got %#02x expected %#02hhx for %s\n", + /* check whoami against all possible values */ + for (i = 0; i < INV_NUM_PARTS; ++i) { + if (regval == hw_info[i].whoami) { + dev_warn(regmap_get_device(st->map), + "whoami mismatch got %#02x (%s)" + "expected %#02hhx (%s)\n", + regval, hw_info[i].name, + st->hw->whoami, st->hw->name); + break; + } + } + if (i >= INV_NUM_PARTS) { + dev_err(regmap_get_device(st->map), + "invalid whoami %#02x expected %#02hhx (%s)\n", regval, st->hw->whoami, st->hw->name); + return -ENODEV; + } } + /* reset to make sure previous state are not there */ + result = 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 |