]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - arch/powerpc/cpu/mpc8xx/serial.c
802d4f1ca8116943792e1adb5b9f9066daa02d90
[karo-tx-uboot.git] / arch / powerpc / cpu / mpc8xx / serial.c
1 /*
2  * (C) Copyright 2000
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <commproc.h>
10 #include <command.h>
11 #include <serial.h>
12 #include <watchdog.h>
13 #include <linux/compiler.h>
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 #if !defined(CONFIG_8xx_CONS_NONE)      /* No Console at all */
18
19 #if defined(CONFIG_8xx_CONS_SMC1)       /* Console on SMC1 */
20 #define SMC_INDEX       0
21 #define PROFF_SMC       PROFF_SMC1
22 #define CPM_CR_CH_SMC   CPM_CR_CH_SMC1
23
24 #elif defined(CONFIG_8xx_CONS_SMC2)     /* Console on SMC2 */
25 #define SMC_INDEX       1
26 #define PROFF_SMC       PROFF_SMC2
27 #define CPM_CR_CH_SMC   CPM_CR_CH_SMC2
28
29 #endif /* CONFIG_8xx_CONS_SMCx */
30
31 #if defined(CONFIG_8xx_CONS_SCC1)       /* Console on SCC1 */
32 #define SCC_INDEX       0
33 #define PROFF_SCC       PROFF_SCC1
34 #define CPM_CR_CH_SCC   CPM_CR_CH_SCC1
35
36 #elif defined(CONFIG_8xx_CONS_SCC2)     /* Console on SCC2 */
37 #define SCC_INDEX       1
38 #define PROFF_SCC       PROFF_SCC2
39 #define CPM_CR_CH_SCC   CPM_CR_CH_SCC2
40
41 #elif defined(CONFIG_8xx_CONS_SCC3)     /* Console on SCC3 */
42 #define SCC_INDEX       2
43 #define PROFF_SCC       PROFF_SCC3
44 #define CPM_CR_CH_SCC   CPM_CR_CH_SCC3
45
46 #elif defined(CONFIG_8xx_CONS_SCC4)     /* Console on SCC4 */
47 #define SCC_INDEX       3
48 #define PROFF_SCC       PROFF_SCC4
49 #define CPM_CR_CH_SCC   CPM_CR_CH_SCC4
50
51 #endif /* CONFIG_8xx_CONS_SCCx */
52
53 #if !defined(CONFIG_SYS_SMC_RXBUFLEN)
54 #define CONFIG_SYS_SMC_RXBUFLEN 1
55 #define CONFIG_SYS_MAXIDLE      0
56 #else
57 #if !defined(CONFIG_SYS_MAXIDLE)
58 #error "you must define CONFIG_SYS_MAXIDLE"
59 #endif
60 #endif
61
62 typedef volatile struct serialbuffer {
63         cbd_t   rxbd;           /* Rx BD */
64         cbd_t   txbd;           /* Tx BD */
65         uint    rxindex;        /* index for next character to read */
66         volatile uchar  rxbuf[CONFIG_SYS_SMC_RXBUFLEN];/* rx buffers */
67         volatile uchar  txbuf;  /* tx buffers */
68 } serialbuffer_t;
69
70 static void serial_setdivisor(volatile cpm8xx_t *cp)
71 {
72         int divisor=(gd->cpu_clk + 8*gd->baudrate)/16/gd->baudrate;
73
74         if(divisor/16>0x1000) {
75                 /* bad divisor, assume 50MHz clock and 9600 baud */
76                 divisor=(50*1000*1000 + 8*9600)/16/9600;
77         }
78
79 #ifdef CONFIG_SYS_BRGCLK_PRESCALE
80         divisor /= CONFIG_SYS_BRGCLK_PRESCALE;
81 #endif
82
83         if(divisor<=0x1000) {
84                 cp->cp_brgc1=((divisor-1)<<1) | CPM_BRG_EN;
85         } else {
86                 cp->cp_brgc1=((divisor/16-1)<<1) | CPM_BRG_EN | CPM_BRG_DIV16;
87         }
88 }
89
90 #if (defined (CONFIG_8xx_CONS_SMC1) || defined (CONFIG_8xx_CONS_SMC2))
91
92 /*
93  * Minimal serial functions needed to use one of the SMC ports
94  * as serial console interface.
95  */
96
97 static void smc_setbrg (void)
98 {
99         volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
100         volatile cpm8xx_t *cp = &(im->im_cpm);
101
102         /* Set up the baud rate generator.
103          * See 8xx_io/commproc.c for details.
104          *
105          * Wire BRG1 to SMCx
106          */
107
108         cp->cp_simode = 0x00000000;
109
110         serial_setdivisor(cp);
111 }
112
113 static int smc_init (void)
114 {
115         volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
116         volatile smc_t *sp;
117         volatile smc_uart_t *up;
118         volatile cpm8xx_t *cp = &(im->im_cpm);
119 #if (!defined(CONFIG_8xx_CONS_SMC1)) && (defined(CONFIG_MPC823) || defined(CONFIG_MPC850))
120         volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
121 #endif
122         uint    dpaddr;
123         volatile serialbuffer_t *rtx;
124
125         /* initialize pointers to SMC */
126
127         sp = (smc_t *) &(cp->cp_smc[SMC_INDEX]);
128         up = (smc_uart_t *) &cp->cp_dparam[PROFF_SMC];
129 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
130         up = (smc_uart_t *) &cp->cp_dpmem[up->smc_rpbase];
131 #else
132         /* Disable relocation */
133         up->smc_rpbase = 0;
134 #endif
135
136         /* Disable transmitter/receiver. */
137         sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
138
139         /* Enable SDMA. */
140         im->im_siu_conf.sc_sdcr = 1;
141
142         /* clear error conditions */
143 #ifdef  CONFIG_SYS_SDSR
144         im->im_sdma.sdma_sdsr = CONFIG_SYS_SDSR;
145 #else
146         im->im_sdma.sdma_sdsr = 0x83;
147 #endif
148
149         /* clear SDMA interrupt mask */
150 #ifdef  CONFIG_SYS_SDMR
151         im->im_sdma.sdma_sdmr = CONFIG_SYS_SDMR;
152 #else
153         im->im_sdma.sdma_sdmr = 0x00;
154 #endif
155
156 #if defined(CONFIG_8xx_CONS_SMC1)
157         /* Use Port B for SMC1 instead of other functions. */
158         cp->cp_pbpar |=  0x000000c0;
159         cp->cp_pbdir &= ~0x000000c0;
160         cp->cp_pbodr &= ~0x000000c0;
161 #else   /* CONFIG_8xx_CONS_SMC2 */
162 # if defined(CONFIG_MPC823) || defined(CONFIG_MPC850)
163         /* Use Port A for SMC2 instead of other functions. */
164         ip->iop_papar |=  0x00c0;
165         ip->iop_padir &= ~0x00c0;
166         ip->iop_paodr &= ~0x00c0;
167 # else  /* must be a 860 then */
168         /* Use Port B for SMC2 instead of other functions.
169          */
170         cp->cp_pbpar |=  0x00000c00;
171         cp->cp_pbdir &= ~0x00000c00;
172         cp->cp_pbodr &= ~0x00000c00;
173 # endif
174 #endif
175
176 #if defined(CONFIG_FADS)
177         /* Enable RS232 */
178 #if defined(CONFIG_8xx_CONS_SMC1)
179         *((uint *) BCSR1) &= ~BCSR1_RS232EN_1;
180 #else
181         *((uint *) BCSR1) &= ~BCSR1_RS232EN_2;
182 #endif
183 #endif  /* CONFIG_FADS */
184
185         /* Set the physical address of the host memory buffers in
186          * the buffer descriptors.
187          */
188
189 #ifdef CONFIG_SYS_ALLOC_DPRAM
190         /* allocate
191          * size of struct serialbuffer with bd rx/tx, buffer rx/tx and rx index
192          */
193         dpaddr = dpram_alloc_align((sizeof(serialbuffer_t)), 8);
194 #else
195         dpaddr = CPM_SERIAL_BASE ;
196 #endif
197
198         rtx = (serialbuffer_t *)&cp->cp_dpmem[dpaddr];
199         /* Allocate space for two buffer descriptors in the DP ram.
200          * For now, this address seems OK, but it may have to
201          * change with newer versions of the firmware.
202          * damm: allocating space after the two buffers for rx/tx data
203          */
204
205         rtx->rxbd.cbd_bufaddr = (uint) &rtx->rxbuf;
206         rtx->rxbd.cbd_sc      = 0;
207
208         rtx->txbd.cbd_bufaddr = (uint) &rtx->txbuf;
209         rtx->txbd.cbd_sc      = 0;
210
211         /* Set up the uart parameters in the parameter ram. */
212         up->smc_rbase = dpaddr;
213         up->smc_tbase = dpaddr+sizeof(cbd_t);
214         up->smc_rfcr = SMC_EB;
215         up->smc_tfcr = SMC_EB;
216 #if defined (CONFIG_SYS_SMC_UCODE_PATCH)
217         up->smc_rbptr = up->smc_rbase;
218         up->smc_tbptr = up->smc_tbase;
219         up->smc_rstate = 0;
220         up->smc_tstate = 0;
221 #endif
222
223         /* Set UART mode, 8 bit, no parity, one stop.
224          * Enable receive and transmit.
225          */
226         sp->smc_smcmr = smcr_mk_clen(9) |  SMCMR_SM_UART;
227
228         /* Mask all interrupts and remove anything pending.
229         */
230         sp->smc_smcm = 0;
231         sp->smc_smce = 0xff;
232
233 #ifdef CONFIG_SYS_SPC1920_SMC1_CLK4
234         /* clock source is PLD */
235
236         /* set freq to 19200 Baud */
237         *((volatile uchar *) CONFIG_SYS_SPC1920_PLD_BASE+6) = 0x3;
238         /* configure clk4 as input */
239         im->im_ioport.iop_pdpar |= 0x800;
240         im->im_ioport.iop_pddir &= ~0x800;
241
242         cp->cp_simode = ((cp->cp_simode & ~0xf000) | 0x7000);
243 #else
244         /* Set up the baud rate generator */
245         smc_setbrg ();
246 #endif
247
248         /* Make the first buffer the only buffer. */
249         rtx->txbd.cbd_sc |= BD_SC_WRAP;
250         rtx->rxbd.cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
251
252         /* single/multi character receive. */
253         up->smc_mrblr = CONFIG_SYS_SMC_RXBUFLEN;
254         up->smc_maxidl = CONFIG_SYS_MAXIDLE;
255         rtx->rxindex = 0;
256
257         /* Initialize Tx/Rx parameters. */
258         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
259           ;
260
261         cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SMC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
262
263         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
264           ;
265
266         /* Enable transmitter/receiver. */
267         sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
268
269         return (0);
270 }
271
272 static void
273 smc_putc(const char c)
274 {
275         volatile smc_uart_t     *up;
276         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
277         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
278         volatile serialbuffer_t *rtx;
279
280 #ifdef CONFIG_MODEM_SUPPORT
281         if (gd->be_quiet)
282                 return;
283 #endif
284
285         if (c == '\n')
286                 smc_putc ('\r');
287
288         up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
289 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
290         up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
291 #endif
292
293         rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
294
295         /* Wait for last character to go. */
296         rtx->txbuf = c;
297         rtx->txbd.cbd_datlen = 1;
298         rtx->txbd.cbd_sc |= BD_SC_READY;
299         __asm__("eieio");
300
301         while (rtx->txbd.cbd_sc & BD_SC_READY) {
302                 WATCHDOG_RESET ();
303                 __asm__("eieio");
304         }
305 }
306
307 static void
308 smc_puts (const char *s)
309 {
310         while (*s) {
311                 smc_putc (*s++);
312         }
313 }
314
315 static int
316 smc_getc(void)
317 {
318         volatile smc_uart_t     *up;
319         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
320         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
321         volatile serialbuffer_t *rtx;
322         unsigned char  c;
323
324         up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
325 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
326         up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
327 #endif
328         rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
329
330         /* Wait for character to show up. */
331         while (rtx->rxbd.cbd_sc & BD_SC_EMPTY)
332                 WATCHDOG_RESET ();
333
334         /* the characters are read one by one,
335          * use the rxindex to know the next char to deliver
336          */
337         c = *(unsigned char *) (rtx->rxbd.cbd_bufaddr+rtx->rxindex);
338         rtx->rxindex++;
339
340         /* check if all char are readout, then make prepare for next receive */
341         if (rtx->rxindex >= rtx->rxbd.cbd_datlen) {
342                 rtx->rxindex = 0;
343                 rtx->rxbd.cbd_sc |= BD_SC_EMPTY;
344         }
345         return(c);
346 }
347
348 static int
349 smc_tstc(void)
350 {
351         volatile smc_uart_t     *up;
352         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
353         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
354         volatile serialbuffer_t *rtx;
355
356         up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
357 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
358         up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
359 #endif
360
361         rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
362
363         return !(rtx->rxbd.cbd_sc & BD_SC_EMPTY);
364 }
365
366 struct serial_device serial_smc_device =
367 {
368         .name   = "serial_smc",
369         .start  = smc_init,
370         .stop   = NULL,
371         .setbrg = smc_setbrg,
372         .getc   = smc_getc,
373         .tstc   = smc_tstc,
374         .putc   = smc_putc,
375         .puts   = smc_puts,
376 };
377
378 #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
379
380 #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
381     defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
382
383 static void
384 scc_setbrg (void)
385 {
386         volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
387         volatile cpm8xx_t *cp = &(im->im_cpm);
388
389         /* Set up the baud rate generator.
390          * See 8xx_io/commproc.c for details.
391          *
392          * Wire BRG1 to SCCx
393          */
394
395         cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX));
396
397         serial_setdivisor(cp);
398 }
399
400 static int scc_init (void)
401 {
402         volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
403         volatile scc_t *sp;
404         volatile scc_uart_t *up;
405         volatile cbd_t *tbdf, *rbdf;
406         volatile cpm8xx_t *cp = &(im->im_cpm);
407         uint     dpaddr;
408 #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
409         volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport);
410 #endif
411
412         /* initialize pointers to SCC */
413
414         sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]);
415         up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC];
416
417 #if defined(CONFIG_LWMON) && defined(CONFIG_8xx_CONS_SCC2)
418     {   /* Disable Ethernet, enable Serial */
419         uchar c;
420
421         c = pic_read  (0x61);
422         c &= ~0x40;     /* enable COM3 */
423         c |=  0x80;     /* disable Ethernet */
424         pic_write (0x61, c);
425
426         /* enable RTS2 */
427         cp->cp_pbpar |=  0x2000;
428         cp->cp_pbdat |=  0x2000;
429         cp->cp_pbdir |=  0x2000;
430     }
431 #endif  /* CONFIG_LWMON */
432
433         /* Disable transmitter/receiver. */
434         sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
435
436 #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
437         /*
438          * The MPC850 has SCC3 on Port B
439          */
440         cp->cp_pbpar |=  0x06;
441         cp->cp_pbdir &= ~0x06;
442         cp->cp_pbodr &= ~0x06;
443
444 #elif (SCC_INDEX < 2) || !defined(CONFIG_IP860)
445         /*
446          * Standard configuration for SCC's is on Part A
447          */
448         ip->iop_papar |=  ((3 << (2 * SCC_INDEX)));
449         ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
450         ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
451 #else
452         /*
453          * The IP860 has SCC3 and SCC4 on Port D
454          */
455         ip->iop_pdpar |=  ((3 << (2 * SCC_INDEX)));
456 #endif
457
458         /* Allocate space for two buffer descriptors in the DP ram. */
459
460 #ifdef CONFIG_SYS_ALLOC_DPRAM
461         dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
462 #else
463         dpaddr = CPM_SERIAL2_BASE ;
464 #endif
465
466         /* Enable SDMA. */
467         im->im_siu_conf.sc_sdcr = 0x0001;
468
469         /* Set the physical address of the host memory buffers in
470          * the buffer descriptors.
471          */
472
473         rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
474         rbdf->cbd_bufaddr = (uint) (rbdf+2);
475         rbdf->cbd_sc = 0;
476         tbdf = rbdf + 1;
477         tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
478         tbdf->cbd_sc = 0;
479
480         /* Set up the baud rate generator. */
481         scc_setbrg ();
482
483         /* Set up the uart parameters in the parameter ram. */
484         up->scc_genscc.scc_rbase = dpaddr;
485         up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
486
487         /* Initialize Tx/Rx parameters. */
488         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
489                 ;
490         cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
491
492         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
493                 ;
494
495         up->scc_genscc.scc_rfcr  = SCC_EB | 0x05;
496         up->scc_genscc.scc_tfcr  = SCC_EB | 0x05;
497
498         up->scc_genscc.scc_mrblr = 1;   /* Single character receive */
499         up->scc_maxidl = 0;             /* disable max idle */
500         up->scc_brkcr  = 1;             /* send one break character on stop TX */
501         up->scc_parec  = 0;
502         up->scc_frmec  = 0;
503         up->scc_nosec  = 0;
504         up->scc_brkec  = 0;
505         up->scc_uaddr1 = 0;
506         up->scc_uaddr2 = 0;
507         up->scc_toseq  = 0;
508         up->scc_char1  = 0x8000;
509         up->scc_char2  = 0x8000;
510         up->scc_char3  = 0x8000;
511         up->scc_char4  = 0x8000;
512         up->scc_char5  = 0x8000;
513         up->scc_char6  = 0x8000;
514         up->scc_char7  = 0x8000;
515         up->scc_char8  = 0x8000;
516         up->scc_rccm   = 0xc0ff;
517
518         /* Set low latency / small fifo. */
519         sp->scc_gsmrh = SCC_GSMRH_RFW;
520
521         /* Set SCC(x) clock mode to 16x
522          * See 8xx_io/commproc.c for details.
523          *
524          * Wire BRG1 to SCCn
525          */
526
527         /* Set UART mode, clock divider 16 on Tx and Rx */
528         sp->scc_gsmrl &= ~0xF;
529         sp->scc_gsmrl |=
530                 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
531
532         sp->scc_psmr  = 0;
533         sp->scc_psmr  |= SCU_PSMR_CL;
534
535         /* Mask all interrupts and remove anything pending. */
536         sp->scc_sccm = 0;
537         sp->scc_scce = 0xffff;
538         sp->scc_dsr  = 0x7e7e;
539         sp->scc_psmr = 0x3000;
540
541         /* Make the first buffer the only buffer. */
542         tbdf->cbd_sc |= BD_SC_WRAP;
543         rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
544
545         /* Enable transmitter/receiver. */
546         sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
547
548         return (0);
549 }
550
551 static void
552 scc_putc(const char c)
553 {
554         volatile cbd_t          *tbdf;
555         volatile char           *buf;
556         volatile scc_uart_t     *up;
557         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
558         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
559
560 #ifdef CONFIG_MODEM_SUPPORT
561         if (gd->be_quiet)
562                 return;
563 #endif
564
565         if (c == '\n')
566                 scc_putc ('\r');
567
568         up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
569
570         tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
571
572         /* Wait for last character to go. */
573
574         buf = (char *)tbdf->cbd_bufaddr;
575
576         *buf = c;
577         tbdf->cbd_datlen = 1;
578         tbdf->cbd_sc |= BD_SC_READY;
579         __asm__("eieio");
580
581         while (tbdf->cbd_sc & BD_SC_READY) {
582                 __asm__("eieio");
583                 WATCHDOG_RESET ();
584         }
585 }
586
587 static void
588 scc_puts (const char *s)
589 {
590         while (*s) {
591                 scc_putc (*s++);
592         }
593 }
594
595 static int
596 scc_getc(void)
597 {
598         volatile cbd_t          *rbdf;
599         volatile unsigned char  *buf;
600         volatile scc_uart_t     *up;
601         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
602         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
603         unsigned char           c;
604
605         up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
606
607         rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
608
609         /* Wait for character to show up. */
610         buf = (unsigned char *)rbdf->cbd_bufaddr;
611
612         while (rbdf->cbd_sc & BD_SC_EMPTY)
613                 WATCHDOG_RESET ();
614
615         c = *buf;
616         rbdf->cbd_sc |= BD_SC_EMPTY;
617
618         return(c);
619 }
620
621 static int
622 scc_tstc(void)
623 {
624         volatile cbd_t          *rbdf;
625         volatile scc_uart_t     *up;
626         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
627         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
628
629         up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
630
631         rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
632
633         return(!(rbdf->cbd_sc & BD_SC_EMPTY));
634 }
635
636 struct serial_device serial_scc_device =
637 {
638         .name   = "serial_scc",
639         .start  = scc_init,
640         .stop   = NULL,
641         .setbrg = scc_setbrg,
642         .getc   = scc_getc,
643         .tstc   = scc_tstc,
644         .putc   = scc_putc,
645         .puts   = scc_puts,
646 };
647
648 #endif  /* CONFIG_8xx_CONS_SCCx */
649
650 __weak struct serial_device *default_serial_console(void)
651 {
652 #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
653         return &serial_smc_device;
654 #else
655         return &serial_scc_device;
656 #endif
657 }
658
659 void mpc8xx_serial_initialize(void)
660 {
661 #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
662         serial_register(&serial_smc_device);
663 #endif
664 #if     defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
665         defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
666         serial_register(&serial_scc_device);
667 #endif
668 }
669
670 #ifdef CONFIG_MODEM_SUPPORT
671 void disable_putc(void)
672 {
673         gd->be_quiet = 1;
674 }
675
676 void enable_putc(void)
677 {
678         gd->be_quiet = 0;
679 }
680 #endif
681
682 #if defined(CONFIG_CMD_KGDB)
683
684 void
685 kgdb_serial_init(void)
686 {
687         int i = -1;
688
689         if (strcmp(default_serial_console()->name, "serial_smc") == 0)
690         {
691 #if defined(CONFIG_8xx_CONS_SMC1)
692                 i = 1;
693 #elif defined(CONFIG_8xx_CONS_SMC2)
694                 i = 2;
695 #endif
696         }
697         else if (strcmp(default_serial_console()->name, "serial_scc") == 0)
698         {
699 #if defined(CONFIG_8xx_CONS_SCC1)
700                 i = 1;
701 #elif defined(CONFIG_8xx_CONS_SCC2)
702                 i = 2;
703 #elif defined(CONFIG_8xx_CONS_SCC3)
704                 i = 3;
705 #elif defined(CONFIG_8xx_CONS_SCC4)
706                 i = 4;
707 #endif
708         }
709
710         if (i >= 0)
711         {
712                 serial_printf("[on %s%d] ", default_serial_console()->name, i);
713         }
714 }
715
716 void
717 putDebugChar (int c)
718 {
719         serial_putc (c);
720 }
721
722 void
723 putDebugStr (const char *str)
724 {
725         serial_puts (str);
726 }
727
728 int
729 getDebugChar (void)
730 {
731         return serial_getc();
732 }
733
734 void
735 kgdb_interruptible (int yes)
736 {
737         return;
738 }
739 #endif
740
741 #endif  /* CONFIG_8xx_CONS_NONE */