serial.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 <serial.h>
  33. #include <linux/compiler.h>
  34. #include "../include/memory.h"
  35. #include "serial.h"
  36. #ifdef CONFIG_DB64360
  37. #include "../db64360/mpsc.h"
  38. #endif
  39. #ifdef CONFIG_DB64460
  40. #include "../db64460/mpsc.h"
  41. #endif
  42. #include "ns16550.h"
  43. DECLARE_GLOBAL_DATA_PTR;
  44. #ifdef CONFIG_MPSC
  45. static int marvell_serial_init(void)
  46. {
  47. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  48. int clock_divisor = 230400 / gd->baudrate;
  49. #endif
  50. mpsc_init (gd->baudrate);
  51. /* init the DUART chans so that KGDB in the kernel can use them */
  52. #ifdef CONFIG_SYS_INIT_CHAN1
  53. NS16550_reinit (COM_PORTS[0], clock_divisor);
  54. #endif
  55. #ifdef CONFIG_SYS_INIT_CHAN2
  56. NS16550_reinit (COM_PORTS[1], clock_divisor);
  57. #endif
  58. return (0);
  59. }
  60. static void marvell_serial_putc(const char c)
  61. {
  62. if (c == '\n')
  63. mpsc_putchar ('\r');
  64. mpsc_putchar (c);
  65. }
  66. static int marvell_serial_getc(void)
  67. {
  68. return mpsc_getchar ();
  69. }
  70. static int marvell_serial_tstc(void)
  71. {
  72. return mpsc_test_char ();
  73. }
  74. static void marvell_serial_setbrg(void)
  75. {
  76. galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
  77. }
  78. #else /* ! CONFIG_MPSC */
  79. static int marvell_serial_init(void)
  80. {
  81. int clock_divisor = 230400 / gd->baudrate;
  82. #ifdef CONFIG_SYS_INIT_CHAN1
  83. (void) NS16550_init (0, clock_divisor);
  84. #endif
  85. #ifdef CONFIG_SYS_INIT_CHAN2
  86. (void) NS16550_init (1, clock_divisor);
  87. #endif
  88. return (0);
  89. }
  90. static void marvell_serial_putc(const char c)
  91. {
  92. if (c == '\n')
  93. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
  94. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
  95. }
  96. static int marvell_serial_getc(void)
  97. {
  98. return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  99. }
  100. static int marvell_serial_tstc(void)
  101. {
  102. return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  103. }
  104. static void marvell_serial_setbrg(void)
  105. {
  106. int clock_divisor = 230400 / gd->baudrate;
  107. #ifdef CONFIG_SYS_INIT_CHAN1
  108. NS16550_reinit (COM_PORTS[0], clock_divisor);
  109. #endif
  110. #ifdef CONFIG_SYS_INIT_CHAN2
  111. NS16550_reinit (COM_PORTS[1], clock_divisor);
  112. #endif
  113. }
  114. #endif /* CONFIG_MPSC */
  115. static struct serial_device marvell_serial_drv = {
  116. .name = "marvell_serial",
  117. .start = marvell_serial_init,
  118. .stop = NULL,
  119. .setbrg = marvell_serial_setbrg,
  120. .putc = marvell_serial_putc,
  121. .puts = default_serial_puts,
  122. .getc = marvell_serial_getc,
  123. .tstc = marvell_serial_tstc,
  124. };
  125. void marvell_serial_initialize(void)
  126. {
  127. serial_register(&marvell_serial_drv);
  128. }
  129. __weak struct serial_device *default_serial_console(void)
  130. {
  131. return &marvell_serial_drv;
  132. }
  133. #if defined(CONFIG_CMD_KGDB)
  134. void kgdb_serial_init (void)
  135. {
  136. }
  137. void putDebugChar (int c)
  138. {
  139. serial_putc (c);
  140. }
  141. void putDebugStr (const char *str)
  142. {
  143. serial_puts (str);
  144. }
  145. int getDebugChar (void)
  146. {
  147. return serial_getc ();
  148. }
  149. void kgdb_interruptible (int yes)
  150. {
  151. return;
  152. }
  153. #endif