serial.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <commproc.h>
  9. #include <command.h>
  10. #include <serial.h>
  11. #include <watchdog.h>
  12. #include <linux/compiler.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. #if !defined(CONFIG_8xx_CONS_NONE) /* No Console at all */
  15. #if defined(CONFIG_8xx_CONS_SMC1) /* Console on SMC1 */
  16. #define SMC_INDEX 0
  17. #define PROFF_SMC PROFF_SMC1
  18. #define CPM_CR_CH_SMC CPM_CR_CH_SMC1
  19. #elif defined(CONFIG_8xx_CONS_SMC2) /* Console on SMC2 */
  20. #define SMC_INDEX 1
  21. #define PROFF_SMC PROFF_SMC2
  22. #define CPM_CR_CH_SMC CPM_CR_CH_SMC2
  23. #endif /* CONFIG_8xx_CONS_SMCx */
  24. #if defined(CONFIG_8xx_CONS_SCC1) /* Console on SCC1 */
  25. #define SCC_INDEX 0
  26. #define PROFF_SCC PROFF_SCC1
  27. #define CPM_CR_CH_SCC CPM_CR_CH_SCC1
  28. #elif defined(CONFIG_8xx_CONS_SCC2) /* Console on SCC2 */
  29. #define SCC_INDEX 1
  30. #define PROFF_SCC PROFF_SCC2
  31. #define CPM_CR_CH_SCC CPM_CR_CH_SCC2
  32. #elif defined(CONFIG_8xx_CONS_SCC3) /* Console on SCC3 */
  33. #define SCC_INDEX 2
  34. #define PROFF_SCC PROFF_SCC3
  35. #define CPM_CR_CH_SCC CPM_CR_CH_SCC3
  36. #elif defined(CONFIG_8xx_CONS_SCC4) /* Console on SCC4 */
  37. #define SCC_INDEX 3
  38. #define PROFF_SCC PROFF_SCC4
  39. #define CPM_CR_CH_SCC CPM_CR_CH_SCC4
  40. #endif /* CONFIG_8xx_CONS_SCCx */
  41. #if !defined(CONFIG_SYS_SMC_RXBUFLEN)
  42. #define CONFIG_SYS_SMC_RXBUFLEN 1
  43. #define CONFIG_SYS_MAXIDLE 0
  44. #else
  45. #if !defined(CONFIG_SYS_MAXIDLE)
  46. #error "you must define CONFIG_SYS_MAXIDLE"
  47. #endif
  48. #endif
  49. typedef volatile struct serialbuffer {
  50. cbd_t rxbd; /* Rx BD */
  51. cbd_t txbd; /* Tx BD */
  52. uint rxindex; /* index for next character to read */
  53. volatile uchar rxbuf[CONFIG_SYS_SMC_RXBUFLEN];/* rx buffers */
  54. volatile uchar txbuf; /* tx buffers */
  55. } serialbuffer_t;
  56. static void serial_setdivisor(volatile cpm8xx_t *cp)
  57. {
  58. int divisor=(gd->cpu_clk + 8*gd->baudrate)/16/gd->baudrate;
  59. if(divisor/16>0x1000) {
  60. /* bad divisor, assume 50MHz clock and 9600 baud */
  61. divisor=(50*1000*1000 + 8*9600)/16/9600;
  62. }
  63. #ifdef CONFIG_SYS_BRGCLK_PRESCALE
  64. divisor /= CONFIG_SYS_BRGCLK_PRESCALE;
  65. #endif
  66. if(divisor<=0x1000) {
  67. cp->cp_brgc1=((divisor-1)<<1) | CPM_BRG_EN;
  68. } else {
  69. cp->cp_brgc1=((divisor/16-1)<<1) | CPM_BRG_EN | CPM_BRG_DIV16;
  70. }
  71. }
  72. #if (defined (CONFIG_8xx_CONS_SMC1) || defined (CONFIG_8xx_CONS_SMC2))
  73. /*
  74. * Minimal serial functions needed to use one of the SMC ports
  75. * as serial console interface.
  76. */
  77. static void smc_setbrg (void)
  78. {
  79. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  80. volatile cpm8xx_t *cp = &(im->im_cpm);
  81. /* Set up the baud rate generator.
  82. * See 8xx_io/commproc.c for details.
  83. *
  84. * Wire BRG1 to SMCx
  85. */
  86. cp->cp_simode = 0x00000000;
  87. serial_setdivisor(cp);
  88. }
  89. static int smc_init (void)
  90. {
  91. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  92. volatile smc_t *sp;
  93. volatile smc_uart_t *up;
  94. volatile cpm8xx_t *cp = &(im->im_cpm);
  95. #if (!defined(CONFIG_8xx_CONS_SMC1)) && (defined(CONFIG_MPC823) || defined(CONFIG_MPC850))
  96. volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
  97. #endif
  98. uint dpaddr;
  99. volatile serialbuffer_t *rtx;
  100. /* initialize pointers to SMC */
  101. sp = (smc_t *) &(cp->cp_smc[SMC_INDEX]);
  102. up = (smc_uart_t *) &cp->cp_dparam[PROFF_SMC];
  103. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  104. up = (smc_uart_t *) &cp->cp_dpmem[up->smc_rpbase];
  105. #else
  106. /* Disable relocation */
  107. up->smc_rpbase = 0;
  108. #endif
  109. /* Disable transmitter/receiver. */
  110. sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  111. /* Enable SDMA. */
  112. im->im_siu_conf.sc_sdcr = 1;
  113. /* clear error conditions */
  114. #ifdef CONFIG_SYS_SDSR
  115. im->im_sdma.sdma_sdsr = CONFIG_SYS_SDSR;
  116. #else
  117. im->im_sdma.sdma_sdsr = 0x83;
  118. #endif
  119. /* clear SDMA interrupt mask */
  120. #ifdef CONFIG_SYS_SDMR
  121. im->im_sdma.sdma_sdmr = CONFIG_SYS_SDMR;
  122. #else
  123. im->im_sdma.sdma_sdmr = 0x00;
  124. #endif
  125. #if defined(CONFIG_8xx_CONS_SMC1)
  126. /* Use Port B for SMC1 instead of other functions. */
  127. cp->cp_pbpar |= 0x000000c0;
  128. cp->cp_pbdir &= ~0x000000c0;
  129. cp->cp_pbodr &= ~0x000000c0;
  130. #else /* CONFIG_8xx_CONS_SMC2 */
  131. # if defined(CONFIG_MPC823) || defined(CONFIG_MPC850)
  132. /* Use Port A for SMC2 instead of other functions. */
  133. ip->iop_papar |= 0x00c0;
  134. ip->iop_padir &= ~0x00c0;
  135. ip->iop_paodr &= ~0x00c0;
  136. # else /* must be a 860 then */
  137. /* Use Port B for SMC2 instead of other functions.
  138. */
  139. cp->cp_pbpar |= 0x00000c00;
  140. cp->cp_pbdir &= ~0x00000c00;
  141. cp->cp_pbodr &= ~0x00000c00;
  142. # endif
  143. #endif
  144. #if defined(CONFIG_FADS) || defined(CONFIG_ADS)
  145. /* Enable RS232 */
  146. #if defined(CONFIG_8xx_CONS_SMC1)
  147. *((uint *) BCSR1) &= ~BCSR1_RS232EN_1;
  148. #else
  149. *((uint *) BCSR1) &= ~BCSR1_RS232EN_2;
  150. #endif
  151. #endif /* CONFIG_FADS */
  152. #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
  153. /* Enable Monitor Port Transceiver */
  154. *((uchar *) BCSR0) |= BCSR0_ENMONXCVR ;
  155. #endif /* CONFIG_RPXLITE */
  156. /* Set the physical address of the host memory buffers in
  157. * the buffer descriptors.
  158. */
  159. #ifdef CONFIG_SYS_ALLOC_DPRAM
  160. /* allocate
  161. * size of struct serialbuffer with bd rx/tx, buffer rx/tx and rx index
  162. */
  163. dpaddr = dpram_alloc_align((sizeof(serialbuffer_t)), 8);
  164. #else
  165. dpaddr = CPM_SERIAL_BASE ;
  166. #endif
  167. rtx = (serialbuffer_t *)&cp->cp_dpmem[dpaddr];
  168. /* Allocate space for two buffer descriptors in the DP ram.
  169. * For now, this address seems OK, but it may have to
  170. * change with newer versions of the firmware.
  171. * damm: allocating space after the two buffers for rx/tx data
  172. */
  173. rtx->rxbd.cbd_bufaddr = (uint) &rtx->rxbuf;
  174. rtx->rxbd.cbd_sc = 0;
  175. rtx->txbd.cbd_bufaddr = (uint) &rtx->txbuf;
  176. rtx->txbd.cbd_sc = 0;
  177. /* Set up the uart parameters in the parameter ram. */
  178. up->smc_rbase = dpaddr;
  179. up->smc_tbase = dpaddr+sizeof(cbd_t);
  180. up->smc_rfcr = SMC_EB;
  181. up->smc_tfcr = SMC_EB;
  182. #if defined (CONFIG_SYS_SMC_UCODE_PATCH)
  183. up->smc_rbptr = up->smc_rbase;
  184. up->smc_tbptr = up->smc_tbase;
  185. up->smc_rstate = 0;
  186. up->smc_tstate = 0;
  187. #endif
  188. #if defined(CONFIG_MBX)
  189. board_serial_init();
  190. #endif /* CONFIG_MBX */
  191. /* Set UART mode, 8 bit, no parity, one stop.
  192. * Enable receive and transmit.
  193. */
  194. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  195. /* Mask all interrupts and remove anything pending.
  196. */
  197. sp->smc_smcm = 0;
  198. sp->smc_smce = 0xff;
  199. #ifdef CONFIG_SYS_SPC1920_SMC1_CLK4
  200. /* clock source is PLD */
  201. /* set freq to 19200 Baud */
  202. *((volatile uchar *) CONFIG_SYS_SPC1920_PLD_BASE+6) = 0x3;
  203. /* configure clk4 as input */
  204. im->im_ioport.iop_pdpar |= 0x800;
  205. im->im_ioport.iop_pddir &= ~0x800;
  206. cp->cp_simode = ((cp->cp_simode & ~0xf000) | 0x7000);
  207. #else
  208. /* Set up the baud rate generator */
  209. smc_setbrg ();
  210. #endif
  211. /* Make the first buffer the only buffer. */
  212. rtx->txbd.cbd_sc |= BD_SC_WRAP;
  213. rtx->rxbd.cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  214. /* single/multi character receive. */
  215. up->smc_mrblr = CONFIG_SYS_SMC_RXBUFLEN;
  216. up->smc_maxidl = CONFIG_SYS_MAXIDLE;
  217. rtx->rxindex = 0;
  218. /* Initialize Tx/Rx parameters. */
  219. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  220. ;
  221. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SMC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  222. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  223. ;
  224. /* Enable transmitter/receiver. */
  225. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  226. return (0);
  227. }
  228. static void
  229. smc_putc(const char c)
  230. {
  231. volatile smc_uart_t *up;
  232. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  233. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  234. volatile serialbuffer_t *rtx;
  235. #ifdef CONFIG_MODEM_SUPPORT
  236. if (gd->be_quiet)
  237. return;
  238. #endif
  239. if (c == '\n')
  240. smc_putc ('\r');
  241. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  242. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  243. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  244. #endif
  245. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  246. /* Wait for last character to go. */
  247. rtx->txbuf = c;
  248. rtx->txbd.cbd_datlen = 1;
  249. rtx->txbd.cbd_sc |= BD_SC_READY;
  250. __asm__("eieio");
  251. while (rtx->txbd.cbd_sc & BD_SC_READY) {
  252. WATCHDOG_RESET ();
  253. __asm__("eieio");
  254. }
  255. }
  256. static void
  257. smc_puts (const char *s)
  258. {
  259. while (*s) {
  260. smc_putc (*s++);
  261. }
  262. }
  263. static int
  264. smc_getc(void)
  265. {
  266. volatile smc_uart_t *up;
  267. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  268. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  269. volatile serialbuffer_t *rtx;
  270. unsigned char c;
  271. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  272. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  273. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  274. #endif
  275. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  276. /* Wait for character to show up. */
  277. while (rtx->rxbd.cbd_sc & BD_SC_EMPTY)
  278. WATCHDOG_RESET ();
  279. /* the characters are read one by one,
  280. * use the rxindex to know the next char to deliver
  281. */
  282. c = *(unsigned char *) (rtx->rxbd.cbd_bufaddr+rtx->rxindex);
  283. rtx->rxindex++;
  284. /* check if all char are readout, then make prepare for next receive */
  285. if (rtx->rxindex >= rtx->rxbd.cbd_datlen) {
  286. rtx->rxindex = 0;
  287. rtx->rxbd.cbd_sc |= BD_SC_EMPTY;
  288. }
  289. return(c);
  290. }
  291. static int
  292. smc_tstc(void)
  293. {
  294. volatile smc_uart_t *up;
  295. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  296. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  297. volatile serialbuffer_t *rtx;
  298. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  299. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  300. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  301. #endif
  302. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  303. return !(rtx->rxbd.cbd_sc & BD_SC_EMPTY);
  304. }
  305. struct serial_device serial_smc_device =
  306. {
  307. .name = "serial_smc",
  308. .start = smc_init,
  309. .stop = NULL,
  310. .setbrg = smc_setbrg,
  311. .getc = smc_getc,
  312. .tstc = smc_tstc,
  313. .putc = smc_putc,
  314. .puts = smc_puts,
  315. };
  316. #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
  317. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  318. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  319. static void
  320. scc_setbrg (void)
  321. {
  322. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  323. volatile cpm8xx_t *cp = &(im->im_cpm);
  324. /* Set up the baud rate generator.
  325. * See 8xx_io/commproc.c for details.
  326. *
  327. * Wire BRG1 to SCCx
  328. */
  329. cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX));
  330. serial_setdivisor(cp);
  331. }
  332. static int scc_init (void)
  333. {
  334. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  335. volatile scc_t *sp;
  336. volatile scc_uart_t *up;
  337. volatile cbd_t *tbdf, *rbdf;
  338. volatile cpm8xx_t *cp = &(im->im_cpm);
  339. uint dpaddr;
  340. #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
  341. volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
  342. #endif
  343. /* initialize pointers to SCC */
  344. sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]);
  345. up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC];
  346. #if defined(CONFIG_LWMON) && defined(CONFIG_8xx_CONS_SCC2)
  347. { /* Disable Ethernet, enable Serial */
  348. uchar c;
  349. c = pic_read (0x61);
  350. c &= ~0x40; /* enable COM3 */
  351. c |= 0x80; /* disable Ethernet */
  352. pic_write (0x61, c);
  353. /* enable RTS2 */
  354. cp->cp_pbpar |= 0x2000;
  355. cp->cp_pbdat |= 0x2000;
  356. cp->cp_pbdir |= 0x2000;
  357. }
  358. #endif /* CONFIG_LWMON */
  359. /* Disable transmitter/receiver. */
  360. sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  361. #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
  362. /*
  363. * The MPC850 has SCC3 on Port B
  364. */
  365. cp->cp_pbpar |= 0x06;
  366. cp->cp_pbdir &= ~0x06;
  367. cp->cp_pbodr &= ~0x06;
  368. #elif (SCC_INDEX < 2) || !defined(CONFIG_IP860)
  369. /*
  370. * Standard configuration for SCC's is on Part A
  371. */
  372. ip->iop_papar |= ((3 << (2 * SCC_INDEX)));
  373. ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
  374. ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
  375. #else
  376. /*
  377. * The IP860 has SCC3 and SCC4 on Port D
  378. */
  379. ip->iop_pdpar |= ((3 << (2 * SCC_INDEX)));
  380. #endif
  381. /* Allocate space for two buffer descriptors in the DP ram. */
  382. #ifdef CONFIG_SYS_ALLOC_DPRAM
  383. dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
  384. #else
  385. dpaddr = CPM_SERIAL2_BASE ;
  386. #endif
  387. /* Enable SDMA. */
  388. im->im_siu_conf.sc_sdcr = 0x0001;
  389. /* Set the physical address of the host memory buffers in
  390. * the buffer descriptors.
  391. */
  392. rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
  393. rbdf->cbd_bufaddr = (uint) (rbdf+2);
  394. rbdf->cbd_sc = 0;
  395. tbdf = rbdf + 1;
  396. tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
  397. tbdf->cbd_sc = 0;
  398. /* Set up the baud rate generator. */
  399. scc_setbrg ();
  400. /* Set up the uart parameters in the parameter ram. */
  401. up->scc_genscc.scc_rbase = dpaddr;
  402. up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
  403. /* Initialize Tx/Rx parameters. */
  404. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  405. ;
  406. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  407. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  408. ;
  409. up->scc_genscc.scc_rfcr = SCC_EB | 0x05;
  410. up->scc_genscc.scc_tfcr = SCC_EB | 0x05;
  411. up->scc_genscc.scc_mrblr = 1; /* Single character receive */
  412. up->scc_maxidl = 0; /* disable max idle */
  413. up->scc_brkcr = 1; /* send one break character on stop TX */
  414. up->scc_parec = 0;
  415. up->scc_frmec = 0;
  416. up->scc_nosec = 0;
  417. up->scc_brkec = 0;
  418. up->scc_uaddr1 = 0;
  419. up->scc_uaddr2 = 0;
  420. up->scc_toseq = 0;
  421. up->scc_char1 = 0x8000;
  422. up->scc_char2 = 0x8000;
  423. up->scc_char3 = 0x8000;
  424. up->scc_char4 = 0x8000;
  425. up->scc_char5 = 0x8000;
  426. up->scc_char6 = 0x8000;
  427. up->scc_char7 = 0x8000;
  428. up->scc_char8 = 0x8000;
  429. up->scc_rccm = 0xc0ff;
  430. /* Set low latency / small fifo. */
  431. sp->scc_gsmrh = SCC_GSMRH_RFW;
  432. /* Set SCC(x) clock mode to 16x
  433. * See 8xx_io/commproc.c for details.
  434. *
  435. * Wire BRG1 to SCCn
  436. */
  437. /* Set UART mode, clock divider 16 on Tx and Rx */
  438. sp->scc_gsmrl &= ~0xF;
  439. sp->scc_gsmrl |=
  440. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  441. sp->scc_psmr = 0;
  442. sp->scc_psmr |= SCU_PSMR_CL;
  443. /* Mask all interrupts and remove anything pending. */
  444. sp->scc_sccm = 0;
  445. sp->scc_scce = 0xffff;
  446. sp->scc_dsr = 0x7e7e;
  447. sp->scc_psmr = 0x3000;
  448. /* Make the first buffer the only buffer. */
  449. tbdf->cbd_sc |= BD_SC_WRAP;
  450. rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  451. /* Enable transmitter/receiver. */
  452. sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  453. return (0);
  454. }
  455. static void
  456. scc_putc(const char c)
  457. {
  458. volatile cbd_t *tbdf;
  459. volatile char *buf;
  460. volatile scc_uart_t *up;
  461. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  462. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  463. #ifdef CONFIG_MODEM_SUPPORT
  464. if (gd->be_quiet)
  465. return;
  466. #endif
  467. if (c == '\n')
  468. scc_putc ('\r');
  469. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  470. tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
  471. /* Wait for last character to go. */
  472. buf = (char *)tbdf->cbd_bufaddr;
  473. *buf = c;
  474. tbdf->cbd_datlen = 1;
  475. tbdf->cbd_sc |= BD_SC_READY;
  476. __asm__("eieio");
  477. while (tbdf->cbd_sc & BD_SC_READY) {
  478. __asm__("eieio");
  479. WATCHDOG_RESET ();
  480. }
  481. }
  482. static void
  483. scc_puts (const char *s)
  484. {
  485. while (*s) {
  486. scc_putc (*s++);
  487. }
  488. }
  489. static int
  490. scc_getc(void)
  491. {
  492. volatile cbd_t *rbdf;
  493. volatile unsigned char *buf;
  494. volatile scc_uart_t *up;
  495. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  496. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  497. unsigned char c;
  498. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  499. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  500. /* Wait for character to show up. */
  501. buf = (unsigned char *)rbdf->cbd_bufaddr;
  502. while (rbdf->cbd_sc & BD_SC_EMPTY)
  503. WATCHDOG_RESET ();
  504. c = *buf;
  505. rbdf->cbd_sc |= BD_SC_EMPTY;
  506. return(c);
  507. }
  508. static int
  509. scc_tstc(void)
  510. {
  511. volatile cbd_t *rbdf;
  512. volatile scc_uart_t *up;
  513. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  514. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  515. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  516. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  517. return(!(rbdf->cbd_sc & BD_SC_EMPTY));
  518. }
  519. struct serial_device serial_scc_device =
  520. {
  521. .name = "serial_scc",
  522. .start = scc_init,
  523. .stop = NULL,
  524. .setbrg = scc_setbrg,
  525. .getc = scc_getc,
  526. .tstc = scc_tstc,
  527. .putc = scc_putc,
  528. .puts = scc_puts,
  529. };
  530. #endif /* CONFIG_8xx_CONS_SCCx */
  531. __weak struct serial_device *default_serial_console(void)
  532. {
  533. #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
  534. return &serial_smc_device;
  535. #else
  536. return &serial_scc_device;
  537. #endif
  538. }
  539. void mpc8xx_serial_initialize(void)
  540. {
  541. #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
  542. serial_register(&serial_smc_device);
  543. #endif
  544. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  545. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  546. serial_register(&serial_scc_device);
  547. #endif
  548. }
  549. #ifdef CONFIG_MODEM_SUPPORT
  550. void disable_putc(void)
  551. {
  552. gd->be_quiet = 1;
  553. }
  554. void enable_putc(void)
  555. {
  556. gd->be_quiet = 0;
  557. }
  558. #endif
  559. #if defined(CONFIG_CMD_KGDB)
  560. void
  561. kgdb_serial_init(void)
  562. {
  563. int i = -1;
  564. if (strcmp(default_serial_console()->name, "serial_smc") == 0)
  565. {
  566. #if defined(CONFIG_8xx_CONS_SMC1)
  567. i = 1;
  568. #elif defined(CONFIG_8xx_CONS_SMC2)
  569. i = 2;
  570. #endif
  571. }
  572. else if (strcmp(default_serial_console()->name, "serial_scc") == 0)
  573. {
  574. #if defined(CONFIG_8xx_CONS_SCC1)
  575. i = 1;
  576. #elif defined(CONFIG_8xx_CONS_SCC2)
  577. i = 2;
  578. #elif defined(CONFIG_8xx_CONS_SCC3)
  579. i = 3;
  580. #elif defined(CONFIG_8xx_CONS_SCC4)
  581. i = 4;
  582. #endif
  583. }
  584. if (i >= 0)
  585. {
  586. serial_printf("[on %s%d] ", default_serial_console()->name, i);
  587. }
  588. }
  589. void
  590. putDebugChar (int c)
  591. {
  592. serial_putc (c);
  593. }
  594. void
  595. putDebugStr (const char *str)
  596. {
  597. serial_puts (str);
  598. }
  599. int
  600. getDebugChar (void)
  601. {
  602. return serial_getc();
  603. }
  604. void
  605. kgdb_interruptible (int yes)
  606. {
  607. return;
  608. }
  609. #endif
  610. #endif /* CONFIG_8xx_CONS_NONE */