serial_scc.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * (C) Copyright 2003 Motorola Inc.
  3. * Xianghua Xiao (X.Xiao@motorola.com)
  4. * Modified based on 8260 for 8560.
  5. *
  6. * (C) Copyright 2000
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. *
  27. * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 19-Oct-00.
  28. */
  29. /*
  30. * Minimal serial functions needed to use one of the SCC ports
  31. * as serial console interface.
  32. */
  33. #include <common.h>
  34. #include <asm/cpm_85xx.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #if defined(CONFIG_CPM2)
  37. #if defined(CONFIG_CONS_ON_SCC)
  38. #if CONFIG_CONS_INDEX == 1 /* Console on SCC1 */
  39. #define SCC_INDEX 0
  40. #define PROFF_SCC PROFF_SCC1
  41. #define CMXSCR_MASK (CMXSCR_GR1|CMXSCR_SC1|\
  42. CMXSCR_RS1CS_MSK|CMXSCR_TS1CS_MSK)
  43. #define CMXSCR_VALUE (CMXSCR_RS1CS_BRG1|CMXSCR_TS1CS_BRG1)
  44. #define CPM_CR_SCC_PAGE CPM_CR_SCC1_PAGE
  45. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC1_SBLOCK
  46. #elif CONFIG_CONS_INDEX == 2 /* Console on SCC2 */
  47. #define SCC_INDEX 1
  48. #define PROFF_SCC PROFF_SCC2
  49. #define CMXSCR_MASK (CMXSCR_GR2|CMXSCR_SC2|\
  50. CMXSCR_RS2CS_MSK|CMXSCR_TS2CS_MSK)
  51. #define CMXSCR_VALUE (CMXSCR_RS2CS_BRG2|CMXSCR_TS2CS_BRG2)
  52. #define CPM_CR_SCC_PAGE CPM_CR_SCC2_PAGE
  53. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC2_SBLOCK
  54. #elif CONFIG_CONS_INDEX == 3 /* Console on SCC3 */
  55. #define SCC_INDEX 2
  56. #define PROFF_SCC PROFF_SCC3
  57. #define CMXSCR_MASK (CMXSCR_GR3|CMXSCR_SC3|\
  58. CMXSCR_RS3CS_MSK|CMXSCR_TS3CS_MSK)
  59. #define CMXSCR_VALUE (CMXSCR_RS3CS_BRG3|CMXSCR_TS3CS_BRG3)
  60. #define CPM_CR_SCC_PAGE CPM_CR_SCC3_PAGE
  61. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC3_SBLOCK
  62. #elif CONFIG_CONS_INDEX == 4 /* Console on SCC4 */
  63. #define SCC_INDEX 3
  64. #define PROFF_SCC PROFF_SCC4
  65. #define CMXSCR_MASK (CMXSCR_GR4|CMXSCR_SC4|\
  66. CMXSCR_RS4CS_MSK|CMXSCR_TS4CS_MSK)
  67. #define CMXSCR_VALUE (CMXSCR_RS4CS_BRG4|CMXSCR_TS4CS_BRG4)
  68. #define CPM_CR_SCC_PAGE CPM_CR_SCC4_PAGE
  69. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC4_SBLOCK
  70. #else
  71. #error "console not correctly defined"
  72. #endif
  73. int serial_init (void)
  74. {
  75. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  76. volatile ccsr_cpm_scc_t *sp;
  77. volatile scc_uart_t *up;
  78. volatile cbd_t *tbdf, *rbdf;
  79. volatile ccsr_cpm_cp_t *cp = &(cpm->im_cpm_cp);
  80. uint dpaddr;
  81. /* initialize pointers to SCC */
  82. sp = (ccsr_cpm_scc_t *) &(cpm->im_cpm_scc[SCC_INDEX]);
  83. up = (scc_uart_t *)&(cpm->im_dprambase[PROFF_SCC]);
  84. /* Disable transmitter/receiver.
  85. */
  86. sp->gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  87. /* put the SCC channel into NMSI (non multiplexd serial interface)
  88. * mode and wire the selected SCC Tx and Rx clocks to BRGx (15-15).
  89. */
  90. cpm->im_cpm_mux.cmxscr = \
  91. (cpm->im_cpm_mux.cmxscr&~CMXSCR_MASK)|CMXSCR_VALUE;
  92. /* Set up the baud rate generator.
  93. */
  94. serial_setbrg ();
  95. /* Allocate space for two buffer descriptors in the DP ram.
  96. * damm: allocating space after the two buffers for rx/tx data
  97. */
  98. dpaddr = m8560_cpm_dpalloc((2 * sizeof (cbd_t)) + 2, 16);
  99. /* Set the physical address of the host memory buffers in
  100. * the buffer descriptors.
  101. */
  102. rbdf = (cbd_t *)&(cpm->im_dprambase[dpaddr]);
  103. rbdf->cbd_bufaddr = (uint) (rbdf+2);
  104. rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
  105. tbdf = rbdf + 1;
  106. tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
  107. tbdf->cbd_sc = BD_SC_WRAP;
  108. /* Set up the uart parameters in the parameter ram.
  109. */
  110. up->scc_genscc.scc_rbase = dpaddr;
  111. up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
  112. up->scc_genscc.scc_rfcr = CPMFCR_EB;
  113. up->scc_genscc.scc_tfcr = CPMFCR_EB;
  114. up->scc_genscc.scc_mrblr = 1;
  115. up->scc_maxidl = 0;
  116. up->scc_brkcr = 1;
  117. up->scc_parec = 0;
  118. up->scc_frmec = 0;
  119. up->scc_nosec = 0;
  120. up->scc_brkec = 0;
  121. up->scc_uaddr1 = 0;
  122. up->scc_uaddr2 = 0;
  123. up->scc_toseq = 0;
  124. up->scc_char1 = up->scc_char2 = up->scc_char3 = up->scc_char4 = 0x8000;
  125. up->scc_char5 = up->scc_char6 = up->scc_char7 = up->scc_char8 = 0x8000;
  126. up->scc_rccm = 0xc0ff;
  127. /* Mask all interrupts and remove anything pending.
  128. */
  129. sp->sccm = 0;
  130. sp->scce = 0xffff;
  131. /* Set 8 bit FIFO, 16 bit oversampling and UART mode.
  132. */
  133. sp->gsmrh = SCC_GSMRH_RFW; /* 8 bit FIFO */
  134. sp->gsmrl = \
  135. SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16 | SCC_GSMRL_MODE_UART;
  136. /* Set CTS no flow control, 1 stop bit, 8 bit character length,
  137. * normal async UART mode, no parity
  138. */
  139. sp->psmr = SCU_PSMR_CL;
  140. /* execute the "Init Rx and Tx params" CP command.
  141. */
  142. while (cp->cpcr & CPM_CR_FLG) /* wait if cp is busy */
  143. ;
  144. cp->cpcr = mk_cr_cmd(CPM_CR_SCC_PAGE, CPM_CR_SCC_SBLOCK,
  145. 0, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  146. while (cp->cpcr & CPM_CR_FLG) /* wait if cp is busy */
  147. ;
  148. /* Enable transmitter/receiver.
  149. */
  150. sp->gsmrl |= SCC_GSMRL_ENR | SCC_GSMRL_ENT;
  151. return (0);
  152. }
  153. void
  154. serial_setbrg (void)
  155. {
  156. #if defined(CONFIG_CONS_USE_EXTC)
  157. m8560_cpm_extcbrg(SCC_INDEX, gd->baudrate,
  158. CONFIG_CONS_EXTC_RATE, CONFIG_CONS_EXTC_PINSEL);
  159. #else
  160. m8560_cpm_setbrg(SCC_INDEX, gd->baudrate);
  161. #endif
  162. }
  163. void
  164. serial_putc(const char c)
  165. {
  166. volatile scc_uart_t *up;
  167. volatile cbd_t *tbdf;
  168. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  169. if (c == '\n')
  170. serial_putc ('\r');
  171. up = (scc_uart_t *)&(cpm->im_dprambase[PROFF_SCC]);
  172. tbdf = (cbd_t *)&(cpm->im_dprambase[up->scc_genscc.scc_tbase]);
  173. /* Wait for last character to go.
  174. */
  175. while (tbdf->cbd_sc & BD_SC_READY)
  176. ;
  177. /* Load the character into the transmit buffer.
  178. */
  179. *(volatile char *)tbdf->cbd_bufaddr = c;
  180. tbdf->cbd_datlen = 1;
  181. tbdf->cbd_sc |= BD_SC_READY;
  182. }
  183. void
  184. serial_puts (const char *s)
  185. {
  186. while (*s) {
  187. serial_putc (*s++);
  188. }
  189. }
  190. int
  191. serial_getc(void)
  192. {
  193. volatile cbd_t *rbdf;
  194. volatile scc_uart_t *up;
  195. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  196. unsigned char c;
  197. up = (scc_uart_t *)&(cpm->im_dprambase[PROFF_SCC]);
  198. rbdf = (cbd_t *)&(cpm->im_dprambase[up->scc_genscc.scc_rbase]);
  199. /* Wait for character to show up.
  200. */
  201. while (rbdf->cbd_sc & BD_SC_EMPTY)
  202. ;
  203. /* Grab the char and clear the buffer again.
  204. */
  205. c = *(volatile unsigned char *)rbdf->cbd_bufaddr;
  206. rbdf->cbd_sc |= BD_SC_EMPTY;
  207. return (c);
  208. }
  209. int
  210. serial_tstc()
  211. {
  212. volatile cbd_t *rbdf;
  213. volatile scc_uart_t *up;
  214. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  215. up = (scc_uart_t *)&(cpm->im_dprambase[PROFF_SCC]);
  216. rbdf = (cbd_t *)&(cpm->im_dprambase[up->scc_genscc.scc_rbase]);
  217. return ((rbdf->cbd_sc & BD_SC_EMPTY) == 0);
  218. }
  219. #endif /* CONFIG_CONS_ON_SCC */
  220. #endif /* CONFIG_CPM2 */