linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/3] i2c: Provide 'device type' to 'OF device node' look-up
Date: Mon,  2 Jun 2014 14:41:01 +0100	[thread overview]
Message-ID: <1401716463-23457-2-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1401716463-23457-1-git-send-email-lee.jones@linaro.org>

We have a problem.  There are lots of I2C device ID tables scattered
around the kernel which are redundant in all Device Tree and/or ACPI
only supported device drivers.  After recent discussions it has become
apparent that the only thing blocking the complete removal of these
tables is the continued support of 'register an I2C device via sysfs'
functionality.  As the sysfs method doesn't know anything about Device
Tree or ACPI, we can not pass any nodes in.  This patch searches all
known Device Tree nodes and attempts to acquire a match from the
device name provided via sysfs.  It can not fail, but if found assigns
the matching of_node to i2c_board_info prior to registering.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/i2c/i2c-core.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7c7f4b8..2e47641 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -64,6 +64,7 @@ static DEFINE_IDR(i2c_adapter_idr);
 
 static struct device_type i2c_client_type;
 static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
+static struct device_node *of_i2c_type_to_node(char *type);
 
 static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE;
 
@@ -863,6 +864,8 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
 		return -EINVAL;
 	}
 
+	info.of_node = of_i2c_type_to_node(info.type);
+
 	client = i2c_new_device(adap, &info);
 	if (!client)
 		return -EINVAL;
@@ -1088,8 +1091,36 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
 	return i2c_verify_adapter(dev);
 }
 EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
+
+static struct device_node *of_i2c_type_to_node(char *type)
+{
+	struct device_node *np;
+	const char *compatible, *name;
+	int len;
+
+	if (!type)
+		return NULL;
+
+	for_each_of_allnodes(np) {
+		compatible = of_get_property(np, "compatible", &len);
+		if (!compatible)
+			continue;
+
+		name = strchr(compatible, ',');
+		if (!name)
+			name = compatible;
+		else
+			name++;
+
+		if (!strncmp(name, type, len - (name - compatible)))
+			return np;
+	}
+
+	return NULL;
+}
 #else
 static void of_i2c_register_devices(struct i2c_adapter *adap) { }
+static struct device_node *of_i2c_type_to_node(char *type) { return NULL; }
 #endif /* CONFIG_OF */
 
 /* ACPI support code */
-- 
1.8.3.2

  reply	other threads:[~2014-06-02 13:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-02 13:41 [PATCH 0/3] i2c: Relax requirement for I2C Device ID tables Lee Jones
2014-06-02 13:41 ` Lee Jones [this message]
2014-06-02 13:57   ` [PATCH 1/3] i2c: Provide 'device type' to 'OF device node' look-up Lee Jones
2014-06-02 16:06   ` Grant Likely
2014-06-02 16:19     ` Lee Jones
2014-06-02 13:41 ` [PATCH 2/3] i2c: Add pointer dereference protection to i2c_match_id() Lee Jones
2014-06-02 16:07   ` Grant Likely
2014-06-02 13:41 ` [PATCH 3/3] i2c: Make I2C ID tables non-mandatory for DT'ed and/or ACPI'ed devices Lee Jones
2014-06-02 14:34   ` One Thousand Gnomes
2014-06-03  8:11     ` Lee Jones
2014-06-02 16:08   ` Grant Likely
2014-06-03  8:11     ` Lee Jones
2014-06-03  9:18       ` Grant Likely

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=1401716463-23457-2-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.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 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).