LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Peter Hurley <peter@hurleysoftware.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Grant Likely <grant.likely@linaro.org>,
	Rob Herring <robh+dt@kernel.org>
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Hurley <peter@hurleysoftware.com>
Subject: [PATCH -next 05/12] of: earlycon: Initialize port fields from DT properties
Date: Wed,  4 Mar 2015 12:24:24 -0500	[thread overview]
Message-ID: <1425489871-22415-6-git-send-email-peter@hurleysoftware.com> (raw)
In-Reply-To: <1425489871-22415-1-git-send-email-peter@hurleysoftware.com>

Read the optional "reg-offset", "reg-shift" and "reg-io-width" properties
and initialize the respective struct uart_port field if found.

NB: These bindings are common to several drivers and the values merely
indicate the default value; the registering earlycon setup() method can
simply override the values if required.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
 drivers/of/fdt.c              |  2 +-
 drivers/tty/serial/earlycon.c | 27 +++++++++++++++++++++++++++
 include/linux/serial_core.h   |  1 +
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index bdb74a8..a732890 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -802,7 +802,7 @@ int __init early_init_dt_scan_chosen_serial(void)
 		if (!addr)
 			return -ENXIO;
 
-		of_setup_earlycon(addr, match, options);
+		of_setup_earlycon(addr, match, offset, options);
 		return 0;
 	}
 	return -ENODEV;
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 436ac88..019010f 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -21,6 +21,10 @@
 #include <linux/sizes.h>
 #include <linux/mod_devicetable.h>
 
+#ifdef CONFIG_OF_EARLY_FLATTREE
+#include <linux/of_fdt.h>
+#endif
+
 #ifdef CONFIG_FIX_EARLYCON_MEM
 #include <asm/fixmap.h>
 #endif
@@ -219,17 +223,40 @@ early_param("earlycon", param_setup_earlycon);
 
 int __init of_setup_earlycon(unsigned long addr,
 			     const struct of_device_id *match,
+			     unsigned long node,
 			     const char *options)
 {
 	int err;
 	struct uart_port *port = &early_console_dev.port;
 	int (*setup)(struct earlycon_device *, const char *) = match->data;
+	const __be32 *val;
 
 	port->iotype = UPIO_MEM;
 	port->mapbase = addr;
 	port->uartclk = BASE_BAUD * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
+	val = of_get_flat_dt_prop(node, "reg-offset", NULL);
+	if (val)
+		port->mapbase += be32_to_cpu(*val);
+	val = of_get_flat_dt_prop(node, "reg-shift", NULL);
+	if (val)
+		port->regshift = be32_to_cpu(*val);
+	val = of_get_flat_dt_prop(node, "reg-io-width", NULL);
+	if (val) {
+		switch (be32_to_cpu(*val)) {
+		case 1:
+			port->iotype = UPIO_MEM;
+			break;
+		case 4:
+			port->iotype = UPIO_MEM32;
+			break;
+		default:
+			pr_warn("[%s] unsupported reg-io-width\n", match->name);
+			return -EINVAL;
+		}
+	}
+
 	if (options) {
 		strlcpy(early_console_dev.options, options,
 			sizeof(early_console_dev.options));
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index ebbcd43..c8e4e8f 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -347,6 +347,7 @@ struct earlycon_id {
 extern int setup_earlycon(char *buf);
 extern int of_setup_earlycon(unsigned long addr,
 			     const struct of_device_id *match,
+			     unsigned long node,
 			     const char *options);
 
 #define EARLYCON_DECLARE(_name, func)					\
-- 
2.3.1


  parent reply	other threads:[~2015-03-04 17:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-04 17:24 [PATCH -next 00/12] OF earlycon cleanup Peter Hurley
2015-03-04 17:24 ` [PATCH -next 01/12] serial: earlycon: Fixup earlycon console name and index Peter Hurley
2015-03-04 17:24 ` [PATCH -next 02/12] serial: earlycon: Emit earlycon name in the OF table Peter Hurley
2015-03-05 15:13   ` Rob Herring
2015-03-06 16:05     ` Peter Hurley
2015-03-04 17:24 ` [PATCH -next 03/12] of: earlycon: Fixup earlycon console name and index Peter Hurley
2015-03-04 17:24 ` [PATCH -next 04/12] of: earlycon: Add options string handling Peter Hurley
2015-03-05 16:28   ` Rob Herring
2015-03-04 17:24 ` Peter Hurley [this message]
2015-03-05 16:16   ` [PATCH -next 05/12] of: earlycon: Initialize port fields from DT properties Rob Herring
2015-03-04 17:24 ` [PATCH -next 06/12] of: earlycon: Move address translation to of_setup_earlycon() Peter Hurley
2015-03-05 16:25   ` Rob Herring
2015-03-04 17:24 ` [PATCH -next 07/12] serial: earlycon: Common log banner for command line and DT Peter Hurley
2015-03-05 12:02   ` Geert Uytterhoeven
2015-03-05 12:24     ` Peter Hurley
2015-03-04 17:24 ` [PATCH -next 08/12] serial: earlycon: Id the earlycon "driver" in banner Peter Hurley
2015-03-04 17:24 ` [PATCH -next 09/12] of: earlycon: Allow multiple OF_EARLYCON_DECLARE() with same name Peter Hurley
2015-03-04 17:24 ` [PATCH -next 10/12] of: earlycon: Log more helpful message if earlycon not found Peter Hurley
2015-03-04 17:24 ` [PATCH -next 11/12] serial: 8250_early: Use port->regshift Peter Hurley
2015-03-04 17:24 ` [PATCH -next 12/12] serial: 8250_omap: Add omap8250 earlycon Peter Hurley
2015-03-04 17:33 ` [PATCH -next 00/12] OF earlycon cleanup Peter Hurley

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=1425489871-22415-6-git-send-email-peter@hurleysoftware.com \
    --to=peter@hurleysoftware.com \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --subject='Re: [PATCH -next 05/12] of: earlycon: Initialize port fields from DT properties' \
    /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

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).