zoom2_serial.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2009 Wind River Systems, Inc.
  3. * Tom Rix <Tom.Rix@windriver.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. *
  20. * This file was adapted from arch/powerpc/cpu/mpc5xxx/serial.c
  21. *
  22. */
  23. #include <common.h>
  24. #include <serial.h>
  25. #include <ns16550.h>
  26. #include <asm/arch/cpu.h>
  27. #include "zoom2_serial.h"
  28. int quad_init_dev (unsigned long base)
  29. {
  30. /*
  31. * The Quad UART is on the debug board.
  32. * Check if the debug board is attached before using the UART
  33. */
  34. if (zoom2_debug_board_connected ()) {
  35. NS16550_t com_port = (NS16550_t) base;
  36. int baud_divisor = CONFIG_SYS_NS16550_CLK / 16 /
  37. CONFIG_BAUDRATE;
  38. /*
  39. * Zoom2 has a board specific initialization of its UART.
  40. * This generic initialization has been copied from
  41. * drivers/serial/ns16550.c. The macros have been expanded.
  42. *
  43. * Do the following instead of
  44. *
  45. * NS16550_init (com_port, clock_divisor);
  46. */
  47. com_port->ier = 0x00;
  48. /*
  49. * On Zoom2 board Set pre-scalar to 1
  50. * CLKSEL is GND => MCR[7] is 1 => preslr is 4
  51. * So change the prescl to 1
  52. */
  53. com_port->lcr = 0xBF;
  54. com_port->fcr |= 0x10;
  55. com_port->mcr &= 0x7F;
  56. /* This is generic ns16550.c setup */
  57. com_port->lcr = UART_LCR_BKSE | UART_LCR_8N1;
  58. com_port->dll = 0;
  59. com_port->dlm = 0;
  60. com_port->lcr = UART_LCR_8N1;
  61. com_port->mcr = UART_MCR_DTR | UART_MCR_RTS;
  62. com_port->fcr = UART_FCR_FIFO_EN | UART_FCR_RXSR |
  63. UART_FCR_TXSR;
  64. com_port->lcr = UART_LCR_BKSE | UART_LCR_8N1;
  65. com_port->dll = baud_divisor & 0xff;
  66. com_port->dlm = (baud_divisor >> 8) & 0xff;
  67. com_port->lcr = UART_LCR_8N1;
  68. }
  69. /*
  70. * We have to lie here, otherwise the board init code will hang
  71. * on the check
  72. */
  73. return 0;
  74. }
  75. void quad_putc_dev (unsigned long base, const char c)
  76. {
  77. if (zoom2_debug_board_connected ()) {
  78. if (c == '\n')
  79. quad_putc_dev (base, '\r');
  80. NS16550_putc ((NS16550_t) base, c);
  81. } else {
  82. usbtty_putc(c);
  83. }
  84. }
  85. void quad_puts_dev (unsigned long base, const char *s)
  86. {
  87. if (zoom2_debug_board_connected ()) {
  88. while ((s != NULL) && (*s != '\0'))
  89. quad_putc_dev (base, *s++);
  90. } else {
  91. usbtty_puts(s);
  92. }
  93. }
  94. int quad_getc_dev (unsigned long base)
  95. {
  96. if (zoom2_debug_board_connected ())
  97. return NS16550_getc ((NS16550_t) base);
  98. return usbtty_getc();
  99. }
  100. int quad_tstc_dev (unsigned long base)
  101. {
  102. if (zoom2_debug_board_connected ())
  103. return NS16550_tstc ((NS16550_t) base);
  104. return usbtty_tstc();
  105. }
  106. void quad_setbrg_dev (unsigned long base)
  107. {
  108. if (zoom2_debug_board_connected ()) {
  109. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 /
  110. CONFIG_BAUDRATE;
  111. NS16550_reinit ((NS16550_t) base, clock_divisor);
  112. }
  113. }
  114. QUAD_INIT (0)
  115. QUAD_INIT (1)
  116. QUAD_INIT (2)
  117. QUAD_INIT (3)