serial.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. #if !defined(CONFIG_8xx_CONS_NONE) /* No Console at all */
  29. #if defined(CONFIG_8xx_CONS_SMC1) /* Console on SMC1 */
  30. #define SMC_INDEX 0
  31. #define PROFF_SMC PROFF_SMC1
  32. #define CPM_CR_CH_SMC CPM_CR_CH_SMC1
  33. #elif defined(CONFIG_8xx_CONS_SMC2) /* Console on SMC2 */
  34. #define SMC_INDEX 1
  35. #define PROFF_SMC PROFF_SMC2
  36. #define CPM_CR_CH_SMC CPM_CR_CH_SMC2
  37. #endif /* CONFIG_8xx_CONS_SMCx */
  38. #if defined(CONFIG_8xx_CONS_SCC1) /* Console on SCC1 */
  39. #define SCC_INDEX 0
  40. #define PROFF_SCC PROFF_SCC1
  41. #define CPM_CR_CH_SCC CPM_CR_CH_SCC1
  42. #elif defined(CONFIG_8xx_CONS_SCC2) /* Console on SCC2 */
  43. #define SCC_INDEX 1
  44. #define PROFF_SCC PROFF_SCC2
  45. #define CPM_CR_CH_SCC CPM_CR_CH_SCC2
  46. #elif defined(CONFIG_8xx_CONS_SCC3) /* Console on SCC3 */
  47. #define SCC_INDEX 2
  48. #define PROFF_SCC PROFF_SCC3
  49. #define CPM_CR_CH_SCC CPM_CR_CH_SCC3
  50. #elif defined(CONFIG_8xx_CONS_SCC4) /* Console on SCC4 */
  51. #define SCC_INDEX 3
  52. #define PROFF_SCC PROFF_SCC4
  53. #define CPM_CR_CH_SCC CPM_CR_CH_SCC4
  54. #endif /* CONFIG_8xx_CONS_SCCx */
  55. static void serial_setdivisor(volatile cpm8xx_t *cp)
  56. {
  57. DECLARE_GLOBAL_DATA_PTR;
  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. /* Set up the baud rate generator.
  191. */
  192. smc_setbrg ();
  193. /* Make the first buffer the only buffer.
  194. */
  195. tbdf->cbd_sc |= BD_SC_WRAP;
  196. rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  197. /* Single character receive.
  198. */
  199. up->smc_mrblr = 1;
  200. up->smc_maxidl = 0;
  201. /* Initialize Tx/Rx parameters.
  202. */
  203. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  204. ;
  205. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SMC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  206. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  207. ;
  208. /* Enable transmitter/receiver.
  209. */
  210. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  211. return (0);
  212. }
  213. static void
  214. smc_putc(const char c)
  215. {
  216. volatile cbd_t *tbdf;
  217. volatile char *buf;
  218. volatile smc_uart_t *up;
  219. volatile immap_t *im = (immap_t *)CFG_IMMR;
  220. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  221. #ifdef CONFIG_MODEM_SUPPORT
  222. DECLARE_GLOBAL_DATA_PTR;
  223. if (gd->be_quiet)
  224. return;
  225. #endif
  226. if (c == '\n')
  227. smc_putc ('\r');
  228. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  229. tbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_tbase];
  230. /* Wait for last character to go.
  231. */
  232. buf = (char *)tbdf->cbd_bufaddr;
  233. *buf = c;
  234. tbdf->cbd_datlen = 1;
  235. tbdf->cbd_sc |= BD_SC_READY;
  236. __asm__("eieio");
  237. while (tbdf->cbd_sc & BD_SC_READY) {
  238. WATCHDOG_RESET ();
  239. __asm__("eieio");
  240. }
  241. }
  242. static void
  243. smc_puts (const char *s)
  244. {
  245. while (*s) {
  246. smc_putc (*s++);
  247. }
  248. }
  249. static int
  250. smc_getc(void)
  251. {
  252. volatile cbd_t *rbdf;
  253. volatile unsigned char *buf;
  254. volatile smc_uart_t *up;
  255. volatile immap_t *im = (immap_t *)CFG_IMMR;
  256. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  257. unsigned char c;
  258. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  259. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
  260. /* Wait for character to show up.
  261. */
  262. buf = (unsigned char *)rbdf->cbd_bufaddr;
  263. while (rbdf->cbd_sc & BD_SC_EMPTY)
  264. WATCHDOG_RESET ();
  265. c = *buf;
  266. rbdf->cbd_sc |= BD_SC_EMPTY;
  267. return(c);
  268. }
  269. static int
  270. smc_tstc(void)
  271. {
  272. volatile cbd_t *rbdf;
  273. volatile smc_uart_t *up;
  274. volatile immap_t *im = (immap_t *)CFG_IMMR;
  275. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  276. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
  277. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
  278. return(!(rbdf->cbd_sc & BD_SC_EMPTY));
  279. }
  280. struct serial_device serial_smc_device =
  281. {
  282. "serial_smc",
  283. "SMC",
  284. smc_init,
  285. smc_setbrg,
  286. smc_getc,
  287. smc_tstc,
  288. smc_putc,
  289. smc_puts,
  290. };
  291. #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
  292. #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
  293. defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
  294. static void
  295. scc_setbrg (void)
  296. {
  297. volatile immap_t *im = (immap_t *)CFG_IMMR;
  298. volatile cpm8xx_t *cp = &(im->im_cpm);
  299. /* Set up the baud rate generator.
  300. * See 8xx_io/commproc.c for details.
  301. *
  302. * Wire BRG1 to SCCx
  303. */
  304. cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX));
  305. serial_setdivisor(cp);
  306. }
  307. static int scc_init (void)
  308. {
  309. volatile immap_t *im = (immap_t *)CFG_IMMR;
  310. volatile scc_t *sp;
  311. volatile scc_uart_t *up;
  312. volatile cbd_t *tbdf, *rbdf;
  313. volatile cpm8xx_t *cp = &(im->im_cpm);
  314. uint dpaddr;
  315. #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
  316. volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
  317. #endif
  318. /* initialize pointers to SCC */
  319. sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]);
  320. up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC];
  321. #if defined(CONFIG_LWMON) && defined(CONFIG_8xx_CONS_SCC2)
  322. { /* Disable Ethernet, enable Serial */
  323. uchar c;
  324. c = pic_read (0x61);
  325. c &= ~0x40; /* enable COM3 */
  326. c |= 0x80; /* disable Ethernet */
  327. pic_write (0x61, c);
  328. /* enable RTS2 */
  329. cp->cp_pbpar |= 0x2000;
  330. cp->cp_pbdat |= 0x2000;
  331. cp->cp_pbdir |= 0x2000;
  332. }
  333. #endif /* CONFIG_LWMON */
  334. /* Disable transmitter/receiver.
  335. */
  336. sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  337. #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
  338. /*
  339. * The MPC850 has SCC3 on Port B
  340. */
  341. cp->cp_pbpar |= 0x06;
  342. cp->cp_pbdir &= ~0x06;
  343. cp->cp_pbodr &= ~0x06;
  344. #elif (SCC_INDEX < 2) || !defined(CONFIG_IP860)
  345. /*
  346. * Standard configuration for SCC's is on Part A
  347. */
  348. ip->iop_papar |= ((3 << (2 * SCC_INDEX)));
  349. ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
  350. ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
  351. #else
  352. /*
  353. * The IP860 has SCC3 and SCC4 on Port D
  354. */
  355. ip->iop_pdpar |= ((3 << (2 * SCC_INDEX)));
  356. #endif
  357. /* Allocate space for two buffer descriptors in the DP ram.
  358. */
  359. #ifdef CFG_ALLOC_DPRAM
  360. dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
  361. #else
  362. dpaddr = CPM_SERIAL2_BASE ;
  363. #endif
  364. /* Enable SDMA.
  365. */
  366. im->im_siu_conf.sc_sdcr = 0x0001;
  367. /* Set the physical address of the host memory buffers in
  368. * the buffer descriptors.
  369. */
  370. rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
  371. rbdf->cbd_bufaddr = (uint) (rbdf+2);
  372. rbdf->cbd_sc = 0;
  373. tbdf = rbdf + 1;
  374. tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
  375. tbdf->cbd_sc = 0;
  376. /* Set up the baud rate generator.
  377. */
  378. scc_setbrg ();
  379. /* Set up the uart parameters in the parameter ram.
  380. */
  381. up->scc_genscc.scc_rbase = dpaddr;
  382. up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
  383. /* Initialize Tx/Rx parameters.
  384. */
  385. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  386. ;
  387. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  388. while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
  389. ;
  390. up->scc_genscc.scc_rfcr = SCC_EB | 0x05;
  391. up->scc_genscc.scc_tfcr = SCC_EB | 0x05;
  392. up->scc_genscc.scc_mrblr = 1; /* Single character receive */
  393. up->scc_maxidl = 0; /* disable max idle */
  394. up->scc_brkcr = 1; /* send one break character on stop TX */
  395. up->scc_parec = 0;
  396. up->scc_frmec = 0;
  397. up->scc_nosec = 0;
  398. up->scc_brkec = 0;
  399. up->scc_uaddr1 = 0;
  400. up->scc_uaddr2 = 0;
  401. up->scc_toseq = 0;
  402. up->scc_char1 = 0x8000;
  403. up->scc_char2 = 0x8000;
  404. up->scc_char3 = 0x8000;
  405. up->scc_char4 = 0x8000;
  406. up->scc_char5 = 0x8000;
  407. up->scc_char6 = 0x8000;
  408. up->scc_char7 = 0x8000;
  409. up->scc_char8 = 0x8000;
  410. up->scc_rccm = 0xc0ff;
  411. /* Set low latency / small fifo.
  412. */
  413. sp->scc_gsmrh = SCC_GSMRH_RFW;
  414. /* Set SCC(x) clock mode to 16x
  415. * See 8xx_io/commproc.c for details.
  416. *
  417. * Wire BRG1 to SCCn
  418. */
  419. /* Set UART mode, clock divider 16 on Tx and Rx
  420. */
  421. sp->scc_gsmrl &= ~0xF;
  422. sp->scc_gsmrl |=
  423. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  424. sp->scc_psmr = 0;
  425. sp->scc_psmr |= SCU_PSMR_CL;
  426. /* Mask all interrupts and remove anything pending.
  427. */
  428. sp->scc_sccm = 0;
  429. sp->scc_scce = 0xffff;
  430. sp->scc_dsr = 0x7e7e;
  431. sp->scc_psmr = 0x3000;
  432. /* Make the first buffer the only buffer.
  433. */
  434. tbdf->cbd_sc |= BD_SC_WRAP;
  435. rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  436. /* Enable transmitter/receiver.
  437. */
  438. sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  439. return (0);
  440. }
  441. static void
  442. scc_putc(const char c)
  443. {
  444. volatile cbd_t *tbdf;
  445. volatile char *buf;
  446. volatile scc_uart_t *up;
  447. volatile immap_t *im = (immap_t *)CFG_IMMR;
  448. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  449. #ifdef CONFIG_MODEM_SUPPORT
  450. DECLARE_GLOBAL_DATA_PTR;
  451. if (gd->be_quiet)
  452. return;
  453. #endif
  454. if (c == '\n')
  455. scc_putc ('\r');
  456. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  457. tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
  458. /* Wait for last character to go.
  459. */
  460. buf = (char *)tbdf->cbd_bufaddr;
  461. *buf = c;
  462. tbdf->cbd_datlen = 1;
  463. tbdf->cbd_sc |= BD_SC_READY;
  464. __asm__("eieio");
  465. while (tbdf->cbd_sc & BD_SC_READY) {
  466. __asm__("eieio");
  467. WATCHDOG_RESET ();
  468. }
  469. }
  470. static void
  471. scc_puts (const char *s)
  472. {
  473. while (*s) {
  474. scc_putc (*s++);
  475. }
  476. }
  477. static int
  478. scc_getc(void)
  479. {
  480. volatile cbd_t *rbdf;
  481. volatile unsigned char *buf;
  482. volatile scc_uart_t *up;
  483. volatile immap_t *im = (immap_t *)CFG_IMMR;
  484. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  485. unsigned char c;
  486. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  487. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  488. /* Wait for character to show up.
  489. */
  490. buf = (unsigned char *)rbdf->cbd_bufaddr;
  491. while (rbdf->cbd_sc & BD_SC_EMPTY)
  492. WATCHDOG_RESET ();
  493. c = *buf;
  494. rbdf->cbd_sc |= BD_SC_EMPTY;
  495. return(c);
  496. }
  497. static int
  498. scc_tstc(void)
  499. {
  500. volatile cbd_t *rbdf;
  501. volatile scc_uart_t *up;
  502. volatile immap_t *im = (immap_t *)CFG_IMMR;
  503. volatile cpm8xx_t *cpmp = &(im->im_cpm);
  504. up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
  505. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
  506. return(!(rbdf->cbd_sc & BD_SC_EMPTY));
  507. }
  508. struct serial_device serial_scc_device =
  509. {
  510. "serial_scc",
  511. "SCC",
  512. scc_init,
  513. scc_setbrg,
  514. scc_getc,
  515. scc_tstc,
  516. scc_putc,
  517. scc_puts,
  518. };
  519. #endif /* CONFIG_8xx_CONS_SCCx */
  520. #ifdef CONFIG_MODEM_SUPPORT
  521. void disable_putc(void)
  522. {
  523. DECLARE_GLOBAL_DATA_PTR;
  524. gd->be_quiet = 1;
  525. }
  526. void enable_putc(void)
  527. {
  528. DECLARE_GLOBAL_DATA_PTR;
  529. gd->be_quiet = 0;
  530. }
  531. #endif
  532. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  533. void
  534. kgdb_serial_init(void)
  535. {
  536. int i = -1;
  537. if (strcmp(default_serial_console()->ctlr, "SMC") == 0)
  538. {
  539. #if defined(CONFIG_8xx_CONS_SMC1)
  540. i = 1;
  541. #elif defined(CONFIG_8xx_CONS_SMC2)
  542. i = 2;
  543. #endif
  544. }
  545. else if (strcmp(default_serial_console()->ctlr, "SMC") == 0)
  546. {
  547. #if defined(CONFIG_8xx_CONS_SCC1)
  548. i = 1;
  549. #elif defined(CONFIG_8xx_CONS_SCC2)
  550. i = 2;
  551. #elif defined(CONFIG_8xx_CONS_SCC3)
  552. i = 3;
  553. #elif defined(CONFIG_8xx_CONS_SCC4)
  554. i = 4;
  555. #endif
  556. }
  557. if (i >= 0)
  558. {
  559. serial_printf("[on %s%d] ", default_serial_console()->ctlr, i);
  560. }
  561. }
  562. void
  563. putDebugChar (int c)
  564. {
  565. serial_putc (c);
  566. }
  567. void
  568. putDebugStr (const char *str)
  569. {
  570. serial_puts (str);
  571. }
  572. int
  573. getDebugChar (void)
  574. {
  575. return serial_getc();
  576. }
  577. void
  578. kgdb_interruptible (int yes)
  579. {
  580. return;
  581. }
  582. #endif /* CFG_CMD_KGDB */
  583. #endif /* CONFIG_8xx_CONS_NONE */