]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/sh/kernel/early_printk.c
Merge git://git.infradead.org/mtd-2.6
[linux-2.6-omap-h63xx.git] / arch / sh / kernel / early_printk.c
index 560b91cdd15ced07aef986db027f9b3ad6daf1fa..6b7d166694e28fecc3f949b66cb94ae8c2e53950 100644 (file)
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 1999, 2000  Niibe Yutaka
  *  Copyright (C) 2002  M. R. Brown
- *  Copyright (C) 2004 - 2006  Paul Mundt
+ *  Copyright (C) 2004 - 2007  Paul Mundt
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
@@ -13,6 +13,7 @@
 #include <linux/tty.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_SH_STANDARD_BIOS
 #include <asm/sh_bios.h>
@@ -62,6 +63,17 @@ static struct console bios_console = {
 #include <linux/serial_core.h>
 #include "../../../drivers/serial/sh-sci.h"
 
+#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
+    defined(CONFIG_CPU_SUBTYPE_SH7721)
+#define EPK_SCSMR_VALUE 0x000
+#define EPK_SCBRR_VALUE 0x00C
+#define EPK_FIFO_SIZE 64
+#define EPK_FIFO_BITS (0x7f00 >> 8)
+#else
+#define EPK_FIFO_SIZE 16
+#define EPK_FIFO_BITS (0x1f00 >> 8)
+#endif
+
 static struct uart_port scif_port = {
        .mapbase        = CONFIG_EARLY_SCIF_CONSOLE_PORT,
        .membase        = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT,
@@ -69,14 +81,14 @@ static struct uart_port scif_port = {
 
 static void scif_sercon_putc(int c)
 {
-       while (((sci_in(&scif_port, SCFDR) & 0x1f00 >> 8) == 16))
+       while (((sci_in(&scif_port, SCFDR) & EPK_FIFO_BITS) >= EPK_FIFO_SIZE))
                ;
 
        sci_out(&scif_port, SCxTDR, c);
        sci_in(&scif_port, SCxSR);
        sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40));
 
-       while ((sci_in(&scif_port, SCxSR) & 0x40) == 0);
+       while ((sci_in(&scif_port, SCxSR) & 0x40) == 0)
                ;
 
        if (c == '\n')
@@ -105,28 +117,73 @@ static struct console scif_console = {
        .index          = -1,
 };
 
-#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_STANDARD_BIOS)
+#if !defined(CONFIG_SH_STANDARD_BIOS)
+#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
+    defined(CONFIG_CPU_SUBTYPE_SH7721)
+static void scif_sercon_init(char *s)
+{
+       sci_out(&scif_port, SCSCR, 0x0000);     /* clear TE and RE */
+       sci_out(&scif_port, SCFCR, 0x4006);     /* reset */
+       sci_out(&scif_port, SCSCR, 0x0000);     /* select internal clock */
+       sci_out(&scif_port, SCSMR, EPK_SCSMR_VALUE);
+       sci_out(&scif_port, SCBRR, EPK_SCBRR_VALUE);
+
+       mdelay(1);      /* wait 1-bit time */
+
+       sci_out(&scif_port, SCFCR, 0x0030);     /* TTRG=b'11 */
+       sci_out(&scif_port, SCSCR, 0x0030);     /* TE, RE */
+}
+#elif defined(CONFIG_CPU_SH4)
+#define DEFAULT_BAUD 115200
 /*
  * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
  * devices that aren't using sh-ipl+g.
  */
-static void scif_sercon_init(int baud)
+static void scif_sercon_init(char *s)
 {
-       ctrl_outw(0, scif_port.mapbase + 8);
-       ctrl_outw(0, scif_port.mapbase);
+       struct uart_port *port = &scif_port;
+       unsigned baud = DEFAULT_BAUD;
+       unsigned int status;
+       char *e;
+
+       if (*s == ',')
+               ++s;
+
+       if (*s) {
+               /* ignore ioport/device name */
+               s += strcspn(s, ",");
+               if (*s == ',')
+                       s++;
+       }
+
+       if (*s) {
+               baud = simple_strtoul(s, &e, 0);
+               if (baud == 0 || s == e)
+                       baud = DEFAULT_BAUD;
+       }
+
+       do {
+               status = sci_in(port, SCxSR);
+       } while (!(status & SCxSR_TEND(port)));
+
+       sci_out(port, SCSCR, 0);         /* TE=0, RE=0 */
+       sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
+       sci_out(port, SCSMR, 0);
 
        /* Set baud rate */
-       ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) /
-                 (32 * baud) - 1, scif_port.mapbase + 4);
-
-       ctrl_outw(12, scif_port.mapbase + 24);
-       ctrl_outw(8, scif_port.mapbase + 24);
-       ctrl_outw(0, scif_port.mapbase + 32);
-       ctrl_outw(0x60, scif_port.mapbase + 16);
-       ctrl_outw(0, scif_port.mapbase + 36);
-       ctrl_outw(0x30, scif_port.mapbase + 8);
+       sci_out(port, SCBRR, (CONFIG_SH_PCLK_FREQ + 16 * baud) /
+               (32 * baud) - 1);
+       udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
+
+       sci_out(port, SCSPTR, 0);
+       sci_out(port, SCxSR, 0x60);
+       sci_out(port, SCLSR, 0);
+
+       sci_out(port, SCFCR, 0);
+       sci_out(port, SCSCR, 0x30);      /* TE=1, RE=1 */
 }
-#endif /* CONFIG_CPU_SH4 && !CONFIG_SH_STANDARD_BIOS */
+#endif /* defined(CONFIG_CPU_SUBTYPE_SH7720) */
+#endif /* !defined(CONFIG_SH_STANDARD_BIOS) */
 #endif /* CONFIG_EARLY_SCIF_CONSOLE */
 
 /*
@@ -143,17 +200,12 @@ static struct console *early_console =
 #endif
        ;
 
-static int __initdata keep_early;
-static int early_console_initialized;
-
-int __init setup_early_printk(char *buf)
+static int __init setup_early_printk(char *buf)
 {
-       if (!buf)
-               return 0;
+       int keep_early = 0;
 
-       if (early_console_initialized)
+       if (!buf)
                return 0;
-       early_console_initialized = 1;
 
        if (strstr(buf, "keep"))
                keep_early = 1;
@@ -166,26 +218,23 @@ int __init setup_early_printk(char *buf)
        if (!strncmp(buf, "serial", 6)) {
                early_console = &scif_console;
 
-#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_STANDARD_BIOS)
-               scif_sercon_init(115200);
+#if !defined(CONFIG_SH_STANDARD_BIOS)
+#if defined(CONFIG_CPU_SH4) || defined(CONFIG_CPU_SUBTYPE_SH7720) || \
+    defined(CONFIG_CPU_SUBTYPE_SH7721)
+               scif_sercon_init(buf + 6);
+#endif
 #endif
        }
 #endif
 
-       if (likely(early_console))
+       if (likely(early_console)) {
+               if (keep_early)
+                       early_console->flags &= ~CON_BOOT;
+               else
+                       early_console->flags |= CON_BOOT;
                register_console(early_console);
+       }
 
        return 0;
 }
 early_param("earlyprintk", setup_early_printk);
-
-void __init disable_early_printk(void)
-{
-       if (!early_console_initialized || !early_console)
-               return;
-       if (!keep_early) {
-               printk("disabling early console\n");
-               unregister_console(early_console);
-       } else
-               printk("keeping early console\n");
-}