serial.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "ns16550.h"
  25. #if CONFIG_CONS_INDEX == 1
  26. static struct NS16550 *console =
  27. (struct NS16550 *) (CFG_EUMB_ADDR + 0x4500);
  28. #elif CONFIG_CONS_INDEX == 2
  29. static struct NS16550 *console =
  30. (struct NS16550 *) (CFG_EUMB_ADDR + 0x4500);
  31. #else
  32. #error no valid console defined
  33. #endif
  34. extern ulong get_bus_freq (ulong);
  35. int serial_init (void)
  36. {
  37. DECLARE_GLOBAL_DATA_PTR;
  38. int clock_divisor = gd->bus_clk / 16 / gd->baudrate;
  39. NS16550_init (CONFIG_CONS_INDEX - 1, clock_divisor);
  40. return (0);
  41. }
  42. void serial_putc (const char c)
  43. {
  44. if (c == '\n') {
  45. serial_putc ('\r');
  46. }
  47. NS16550_putc (console, c);
  48. }
  49. void serial_puts (const char *s)
  50. {
  51. while (*s) {
  52. serial_putc (*s++);
  53. }
  54. }
  55. int serial_getc (void)
  56. {
  57. return NS16550_getc (console);
  58. }
  59. int serial_tstc (void)
  60. {
  61. return NS16550_tstc (console);
  62. }
  63. void serial_setbrg (void)
  64. {
  65. DECLARE_GLOBAL_DATA_PTR;
  66. int clock_divisor = get_bus_freq (0) / 16 / gd->baudrate;
  67. NS16550_reinit (console, clock_divisor);
  68. }