serial.c 3.3 KB

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