serial.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_3A780E1W] = {PORT_M(2, 33177600), {} },
  46. [MACH_LOONGSON_END] = {},
  47. };
  48. static struct platform_device uart8250_device = {
  49. .name = "serial8250",
  50. .id = PLAT8250_DEV_PLATFORM,
  51. };
  52. static int __init serial_init(void)
  53. {
  54. int i;
  55. unsigned char iotype;
  56. iotype = uart8250_data[mips_machtype][0].iotype;
  57. if (UPIO_MEM == iotype) {
  58. uart8250_data[mips_machtype][0].mapbase =
  59. loongson_uart_base[0];
  60. uart8250_data[mips_machtype][0].membase =
  61. (void __iomem *)_loongson_uart_base[0];
  62. }
  63. else if (UPIO_PORT == iotype)
  64. uart8250_data[mips_machtype][0].iobase =
  65. loongson_uart_base[0] - LOONGSON_PCIIO_BASE;
  66. if (loongson_sysconf.uarts[0].uartclk)
  67. uart8250_data[mips_machtype][0].uartclk =
  68. loongson_sysconf.uarts[0].uartclk;
  69. for (i = 1; i < loongson_sysconf.nr_uarts; i++) {
  70. iotype = loongson_sysconf.uarts[i].iotype;
  71. uart8250_data[mips_machtype][i].iotype = iotype;
  72. loongson_uart_base[i] = loongson_sysconf.uarts[i].uart_base;
  73. if (UPIO_MEM == iotype) {
  74. uart8250_data[mips_machtype][i].irq =
  75. MIPS_CPU_IRQ_BASE + loongson_sysconf.uarts[i].int_offset;
  76. uart8250_data[mips_machtype][i].mapbase =
  77. loongson_uart_base[i];
  78. uart8250_data[mips_machtype][i].membase =
  79. ioremap_nocache(loongson_uart_base[i], 8);
  80. } else if (UPIO_PORT == iotype) {
  81. uart8250_data[mips_machtype][i].irq =
  82. loongson_sysconf.uarts[i].int_offset;
  83. uart8250_data[mips_machtype][i].iobase =
  84. loongson_uart_base[i] - LOONGSON_PCIIO_BASE;
  85. }
  86. uart8250_data[mips_machtype][i].uartclk =
  87. loongson_sysconf.uarts[i].uartclk;
  88. uart8250_data[mips_machtype][i].flags =
  89. UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  90. }
  91. memset(&uart8250_data[mips_machtype][loongson_sysconf.nr_uarts],
  92. 0, sizeof(struct plat_serial8250_port));
  93. uart8250_device.dev.platform_data = uart8250_data[mips_machtype];
  94. return platform_device_register(&uart8250_device);
  95. }
  96. module_init(serial_init);
  97. static void __exit serial_exit(void)
  98. {
  99. platform_device_unregister(&uart8250_device);
  100. }
  101. module_exit(serial_exit);