serial.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Author: Xilinx, Inc.
  3. *
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. *
  11. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
  12. * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
  13. * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
  14. * XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
  15. * FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
  16. * ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
  17. * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
  18. * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
  19. * WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
  20. * CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
  21. * FITNESS FOR A PARTICULAR PURPOSE.
  22. *
  23. *
  24. * Xilinx hardware products are not intended for use in life support
  25. * appliances, devices, or systems. Use in such applications is
  26. * expressly prohibited.
  27. *
  28. *
  29. * (c) Copyright 2002-2004 Xilinx Inc.
  30. * All rights reserved.
  31. *
  32. *
  33. * You should have received a copy of the GNU General Public License along
  34. * with this program; if not, write to the Free Software Foundation, Inc.,
  35. * 675 Mass Ave, Cambridge, MA 02139, USA.
  36. *
  37. */
  38. #include <asm/u-boot.h>
  39. #include <asm/processor.h>
  40. #include <common.h>
  41. #include <command.h>
  42. #include <config.h>
  43. DECLARE_GLOBAL_DATA_PTR;
  44. #define USE_CHAN1 \
  45. ((defined XPAR_UARTNS550_0_BASEADDR) && (defined CFG_INIT_CHAN1))
  46. #define USE_CHAN2 \
  47. ((defined XPAR_UARTNS550_1_BASEADDR) && (defined CFG_INIT_CHAN2))
  48. #if USE_CHAN1
  49. #include <ns16550.h>
  50. #endif
  51. #if USE_CHAN1
  52. const NS16550_t COM_PORTS[] = { (NS16550_t) (XPAR_UARTNS550_0_BASEADDR + 3)
  53. #if USE_CHAN2
  54. , (NS16550_t) (XPAR_UARTNS550_1_BASEADDR + 3)
  55. #endif
  56. };
  57. #endif
  58. int
  59. serial_init(void)
  60. {
  61. #if USE_CHAN1
  62. int clock_divisor;
  63. clock_divisor = XPAR_UARTNS550_0_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  64. (void) NS16550_init(COM_PORTS[0], clock_divisor);
  65. #if USE_CHAN2
  66. clock_divisor = XPAR_UARTNS550_1_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  67. (void) NS16550_init(COM_PORTS[1], clock_divisor);
  68. #endif
  69. #endif
  70. return 0;
  71. }
  72. void
  73. serial_putc(const char c)
  74. {
  75. if (c == '\n')
  76. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
  77. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
  78. }
  79. int
  80. serial_getc(void)
  81. {
  82. return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
  83. }
  84. int
  85. serial_tstc(void)
  86. {
  87. return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
  88. }
  89. void
  90. serial_setbrg(void)
  91. {
  92. #if USE_CHAN1
  93. int clock_divisor;
  94. clock_divisor = XPAR_UARTNS550_0_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  95. NS16550_reinit(COM_PORTS[0], clock_divisor);
  96. #if USE_CHAN2
  97. clock_divisor = XPAR_UARTNS550_1_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  98. NS16550_reinit(COM_PORTS[1], clock_divisor);
  99. #endif
  100. #endif
  101. }
  102. void
  103. serial_puts(const char *s)
  104. {
  105. while (*s) {
  106. serial_putc(*s++);
  107. }
  108. }
  109. #if defined(CONFIG_CMD_KGDB)
  110. void
  111. kgdb_serial_init(void)
  112. {
  113. }
  114. void
  115. putDebugChar(int c)
  116. {
  117. serial_putc(c);
  118. }
  119. void
  120. putDebugStr(const char *str)
  121. {
  122. serial_puts(str);
  123. }
  124. int
  125. getDebugChar(void)
  126. {
  127. return serial_getc();
  128. }
  129. void
  130. kgdb_interruptible(int yes)
  131. {
  132. return;
  133. }
  134. #endif