linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: linuxppc-dev@ozlabs.org
Subject: [PATCH] of: i2c: improve last resort compatible entry selection
Date: Mon, 14 Jul 2008 21:54:37 +0400	[thread overview]
Message-ID: <20080714175437.GA5230@polina.dev.rtsoft.ru> (raw)

Currently of_i2c will select first compatible property as a last resort
option. This isn't best choice though, because generic compatible entries
are listed last, not first. For example, two compatible entries given for
the MCU node:

"fsl,mc9s08qg8-mpc837xrdb", "fsl,mcu-mpc8349emitx";

Since no sane driver will ever match specific devices, what we want is
to select most generic option (last). Then driver may call
of_device_is_compatible() if it is really interested in details.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---

Other options are: start filling the exceptions list, or add  "linux,..."
compatible entry to the device tree.

 drivers/of/of_i2c.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index b2ccdcb..0d35a0a 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -29,6 +29,7 @@ static int of_find_i2c_driver(struct device_node *node,
 	int i, cplen;
 	const char *compatible;
 	const char *p;
+	const char *last_wcomma = NULL;
 
 	/* 1. search for exception list entry */
 	for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
@@ -45,7 +46,7 @@ static int of_find_i2c_driver(struct device_node *node,
 	if (!compatible)
 		return -ENODEV;
 
-	/* 2. search for linux,<i2c-type> entry */
+	/* 2. search for linux,<i2c-type> entry, or remember last w/ comma */
 	p = compatible;
 	while (cplen > 0) {
 		if (!strncmp(p, "linux,", 6)) {
@@ -54,6 +55,12 @@ static int of_find_i2c_driver(struct device_node *node,
 				    I2C_NAME_SIZE) >= I2C_NAME_SIZE)
 				return -ENOMEM;
 			return 0;
+		} else {
+			const char *comma;
+
+			comma = strchr(p, ',');
+			if (comma)
+				last_wcomma = comma + 1;
 		}
 
 		i = strlen(p) + 1;
@@ -61,12 +68,10 @@ static int of_find_i2c_driver(struct device_node *node,
 		cplen -= i;
 	}
 
-	/* 3. take fist compatible entry and strip manufacturer */
-	p = strchr(compatible, ',');
-	if (!p)
+	/* 3. take last compatible entry w/ comma, manufacturer stripped */
+	if (!last_wcomma)
 		return -ENODEV;
-	p++;
-	if (strlcpy(info->type, p, I2C_NAME_SIZE) >= I2C_NAME_SIZE)
+	if (strlcpy(info->type, last_wcomma, I2C_NAME_SIZE) >= I2C_NAME_SIZE)
 		return -ENOMEM;
 	return 0;
 }
-- 
1.5.5.4

             reply	other threads:[~2008-07-14 17:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-14 17:54 Anton Vorontsov [this message]
2008-07-15 10:44 ` [PATCH] of: i2c: improve last resort compatible entry selection Jochen Friedrich
2008-07-15 13:40   ` Jon Smirl
2008-07-15 14:05     ` Jean Delvare
2008-07-15 14:52       ` Jochen Friedrich
2008-07-15 15:39         ` Jean Delvare
2008-07-27  0:11 ` Grant Likely
2008-07-27  5:05   ` Jon Smirl
2008-07-27  5:35     ` Grant Likely
2008-07-27 14:21       ` Jon Smirl
2008-07-27 21:52         ` Segher Boessenkool
2008-07-27 22:00           ` Jon Smirl
2008-07-28  4:16             ` M. Warner Losh
2008-07-28  7:47             ` Segher Boessenkool
2008-07-30 14:42               ` Grant Likely
2008-07-30 20:20                 ` Jon Smirl

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=20080714175437.GA5230@polina.dev.rtsoft.ru \
    --to=avorontsov@ru.mvista.com \
    --cc=linuxppc-dev@ozlabs.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).