serial.c 16 KB

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