linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: linux-mmc@vger.kernel.org
Cc: Dirk Behme <dirk.behme@de.bosch.com>,
	Fabio Estevam <festevam@gmail.com>,
	ptx@pengutronix.de, Stephen Warren <swarren@wwwdotorg.org>,
	Sascha Hauer <s.hauer@pengutronix.de>
Subject: [PATCH 1/2] of: Add helper for getting the maximum alias index for a stem
Date: Thu, 22 May 2014 17:30:22 +0200	[thread overview]
Message-ID: <1400772623-8390-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1400772623-8390-1-git-send-email-s.hauer@pengutronix.de>

of_alias_max_index will return the maximum number for which an
alias of a given stem exists. This is useful for frameworks
whishing to reserve a number of device slots from dynamic
allocation.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c  | 29 +++++++++++++++++++++++++++++
 include/linux/of.h |  6 ++++++
 2 files changed, 35 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index f807d0e..f953b9d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1758,6 +1758,35 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
 		 ap->alias, ap->stem, ap->id, of_node_full_name(np));
 }
 
+/*
+ * of_alias_max_index() - get the maximum index for a given alias stem
+ * @stem:   The alias stem for which the maximum index is searched for
+ *
+ * Given an alias stem (the alias without the number) this function
+ * returns the maximum number for which an alias exists.
+ *
+ * Return: The maximum existing alias index or -ENODEV if no alias
+ *         exists for this stem.
+ */
+int of_alias_max_index(const char *stem)
+{
+	struct alias_prop *app;
+	int max = -ENODEV;
+
+	mutex_lock(&of_aliases_mutex);
+
+	list_for_each_entry(app, &aliases_lookup, link) {
+		if (strcmp(app->stem, stem))
+			continue;
+		if (app->id > max)
+			max = app->id;
+	}
+
+	mutex_unlock(&of_aliases_mutex);
+
+	return max;
+}
+
 /**
  * of_alias_scan - Scan all properties of 'aliases' node
  *
diff --git a/include/linux/of.h b/include/linux/of.h
index 276c546..963e295 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -305,6 +305,7 @@ extern int of_count_phandle_with_args(const struct device_node *np,
 
 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
 extern int of_alias_get_id(struct device_node *np, const char *stem);
+extern int of_alias_max_index(const char *stem);
 
 extern int of_machine_is_compatible(const char *compat);
 
@@ -532,6 +533,11 @@ static inline int of_alias_get_id(struct device_node *np, const char *stem)
 	return -ENOSYS;
 }
 
+static inline int of_alias_max_index(const char *stem)
+{
+	return -ENODEV;
+}
+
 static inline int of_machine_is_compatible(const char *compat)
 {
 	return 0;
-- 
2.0.0.rc0


  reply	other threads:[~2014-05-22 15:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 15:30 adding aliases to mmc ... again Sascha Hauer
2014-05-22 15:30 ` Sascha Hauer [this message]
2014-05-22 15:30 ` [PATCH 2/2] mmc: Allow setting slot index via devicetree alias Sascha Hauer
2014-05-22 16:16 ` adding aliases to mmc ... again Stephen Warren
2014-05-22 18:21   ` Sascha Hauer
2014-05-22 19:23     ` Stephen Warren
2014-05-23  8:29       ` Michael Olbrich
2014-05-23 16:02         ` Stephen Warren
2014-05-23  9:23       ` Sascha Hauer
2014-05-23 16:01         ` Stephen Warren
2014-05-24  5:10           ` 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=1400772623-8390-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=dirk.behme@de.bosch.com \
    --cc=festevam@gmail.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ptx@pengutronix.de \
    --cc=swarren@wwwdotorg.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).