serial.c 15 KB

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