uart.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #include <serial.h>
  31. #include <linux/compiler.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #define PSC_BASE MMAP_PSC1
  34. #if defined(CONFIG_PSC_CONSOLE)
  35. static int mpc8220_serial_init(void)
  36. {
  37. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  38. u32 counter;
  39. /* write to SICR: SIM2 = uart mode,dcd does not affect rx */
  40. psc->cr = 0;
  41. psc->ipcr_acr = 0;
  42. psc->isr_imr = 0;
  43. /* write to CSR: RX/TX baud rate from timers */
  44. psc->sr_csr = 0xdd000000;
  45. psc->mr1_2 = PSC_MR1_BITS_CHAR_8 | PSC_MR1_NO_PARITY | PSC_MR2_STOP_BITS_1;
  46. /* Setting up BaudRate */
  47. counter = ((gd->bus_clk / gd->baudrate)) >> 5;
  48. counter++;
  49. /* write to CTUR: divide counter upper byte */
  50. psc->ctur = ((counter & 0xff00) << 16);
  51. /* write to CTLR: divide counter lower byte */
  52. psc->ctlr = ((counter & 0x00ff) << 24);
  53. psc->cr = PSC_CR_RST_RX_CMD;
  54. psc->cr = PSC_CR_RST_TX_CMD;
  55. psc->cr = PSC_CR_RST_ERR_STS_CMD;
  56. psc->cr = PSC_CR_RST_BRK_INT_CMD;
  57. psc->cr = PSC_CR_RST_MR_PTR_CMD;
  58. psc->cr = PSC_CR_RX_ENABLE | PSC_CR_TX_ENABLE;
  59. return (0);
  60. }
  61. static void mpc8220_serial_putc(const char c)
  62. {
  63. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  64. if (c == '\n')
  65. serial_putc ('\r');
  66. /* Wait for last character to go. */
  67. while (!(psc->sr_csr & PSC_SR_TXRDY));
  68. psc->xmitbuf[0] = c;
  69. }
  70. static int mpc8220_serial_getc(void)
  71. {
  72. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  73. /* Wait for a character to arrive. */
  74. while (!(psc->sr_csr & PSC_SR_RXRDY));
  75. return psc->xmitbuf[2];
  76. }
  77. static int mpc8220_serial_tstc(void)
  78. {
  79. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  80. return (psc->sr_csr & PSC_SR_RXRDY);
  81. }
  82. static void mpc8220_serial_setbrg(void)
  83. {
  84. volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
  85. u32 counter;
  86. counter = ((gd->bus_clk / gd->baudrate)) >> 5;
  87. counter++;
  88. /* write to CTUR: divide counter upper byte */
  89. psc->ctur = ((counter & 0xff00) << 16);
  90. /* write to CTLR: divide counter lower byte */
  91. psc->ctlr = ((counter & 0x00ff) << 24);
  92. psc->cr = PSC_CR_RST_RX_CMD;
  93. psc->cr = PSC_CR_RST_TX_CMD;
  94. psc->cr = PSC_CR_RX_ENABLE | PSC_CR_TX_ENABLE;
  95. }
  96. static struct serial_device mpc8220_serial_drv = {
  97. .name = "mpc8220_serial",
  98. .start = mpc8220_serial_init,
  99. .stop = NULL,
  100. .setbrg = mpc8220_serial_setbrg,
  101. .putc = mpc8220_serial_putc,
  102. .puts = default_serial_puts,
  103. .getc = mpc8220_serial_getc,
  104. .tstc = mpc8220_serial_tstc,
  105. };
  106. void mpc8220_serial_initialize(void)
  107. {
  108. serial_register(&mpc8220_serial_drv);
  109. }
  110. __weak struct serial_device *default_serial_console(void)
  111. {
  112. return &mpc8220_serial_drv;
  113. }
  114. #endif /* CONFIG_PSC_CONSOLE */