devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
	Alan Cox <alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Subject: [PATCH 1/4] OF: Add helper for matching against linux,stdout-path
Date: Wed, 21 Nov 2012 16:57:05 +0100	[thread overview]
Message-ID: <1353513428-25697-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20121121155312.GX4398-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>

From: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

devicetrees may have a linux,stdout-path or stdout-path property
in the chosen node describing the console device. This adds a helper
function to match a device against this property and retrieve the options
so a driver can call add_preferred_console for a matching device.

Signed-off-by: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org
Cc: Alan Cox <alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
---
 drivers/of/base.c  |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h |    7 +++++++
 2 files changed, 53 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index f2f63c8..72c49ce 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1470,3 +1470,49 @@ const char *of_prop_next_string(struct property *prop, const char *cur)
 	return curv;
 }
 EXPORT_SYMBOL_GPL(of_prop_next_string);
+
+/**
+ * of_device_is_stdout_path - check if a device node matches the
+ *			      linux,stdout-path property
+ * @np:		Pointer to the given device_node
+ * @option:	parsed option
+ *
+ * Check if this device node matches the linux,stdout-path property
+ * in the chosen node. return true if yes, false otherwise.
+ */
+int of_device_is_stdout_path(struct device_node *dn, char **option)
+{
+	const char *name;
+	struct device_node *dn_stdout;
+	bool is_stdout = 0;
+	const char *tmp;
+	const char *tmp_option;
+
+	name = of_get_property(of_chosen, "linux,stdout-path", NULL);
+	if (name == NULL)
+		name = of_get_property(of_chosen, "stdout-path", NULL);
+
+	if (name == NULL)
+		return 0;
+
+	tmp_option = strchr(name, ':');
+
+	tmp = kstrndup(name, strlen(name) - strlen(tmp_option), GFP_KERNEL);
+	if (!tmp)
+		return 0;
+
+	dn_stdout = of_find_node_by_path(tmp);
+
+	if (dn_stdout && dn_stdout == dn) {
+		is_stdout = 1;
+		tmp_option++;
+		*option = kstrdup(tmp_option, GFP_KERNEL);
+	}
+
+	of_node_put(dn_stdout);
+
+	kfree(tmp);
+
+	return is_stdout;
+}
+EXPORT_SYMBOL_GPL(of_device_is_stdout_path);
diff --git a/include/linux/of.h b/include/linux/of.h
index 681a6c8..6a82e3f 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -323,6 +323,8 @@ const char *of_prop_next_string(struct property *prop, const char *cur);
 		s;						\
 		s = of_prop_next_string(prop, s))
 
+int of_device_is_stdout_path(struct device_node *dn, char **option);
+
 #else /* CONFIG_OF */
 
 static inline const char* of_node_full_name(struct device_node *np)
@@ -450,6 +452,11 @@ static inline int of_machine_is_compatible(const char *compat)
 	return 0;
 }
 
+static inline int of_device_is_stdout_path(struct device_node *dn, char **option)
+{
+	return 0;
+}
+
 #define of_match_ptr(_ptr)	NULL
 #define of_match_node(_matches, _node)	NULL
 #define of_property_for_each_u32(np, propname, prop, p, u) \
-- 
1.7.10.4

  parent reply	other threads:[~2012-11-21 15:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21 15:53 [PATCH v5] linux,stdout-path helper Jean-Christophe PLAGNIOL-VILLARD
     [not found] ` <20121121155312.GX4398-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-11-21 15:57   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-11-21 15:57     ` [PATCH 2/4] serial: i.MX: Make console support non optional Jean-Christophe PLAGNIOL-VILLARD
     [not found]     ` <1353513428-25697-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-11-21 15:57       ` [PATCH 3/4] serial: i.MX: evaluate linux,stdout-path property Jean-Christophe PLAGNIOL-VILLARD
2012-11-21 15:57     ` [PATCH 4/4] tty: Atmel serial: add linux,stdout-path support Jean-Christophe PLAGNIOL-VILLARD
2012-11-21 17:26     ` [PATCH 1/4] OF: Add helper for matching against linux,stdout-path Sascha Hauer
2012-11-22  5:33       ` [PATCH 1/4] OF: Add helper for matching against linux, stdout-path Lothar Waßmann
2012-11-21 18:03     ` [PATCH 1/4] OF: Add helper for matching against linux,stdout-path Grant Likely
2012-11-22  5:41       ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]         ` <20121122054138.GY4398-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-11-22 15:31           ` [PATCH 1/4] OF: Add helper for matching against linux, stdout-path Grant Likely
2012-11-22 19:35             ` [PATCH 1/4] OF: Add helper for matching against linux,stdout-path Jean-Christophe PLAGNIOL-VILLARD
2012-11-22 21:21               ` Grant Likely
2013-07-23 14:17 ` [PATCH v5] linux,stdout-path helper 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=1353513428-25697-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj-sclmfoaustbwk0htik3j/w@public.gmane.org \
    --cc=alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@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).