serial.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. static struct serial_device amirix_serial_drv = {
  74. .name = "amirix_serial",
  75. .start = amirix_serial_init,
  76. .stop = NULL,
  77. .setbrg = amirix_serial_setbrg,
  78. .putc = amirix_serial_putc,
  79. .puts = amirix_serial_puts,
  80. .getc = amirix_serial_getc,
  81. .tstc = amirix_serial_tstc,
  82. };
  83. void amirix_serial_initialize(void)
  84. {
  85. serial_register(&amirix_serial_drv);
  86. }
  87. __weak struct serial_device *default_serial_console(void)
  88. {
  89. return &amirix_serial_drv;
  90. }
  91. #if defined(CONFIG_CMD_KGDB)
  92. void kgdb_serial_init (void)
  93. {
  94. }
  95. void putDebugChar (int c)
  96. {
  97. serial_putc (c);
  98. }
  99. void putDebugStr (const char *str)
  100. {
  101. serial_puts (str);
  102. }
  103. int getDebugChar (void)
  104. {
  105. return serial_getc ();
  106. }
  107. void kgdb_interruptible (int yes)
  108. {
  109. return;
  110. }
  111. #endif