From: Lucas Stach <dev@lynxeye.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] of: import of_property_match_string from Linux
Date: Tue, 4 Jun 2013 09:29:10 +0200 [thread overview]
Message-ID: <1370330951-3548-2-git-send-email-dev@lynxeye.de> (raw)
In-Reply-To: <1370330951-3548-1-git-send-email-dev@lynxeye.de>
Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
drivers/of/base.c | 37 +++++++++++++++++++++++++++++++++++++
include/of.h | 2 ++
2 files changed, 39 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b3d012c..912e793 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -683,6 +683,43 @@ int of_property_read_string_index(struct device_node *np, const char *propname,
EXPORT_SYMBOL_GPL(of_property_read_string_index);
/**
+ * of_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int of_property_match_string(struct device_node *np, const char *propname,
+ const char *string)
+{
+ struct property *prop = of_find_property(np, propname);
+ size_t l;
+ int i;
+ const char *p, *end;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+
+ p = prop->value;
+ end = p + prop->length;
+
+ for (i = 0; p < end; i++, p += l) {
+ l = strlen(p) + 1;
+ if (p + l > end)
+ return -EILSEQ;
+ pr_debug("comparing %s with %s\n", string, p);
+ if (strcmp(string, p) == 0)
+ return i; /* Found it; return index */
+ }
+ return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_match_string);
+
+/**
* of_modalias_node - Lookup appropriate modalias for a device node
* @node: pointer to a device tree node
* @modalias: Pointer to buffer that modalias value will be copied into
diff --git a/include/of.h b/include/of.h
index f00d1b4..27fd8da 100644
--- a/include/of.h
+++ b/include/of.h
@@ -172,6 +172,8 @@ int of_property_read_string(struct device_node *np, const char *propname,
const char **out_string);
int of_property_read_string_index(struct device_node *np, const char *propname,
int index, const char **output);
+int of_property_match_string(struct device_node *np, const char *propname,
+ const char *string);
int of_set_property(struct device_node *node, const char *p, const void *val, int len,
int create);
struct device_node *of_create_node(struct device_node *root, const char *path);
--
1.8.2.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-06-04 7:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-04 7:29 [PATCH 1/3] of: update of_parse_phandle_with_args to latest linux code Lucas Stach
2013-06-04 7:29 ` Lucas Stach [this message]
2013-06-04 7:29 ` [PATCH 3/3] clk: add clock lookup from devicetree Lucas Stach
2013-06-05 6:47 ` Sascha Hauer
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=1370330951-3548-2-git-send-email-dev@lynxeye.de \
--to=dev@lynxeye.de \
--cc=barebox@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