devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Frank Rowand
	<frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Grant Likely
	<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
Cc: paul.burton-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Jon Hunter <jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 1/3] serial: earlycon: Add device-tree support for other IO types
Date: Tue, 12 Jan 2016 10:33:27 +0000	[thread overview]
Message-ID: <1452594809-17972-2-git-send-email-jonathanh@nvidia.com> (raw)
In-Reply-To: <1452594809-17972-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

When early console are registered via device-tree, currently it is assumed
that the console iotype is UPIO_MEM and the regshift is 0. This is not the
case for all devices and so add support for reading the device-tree
properties "reg-io-width" and "reg-shift" so that the appropriate iotype
and regshift can be specified for a given device.

Signed-off-by: Jon Hunter <jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 drivers/of/fdt.c              | 26 +++++++++++++++++++++++++-
 drivers/tty/serial/earlycon.c |  6 ++++--
 include/linux/serial_core.h   |  3 ++-
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 655f79db7899..f69406e42631 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -827,7 +827,9 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		return -ENODEV;
 
 	while (match->compatible[0]) {
+		const __be32 *prop;
 		u64 addr;
+		u8 iotype, regshift;
 
 		if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
 			match++;
@@ -838,7 +840,29 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		if (addr == OF_BAD_ADDR)
 			return -ENXIO;
 
-		of_setup_earlycon(addr, match->data);
+		prop = fdt_getprop(fdt, offset, "reg-shift", NULL);
+		regshift = prop ? be32_to_cpup(prop) : 0;
+
+		prop = fdt_getprop(fdt, offset, "reg-io-width", NULL);
+		if (prop) {
+			switch (be32_to_cpup(prop)) {
+			case 1:
+				iotype = UPIO_MEM;
+				break;
+			case 2:
+				iotype = UPIO_MEM16;
+				break;
+			case 4:
+				iotype = UPIO_MEM32;
+				break;
+			default:
+				return -EINVAL;
+			}
+		} else {
+			iotype = UPIO_MEM;
+		}
+
+		of_setup_earlycon(addr, iotype, regshift, match->data);
 		return 0;
 	}
 	return -ENODEV;
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 3f2423690d01..2fd2f19d7091 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -204,17 +204,19 @@ static int __init param_setup_earlycon(char *buf)
 }
 early_param("earlycon", param_setup_earlycon);
 
-int __init of_setup_earlycon(unsigned long addr,
+int __init of_setup_earlycon(unsigned long addr, unsigned char iotype,
+			     unsigned char regshift,
 			     int (*setup)(struct earlycon_device *, const char *))
 {
 	int err;
 	struct uart_port *port = &early_console_dev.port;
 
 	spin_lock_init(&port->lock);
-	port->iotype = UPIO_MEM;
+	port->iotype = iotype;
 	port->mapbase = addr;
 	port->uartclk = BASE_BAUD * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
+	port->regshift = regshift;
 
 	early_console_dev.con->data = &early_console_dev;
 	err = setup(&early_console_dev, NULL);
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index e03d6ba5e5b4..e0e1c7ef2856 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -346,7 +346,8 @@ struct earlycon_id {
 } __aligned(32);
 
 extern int setup_earlycon(char *buf);
-extern int of_setup_earlycon(unsigned long addr,
+extern int of_setup_earlycon(unsigned long addr, unsigned char iotype,
+			     unsigned char regshift,
 			     int (*setup)(struct earlycon_device *, const char *));
 
 #define EARLYCON_DECLARE(_name, func)					\
-- 
2.1.4

  parent reply	other threads:[~2016-01-12 10:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 10:33 [PATCH 0/3] serial: earlycon: Add device-tree support for earlycon on Tegra Jon Hunter
     [not found] ` <1452594809-17972-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-01-12 10:33   ` Jon Hunter [this message]
2016-01-12 10:33   ` [PATCH 2/3] serial: 8250_early: Add support for regshift Jon Hunter
     [not found]     ` <1452594809-17972-3-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-01-12 16:15       ` Peter Hurley
     [not found]         ` <569526B1.3030000-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2016-01-12 18:28           ` Jon Hunter
     [not found]             ` <569545B8.5000200-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-01-12 18:43               ` Peter Hurley
2016-01-12 10:33   ` [PATCH 3/3] serial: 8250_early: Add earlycon support for Tegra Jon Hunter
2016-01-12 10:56   ` [PATCH 0/3] serial: earlycon: Add device-tree support for earlycon on Tegra Arnd Bergmann
2016-01-13 16:03   ` Thierry Reding
2016-01-13 17:21     ` Jon Hunter
     [not found]       ` <569687B2.9090609-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-01-13 17:32         ` Thierry Reding

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=1452594809-17972-2-git-send-email-jonathanh@nvidia.com \
    --to=jonathanh-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=paul.burton-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@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).