linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: accel: bmc150: Check for a second ACPI device for BOSC0200
@ 2017-12-06 17:52 Jeremy Cline
  2017-12-10 18:21 ` Jonathan Cameron
  0 siblings, 1 reply; 31+ messages in thread
From: Jeremy Cline @ 2017-12-06 17:52 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler
  Cc: Hans de Goede, Lars Kellogg-Stedman, Steven Presser,
	Mika Westerberg, Wolfram Sang, linux-iio, linux-kernel,
	Jeremy Cline

Some BOSC0200 acpi_device-s describe two accelerometers in a single ACPI
device. Check for a companion device and handle a second i2c_client
if it is present.

Signed-off-by: Jeremy Cline <jeremy@jcline.org>
---
Changes in v2:
  - Rather than exposing the bmc150_accel_data struct, use get and set
    functions.

 drivers/iio/accel/bmc150-accel-core.c | 20 ++++++++++++++++++++
 drivers/iio/accel/bmc150-accel-i2c.c  | 29 ++++++++++++++++++++++++++++-
 drivers/iio/accel/bmc150-accel.h      |  2 ++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 870f92ef61c2..7496c5121a8c 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -204,6 +204,7 @@ struct bmc150_accel_data {
 	int ev_enable_state;
 	int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
 	const struct bmc150_accel_chip_info *chip_info;
+	struct i2c_client *second_device;
 };
 
 static const struct {
@@ -1659,6 +1660,25 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 }
 EXPORT_SYMBOL_GPL(bmc150_accel_core_probe);
 
+struct i2c_client *bmc150_get_second_device(struct i2c_client *client)
+{
+	struct bmc150_accel_data *data = i2c_get_clientdata(client);
+
+	if (!data)
+		return NULL;
+
+	return data->second_device;
+}
+EXPORT_SYMBOL_GPL(bmc150_get_second_device);
+
+void bmc150_set_second_device(struct i2c_client *client)
+{
+	struct bmc150_accel_data *data = i2c_get_clientdata(client);
+	if (data)
+		data->second_device = client;
+}
+EXPORT_SYMBOL_GPL(bmc150_set_second_device);
+
 int bmc150_accel_core_remove(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
index f85014fbaa12..c7341df086e2 100644
--- a/drivers/iio/accel/bmc150-accel-i2c.c
+++ b/drivers/iio/accel/bmc150-accel-i2c.c
@@ -31,6 +31,10 @@
 static int bmc150_accel_probe(struct i2c_client *client,
 			      const struct i2c_device_id *id)
 {
+	int ret;
+	struct acpi_device *adev;
+	struct i2c_board_info board_info;
+	struct i2c_client *second_dev;
 	struct regmap *regmap;
 	const char *name = NULL;
 	bool block_supported =
@@ -47,12 +51,35 @@ static int bmc150_accel_probe(struct i2c_client *client,
 	if (id)
 		name = id->name;
 
-	return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name,
+	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name,
 				       block_supported);
+	if (ret)
+		return ret;
+
+	/*
+	 * Some BOSC0200 acpi_devices describe 2 accelerometers in a single ACPI
+	 * device, try instantiating a second i2c_client for an I2cSerialBusV2
+	 * ACPI resource with index 1.
+	 */
+	adev = ACPI_COMPANION(&client->dev);
+	if (adev && strcmp(acpi_device_hid(adev), "BOSC0200") == 0) {
+		memset(&board_info, 0, sizeof(board_info));
+		strlcpy(board_info.type, "bma250e", I2C_NAME_SIZE);
+		second_dev = i2c_acpi_new_device(&client->dev, 1, &board_info);
+		if (second_dev)
+			bmc150_set_second_device(second_dev);
+	}
+
+	return ret;
 }
 
 static int bmc150_accel_remove(struct i2c_client *client)
 {
+	struct i2c_client *second_dev = bmc150_get_second_device(client);
+
+	if (second_dev)
+		i2c_unregister_device(second_dev);
+
 	return bmc150_accel_core_remove(&client->dev);
 }
 
diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h
index ae6118ae11b1..6e965a3ca322 100644
--- a/drivers/iio/accel/bmc150-accel.h
+++ b/drivers/iio/accel/bmc150-accel.h
@@ -16,6 +16,8 @@ enum {
 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 			    const char *name, bool block_supported);
 int bmc150_accel_core_remove(struct device *dev);
+struct i2c_client *bmc150_get_second_device(struct i2c_client *second_device);
+void bmc150_set_second_device(struct i2c_client *second_device);
 extern const struct dev_pm_ops bmc150_accel_pm_ops;
 extern const struct regmap_config bmc150_regmap_conf;
 
-- 
2.14.3

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

end of thread, other threads:[~2018-02-16 14:50 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06 17:52 [PATCH v2] iio: accel: bmc150: Check for a second ACPI device for BOSC0200 Jeremy Cline
2017-12-10 18:21 ` Jonathan Cameron
2018-01-09 21:24   ` Jeremy Cline
2018-01-14 10:43     ` Jonathan Cameron
2018-01-28  9:40       ` Jonathan Cameron
2018-01-29 14:07         ` Andy Shevchenko
2018-01-30 16:01           ` Jonathan Cameron
2018-01-30 16:40             ` Andy Shevchenko
2018-01-30 17:05               ` Andy Shevchenko
     [not found]                 ` <CADXBfmvKF_doLv0Vg0TY4cH_rDBEP5NvJ4jHJf85iuOjJB6TzA@mail.gmail.com>
2018-01-30 17:38                   ` Andy Shevchenko
2018-01-30 18:08                     ` Andy Shevchenko
2018-01-30 18:33                       ` Jonathan Cameron
2018-01-30 18:46                         ` Jonathan Cameron
2018-01-30 18:47                           ` Andy Shevchenko
2018-01-30 18:34                     ` Steven Presser
2018-01-30 19:05                       ` Andy Shevchenko
2018-01-30 19:27                         ` Steven Presser
2018-01-30 20:12                           ` Andy Shevchenko
2018-01-30 21:20                             ` Andy Shevchenko
2018-01-31 10:55                               ` Jonathan Cameron
2018-02-04 18:25                               ` Steven Presser
2018-02-15 12:50                                 ` Andy Shevchenko
     [not found]                                   ` <CADXBfmsJPv9Q6W+j=RdzUAHJ9Ya-6zrV9Ns7KMNBHOAnn_BZuA@mail.gmail.com>
2018-02-16 14:50                                     ` Andy Shevchenko
2018-02-04 17:58                             ` Steven Presser
2018-02-06 19:47                               ` Andy Shevchenko
2018-01-31 11:43                     ` Hans de Goede
2018-01-31 12:25                       ` Andy Shevchenko
2018-01-31 14:58                         ` Hans de Goede
2018-01-31 15:19                           ` Andy Shevchenko
2018-01-31 19:53                           ` Jeremy Cline
2018-01-30 15:22         ` Jeremy Cline

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