serial.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. DECLARE_GLOBAL_DATA_PTR;
  42. #ifdef CONFIG_MPSC
  43. int serial_init (void)
  44. {
  45. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_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 CONFIG_SYS_INIT_CHAN1
  51. NS16550_reinit (COM_PORTS[0], clock_divisor);
  52. #endif
  53. #ifdef CONFIG_SYS_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. galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
  75. }
  76. #else /* ! CONFIG_MPSC */
  77. int serial_init (void)
  78. {
  79. int clock_divisor = 230400 / gd->baudrate;
  80. #ifdef CONFIG_SYS_INIT_CHAN1
  81. (void) NS16550_init (0, clock_divisor);
  82. #endif
  83. #ifdef CONFIG_SYS_INIT_CHAN2
  84. (void) NS16550_init (1, clock_divisor);
  85. #endif
  86. return (0);
  87. }
  88. void serial_putc (const char c)
  89. {
  90. if (c == '\n')
  91. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
  92. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
  93. }
  94. int serial_getc (void)
  95. {
  96. return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  97. }
  98. int serial_tstc (void)
  99. {
  100. return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  101. }
  102. void serial_setbrg (void)
  103. {
  104. int clock_divisor = 230400 / gd->baudrate;
  105. #ifdef CONFIG_SYS_INIT_CHAN1
  106. NS16550_reinit (COM_PORTS[0], clock_divisor);
  107. #endif
  108. #ifdef CONFIG_SYS_INIT_CHAN2
  109. NS16550_reinit (COM_PORTS[1], clock_divisor);
  110. #endif
  111. }
  112. #endif /* CONFIG_MPSC */
  113. void serial_puts (const char *s)
  114. {
  115. while (*s) {
  116. serial_putc (*s++);
  117. }
  118. }
  119. #if defined(CONFIG_CMD_KGDB)
  120. void kgdb_serial_init (void)
  121. {
  122. }
  123. void putDebugChar (int c)
  124. {
  125. serial_putc (c);
  126. }
  127. void putDebugStr (const char *str)
  128. {
  129. serial_puts (str);
  130. }
  131. int getDebugChar (void)
  132. {
  133. return serial_getc ();
  134. }
  135. void kgdb_interruptible (int yes)
  136. {
  137. return;
  138. }
  139. #endif