Message ID | 1353513428-25697-1-git-send-email-plagnioj@jcrosoft.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Nov 21, 2012 at 04:57:05PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote: > From: Sascha Hauer <s.hauer@pengutronix.de> > > 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@pengutronix.de> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> > Cc: linux-serial@vger.kernel.org > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Cc: kernel@pengutronix.de > Cc: Alan Cox <alan@linux.intel.com> > Cc: Grant Likely <grant.likely@secretlab.ca> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com> > --- > 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); tmp_option may be NULL. > + 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); dn_stdout may be NULL aswell. Sascha
On Wed, Nov 21, 2012 at 3:57 PM, Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> wrote: > From: Sascha Hauer <s.hauer@pengutronix.de> > > 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. NIce. Looks like the right behaviour, but is a little inefficient. Since the stdout property doesn't change this code could be called once right after the tree is unflattened and then cache the pointer to the node and arguments. Can you add the code to of_alias_scan()? g. > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> > Cc: linux-serial@vger.kernel.org > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Cc: kernel@pengutronix.de > Cc: Alan Cox <alan@linux.intel.com> > Cc: Grant Likely <grant.likely@secretlab.ca> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com> > --- > 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 > -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Hi, Sascha Hauer writes: > On Wed, Nov 21, 2012 at 04:57:05PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote: > > From: Sascha Hauer <s.hauer@pengutronix.de> > > > > 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. > > [...] > > + 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); > > dn_stdout may be NULL aswell. > which is handled gracefully by of_node_put()... Lothar Waßmann
On 18:03 Wed 21 Nov , Grant Likely wrote: > On Wed, Nov 21, 2012 at 3:57 PM, Jean-Christophe PLAGNIOL-VILLARD > <plagnioj@jcrosoft.com> wrote: > > From: Sascha Hauer <s.hauer@pengutronix.de> > > > > 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. > > NIce. Looks like the right behaviour, but is a little inefficient. > Since the stdout property doesn't change this code could be called > once right after the tree is unflattened and then cache the pointer to > the node anarguments. Can you add the code to of_alias_scan()? do we assume that we can have only one stdout-path? I think we could have more serial, framebuffer console Best Regards, J.
On Thu, 22 Nov 2012 06:41:38 +0100, Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> wrote: > On 18:03 Wed 21 Nov , Grant Likely wrote: > > On Wed, Nov 21, 2012 at 3:57 PM, Jean-Christophe PLAGNIOL-VILLARD > > <plagnioj@jcrosoft.com> wrote: > > > From: Sascha Hauer <s.hauer@pengutronix.de> > > > > > > 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. > > > > NIce. Looks like the right behaviour, but is a little inefficient. > > Since the stdout property doesn't change this code could be called > > once right after the tree is unflattened and then cache the pointer to > > the node anarguments. Can you add the code to of_alias_scan()? > do we assume that we can have only one stdout-path? > > I think we could have more serial, framebuffer console Nope. stdout-path as currently defined is only one device. Someone would need to propose an extension for multiple stdout's before I'd bother trying to support that. g.
On 15:31 Thu 22 Nov , Grant Likely wrote: > On Thu, 22 Nov 2012 06:41:38 +0100, Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> wrote: > > On 18:03 Wed 21 Nov , Grant Likely wrote: > > > On Wed, Nov 21, 2012 at 3:57 PM, Jean-Christophe PLAGNIOL-VILLARD > > > <plagnioj@jcrosoft.com> wrote: > > > > From: Sascha Hauer <s.hauer@pengutronix.de> > > > > > > > > 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. > > > > > > NIce. Looks like the right behaviour, but is a little inefficient. > > > Since the stdout property doesn't change this code could be called > > > once right after the tree is unflattened and then cache the pointer to > > > the node anarguments. Can you add the code to of_alias_scan()? > > do we assume that we can have only one stdout-path? > > > > I think we could have more serial, framebuffer console > > Nope. stdout-path as currently defined is only one device. Someone would > need to propose an extension for multiple stdout's before I'd bother > trying to support that. ok for this version I do not put it but I need it I want to have 2 console uart and framebuffer Personnaly I'd just allow multiple instance of stdout-path what do you prefer Best Regards, J.
On Thu, Nov 22, 2012 at 7:35 PM, Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> wrote: > On 15:31 Thu 22 Nov , Grant Likely wrote: >> On Thu, 22 Nov 2012 06:41:38 +0100, Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> wrote: >> > On 18:03 Wed 21 Nov , Grant Likely wrote: >> > > On Wed, Nov 21, 2012 at 3:57 PM, Jean-Christophe PLAGNIOL-VILLARD >> > > <plagnioj@jcrosoft.com> wrote: >> > > > From: Sascha Hauer <s.hauer@pengutronix.de> >> > > > >> > > > 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. >> > > >> > > NIce. Looks like the right behaviour, but is a little inefficient. >> > > Since the stdout property doesn't change this code could be called >> > > once right after the tree is unflattened and then cache the pointer to >> > > the node anarguments. Can you add the code to of_alias_scan()? >> > do we assume that we can have only one stdout-path? >> > >> > I think we could have more serial, framebuffer console >> >> Nope. stdout-path as currently defined is only one device. Someone would >> need to propose an extension for multiple stdout's before I'd bother >> trying to support that. > ok for this version I do not put it but I need it > > I want to have 2 console uart and framebuffer > > Personnaly I'd just allow multiple instance of stdout-path Propose a binding extension. g.
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) \