serial.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * (C) Copyright 2001
  3. * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * serial.c - serial support for the gal ev board
  25. */
  26. /* supports both the 16650 duart and the MPSC */
  27. #include <common.h>
  28. #include <command.h>
  29. #include <galileo/memory.h>
  30. #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
  31. #include <ns16550.h>
  32. #endif
  33. #include "serial.h"
  34. #include "mpsc.h"
  35. #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
  36. const NS16550_t COM_PORTS[] = { (NS16550_t) CFG_NS16550_COM1,
  37. (NS16550_t) CFG_NS16550_COM2 };
  38. #endif
  39. #ifdef CONFIG_MPSC
  40. int serial_init (void)
  41. {
  42. DECLARE_GLOBAL_DATA_PTR;
  43. #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
  44. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  45. #endif
  46. mpsc_init(gd->baudrate);
  47. /* init the DUART chans so that KGDB in the kernel can use them */
  48. #ifdef CFG_INIT_CHAN1
  49. NS16550_reinit(COM_PORTS[0], clock_divisor);
  50. #endif
  51. #ifdef CFG_INIT_CHAN2
  52. NS16550_reinit(COM_PORTS[1], clock_divisor);
  53. #endif
  54. return (0);
  55. }
  56. void
  57. serial_putc(const char c)
  58. {
  59. if (c == '\n')
  60. mpsc_putchar('\r');
  61. mpsc_putchar(c);
  62. }
  63. int
  64. serial_getc(void)
  65. {
  66. return mpsc_getchar();
  67. }
  68. int
  69. serial_tstc(void)
  70. {
  71. return mpsc_test_char();
  72. }
  73. void
  74. serial_setbrg (void)
  75. {
  76. DECLARE_GLOBAL_DATA_PTR;
  77. galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
  78. }
  79. #else /* ! CONFIG_MPSC */
  80. int serial_init (void)
  81. {
  82. DECLARE_GLOBAL_DATA_PTR;
  83. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  84. #ifdef CFG_INIT_CHAN1
  85. (void)NS16550_init(COM_PORTS[0], clock_divisor);
  86. #endif
  87. #ifdef CFG_INIT_CHAN2
  88. (void)NS16550_init(COM_PORTS[1], clock_divisor);
  89. #endif
  90. return (0);
  91. }
  92. void
  93. serial_putc(const char c)
  94. {
  95. if (c == '\n')
  96. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
  97. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
  98. }
  99. int
  100. serial_getc(void)
  101. {
  102. return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
  103. }
  104. int
  105. serial_tstc(void)
  106. {
  107. return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
  108. }
  109. void
  110. serial_setbrg (void)
  111. {
  112. DECLARE_GLOBAL_DATA_PTR;
  113. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  114. #ifdef CFG_INIT_CHAN1
  115. NS16550_reinit(COM_PORTS[0], clock_divisor);
  116. #endif
  117. #ifdef CFG_INIT_CHAN2
  118. NS16550_reinit(COM_PORTS[1], clock_divisor);
  119. #endif
  120. }
  121. #endif /* CONFIG_MPSC */
  122. void
  123. serial_puts (const char *s)
  124. {
  125. while (*s) {
  126. serial_putc (*s++);
  127. }
  128. }
  129. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  130. void
  131. kgdb_serial_init(void)
  132. {
  133. }
  134. void
  135. putDebugChar (int c)
  136. {
  137. serial_putc (c);
  138. }
  139. void
  140. putDebugStr (const char *str)
  141. {
  142. serial_puts (str);
  143. }
  144. int
  145. getDebugChar (void)
  146. {
  147. return serial_getc();
  148. }
  149. void
  150. kgdb_interruptible (int yes)
  151. {
  152. return;
  153. }
  154. #endif /* CFG_CMD_KGDB */