serial.c 15 KB

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