Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1383374 > unrolled thread

[PATCH 0/5] iio: inv_mpu6050: Cleanup chip types and add mpu9150

Started byCrestez Dan Leonard <leonard.crestez@intel.com>
First post2016-04-20 15:20 +0200
Last post2016-04-20 15:20 +0200
Articles 8 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/5] iio: inv_mpu6050: Cleanup chip types and add mpu9150 Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-20 15:20 +0200
    [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-20 15:20 +0200
      Re: [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg Jonathan Cameron <jic23@kernel.org> - 2016-04-24 13:20 +0200
        Re: [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg Jonathan Cameron <jic23@kernel.org> - 2016-04-25 20:50 +0200
    [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-20 15:20 +0200
      Re: [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping Jonathan Cameron <jic23@kernel.org> - 2016-04-24 13:20 +0200
        Re: [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping Jonathan Cameron <jic23@kernel.org> - 2016-04-25 20:50 +0200
    [PATCH 4/5] iio: inv_mpu6050: Add spi_device_id for INV_MPU6500 Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-20 15:20 +0200

#1383374 — [PATCH 0/5] iio: inv_mpu6050: Cleanup chip types and add mpu9150

FromCrestez Dan Leonard <leonard.crestez@intel.com>
Date2016-04-20 15:20 +0200
Subject[PATCH 0/5] iio: inv_mpu6050: Cleanup chip types and add mpu9150
Message-ID<rq0cW-8rY-19@gated-at.bofh.it>
This adds support for mpu9150 explictly. This device includes a MPU60X0 and
AK8975 inside the same package. It also cleans the chip_type <=> hw_info
mappings which were just a mess.

Crestez Dan Leonard (5):
  iio: inv_mpu6050: Cleanup hw_info mapping
  iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg
  iio: inv_mpu6050: Check WHO_AM_I register on probe
  iio: inv_mpu6050: Add spi_device_id for INV_MPU6500
  iio: inv_mpu6050: Add explicit support for MPU9150

 drivers/iio/imu/inv_mpu6050/Kconfig        | 10 ++++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 37 +++++++++++++++++++++++++++---
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  |  3 ++-
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 12 ++++++++--
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 20 ++++++++++++----
 5 files changed, 66 insertions(+), 16 deletions(-)

-- 
2.5.5

[toc] | [next] | [standalone]


#1383375 — [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg

FromCrestez Dan Leonard <leonard.crestez@intel.com>
Date2016-04-20 15:20 +0200
Subject[PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg
Message-ID<rq0cW-8rY-29@gated-at.bofh.it>
In reply to#1383374
This field was unused and incorrect for mpu6500.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ---
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 2 --
 2 files changed, 5 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 52e62b3..faccabafc 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -91,19 +91,16 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
 /* Indexed by enum inv_devices */
 static const struct inv_mpu6050_hw hw_info[] = {
 	{
-		.num_reg = 117,
 		.name = "MPU6050",
 		.reg = &reg_set_6050,
 		.config = &chip_config_6050,
 	},
 	{
-		.num_reg = 117,
 		.name = "MPU6500",
 		.reg = &reg_set_6500,
 		.config = &chip_config_6050,
 	},
 	{
-		.num_reg = 117,
 		.name = "MPU6000",
 		.reg = &reg_set_6050,
 		.config = &chip_config_6050,
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index e302a49..c66dbfc 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -93,13 +93,11 @@ struct inv_mpu6050_chip_config {
 
 /**
  *  struct inv_mpu6050_hw - Other important hardware information.
- *  @num_reg:	Number of registers on device.
  *  @name:      name of the chip.
  *  @reg:   register map of the chip.
  *  @config:    configuration of the chip.
  */
 struct inv_mpu6050_hw {
-	u8 num_reg;
 	u8 *name;
 	const struct inv_mpu6050_reg_map *reg;
 	const struct inv_mpu6050_chip_config *config;
-- 
2.5.5

[toc] | [prev] | [next] | [standalone]


#1385805 — Re: [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg

FromJonathan Cameron <jic23@kernel.org>
Date2016-04-24 13:20 +0200
SubjectRe: [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg
Message-ID<rrqf0-3v8-13@gated-at.bofh.it>
In reply to#1383375
On 20/04/16 14:15, Crestez Dan Leonard wrote:
> This field was unused and incorrect for mpu6500.
> 
> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>. 
This one I think I can safely take :)

Good spot
> --- 
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 2 --
>  2 files changed, 5 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 52e62b3..faccabafc 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -91,19 +91,16 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
>  /* Indexed by enum inv_devices */
>  static const struct inv_mpu6050_hw hw_info[] = {
>  	{
> -		.num_reg = 117,
>  		.name = "MPU6050",
>  		.reg = &reg_set_6050,
>  		.config = &chip_config_6050,
>  	},
>  	{
> -		.num_reg = 117,
>  		.name = "MPU6500",
>  		.reg = &reg_set_6500,
>  		.config = &chip_config_6050,
>  	},
>  	{
> -		.num_reg = 117,
>  		.name = "MPU6000",
>  		.reg = &reg_set_6050,
>  		.config = &chip_config_6050,
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index e302a49..c66dbfc 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -93,13 +93,11 @@ struct inv_mpu6050_chip_config {
>  
>  /**
>   *  struct inv_mpu6050_hw - Other important hardware information.
> - *  @num_reg:	Number of registers on device.
>   *  @name:      name of the chip.
>   *  @reg:   register map of the chip.
>   *  @config:    configuration of the chip.
>   */
>  struct inv_mpu6050_hw {
> -	u8 num_reg;
>  	u8 *name;
>  	const struct inv_mpu6050_reg_map *reg;
>  	const struct inv_mpu6050_chip_config *config;
> 

[toc] | [prev] | [next] | [standalone]


#1386747 — Re: [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg

FromJonathan Cameron <jic23@kernel.org>
Date2016-04-25 20:50 +0200
SubjectRe: [PATCH 2/5] iio: inv_mpu6050: Remove inv_mpu6050_hw.num_reg
Message-ID<rrTK2-269-17@gated-at.bofh.it>
In reply to#1385805
On 24/04/16 12:12, Jonathan Cameron wrote:
> On 20/04/16 14:15, Crestez Dan Leonard wrote:
>> This field was unused and incorrect for mpu6500.
>>
>> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>. 
> This one I think I can safely take :)
> 
> Good spot
Applied.

Thanks,
>> --- 
>>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ---
>>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  | 2 --
>>  2 files changed, 5 deletions(-)
>>
>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> index 52e62b3..faccabafc 100644
>> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> @@ -91,19 +91,16 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
>>  /* Indexed by enum inv_devices */
>>  static const struct inv_mpu6050_hw hw_info[] = {
>>  	{
>> -		.num_reg = 117,
>>  		.name = "MPU6050",
>>  		.reg = &reg_set_6050,
>>  		.config = &chip_config_6050,
>>  	},
>>  	{
>> -		.num_reg = 117,
>>  		.name = "MPU6500",
>>  		.reg = &reg_set_6500,
>>  		.config = &chip_config_6050,
>>  	},
>>  	{
>> -		.num_reg = 117,
>>  		.name = "MPU6000",
>>  		.reg = &reg_set_6050,
>>  		.config = &chip_config_6050,
>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
>> index e302a49..c66dbfc 100644
>> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
>> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
>> @@ -93,13 +93,11 @@ struct inv_mpu6050_chip_config {
>>  
>>  /**
>>   *  struct inv_mpu6050_hw - Other important hardware information.
>> - *  @num_reg:	Number of registers on device.
>>   *  @name:      name of the chip.
>>   *  @reg:   register map of the chip.
>>   *  @config:    configuration of the chip.
>>   */
>>  struct inv_mpu6050_hw {
>> -	u8 num_reg;
>>  	u8 *name;
>>  	const struct inv_mpu6050_reg_map *reg;
>>  	const struct inv_mpu6050_chip_config *config;
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

[toc] | [prev] | [next] | [standalone]


#1383377 — [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping

FromCrestez Dan Leonard <leonard.crestez@intel.com>
Date2016-04-20 15:20 +0200
Subject[PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping
Message-ID<rq0cW-8rY-33@gated-at.bofh.it>
In reply to#1383374
The hw_info array was indexed by enum inv_devices chip_type despite the
fact that the enumeration had more members than the array and was
ordered differently.

The patch cleans this up and adds explicit chip_types to i2c/spi/acpi
IDs. It also adds some stricter checks inside the driver core.

This happened to work so far because the differences between the
supported models are very minor.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 15 ++++++++++++++-
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  |  2 +-
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 18 ++++++++++++++----
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index d192953..52e62b3 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -88,16 +88,23 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
 	.accl_fs = INV_MPU6050_FS_02G,
 };
 
+/* Indexed by enum inv_devices */
 static const struct inv_mpu6050_hw hw_info[] = {
 	{
 		.num_reg = 117,
+		.name = "MPU6050",
+		.reg = &reg_set_6050,
+		.config = &chip_config_6050,
+	},
+	{
+		.num_reg = 117,
 		.name = "MPU6500",
 		.reg = &reg_set_6500,
 		.config = &chip_config_6050,
 	},
 	{
 		.num_reg = 117,
-		.name = "MPU6050",
+		.name = "MPU6000",
 		.reg = &reg_set_6050,
 		.config = &chip_config_6050,
 	},
@@ -774,6 +781,12 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	if (!indio_dev)
 		return -ENOMEM;
 
+	BUILD_BUG_ON(ARRAY_SIZE(hw_info) != INV_NUM_PARTS);
+	if (chip_type < 0 || chip_type >= INV_NUM_PARTS) {
+		dev_err(dev, "Bad invensense chip_type=%d name=%s\n",
+				chip_type, name);
+		return -ENODEV;
+	}
 	st = iio_priv(indio_dev);
 	st->chip_type = chip_type;
 	st->powerup_count = 0;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index 5ee4e0d..bb1a7b1 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -208,7 +208,7 @@ static const struct i2c_device_id inv_mpu_id[] = {
 MODULE_DEVICE_TABLE(i2c, inv_mpu_id);
 
 static const struct acpi_device_id inv_acpi_match[] = {
-	{"INVN6500", 0},
+	{"INVN6500", INV_MPU6500},
 	{ },
 };
 
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index 7bcb8d8..3972a46 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -44,9 +44,19 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
 static int inv_mpu_probe(struct spi_device *spi)
 {
 	struct regmap *regmap;
-	const struct spi_device_id *id = spi_get_device_id(spi);
-	const char *name = id ? id->name : NULL;
-	const int chip_type = id ? id->driver_data : 0;
+	const struct spi_device_id *spi_id;
+	const struct acpi_device_id *acpi_id;
+	const char *name = NULL;
+	enum inv_devices chip_type;
+
+	if ((spi_id = spi_get_device_id(spi))) {
+		chip_type = (enum inv_devices)spi_id->driver_data;
+		name = spi_id->name;
+	} else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
+		chip_type = (enum inv_devices)acpi_id->driver_data;
+	} else {
+		return -ENODEV;
+	}
 
 	regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
 	if (IS_ERR(regmap)) {
@@ -76,7 +86,7 @@ static const struct spi_device_id inv_mpu_id[] = {
 MODULE_DEVICE_TABLE(spi, inv_mpu_id);
 
 static const struct acpi_device_id inv_acpi_match[] = {
-	{"INVN6000", 0},
+	{"INVN6000", INV_MPU6000},
 	{ },
 };
 MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
-- 
2.5.5

[toc] | [prev] | [next] | [standalone]


#1385802 — Re: [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping

FromJonathan Cameron <jic23@kernel.org>
Date2016-04-24 13:20 +0200
SubjectRe: [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping
Message-ID<rrqeZ-3v8-1@gated-at.bofh.it>
In reply to#1383377
On 20/04/16 14:15, Crestez Dan Leonard wrote:
> The hw_info array was indexed by enum inv_devices chip_type despite the
> fact that the enumeration had more members than the array and was
> ordered differently.
> 
> The patch cleans this up and adds explicit chip_types to i2c/spi/acpi
> IDs. It also adds some stricter checks inside the driver core.
> 
> This happened to work so far because the differences between the
> supported models are very minor.
> 
> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>h
Ideally I'd like an Ack / review from Ge on these.
The same is true for the whole series.

Looks good to me though!

Jonathan
> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 15 ++++++++++++++-
>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  |  2 +-
>  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 18 ++++++++++++++----
>  3 files changed, 29 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index d192953..52e62b3 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -88,16 +88,23 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
>  	.accl_fs = INV_MPU6050_FS_02G,
>  };
>  
> +/* Indexed by enum inv_devices */
>  static const struct inv_mpu6050_hw hw_info[] = {
>  	{
>  		.num_reg = 117,
> +		.name = "MPU6050",
> +		.reg = &reg_set_6050,
> +		.config = &chip_config_6050,
> +	},
> +	{
> +		.num_reg = 117,
>  		.name = "MPU6500",
>  		.reg = &reg_set_6500,
>  		.config = &chip_config_6050,
>  	},
>  	{
>  		.num_reg = 117,
> -		.name = "MPU6050",
> +		.name = "MPU6000",
>  		.reg = &reg_set_6050,
>  		.config = &chip_config_6050,
>  	},
> @@ -774,6 +781,12 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
> +	BUILD_BUG_ON(ARRAY_SIZE(hw_info) != INV_NUM_PARTS);
> +	if (chip_type < 0 || chip_type >= INV_NUM_PARTS) {
> +		dev_err(dev, "Bad invensense chip_type=%d name=%s\n",
> +				chip_type, name);
> +		return -ENODEV;
> +	}
>  	st = iio_priv(indio_dev);
>  	st->chip_type = chip_type;
>  	st->powerup_count = 0;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index 5ee4e0d..bb1a7b1 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -208,7 +208,7 @@ static const struct i2c_device_id inv_mpu_id[] = {
>  MODULE_DEVICE_TABLE(i2c, inv_mpu_id);
>  
>  static const struct acpi_device_id inv_acpi_match[] = {
> -	{"INVN6500", 0},
> +	{"INVN6500", INV_MPU6500},
>  	{ },
>  };
>  
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index 7bcb8d8..3972a46 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -44,9 +44,19 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
>  static int inv_mpu_probe(struct spi_device *spi)
>  {
>  	struct regmap *regmap;
> -	const struct spi_device_id *id = spi_get_device_id(spi);
> -	const char *name = id ? id->name : NULL;
> -	const int chip_type = id ? id->driver_data : 0;
> +	const struct spi_device_id *spi_id;
> +	const struct acpi_device_id *acpi_id;
> +	const char *name = NULL;
> +	enum inv_devices chip_type;
> +
> +	if ((spi_id = spi_get_device_id(spi))) {
> +		chip_type = (enum inv_devices)spi_id->driver_data;
> +		name = spi_id->name;
> +	} else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
> +		chip_type = (enum inv_devices)acpi_id->driver_data;
> +	} else {
> +		return -ENODEV;
> +	}
>  
>  	regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
>  	if (IS_ERR(regmap)) {
> @@ -76,7 +86,7 @@ static const struct spi_device_id inv_mpu_id[] = {
>  MODULE_DEVICE_TABLE(spi, inv_mpu_id);
>  
>  static const struct acpi_device_id inv_acpi_match[] = {
> -	{"INVN6000", 0},
> +	{"INVN6000", INV_MPU6000},
>  	{ },
>  };
>  MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
> 

[toc] | [prev] | [next] | [standalone]


#1386746 — Re: [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping

FromJonathan Cameron <jic23@kernel.org>
Date2016-04-25 20:50 +0200
SubjectRe: [PATCH 1/5] iio: inv_mpu6050: Cleanup hw_info mapping
Message-ID<rrTK2-269-11@gated-at.bofh.it>
In reply to#1385802
On 24/04/16 12:10, Jonathan Cameron wrote:
> On 20/04/16 14:15, Crestez Dan Leonard wrote:
>> The hw_info array was indexed by enum inv_devices chip_type despite the
>> fact that the enumeration had more members than the array and was
>> ordered differently.
>>
>> The patch cleans this up and adds explicit chip_types to i2c/spi/acpi
>> IDs. It also adds some stricter checks inside the driver core.
>>
>> This happened to work so far because the differences between the
>> supported models are very minor.
>>
>> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>h
> Ideally I'd like an Ack / review from Ge on these.
> The same is true for the whole series.
Applied.
> 
> Looks good to me though!
> 
> Jonathan
>> ---
>>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 15 ++++++++++++++-
>>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c  |  2 +-
>>  drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c  | 18 ++++++++++++++----
>>  3 files changed, 29 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> index d192953..52e62b3 100644
>> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
>> @@ -88,16 +88,23 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
>>  	.accl_fs = INV_MPU6050_FS_02G,
>>  };
>>  
>> +/* Indexed by enum inv_devices */
>>  static const struct inv_mpu6050_hw hw_info[] = {
>>  	{
>>  		.num_reg = 117,
>> +		.name = "MPU6050",
>> +		.reg = &reg_set_6050,
>> +		.config = &chip_config_6050,
>> +	},
>> +	{
>> +		.num_reg = 117,
>>  		.name = "MPU6500",
>>  		.reg = &reg_set_6500,
>>  		.config = &chip_config_6050,
>>  	},
>>  	{
>>  		.num_reg = 117,
>> -		.name = "MPU6050",
>> +		.name = "MPU6000",
>>  		.reg = &reg_set_6050,
>>  		.config = &chip_config_6050,
>>  	},
>> @@ -774,6 +781,12 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>>  	if (!indio_dev)
>>  		return -ENOMEM;
>>  
>> +	BUILD_BUG_ON(ARRAY_SIZE(hw_info) != INV_NUM_PARTS);
>> +	if (chip_type < 0 || chip_type >= INV_NUM_PARTS) {
>> +		dev_err(dev, "Bad invensense chip_type=%d name=%s\n",
>> +				chip_type, name);
>> +		return -ENODEV;
>> +	}
>>  	st = iio_priv(indio_dev);
>>  	st->chip_type = chip_type;
>>  	st->powerup_count = 0;
>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
>> index 5ee4e0d..bb1a7b1 100644
>> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
>> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
>> @@ -208,7 +208,7 @@ static const struct i2c_device_id inv_mpu_id[] = {
>>  MODULE_DEVICE_TABLE(i2c, inv_mpu_id);
>>  
>>  static const struct acpi_device_id inv_acpi_match[] = {
>> -	{"INVN6500", 0},
>> +	{"INVN6500", INV_MPU6500},
>>  	{ },
>>  };
>>  
>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
>> index 7bcb8d8..3972a46 100644
>> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
>> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
>> @@ -44,9 +44,19 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
>>  static int inv_mpu_probe(struct spi_device *spi)
>>  {
>>  	struct regmap *regmap;
>> -	const struct spi_device_id *id = spi_get_device_id(spi);
>> -	const char *name = id ? id->name : NULL;
>> -	const int chip_type = id ? id->driver_data : 0;
>> +	const struct spi_device_id *spi_id;
>> +	const struct acpi_device_id *acpi_id;
>> +	const char *name = NULL;
>> +	enum inv_devices chip_type;
>> +
>> +	if ((spi_id = spi_get_device_id(spi))) {
>> +		chip_type = (enum inv_devices)spi_id->driver_data;
>> +		name = spi_id->name;
>> +	} else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
>> +		chip_type = (enum inv_devices)acpi_id->driver_data;
>> +	} else {
>> +		return -ENODEV;
>> +	}
>>  
>>  	regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
>>  	if (IS_ERR(regmap)) {
>> @@ -76,7 +86,7 @@ static const struct spi_device_id inv_mpu_id[] = {
>>  MODULE_DEVICE_TABLE(spi, inv_mpu_id);
>>  
>>  static const struct acpi_device_id inv_acpi_match[] = {
>> -	{"INVN6000", 0},
>> +	{"INVN6000", INV_MPU6000},
>>  	{ },
>>  };
>>  MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

[toc] | [prev] | [next] | [standalone]


#1383378 — [PATCH 4/5] iio: inv_mpu6050: Add spi_device_id for INV_MPU6500

FromCrestez Dan Leonard <leonard.crestez@intel.com>
Date2016-04-20 15:20 +0200
Subject[PATCH 4/5] iio: inv_mpu6050: Add spi_device_id for INV_MPU6500
Message-ID<rq0cW-8rY-35@gated-at.bofh.it>
In reply to#1383374
Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index 3972a46..a0f8df2 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -80,6 +80,7 @@ static int inv_mpu_remove(struct spi_device *spi)
  */
 static const struct spi_device_id inv_mpu_id[] = {
 	{"mpu6000", INV_MPU6000},
+	{"mpu6500", INV_MPU6500},
 	{}
 };
 
-- 
2.5.5

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web