serial_scc.c 7.4 KB

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