serial.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. if (c == '\n')
  221. smc_putc ('\r');
  222. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  223. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  224. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  225. #endif
  226. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  227. /* Wait for last character to go. */
  228. rtx->txbuf = c;
  229. rtx->txbd.cbd_datlen = 1;
  230. rtx->txbd.cbd_sc |= BD_SC_READY;
  231. __asm__("eieio");
  232. while (rtx->txbd.cbd_sc & BD_SC_READY) {
  233. WATCHDOG_RESET ();
  234. __asm__("eieio");
  235. }
  236. }
  237. static void
  238. smc_puts (const char *s)
  239. {
  240. while (*s) {
  241. smc_putc (*s++);
  242. }
  243. }
  244. static int
  245. smc_getc(void)
  246. {
  247. volatile smc_uart_t *up;
  248. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  249. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  250. volatile serialbuffer_t *rtx;
  251. unsigned char c;
  252. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  253. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  254. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  255. #endif
  256. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  257. /* Wait for character to show up. */
  258. while (rtx->rxbd.cbd_sc & BD_SC_EMPTY)
  259. WATCHDOG_RESET ();
  260. /* the characters are read one by one,
  261. * use the rxindex to know the next char to deliver
  262. */
  263. c = *(unsigned char *) (rtx->rxbd.cbd_bufaddr+rtx->rxindex);
  264. rtx->rxindex++;
  265. /* check if all char are readout, then make prepare for next receive */
  266. if (rtx->rxindex >= rtx->rxbd.cbd_datlen) {
  267. rtx->rxindex = 0;
  268. rtx->rxbd.cbd_sc |= BD_SC_EMPTY;
  269. }
  270. return(c);
  271. }
  272. static int
  273. smc_tstc(void)
  274. {
  275. volatile smc_uart_t *up;
  276. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  277. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  278. volatile serialbuffer_t *rtx;
  279. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  280. #ifdef CONFIG_SYS_SMC_UCODE_PATCH
  281. up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
  282. #endif
  283. rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
  284. return !(rtx->rxbd.cbd_sc & BD_SC_EMPTY);
  285. }
  286. struct serial_device serial_smc_device =
  287. {
  288. .name = "serial_smc",
  289. .start = smc_init,
  290. .stop = NULL,
  291. .setbrg = smc_setbrg,
  292. .getc = smc_getc,
  293. .tstc = smc_tstc,
  294. .putc = smc_putc,
  295. .puts = smc_puts,
  296. };
  297. #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
  298. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  299. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  300. static void
  301. scc_setbrg (void)
  302. {
  303. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  304. volatile cpm8xx_t *cp = &(im->im_cpm);
  305. /* Set up the baud rate generator.
  306. * See 8xx_io/commproc.c for details.
  307. *
  308. * Wire BRG1 to SCCx
  309. */
  310. cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX));
  311. serial_setdivisor(cp);
  312. }
  313. static int scc_init (void)
  314. {
  315. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  316. volatile scc_t *sp;
  317. volatile scc_uart_t *up;
  318. volatile cbd_t *tbdf, *rbdf;
  319. volatile cpm8xx_t *cp = &(im->im_cpm);
  320. uint dpaddr;
  321. #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
  322. volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
  323. #endif
  324. /* initialize pointers to SCC */
  325. sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]);
  326. up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC];
  327. /* Disable transmitter/receiver. */
  328. sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  329. #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
  330. /*
  331. * The MPC850 has SCC3 on Port B
  332. */
  333. cp->cp_pbpar |= 0x06;
  334. cp->cp_pbdir &= ~0x06;
  335. cp->cp_pbodr &= ~0x06;
  336. #elif (SCC_INDEX < 2)
  337. /*
  338. * Standard configuration for SCC's is on Part A
  339. */
  340. ip->iop_papar |= ((3 << (2 * SCC_INDEX)));
  341. ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
  342. ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
  343. #endif
  344. /* Allocate space for two buffer descriptors in the DP ram. */
  345. #ifdef CONFIG_SYS_ALLOC_DPRAM
  346. dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
  347. #else
  348. dpaddr = CPM_SERIAL2_BASE ;
  349. #endif
  350. /* Enable SDMA. */
  351. im->im_siu_conf.sc_sdcr = 0x0001;
  352. /* Set the physical address of the host memory buffers in
  353. * the buffer descriptors.
  354. */
  355. rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
  356. rbdf->cbd_bufaddr = (uint) (rbdf+2);
  357. rbdf->cbd_sc = 0;
  358. tbdf = rbdf + 1;
  359. tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
  360. tbdf->cbd_sc = 0;
  361. /* Set up the baud rate generator. */
  362. scc_setbrg ();
  363. /* Set up the uart parameters in the parameter ram. */
  364. up->scc_genscc.scc_rbase = dpaddr;
  365. up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
  366. /* Initialize Tx/Rx parameters. */
  367. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  368. ;
  369. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  370. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  371. ;
  372. up->scc_genscc.scc_rfcr = SCC_EB | 0x05;
  373. up->scc_genscc.scc_tfcr = SCC_EB | 0x05;
  374. up->scc_genscc.scc_mrblr = 1; /* Single character receive */
  375. up->scc_maxidl = 0; /* disable max idle */
  376. up->scc_brkcr = 1; /* send one break character on stop TX */
  377. up->scc_parec = 0;
  378. up->scc_frmec = 0;
  379. up->scc_nosec = 0;
  380. up->scc_brkec = 0;
  381. up->scc_uaddr1 = 0;
  382. up->scc_uaddr2 = 0;
  383. up->scc_toseq = 0;
  384. up->scc_char1 = 0x8000;
  385. up->scc_char2 = 0x8000;
  386. up->scc_char3 = 0x8000;
  387. up->scc_char4 = 0x8000;
  388. up->scc_char5 = 0x8000;
  389. up->scc_char6 = 0x8000;
  390. up->scc_char7 = 0x8000;
  391. up->scc_char8 = 0x8000;
  392. up->scc_rccm = 0xc0ff;
  393. /* Set low latency / small fifo. */
  394. sp->scc_gsmrh = SCC_GSMRH_RFW;
  395. /* Set SCC(x) clock mode to 16x
  396. * See 8xx_io/commproc.c for details.
  397. *
  398. * Wire BRG1 to SCCn
  399. */
  400. /* Set UART mode, clock divider 16 on Tx and Rx */
  401. sp->scc_gsmrl &= ~0xF;
  402. sp->scc_gsmrl |=
  403. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  404. sp->scc_psmr = 0;
  405. sp->scc_psmr |= SCU_PSMR_CL;
  406. /* Mask all interrupts and remove anything pending. */
  407. sp->scc_sccm = 0;
  408. sp->scc_scce = 0xffff;
  409. sp->scc_dsr = 0x7e7e;
  410. sp->scc_psmr = 0x3000;
  411. /* Make the first buffer the only buffer. */
  412. tbdf->cbd_sc |= BD_SC_WRAP;
  413. rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  414. /* Enable transmitter/receiver. */
  415. sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  416. return (0);
  417. }
  418. static void
  419. scc_putc(const char c)
  420. {
  421. volatile cbd_t *tbdf;
  422. volatile char *buf;
  423. volatile scc_uart_t *up;
  424. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  425. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  426. if (c == '\n')
  427. scc_putc ('\r');
  428. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  429. tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
  430. /* Wait for last character to go. */
  431. buf = (char *)tbdf->cbd_bufaddr;
  432. *buf = c;
  433. tbdf->cbd_datlen = 1;
  434. tbdf->cbd_sc |= BD_SC_READY;
  435. __asm__("eieio");
  436. while (tbdf->cbd_sc & BD_SC_READY) {
  437. __asm__("eieio");
  438. WATCHDOG_RESET ();
  439. }
  440. }
  441. static void
  442. scc_puts (const char *s)
  443. {
  444. while (*s) {
  445. scc_putc (*s++);
  446. }
  447. }
  448. static int
  449. scc_getc(void)
  450. {
  451. volatile cbd_t *rbdf;
  452. volatile unsigned char *buf;
  453. volatile scc_uart_t *up;
  454. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  455. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  456. unsigned char c;
  457. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  458. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  459. /* Wait for character to show up. */
  460. buf = (unsigned char *)rbdf->cbd_bufaddr;
  461. while (rbdf->cbd_sc & BD_SC_EMPTY)
  462. WATCHDOG_RESET ();
  463. c = *buf;
  464. rbdf->cbd_sc |= BD_SC_EMPTY;
  465. return(c);
  466. }
  467. static int
  468. scc_tstc(void)
  469. {
  470. volatile cbd_t *rbdf;
  471. volatile scc_uart_t *up;
  472. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  473. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  474. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  475. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  476. return(!(rbdf->cbd_sc & BD_SC_EMPTY));
  477. }
  478. struct serial_device serial_scc_device =
  479. {
  480. .name = "serial_scc",
  481. .start = scc_init,
  482. .stop = NULL,
  483. .setbrg = scc_setbrg,
  484. .getc = scc_getc,
  485. .tstc = scc_tstc,
  486. .putc = scc_putc,
  487. .puts = scc_puts,
  488. };
  489. #endif /* CONFIG_8xx_CONS_SCCx */
  490. __weak struct serial_device *default_serial_console(void)
  491. {
  492. #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
  493. return &serial_smc_device;
  494. #else
  495. return &serial_scc_device;
  496. #endif
  497. }
  498. void mpc8xx_serial_initialize(void)
  499. {
  500. #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
  501. serial_register(&serial_smc_device);
  502. #endif
  503. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  504. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  505. serial_register(&serial_scc_device);
  506. #endif
  507. }
  508. #if defined(CONFIG_CMD_KGDB)
  509. void
  510. kgdb_serial_init(void)
  511. {
  512. int i = -1;
  513. if (strcmp(default_serial_console()->name, "serial_smc") == 0)
  514. {
  515. #if defined(CONFIG_8xx_CONS_SMC1)
  516. i = 1;
  517. #elif defined(CONFIG_8xx_CONS_SMC2)
  518. i = 2;
  519. #endif
  520. }
  521. else if (strcmp(default_serial_console()->name, "serial_scc") == 0)
  522. {
  523. #if defined(CONFIG_8xx_CONS_SCC1)
  524. i = 1;
  525. #elif defined(CONFIG_8xx_CONS_SCC2)
  526. i = 2;
  527. #elif defined(CONFIG_8xx_CONS_SCC3)
  528. i = 3;
  529. #elif defined(CONFIG_8xx_CONS_SCC4)
  530. i = 4;
  531. #endif
  532. }
  533. if (i >= 0)
  534. {
  535. serial_printf("[on %s%d] ", default_serial_console()->name, i);
  536. }
  537. }
  538. void
  539. putDebugChar (int c)
  540. {
  541. serial_putc (c);
  542. }
  543. void
  544. putDebugStr (const char *str)
  545. {
  546. serial_puts (str);
  547. }
  548. int
  549. getDebugChar (void)
  550. {
  551. return serial_getc();
  552. }
  553. void
  554. kgdb_interruptible (int yes)
  555. {
  556. return;
  557. }
  558. #endif
  559. #endif /* CONFIG_8xx_CONS_NONE */