serial.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. NULL,
  326. smc_setbrg,
  327. smc_getc,
  328. smc_tstc,
  329. smc_putc,
  330. smc_puts,
  331. };
  332. #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
  333. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  334. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  335. static void
  336. scc_setbrg (void)
  337. {
  338. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  339. volatile cpm8xx_t *cp = &(im->im_cpm);
  340. /* Set up the baud rate generator.
  341. * See 8xx_io/commproc.c for details.
  342. *
  343. * Wire BRG1 to SCCx
  344. */
  345. cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX));
  346. serial_setdivisor(cp);
  347. }
  348. static int scc_init (void)
  349. {
  350. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  351. volatile scc_t *sp;
  352. volatile scc_uart_t *up;
  353. volatile cbd_t *tbdf, *rbdf;
  354. volatile cpm8xx_t *cp = &(im->im_cpm);
  355. uint dpaddr;
  356. #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
  357. volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
  358. #endif
  359. /* initialize pointers to SCC */
  360. sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]);
  361. up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC];
  362. #if defined(CONFIG_LWMON) && defined(CONFIG_8xx_CONS_SCC2)
  363. { /* Disable Ethernet, enable Serial */
  364. uchar c;
  365. c = pic_read (0x61);
  366. c &= ~0x40; /* enable COM3 */
  367. c |= 0x80; /* disable Ethernet */
  368. pic_write (0x61, c);
  369. /* enable RTS2 */
  370. cp->cp_pbpar |= 0x2000;
  371. cp->cp_pbdat |= 0x2000;
  372. cp->cp_pbdir |= 0x2000;
  373. }
  374. #endif /* CONFIG_LWMON */
  375. /* Disable transmitter/receiver. */
  376. sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  377. #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
  378. /*
  379. * The MPC850 has SCC3 on Port B
  380. */
  381. cp->cp_pbpar |= 0x06;
  382. cp->cp_pbdir &= ~0x06;
  383. cp->cp_pbodr &= ~0x06;
  384. #elif (SCC_INDEX < 2) || !defined(CONFIG_IP860)
  385. /*
  386. * Standard configuration for SCC's is on Part A
  387. */
  388. ip->iop_papar |= ((3 << (2 * SCC_INDEX)));
  389. ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
  390. ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
  391. #else
  392. /*
  393. * The IP860 has SCC3 and SCC4 on Port D
  394. */
  395. ip->iop_pdpar |= ((3 << (2 * SCC_INDEX)));
  396. #endif
  397. /* Allocate space for two buffer descriptors in the DP ram. */
  398. #ifdef CONFIG_SYS_ALLOC_DPRAM
  399. dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
  400. #else
  401. dpaddr = CPM_SERIAL2_BASE ;
  402. #endif
  403. /* Enable SDMA. */
  404. im->im_siu_conf.sc_sdcr = 0x0001;
  405. /* Set the physical address of the host memory buffers in
  406. * the buffer descriptors.
  407. */
  408. rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
  409. rbdf->cbd_bufaddr = (uint) (rbdf+2);
  410. rbdf->cbd_sc = 0;
  411. tbdf = rbdf + 1;
  412. tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
  413. tbdf->cbd_sc = 0;
  414. /* Set up the baud rate generator. */
  415. scc_setbrg ();
  416. /* Set up the uart parameters in the parameter ram. */
  417. up->scc_genscc.scc_rbase = dpaddr;
  418. up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
  419. /* Initialize Tx/Rx parameters. */
  420. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  421. ;
  422. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  423. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  424. ;
  425. up->scc_genscc.scc_rfcr = SCC_EB | 0x05;
  426. up->scc_genscc.scc_tfcr = SCC_EB | 0x05;
  427. up->scc_genscc.scc_mrblr = 1; /* Single character receive */
  428. up->scc_maxidl = 0; /* disable max idle */
  429. up->scc_brkcr = 1; /* send one break character on stop TX */
  430. up->scc_parec = 0;
  431. up->scc_frmec = 0;
  432. up->scc_nosec = 0;
  433. up->scc_brkec = 0;
  434. up->scc_uaddr1 = 0;
  435. up->scc_uaddr2 = 0;
  436. up->scc_toseq = 0;
  437. up->scc_char1 = 0x8000;
  438. up->scc_char2 = 0x8000;
  439. up->scc_char3 = 0x8000;
  440. up->scc_char4 = 0x8000;
  441. up->scc_char5 = 0x8000;
  442. up->scc_char6 = 0x8000;
  443. up->scc_char7 = 0x8000;
  444. up->scc_char8 = 0x8000;
  445. up->scc_rccm = 0xc0ff;
  446. /* Set low latency / small fifo. */
  447. sp->scc_gsmrh = SCC_GSMRH_RFW;
  448. /* Set SCC(x) clock mode to 16x
  449. * See 8xx_io/commproc.c for details.
  450. *
  451. * Wire BRG1 to SCCn
  452. */
  453. /* Set UART mode, clock divider 16 on Tx and Rx */
  454. sp->scc_gsmrl &= ~0xF;
  455. sp->scc_gsmrl |=
  456. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  457. sp->scc_psmr = 0;
  458. sp->scc_psmr |= SCU_PSMR_CL;
  459. /* Mask all interrupts and remove anything pending. */
  460. sp->scc_sccm = 0;
  461. sp->scc_scce = 0xffff;
  462. sp->scc_dsr = 0x7e7e;
  463. sp->scc_psmr = 0x3000;
  464. /* Make the first buffer the only buffer. */
  465. tbdf->cbd_sc |= BD_SC_WRAP;
  466. rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  467. /* Enable transmitter/receiver. */
  468. sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  469. return (0);
  470. }
  471. static void
  472. scc_putc(const char c)
  473. {
  474. volatile cbd_t *tbdf;
  475. volatile char *buf;
  476. volatile scc_uart_t *up;
  477. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  478. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  479. #ifdef CONFIG_MODEM_SUPPORT
  480. if (gd->be_quiet)
  481. return;
  482. #endif
  483. if (c == '\n')
  484. scc_putc ('\r');
  485. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  486. tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
  487. /* Wait for last character to go. */
  488. buf = (char *)tbdf->cbd_bufaddr;
  489. *buf = c;
  490. tbdf->cbd_datlen = 1;
  491. tbdf->cbd_sc |= BD_SC_READY;
  492. __asm__("eieio");
  493. while (tbdf->cbd_sc & BD_SC_READY) {
  494. __asm__("eieio");
  495. WATCHDOG_RESET ();
  496. }
  497. }
  498. static void
  499. scc_puts (const char *s)
  500. {
  501. while (*s) {
  502. scc_putc (*s++);
  503. }
  504. }
  505. static int
  506. scc_getc(void)
  507. {
  508. volatile cbd_t *rbdf;
  509. volatile unsigned char *buf;
  510. volatile scc_uart_t *up;
  511. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  512. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  513. unsigned char c;
  514. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  515. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  516. /* Wait for character to show up. */
  517. buf = (unsigned char *)rbdf->cbd_bufaddr;
  518. while (rbdf->cbd_sc & BD_SC_EMPTY)
  519. WATCHDOG_RESET ();
  520. c = *buf;
  521. rbdf->cbd_sc |= BD_SC_EMPTY;
  522. return(c);
  523. }
  524. static int
  525. scc_tstc(void)
  526. {
  527. volatile cbd_t *rbdf;
  528. volatile scc_uart_t *up;
  529. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  530. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  531. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  532. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  533. return(!(rbdf->cbd_sc & BD_SC_EMPTY));
  534. }
  535. struct serial_device serial_scc_device =
  536. {
  537. "serial_scc",
  538. "SCC",
  539. scc_init,
  540. NULL,
  541. scc_setbrg,
  542. scc_getc,
  543. scc_tstc,
  544. scc_putc,
  545. scc_puts,
  546. };
  547. #endif /* CONFIG_8xx_CONS_SCCx */
  548. #ifdef CONFIG_MODEM_SUPPORT
  549. void disable_putc(void)
  550. {
  551. gd->be_quiet = 1;
  552. }
  553. void enable_putc(void)
  554. {
  555. gd->be_quiet = 0;
  556. }
  557. #endif
  558. #if defined(CONFIG_CMD_KGDB)
  559. void
  560. kgdb_serial_init(void)
  561. {
  562. int i = -1;
  563. if (strcmp(default_serial_console()->ctlr, "SMC") == 0)
  564. {
  565. #if defined(CONFIG_8xx_CONS_SMC1)
  566. i = 1;
  567. #elif defined(CONFIG_8xx_CONS_SMC2)
  568. i = 2;
  569. #endif
  570. }
  571. else if (strcmp(default_serial_console()->ctlr, "SMC") == 0)
  572. {
  573. #if defined(CONFIG_8xx_CONS_SCC1)
  574. i = 1;
  575. #elif defined(CONFIG_8xx_CONS_SCC2)
  576. i = 2;
  577. #elif defined(CONFIG_8xx_CONS_SCC3)
  578. i = 3;
  579. #elif defined(CONFIG_8xx_CONS_SCC4)
  580. i = 4;
  581. #endif
  582. }
  583. if (i >= 0)
  584. {
  585. serial_printf("[on %s%d] ", default_serial_console()->ctlr, i);
  586. }
  587. }
  588. void
  589. putDebugChar (int c)
  590. {
  591. serial_putc (c);
  592. }
  593. void
  594. putDebugStr (const char *str)
  595. {
  596. serial_puts (str);
  597. }
  598. int
  599. getDebugChar (void)
  600. {
  601. return serial_getc();
  602. }
  603. void
  604. kgdb_interruptible (int yes)
  605. {
  606. return;
  607. }
  608. #endif
  609. #endif /* CONFIG_8xx_CONS_NONE */