All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
To: grant.likely@secretlab.ca, simekm2@fel.cvut.cz,
	jwilliams@itee.uq.edu.au, linuxppc-dev@ozlabs.org
Subject: [PATCH 3/7] [POWERPC] Xilinx: Uartlite: Make console output actually work.
Date: Thu, 13 Dec 2007 15:43:29 -0800	[thread overview]
Message-ID: <20071213234338.D03BA105805B@mail74-blu.bigfish.com> (raw)
In-Reply-To: <1197589413-5965-2-git-send-email-stephen.neuendorffer@xilinx.com>

From: Grant Likely <grant.likely@secretlab.ca>

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

Fixed to apply against 2.6.24-rc5, and remove DEBUG information.

Signed-off-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
---
 drivers/serial/uartlite.c |  121 +++++++++++++++++++++++++++++----------------
 1 files changed, 79 insertions(+), 42 deletions(-)

diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index 3f59324..5ec42f3 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -9,6 +9,8 @@
  * kind, whether express or implied.
  */
 
+#undef DEBUG
+
 #include <linux/platform_device.h>
 #include <linux/module.h>
 #include <linux/console.h>
@@ -321,6 +323,49 @@ static struct uart_ops ulite_ops = {
 	.verify_port	= ulite_verify_port
 };
 
+/**
+ * ulite_get_port: Get the uart_port for a given port number and base addr
+ */
+static struct uart_port * ulite_get_port(int id)
+{
+	struct uart_port *port;
+
+	/* if id = -1; then scan for a free id and use that */
+	if (id < 0) {
+		for (id = 0; id < ULITE_NR_UARTS; id++)
+			if (ulite_ports[id].mapbase == 0)
+				break;
+	}
+
+	if ((id < 0) || (id >= ULITE_NR_UARTS)) {
+		printk(KERN_WARNING "uartlite: invalid id: %i\n", id);
+		return NULL;
+	}
+
+	/* The ID is valid, so get the address of the uart_port structure */
+	port = &ulite_ports[id];
+
+	/* Is the structure is already initialized? */
+	if (port->mapbase)
+		return port;
+
+	/* At this point, we've got an empty uart_port struct, initialize it */
+	spin_lock_init(&port->lock);
+	port->membase = NULL;
+	port->fifosize = 16;
+	port->regshift = 2;
+	port->iotype = UPIO_MEM;
+	port->iobase = 1; /* mark port in use */
+	port->ops = &ulite_ops;
+	port->irq = NO_IRQ;
+	port->flags = UPF_BOOT_AUTOCONF;
+	port->dev = NULL;
+	port->type = PORT_UNKNOWN;
+	port->line = id;
+
+	return port;
+}
+
 /* ---------------------------------------------------------------------
  * Console driver operations
  */
@@ -376,7 +421,7 @@ static void ulite_console_write(struct console *co, const char *s,
 }
 
 #if defined(CONFIG_OF)
-static inline void __init ulite_console_of_find_device(int id)
+static inline u32 __init ulite_console_of_find_device(int id)
 {
 	struct device_node *np;
 	struct resource res;
@@ -392,13 +437,14 @@ static inline void __init ulite_console_of_find_device(int id)
 		if (rc)
 			continue;
 
-		ulite_ports[id].mapbase = res.start;
 		of_node_put(np);
-		return;
+		return res.start+3;
 	}
+
+	return 0;
 }
 #else /* CONFIG_OF */
-static inline void __init ulite_console_of_find_device(int id) { /* do nothing */ }
+static inline u32 __init ulite_console_of_find_device(int id) { return 0; }
 #endif /* CONFIG_OF */
 
 static int __init ulite_console_setup(struct console *co, char *options)
@@ -408,25 +454,33 @@ static int __init ulite_console_setup(struct console *co, char *options)
 	int bits = 8;
 	int parity = 'n';
 	int flow = 'n';
+	u32 base;
 
-	if (co->index < 0 || co->index >= ULITE_NR_UARTS)
-		return -EINVAL;
+	/* Find a matching uart port in the device tree */
+	base = ulite_console_of_find_device(co->index);
 
-	port = &ulite_ports[co->index];
+	/* Get the port structure */
+	port = ulite_get_port(co->index);
+	if (!port)
+		return -ENODEV;
 
-	/* Check if it is an OF device */
-	if (!port->mapbase)
-		ulite_console_of_find_device(co->index);
+	/* was it initialized for this device? */
+	if (base) {
+		if ((port->mapbase) && (port->mapbase != base)) {
+			pr_debug(KERN_DEBUG "ulite: addr mismatch; %x != %x\n",
+				 port->mapbase, base);
+			return -ENODEV; /* port used by another device; bail */
+		}
+		port->mapbase = base;
+	}
 
-	/* Do we have a device now? */
-	if (!port->mapbase) {
-		pr_debug("console on ttyUL%i not present\n", co->index);
+	if (!port->mapbase)
 		return -ENODEV;
-	}
 
-	/* not initialized yet? */
+	/* registers mapped yet? */
 	if (!port->membase) {
-		if (ulite_request_port(port))
+		port->membase = ioremap(port->mapbase, ULITE_REGION);
+		if (!port->membase)
 			return -ENODEV;
 	}
 
@@ -488,39 +542,22 @@ static int __devinit ulite_assign(struct device *dev, int id, u32 base, int irq)
 	struct uart_port *port;
 	int rc;
 
-	/* if id = -1; then scan for a free id and use that */
-	if (id < 0) {
-		for (id = 0; id < ULITE_NR_UARTS; id++)
-			if (ulite_ports[id].mapbase == 0)
-				break;
-	}
-	if (id < 0 || id >= ULITE_NR_UARTS) {
-		dev_err(dev, "%s%i too large\n", ULITE_NAME, id);
-		return -EINVAL;
+	port = ulite_get_port(id);
+	if (!port) {
+		dev_err(dev, "Cannot get uart_port structure\n");
+		return -ENODEV;
 	}
 
-	if ((ulite_ports[id].mapbase) && (ulite_ports[id].mapbase != base)) {
-		dev_err(dev, "cannot assign to %s%i; it is already in use\n",
-			ULITE_NAME, id);
-		return -EBUSY;
+	/* was it initialized for this device? */
+	if ((port->mapbase) && (port->mapbase != base)) {
+		pr_debug(KERN_DEBUG "ulite: addr mismatch; %x != %x\n",
+			 port->mapbase, base);
+		return -ENODEV;
 	}
 
-	port = &ulite_ports[id];
-
-	spin_lock_init(&port->lock);
-	port->fifosize = 16;
-	port->regshift = 2;
-	port->iotype = UPIO_MEM;
-	port->iobase = 1; /* mark port in use */
 	port->mapbase = base;
-	port->membase = NULL;
-	port->ops = &ulite_ops;
 	port->irq = irq;
-	port->flags = UPF_BOOT_AUTOCONF;
 	port->dev = dev;
-	port->type = PORT_UNKNOWN;
-	port->line = id;
-
 	dev_set_drvdata(dev, port);
 
 	/* Register the port */
-- 
1.5.3.4

  parent reply	other threads:[~2007-12-13 23:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1197589413-5965-1-git-send-email-stephen.neuendorffer@xilinx.com>
2007-12-13 23:43 ` [PATCH 2/7] [POWERPC] Xilinx: clear data caches Stephen Neuendorffer
2007-12-14  0:07   ` Benjamin Herrenschmidt
2007-12-14  0:09     ` Benjamin Herrenschmidt
2007-12-14  0:36       ` Stephen Neuendorffer
2008-02-01 20:40         ` Grant Likely
     [not found] ` <1197589413-5965-2-git-send-email-stephen.neuendorffer@xilinx.com>
2007-12-13 23:43   ` Stephen Neuendorffer [this message]
     [not found]   ` <1197589413-5965-3-git-send-email-stephen.neuendorffer@xilinx.com>
2007-12-13 23:43     ` [PATCH 4/7] [POWERPC] Xilinx: update compatible list for interrupt controller Stephen Neuendorffer
     [not found]     ` <1197589413-5965-4-git-send-email-stephen.neuendorffer@xilinx.com>
2007-12-13 23:43       ` [PATCH 5/7] [POWERPC] Xilinx: Update compatible to use values generated by BSP generator Stephen Neuendorffer
     [not found]       ` <1197589413-5965-5-git-send-email-stephen.neuendorffer@xilinx.com>
2007-12-13 23:43         ` [PATCH 6/7] [POWERPC] Xilinx: Add correct compatible list for device tree bus bindings Stephen Neuendorffer
     [not found]         ` <1197589413-5965-6-git-send-email-stephen.neuendorffer@xilinx.com>
2007-12-13 23:43           ` [PATCH 7/7] [POWERPC] Xilinx: Update booting-without-of Stephen Neuendorffer
2007-12-17  4:14             ` David Gibson
2007-12-17  4:30               ` Grant Likely
2007-12-17  4:48                 ` Stephen Neuendorffer
2007-12-17 11:57                 ` Peter Korsgaard
2007-12-17 15:27                   ` Grant Likely
2007-12-17 15:19             ` Grant Likely
2007-12-17 18:24               ` Stephen Neuendorffer
2007-12-17 18:40                 ` Grant Likely
2007-12-18  0:22               ` Stephen Neuendorffer

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=20071213234338.D03BA105805B@mail74-blu.bigfish.com \
    --to=stephen.neuendorffer@xilinx.com \
    --cc=grant.likely@secretlab.ca \
    --cc=jwilliams@itee.uq.edu.au \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=simekm2@fel.cvut.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.