serial.c 17 KB

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