uart.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #define PSC_BASE MMAP_PSC1
  31. #if defined(CONFIG_PSC_CONSOLE)
  32. int psc_serial_init (void)
  33. {
  34. DECLARE_GLOBAL_DATA_PTR;
  35. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  36. u32 counter;
  37. /* write to SICR: SIM2 = uart mode,dcd does not affect rx */
  38. psc->cr = 0;
  39. psc->ipcr_acr = 0;
  40. psc->isr_imr = 0;
  41. /* write to CSR: RX/TX baud rate from timers */
  42. psc->sr_csr = 0xdd000000;
  43. psc->mr1_2 = PSC_MR1_BITS_CHAR_8 | PSC_MR1_NO_PARITY | PSC_MR1_RX_RTS;
  44. psc->mr1_2 = PSC_MR2_STOP_BITS_1 | PSC_MR2_TX_CTS;
  45. /* Setting up BaudRate */
  46. counter = ((gd->bus_clk / gd->baudrate)) >> 5;
  47. counter++;
  48. /* write to CTUR: divide counter upper byte */
  49. psc->ctur = ((counter & 0xff00) << 16);
  50. /* write to CTLR: divide counter lower byte */
  51. psc->ctlr = ((counter & 0x00ff) << 24);
  52. psc->cr = PSC_CR_RST_RX_CMD;
  53. psc->cr = PSC_CR_RST_TX_CMD;
  54. psc->cr = PSC_CR_RST_ERR_STS_CMD;
  55. psc->cr = PSC_CR_RST_BRK_INT_CMD;
  56. psc->cr = PSC_CR_RST_MR_PTR_CMD;
  57. psc->cr = PSC_CR_RX_ENABLE | PSC_CR_TX_ENABLE;
  58. return (0);
  59. }
  60. void psc_serial_putc (const char c)
  61. {
  62. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  63. if (c == '\n')
  64. serial_putc ('\r');
  65. /* Wait for last character to go. */
  66. while (!(psc->sr_csr & PSC_SR_TXEMT));
  67. psc->xmitbuf[0] = c;
  68. }
  69. void psc_serial_puts (const char *s)
  70. {
  71. while (*s) {
  72. serial_putc (*s++);
  73. }
  74. }
  75. int psc_serial_getc (void)
  76. {
  77. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  78. /* Wait for a character to arrive. */
  79. while (!(psc->sr_csr & PSC_SR_RXRDY));
  80. return psc->xmitbuf[2];
  81. }
  82. int psc_serial_tstc (void)
  83. {
  84. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  85. return (psc->sr_csr & PSC_SR_RXRDY);
  86. }
  87. void psc_serial_setbrg (void)
  88. {
  89. DECLARE_GLOBAL_DATA_PTR;
  90. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  91. u32 counter;
  92. counter = ((gd->bus_clk / gd->baudrate)) >> 5;
  93. counter++;
  94. /* write to CTUR: divide counter upper byte */
  95. psc->ctur = ((counter & 0xff00) << 16);
  96. /* write to CTLR: divide counter lower byte */
  97. psc->ctlr = ((counter & 0x00ff) << 24);
  98. psc->cr = PSC_CR_RST_RX_CMD;
  99. psc->cr = PSC_CR_RST_TX_CMD;
  100. psc->cr = PSC_CR_RX_ENABLE | PSC_CR_TX_ENABLE;
  101. }
  102. #endif /* CONFIG_PSC_CONSOLE */