serial.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * (C) Copyright 2000
  3. * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <serial.h>
  25. #include <linux/compiler.h>
  26. #include "ns16550.h"
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #if CONFIG_CONS_INDEX == 1
  29. static struct NS16550 *console =
  30. (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
  31. #elif CONFIG_CONS_INDEX == 2
  32. static struct NS16550 *console =
  33. (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
  34. #else
  35. #error no valid console defined
  36. #endif
  37. extern ulong get_bus_freq (ulong);
  38. static int bmw_serial_init(void)
  39. {
  40. int clock_divisor = gd->bus_clk / 16 / gd->baudrate;
  41. NS16550_init (CONFIG_CONS_INDEX - 1, clock_divisor);
  42. return (0);
  43. }
  44. static void bmw_serial_putc(const char c)
  45. {
  46. if (c == '\n') {
  47. serial_putc ('\r');
  48. }
  49. NS16550_putc (console, c);
  50. }
  51. static void bmw_serial_puts(const char *s)
  52. {
  53. while (*s) {
  54. serial_putc (*s++);
  55. }
  56. }
  57. static int bmw_serial_getc(void)
  58. {
  59. return NS16550_getc (console);
  60. }
  61. static int bmw_serial_tstc(void)
  62. {
  63. return NS16550_tstc (console);
  64. }
  65. static void bmw_serial_setbrg(void)
  66. {
  67. int clock_divisor = get_bus_freq (0) / 16 / gd->baudrate;
  68. NS16550_reinit (console, clock_divisor);
  69. }
  70. #ifdef CONFIG_SERIAL_MULTI
  71. static struct serial_device bmw_serial_drv = {
  72. .name = "bmw_serial",
  73. .start = bmw_serial_init,
  74. .stop = NULL,
  75. .setbrg = bmw_serial_setbrg,
  76. .putc = bmw_serial_putc,
  77. .puts = bmw_serial_puts,
  78. .getc = bmw_serial_getc,
  79. .tstc = bmw_serial_tstc,
  80. };
  81. void bmw_serial_initialize(void)
  82. {
  83. serial_register(&bmw_serial_drv);
  84. }
  85. __weak struct serial_device *default_serial_console(void)
  86. {
  87. return &bmw_serial_drv;
  88. }
  89. #else
  90. int serial_init(void)
  91. {
  92. return bmw_serial_init();
  93. }
  94. void serial_setbrg(void)
  95. {
  96. bmw_serial_setbrg();
  97. }
  98. void serial_putc(const char c)
  99. {
  100. bmw_serial_putc(c);
  101. }
  102. void serial_puts(const char *s)
  103. {
  104. bmw_serial_puts(s);
  105. }
  106. int serial_getc(void)
  107. {
  108. return bmw_serial_getc();
  109. }
  110. int serial_tstc(void)
  111. {
  112. return bmw_serial_tstc();
  113. }
  114. #endif