From: Huang Shijie <b32955@freescale.com>
To: <grant.likely@linaro.org>
Cc: <rob.herring@calxeda.com>, <devicetree-discuss@lists.ozlabs.org>,
<linux-kernel@vger.kernel.org>, <shawn.guo@linaro.org>,
<linux-arm-kernel@lists.infradead.org>,
Huang Shijie <b32955@freescale.com>
Subject: [PATCH] of: match the compatible in the order set by the dts file
Date: Fri, 5 Jul 2013 16:43:38 +0800 [thread overview]
Message-ID: <1373013818-11365-1-git-send-email-b32955@freescale.com> (raw)
If we set the uart compatible in the dts file like this:
------------------------------------------------------
compatible = "fsl,imx6q-uart", "fsl,imx21-uart";
------------------------------------------------------
and we set the uart compatible in the uart driver like this:
------------------------------------------------------
{ .compatible = "fsl,imx1-uart", ... },
{ .compatible = "fsl,imx21-uart", ... },
{ .compatible = "fsl,imx6q-uart", ... },
{ /* sentinel */ }
------------------------------------------------------
the current code will match the "fsl,imx21-uart" in the end.
Of course, this is not what we want. We want it to match the "fsl,imx6q-uart".
This patch rewrites the match code, and make it to check the compatible
in the order set by the DTS file.
Signed-off-by: Huang Shijie <b32955@freescale.com>
---
drivers/of/base.c | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 0d61fc5..b13846b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -622,10 +622,14 @@ static
const struct of_device_id *__of_match_node(const struct of_device_id *matches,
const struct device_node *node)
{
+ struct of_device_id *old = (struct of_device_id *)matches;
+ const char *cp;
+ int cplen, l;
+
if (!matches)
return NULL;
- while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
+ while (matches->name[0] || matches->type[0]) {
int match = 1;
if (matches->name[0])
match &= node->name
@@ -633,13 +637,30 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
if (matches->type[0])
match &= node->type
&& !strcmp(matches->type, node->type);
- if (matches->compatible[0])
- match &= __of_device_is_compatible(node,
- matches->compatible);
if (match)
return matches;
matches++;
}
+
+ /* Check the compatible in the order set by the DTS file. */
+ cp = __of_get_property(node, "compatible", &cplen);
+ if (!cp)
+ return NULL;
+
+ while (cplen > 0) {
+ matches = old;
+
+ while (matches->compatible[0]) {
+ if (!of_compat_cmp(cp, matches->compatible,
+ strlen(matches->compatible)))
+ return matches;
+ matches++;
+ }
+
+ l = strlen(cp) + 1;
+ cp += l;
+ cplen -= l;
+ }
return NULL;
}
--
1.7.1
next reply other threads:[~2013-07-05 9:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-05 8:43 Huang Shijie [this message]
2013-07-09 7:05 ` [PATCH] of: match the compatible in the order set by the dts file Sascha Hauer
2013-07-09 7:46 ` Huang Shijie
2013-07-09 7:51 ` Sascha Hauer
2013-07-09 8:10 ` Huang Shijie
2013-07-09 12:03 ` Rob Herring
2013-07-09 14:40 ` Stephen Warren
2013-07-10 2:58 ` Huang Shijie
2013-07-20 5:44 ` Grant Likely
2013-07-21 6:35 ` Thierry Reding
2013-07-21 20:45 ` Rob Herring
2013-07-21 23:36 ` Grant Likely
2013-07-09 14:27 ` Stephen Warren
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=1373013818-11365-1-git-send-email-b32955@freescale.com \
--to=b32955@freescale.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rob.herring@calxeda.com \
--cc=shawn.guo@linaro.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).