serial.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #include <serial.h>
  31. #include <linux/compiler.h>
  32. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  33. #include <ns16550.h>
  34. #endif
  35. #include "serial.h"
  36. #include "mpsc.h"
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  39. const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
  40. (NS16550_t) CONFIG_SYS_NS16550_COM2 };
  41. #endif
  42. #ifdef CONFIG_MPSC
  43. static int evb64260_serial_init(void)
  44. {
  45. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  46. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / 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. static void evb64260_serial_putc(const char c)
  59. {
  60. if (c == '\n')
  61. mpsc_putchar('\r');
  62. mpsc_putchar(c);
  63. }
  64. static int evb64260_serial_getc(void)
  65. {
  66. return mpsc_getchar();
  67. }
  68. static int evb64260_serial_tstc(void)
  69. {
  70. return mpsc_test_char();
  71. }
  72. static void evb64260_serial_setbrg(void)
  73. {
  74. galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
  75. }
  76. #else /* ! CONFIG_MPSC */
  77. static int evb64260_serial_init(void)
  78. {
  79. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
  80. #ifdef CONFIG_SYS_INIT_CHAN1
  81. (void)NS16550_init(COM_PORTS[0], clock_divisor);
  82. #endif
  83. #ifdef CONFIG_SYS_INIT_CHAN2
  84. (void)NS16550_init(COM_PORTS[1], clock_divisor);
  85. #endif
  86. return (0);
  87. }
  88. static void evb64260_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. static int evb64260_serial_getc(void)
  95. {
  96. return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  97. }
  98. static int evb64260_serial_tstc(void)
  99. {
  100. return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  101. }
  102. static void evb64260_serial_setbrg(void)
  103. {
  104. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / 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. static struct serial_device evb64260_serial_drv = {
  114. .name = "evb64260_serial",
  115. .start = evb64260_serial_init,
  116. .stop = NULL,
  117. .setbrg = evb64260_serial_setbrg,
  118. .putc = evb64260_serial_putc,
  119. .puts = default_serial_puts,
  120. .getc = evb64260_serial_getc,
  121. .tstc = evb64260_serial_tstc,
  122. };
  123. void evb64260_serial_initialize(void)
  124. {
  125. serial_register(&evb64260_serial_drv);
  126. }
  127. __weak struct serial_device *default_serial_console(void)
  128. {
  129. return &evb64260_serial_drv;
  130. }
  131. #if defined(CONFIG_CMD_KGDB)
  132. void
  133. kgdb_serial_init(void)
  134. {
  135. }
  136. void
  137. putDebugChar (int c)
  138. {
  139. serial_putc (c);
  140. }
  141. void
  142. putDebugStr (const char *str)
  143. {
  144. serial_puts (str);
  145. }
  146. int
  147. getDebugChar (void)
  148. {
  149. return serial_getc();
  150. }
  151. void
  152. kgdb_interruptible (int yes)
  153. {
  154. return;
  155. }
  156. #endif