serial.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/types.h>
  39. #include <asm/u-boot.h>
  40. #include <asm/processor.h>
  41. #include <common.h>
  42. #include <command.h>
  43. #include <config.h>
  44. DECLARE_GLOBAL_DATA_PTR;
  45. #define USE_CHAN1 \
  46. ((defined XPAR_UARTNS550_0_BASEADDR) && (defined CFG_INIT_CHAN1))
  47. #define USE_CHAN2 \
  48. ((defined XPAR_UARTNS550_1_BASEADDR) && (defined CFG_INIT_CHAN2))
  49. #if USE_CHAN1
  50. #include <ns16550.h>
  51. #endif
  52. #if USE_CHAN1
  53. const NS16550_t COM_PORTS[] = { (NS16550_t) (XPAR_UARTNS550_0_BASEADDR + 3)
  54. #if USE_CHAN2
  55. , (NS16550_t) (XPAR_UARTNS550_1_BASEADDR + 3)
  56. #endif
  57. };
  58. #endif
  59. int
  60. serial_init(void)
  61. {
  62. #if USE_CHAN1
  63. int clock_divisor;
  64. clock_divisor = XPAR_UARTNS550_0_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  65. (void) NS16550_init(COM_PORTS[0], clock_divisor);
  66. #if USE_CHAN2
  67. clock_divisor = XPAR_UARTNS550_1_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  68. (void) NS16550_init(COM_PORTS[1], clock_divisor);
  69. #endif
  70. #endif
  71. return 0;
  72. }
  73. void
  74. serial_putc(const char c)
  75. {
  76. if (c == '\n')
  77. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
  78. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
  79. }
  80. int
  81. serial_getc(void)
  82. {
  83. return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
  84. }
  85. int
  86. serial_tstc(void)
  87. {
  88. return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
  89. }
  90. void
  91. serial_setbrg(void)
  92. {
  93. #if USE_CHAN1
  94. int clock_divisor;
  95. clock_divisor = XPAR_UARTNS550_0_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  96. NS16550_reinit(COM_PORTS[0], clock_divisor);
  97. #if USE_CHAN2
  98. clock_divisor = XPAR_UARTNS550_1_CLOCK_FREQ_HZ / 16 / gd->baudrate;
  99. NS16550_reinit(COM_PORTS[1], clock_divisor);
  100. #endif
  101. #endif
  102. }
  103. void
  104. serial_puts(const char *s)
  105. {
  106. while (*s) {
  107. serial_putc(*s++);
  108. }
  109. }
  110. #if defined(CONFIG_CMD_KGDB)
  111. void
  112. kgdb_serial_init(void)
  113. {
  114. }
  115. void
  116. putDebugChar(int c)
  117. {
  118. serial_putc(c);
  119. }
  120. void
  121. putDebugStr(const char *str)
  122. {
  123. serial_puts(str);
  124. }
  125. int
  126. getDebugChar(void)
  127. {
  128. return serial_getc();
  129. }
  130. void
  131. kgdb_interruptible(int yes)
  132. {
  133. return;
  134. }
  135. #endif