serial.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. DECLARE_GLOBAL_DATA_PTR;
  36. #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
  37. const NS16550_t COM_PORTS[] = { (NS16550_t) CFG_NS16550_COM1,
  38. (NS16550_t) CFG_NS16550_COM2 };
  39. #endif
  40. #ifdef CONFIG_MPSC
  41. int serial_init (void)
  42. {
  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. galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
  77. }
  78. #else /* ! CONFIG_MPSC */
  79. int serial_init (void)
  80. {
  81. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  82. #ifdef CFG_INIT_CHAN1
  83. (void)NS16550_init(COM_PORTS[0], clock_divisor);
  84. #endif
  85. #ifdef CFG_INIT_CHAN2
  86. (void)NS16550_init(COM_PORTS[1], clock_divisor);
  87. #endif
  88. return (0);
  89. }
  90. void
  91. serial_putc(const char c)
  92. {
  93. if (c == '\n')
  94. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
  95. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
  96. }
  97. int
  98. serial_getc(void)
  99. {
  100. return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
  101. }
  102. int
  103. serial_tstc(void)
  104. {
  105. return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
  106. }
  107. void
  108. serial_setbrg (void)
  109. {
  110. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  111. #ifdef CFG_INIT_CHAN1
  112. NS16550_reinit(COM_PORTS[0], clock_divisor);
  113. #endif
  114. #ifdef CFG_INIT_CHAN2
  115. NS16550_reinit(COM_PORTS[1], clock_divisor);
  116. #endif
  117. }
  118. #endif /* CONFIG_MPSC */
  119. void
  120. serial_puts (const char *s)
  121. {
  122. while (*s) {
  123. serial_putc (*s++);
  124. }
  125. }
  126. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  127. void
  128. kgdb_serial_init(void)
  129. {
  130. }
  131. void
  132. putDebugChar (int c)
  133. {
  134. serial_putc (c);
  135. }
  136. void
  137. putDebugStr (const char *str)
  138. {
  139. serial_puts (str);
  140. }
  141. int
  142. getDebugChar (void)
  143. {
  144. return serial_getc();
  145. }
  146. void
  147. kgdb_interruptible (int yes)
  148. {
  149. return;
  150. }
  151. #endif /* CFG_CMD_KGDB */