3 * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
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
26 * Discription: Serial interface driver for SCI1 and SCI2.
27 * Since this code will be called from ROM use
28 * only non-static local variables.
37 #include <linux/compiler.h>
39 DECLARE_GLOBAL_DATA_PTR
;
45 static int ready_to_send(void)
47 volatile immap_t
*immr
= (immap_t
*)CONFIG_SYS_IMMR
;
48 volatile short status
;
51 #if defined(CONFIG_5xx_CONS_SCI1)
52 status
= immr
->im_qsmcm
.qsmcm_sc1sr
;
54 status
= immr
->im_qsmcm
.qsmcm_sc2sr
;
57 #if defined(CONFIG_WATCHDOG)
58 reset_5xx_watchdog (immr
);
60 } while ((status
& SCI_TDRE
) == 0);
66 * Minimal global serial functions needed to use one of the SCI modules.
69 static int mpc5xx_serial_init(void)
71 volatile immap_t
*immr
= (immap_t
*)CONFIG_SYS_IMMR
;
75 #if defined(CONFIG_5xx_CONS_SCI1)
76 /* 10-Bit, 1 start bit, 8 data bit, no parity, 1 stop bit */
77 immr
->im_qsmcm
.qsmcm_scc1r1
= SCI_M_10
;
78 immr
->im_qsmcm
.qsmcm_scc1r1
= SCI_TE
| SCI_RE
;
80 immr
->im_qsmcm
.qsmcm_scc2r1
= SCI_M_10
;
81 immr
->im_qsmcm
.qsmcm_scc2r1
= SCI_TE
| SCI_RE
;
86 static void mpc5xx_serial_putc(const char c
)
88 volatile immap_t
*immr
= (immap_t
*)CONFIG_SYS_IMMR
;
90 /* Test for completition */
92 #if defined(CONFIG_5xx_CONS_SCI1)
93 immr
->im_qsmcm
.qsmcm_sc1dr
= (short)c
;
95 immr
->im_qsmcm
.qsmcm_sc2dr
= (short)c
;
99 #if defined(CONFIG_5xx_CONS_SCI1)
100 immr
->im_qsmcm
.qsmcm_sc1dr
= (short)'\r';
102 immr
->im_qsmcm
.qsmcm_sc2dr
= (short)'\r';
108 static int mpc5xx_serial_getc(void)
110 volatile immap_t
*immr
= (immap_t
*)CONFIG_SYS_IMMR
;
111 volatile short status
;
116 #if defined(CONFIG_5xx_CONS_SCI1)
117 status
= immr
->im_qsmcm
.qsmcm_sc1sr
;
119 status
= immr
->im_qsmcm
.qsmcm_sc2sr
;
122 #if defined(CONFIG_WATCHDOG)
123 reset_5xx_watchdog (immr
);
125 } while ((status
& SCI_RDRF
) == 0);
128 #if defined(CONFIG_5xx_CONS_SCI1)
129 tmp
= (unsigned char)(immr
->im_qsmcm
.qsmcm_sc1dr
& SCI_SCXDR_MK
);
131 tmp
= (unsigned char)( immr
->im_qsmcm
.qsmcm_sc2dr
& SCI_SCXDR_MK
);
136 static int mpc5xx_serial_tstc(void)
138 volatile immap_t
*immr
= (immap_t
*)CONFIG_SYS_IMMR
;
141 /* New data character ? */
142 #if defined(CONFIG_5xx_CONS_SCI1)
143 status
= immr
->im_qsmcm
.qsmcm_sc1sr
;
145 status
= immr
->im_qsmcm
.qsmcm_sc2sr
;
147 return (status
& SCI_RDRF
);
150 static void mpc5xx_serial_setbrg(void)
152 volatile immap_t
*immr
= (immap_t
*)CONFIG_SYS_IMMR
;
156 scxbr
= (gd
->cpu_clk
/ (32 * gd
->baudrate
));
157 #if defined(CONFIG_5xx_CONS_SCI1)
158 immr
->im_qsmcm
.qsmcm_scc1r0
= (scxbr
& SCI_SCXBR_MK
);
160 immr
->im_qsmcm
.qsmcm_scc2r0
= (scxbr
& SCI_SCXBR_MK
);
164 static void mpc5xx_serial_puts(const char *s
)
172 static struct serial_device mpc5xx_serial_drv
= {
173 .name
= "mpc5xx_serial",
174 .start
= mpc5xx_serial_init
,
176 .setbrg
= mpc5xx_serial_setbrg
,
177 .putc
= mpc5xx_serial_putc
,
178 .puts
= mpc5xx_serial_puts
,
179 .getc
= mpc5xx_serial_getc
,
180 .tstc
= mpc5xx_serial_tstc
,
183 void mpc5xx_serial_initialize(void)
185 serial_register(&mpc5xx_serial_drv
);
188 __weak
struct serial_device
*default_serial_console(void)
190 return &mpc5xx_serial_drv
;