Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1307783

[PATCH v4 02/11] serial: earlycon: Fixup earlycon console name and index

From Peter Hurley <peter@hurleysoftware.com>
Newsgroups linux.kernel
Subject [PATCH v4 02/11] serial: earlycon: Fixup earlycon console name and index
Date 2016-01-12 20:50 +0100
Message-ID <qQd75-5xe-29@gated-at.bofh.it> (permalink)
References <pd2gV-7Bs-3@gated-at.bofh.it> <qQd74-5xe-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Properly initialize the struct console 'name' and 'index' fields for
the registering earlycon. For earlycons w/o trailing numerals, the
index is set to 0; otherwise, the index is set to the value of the
trailing numeral. For example, the 'exynos4210' earlycon name == "exynos"
and index == 4210. Earlycons with embedded numerals will have all
non-trailing numerals as part of the name; for example, the 's3c2412'
earlycon name == "s3c" and index == 2412.

This ackward scheme was initially added for the uart8250 earlycon;
adopt this scheme for the other earlycon "drivers".

Introduce earlycon_init() which performs the string scanning and
initializes the name and index fields; encapsulate the other console
field initializations within.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
 drivers/tty/serial/earlycon.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index d50b700..90b064f 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -27,9 +27,9 @@
 #include <asm/serial.h>
 
 static struct console early_con = {
-	.name =		"uart", /* 8250 console switch requires this name */
+	.name =		"uart",		/* fixed up at earlycon registration */
 	.flags =	CON_PRINTBUFFER | CON_BOOT,
-	.index =	-1,
+	.index =	0,
 };
 
 static struct earlycon_device early_console_dev = {
@@ -53,6 +53,25 @@ static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
 	return base;
 }
 
+static void __init earlycon_init(struct earlycon_device *device,
+				 const char *name)
+{
+	struct console *earlycon = device->con;
+	const char *s;
+	size_t len;
+
+	/* scan backwards from end of string for first non-numeral */
+	for (s = name + strlen(name);
+	     s > name && s[-1] >= '0' && s[-1] <= '9';
+	     s--)
+		;
+	if (*s)
+		earlycon->index = simple_strtoul(s, NULL, 10);
+	len = s - name;
+	strlcpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
+	earlycon->data = &early_console_dev;
+}
+
 static int __init parse_options(struct earlycon_device *device, char *options)
 {
 	struct uart_port *port = &device->port;
@@ -119,7 +138,7 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match)
 	if (port->mapbase)
 		port->membase = earlycon_map(port->mapbase, 64);
 
-	early_console_dev.con->data = &early_console_dev;
+	earlycon_init(&early_console_dev, match->name);
 	err = match->setup(&early_console_dev, buf);
 	if (err < 0)
 		return err;
-- 
2.7.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/11] Earlycon cleanup Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
  [PATCH v4 08/11] serial: earlycon: Show the earlycon "driver" in banner Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
  [PATCH v4 11/11] serial: 8250_omap: Add omap8250 earlycon Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
    Re: [PATCH v4 11/11] serial: 8250_omap: Add omap8250 earlycon Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 21:00 +0100
      Re: [PATCH v4 11/11] serial: 8250_omap: Add omap8250 earlycon Jon Hunter <jonathanh@nvidia.com> - 2016-01-13 10:30 +0100
        Re: [PATCH v4 11/11] serial: 8250_omap: Add omap8250 earlycon Jon Hunter <jonathanh@nvidia.com> - 2016-01-13 11:00 +0100
        Re: [PATCH v4 11/11] serial: 8250_omap: Add omap8250 earlycon Jon Hunter <jonathanh@nvidia.com> - 2016-01-13 11:20 +0100
          Re: [PATCH v4 11/11] serial: 8250_omap: Add omap8250 earlycon Peter Hurley <peter@hurleysoftware.com> - 2016-01-13 18:10 +0100
            Re: [PATCH v4 11/11] serial: 8250_omap: Add omap8250 earlycon Jon Hunter <jonathanh@nvidia.com> - 2016-01-13 18:20 +0100
  [PATCH v4 10/11] of: earlycon: Log more helpful message if stdout-path node not found Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
    Re: [PATCH v4 10/11] of: earlycon: Log more helpful message if  stdout-path node not found Rob Herring <robh+dt@kernel.org> - 2016-01-13 00:40 +0100
  [PATCH v4 02/11] serial: earlycon: Fixup earlycon console name and index Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
  [PATCH v4 05/11] of: earlycon: Initialize port fields from DT properties Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
    Re: [PATCH v4 05/11] of: earlycon: Initialize port fields from DT properties Rob Herring <robh+dt@kernel.org> - 2016-01-13 01:00 +0100
      Re: [PATCH v4 05/11] of: earlycon: Initialize port fields from DT  properties Peter Hurley <peter@hurleysoftware.com> - 2016-01-13 17:40 +0100
  [PATCH v4 06/11] of: earlycon: Move address translation to of_setup_earlycon() Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
  [PATCH v4 07/11] serial: earlycon: Common log banner for command line and DT Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
  [PATCH v4 09/11] serial: 8250_early: Use port->regshift Peter Hurley <peter@hurleysoftware.com> - 2016-01-12 20:50 +0100
  Re: [PATCH v4 00/11] Earlycon cleanup Rob Herring <robh+dt@kernel.org> - 2016-01-13 01:00 +0100

csiph-web