serial.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. static struct serial_device bmw_serial_drv = {
  71. .name = "bmw_serial",
  72. .start = bmw_serial_init,
  73. .stop = NULL,
  74. .setbrg = bmw_serial_setbrg,
  75. .putc = bmw_serial_putc,
  76. .puts = bmw_serial_puts,
  77. .getc = bmw_serial_getc,
  78. .tstc = bmw_serial_tstc,
  79. };
  80. void bmw_serial_initialize(void)
  81. {
  82. serial_register(&bmw_serial_drv);
  83. }
  84. __weak struct serial_device *default_serial_console(void)
  85. {
  86. return &bmw_serial_drv;
  87. }