serial_scc.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. #if defined(CONFIG_CPM2)
  36. #if defined(CONFIG_CONS_ON_SCC)
  37. #if CONFIG_CONS_INDEX == 1 /* Console on SCC1 */
  38. #define SCC_INDEX 0
  39. #define PROFF_SCC PROFF_SCC1
  40. #define CMXSCR_MASK (CMXSCR_GR1|CMXSCR_SC1|\
  41. CMXSCR_RS1CS_MSK|CMXSCR_TS1CS_MSK)
  42. #define CMXSCR_VALUE (CMXSCR_RS1CS_BRG1|CMXSCR_TS1CS_BRG1)
  43. #define CPM_CR_SCC_PAGE CPM_CR_SCC1_PAGE
  44. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC1_SBLOCK
  45. #elif CONFIG_CONS_INDEX == 2 /* Console on SCC2 */
  46. #define SCC_INDEX 1
  47. #define PROFF_SCC PROFF_SCC2
  48. #define CMXSCR_MASK (CMXSCR_GR2|CMXSCR_SC2|\
  49. CMXSCR_RS2CS_MSK|CMXSCR_TS2CS_MSK)
  50. #define CMXSCR_VALUE (CMXSCR_RS2CS_BRG2|CMXSCR_TS2CS_BRG2)
  51. #define CPM_CR_SCC_PAGE CPM_CR_SCC2_PAGE
  52. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC2_SBLOCK
  53. #elif CONFIG_CONS_INDEX == 3 /* Console on SCC3 */
  54. #define SCC_INDEX 2
  55. #define PROFF_SCC PROFF_SCC3
  56. #define CMXSCR_MASK (CMXSCR_GR3|CMXSCR_SC3|\
  57. CMXSCR_RS3CS_MSK|CMXSCR_TS3CS_MSK)
  58. #define CMXSCR_VALUE (CMXSCR_RS3CS_BRG3|CMXSCR_TS3CS_BRG3)
  59. #define CPM_CR_SCC_PAGE CPM_CR_SCC3_PAGE
  60. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC3_SBLOCK
  61. #elif CONFIG_CONS_INDEX == 4 /* Console on SCC4 */
  62. #define SCC_INDEX 3
  63. #define PROFF_SCC PROFF_SCC4
  64. #define CMXSCR_MASK (CMXSCR_GR4|CMXSCR_SC4|\
  65. CMXSCR_RS4CS_MSK|CMXSCR_TS4CS_MSK)
  66. #define CMXSCR_VALUE (CMXSCR_RS4CS_BRG4|CMXSCR_TS4CS_BRG4)
  67. #define CPM_CR_SCC_PAGE CPM_CR_SCC4_PAGE
  68. #define CPM_CR_SCC_SBLOCK CPM_CR_SCC4_SBLOCK
  69. #else
  70. #error "console not correctly defined"
  71. #endif
  72. int serial_init (void)
  73. {
  74. volatile immap_t *im = (immap_t *)CFG_IMMR;
  75. volatile ccsr_cpm_scc_t *sp;
  76. volatile scc_uart_t *up;
  77. volatile cbd_t *tbdf, *rbdf;
  78. volatile ccsr_cpm_cp_t *cp = &(im->im_cpm.im_cpm_cp);
  79. uint dpaddr;
  80. /* initialize pointers to SCC */
  81. sp = (ccsr_cpm_scc_t *) &(im->im_cpm.im_cpm_scc[SCC_INDEX]);
  82. up = (scc_uart_t *)&(im->im_cpm.im_dprambase[PROFF_SCC]);
  83. /* Disable transmitter/receiver.
  84. */
  85. sp->gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  86. /* put the SCC channel into NMSI (non multiplexd serial interface)
  87. * mode and wire the selected SCC Tx and Rx clocks to BRGx (15-15).
  88. */
  89. im->im_cpm.im_cpm_mux.cmxscr = \
  90. (im->im_cpm.im_cpm_mux.cmxscr&~CMXSCR_MASK)|CMXSCR_VALUE;
  91. /* Set up the baud rate generator.
  92. */
  93. serial_setbrg ();
  94. /* Allocate space for two buffer descriptors in the DP ram.
  95. * damm: allocating space after the two buffers for rx/tx data
  96. */
  97. dpaddr = m8560_cpm_dpalloc((2 * sizeof (cbd_t)) + 2, 16);
  98. /* Set the physical address of the host memory buffers in
  99. * the buffer descriptors.
  100. */
  101. rbdf = (cbd_t *)&(im->im_cpm.im_dprambase[dpaddr]);
  102. rbdf->cbd_bufaddr = (uint) (rbdf+2);
  103. rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
  104. tbdf = rbdf + 1;
  105. tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
  106. tbdf->cbd_sc = BD_SC_WRAP;
  107. /* Set up the uart parameters in the parameter ram.
  108. */
  109. up->scc_genscc.scc_rbase = dpaddr;
  110. up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
  111. up->scc_genscc.scc_rfcr = CPMFCR_EB;
  112. up->scc_genscc.scc_tfcr = CPMFCR_EB;
  113. up->scc_genscc.scc_mrblr = 1;
  114. up->scc_maxidl = 0;
  115. up->scc_brkcr = 1;
  116. up->scc_parec = 0;
  117. up->scc_frmec = 0;
  118. up->scc_nosec = 0;
  119. up->scc_brkec = 0;
  120. up->scc_uaddr1 = 0;
  121. up->scc_uaddr2 = 0;
  122. up->scc_toseq = 0;
  123. up->scc_char1 = up->scc_char2 = up->scc_char3 = up->scc_char4 = 0x8000;
  124. up->scc_char5 = up->scc_char6 = up->scc_char7 = up->scc_char8 = 0x8000;
  125. up->scc_rccm = 0xc0ff;
  126. /* Mask all interrupts and remove anything pending.
  127. */
  128. sp->sccm = 0;
  129. sp->scce = 0xffff;
  130. /* Set 8 bit FIFO, 16 bit oversampling and UART mode.
  131. */
  132. sp->gsmrh = SCC_GSMRH_RFW; /* 8 bit FIFO */
  133. sp->gsmrl = \
  134. SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16 | SCC_GSMRL_MODE_UART;
  135. /* Set CTS no flow control, 1 stop bit, 8 bit character length,
  136. * normal async UART mode, no parity
  137. */
  138. sp->psmr = SCU_PSMR_CL;
  139. /* execute the "Init Rx and Tx params" CP command.
  140. */
  141. while (cp->cpcr & CPM_CR_FLG) /* wait if cp is busy */
  142. ;
  143. cp->cpcr = mk_cr_cmd(CPM_CR_SCC_PAGE, CPM_CR_SCC_SBLOCK,
  144. 0, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  145. while (cp->cpcr & CPM_CR_FLG) /* wait if cp is busy */
  146. ;
  147. /* Enable transmitter/receiver.
  148. */
  149. sp->gsmrl |= SCC_GSMRL_ENR | SCC_GSMRL_ENT;
  150. return (0);
  151. }
  152. void
  153. serial_setbrg (void)
  154. {
  155. DECLARE_GLOBAL_DATA_PTR;
  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 immap_t *im;
  169. if (c == '\n')
  170. serial_putc ('\r');
  171. im = (immap_t *)CFG_IMMR;
  172. up = (scc_uart_t *)&(im->im_cpm.im_dprambase[PROFF_SCC]);
  173. tbdf = (cbd_t *)&(im->im_cpm.im_dprambase[up->scc_genscc.scc_tbase]);
  174. /* Wait for last character to go.
  175. */
  176. while (tbdf->cbd_sc & BD_SC_READY)
  177. ;
  178. /* Load the character into the transmit buffer.
  179. */
  180. *(volatile char *)tbdf->cbd_bufaddr = c;
  181. tbdf->cbd_datlen = 1;
  182. tbdf->cbd_sc |= BD_SC_READY;
  183. }
  184. void
  185. serial_puts (const char *s)
  186. {
  187. while (*s) {
  188. serial_putc (*s++);
  189. }
  190. }
  191. int
  192. serial_getc(void)
  193. {
  194. volatile cbd_t *rbdf;
  195. volatile scc_uart_t *up;
  196. volatile immap_t *im;
  197. unsigned char c;
  198. im = (immap_t *)CFG_IMMR;
  199. up = (scc_uart_t *)&(im->im_cpm.im_dprambase[PROFF_SCC]);
  200. rbdf = (cbd_t *)&(im->im_cpm.im_dprambase[up->scc_genscc.scc_rbase]);
  201. /* Wait for character to show up.
  202. */
  203. while (rbdf->cbd_sc & BD_SC_EMPTY)
  204. ;
  205. /* Grab the char and clear the buffer again.
  206. */
  207. c = *(volatile unsigned char *)rbdf->cbd_bufaddr;
  208. rbdf->cbd_sc |= BD_SC_EMPTY;
  209. return (c);
  210. }
  211. int
  212. serial_tstc()
  213. {
  214. volatile cbd_t *rbdf;
  215. volatile scc_uart_t *up;
  216. volatile immap_t *im;
  217. im = (immap_t *)CFG_IMMR;
  218. up = (scc_uart_t *)&(im->im_cpm.im_dprambase[PROFF_SCC]);
  219. rbdf = (cbd_t *)&(im->im_cpm.im_dprambase[up->scc_genscc.scc_rbase]);
  220. return ((rbdf->cbd_sc & BD_SC_EMPTY) == 0);
  221. }
  222. #endif /* CONFIG_CONS_ON_SCC */
  223. #endif /* CONFIG_CPM2 */