MIPS: Loongson: Cleanup the serial port support
authorWu Zhangjin <wuzhangjin@gmail.com>
Fri, 6 Nov 2009 10:35:34 +0000 (18:35 +0800)
committerRalf Baechle <ralf@linux-mips.org>
Thu, 17 Dec 2009 01:57:09 +0000 (01:57 +0000)
To share the same kernel image amon different machines we have added the
machtype command line support.

In the old serial port implementation the UART base address is hardcoded as
a macro in machine.h which breaks with machtype, so change that to discover
the address dynamically.  Also move the initialization of the UART base
address to uart_base.c to avoid remapping twice for early_printk.c and
serial.c.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
Cc: linux-mips@linux-mips.org
Patchwork: http://patchwork.linux-mips.org/patch/581/
Patchwork: http://patchwork.linux-mips.org/patch/682/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/include/asm/mach-loongson/loongson.h
arch/mips/include/asm/mach-loongson/machine.h
arch/mips/loongson/common/Makefile
arch/mips/loongson/common/early_printk.c
arch/mips/loongson/common/init.c
arch/mips/loongson/common/serial.c
arch/mips/loongson/common/uart_base.c [new file with mode: 0644]

index efb234437791bbf8fef4623671d3ab6e34766a95..722db9e811e5b568c4a9fc5008908732f7bb5462 100644 (file)
@@ -31,6 +31,9 @@ extern void __init prom_init_memory(void);
 extern void __init prom_init_cmdline(void);
 extern void __init prom_init_machtype(void);
 extern void __init prom_init_env(void);
+extern unsigned long _loongson_uart_base;
+extern unsigned long uart8250_base[];
+extern void prom_init_uart_base(void);
 
 /* irq operation functions */
 extern void bonito_irqdispatch(void);
index ea5954c4b221f2befbf9026168646e17579a8e14..d2f586157630ec414411568c9f7d8ad9709ded5e 100644 (file)
@@ -13,8 +13,6 @@
 
 #ifdef CONFIG_LEMOTE_FULOONG2E
 
-#define LOONGSON_UART_BASE (LOONGSON_PCIIO_BASE + 0x3f8)
-
 #define LOONGSON_MACHTYPE MACH_LEMOTE_FL2E
 
 #endif
index d21d1163fad02812867983cdcc8cee85c0de4de7..be6adf7eb82502a5f871fc3ebabdb72f94b8440d 100644 (file)
@@ -3,7 +3,7 @@
 #
 
 obj-y += setup.o init.o cmdline.o env.o time.o reset.o irq.o \
-    pci.o bonito-irq.o mem.o machtype.o
+    pci.o bonito-irq.o mem.o machtype.o uart_base.o
 
 #
 # Early printk support
index 8ec4fb2066ae48aeda90c33797cfc6dd32a3c9ae..23e7a8f8897f6626b77d1511df9fcf6176b8e5e0 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/serial_reg.h>
 
 #include <loongson.h>
-#include <machine.h>
 
 #define PORT(base, offset) (u8 *)(base + offset)
 
@@ -28,10 +27,14 @@ static inline void serial_out(unsigned char *base, int offset, int value)
 
 void prom_putchar(char c)
 {
-       unsigned char *uart_base =
-               (unsigned char *) ioremap_nocache(LOONGSON_UART_BASE, 8);
+       int timeout;
+       unsigned char *uart_base;
 
-       while ((serial_in(uart_base, UART_LSR) & UART_LSR_THRE) == 0)
+       uart_base = (unsigned char *)_loongson_uart_base;
+       timeout = 1024;
+
+       while (((serial_in(uart_base, UART_LSR) & UART_LSR_THRE) == 0) &&
+                       (timeout-- > 0))
                ;
 
        serial_out(uart_base, UART_TX, c);
index b7e4913627abf60d1e70e421884dea4f47eaf9f8..3b1dbc1ca242e8004924c8a2c3c3cfb7e0de7b5a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
+ * Copyright (C) 2009 Lemote Inc.
  * Author: Wu Zhangjin, wuzj@lemote.com
  *
  * This program is free software; you can redistribute  it and/or modify it
 
 #include <linux/bootmem.h>
 
-#include <asm/bootinfo.h>
-
 #include <loongson.h>
 
 void __init prom_init(void)
 {
-    /* init base address of io space */
+       /* init base address of io space */
        set_io_port_base((unsigned long)
                ioremap(LOONGSON_PCIIO_BASE, LOONGSON_PCIIO_SIZE));
 
        prom_init_cmdline();
        prom_init_env();
        prom_init_memory();
+
+       /*init the uart base address */
+#if defined(CONFIG_EARLY_PRINTK) || defined(CONFIG_SERIAL_8250)
+       prom_init_uart_base();
+#endif
 }
 
 void __init prom_free_prom_memory(void)
index 6d341e426f64f4e56295a3fd0e80e31d94dd3e24..dc6488c1476320a8e501c0105a47b5259597756d 100644 (file)
@@ -23,7 +23,6 @@
 {                                                              \
        .irq            = int,                                  \
        .uartclk        = 1843200,                              \
-       .iobase         = (LOONGSON_UART_BASE - LOONGSON_PCIIO_BASE),\
        .iotype         = UPIO_PORT,                            \
        .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,    \
        .regshift       = 0,                                    \
@@ -52,20 +51,20 @@ static struct plat_serial8250_port uart8250_data[][2] = {
 static struct platform_device uart8250_device = {
        .name = "serial8250",
        .id = PLAT8250_DEV_PLATFORM,
-       .dev = {
-               .platform_data = uart8250_data[LOONGSON_MACHTYPE],
-               },
 };
 
 static int __init serial_init(void)
 {
-       if (uart8250_data[LOONGSON_MACHTYPE][0].iotype == UPIO_MEM)
-               uart8250_data[LOONGSON_MACHTYPE][0].membase =
-                       ioremap_nocache(LOONGSON_UART_BASE, 8);
+       if (uart8250_data[mips_machtype][0].iotype == UPIO_MEM)
+               uart8250_data[mips_machtype][0].membase =
+                       (void __iomem *)_loongson_uart_base;
+       else if (uart8250_data[mips_machtype][0].iotype == UPIO_PORT)
+               uart8250_data[mips_machtype][0].iobase =
+                   uart8250_base[mips_machtype] - LOONGSON_PCIIO_BASE;
 
-       platform_device_register(&uart8250_device);
+       uart8250_device.dev.platform_data = uart8250_data[mips_machtype];
 
-       return 0;
+       return platform_device_register(&uart8250_device);
 }
 
 device_initcall(serial_init);
diff --git a/arch/mips/loongson/common/uart_base.c b/arch/mips/loongson/common/uart_base.c
new file mode 100644 (file)
index 0000000..233c708
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2009 Lemote Inc.
+ * Author: Wu Zhangjin, wuzj@lemote.com
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/module.h>
+#include <asm/bootinfo.h>
+
+#include <loongson.h>
+
+unsigned long __maybe_unused _loongson_uart_base;
+EXPORT_SYMBOL(_loongson_uart_base);
+
+unsigned long __maybe_unused uart8250_base[] = {
+       [MACH_LOONGSON_UNKNOWN] 0,
+       [MACH_LEMOTE_FL2E]      (LOONGSON_PCIIO_BASE + 0x3f8),
+       [MACH_LEMOTE_FL2F]      (LOONGSON_PCIIO_BASE + 0x2f8),
+       [MACH_LEMOTE_ML2F7]     (LOONGSON_LIO1_BASE + 0x3f8),
+       [MACH_LEMOTE_YL2F89]    (LOONGSON_LIO1_BASE + 0x3f8),
+       [MACH_DEXXON_GDIUM2F10] (LOONGSON_LIO1_BASE + 0x3f8),
+       [MACH_LOONGSON_END]     0,
+};
+EXPORT_SYMBOL(uart8250_base);
+
+void __maybe_unused prom_init_uart_base(void)
+{
+       _loongson_uart_base =
+               (unsigned long)ioremap_nocache(uart8250_base[mips_machtype], 8);
+}