serial.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. int serial_init (void)
  31. {
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #if defined (CONFIG_EXTUART_CONSOLE)
  34. volatile uchar *cpld = (volatile uchar *) CFG_CPLD_BASE;
  35. #endif
  36. /* Check CPLD Switch 2 whether is external or internal */
  37. #if defined (CONFIG_EXTUART_CONSOLE)
  38. if ((*cpld & 0x02) == 0x02) {
  39. gd->bExtUart = 1;
  40. return ext_serial_init ();
  41. } else
  42. #endif
  43. {
  44. #if defined(CONFIG_PSC_CONSOLE)
  45. gd->bExtUart = 0;
  46. return psc_serial_init ();
  47. #endif
  48. }
  49. return (0);
  50. }
  51. void serial_putc (const char c)
  52. {
  53. DECLARE_GLOBAL_DATA_PTR;
  54. if (gd->bExtUart) {
  55. #if defined (CONFIG_EXTUART_CONSOLE)
  56. ext_serial_putc (c);
  57. #endif
  58. } else {
  59. #if defined(CONFIG_PSC_CONSOLE)
  60. psc_serial_putc (c);
  61. #endif
  62. }
  63. }
  64. void serial_puts (const char *s)
  65. {
  66. DECLARE_GLOBAL_DATA_PTR;
  67. if (gd->bExtUart) {
  68. #if defined (CONFIG_EXTUART_CONSOLE)
  69. ext_serial_puts (s);
  70. #endif
  71. } else {
  72. #if defined(CONFIG_PSC_CONSOLE)
  73. psc_serial_puts (s);
  74. #endif
  75. }
  76. }
  77. int serial_getc (void)
  78. {
  79. DECLARE_GLOBAL_DATA_PTR;
  80. if (gd->bExtUart) {
  81. #if defined (CONFIG_EXTUART_CONSOLE)
  82. return ext_serial_getc ();
  83. #endif
  84. } else {
  85. #if defined(CONFIG_PSC_CONSOLE)
  86. return psc_serial_getc ();
  87. #endif
  88. }
  89. }
  90. int serial_tstc (void)
  91. {
  92. DECLARE_GLOBAL_DATA_PTR;
  93. if (gd->bExtUart) {
  94. #if defined (CONFIG_EXTUART_CONSOLE)
  95. return ext_serial_tstc ();
  96. #endif
  97. } else {
  98. #if defined(CONFIG_PSC_CONSOLE)
  99. return psc_serial_tstc ();
  100. #endif
  101. }
  102. }
  103. void serial_setbrg (void)
  104. {
  105. DECLARE_GLOBAL_DATA_PTR;
  106. if (gd->bExtUart) {
  107. #if defined (CONFIG_EXTUART_CONSOLE)
  108. ext_serial_setbrg ();
  109. #endif
  110. } else {
  111. #if defined(CONFIG_PSC_CONSOLE)
  112. psc_serial_setbrg ();
  113. #endif
  114. }
  115. }