serial.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * (C) Copyright 2002
  3. * Peter De Schrijver (p2@mind.be), Mind Linux Solutions, NV.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. *
  20. */
  21. #include <common.h>
  22. #include <asm/u-boot.h>
  23. #include <asm/processor.h>
  24. #include <command.h>
  25. #include <config.h>
  26. #include <serial.h>
  27. #include <linux/compiler.h>
  28. #include <ns16550.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. const NS16550_t COM_PORTS[] =
  31. { (NS16550_t) CONFIG_SYS_NS16550_COM1, (NS16550_t) CONFIG_SYS_NS16550_COM2 };
  32. #undef CONFIG_SYS_DUART_CHAN
  33. #define CONFIG_SYS_DUART_CHAN gComPort
  34. static int gComPort = 0;
  35. static int amirix_serial_init(void)
  36. {
  37. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
  38. (void) NS16550_init (COM_PORTS[0], clock_divisor);
  39. gComPort = 0;
  40. return 0;
  41. }
  42. static void amirix_serial_putc(const char c)
  43. {
  44. if (c == '\n') {
  45. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
  46. }
  47. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
  48. }
  49. static int amirix_serial_getc(void)
  50. {
  51. return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  52. }
  53. static int amirix_serial_tstc(void)
  54. {
  55. return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  56. }
  57. static void amirix_serial_setbrg(void)
  58. {
  59. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
  60. #ifdef CONFIG_SYS_INIT_CHAN1
  61. NS16550_reinit (COM_PORTS[0], clock_divisor);
  62. #endif
  63. #ifdef CONFIG_SYS_INIT_CHAN2
  64. NS16550_reinit (COM_PORTS[1], clock_divisor);
  65. #endif
  66. }
  67. static void amirix_serial_puts(const char *s)
  68. {
  69. while (*s) {
  70. serial_putc (*s++);
  71. }
  72. }
  73. #ifdef CONFIG_SERIAL_MULTI
  74. static struct serial_device amirix_serial_drv = {
  75. .name = "amirix_serial",
  76. .start = amirix_serial_init,
  77. .stop = NULL,
  78. .setbrg = amirix_serial_setbrg,
  79. .putc = amirix_serial_putc,
  80. .puts = amirix_serial_puts,
  81. .getc = amirix_serial_getc,
  82. .tstc = amirix_serial_tstc,
  83. };
  84. void amirix_serial_initialize(void)
  85. {
  86. serial_register(&amirix_serial_drv);
  87. }
  88. __weak struct serial_device *default_serial_console(void)
  89. {
  90. return &amirix_serial_drv;
  91. }
  92. #else
  93. int serial_init(void)
  94. {
  95. return amirix_serial_init();
  96. }
  97. void serial_setbrg(void)
  98. {
  99. amirix_serial_setbrg();
  100. }
  101. void serial_putc(const char c)
  102. {
  103. amirix_serial_putc(c);
  104. }
  105. void serial_puts(const char *s)
  106. {
  107. amirix_serial_puts(s);
  108. }
  109. int serial_getc(void)
  110. {
  111. return amirix_serial_getc();
  112. }
  113. int serial_tstc(void)
  114. {
  115. return amirix_serial_tstc();
  116. }
  117. #endif
  118. #if defined(CONFIG_CMD_KGDB)
  119. void kgdb_serial_init (void)
  120. {
  121. }
  122. void putDebugChar (int c)
  123. {
  124. serial_putc (c);
  125. }
  126. void putDebugStr (const char *str)
  127. {
  128. serial_puts (str);
  129. }
  130. int getDebugChar (void)
  131. {
  132. return serial_getc ();
  133. }
  134. void kgdb_interruptible (int yes)
  135. {
  136. return;
  137. }
  138. #endif