Commit cec01545 authored by Crestez Dan Leonard's avatar Crestez Dan Leonard Committed by Jonathan Cameron

iio: inv_mpu6050: Check WHO_AM_I register on probe

This can be used to distinguish mpu6500. This is a warning rather than
an error because the differences are mostly irrelevant and it's nice to
avoid breaking users with slightly incorrect ACPI/DT.
Signed-off-by: default avatarCrestez Dan Leonard <leonard.crestez@intel.com>
Acked-by: default avatarGe Gao <ggao@invensense.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 7bdd3181
...@@ -91,16 +91,19 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = { ...@@ -91,16 +91,19 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
/* Indexed by enum inv_devices */ /* Indexed by enum inv_devices */
static const struct inv_mpu6050_hw hw_info[] = { static const struct inv_mpu6050_hw hw_info[] = {
{ {
.whoami = INV_MPU6050_WHOAMI_VALUE,
.name = "MPU6050", .name = "MPU6050",
.reg = &reg_set_6050, .reg = &reg_set_6050,
.config = &chip_config_6050, .config = &chip_config_6050,
}, },
{ {
.whoami = INV_MPU6500_WHOAMI_VALUE,
.name = "MPU6500", .name = "MPU6500",
.reg = &reg_set_6500, .reg = &reg_set_6500,
.config = &chip_config_6050, .config = &chip_config_6050,
}, },
{ {
.whoami = INV_MPU6000_WHOAMI_VALUE,
.name = "MPU6000", .name = "MPU6000",
.reg = &reg_set_6050, .reg = &reg_set_6050,
.config = &chip_config_6050, .config = &chip_config_6050,
...@@ -749,6 +752,7 @@ static const struct iio_info mpu_info = { ...@@ -749,6 +752,7 @@ static const struct iio_info mpu_info = {
static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
{ {
int result; int result;
unsigned int regval;
st->hw = &hw_info[st->chip_type]; st->hw = &hw_info[st->chip_type];
st->reg = hw_info[st->chip_type].reg; st->reg = hw_info[st->chip_type].reg;
...@@ -759,6 +763,17 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) ...@@ -759,6 +763,17 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
if (result) if (result)
return result; return result;
msleep(INV_MPU6050_POWER_UP_TIME); msleep(INV_MPU6050_POWER_UP_TIME);
/* check chip self-identification */
result = regmap_read(st->map, INV_MPU6050_REG_WHOAMI, &regval);
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",
regval, st->hw->whoami, st->hw->name);
}
/* /*
* toggle power state. After reset, the sleep bit could be on * toggle power state. After reset, the sleep bit could be on
* or off depending on the OTP settings. Toggling power would * or off depending on the OTP settings. Toggling power would
......
...@@ -93,11 +93,13 @@ struct inv_mpu6050_chip_config { ...@@ -93,11 +93,13 @@ struct inv_mpu6050_chip_config {
/** /**
* struct inv_mpu6050_hw - Other important hardware information. * struct inv_mpu6050_hw - Other important hardware information.
* @whoami: Self identification byte from WHO_AM_I register
* @name: name of the chip. * @name: name of the chip.
* @reg: register map of the chip. * @reg: register map of the chip.
* @config: configuration of the chip. * @config: configuration of the chip.
*/ */
struct inv_mpu6050_hw { struct inv_mpu6050_hw {
u8 whoami;
u8 *name; u8 *name;
const struct inv_mpu6050_reg_map *reg; const struct inv_mpu6050_reg_map *reg;
const struct inv_mpu6050_chip_config *config; const struct inv_mpu6050_chip_config *config;
...@@ -215,6 +217,12 @@ struct inv_mpu6050_state { ...@@ -215,6 +217,12 @@ struct inv_mpu6050_state {
#define INV_MPU6050_MIN_FIFO_RATE 4 #define INV_MPU6050_MIN_FIFO_RATE 4
#define INV_MPU6050_ONE_K_HZ 1000 #define INV_MPU6050_ONE_K_HZ 1000
#define INV_MPU6050_REG_WHOAMI 117
#define INV_MPU6000_WHOAMI_VALUE 0x68
#define INV_MPU6050_WHOAMI_VALUE 0x68
#define INV_MPU6500_WHOAMI_VALUE 0x70
/* scan element definition */ /* scan element definition */
enum inv_mpu6050_scan { enum inv_mpu6050_scan {
INV_MPU6050_SCAN_ACCL_X, INV_MPU6050_SCAN_ACCL_X,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment