serial.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * (C) Copyright 2001
  3. * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
  4. *
  5. * modified for marvell db64360 eval board by
  6. * Ingo Assmus <ingo.assmus@keymile.com>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. /*
  11. * serial.c - serial support for the gal ev board
  12. */
  13. /* supports both the 16650 duart and the MPSC */
  14. #include <common.h>
  15. #include <command.h>
  16. #include <serial.h>
  17. #include <linux/compiler.h>
  18. #include "../include/memory.h"
  19. #include "ns16550.h"
  20. DECLARE_GLOBAL_DATA_PTR;
  21. #ifdef CONFIG_MPSC
  22. static int marvell_serial_init(void)
  23. {
  24. #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  25. int clock_divisor = 230400 / gd->baudrate;
  26. #endif
  27. mpsc_init (gd->baudrate);
  28. /* init the DUART chans so that KGDB in the kernel can use them */
  29. #ifdef CONFIG_SYS_INIT_CHAN1
  30. NS16550_reinit (COM_PORTS[0], clock_divisor);
  31. #endif
  32. #ifdef CONFIG_SYS_INIT_CHAN2
  33. NS16550_reinit (COM_PORTS[1], clock_divisor);
  34. #endif
  35. return (0);
  36. }
  37. static void marvell_serial_putc(const char c)
  38. {
  39. if (c == '\n')
  40. mpsc_putchar ('\r');
  41. mpsc_putchar (c);
  42. }
  43. static int marvell_serial_getc(void)
  44. {
  45. return mpsc_getchar ();
  46. }
  47. static int marvell_serial_tstc(void)
  48. {
  49. return mpsc_test_char ();
  50. }
  51. static void marvell_serial_setbrg(void)
  52. {
  53. galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
  54. }
  55. #else /* ! CONFIG_MPSC */
  56. static int marvell_serial_init(void)
  57. {
  58. int clock_divisor = 230400 / gd->baudrate;
  59. #ifdef CONFIG_SYS_INIT_CHAN1
  60. (void) NS16550_init (0, clock_divisor);
  61. #endif
  62. #ifdef CONFIG_SYS_INIT_CHAN2
  63. (void) NS16550_init (1, clock_divisor);
  64. #endif
  65. return (0);
  66. }
  67. static void marvell_serial_putc(const char c)
  68. {
  69. if (c == '\n')
  70. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
  71. NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
  72. }
  73. static int marvell_serial_getc(void)
  74. {
  75. return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  76. }
  77. static int marvell_serial_tstc(void)
  78. {
  79. return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
  80. }
  81. static void marvell_serial_setbrg(void)
  82. {
  83. int clock_divisor = 230400 / gd->baudrate;
  84. #ifdef CONFIG_SYS_INIT_CHAN1
  85. NS16550_reinit (COM_PORTS[0], clock_divisor);
  86. #endif
  87. #ifdef CONFIG_SYS_INIT_CHAN2
  88. NS16550_reinit (COM_PORTS[1], clock_divisor);
  89. #endif
  90. }
  91. #endif /* CONFIG_MPSC */
  92. static struct serial_device marvell_serial_drv = {
  93. .name = "marvell_serial",
  94. .start = marvell_serial_init,
  95. .stop = NULL,
  96. .setbrg = marvell_serial_setbrg,
  97. .putc = marvell_serial_putc,
  98. .puts = default_serial_puts,
  99. .getc = marvell_serial_getc,
  100. .tstc = marvell_serial_tstc,
  101. };
  102. void marvell_serial_initialize(void)
  103. {
  104. serial_register(&marvell_serial_drv);
  105. }
  106. __weak struct serial_device *default_serial_console(void)
  107. {
  108. return &marvell_serial_drv;
  109. }
  110. #if defined(CONFIG_CMD_KGDB)
  111. void kgdb_serial_init (void)
  112. {
  113. }
  114. void putDebugChar (int c)
  115. {
  116. serial_putc (c);
  117. }
  118. void putDebugStr (const char *str)
  119. {
  120. serial_puts (str);
  121. }
  122. int getDebugChar (void)
  123. {
  124. return serial_getc ();
  125. }
  126. void kgdb_interruptible (int yes)
  127. {
  128. return;
  129. }
  130. #endif