mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Crestez Dan Leonard <leonard.crestez@intel.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Crestez Dan Leonard <leonard.crestez@intel.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Len Brown <lenb@kernel.org>,
	linux-i2c@vger.kernel.org, Wolfram Sang <wsa@the-dreams.de>,
	linux-kernel@vger.kernel.org,
	Irina Tirdea <irina.tirdea@intel.com>,
	Octavian Purdila <octavian.purdila@intel.com>
Subject: [RFC 2/2] i2c: Pass i2c_device_id to probe func when using DT ids through ACPI
Date: Mon,  6 Jun 2016 23:03:28 +0300	[thread overview]
Message-ID: <3d3faf7ace51bb7dcf27c328e82653aa28298936.1465242308.git.leonard.crestez@intel.com> (raw)
In-Reply-To: <cover.1465242308.git.leonard.crestez@intel.com>
In-Reply-To: <cover.1465242308.git.leonard.crestez@intel.com>

When devices are instatiated through devicetree the i2c_client->name is
set to the compatible string with company name stripped out. This is
then matched to the i2c_device_id table to pass the device_id to the
probe function. This id parameter is used by some device drivers to
differentiate between model numbers.

When using ACPI this id parameter is NULL and the driver usually needs
to do ACPI-specific differentiation.

This patch attempts to find a valid i2c_device_id when using ACPI with
DT-like compatible strings.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
---
 drivers/i2c/i2c-core.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 3ffeb6c..c899108 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -581,17 +581,23 @@ static inline int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
 
 /* ------------------------------------------------------------------------- */
 
-static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
-						const struct i2c_client *client)
+static const struct i2c_device_id *i2c_match_id_name(const struct i2c_device_id *id,
+						     const char *id_name)
 {
 	while (id->name[0]) {
-		if (strcmp(client->name, id->name) == 0)
+		if (strcmp(id_name, id->name) == 0)
 			return id;
 		id++;
 	}
 	return NULL;
 }
 
+static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
+						const struct i2c_client *client)
+{
+	return i2c_match_id_name(id, client->name);
+}
+
 static int i2c_device_match(struct device *dev, struct device_driver *drv)
 {
 	struct i2c_client	*client = i2c_verify_client(dev);
@@ -767,6 +773,7 @@ static int i2c_device_probe(struct device *dev)
 {
 	struct i2c_client	*client = i2c_verify_client(dev);
 	struct i2c_driver	*driver;
+	const struct i2c_device_id *i2c_device_id;
 	int status;
 
 	if (!client)
@@ -826,6 +833,19 @@ static int i2c_device_probe(struct device *dev)
 	if (status == -EPROBE_DEFER)
 		goto err_clear_wakeup_irq;
 
+	i2c_device_id = i2c_match_id(driver->id_table, client);
+#ifdef CONFIG_ACPI
+	if (!i2c_device_id) {
+		const char *id_name;
+		const struct of_device_id *ofid;
+
+		ofid = acpi_of_match_device(ACPI_COMPANION(&client->dev),
+					    driver->driver.of_match_table);
+		id_name = strchr(ofid->name, ',');
+		id_name = id_name ? id_name + 1 : ofid->name;
+		i2c_device_id = i2c_match_id_name(driver->id_table, id_name);
+	}
+#endif
 	status = driver->probe(client, i2c_match_id(driver->id_table, client));
 	if (status)
 		goto err_detach_pm_domain;
-- 
2.5.5

  parent reply	other threads:[~2016-06-06 20:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06 20:03 [RFC 0/2] Match i2c_device_id " Crestez Dan Leonard
2016-06-06 20:03 ` [RFC 1/2] acpi: Expose acpi_of_match_device Crestez Dan Leonard
2016-06-06 20:03 ` Crestez Dan Leonard [this message]
2016-06-08  0:15 ` [RFC 0/2] Match i2c_device_id when using DT ids through ACPI Rafael J. Wysocki

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=3d3faf7ace51bb7dcf27c328e82653aa28298936.1465242308.git.leonard.crestez@intel.com \
    --to=leonard.crestez@intel.com \
    --cc=irina.tirdea@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=octavian.purdila@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=wsa@the-dreams.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®