Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
0007  *
0008  * Copyright (C) 2009 Lemote, Inc.
0009  * Author: Yan hua (yanhua@lemote.com)
0010  * Author: Wu Zhangjin (wuzhangjin@gmail.com)
0011  */
0012 
0013 #include <linux/io.h>
0014 #include <linux/module.h>
0015 #include <linux/serial_8250.h>
0016 
0017 #include <asm/bootinfo.h>
0018 
0019 #include <loongson.h>
0020 #include <machine.h>
0021 
0022 #define PORT(int, clk)          \
0023 {                               \
0024     .irq        = int,                  \
0025     .uartclk    = clk,                  \
0026     .iotype     = UPIO_PORT,                \
0027     .flags      = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,    \
0028     .regshift   = 0,                    \
0029 }
0030 
0031 #define PORT_M(int, clk)                \
0032 {                               \
0033     .irq        = MIPS_CPU_IRQ_BASE + (int),        \
0034     .uartclk    = clk,                  \
0035     .iotype     = UPIO_MEM,             \
0036     .membase    = (void __iomem *)NULL,         \
0037     .flags      = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,    \
0038     .regshift   = 0,                    \
0039 }
0040 
0041 static struct plat_serial8250_port uart8250_data[MACH_LOONGSON_END + 1] = {
0042     [MACH_LOONGSON_UNKNOWN] = {},
0043     [MACH_LEMOTE_FL2E]  = PORT(4, 1843200),
0044     [MACH_LEMOTE_FL2F]  = PORT(3, 1843200),
0045     [MACH_LEMOTE_ML2F7] = PORT_M(3, 3686400),
0046     [MACH_LEMOTE_YL2F89]    = PORT_M(3, 3686400),
0047     [MACH_DEXXON_GDIUM2F10] = PORT_M(3, 3686400),
0048     [MACH_LEMOTE_NAS]   = PORT_M(3, 3686400),
0049     [MACH_LEMOTE_LL2F]  = PORT(3, 1843200),
0050     [MACH_LOONGSON_END] = {},
0051 };
0052 
0053 static struct platform_device uart8250_device = {
0054     .name = "serial8250",
0055     .id = PLAT8250_DEV_PLATFORM,
0056 };
0057 
0058 static int __init serial_init(void)
0059 {
0060     unsigned char iotype;
0061 
0062     iotype = uart8250_data[mips_machtype].iotype;
0063 
0064     if (UPIO_MEM == iotype) {
0065         uart8250_data[mips_machtype].mapbase =
0066             loongson_uart_base;
0067         uart8250_data[mips_machtype].membase =
0068             (void __iomem *)_loongson_uart_base;
0069     }
0070     else if (UPIO_PORT == iotype)
0071         uart8250_data[mips_machtype].iobase =
0072             loongson_uart_base - LOONGSON_PCIIO_BASE;
0073 
0074     memset(&uart8250_data[mips_machtype + 1], 0,
0075             sizeof(struct plat_serial8250_port));
0076     uart8250_device.dev.platform_data = &uart8250_data[mips_machtype];
0077 
0078     return platform_device_register(&uart8250_device);
0079 }
0080 module_init(serial_init);
0081 
0082 static void __exit serial_exit(void)
0083 {
0084     platform_device_unregister(&uart8250_device);
0085 }
0086 module_exit(serial_exit);