All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: jic23@kernel.org
Cc: linux-iio@vger.kernel.org,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Subject: [PATCH 3/3] iio: ak8975: Added autodetect feature for ACPI
Date: Mon, 15 Dec 2014 13:19:23 -0800	[thread overview]
Message-ID: <1418678363-22437-4-git-send-email-srinivas.pandruvada@linux.intel.com> (raw)
In-Reply-To: <1418678363-22437-1-git-send-email-srinivas.pandruvada@linux.intel.com>

Using i2c auto detect feature and auto device creation feature,
enumerate ak8975 device, by checking their presence.
This is needed because when this device sits behind an i2c mux, there
is no way to define i2c mux in ACPI. This will enable ak8975 on
windows based tablets/laptops running Linux when connected via a mux.
Since DT model already can define an i2c mux and devices connected to
it, this feature is only enabled for ACPI.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/magnetometer/ak8975.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index 0d10a4b..c3455bd 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -820,6 +820,36 @@ static const struct i2c_device_id ak8975_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, ak8975_id);
 
+#if defined(CONFIG_ACPI)
+static int ak8975_detect(struct i2c_client *temp_client,
+			 struct i2c_board_info *info)
+{
+	struct i2c_adapter *adapter;
+	int i, j;
+	int ret;
+
+	/* autodetect only when we are behind a mux */
+	adapter = i2c_parent_is_i2c_adapter(temp_client->adapter);
+	if (!adapter)
+		return -ENODEV;
+
+	for (i = 0; i < AK_MAX_TYPE; ++i) {
+		ret = ak8975_who_i_am(temp_client, i);
+		if (ret >= 0) {
+			for (j = 0; j < ARRAY_SIZE(ak8975_id) - 1; ++j) {
+				if (i == (int)ak8975_id[j].driver_data) {
+					strlcpy(info->type, ak8975_id[j].name,
+						I2C_NAME_SIZE);
+					return 0;
+				}
+			}
+		}
+	}
+
+	return -ENODEV;
+}
+#endif
+
 static const struct of_device_id ak8975_of_match[] = {
 	{ .compatible = "asahi-kasei,ak8975", },
 	{ .compatible = "ak8975", },
@@ -841,6 +871,11 @@ static struct i2c_driver ak8975_driver = {
 	},
 	.probe		= ak8975_probe,
 	.id_table	= ak8975_id,
+#if defined(CONFIG_ACPI)
+	.class		= I2C_CLASS_HWMON,
+	.address_list	= I2C_ADDRS(0x0C, 0x0D, 0x0E, 0x0F),
+	.detect		= ak8975_detect,
+#endif
 };
 module_i2c_driver(ak8975_driver);
 
-- 
1.9.3

  parent reply	other threads:[~2014-12-15 21:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-15 21:19 [PATCH 0/3] Enable AK8963 conneted via INV6500 Srinivas Pandruvada
2014-12-15 21:19 ` [PATCH 1/3] iio: imu: inv_mpu6050: ACPI enumeration Srinivas Pandruvada
2014-12-26 12:39   ` Jonathan Cameron
2014-12-15 21:19 ` [PATCH 2/3] iio: imu: inv_mpu6050: Added adapter class Srinivas Pandruvada
2014-12-26 12:37   ` Jonathan Cameron
2014-12-31 10:25     ` Wolfram Sang
2015-01-01 12:27       ` Jonathan Cameron
2015-01-04 19:20       ` Jean Delvare
2014-12-15 21:19 ` Srinivas Pandruvada [this message]
     [not found]   ` <1418678363-22437-4-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-12-18 16:28     ` [PATCH 3/3] iio: ak8975: Added autodetect feature for ACPI Lars-Peter Clausen
2014-12-18 16:28       ` Lars-Peter Clausen
     [not found]       ` <549300A5.5080904-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2014-12-18 16:52         ` Srinivas Pandruvada
2014-12-18 16:52           ` Srinivas Pandruvada
     [not found]           ` <1418921521.740.282.camel-hINH/TbAiWppyMZ9rn1DP+ejPoqOX1/hEvhb3Hwu1Ks@public.gmane.org>
2014-12-18 17:05             ` Lars-Peter Clausen
2014-12-18 17:05               ` Lars-Peter Clausen
     [not found]               ` <54930965.3030008-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2014-12-18 17:30                 ` Srinivas Pandruvada
2014-12-18 17:30                   ` Srinivas Pandruvada
     [not found]                   ` <1418923812.4459.8.camel-hINH/TbAiWppyMZ9rn1DP+ejPoqOX1/hEvhb3Hwu1Ks@public.gmane.org>
2014-12-18 17:54                     ` Lars-Peter Clausen
2014-12-18 17:54                       ` Lars-Peter Clausen
     [not found]                       ` <549314C4.8090001-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2014-12-18 18:00                         ` Srinivas Pandruvada
2014-12-18 18:00                           ` Srinivas Pandruvada
     [not found]                           ` <1418925641.4459.11.camel-hINH/TbAiWppyMZ9rn1DP+ejPoqOX1/hEvhb3Hwu1Ks@public.gmane.org>
2014-12-26 11:53                             ` Jonathan Cameron
2014-12-26 11:53                               ` Jonathan Cameron
     [not found]                               ` <549D4C1F.6050907-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-01-08 16:40                                 ` Wolfram Sang
2015-01-08 16:40                                   ` Wolfram Sang
2015-01-08 16:54                                   ` Srinivas Pandruvada
2015-01-08 16:54                                     ` Srinivas Pandruvada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418678363-22437-4-git-send-email-srinivas.pandruvada@linux.intel.com \
    --to=srinivas.pandruvada@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.