94c785f611c6ed93a684c94d7325f5a003bf70a3
[oweals/u-boot.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         /* Set the physical address of the host memory buffers in
177          * the buffer descriptors.
178          */
179
180 #ifdef CONFIG_SYS_ALLOC_DPRAM
181         /* allocate
182          * size of struct serialbuffer with bd rx/tx, buffer rx/tx and rx index
183          */
184         dpaddr = dpram_alloc_align((sizeof(serialbuffer_t)), 8);
185 #else
186         dpaddr = CPM_SERIAL_BASE ;
187 #endif
188
189         rtx = (serialbuffer_t *)&cp->cp_dpmem[dpaddr];
190         /* Allocate space for two buffer descriptors in the DP ram.
191          * For now, this address seems OK, but it may have to
192          * change with newer versions of the firmware.
193          * damm: allocating space after the two buffers for rx/tx data
194          */
195
196         rtx->rxbd.cbd_bufaddr = (uint) &rtx->rxbuf;
197         rtx->rxbd.cbd_sc      = 0;
198
199         rtx->txbd.cbd_bufaddr = (uint) &rtx->txbuf;
200         rtx->txbd.cbd_sc      = 0;
201
202         /* Set up the uart parameters in the parameter ram. */
203         up->smc_rbase = dpaddr;
204         up->smc_tbase = dpaddr+sizeof(cbd_t);
205         up->smc_rfcr = SMC_EB;
206         up->smc_tfcr = SMC_EB;
207 #if defined (CONFIG_SYS_SMC_UCODE_PATCH)
208         up->smc_rbptr = up->smc_rbase;
209         up->smc_tbptr = up->smc_tbase;
210         up->smc_rstate = 0;
211         up->smc_tstate = 0;
212 #endif
213
214         /* Set UART mode, 8 bit, no parity, one stop.
215          * Enable receive and transmit.
216          */
217         sp->smc_smcmr = smcr_mk_clen(9) |  SMCMR_SM_UART;
218
219         /* Mask all interrupts and remove anything pending.
220         */
221         sp->smc_smcm = 0;
222         sp->smc_smce = 0xff;
223
224 #ifdef CONFIG_SYS_SPC1920_SMC1_CLK4
225         /* clock source is PLD */
226
227         /* set freq to 19200 Baud */
228         *((volatile uchar *) CONFIG_SYS_SPC1920_PLD_BASE+6) = 0x3;
229         /* configure clk4 as input */
230         im->im_ioport.iop_pdpar |= 0x800;
231         im->im_ioport.iop_pddir &= ~0x800;
232
233         cp->cp_simode = ((cp->cp_simode & ~0xf000) | 0x7000);
234 #else
235         /* Set up the baud rate generator */
236         smc_setbrg ();
237 #endif
238
239         /* Make the first buffer the only buffer. */
240         rtx->txbd.cbd_sc |= BD_SC_WRAP;
241         rtx->rxbd.cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
242
243         /* single/multi character receive. */
244         up->smc_mrblr = CONFIG_SYS_SMC_RXBUFLEN;
245         up->smc_maxidl = CONFIG_SYS_MAXIDLE;
246         rtx->rxindex = 0;
247
248         /* Initialize Tx/Rx parameters. */
249         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
250           ;
251
252         cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SMC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
253
254         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
255           ;
256
257         /* Enable transmitter/receiver. */
258         sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
259
260         return (0);
261 }
262
263 static void
264 smc_putc(const char c)
265 {
266         volatile smc_uart_t     *up;
267         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
268         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
269         volatile serialbuffer_t *rtx;
270
271         if (c == '\n')
272                 smc_putc ('\r');
273
274         up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
275 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
276         up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
277 #endif
278
279         rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
280
281         /* Wait for last character to go. */
282         rtx->txbuf = c;
283         rtx->txbd.cbd_datlen = 1;
284         rtx->txbd.cbd_sc |= BD_SC_READY;
285         __asm__("eieio");
286
287         while (rtx->txbd.cbd_sc & BD_SC_READY) {
288                 WATCHDOG_RESET ();
289                 __asm__("eieio");
290         }
291 }
292
293 static void
294 smc_puts (const char *s)
295 {
296         while (*s) {
297                 smc_putc (*s++);
298         }
299 }
300
301 static int
302 smc_getc(void)
303 {
304         volatile smc_uart_t     *up;
305         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
306         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
307         volatile serialbuffer_t *rtx;
308         unsigned char  c;
309
310         up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
311 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
312         up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
313 #endif
314         rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
315
316         /* Wait for character to show up. */
317         while (rtx->rxbd.cbd_sc & BD_SC_EMPTY)
318                 WATCHDOG_RESET ();
319
320         /* the characters are read one by one,
321          * use the rxindex to know the next char to deliver
322          */
323         c = *(unsigned char *) (rtx->rxbd.cbd_bufaddr+rtx->rxindex);
324         rtx->rxindex++;
325
326         /* check if all char are readout, then make prepare for next receive */
327         if (rtx->rxindex >= rtx->rxbd.cbd_datlen) {
328                 rtx->rxindex = 0;
329                 rtx->rxbd.cbd_sc |= BD_SC_EMPTY;
330         }
331         return(c);
332 }
333
334 static int
335 smc_tstc(void)
336 {
337         volatile smc_uart_t     *up;
338         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
339         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
340         volatile serialbuffer_t *rtx;
341
342         up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC];
343 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
344         up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase];
345 #endif
346
347         rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase];
348
349         return !(rtx->rxbd.cbd_sc & BD_SC_EMPTY);
350 }
351
352 struct serial_device serial_smc_device =
353 {
354         .name   = "serial_smc",
355         .start  = smc_init,
356         .stop   = NULL,
357         .setbrg = smc_setbrg,
358         .getc   = smc_getc,
359         .tstc   = smc_tstc,
360         .putc   = smc_putc,
361         .puts   = smc_puts,
362 };
363
364 #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
369 static void
370 scc_setbrg (void)
371 {
372         volatile immap_t *im = (immap_t *)CONFIG_SYS_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
386 static int scc_init (void)
387 {
388         volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
389         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         /* Disable transmitter/receiver. */
404         sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
405
406 #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
407         /*
408          * The MPC850 has SCC3 on Port B
409          */
410         cp->cp_pbpar |=  0x06;
411         cp->cp_pbdir &= ~0x06;
412         cp->cp_pbodr &= ~0x06;
413
414 #elif (SCC_INDEX < 2)
415         /*
416          * Standard configuration for SCC's is on Part A
417          */
418         ip->iop_papar |=  ((3 << (2 * SCC_INDEX)));
419         ip->iop_padir &= ~((3 << (2 * SCC_INDEX)));
420         ip->iop_paodr &= ~((3 << (2 * SCC_INDEX)));
421 #endif
422
423         /* Allocate space for two buffer descriptors in the DP ram. */
424
425 #ifdef CONFIG_SYS_ALLOC_DPRAM
426         dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ;
427 #else
428         dpaddr = CPM_SERIAL2_BASE ;
429 #endif
430
431         /* Enable SDMA. */
432         im->im_siu_conf.sc_sdcr = 0x0001;
433
434         /* Set the physical address of the host memory buffers in
435          * the buffer descriptors.
436          */
437
438         rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
439         rbdf->cbd_bufaddr = (uint) (rbdf+2);
440         rbdf->cbd_sc = 0;
441         tbdf = rbdf + 1;
442         tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
443         tbdf->cbd_sc = 0;
444
445         /* Set up the baud rate generator. */
446         scc_setbrg ();
447
448         /* Set up the uart parameters in the parameter ram. */
449         up->scc_genscc.scc_rbase = dpaddr;
450         up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
451
452         /* Initialize Tx/Rx parameters. */
453         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
454                 ;
455         cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG;
456
457         while (cp->cp_cpcr & CPM_CR_FLG)  /* wait if cp is busy */
458                 ;
459
460         up->scc_genscc.scc_rfcr  = SCC_EB | 0x05;
461         up->scc_genscc.scc_tfcr  = SCC_EB | 0x05;
462
463         up->scc_genscc.scc_mrblr = 1;   /* Single character receive */
464         up->scc_maxidl = 0;             /* disable max idle */
465         up->scc_brkcr  = 1;             /* send one break character on stop TX */
466         up->scc_parec  = 0;
467         up->scc_frmec  = 0;
468         up->scc_nosec  = 0;
469         up->scc_brkec  = 0;
470         up->scc_uaddr1 = 0;
471         up->scc_uaddr2 = 0;
472         up->scc_toseq  = 0;
473         up->scc_char1  = 0x8000;
474         up->scc_char2  = 0x8000;
475         up->scc_char3  = 0x8000;
476         up->scc_char4  = 0x8000;
477         up->scc_char5  = 0x8000;
478         up->scc_char6  = 0x8000;
479         up->scc_char7  = 0x8000;
480         up->scc_char8  = 0x8000;
481         up->scc_rccm   = 0xc0ff;
482
483         /* Set low latency / small fifo. */
484         sp->scc_gsmrh = SCC_GSMRH_RFW;
485
486         /* Set SCC(x) clock mode to 16x
487          * See 8xx_io/commproc.c for details.
488          *
489          * Wire BRG1 to SCCn
490          */
491
492         /* Set UART mode, clock divider 16 on Tx and Rx */
493         sp->scc_gsmrl &= ~0xF;
494         sp->scc_gsmrl |=
495                 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
496
497         sp->scc_psmr  = 0;
498         sp->scc_psmr  |= SCU_PSMR_CL;
499
500         /* Mask all interrupts and remove anything pending. */
501         sp->scc_sccm = 0;
502         sp->scc_scce = 0xffff;
503         sp->scc_dsr  = 0x7e7e;
504         sp->scc_psmr = 0x3000;
505
506         /* Make the first buffer the only buffer. */
507         tbdf->cbd_sc |= BD_SC_WRAP;
508         rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
509
510         /* Enable transmitter/receiver. */
511         sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
512
513         return (0);
514 }
515
516 static void
517 scc_putc(const char c)
518 {
519         volatile cbd_t          *tbdf;
520         volatile char           *buf;
521         volatile scc_uart_t     *up;
522         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
523         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
524
525         if (c == '\n')
526                 scc_putc ('\r');
527
528         up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
529
530         tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
531
532         /* Wait for last character to go. */
533
534         buf = (char *)tbdf->cbd_bufaddr;
535
536         *buf = c;
537         tbdf->cbd_datlen = 1;
538         tbdf->cbd_sc |= BD_SC_READY;
539         __asm__("eieio");
540
541         while (tbdf->cbd_sc & BD_SC_READY) {
542                 __asm__("eieio");
543                 WATCHDOG_RESET ();
544         }
545 }
546
547 static void
548 scc_puts (const char *s)
549 {
550         while (*s) {
551                 scc_putc (*s++);
552         }
553 }
554
555 static int
556 scc_getc(void)
557 {
558         volatile cbd_t          *rbdf;
559         volatile unsigned char  *buf;
560         volatile scc_uart_t     *up;
561         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
562         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
563         unsigned char           c;
564
565         up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
566
567         rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
568
569         /* Wait for character to show up. */
570         buf = (unsigned char *)rbdf->cbd_bufaddr;
571
572         while (rbdf->cbd_sc & BD_SC_EMPTY)
573                 WATCHDOG_RESET ();
574
575         c = *buf;
576         rbdf->cbd_sc |= BD_SC_EMPTY;
577
578         return(c);
579 }
580
581 static int
582 scc_tstc(void)
583 {
584         volatile cbd_t          *rbdf;
585         volatile scc_uart_t     *up;
586         volatile immap_t        *im = (immap_t *)CONFIG_SYS_IMMR;
587         volatile cpm8xx_t       *cpmp = &(im->im_cpm);
588
589         up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC];
590
591         rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
592
593         return(!(rbdf->cbd_sc & BD_SC_EMPTY));
594 }
595
596 struct serial_device serial_scc_device =
597 {
598         .name   = "serial_scc",
599         .start  = scc_init,
600         .stop   = NULL,
601         .setbrg = scc_setbrg,
602         .getc   = scc_getc,
603         .tstc   = scc_tstc,
604         .putc   = scc_putc,
605         .puts   = scc_puts,
606 };
607
608 #endif  /* CONFIG_8xx_CONS_SCCx */
609
610 __weak struct serial_device *default_serial_console(void)
611 {
612 #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
613         return &serial_smc_device;
614 #else
615         return &serial_scc_device;
616 #endif
617 }
618
619 void mpc8xx_serial_initialize(void)
620 {
621 #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
622         serial_register(&serial_smc_device);
623 #endif
624 #if     defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
625         defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
626         serial_register(&serial_scc_device);
627 #endif
628 }
629
630 #if defined(CONFIG_CMD_KGDB)
631
632 void
633 kgdb_serial_init(void)
634 {
635         int i = -1;
636
637         if (strcmp(default_serial_console()->name, "serial_smc") == 0)
638         {
639 #if defined(CONFIG_8xx_CONS_SMC1)
640                 i = 1;
641 #elif defined(CONFIG_8xx_CONS_SMC2)
642                 i = 2;
643 #endif
644         }
645         else if (strcmp(default_serial_console()->name, "serial_scc") == 0)
646         {
647 #if defined(CONFIG_8xx_CONS_SCC1)
648                 i = 1;
649 #elif defined(CONFIG_8xx_CONS_SCC2)
650                 i = 2;
651 #elif defined(CONFIG_8xx_CONS_SCC3)
652                 i = 3;
653 #elif defined(CONFIG_8xx_CONS_SCC4)
654                 i = 4;
655 #endif
656         }
657
658         if (i >= 0)
659         {
660                 serial_printf("[on %s%d] ", default_serial_console()->name, i);
661         }
662 }
663
664 void
665 putDebugChar (int c)
666 {
667         serial_putc (c);
668 }
669
670 void
671 putDebugStr (const char *str)
672 {
673         serial_puts (str);
674 }
675
676 int
677 getDebugChar (void)
678 {
679         return serial_getc();
680 }
681
682 void
683 kgdb_interruptible (int yes)
684 {
685         return;
686 }
687 #endif
688
689 #endif  /* CONFIG_8xx_CONS_NONE */