extserial.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * (C) Copyright 2004, Freescale, Inc
  3. * TsiChung Liew, Tsi-Chung.Liew@freescale.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. */
  24. /*
  25. * Minimal serial functions needed to use one of the PSC ports
  26. * as serial console interface.
  27. */
  28. #include <common.h>
  29. #include <mpc8220.h>
  30. #if defined (CONFIG_EXTUART_CONSOLE)
  31. # include <ns16550.h>
  32. # define PADSERIAL_BAUD_115200 0x40
  33. # define PADSERIAL_BAUD_57600 0x20
  34. # define PADSERIAL_BAUD_9600 0
  35. # define PADCARD_FREQ 18432000
  36. const NS16550_t com_port = (NS16550_t) CFG_NS16550_COM1;
  37. int ext_serial_init (void)
  38. {
  39. DECLARE_GLOBAL_DATA_PTR;
  40. volatile u8 *dipswitch = (volatile u8 *) (CFG_CPLD_BASE + 0x1002);
  41. int baud_divisor;
  42. /* Find out the baud rate speed on debug card dip switches */
  43. if (*dipswitch & PADSERIAL_BAUD_115200)
  44. gd->baudrate = 115200;
  45. else if (*dipswitch & PADSERIAL_BAUD_57600)
  46. gd->baudrate = 57600;
  47. else
  48. gd->baudrate = 9600;
  49. /* Debug card frequency */
  50. baud_divisor = PADCARD_FREQ / (16 * gd->baudrate);
  51. NS16550_init (com_port, baud_divisor);
  52. return (0);
  53. }
  54. void ext_serial_putc (const char c)
  55. {
  56. if (c == '\n')
  57. NS16550_putc (com_port, '\r');
  58. NS16550_putc (com_port, c);
  59. }
  60. void ext_serial_puts (const char *s)
  61. {
  62. while (*s) {
  63. serial_putc (*s++);
  64. }
  65. }
  66. int ext_serial_getc (void)
  67. {
  68. return NS16550_getc (com_port);
  69. }
  70. int ext_serial_tstc (void)
  71. {
  72. return NS16550_tstc (com_port);
  73. }
  74. void ext_serial_setbrg (void)
  75. {
  76. DECLARE_GLOBAL_DATA_PTR;
  77. volatile u8 *dipswitch = (volatile u8 *) (CFG_CPLD_BASE + 0x1002);
  78. int baud_divisor;
  79. /* Find out the baud rate speed on debug card dip switches */
  80. if (*dipswitch & PADSERIAL_BAUD_115200)
  81. gd->baudrate = 115200;
  82. else if (*dipswitch & PADSERIAL_BAUD_57600)
  83. gd->baudrate = 57600;
  84. else
  85. gd->baudrate = 9600;
  86. /* Debug card frequency */
  87. baud_divisor = PADCARD_FREQ / (16 * gd->baudrate);
  88. NS16550_reinit (com_port, baud_divisor);
  89. }
  90. #endif /* CONFIG_EXTUART_CONSOLE */