blob: 8ae584f2e1dd4ddcba111a548da0f78fa6869b14 [file] [log] [blame]
wdenk4a9cbbe2002-08-27 09:48:53 +00001/*
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
24#include <common.h>
25#include <commproc.h>
26#include <command.h>
wdenk281e00a2004-08-01 22:48:16 +000027#include <serial.h>
wdenkd0fb80c2003-01-11 09:48:40 +000028#include <watchdog.h>
wdenk4a9cbbe2002-08-27 09:48:53 +000029
Wolfgang Denkd87080b2006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
31
wdenk4a9cbbe2002-08-27 09:48:53 +000032#if !defined(CONFIG_8xx_CONS_NONE) /* No Console at all */
33
34#if defined(CONFIG_8xx_CONS_SMC1) /* Console on SMC1 */
35#define SMC_INDEX 0
wdenk4a9cbbe2002-08-27 09:48:53 +000036#define PROFF_SMC PROFF_SMC1
37#define CPM_CR_CH_SMC CPM_CR_CH_SMC1
38
39#elif defined(CONFIG_8xx_CONS_SMC2) /* Console on SMC2 */
40#define SMC_INDEX 1
wdenk4a9cbbe2002-08-27 09:48:53 +000041#define PROFF_SMC PROFF_SMC2
42#define CPM_CR_CH_SMC CPM_CR_CH_SMC2
43
wdenk281e00a2004-08-01 22:48:16 +000044#endif /* CONFIG_8xx_CONS_SMCx */
45
46#if defined(CONFIG_8xx_CONS_SCC1) /* Console on SCC1 */
wdenk4a9cbbe2002-08-27 09:48:53 +000047#define SCC_INDEX 0
48#define PROFF_SCC PROFF_SCC1
49#define CPM_CR_CH_SCC CPM_CR_CH_SCC1
50
51#elif defined(CONFIG_8xx_CONS_SCC2) /* Console on SCC2 */
wdenk4a9cbbe2002-08-27 09:48:53 +000052#define SCC_INDEX 1
53#define PROFF_SCC PROFF_SCC2
54#define CPM_CR_CH_SCC CPM_CR_CH_SCC2
55
56#elif defined(CONFIG_8xx_CONS_SCC3) /* Console on SCC3 */
wdenk4a9cbbe2002-08-27 09:48:53 +000057#define SCC_INDEX 2
58#define PROFF_SCC PROFF_SCC3
59#define CPM_CR_CH_SCC CPM_CR_CH_SCC3
60
61#elif defined(CONFIG_8xx_CONS_SCC4) /* Console on SCC4 */
wdenk4a9cbbe2002-08-27 09:48:53 +000062#define SCC_INDEX 3
63#define PROFF_SCC PROFF_SCC4
64#define CPM_CR_CH_SCC CPM_CR_CH_SCC4
65
wdenk281e00a2004-08-01 22:48:16 +000066#endif /* CONFIG_8xx_CONS_SCCx */
wdenk4a9cbbe2002-08-27 09:48:53 +000067
wdenk2535d602003-07-17 23:16:40 +000068static void serial_setdivisor(volatile cpm8xx_t *cp)
69{
wdenk75d1ea72004-01-31 20:06:54 +000070 int divisor=(gd->cpu_clk + 8*gd->baudrate)/16/gd->baudrate;
wdenk2535d602003-07-17 23:16:40 +000071
72 if(divisor/16>0x1000) {
73 /* bad divisor, assume 50Mhz clock and 9600 baud */
wdenk75d1ea72004-01-31 20:06:54 +000074 divisor=(50*1000*1000 + 8*9600)/16/9600;
wdenk2535d602003-07-17 23:16:40 +000075 }
76
wdenk3bbc8992003-12-07 22:27:15 +000077#ifdef CFG_BRGCLK_PRESCALE
78 divisor /= CFG_BRGCLK_PRESCALE;
79#endif
80
wdenk2535d602003-07-17 23:16:40 +000081 if(divisor<=0x1000) {
82 cp->cp_brgc1=((divisor-1)<<1) | CPM_BRG_EN;
83 } else {
84 cp->cp_brgc1=((divisor/16-1)<<1) | CPM_BRG_EN | CPM_BRG_DIV16;
85 }
86}
87
wdenk4a9cbbe2002-08-27 09:48:53 +000088#if (defined (CONFIG_8xx_CONS_SMC1) || defined (CONFIG_8xx_CONS_SMC2))
89
90/*
91 * Minimal serial functions needed to use one of the SMC ports
92 * as serial console interface.
93 */
94
wdenk281e00a2004-08-01 22:48:16 +000095static void smc_setbrg (void)
96{
97 volatile immap_t *im = (immap_t *)CFG_IMMR;
98 volatile cpm8xx_t *cp = &(im->im_cpm);
99
100 /* Set up the baud rate generator.
101 * See 8xx_io/commproc.c for details.
102 *
103 * Wire BRG1 to SMCx
104 */
105
106 cp->cp_simode = 0x00000000;
107
108 serial_setdivisor(cp);
109}
110
111static int smc_init (void)
wdenk4a9cbbe2002-08-27 09:48:53 +0000112{
wdenk8bde7f72003-06-27 21:31:46 +0000113 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000114 volatile smc_t *sp;
115 volatile smc_uart_t *up;
116 volatile cbd_t *tbdf, *rbdf;
117 volatile cpm8xx_t *cp = &(im->im_cpm);
118#if (!defined(CONFIG_8xx_CONS_SMC1)) && (defined(CONFIG_MPC823) || defined(CONFIG_MPC850))
119 volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
120#endif
121 uint dpaddr;
122
123 /* initialize pointers to SMC */
124
125 sp = (smc_t *) &(cp->cp_smc[SMC_INDEX]);
126 up = (smc_uart_t *) &cp->cp_dparam[PROFF_SMC];
127
128 /* Disable transmitter/receiver.
129 */
130 sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
131
132 /* Enable SDMA.
133 */
134 im->im_siu_conf.sc_sdcr = 1;
135
136 /* clear error conditions */
137#ifdef CFG_SDSR
138 im->im_sdma.sdma_sdsr = CFG_SDSR;
139#else
140 im->im_sdma.sdma_sdsr = 0x83;
141#endif
142
143 /* clear SDMA interrupt mask */
144#ifdef CFG_SDMR
145 im->im_sdma.sdma_sdmr = CFG_SDMR;
146#else
147 im->im_sdma.sdma_sdmr = 0x00;
148#endif
149
150#if defined(CONFIG_8xx_CONS_SMC1)
151 /* Use Port B for SMC1 instead of other functions.
152 */
153 cp->cp_pbpar |= 0x000000c0;
154 cp->cp_pbdir &= ~0x000000c0;
155 cp->cp_pbodr &= ~0x000000c0;
156#else /* CONFIG_8xx_CONS_SMC2 */
157# if defined(CONFIG_MPC823) || defined(CONFIG_MPC850)
158 /* Use Port A for SMC2 instead of other functions.
159 */
160 ip->iop_papar |= 0x00c0;
161 ip->iop_padir &= ~0x00c0;
162 ip->iop_paodr &= ~0x00c0;
163# else /* must be a 860 then */
164 /* Use Port B for SMC2 instead of other functions.
165 */
166 cp->cp_pbpar |= 0x00000c00;
167 cp->cp_pbdir &= ~0x00000c00;
168 cp->cp_pbodr &= ~0x00000c00;
169# endif
170#endif
171
wdenkb028f712003-12-07 21:39:28 +0000172#if defined(CONFIG_FADS) || defined(CONFIG_ADS)
wdenk4a9cbbe2002-08-27 09:48:53 +0000173 /* Enable RS232 */
174#if defined(CONFIG_8xx_CONS_SMC1)
175 *((uint *) BCSR1) &= ~BCSR1_RS232EN_1;
176#else
177 *((uint *) BCSR1) &= ~BCSR1_RS232EN_2;
178#endif
179#endif /* CONFIG_FADS */
180
181#if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
182 /* Enable Monitor Port Transceiver */
183 *((uchar *) BCSR0) |= BCSR0_ENMONXCVR ;
184#endif /* CONFIG_RPXLITE */
185
186 /* Set the physical address of the host memory buffers in
187 * the buffer descriptors.
188 */
189
190#ifdef CFG_ALLOC_DPRAM
191 dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
192#else
193 dpaddr = CPM_SERIAL_BASE ;
194#endif
195
196 /* Allocate space for two buffer descriptors in the DP ram.
197 * For now, this address seems OK, but it may have to
198 * change with newer versions of the firmware.
199 * damm: allocating space after the two buffers for rx/tx data
200 */
201
202 rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
203 rbdf->cbd_bufaddr = (uint) (rbdf+2);
204 rbdf->cbd_sc = 0;
205 tbdf = rbdf + 1;
206 tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
207 tbdf->cbd_sc = 0;
208
209 /* Set up the uart parameters in the parameter ram.
210 */
211 up->smc_rbase = dpaddr;
212 up->smc_tbase = dpaddr+sizeof(cbd_t);
213 up->smc_rfcr = SMC_EB;
214 up->smc_tfcr = SMC_EB;
215
216#if defined(CONFIG_MBX)
217 board_serial_init();
218#endif /* CONFIG_MBX */
219
220 /* Set UART mode, 8 bit, no parity, one stop.
221 * Enable receive and transmit.
222 */
223 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
224
225 /* Mask all interrupts and remove anything pending.
226 */
227 sp->smc_smcm = 0;
228 sp->smc_smce = 0xff;
229
Markus Klotzbuecherb02d0172006-07-12 08:48:24 +0200230#ifdef CFG_SPC1920_SMC1_CLK4 /* clock source is PLD */
231 *((volatile uchar *) CFG_SPC1920_PLD_BASE+6) = 0xff;
232#else
233 /* Set up the baud rate generator */
wdenk281e00a2004-08-01 22:48:16 +0000234 smc_setbrg ();
Markus Klotzbuecherb02d0172006-07-12 08:48:24 +0200235#endif
wdenk4a9cbbe2002-08-27 09:48:53 +0000236
237 /* Make the first buffer the only buffer.
238 */
239 tbdf->cbd_sc |= BD_SC_WRAP;
240 rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
241
242 /* Single character receive.
243 */
244 up->smc_mrblr = 1;
245 up->smc_maxidl = 0;
246
247 /* Initialize Tx/Rx parameters.
248 */
249
250 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
251 ;
252
253 cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SMC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
254
255 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
256 ;
257
258 /* Enable transmitter/receiver.
259 */
260 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
261
262 return (0);
263}
264
wdenk281e00a2004-08-01 22:48:16 +0000265static void
266smc_putc(const char c)
wdenk4a9cbbe2002-08-27 09:48:53 +0000267{
268 volatile cbd_t *tbdf;
269 volatile char *buf;
270 volatile smc_uart_t *up;
wdenk8bde7f72003-06-27 21:31:46 +0000271 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000272 volatile cpm8xx_t *cpmp = &(im->im_cpm);
273
wdenk4532cb62003-04-27 22:52:51 +0000274#ifdef CONFIG_MODEM_SUPPORT
wdenk4532cb62003-04-27 22:52:51 +0000275 if (gd->be_quiet)
276 return;
277#endif
278
wdenk4a9cbbe2002-08-27 09:48:53 +0000279 if (c == '\n')
wdenk281e00a2004-08-01 22:48:16 +0000280 smc_putc ('\r');
wdenk4a9cbbe2002-08-27 09:48:53 +0000281
282 up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
283
284 tbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_tbase];
285
286 /* Wait for last character to go.
287 */
288
289 buf = (char *)tbdf->cbd_bufaddr;
wdenk4a9cbbe2002-08-27 09:48:53 +0000290
291 *buf = c;
292 tbdf->cbd_datlen = 1;
293 tbdf->cbd_sc |= BD_SC_READY;
294 __asm__("eieio");
wdenkd0fb80c2003-01-11 09:48:40 +0000295
296 while (tbdf->cbd_sc & BD_SC_READY) {
297 WATCHDOG_RESET ();
wdenk4a9cbbe2002-08-27 09:48:53 +0000298 __asm__("eieio");
wdenkd0fb80c2003-01-11 09:48:40 +0000299 }
wdenk4a9cbbe2002-08-27 09:48:53 +0000300}
301
wdenk281e00a2004-08-01 22:48:16 +0000302static void
303smc_puts (const char *s)
304{
305 while (*s) {
306 smc_putc (*s++);
307 }
308}
309
310static int
311smc_getc(void)
wdenk4a9cbbe2002-08-27 09:48:53 +0000312{
313 volatile cbd_t *rbdf;
314 volatile unsigned char *buf;
315 volatile smc_uart_t *up;
wdenk8bde7f72003-06-27 21:31:46 +0000316 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000317 volatile cpm8xx_t *cpmp = &(im->im_cpm);
318 unsigned char c;
319
320 up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
321
322 rbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
323
324 /* Wait for character to show up.
325 */
326 buf = (unsigned char *)rbdf->cbd_bufaddr;
wdenkd0fb80c2003-01-11 09:48:40 +0000327
wdenk4a9cbbe2002-08-27 09:48:53 +0000328 while (rbdf->cbd_sc & BD_SC_EMPTY)
wdenkd0fb80c2003-01-11 09:48:40 +0000329 WATCHDOG_RESET ();
330
wdenk4a9cbbe2002-08-27 09:48:53 +0000331 c = *buf;
332 rbdf->cbd_sc |= BD_SC_EMPTY;
333
334 return(c);
335}
336
wdenk281e00a2004-08-01 22:48:16 +0000337static int
338smc_tstc(void)
wdenk4a9cbbe2002-08-27 09:48:53 +0000339{
340 volatile cbd_t *rbdf;
341 volatile smc_uart_t *up;
wdenk8bde7f72003-06-27 21:31:46 +0000342 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000343 volatile cpm8xx_t *cpmp = &(im->im_cpm);
344
345 up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
346
347 rbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
348
349 return(!(rbdf->cbd_sc & BD_SC_EMPTY));
350}
351
wdenk281e00a2004-08-01 22:48:16 +0000352struct serial_device serial_smc_device =
353{
354 "serial_smc",
355 "SMC",
356 smc_init,
357 smc_setbrg,
358 smc_getc,
359 smc_tstc,
360 smc_putc,
361 smc_puts,
362};
wdenk4a9cbbe2002-08-27 09:48:53 +0000363
wdenk281e00a2004-08-01 22:48:16 +0000364#endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
365
366#if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
367 defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
368
369static void
370scc_setbrg (void)
371{
372 volatile immap_t *im = (immap_t *)CFG_IMMR;
373 volatile cpm8xx_t *cp = &(im->im_cpm);
374
375 /* Set up the baud rate generator.
376 * See 8xx_io/commproc.c for details.
377 *
378 * Wire BRG1 to SCCx
379 */
380
381 cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX));
382
383 serial_setdivisor(cp);
384}
385
386static int scc_init (void)
wdenk4a9cbbe2002-08-27 09:48:53 +0000387{
wdenk8bde7f72003-06-27 21:31:46 +0000388 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000389 volatile scc_t *sp;
390 volatile scc_uart_t *up;
391 volatile cbd_t *tbdf, *rbdf;
392 volatile cpm8xx_t *cp = &(im->im_cpm);
393 uint dpaddr;
394#if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
395 volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
396#endif
397
398 /* initialize pointers to SCC */
399
400 sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]);
401 up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC];
402
403#if defined(CONFIG_LWMON) && defined(CONFIG_8xx_CONS_SCC2)
404 { /* Disable Ethernet, enable Serial */
405 uchar c;
406
407 c = pic_read (0x61);
408 c &= ~0x40; /* enable COM3 */
409 c |= 0x80; /* disable Ethernet */
410 pic_write (0x61, c);
411
412 /* enable RTS2 */
413 cp->cp_pbpar |= 0x2000;
414 cp->cp_pbdat |= 0x2000;
415 cp->cp_pbdir |= 0x2000;
416 }
417#endif /* CONFIG_LWMON */
418
419 /* Disable transmitter/receiver.
420 */
421 sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
422
423#if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
424 /*
425 * The MPC850 has SCC3 on Port B
426 */
427 cp->cp_pbpar |= 0x06;
428 cp->cp_pbdir &= ~0x06;
429 cp->cp_pbodr &= ~0x06;
430
431#elif (SCC_INDEX < 2) || !defined(CONFIG_IP860)
432 /*
433 * Standard configuration for SCC's is on Part A
434 */
435 ip->iop_papar |= ((3 << (2 * SCC_INDEX)));
436 ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
437 ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
438#else
439 /*
440 * The IP860 has SCC3 and SCC4 on Port D
441 */
442 ip->iop_pdpar |= ((3 << (2 * SCC_INDEX)));
443#endif
444
445 /* Allocate space for two buffer descriptors in the DP ram.
446 */
447
448#ifdef CFG_ALLOC_DPRAM
449 dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
450#else
wdenk281e00a2004-08-01 22:48:16 +0000451 dpaddr = CPM_SERIAL2_BASE ;
wdenk4a9cbbe2002-08-27 09:48:53 +0000452#endif
453
454 /* Enable SDMA.
455 */
456 im->im_siu_conf.sc_sdcr = 0x0001;
457
458 /* Set the physical address of the host memory buffers in
459 * the buffer descriptors.
460 */
461
462 rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
463 rbdf->cbd_bufaddr = (uint) (rbdf+2);
464 rbdf->cbd_sc = 0;
465 tbdf = rbdf + 1;
466 tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
467 tbdf->cbd_sc = 0;
468
469 /* Set up the baud rate generator.
470 */
wdenk281e00a2004-08-01 22:48:16 +0000471 scc_setbrg ();
wdenk4a9cbbe2002-08-27 09:48:53 +0000472
473 /* Set up the uart parameters in the parameter ram.
474 */
475 up->scc_genscc.scc_rbase = dpaddr;
476 up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
477
478 /* Initialize Tx/Rx parameters.
479 */
480 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
481 ;
482 cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
483
484 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
485 ;
486
487 up->scc_genscc.scc_rfcr = SCC_EB | 0x05;
488 up->scc_genscc.scc_tfcr = SCC_EB | 0x05;
489
490 up->scc_genscc.scc_mrblr = 1; /* Single character receive */
491 up->scc_maxidl = 0; /* disable max idle */
492 up->scc_brkcr = 1; /* send one break character on stop TX */
493 up->scc_parec = 0;
494 up->scc_frmec = 0;
495 up->scc_nosec = 0;
496 up->scc_brkec = 0;
497 up->scc_uaddr1 = 0;
498 up->scc_uaddr2 = 0;
499 up->scc_toseq = 0;
500 up->scc_char1 = 0x8000;
501 up->scc_char2 = 0x8000;
502 up->scc_char3 = 0x8000;
503 up->scc_char4 = 0x8000;
504 up->scc_char5 = 0x8000;
505 up->scc_char6 = 0x8000;
506 up->scc_char7 = 0x8000;
507 up->scc_char8 = 0x8000;
508 up->scc_rccm = 0xc0ff;
509
510 /* Set low latency / small fifo.
511 */
512 sp->scc_gsmrh = SCC_GSMRH_RFW;
513
514 /* Set SCC(x) clock mode to 16x
515 * See 8xx_io/commproc.c for details.
516 *
517 * Wire BRG1 to SCCn
518 */
519
520 /* Set UART mode, clock divider 16 on Tx and Rx
521 */
wdenk281e00a2004-08-01 22:48:16 +0000522 sp->scc_gsmrl &= ~0xF;
wdenk4a9cbbe2002-08-27 09:48:53 +0000523 sp->scc_gsmrl |=
524 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
525
wdenk281e00a2004-08-01 22:48:16 +0000526 sp->scc_psmr = 0;
wdenk4a9cbbe2002-08-27 09:48:53 +0000527 sp->scc_psmr |= SCU_PSMR_CL;
528
529 /* Mask all interrupts and remove anything pending.
530 */
531 sp->scc_sccm = 0;
532 sp->scc_scce = 0xffff;
533 sp->scc_dsr = 0x7e7e;
534 sp->scc_psmr = 0x3000;
535
536 /* Make the first buffer the only buffer.
537 */
538 tbdf->cbd_sc |= BD_SC_WRAP;
539 rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
540
541 /* Enable transmitter/receiver.
542 */
543 sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
544
545 return (0);
546}
547
wdenk281e00a2004-08-01 22:48:16 +0000548static void
549scc_putc(const char c)
wdenk4a9cbbe2002-08-27 09:48:53 +0000550{
551 volatile cbd_t *tbdf;
552 volatile char *buf;
553 volatile scc_uart_t *up;
wdenk8bde7f72003-06-27 21:31:46 +0000554 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000555 volatile cpm8xx_t *cpmp = &(im->im_cpm);
556
wdenk281e00a2004-08-01 22:48:16 +0000557#ifdef CONFIG_MODEM_SUPPORT
wdenk281e00a2004-08-01 22:48:16 +0000558 if (gd->be_quiet)
559 return;
560#endif
561
wdenk4a9cbbe2002-08-27 09:48:53 +0000562 if (c == '\n')
wdenk281e00a2004-08-01 22:48:16 +0000563 scc_putc ('\r');
wdenk4a9cbbe2002-08-27 09:48:53 +0000564
565 up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
566
567 tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
568
569 /* Wait for last character to go.
570 */
571
572 buf = (char *)tbdf->cbd_bufaddr;
wdenk4a9cbbe2002-08-27 09:48:53 +0000573
574 *buf = c;
575 tbdf->cbd_datlen = 1;
576 tbdf->cbd_sc |= BD_SC_READY;
577 __asm__("eieio");
wdenkd0fb80c2003-01-11 09:48:40 +0000578
579 while (tbdf->cbd_sc & BD_SC_READY) {
wdenk4a9cbbe2002-08-27 09:48:53 +0000580 __asm__("eieio");
wdenkd0fb80c2003-01-11 09:48:40 +0000581 WATCHDOG_RESET ();
582 }
wdenk4a9cbbe2002-08-27 09:48:53 +0000583}
584
wdenk281e00a2004-08-01 22:48:16 +0000585static void
586scc_puts (const char *s)
587{
588 while (*s) {
589 scc_putc (*s++);
590 }
591}
592
593static int
594scc_getc(void)
wdenk4a9cbbe2002-08-27 09:48:53 +0000595{
596 volatile cbd_t *rbdf;
597 volatile unsigned char *buf;
598 volatile scc_uart_t *up;
wdenk8bde7f72003-06-27 21:31:46 +0000599 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000600 volatile cpm8xx_t *cpmp = &(im->im_cpm);
601 unsigned char c;
602
603 up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
604
605 rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
606
607 /* Wait for character to show up.
608 */
609 buf = (unsigned char *)rbdf->cbd_bufaddr;
wdenkd0fb80c2003-01-11 09:48:40 +0000610
wdenk4a9cbbe2002-08-27 09:48:53 +0000611 while (rbdf->cbd_sc & BD_SC_EMPTY)
wdenkd0fb80c2003-01-11 09:48:40 +0000612 WATCHDOG_RESET ();
613
wdenk4a9cbbe2002-08-27 09:48:53 +0000614 c = *buf;
615 rbdf->cbd_sc |= BD_SC_EMPTY;
616
617 return(c);
618}
619
wdenk281e00a2004-08-01 22:48:16 +0000620static int
621scc_tstc(void)
wdenk4a9cbbe2002-08-27 09:48:53 +0000622{
623 volatile cbd_t *rbdf;
624 volatile scc_uart_t *up;
wdenk8bde7f72003-06-27 21:31:46 +0000625 volatile immap_t *im = (immap_t *)CFG_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000626 volatile cpm8xx_t *cpmp = &(im->im_cpm);
627
628 up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
629
630 rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
631
632 return(!(rbdf->cbd_sc & BD_SC_EMPTY));
633}
634
wdenk281e00a2004-08-01 22:48:16 +0000635struct serial_device serial_scc_device =
wdenk4a9cbbe2002-08-27 09:48:53 +0000636{
wdenk281e00a2004-08-01 22:48:16 +0000637 "serial_scc",
638 "SCC",
639 scc_init,
640 scc_setbrg,
641 scc_getc,
642 scc_tstc,
643 scc_putc,
644 scc_puts,
645};
646
647#endif /* CONFIG_8xx_CONS_SCCx */
648
649#ifdef CONFIG_MODEM_SUPPORT
650void disable_putc(void)
651{
wdenk281e00a2004-08-01 22:48:16 +0000652 gd->be_quiet = 1;
wdenk4a9cbbe2002-08-27 09:48:53 +0000653}
654
wdenk281e00a2004-08-01 22:48:16 +0000655void enable_putc(void)
656{
wdenk281e00a2004-08-01 22:48:16 +0000657 gd->be_quiet = 0;
658}
659#endif
wdenk4a9cbbe2002-08-27 09:48:53 +0000660
661#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
662
663void
664kgdb_serial_init(void)
665{
wdenk281e00a2004-08-01 22:48:16 +0000666 int i = -1;
667
668 if (strcmp(default_serial_console()->ctlr, "SMC") == 0)
669 {
wdenk4a9cbbe2002-08-27 09:48:53 +0000670#if defined(CONFIG_8xx_CONS_SMC1)
wdenk281e00a2004-08-01 22:48:16 +0000671 i = 1;
wdenk4a9cbbe2002-08-27 09:48:53 +0000672#elif defined(CONFIG_8xx_CONS_SMC2)
wdenk281e00a2004-08-01 22:48:16 +0000673 i = 2;
wdenk4a9cbbe2002-08-27 09:48:53 +0000674#endif
wdenk281e00a2004-08-01 22:48:16 +0000675 }
676 else if (strcmp(default_serial_console()->ctlr, "SMC") == 0)
677 {
678#if defined(CONFIG_8xx_CONS_SCC1)
679 i = 1;
680#elif defined(CONFIG_8xx_CONS_SCC2)
681 i = 2;
682#elif defined(CONFIG_8xx_CONS_SCC3)
683 i = 3;
684#elif defined(CONFIG_8xx_CONS_SCC4)
685 i = 4;
686#endif
687 }
688
689 if (i >= 0)
690 {
691 serial_printf("[on %s%d] ", default_serial_console()->ctlr, i);
692 }
wdenk4a9cbbe2002-08-27 09:48:53 +0000693}
694
695void
696putDebugChar (int c)
697{
698 serial_putc (c);
699}
700
701void
702putDebugStr (const char *str)
703{
704 serial_puts (str);
705}
706
707int
708getDebugChar (void)
709{
710 return serial_getc();
711}
712
713void
714kgdb_interruptible (int yes)
715{
716 return;
717}
718#endif /* CFG_CMD_KGDB */
719
720#endif /* CONFIG_8xx_CONS_NONE */