serial.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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. /* Set the physical address of the host memory buffers in
  145. * the buffer descriptors.
  146. */
  147. #ifdef CONFIG_SYS_ALLOC_DPRAM
  148. /* allocate
  149. * size of struct serialbuffer with bd rx/tx, buffer rx/tx and rx index
  150. */
  151. dpaddr = dpram_alloc_align((sizeof(serialbuffer_t)), 8);
  152. #else
  153. dpaddr = CPM_SERIAL_BASE ;
  154. #endif
  155. rtx = (serialbuffer_t *)&cp->cp_dpmem[dpaddr];
  156. /* Allocate space for two buffer descriptors in the DP ram.
  157. * For now, this address seems OK, but it may have to
  158. * change with newer versions of the firmware.
  159. * damm: allocating space after the two buffers for rx/tx data
  160. */
  161. rtx->rxbd.cbd_bufaddr = (uint) &rtx->rxbuf;
  162. rtx->rxbd.cbd_sc = 0;
  163. rtx->txbd.cbd_bufaddr = (uint) &rtx->txbuf;
  164. rtx->txbd.cbd_sc = 0;
  165. /* Set up the uart parameters in the parameter ram. */
  166. up->smc_rbase = dpaddr;
  167. up->smc_tbase = dpaddr+sizeof(cbd_t);
  168. up->smc_rfcr = SMC_EB;
  169. up->smc_tfcr = SMC_EB;
  170. #if defined (CONFIG_SYS_SMC_UCODE_PATCH)
  171. up->smc_rbptr = up->smc_rbase;
  172. up->smc_tbptr = up->smc_tbase;
  173. up->smc_rstate = 0;
  174. up->smc_tstate = 0;
  175. #endif
  176. /* Set UART mode, 8 bit, no parity, one stop.
  177. * Enable receive and transmit.
  178. */
  179. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  180. /* Mask all interrupts and remove anything pending.
  181. */
  182. sp->smc_smcm = 0;
  183. sp->smc_smce = 0xff;
  184. #ifdef CONFIG_SYS_SPC1920_SMC1_CLK4
  185. /* clock source is PLD */
  186. /* set freq to 19200 Baud */
  187. *((volatile uchar *) CONFIG_SYS_SPC1920_PLD_BASE+6) = 0x3;
  188. /* configure clk4 as input */
  189. im->im_ioport.iop_pdpar |= 0x800;
  190. im->im_ioport.iop_pddir &= ~0x800;
  191. cp->cp_simode = ((cp->cp_simode & ~0xf000) | 0x7000);
  192. #else
  193. /* Set up the baud rate generator */
  194. smc_setbrg ();
  195. #endif
  196. /* Make the first buffer the only buffer. */
  197. rtx->txbd.cbd_sc |= BD_SC_WRAP;
  198. rtx->rxbd.cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  199. /* single/multi character receive. */
  200. up->smc_mrblr = CONFIG_SYS_SMC_RXBUFLEN;
  201. up->smc_maxidl = CONFIG_SYS_MAXIDLE;
  202. rtx->rxindex = 0;
  203. /* Initialize Tx/Rx parameters. */
  204. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  205. ;
  206. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SMC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  207. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  208. ;
  209. /* Enable transmitter/receiver. */
  210. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  211. return (0);
  212. }
  213. static void
  214. smc_putc(const char c)
  215. {
  216. volatile smc_uart_t *up;
  217. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  218. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  219. volatile serialbuffer_t *rtx;
  220. #ifdef CONFIG_MODEM_SUPPORT
  221. if (gd->be_quiet)
  222. return;
  223. #endif
  224. if (c == '\n')
  225. smc_putc ('\r');
  226. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  227. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  228. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  229. #endif
  230. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  231. /* Wait for last character to go. */
  232. rtx->txbuf = c;
  233. rtx->txbd.cbd_datlen = 1;
  234. rtx->txbd.cbd_sc |= BD_SC_READY;
  235. __asm__("eieio");
  236. while (rtx->txbd.cbd_sc & BD_SC_READY) {
  237. WATCHDOG_RESET ();
  238. __asm__("eieio");
  239. }
  240. }
  241. static void
  242. smc_puts (const char *s)
  243. {
  244. while (*s) {
  245. smc_putc (*s++);
  246. }
  247. }
  248. static int
  249. smc_getc(void)
  250. {
  251. volatile smc_uart_t *up;
  252. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  253. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  254. volatile serialbuffer_t *rtx;
  255. unsigned char c;
  256. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  257. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  258. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  259. #endif
  260. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  261. /* Wait for character to show up. */
  262. while (rtx->rxbd.cbd_sc & BD_SC_EMPTY)
  263. WATCHDOG_RESET ();
  264. /* the characters are read one by one,
  265. * use the rxindex to know the next char to deliver
  266. */
  267. c = *(unsigned char *) (rtx->rxbd.cbd_bufaddr+rtx->rxindex);
  268. rtx->rxindex++;
  269. /* check if all char are readout, then make prepare for next receive */
  270. if (rtx->rxindex >= rtx->rxbd.cbd_datlen) {
  271. rtx->rxindex = 0;
  272. rtx->rxbd.cbd_sc |= BD_SC_EMPTY;
  273. }
  274. return(c);
  275. }
  276. static int
  277. smc_tstc(void)
  278. {
  279. volatile smc_uart_t *up;
  280. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  281. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  282. volatile serialbuffer_t *rtx;
  283. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  284. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  285. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  286. #endif
  287. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  288. return !(rtx->rxbd.cbd_sc & BD_SC_EMPTY);
  289. }
  290. struct serial_device serial_smc_device =
  291. {
  292. .name = "serial_smc",
  293. .start = smc_init,
  294. .stop = NULL,
  295. .setbrg = smc_setbrg,
  296. .getc = smc_getc,
  297. .tstc = smc_tstc,
  298. .putc = smc_putc,
  299. .puts = smc_puts,
  300. };
  301. #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
  302. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  303. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  304. static void
  305. scc_setbrg (void)
  306. {
  307. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  308. volatile cpm8xx_t *cp = &(im->im_cpm);
  309. /* Set up the baud rate generator.
  310. * See 8xx_io/commproc.c for details.
  311. *
  312. * Wire BRG1 to SCCx
  313. */
  314. cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX));
  315. serial_setdivisor(cp);
  316. }
  317. static int scc_init (void)
  318. {
  319. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  320. volatile scc_t *sp;
  321. volatile scc_uart_t *up;
  322. volatile cbd_t *tbdf, *rbdf;
  323. volatile cpm8xx_t *cp = &(im->im_cpm);
  324. uint dpaddr;
  325. #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
  326. volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
  327. #endif
  328. /* initialize pointers to SCC */
  329. sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]);
  330. up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC];
  331. /* Disable transmitter/receiver. */
  332. sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  333. #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
  334. /*
  335. * The MPC850 has SCC3 on Port B
  336. */
  337. cp->cp_pbpar |= 0x06;
  338. cp->cp_pbdir &= ~0x06;
  339. cp->cp_pbodr &= ~0x06;
  340. #elif (SCC_INDEX < 2)
  341. /*
  342. * Standard configuration for SCC's is on Part A
  343. */
  344. ip->iop_papar |= ((3 << (2 * SCC_INDEX)));
  345. ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
  346. ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
  347. #endif
  348. /* Allocate space for two buffer descriptors in the DP ram. */
  349. #ifdef CONFIG_SYS_ALLOC_DPRAM
  350. dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
  351. #else
  352. dpaddr = CPM_SERIAL2_BASE ;
  353. #endif
  354. /* Enable SDMA. */
  355. im->im_siu_conf.sc_sdcr = 0x0001;
  356. /* Set the physical address of the host memory buffers in
  357. * the buffer descriptors.
  358. */
  359. rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
  360. rbdf->cbd_bufaddr = (uint) (rbdf+2);
  361. rbdf->cbd_sc = 0;
  362. tbdf = rbdf + 1;
  363. tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
  364. tbdf->cbd_sc = 0;
  365. /* Set up the baud rate generator. */
  366. scc_setbrg ();
  367. /* Set up the uart parameters in the parameter ram. */
  368. up->scc_genscc.scc_rbase = dpaddr;
  369. up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
  370. /* Initialize Tx/Rx parameters. */
  371. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  372. ;
  373. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  374. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  375. ;
  376. up->scc_genscc.scc_rfcr = SCC_EB | 0x05;
  377. up->scc_genscc.scc_tfcr = SCC_EB | 0x05;
  378. up->scc_genscc.scc_mrblr = 1; /* Single character receive */
  379. up->scc_maxidl = 0; /* disable max idle */
  380. up->scc_brkcr = 1; /* send one break character on stop TX */
  381. up->scc_parec = 0;
  382. up->scc_frmec = 0;
  383. up->scc_nosec = 0;
  384. up->scc_brkec = 0;
  385. up->scc_uaddr1 = 0;
  386. up->scc_uaddr2 = 0;
  387. up->scc_toseq = 0;
  388. up->scc_char1 = 0x8000;
  389. up->scc_char2 = 0x8000;
  390. up->scc_char3 = 0x8000;
  391. up->scc_char4 = 0x8000;
  392. up->scc_char5 = 0x8000;
  393. up->scc_char6 = 0x8000;
  394. up->scc_char7 = 0x8000;
  395. up->scc_char8 = 0x8000;
  396. up->scc_rccm = 0xc0ff;
  397. /* Set low latency / small fifo. */
  398. sp->scc_gsmrh = SCC_GSMRH_RFW;
  399. /* Set SCC(x) clock mode to 16x
  400. * See 8xx_io/commproc.c for details.
  401. *
  402. * Wire BRG1 to SCCn
  403. */
  404. /* Set UART mode, clock divider 16 on Tx and Rx */
  405. sp->scc_gsmrl &= ~0xF;
  406. sp->scc_gsmrl |=
  407. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  408. sp->scc_psmr = 0;
  409. sp->scc_psmr |= SCU_PSMR_CL;
  410. /* Mask all interrupts and remove anything pending. */
  411. sp->scc_sccm = 0;
  412. sp->scc_scce = 0xffff;
  413. sp->scc_dsr = 0x7e7e;
  414. sp->scc_psmr = 0x3000;
  415. /* Make the first buffer the only buffer. */
  416. tbdf->cbd_sc |= BD_SC_WRAP;
  417. rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  418. /* Enable transmitter/receiver. */
  419. sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  420. return (0);
  421. }
  422. static void
  423. scc_putc(const char c)
  424. {
  425. volatile cbd_t *tbdf;
  426. volatile char *buf;
  427. volatile scc_uart_t *up;
  428. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  429. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  430. #ifdef CONFIG_MODEM_SUPPORT
  431. if (gd->be_quiet)
  432. return;
  433. #endif
  434. if (c == '\n')
  435. scc_putc ('\r');
  436. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  437. tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
  438. /* Wait for last character to go. */
  439. buf = (char *)tbdf->cbd_bufaddr;
  440. *buf = c;
  441. tbdf->cbd_datlen = 1;
  442. tbdf->cbd_sc |= BD_SC_READY;
  443. __asm__("eieio");
  444. while (tbdf->cbd_sc & BD_SC_READY) {
  445. __asm__("eieio");
  446. WATCHDOG_RESET ();
  447. }
  448. }
  449. static void
  450. scc_puts (const char *s)
  451. {
  452. while (*s) {
  453. scc_putc (*s++);
  454. }
  455. }
  456. static int
  457. scc_getc(void)
  458. {
  459. volatile cbd_t *rbdf;
  460. volatile unsigned char *buf;
  461. volatile scc_uart_t *up;
  462. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  463. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  464. unsigned char c;
  465. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  466. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  467. /* Wait for character to show up. */
  468. buf = (unsigned char *)rbdf->cbd_bufaddr;
  469. while (rbdf->cbd_sc & BD_SC_EMPTY)
  470. WATCHDOG_RESET ();
  471. c = *buf;
  472. rbdf->cbd_sc |= BD_SC_EMPTY;
  473. return(c);
  474. }
  475. static int
  476. scc_tstc(void)
  477. {
  478. volatile cbd_t *rbdf;
  479. volatile scc_uart_t *up;
  480. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  481. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  482. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  483. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  484. return(!(rbdf->cbd_sc & BD_SC_EMPTY));
  485. }
  486. struct serial_device serial_scc_device =
  487. {
  488. .name = "serial_scc",
  489. .start = scc_init,
  490. .stop = NULL,
  491. .setbrg = scc_setbrg,
  492. .getc = scc_getc,
  493. .tstc = scc_tstc,
  494. .putc = scc_putc,
  495. .puts = scc_puts,
  496. };
  497. #endif /* CONFIG_8xx_CONS_SCCx */
  498. __weak struct serial_device *default_serial_console(void)
  499. {
  500. #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
  501. return &serial_smc_device;
  502. #else
  503. return &serial_scc_device;
  504. #endif
  505. }
  506. void mpc8xx_serial_initialize(void)
  507. {
  508. #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
  509. serial_register(&serial_smc_device);
  510. #endif
  511. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  512. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  513. serial_register(&serial_scc_device);
  514. #endif
  515. }
  516. #ifdef CONFIG_MODEM_SUPPORT
  517. void disable_putc(void)
  518. {
  519. gd->be_quiet = 1;
  520. }
  521. void enable_putc(void)
  522. {
  523. gd->be_quiet = 0;
  524. }
  525. #endif
  526. #if defined(CONFIG_CMD_KGDB)
  527. void
  528. kgdb_serial_init(void)
  529. {
  530. int i = -1;
  531. if (strcmp(default_serial_console()->name, "serial_smc") == 0)
  532. {
  533. #if defined(CONFIG_8xx_CONS_SMC1)
  534. i = 1;
  535. #elif defined(CONFIG_8xx_CONS_SMC2)
  536. i = 2;
  537. #endif
  538. }
  539. else if (strcmp(default_serial_console()->name, "serial_scc") == 0)
  540. {
  541. #if defined(CONFIG_8xx_CONS_SCC1)
  542. i = 1;
  543. #elif defined(CONFIG_8xx_CONS_SCC2)
  544. i = 2;
  545. #elif defined(CONFIG_8xx_CONS_SCC3)
  546. i = 3;
  547. #elif defined(CONFIG_8xx_CONS_SCC4)
  548. i = 4;
  549. #endif
  550. }
  551. if (i >= 0)
  552. {
  553. serial_printf("[on %s%d] ", default_serial_console()->name, i);
  554. }
  555. }
  556. void
  557. putDebugChar (int c)
  558. {
  559. serial_putc (c);
  560. }
  561. void
  562. putDebugStr (const char *str)
  563. {
  564. serial_puts (str);
  565. }
  566. int
  567. getDebugChar (void)
  568. {
  569. return serial_getc();
  570. }
  571. void
  572. kgdb_interruptible (int yes)
  573. {
  574. return;
  575. }
  576. #endif
  577. #endif /* CONFIG_8xx_CONS_NONE */