Skip to contentSkip to conversation

linux,stdout-path helper

PATCH In review Jean-Christophe PLAGNIOL-VILLARD 4 participants 13 messages Nov 21, 2012 – Jul 23, 2013

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 linux,stdout-path helper

The following adds a helper for matching the linux,stdout-path property in the chosen node and makes use of it in the i.MX serial and Atmel serial driver.

changes since v4:

- add option support and check stdout-path too

changes since v3:

- move code from separate files to drivers/of/base.c and include/linux/of.h

changes since v2:

- move helper to OF core and make it independent of serial devices

changes since v1:

- move it out of the i.MX serial driver and make it generic for serial devices.

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

#1 lore raw

PATCH 1/4 OF: Add helper for matching against linux,stdout-path

From: Sascha Hauer <[email protected]>

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.

Cc linux-serial at vger.kernel.org
Cc Greg Kroah-Hartman <[email protected]>
Cc kernel at pengutronix.de
Cc Alan Cox <[email protected]>
Cc Grant Likely <[email protected]>
Cc Nicolas Ferre <[email protected]>
---
 drivers/of/base.c  |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h |    7 +++++++
 2 files changed, 53 insertions(+)
drivers/of/base.c +46 -0
index f2f63c8..72c49ce 100644
@@ -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);
include/linux/of.h +7 -0
index 681a6c8..6a82e3f 100644
@@ -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) \
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/4 serial: i.MX: Make console support non optional

From: Sascha Hauer <[email protected]>

Traditionally console support is optional for serial drivers. This makes it non optional for the i.MX driver since it's not worth asking questions for a feature virtually every user of this driver wants to have.

Cc linux-serial at vger.kernel.org
Cc Greg Kroah-Hartman <[email protected]>
Cc kernel at pengutronix.de
Cc Alan Cox <[email protected]>
Cc Grant Likely <[email protected]>
Cc Nicolas Ferre <[email protected]>
---
 drivers/tty/serial/Kconfig |   16 +---------------
 drivers/tty/serial/imx.c   |    8 +-------
 2 files changed, 2 insertions(+), 22 deletions(-)
drivers/tty/serial/Kconfig +1 -15
index b176801..10e5eec 100644
@@ -541,26 +541,12 @@ config SERIAL_IMX
 	bool "IMX serial port support"
 	depends on ARCH_MXC
 	select SERIAL_CORE
+	select SERIAL_CORE_CONSOLE
 	select RATIONAL
 	help
 	  If you have a machine based on a Motorola IMX CPU you
 	  can enable its onboard serial port by enabling this option.
 
-config SERIAL_IMX_CONSOLE
-	bool "Console on IMX serial port"
-	depends on SERIAL_IMX
-	select SERIAL_CORE_CONSOLE
-	help
-	  If you have enabled the serial port on the Motorola IMX
-	  CPU you can make it the console by answering Y to this option.
-
-	  Even if you say Y here, the currently visible virtual console
-	  (/dev/tty0) will still be used as the system console by default, but
-	  you can alter that using a kernel command line option such as
-	  "console=ttySA0". (Try "man bootparam" or see the documentation of
-	  your boot loader (lilo or loadlin) about how to pass options to the
-	  kernel at boot time.)
-
 config SERIAL_UARTLITE
 	tristate "Xilinx uartlite serial port support"
 	depends on PPC32 || MICROBLAZE || MFD_TIMBERDALE
drivers/tty/serial/imx.c +1 -7
index 5981912..07a8ca1 100644
@@ -1192,7 +1192,6 @@ static struct uart_ops imx_pops = {
 
 static struct imx_port *imx_ports[UART_NR];
 
-#ifdef CONFIG_SERIAL_IMX_CONSOLE
 static void imx_console_putchar(struct uart_port *port, int ch)
 {
 	struct imx_port *sport = (struct imx_port *)port;
@@ -1348,11 +1347,6 @@ static struct console imx_console = {
 	.data		= &imx_reg,
 };
 
-#define IMX_CONSOLE	&imx_console
-#else
-#define IMX_CONSOLE	NULL
-#endif
-
 static struct uart_driver imx_reg = {
 	.owner          = THIS_MODULE,
 	.driver_name    = DRIVER_NAME,
@@ -1360,7 +1354,7 @@ static struct uart_driver imx_reg = {
 	.major          = SERIAL_IMX_MAJOR,
 	.minor          = MINOR_START,
 	.nr             = ARRAY_SIZE(imx_ports),
-	.cons           = IMX_CONSOLE,
+	.cons           = &imx_console,
 };
 
 static int serial_imx_suspend(struct platform_device *dev, pm_message_t state)
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/4 serial: i.MX: evaluate linux,stdout-path property

In reply to Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

devicetrees may have the linux,stdout-path property to specify the console. This patch adds support to the i.MX serial driver for this.

Cc linux-serial at vger.kernel.org
Cc Greg Kroah-Hartman <[email protected]>
Cc kernel at pengutronix.de
Cc Alan Cox <[email protected]>
Cc Grant Likely <[email protected]>
Cc Nicolas Ferre <[email protected]>
---
 drivers/tty/serial/imx.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/imx.c +4 -0
index 07a8ca1..28a3193 100644
@@ -1398,6 +1398,7 @@ static int serial_imx_probe_dt(struct imx_port *sport,
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *of_id =
 			of_match_device(imx_uart_dt_ids, &pdev->dev);
+	char *option = NULL;
 	int ret;
 
 	if (!np)
@@ -1419,6 +1420,9 @@ static int serial_imx_probe_dt(struct imx_port *sport,
 
 	sport->devdata = of_id->data;
 
+	if (of_device_is_stdout_path(np, &option))
+		add_preferred_console(imx_reg.cons->name, sport->port.line, option);
+
 	return 0;
 }
 #else
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/4 tty: Atmel serial: add linux,stdout-path support

In reply to Jean-Christophe PLAGNIOL-VILLARD
Cc linux-serial at vger.kernel.org
Cc Greg Kroah-Hartman <[email protected]>
Cc kernel at pengutronix.de
Cc Alan Cox <[email protected]>
Cc Grant Likely <[email protected]>
Cc Nicolas Ferre <[email protected]>
---
 drivers/tty/serial/atmel_serial.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/tty/serial/atmel_serial.c +5 -0
index 5608b6b..f62a3c3 100644
@@ -1427,6 +1427,7 @@ static struct uart_ops atmel_pops = {
 static void __devinit atmel_of_init_port(struct atmel_uart_port *atmel_port,
 					 struct device_node *np)
 {
+	char *option = NULL;
 	u32 rs485_delay[2];
 
 	/* DMA/PDC usage specification */
@@ -1453,6 +1454,10 @@ static void __devinit atmel_of_init_port(struct atmel_uart_port *atmel_port,
 
 		if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
 			rs485conf->flags |= SER_RS485_ENABLED;
+	} else if (of_device_is_stdout_path(np, &option)) {
+		pr_info("add preferred console %s%d option=%s\n",
+			ATMEL_DEVICENAME, atmel_port->uart.line, option);
+		add_preferred_console(ATMEL_DEVICENAME, atmel_port->uart.line, option);
 	}
 }
 
Signature · 1 line
1.7.10.4
maintainer
#5 lore raw

PATCH 1/4 OF: Add helper for matching against linux, stdout-path

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 46 lines · Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

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.

Cc linux-serial at vger.kernel.org
Cc Greg Kroah-Hartman <[email protected]>
Cc kernel at pengutronix.de
Cc Alan Cox <[email protected]>
Cc Grant Likely <[email protected]>
Cc Nicolas Ferre <[email protected]>
---
 drivers/of/base.c  |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h |    7 +++++++
 2 files changed, 53 insertions(+)
drivers/of/base.c +18 -0
index f2f63c8..72c49ce 100644
@@ -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;
+

drivers/of/base.c const char *of_prop_next_string(struct property *prop, const char *cur) · line 1500

Quoted 10 lines
drivers/of/base.c +10 -0
+	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.

drivers/of/base.c const char *of_prop_next_string(struct property *prop, const char *cur) · line 1512

Quoted 12 lines
drivers/of/base.c +12 -0
+	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

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#6 lore raw

PATCH 1/4 OF: Add helper for matching against linux, stdout-path

Hi,

Quoted 8 lines · Sascha Hauer
Quoted 7 lines · Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

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.

[...]

Quoted 6 lines
Quoted 6 lines
drivers/of/base.c +6 -0
+	if (!tmp)
+		return 0;
+
+	dn_stdout = of_find_node_by_path(tmp);
+
+	if (dn_stdout && dn_stdout == dn) {
Quoted 9 lines

drivers/of/base.c const char *of_prop_next_string(struct property *prop, const char *cur) · line 1512

Quoted 6 lines
drivers/of/base.c +6 -0
+		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

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#7 lore raw

PATCH 1/4 OF: Add helper for matching against linux, stdout-path

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

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.

Quoted 94 lines
Cc linux-serial at vger.kernel.org
Cc Greg Kroah-Hartman <[email protected]>
Cc kernel at pengutronix.de
Cc Alan Cox <[email protected]>
Cc Grant Likely <[email protected]>
Cc Nicolas Ferre <[email protected]>
---
 drivers/of/base.c  |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h |    7 +++++++
 2 files changed, 53 insertions(+)
drivers/of/base.c +46 -0
index f2f63c8..72c49ce 100644
@@ -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);
include/linux/of.h +7 -1
index 681a6c8..6a82e3f 100644
@@ -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) \
--
Quoted 2 lines

1.7.10.4

--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#8 lore raw

PATCH 1/4 OF: Add helper for matching against linux,stdout-path

Quoted 9 lines · Grant Likely
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

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.

Quoted 4 lines

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.

#9 lore raw

PATCH 1/4 OF: Add helper for matching against linux, stdout-path

Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · Grant Likely
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

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.

Quoted 7 lines
Quoted 4 lines

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.

#10 lore raw

PATCH 1/4 OF: Add helper for matching against linux,stdout-path

Quoted 15 lines · Grant Likely
Quoted 14 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 13 lines · Grant Likely
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

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()?

Quoted 7 lines
Quoted 3 lines

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.

#11 lore raw

PATCH 1/4 OF: Add helper for matching against linux, stdout-path

Quoted 20 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 19 lines · Grant Likely
Quoted 17 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · Grant Likely
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

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.

Quoted 4 lines

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

Quoted 8 lines
Quoted 3 lines

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.

maintainer
#12 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines · Jean-Christophe PLAGNIOL-VILLARD

The following adds a helper for matching the linux,stdout-path property in the chosen node and makes use of it in the i.MX serial and Atmel serial driver.

Seems this got stuck. Jean-Christophe, will you update this series? I could really make use of this.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |