serial.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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) 2004-2007 Cavium Networks
  7. */
  8. #include <linux/console.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/serial.h>
  13. #include <linux/serial_8250.h>
  14. #include <linux/serial_reg.h>
  15. #include <linux/tty.h>
  16. #include <linux/irq.h>
  17. #include <asm/time.h>
  18. #include <asm/octeon/octeon.h>
  19. #define DEBUG_UART 1
  20. unsigned int octeon_serial_in(struct uart_port *up, int offset)
  21. {
  22. int rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));
  23. if (offset == UART_IIR && (rv & 0xf) == 7) {
  24. /* Busy interrupt, read the USR (39) and try again. */
  25. cvmx_read_csr((uint64_t)(up->membase + (39 << 3)));
  26. rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));
  27. }
  28. return rv;
  29. }
  30. void octeon_serial_out(struct uart_port *up, int offset, int value)
  31. {
  32. /*
  33. * If bits 6 or 7 of the OCTEON UART's LCR are set, it quits
  34. * working.
  35. */
  36. if (offset == UART_LCR)
  37. value &= 0x9f;
  38. cvmx_write_csr((uint64_t)(up->membase + (offset << 3)), (u8)value);
  39. }
  40. /*
  41. * Allocated in .bss, so it is all zeroed.
  42. */
  43. #define OCTEON_MAX_UARTS 3
  44. static struct plat_serial8250_port octeon_uart8250_data[OCTEON_MAX_UARTS + 1];
  45. static struct platform_device octeon_uart8250_device = {
  46. .name = "serial8250",
  47. .id = PLAT8250_DEV_PLATFORM,
  48. .dev = {
  49. .platform_data = octeon_uart8250_data,
  50. },
  51. };
  52. static void __init octeon_uart_set_common(struct plat_serial8250_port *p)
  53. {
  54. p->flags = ASYNC_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
  55. p->type = PORT_OCTEON;
  56. p->iotype = UPIO_MEM;
  57. p->regshift = 3; /* I/O addresses are every 8 bytes */
  58. if (octeon_is_simulation())
  59. /* Make simulator output fast*/
  60. p->uartclk = 115200 * 16;
  61. else
  62. p->uartclk = octeon_get_io_clock_rate();
  63. p->serial_in = octeon_serial_in;
  64. p->serial_out = octeon_serial_out;
  65. }
  66. static int __init octeon_serial_init(void)
  67. {
  68. int enable_uart0;
  69. int enable_uart1;
  70. int enable_uart2;
  71. struct plat_serial8250_port *p;
  72. #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
  73. /*
  74. * If we are configured to run as the second of two kernels,
  75. * disable uart0 and enable uart1. Uart0 is owned by the first
  76. * kernel
  77. */
  78. enable_uart0 = 0;
  79. enable_uart1 = 1;
  80. #else
  81. /*
  82. * We are configured for the first kernel. We'll enable uart0
  83. * if the bootloader told us to use 0, otherwise will enable
  84. * uart 1.
  85. */
  86. enable_uart0 = (octeon_get_boot_uart() == 0);
  87. enable_uart1 = (octeon_get_boot_uart() == 1);
  88. #ifdef CONFIG_KGDB
  89. enable_uart1 = 1;
  90. #endif
  91. #endif
  92. /* Right now CN52XX is the only chip with a third uart */
  93. enable_uart2 = OCTEON_IS_MODEL(OCTEON_CN52XX);
  94. p = octeon_uart8250_data;
  95. if (enable_uart0) {
  96. /* Add a ttyS device for hardware uart 0 */
  97. octeon_uart_set_common(p);
  98. p->membase = (void *) CVMX_MIO_UARTX_RBR(0);
  99. p->mapbase = CVMX_MIO_UARTX_RBR(0) & ((1ull << 49) - 1);
  100. p->irq = OCTEON_IRQ_UART0;
  101. p++;
  102. }
  103. if (enable_uart1) {
  104. /* Add a ttyS device for hardware uart 1 */
  105. octeon_uart_set_common(p);
  106. p->membase = (void *) CVMX_MIO_UARTX_RBR(1);
  107. p->mapbase = CVMX_MIO_UARTX_RBR(1) & ((1ull << 49) - 1);
  108. p->irq = OCTEON_IRQ_UART1;
  109. p++;
  110. }
  111. if (enable_uart2) {
  112. /* Add a ttyS device for hardware uart 2 */
  113. octeon_uart_set_common(p);
  114. p->membase = (void *) CVMX_MIO_UART2_RBR;
  115. p->mapbase = CVMX_MIO_UART2_RBR & ((1ull << 49) - 1);
  116. p->irq = OCTEON_IRQ_UART2;
  117. p++;
  118. }
  119. BUG_ON(p > &octeon_uart8250_data[OCTEON_MAX_UARTS]);
  120. return platform_device_register(&octeon_uart8250_device);
  121. }
  122. device_initcall(octeon_serial_init);