From: Tony Lindgren <tony@atomide.com>
To: Frank Rowand <frowand.list@gmail.com>,
Grant Likely <grant.likely@linaro.org>,
Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-omap@vger.kernel.org
Subject: [PATCH] of/platform: Allow secondary compatible match in of_dev_lookup
Date: Fri, 1 Apr 2016 14:35:04 -0700 [thread overview]
Message-ID: <1459546504-32668-1-git-send-email-tony@atomide.com> (raw)
We currently try to match of_dev_auxdata based on compatible,
IO address, and device name. But in some cases we have multiple
instances of drivers that can use the same auxdata.
Let's add an additional secondary lookup for generic compatible
match for auxdata if no device specific match is found. This does
not change the existing matching, and still allows adding device
specific auxdata.
This simplifies things as specifying the IO address and device
name is prone errors as it requires maintaining an in kernel
database for each SoC.
To specify a generic match, all that is needed is to add a
OF_DEV_AUXDATA entry with no device instance specified:
OF_DEV_AUXDATA("pinctrl-single", 0, NULL, &pcs_pdata),
As the auxdata is already initialized only for the booted SoC,
there's not much of a chance of getting things wrong.
Let's also fix two checkpatch warnings while at it to add a
space before parenthesis in the for loop, and remove a comparison
to NULL by using !auxdata->compatible.
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
drivers/of/platform.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 8d103e4..16e8daf 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -297,19 +297,37 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *lookup,
struct device_node *np)
{
+ const struct of_dev_auxdata *auxdata;
struct resource res;
+ int compatible = 0;
if (!lookup)
return NULL;
- for(; lookup->compatible != NULL; lookup++) {
- if (!of_device_is_compatible(np, lookup->compatible))
+ auxdata = lookup;
+ for (; auxdata->compatible; auxdata++) {
+ if (!of_device_is_compatible(np, auxdata->compatible))
continue;
+ compatible++;
if (!of_address_to_resource(np, 0, &res))
- if (res.start != lookup->phys_addr)
+ if (res.start != auxdata->phys_addr)
continue;
- pr_debug("%s: devname=%s\n", np->full_name, lookup->name);
- return lookup;
+ pr_debug("%s: devname=%s\n", np->full_name, auxdata->name);
+ return auxdata;
+ }
+
+ if (!compatible)
+ return NULL;
+
+ /* Try compatible match if no phys_addr and name are specified */
+ auxdata = lookup;
+ for (; auxdata->compatible; auxdata++) {
+ if (!of_device_is_compatible(np, auxdata->compatible))
+ continue;
+ if (!auxdata->phys_addr && !auxdata->name) {
+ pr_debug("%s: compatible match\n", np->full_name);
+ return auxdata;
+ }
}
return NULL;
--
2.7.0
next reply other threads:[~2016-04-01 21:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-01 21:35 Tony Lindgren [this message]
[not found] ` <1459546504-32668-1-git-send-email-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-04-01 21:40 ` [PATCH] of/platform: Allow secondary compatible match in of_dev_lookup Tony Lindgren
[not found] ` <20160401214053.GQ9329-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-04-07 4:52 ` Rob Herring
[not found] ` <CAL_Jsq+PcTD=duHmWgHyx_ywYbT10vEtcm=79x5o5wYSkgG63g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-07 10:21 ` Grygorii Strashko
[not found] ` <5706348C.1040709-l0cyMroinI0@public.gmane.org>
2016-04-07 11:15 ` Felipe Balbi
2016-04-12 15:13 ` Tony Lindgren
2016-04-07 16:58 ` Tony Lindgren
[not found] ` <20160407165842.GJ16484-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-04-12 15:56 ` Rob Herring
[not found] ` <CAL_Jsq+XrNoqEjCnQ=rLJVdQe9EdHb+MopUtvM2vy12N2veo3A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-12 16:31 ` Tony Lindgren
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=1459546504-32668-1-git-send-email-tony@atomide.com \
--to=tony@atomide.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=grant.likely@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=robh+dt@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 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).