Skip to contentSkip to conversation

iio: accel: bma180: Add support for BMA250E

PATCH In review Hans de Goede 2 participants 5 messages May 16, 2017 – May 21, 2017 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 iio: accel: bma180: Add support for BMA250E

The BMA250E adds a new fifo mode and is fully backwards compatible with the BMA250, but with a different chip-id.

This commit adds support for it by adjusting the chip-id check and otherwise treating it as a regular BMA250.

---
 drivers/iio/accel/bma180.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/iio/accel/bma180.c +23 -1
index efc67739c28f..3d6694821a96 100644
@@ -36,6 +36,7 @@
 enum chip_ids {
 	BMA180,
 	BMA250,
+	BMA250E,
 };
 
 struct bma180_data;
@@ -55,6 +56,7 @@ struct bma180_part_info {
 	u8 power_reg, power_mask, lowpower_val;
 	u8 int_enable_reg, int_enable_mask;
 	u8 softreset_reg;
+	u8 chip_id;
 
 	int (*chip_config)(struct bma180_data *data);
 	void (*chip_disable)(struct bma180_data *data);
@@ -112,6 +114,8 @@ struct bma180_part_info {
 #define BMA250_INT1_DATA_MASK	BIT(0)
 #define BMA250_INT_RESET_MASK	BIT(7) /* Reset pending interrupts */
 
+#define BMA250E_CHIP_ID		0xf9
+
 struct bma180_data {
 	struct i2c_client *client;
 	struct iio_trigger *trig;
@@ -309,7 +313,7 @@ static int bma180_chip_init(struct bma180_data *data)
 
 	if (ret < 0)
 		return ret;
-	if (ret != BMA180_ID_REG_VAL)
+	if (ret != data->part_info->chip_id)
 		return -ENODEV;
 
 	ret = bma180_soft_reset(data);
@@ -632,6 +636,7 @@ static const struct bma180_part_info bma180_part_info[] = {
 		BMA180_TCO_Z, BMA180_MODE_CONFIG, BMA180_LOW_POWER,
 		BMA180_CTRL_REG3, BMA180_NEW_DATA_INT,
 		BMA180_RESET,
+		BMA180_CHIP_ID,
 		bma180_chip_config,
 		bma180_chip_disable,
 	},
@@ -646,6 +651,22 @@ static const struct bma180_part_info bma180_part_info[] = {
 		BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1,
 		BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK,
 		BMA250_RESET_REG,
+		BMA180_CHIP_ID,
+		bma250_chip_config,
+		bma250_chip_disable,
+	},
+	[BMA250E] = {
+		bma250_channels, ARRAY_SIZE(bma250_channels),
+		bma250_scale_table, ARRAY_SIZE(bma250_scale_table),
+		bma250_bw_table, ARRAY_SIZE(bma250_bw_table),
+		BMA250_INT_RESET_REG, BMA250_INT_RESET_MASK,
+		BMA250_POWER_REG, BMA250_SUSPEND_MASK,
+		BMA250_BW_REG, BMA250_BW_MASK,
+		BMA250_RANGE_REG, BMA250_RANGE_MASK,
+		BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1,
+		BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK,
+		BMA250_RESET_REG,
+		BMA250E_CHIP_ID,
 		bma250_chip_config,
 		bma250_chip_disable,
 	},
@@ -845,6 +866,7 @@ static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume);
 static struct i2c_device_id bma180_ids[] = {
 	{ "bma180", BMA180 },
 	{ "bma250", BMA250 },
+	{ "bma250e", BMA250E },
 	{ }
 };
 
Signature · 1 line
2.12.2
#1 lore raw

PATCH v2 2/2 iio: accel: bma180: Add ACPI enumeration support for BMA250E

Some x86 tablets use the BMA250E accelerometer, add support for this.

---
Changes in v2:
-Rebase on top of current master
-Map ACPI "BMA250E" to BMA250E not BMA250, these are not the same

---
 drivers/iio/accel/bma180.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iio/accel/bma180.c +19 -2
index 3d6694821a96..17b7953f2502 100644
@@ -14,6 +14,7 @@
  * BMA250: 7-bit I2C slave address 0x18 or 0x19
  */
 
+#include <linux/acpi.h>
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
@@ -727,6 +728,8 @@ static const struct iio_trigger_ops bma180_trigger_ops = {
 static int bma180_probe(struct i2c_client *client,
 		const struct i2c_device_id *id)
 {
+	struct device *dev = &client->dev;
+	const struct acpi_device_id *acpi_id;
 	struct bma180_data *data;
 	struct iio_dev *indio_dev;
 	enum chip_ids chip;
@@ -739,10 +742,17 @@ static int bma180_probe(struct i2c_client *client,
 	data = iio_priv(indio_dev);
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
-	if (client->dev.of_node)
+	if (dev->of_node) {
 		chip = (enum chip_ids)of_device_get_match_data(&client->dev);
-	else
+	} else if (id) {
 		chip = id->driver_data;
+	} else {
+		acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
+		if (!acpi_id)
+			return -ENODEV;
+
+		chip = acpi_id->driver_data;
+	}
 	data->part_info = &bma180_part_info[chip];
 
 	ret = data->part_info->chip_config(data);
@@ -863,6 +873,12 @@ static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume);
 #define BMA180_PM_OPS NULL
 #endif
 
+static const struct acpi_device_id bma180_acpi_match[] = {
+	{ "BMA250E", BMA250E },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, bma180_acpi_match);
+
 static struct i2c_device_id bma180_ids[] = {
 	{ "bma180", BMA180 },
 	{ "bma250", BMA250 },
@@ -888,6 +904,7 @@ MODULE_DEVICE_TABLE(of, bma180_of_match);
 static struct i2c_driver bma180_driver = {
 	.driver = {
 		.name	= "bma180",
+		.acpi_match_table = ACPI_PTR(bma180_acpi_match),
 		.pm	= BMA180_PM_OPS,
 		.of_match_table = bma180_of_match,
 	},
Signature · 1 line
2.12.2
maintainer
#3 lore raw
In reply to Hans de Goede
Quoted 70 lines · Hans de Goede

The BMA250E adds a new fifo mode and is fully backwards compatible with the BMA250, but with a different chip-id.

This commit adds support for it by adjusting the chip-id check and otherwise treating it as a regular BMA250.

---
  drivers/iio/accel/bma180.c | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)
drivers/iio/accel/bma180.c +15 -1
index efc67739c28f..3d6694821a96 100644
@@ -36,6 +36,7 @@
  enum chip_ids {
  	BMA180,
  	BMA250,
+	BMA250E,
  };
 
  struct bma180_data;
@@ -55,6 +56,7 @@ struct bma180_part_info {
  	u8 power_reg, power_mask, lowpower_val;
  	u8 int_enable_reg, int_enable_mask;
  	u8 softreset_reg;
+	u8 chip_id;
 
  	int (*chip_config)(struct bma180_data *data);
  	void (*chip_disable)(struct bma180_data *data);
@@ -112,6 +114,8 @@ struct bma180_part_info {
  #define BMA250_INT1_DATA_MASK	BIT(0)
  #define BMA250_INT_RESET_MASK	BIT(7) /* Reset pending interrupts */
 
+#define BMA250E_CHIP_ID		0xf9
+
  struct bma180_data {
  	struct i2c_client *client;
  	struct iio_trigger *trig;
@@ -309,7 +313,7 @@ static int bma180_chip_init(struct bma180_data *data)
 
  	if (ret < 0)
  		return ret;
-	if (ret != BMA180_ID_REG_VAL)
+	if (ret != data->part_info->chip_id)
  		return -ENODEV;
 
  	ret = bma180_soft_reset(data);
@@ -632,6 +636,7 @@ static const struct bma180_part_info bma180_part_info[] = {
  		BMA180_TCO_Z, BMA180_MODE_CONFIG, BMA180_LOW_POWER,
  		BMA180_CTRL_REG3, BMA180_NEW_DATA_INT,
  		BMA180_RESET,
+		BMA180_CHIP_ID,
  		bma180_chip_config,
  		bma180_chip_disable,
  	},
@@ -646,6 +651,22 @@ static const struct bma180_part_info bma180_part_info[] = {
  		BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1,
  		BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK,
  		BMA250_RESET_REG,
+		BMA180_CHIP_ID,
+		bma250_chip_config,
+		bma250_chip_disable,
+	},
+	[BMA250E] = {
+		bma250_channels, ARRAY_SIZE(bma250_channels),
+		bma250_scale_table, ARRAY_SIZE(bma250_scale_table),
+		bma250_bw_table, ARRAY_SIZE(bma250_bw_table),
+		BMA250_INT_RESET_REG, BMA250_INT_RESET_MASK,

drivers/iio/accel/bma180.c static const struct bma180_part_info bma180_part_info[] = { · line 672

Quoted 10 lines
drivers/iio/accel/bma180.c +7 -0
+		BMA250_POWER_REG, BMA250_SUSPEND_MASK,
+		BMA250_BW_REG, BMA250_BW_MASK,
+		BMA250_RANGE_REG, BMA250_RANGE_MASK,
+		BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1,
+		BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK,
+		BMA250_RESET_REG,
+		BMA250E_CHIP_ID,
  		bma250_chip_config,
  		bma250_chip_disable,
  	},

Yikes. I never picked up on this being there before.
Assigning elements of such a large structure is always going to be fragile.

I'll probably take this patch as is, but we really ought to move over to using named element assignment in here. It'll be a little more verbose but
way less fragile! Not to mention allows the possibly upcoming
structure random ordering to work (if that merges).

Quoted 9 lines
drivers/iio/accel/bma180.c +1 -0
@@ -845,6 +866,7 @@ static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume);
  static struct i2c_device_id bma180_ids[] = {
  	{ "bma180", BMA180 },
  	{ "bma250", BMA250 },
+	{ "bma250e", BMA250E },
  	{ }
  };
 
maintainer
#4 lore raw
Quoted 8 lines · Jonathan Cameron
Quoted 7 lines · Hans de Goede

The BMA250E adds a new fifo mode and is fully backwards compatible with the BMA250, but with a different chip-id.

This commit adds support for it by adjusting the chip-id check and otherwise treating it as a regular BMA250.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 88 lines
Quoted 58 lines
---
  drivers/iio/accel/bma180.c | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)
drivers/iio/accel/bma180.c +15 -1
index efc67739c28f..3d6694821a96 100644
@@ -36,6 +36,7 @@
  enum chip_ids {
      BMA180,
      BMA250,
+    BMA250E,
  };
  struct bma180_data;
@@ -55,6 +56,7 @@ struct bma180_part_info {
      u8 power_reg, power_mask, lowpower_val;
      u8 int_enable_reg, int_enable_mask;
      u8 softreset_reg;
+    u8 chip_id;
      int (*chip_config)(struct bma180_data *data);
      void (*chip_disable)(struct bma180_data *data);
@@ -112,6 +114,8 @@ struct bma180_part_info {
  #define BMA250_INT1_DATA_MASK    BIT(0)
  #define BMA250_INT_RESET_MASK    BIT(7) /* Reset pending interrupts */
+#define BMA250E_CHIP_ID        0xf9
+
  struct bma180_data {
      struct i2c_client *client;
      struct iio_trigger *trig;
@@ -309,7 +313,7 @@ static int bma180_chip_init(struct bma180_data *data)
      if (ret < 0)
          return ret;
-    if (ret != BMA180_ID_REG_VAL)
+    if (ret != data->part_info->chip_id)
          return -ENODEV;
      ret = bma180_soft_reset(data);
@@ -632,6 +636,7 @@ static const struct bma180_part_info bma180_part_info[] = {
          BMA180_TCO_Z, BMA180_MODE_CONFIG, BMA180_LOW_POWER,
          BMA180_CTRL_REG3, BMA180_NEW_DATA_INT,
          BMA180_RESET,
+        BMA180_CHIP_ID,
          bma180_chip_config,
          bma180_chip_disable,
      },
@@ -646,6 +651,22 @@ static const struct bma180_part_info bma180_part_info[] = {
          BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1,
          BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK,
          BMA250_RESET_REG,
+        BMA180_CHIP_ID,
+        bma250_chip_config,
+        bma250_chip_disable,
+    },
+    [BMA250E] = {
+        bma250_channels, ARRAY_SIZE(bma250_channels),
+        bma250_scale_table, ARRAY_SIZE(bma250_scale_table),
+        bma250_bw_table, ARRAY_SIZE(bma250_bw_table),
+        BMA250_INT_RESET_REG, BMA250_INT_RESET_MASK,

drivers/iio/accel/bma180.c static const struct bma180_part_info bma180_part_info[] = { · line 672

Quoted 10 lines
drivers/iio/accel/bma180.c +7 -0
+        BMA250_POWER_REG, BMA250_SUSPEND_MASK,
+        BMA250_BW_REG, BMA250_BW_MASK,
+        BMA250_RANGE_REG, BMA250_RANGE_MASK,
+        BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1,
+        BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK,
+        BMA250_RESET_REG,
+        BMA250E_CHIP_ID,
          bma250_chip_config,
          bma250_chip_disable,
      },

Yikes. I never picked up on this being there before.
Assigning elements of such a large structure is always going to be fragile.

I'll probably take this patch as is, but we really ought to move over to using named element assignment in here. It'll be a little more verbose but
way less fragile! Not to mention allows the possibly upcoming
structure random ordering to work (if that merges).

Quoted 8 lines
drivers/iio/accel/bma180.c +1 -0
@@ -845,6 +866,7 @@ static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume);
  static struct i2c_device_id bma180_ids[] = {
      { "bma180", BMA180 },
      { "bma250", BMA250 },
+    { "bma250e", BMA250E },
      { }
  };
 
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#2 lore raw

Re: [PATCH v2 2/2] iio: accel: bma180: Add ACPI enumeration support for BMA250E

In reply to Hans de Goede
Quoted 3 lines · Hans de Goede

Some x86 tablets use the BMA250E accelerometer, add support for this.

Applied to the togreg branch of iio.git and pushed out as testing.

Jonathan

Quoted 71 lines

---
Changes in v2:

(quoted diff) +0 -3
-Rebase on top of current master
-Map ACPI "BMA250E" to BMA250E not BMA250, these are not the same
---
  drivers/iio/accel/bma180.c | 21 +++++++++++++++++++--
  1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iio/accel/bma180.c +19 -2
index 3d6694821a96..17b7953f2502 100644
@@ -14,6 +14,7 @@
   * BMA250: 7-bit I2C slave address 0x18 or 0x19
   */
 
+#include <linux/acpi.h>
  #include <linux/module.h>
  #include <linux/i2c.h>
  #include <linux/interrupt.h>
@@ -727,6 +728,8 @@ static const struct iio_trigger_ops bma180_trigger_ops = {
  static int bma180_probe(struct i2c_client *client,
  		const struct i2c_device_id *id)
  {
+	struct device *dev = &client->dev;
+	const struct acpi_device_id *acpi_id;
  	struct bma180_data *data;
  	struct iio_dev *indio_dev;
  	enum chip_ids chip;
@@ -739,10 +742,17 @@ static int bma180_probe(struct i2c_client *client,
  	data = iio_priv(indio_dev);
  	i2c_set_clientdata(client, indio_dev);
  	data->client = client;
-	if (client->dev.of_node)
+	if (dev->of_node) {
  		chip = (enum chip_ids)of_device_get_match_data(&client->dev);
-	else
+	} else if (id) {
  		chip = id->driver_data;
+	} else {
+		acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
+		if (!acpi_id)
+			return -ENODEV;
+
+		chip = acpi_id->driver_data;
+	}
  	data->part_info = &bma180_part_info[chip];
 
  	ret = data->part_info->chip_config(data);
@@ -863,6 +873,12 @@ static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume);
  #define BMA180_PM_OPS NULL
  #endif
 
+static const struct acpi_device_id bma180_acpi_match[] = {
+	{ "BMA250E", BMA250E },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, bma180_acpi_match);
+
  static struct i2c_device_id bma180_ids[] = {
  	{ "bma180", BMA180 },
  	{ "bma250", BMA250 },
@@ -888,6 +904,7 @@ MODULE_DEVICE_TABLE(of, bma180_of_match);
  static struct i2c_driver bma180_driver = {
  	.driver = {
  		.name	= "bma180",
+		.acpi_match_table = ACPI_PTR(bma180_acpi_match),
  		.pm	= BMA180_PM_OPS,
  		.of_match_table = bma180_of_match,
  	},