serial.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
  7. *
  8. * Copyright (C) 2009 Lemote, Inc.
  9. * Author: Yan hua (yanhua@lemote.com)
  10. * Author: Wu Zhangjin (wuzhangjin@gmail.com)
  11. */
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/serial_8250.h>
  15. #include <asm/bootinfo.h>
  16. #include <loongson.h>
  17. #include <machine.h>
  18. #define PORT(int, clk) \
  19. { \
  20. .irq = int, \
  21. .uartclk = clk, \
  22. .iotype = UPIO_PORT, \
  23. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST, \
  24. .regshift = 0, \
  25. }
  26. #define PORT_M(int, clk) \
  27. { \
  28. .irq = MIPS_CPU_IRQ_BASE + (int), \
  29. .uartclk = clk, \
  30. .iotype = UPIO_MEM, \
  31. .membase = (void __iomem *)NULL, \
  32. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST, \
  33. .regshift = 0, \
  34. }
  35. static struct plat_serial8250_port uart8250_data[][MAX_UARTS + 1] = {
  36. [MACH_LOONGSON_UNKNOWN] = {},
  37. [MACH_LEMOTE_FL2E] = {PORT(4, 1843200), {} },
  38. [MACH_LEMOTE_FL2F] = {PORT(3, 1843200), {} },
  39. [MACH_LEMOTE_ML2F7] = {PORT_M(3, 3686400), {} },
  40. [MACH_LEMOTE_YL2F89] = {PORT_M(3, 3686400), {} },
  41. [MACH_DEXXON_GDIUM2F10] = {PORT_M(3, 3686400), {} },
  42. [MACH_LEMOTE_NAS] = {PORT_M(3, 3686400), {} },
  43. [MACH_LEMOTE_LL2F] = {PORT(3, 1843200), {} },
  44. [MACH_LOONGSON_GENERIC] = {PORT_M(2, 25000000), {} },
  45. [MACH_LOONGSON_END] = {},
  46. };
  47. static struct platform_device uart8250_device = {
  48. .name = "serial8250",
  49. .id = PLAT8250_DEV_PLATFORM,
  50. };
  51. static int __init serial_init(void)
  52. {
  53. int i;
  54. unsigned char iotype;
  55. iotype = uart8250_data[mips_machtype][0].iotype;
  56. if (UPIO_MEM == iotype) {
  57. uart8250_data[mips_machtype][0].mapbase =
  58. loongson_uart_base[0];
  59. uart8250_data[mips_machtype][0].membase =
  60. (void __iomem *)_loongson_uart_base[0];
  61. }
  62. else if (UPIO_PORT == iotype)
  63. uart8250_data[mips_machtype][0].iobase =
  64. loongson_uart_base[0] - LOONGSON_PCIIO_BASE;
  65. if (loongson_sysconf.uarts[0].uartclk)
  66. uart8250_data[mips_machtype][0].uartclk =
  67. loongson_sysconf.uarts[0].uartclk;
  68. for (i = 1; i < loongson_sysconf.nr_uarts; i++) {
  69. iotype = loongson_sysconf.uarts[i].iotype;
  70. uart8250_data[mips_machtype][i].iotype = iotype;
  71. loongson_uart_base[i] = loongson_sysconf.uarts[i].uart_base;
  72. if (UPIO_MEM == iotype) {
  73. uart8250_data[mips_machtype][i].irq =
  74. MIPS_CPU_IRQ_BASE + loongson_sysconf.uarts[i].int_offset;
  75. uart8250_data[mips_machtype][i].mapbase =
  76. loongson_uart_base[i];
  77. uart8250_data[mips_machtype][i].membase =
  78. ioremap_nocache(loongson_uart_base[i], 8);
  79. } else if (UPIO_PORT == iotype) {
  80. uart8250_data[mips_machtype][i].irq =
  81. loongson_sysconf.uarts[i].int_offset;
  82. uart8250_data[mips_machtype][i].iobase =
  83. loongson_uart_base[i] - LOONGSON_PCIIO_BASE;
  84. }
  85. uart8250_data[mips_machtype][i].uartclk =
  86. loongson_sysconf.uarts[i].uartclk;
  87. uart8250_data[mips_machtype][i].flags =
  88. UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  89. }
  90. memset(&uart8250_data[mips_machtype][loongson_sysconf.nr_uarts],
  91. 0, sizeof(struct plat_serial8250_port));
  92. uart8250_device.dev.platform_data = uart8250_data[mips_machtype];
  93. return platform_device_register(&uart8250_device);
  94. }
  95. module_init(serial_init);
  96. static void __init serial_exit(void)
  97. {
  98. platform_device_unregister(&uart8250_device);
  99. }
  100. module_exit(serial_exit);