serial.c 2.3 KB

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