3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
30 DECLARE_GLOBAL_DATA_PTR
;
32 #if !defined(CONFIG_8xx_CONS_NONE) /* No Console at all */
34 #if defined(CONFIG_8xx_CONS_SMC1) /* Console on SMC1 */
36 #define PROFF_SMC PROFF_SMC1
37 #define CPM_CR_CH_SMC CPM_CR_CH_SMC1
39 #elif defined(CONFIG_8xx_CONS_SMC2) /* Console on SMC2 */
41 #define PROFF_SMC PROFF_SMC2
42 #define CPM_CR_CH_SMC CPM_CR_CH_SMC2
44 #endif /* CONFIG_8xx_CONS_SMCx */
46 #if defined(CONFIG_8xx_CONS_SCC1) /* Console on SCC1 */
48 #define PROFF_SCC PROFF_SCC1
49 #define CPM_CR_CH_SCC CPM_CR_CH_SCC1
51 #elif defined(CONFIG_8xx_CONS_SCC2) /* Console on SCC2 */
53 #define PROFF_SCC PROFF_SCC2
54 #define CPM_CR_CH_SCC CPM_CR_CH_SCC2
56 #elif defined(CONFIG_8xx_CONS_SCC3) /* Console on SCC3 */
58 #define PROFF_SCC PROFF_SCC3
59 #define CPM_CR_CH_SCC CPM_CR_CH_SCC3
61 #elif defined(CONFIG_8xx_CONS_SCC4) /* Console on SCC4 */
63 #define PROFF_SCC PROFF_SCC4
64 #define CPM_CR_CH_SCC CPM_CR_CH_SCC4
66 #endif /* CONFIG_8xx_CONS_SCCx */
68 #if !defined(CONFIG_SYS_SMC_RXBUFLEN)
69 #define CONFIG_SYS_SMC_RXBUFLEN 1
70 #define CONFIG_SYS_MAXIDLE 0
72 #if !defined(CONFIG_SYS_MAXIDLE)
73 #error "you must define CONFIG_SYS_MAXIDLE"
77 typedef volatile struct serialbuffer
{
78 cbd_t rxbd
; /* Rx BD */
79 cbd_t txbd
; /* Tx BD */
80 uint rxindex
; /* index for next character to read */
81 volatile uchar rxbuf
[CONFIG_SYS_SMC_RXBUFLEN
];/* rx buffers */
82 volatile uchar txbuf
; /* tx buffers */
85 static void serial_setdivisor(volatile cpm8xx_t
*cp
)
87 int divisor
=(gd
->cpu_clk
+ 8*gd
->baudrate
)/16/gd
->baudrate
;
89 if(divisor
/16>0x1000) {
90 /* bad divisor, assume 50MHz clock and 9600 baud */
91 divisor
=(50*1000*1000 + 8*9600)/16/9600;
94 #ifdef CONFIG_SYS_BRGCLK_PRESCALE
95 divisor
/= CONFIG_SYS_BRGCLK_PRESCALE
;
99 cp
->cp_brgc1
=((divisor
-1)<<1) | CPM_BRG_EN
;
101 cp
->cp_brgc1
=((divisor
/16-1)<<1) | CPM_BRG_EN
| CPM_BRG_DIV16
;
105 #if (defined (CONFIG_8xx_CONS_SMC1) || defined (CONFIG_8xx_CONS_SMC2))
108 * Minimal serial functions needed to use one of the SMC ports
109 * as serial console interface.
112 static void smc_setbrg (void)
114 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
115 volatile cpm8xx_t
*cp
= &(im
->im_cpm
);
117 /* Set up the baud rate generator.
118 * See 8xx_io/commproc.c for details.
123 cp
->cp_simode
= 0x00000000;
125 serial_setdivisor(cp
);
128 static int smc_init (void)
130 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
132 volatile smc_uart_t
*up
;
133 volatile cpm8xx_t
*cp
= &(im
->im_cpm
);
134 #if (!defined(CONFIG_8xx_CONS_SMC1)) && (defined(CONFIG_MPC823) || defined(CONFIG_MPC850))
135 volatile iop8xx_t
*ip
= (iop8xx_t
*)&(im
->im_ioport
);
138 volatile serialbuffer_t
*rtx
;
140 /* initialize pointers to SMC */
142 sp
= (smc_t
*) &(cp
->cp_smc
[SMC_INDEX
]);
143 up
= (smc_uart_t
*) &cp
->cp_dparam
[PROFF_SMC
];
144 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
145 up
= (smc_uart_t
*) &cp
->cp_dpmem
[up
->smc_rpbase
];
147 /* Disable relocation */
151 /* Disable transmitter/receiver. */
152 sp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
155 im
->im_siu_conf
.sc_sdcr
= 1;
157 /* clear error conditions */
158 #ifdef CONFIG_SYS_SDSR
159 im
->im_sdma
.sdma_sdsr
= CONFIG_SYS_SDSR
;
161 im
->im_sdma
.sdma_sdsr
= 0x83;
164 /* clear SDMA interrupt mask */
165 #ifdef CONFIG_SYS_SDMR
166 im
->im_sdma
.sdma_sdmr
= CONFIG_SYS_SDMR
;
168 im
->im_sdma
.sdma_sdmr
= 0x00;
171 #if defined(CONFIG_8xx_CONS_SMC1)
172 /* Use Port B for SMC1 instead of other functions. */
173 cp
->cp_pbpar
|= 0x000000c0;
174 cp
->cp_pbdir
&= ~0x000000c0;
175 cp
->cp_pbodr
&= ~0x000000c0;
176 #else /* CONFIG_8xx_CONS_SMC2 */
177 # if defined(CONFIG_MPC823) || defined(CONFIG_MPC850)
178 /* Use Port A for SMC2 instead of other functions. */
179 ip
->iop_papar
|= 0x00c0;
180 ip
->iop_padir
&= ~0x00c0;
181 ip
->iop_paodr
&= ~0x00c0;
182 # else /* must be a 860 then */
183 /* Use Port B for SMC2 instead of other functions.
185 cp
->cp_pbpar
|= 0x00000c00;
186 cp
->cp_pbdir
&= ~0x00000c00;
187 cp
->cp_pbodr
&= ~0x00000c00;
191 #if defined(CONFIG_FADS) || defined(CONFIG_ADS)
193 #if defined(CONFIG_8xx_CONS_SMC1)
194 *((uint
*) BCSR1
) &= ~BCSR1_RS232EN_1
;
196 *((uint
*) BCSR1
) &= ~BCSR1_RS232EN_2
;
198 #endif /* CONFIG_FADS */
200 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
201 /* Enable Monitor Port Transceiver */
202 *((uchar
*) BCSR0
) |= BCSR0_ENMONXCVR
;
203 #endif /* CONFIG_RPXLITE */
205 /* Set the physical address of the host memory buffers in
206 * the buffer descriptors.
209 #ifdef CONFIG_SYS_ALLOC_DPRAM
211 * size of struct serialbuffer with bd rx/tx, buffer rx/tx and rx index
213 dpaddr
= dpram_alloc_align((sizeof(serialbuffer_t
)), 8);
215 dpaddr
= CPM_SERIAL_BASE
;
218 rtx
= (serialbuffer_t
*)&cp
->cp_dpmem
[dpaddr
];
219 /* Allocate space for two buffer descriptors in the DP ram.
220 * For now, this address seems OK, but it may have to
221 * change with newer versions of the firmware.
222 * damm: allocating space after the two buffers for rx/tx data
225 rtx
->rxbd
.cbd_bufaddr
= (uint
) &rtx
->rxbuf
;
226 rtx
->rxbd
.cbd_sc
= 0;
228 rtx
->txbd
.cbd_bufaddr
= (uint
) &rtx
->txbuf
;
229 rtx
->txbd
.cbd_sc
= 0;
231 /* Set up the uart parameters in the parameter ram. */
232 up
->smc_rbase
= dpaddr
;
233 up
->smc_tbase
= dpaddr
+sizeof(cbd_t
);
234 up
->smc_rfcr
= SMC_EB
;
235 up
->smc_tfcr
= SMC_EB
;
236 #if defined (CONFIG_SYS_SMC_UCODE_PATCH)
237 up
->smc_rbptr
= up
->smc_rbase
;
238 up
->smc_tbptr
= up
->smc_tbase
;
243 #if defined(CONFIG_MBX)
245 #endif /* CONFIG_MBX */
247 /* Set UART mode, 8 bit, no parity, one stop.
248 * Enable receive and transmit.
250 sp
->smc_smcmr
= smcr_mk_clen(9) | SMCMR_SM_UART
;
252 /* Mask all interrupts and remove anything pending.
257 #ifdef CONFIG_SYS_SPC1920_SMC1_CLK4
258 /* clock source is PLD */
260 /* set freq to 19200 Baud */
261 *((volatile uchar
*) CONFIG_SYS_SPC1920_PLD_BASE
+6) = 0x3;
262 /* configure clk4 as input */
263 im
->im_ioport
.iop_pdpar
|= 0x800;
264 im
->im_ioport
.iop_pddir
&= ~0x800;
266 cp
->cp_simode
= ((cp
->cp_simode
& ~0xf000) | 0x7000);
268 /* Set up the baud rate generator */
272 /* Make the first buffer the only buffer. */
273 rtx
->txbd
.cbd_sc
|= BD_SC_WRAP
;
274 rtx
->rxbd
.cbd_sc
|= BD_SC_EMPTY
| BD_SC_WRAP
;
276 /* single/multi character receive. */
277 up
->smc_mrblr
= CONFIG_SYS_SMC_RXBUFLEN
;
278 up
->smc_maxidl
= CONFIG_SYS_MAXIDLE
;
281 /* Initialize Tx/Rx parameters. */
282 while (cp
->cp_cpcr
& CPM_CR_FLG
) /* wait if cp is busy */
285 cp
->cp_cpcr
= mk_cr_cmd(CPM_CR_CH_SMC
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
287 while (cp
->cp_cpcr
& CPM_CR_FLG
) /* wait if cp is busy */
290 /* Enable transmitter/receiver. */
291 sp
->smc_smcmr
|= SMCMR_REN
| SMCMR_TEN
;
297 smc_putc(const char c
)
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 volatile serialbuffer_t
*rtx
;
304 #ifdef CONFIG_MODEM_SUPPORT
312 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[PROFF_SMC
];
313 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
314 up
= (smc_uart_t
*) &cpmp
->cp_dpmem
[up
->smc_rpbase
];
317 rtx
= (serialbuffer_t
*)&cpmp
->cp_dpmem
[up
->smc_rbase
];
319 /* Wait for last character to go. */
321 rtx
->txbd
.cbd_datlen
= 1;
322 rtx
->txbd
.cbd_sc
|= BD_SC_READY
;
325 while (rtx
->txbd
.cbd_sc
& BD_SC_READY
) {
332 smc_puts (const char *s
)
342 volatile smc_uart_t
*up
;
343 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
344 volatile cpm8xx_t
*cpmp
= &(im
->im_cpm
);
345 volatile serialbuffer_t
*rtx
;
348 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[PROFF_SMC
];
349 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
350 up
= (smc_uart_t
*) &cpmp
->cp_dpmem
[up
->smc_rpbase
];
352 rtx
= (serialbuffer_t
*)&cpmp
->cp_dpmem
[up
->smc_rbase
];
354 /* Wait for character to show up. */
355 while (rtx
->rxbd
.cbd_sc
& BD_SC_EMPTY
)
358 /* the characters are read one by one,
359 * use the rxindex to know the next char to deliver
361 c
= *(unsigned char *) (rtx
->rxbd
.cbd_bufaddr
+rtx
->rxindex
);
364 /* check if all char are readout, then make prepare for next receive */
365 if (rtx
->rxindex
>= rtx
->rxbd
.cbd_datlen
) {
367 rtx
->rxbd
.cbd_sc
|= BD_SC_EMPTY
;
375 volatile smc_uart_t
*up
;
376 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
377 volatile cpm8xx_t
*cpmp
= &(im
->im_cpm
);
378 volatile serialbuffer_t
*rtx
;
380 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[PROFF_SMC
];
381 #ifdef CONFIG_SYS_SMC_UCODE_PATCH
382 up
= (smc_uart_t
*) &cpmp
->cp_dpmem
[up
->smc_rpbase
];
385 rtx
= (serialbuffer_t
*)&cpmp
->cp_dpmem
[up
->smc_rbase
];
387 return !(rtx
->rxbd
.cbd_sc
& BD_SC_EMPTY
);
390 struct serial_device serial_smc_device
=
402 #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */
404 #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
405 defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
410 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
411 volatile cpm8xx_t
*cp
= &(im
->im_cpm
);
413 /* Set up the baud rate generator.
414 * See 8xx_io/commproc.c for details.
419 cp
->cp_sicr
&= ~(0x000000FF << (8 * SCC_INDEX
));
421 serial_setdivisor(cp
);
424 static int scc_init (void)
426 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
428 volatile scc_uart_t
*up
;
429 volatile cbd_t
*tbdf
, *rbdf
;
430 volatile cpm8xx_t
*cp
= &(im
->im_cpm
);
432 #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850)
433 volatile iop8xx_t
*ip
= (iop8xx_t
*)&(im
->im_ioport
);
436 /* initialize pointers to SCC */
438 sp
= (scc_t
*) &(cp
->cp_scc
[SCC_INDEX
]);
439 up
= (scc_uart_t
*) &cp
->cp_dparam
[PROFF_SCC
];
441 #if defined(CONFIG_LWMON) && defined(CONFIG_8xx_CONS_SCC2)
442 { /* Disable Ethernet, enable Serial */
446 c
&= ~0x40; /* enable COM3 */
447 c
|= 0x80; /* disable Ethernet */
451 cp
->cp_pbpar
|= 0x2000;
452 cp
->cp_pbdat
|= 0x2000;
453 cp
->cp_pbdir
|= 0x2000;
455 #endif /* CONFIG_LWMON */
457 /* Disable transmitter/receiver. */
458 sp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
460 #if (SCC_INDEX == 2) && defined(CONFIG_MPC850)
462 * The MPC850 has SCC3 on Port B
464 cp
->cp_pbpar
|= 0x06;
465 cp
->cp_pbdir
&= ~0x06;
466 cp
->cp_pbodr
&= ~0x06;
468 #elif (SCC_INDEX < 2) || !defined(CONFIG_IP860)
470 * Standard configuration for SCC's is on Part A
472 ip
->iop_papar
|= ((3 << (2 * SCC_INDEX
)));
473 ip
->iop_padir
&= ~((3 << (2 * SCC_INDEX
)));
474 ip
->iop_paodr
&= ~((3 << (2 * SCC_INDEX
)));
477 * The IP860 has SCC3 and SCC4 on Port D
479 ip
->iop_pdpar
|= ((3 << (2 * SCC_INDEX
)));
482 /* Allocate space for two buffer descriptors in the DP ram. */
484 #ifdef CONFIG_SYS_ALLOC_DPRAM
485 dpaddr
= dpram_alloc_align (sizeof(cbd_t
)*2 + 2, 8) ;
487 dpaddr
= CPM_SERIAL2_BASE
;
491 im
->im_siu_conf
.sc_sdcr
= 0x0001;
493 /* Set the physical address of the host memory buffers in
494 * the buffer descriptors.
497 rbdf
= (cbd_t
*)&cp
->cp_dpmem
[dpaddr
];
498 rbdf
->cbd_bufaddr
= (uint
) (rbdf
+2);
501 tbdf
->cbd_bufaddr
= ((uint
) (rbdf
+2)) + 1;
504 /* Set up the baud rate generator. */
507 /* Set up the uart parameters in the parameter ram. */
508 up
->scc_genscc
.scc_rbase
= dpaddr
;
509 up
->scc_genscc
.scc_tbase
= dpaddr
+sizeof(cbd_t
);
511 /* Initialize Tx/Rx parameters. */
512 while (cp
->cp_cpcr
& CPM_CR_FLG
) /* wait if cp is busy */
514 cp
->cp_cpcr
= mk_cr_cmd(CPM_CR_CH_SCC
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
516 while (cp
->cp_cpcr
& CPM_CR_FLG
) /* wait if cp is busy */
519 up
->scc_genscc
.scc_rfcr
= SCC_EB
| 0x05;
520 up
->scc_genscc
.scc_tfcr
= SCC_EB
| 0x05;
522 up
->scc_genscc
.scc_mrblr
= 1; /* Single character receive */
523 up
->scc_maxidl
= 0; /* disable max idle */
524 up
->scc_brkcr
= 1; /* send one break character on stop TX */
532 up
->scc_char1
= 0x8000;
533 up
->scc_char2
= 0x8000;
534 up
->scc_char3
= 0x8000;
535 up
->scc_char4
= 0x8000;
536 up
->scc_char5
= 0x8000;
537 up
->scc_char6
= 0x8000;
538 up
->scc_char7
= 0x8000;
539 up
->scc_char8
= 0x8000;
540 up
->scc_rccm
= 0xc0ff;
542 /* Set low latency / small fifo. */
543 sp
->scc_gsmrh
= SCC_GSMRH_RFW
;
545 /* Set SCC(x) clock mode to 16x
546 * See 8xx_io/commproc.c for details.
551 /* Set UART mode, clock divider 16 on Tx and Rx */
552 sp
->scc_gsmrl
&= ~0xF;
554 (SCC_GSMRL_MODE_UART
| SCC_GSMRL_TDCR_16
| SCC_GSMRL_RDCR_16
);
557 sp
->scc_psmr
|= SCU_PSMR_CL
;
559 /* Mask all interrupts and remove anything pending. */
561 sp
->scc_scce
= 0xffff;
562 sp
->scc_dsr
= 0x7e7e;
563 sp
->scc_psmr
= 0x3000;
565 /* Make the first buffer the only buffer. */
566 tbdf
->cbd_sc
|= BD_SC_WRAP
;
567 rbdf
->cbd_sc
|= BD_SC_EMPTY
| BD_SC_WRAP
;
569 /* Enable transmitter/receiver. */
570 sp
->scc_gsmrl
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
576 scc_putc(const char c
)
578 volatile cbd_t
*tbdf
;
580 volatile scc_uart_t
*up
;
581 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
582 volatile cpm8xx_t
*cpmp
= &(im
->im_cpm
);
584 #ifdef CONFIG_MODEM_SUPPORT
592 up
= (scc_uart_t
*)&cpmp
->cp_dparam
[PROFF_SCC
];
594 tbdf
= (cbd_t
*)&cpmp
->cp_dpmem
[up
->scc_genscc
.scc_tbase
];
596 /* Wait for last character to go. */
598 buf
= (char *)tbdf
->cbd_bufaddr
;
601 tbdf
->cbd_datlen
= 1;
602 tbdf
->cbd_sc
|= BD_SC_READY
;
605 while (tbdf
->cbd_sc
& BD_SC_READY
) {
612 scc_puts (const char *s
)
622 volatile cbd_t
*rbdf
;
623 volatile unsigned char *buf
;
624 volatile scc_uart_t
*up
;
625 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
626 volatile cpm8xx_t
*cpmp
= &(im
->im_cpm
);
629 up
= (scc_uart_t
*)&cpmp
->cp_dparam
[PROFF_SCC
];
631 rbdf
= (cbd_t
*)&cpmp
->cp_dpmem
[up
->scc_genscc
.scc_rbase
];
633 /* Wait for character to show up. */
634 buf
= (unsigned char *)rbdf
->cbd_bufaddr
;
636 while (rbdf
->cbd_sc
& BD_SC_EMPTY
)
640 rbdf
->cbd_sc
|= BD_SC_EMPTY
;
648 volatile cbd_t
*rbdf
;
649 volatile scc_uart_t
*up
;
650 volatile immap_t
*im
= (immap_t
*)CONFIG_SYS_IMMR
;
651 volatile cpm8xx_t
*cpmp
= &(im
->im_cpm
);
653 up
= (scc_uart_t
*)&cpmp
->cp_dparam
[PROFF_SCC
];
655 rbdf
= (cbd_t
*)&cpmp
->cp_dpmem
[up
->scc_genscc
.scc_rbase
];
657 return(!(rbdf
->cbd_sc
& BD_SC_EMPTY
));
660 struct serial_device serial_scc_device
=
672 #endif /* CONFIG_8xx_CONS_SCCx */
674 #ifdef CONFIG_MODEM_SUPPORT
675 void disable_putc(void)
680 void enable_putc(void)
686 #if defined(CONFIG_CMD_KGDB)
689 kgdb_serial_init(void)
693 if (strcmp(default_serial_console()->ctlr
, "SMC") == 0)
695 #if defined(CONFIG_8xx_CONS_SMC1)
697 #elif defined(CONFIG_8xx_CONS_SMC2)
701 else if (strcmp(default_serial_console()->ctlr
, "SMC") == 0)
703 #if defined(CONFIG_8xx_CONS_SCC1)
705 #elif defined(CONFIG_8xx_CONS_SCC2)
707 #elif defined(CONFIG_8xx_CONS_SCC3)
709 #elif defined(CONFIG_8xx_CONS_SCC4)
716 serial_printf("[on %s%d] ", default_serial_console()->ctlr
, i
);
727 putDebugStr (const char *str
)
735 return serial_getc();
739 kgdb_interruptible (int yes
)
745 #endif /* CONFIG_8xx_CONS_NONE */