serial.c 16 KB

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