serial.c 17 KB

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