serial.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 <asm/u-boot.h>
  22. #include <asm/processor.h>
  23. #include <common.h>
  24. #include <command.h>
  25. #include <configs/ML2.h>
  26. #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
  27. #include <ns16550.h>
  28. #endif
  29. #if 0
  30. #include "serial.h"
  31. #endif
  32. #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
  33. const NS16550_t COM_PORTS[] = { (NS16550_t) CFG_NS16550_COM1,
  34. (NS16550_t) CFG_NS16550_COM2 };
  35. #endif
  36. int
  37. serial_init (void)
  38. {
  39. DECLARE_GLOBAL_DATA_PTR;
  40. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  41. #ifdef CFG_INIT_CHAN1
  42. (void)NS16550_init(COM_PORTS[0], clock_divisor);
  43. #endif
  44. #ifdef CFG_INIT_CHAN2
  45. (void)NS16550_init(COM_PORTS[1], clock_divisor);
  46. #endif
  47. return 0;
  48. }
  49. void
  50. serial_putc(const char c)
  51. {
  52. if (c == '\n')
  53. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
  54. NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
  55. }
  56. int
  57. serial_getc(void)
  58. {
  59. return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
  60. }
  61. int
  62. serial_tstc(void)
  63. {
  64. return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
  65. }
  66. void
  67. serial_setbrg (void)
  68. {
  69. DECLARE_GLOBAL_DATA_PTR;
  70. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  71. #ifdef CFG_INIT_CHAN1
  72. NS16550_reinit(COM_PORTS[0], clock_divisor);
  73. #endif
  74. #ifdef CFG_INIT_CHAN2
  75. NS16550_reinit(COM_PORTS[1], clock_divisor);
  76. #endif
  77. }
  78. void
  79. serial_puts (const char *s)
  80. {
  81. while (*s) {
  82. serial_putc (*s++);
  83. }
  84. }
  85. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  86. void
  87. kgdb_serial_init(void)
  88. {
  89. }
  90. void
  91. putDebugChar (int c)
  92. {
  93. serial_putc (c);
  94. }
  95. void
  96. putDebugStr (const char *str)
  97. {
  98. serial_puts (str);
  99. }
  100. int
  101. getDebugChar (void)
  102. {
  103. return serial_getc();
  104. }
  105. void
  106. kgdb_interruptible (int yes)
  107. {
  108. return;
  109. }
  110. #endif /* CFG_CMD_KGDB */