serial.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <configs/ML2.h>
  26. #include <serial.h>
  27. #include <linux/compiler.h>
  28. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  29. #include <ns16550.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  33. const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
  34. (NS16550_t) CONFIG_SYS_NS16550_COM2
  35. };
  36. #endif
  37. static int ml2_serial_init(void)
  38. {
  39. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
  40. #ifdef CONFIG_SYS_INIT_CHAN1
  41. (void) NS16550_init (COM_PORTS[0], clock_divisor);
  42. #endif
  43. #ifdef CONFIG_SYS_INIT_CHAN2
  44. (void) NS16550_init (COM_PORTS[1], clock_divisor);
  45. #endif
  46. return 0;
  47. }
  48. static void ml2_serial_putc(const char c)
  49. {
  50. if (c == '\n')
  51. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
  52. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
  53. }
  54. static int ml2_serial_getc(void)
  55. {
  56. return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  57. }
  58. static int ml2_serial_tstc(void)
  59. {
  60. return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  61. }
  62. static void ml2_serial_setbrg(void)
  63. {
  64. int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
  65. #ifdef CONFIG_SYS_INIT_CHAN1
  66. NS16550_reinit (COM_PORTS[0], clock_divisor);
  67. #endif
  68. #ifdef CONFIG_SYS_INIT_CHAN2
  69. NS16550_reinit (COM_PORTS[1], clock_divisor);
  70. #endif
  71. }
  72. static void ml2_serial_puts(const char *s)
  73. {
  74. while (*s) {
  75. serial_putc (*s++);
  76. }
  77. }
  78. static struct serial_device ml2_serial_drv = {
  79. .name = "ml2_serial",
  80. .start = ml2_serial_init,
  81. .stop = NULL,
  82. .setbrg = ml2_serial_setbrg,
  83. .putc = ml2_serial_putc,
  84. .puts = ml2_serial_puts,
  85. .getc = ml2_serial_getc,
  86. .tstc = ml2_serial_tstc,
  87. };
  88. void ml2_serial_initialize(void)
  89. {
  90. serial_register(&ml2_serial_drv);
  91. }
  92. __weak struct serial_device *default_serial_console(void)
  93. {
  94. return &ml2_serial_drv;
  95. }
  96. #if defined(CONFIG_CMD_KGDB)
  97. void kgdb_serial_init (void)
  98. {
  99. }
  100. void putDebugChar (int c)
  101. {
  102. serial_putc (c);
  103. }
  104. void putDebugStr (const char *str)
  105. {
  106. serial_puts (str);
  107. }
  108. int getDebugChar (void)
  109. {
  110. return serial_getc ();
  111. }
  112. void kgdb_interruptible (int yes)
  113. {
  114. return;
  115. }
  116. #endif