devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Heiko Stübner" <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
To: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Grant Likely
	<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 2/6] of: add function to check against a list of compatible strings
Date: Tue, 15 Oct 2013 12:47:50 +0200	[thread overview]
Message-ID: <201310151247.50408.heiko@sntech.de> (raw)
In-Reply-To: <201310151246.49402.heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>

The basic of functions already provide a of_device_is_compatible to check
if a device's compatible property contains a specific one. But sometimes
it's also necessary to check if the device is compatible to one out of a
list of compatible devices.

Therefore add of_device_is_any_of that reuses the compatible check of
of_device_is_compatible but checks against a list of compatible strings
without the locking overhead of calling of_device_is_compatible multiple
times.

Signed-off-by: Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
---
 drivers/of/base.c  |   21 +++++++++++++++++++++
 include/linux/of.h |    2 ++
 2 files changed, 23 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 865d3f6..589f43e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -366,6 +366,27 @@ int of_device_is_compatible(const struct device_node *device,
 EXPORT_SYMBOL(of_device_is_compatible);
 
 /**
+ * Checks if any of the given "compat" strings matches one of the strings
+ * in the device's "compatible" property.
+ */
+int of_device_is_any_of(const struct device_node *device,
+			const char * const *compat, int num) {
+	unsigned long flags;
+	int res = 0, i;
+
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+	for (i = 0; i < num; i++) {
+		if (__of_device_is_compatible(device, compat[i])) {
+			res = 1;
+			break;
+		}
+	}
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	return res;
+}
+EXPORT_SYMBOL(of_device_is_any_of);
+
+/**
  * of_machine_is_compatible - Test root of device tree for a given compatible value
  * @compat: compatible string to look for in root node's compatible property.
  *
diff --git a/include/linux/of.h b/include/linux/of.h
index f95aee3..5bf7c9a 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -262,6 +262,8 @@ extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 extern int of_device_is_compatible(const struct device_node *device,
 				   const char *);
+extern int of_device_is_any_of(const struct device_node *device,
+			       const char * const *compat, int num);
 extern int of_device_is_available(const struct device_node *device);
 extern const void *of_get_property(const struct device_node *node,
 				const char *name,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-10-15 10:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-15 10:46 [PATCH 0/6] pinctrl: rockchip: add rk3188 support Heiko Stübner
     [not found] ` <201310151246.49402.heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
2013-10-15 10:47   ` [PATCH 1/6] pinctrl: rockchip: separate different sub-types more Heiko Stübner
2013-10-15 10:47   ` Heiko Stübner [this message]
2013-10-15 11:11     ` [PATCH 2/6] of: add function to check against a list of compatible strings Mark Rutland
     [not found]       ` <20131015111145.GE19196-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2013-10-15 12:44         ` Heiko Stübner
2013-10-15 10:48   ` [PATCH 3/6] pinctrl: rockchip: add support for multiple bank types Heiko Stübner
2013-10-15 10:48   ` [PATCH 4/6] pinctrl: rockchip: remove redundant check Heiko Stübner
2013-10-15 10:49   ` [PATCH 5/6] pinctrl: rockchip: add rk3188 specifics Heiko Stübner
2013-10-15 10:49   ` [PATCH 6/6] pinctrl: rockchip: emulate both edge triggered interrupts Heiko Stübner

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=201310151247.50408.heiko@sntech.de \
    --to=heiko-4mtyjxux2i+zqb+pc5nmwq@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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).