2 * (C) Copyright 2000 - 2003
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,
23 * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 19-Oct-00, with
24 * changes based on the file arch/ppc/mbxboot/m8260_tty.c from the
25 * Linux/PPC sources (m8260_tty.c had no copyright info in it).
27 * Martin Krause, 8 Jun 2006
28 * Added CONFIG_SERIAL_MULTI support
32 * Minimal serial functions needed to use one of the PSC ports
33 * as serial console interface.
39 #if defined (CONFIG_SERIAL_MULTI)
43 DECLARE_GLOBAL_DATA_PTR
;
45 #if defined(CONFIG_PSC_CONSOLE)
47 #if CONFIG_PSC_CONSOLE == 1
48 #define PSC_BASE MPC5XXX_PSC1
49 #elif CONFIG_PSC_CONSOLE == 2
50 #define PSC_BASE MPC5XXX_PSC2
51 #elif CONFIG_PSC_CONSOLE == 3
52 #define PSC_BASE MPC5XXX_PSC3
53 #elif defined(CONFIG_MGT5100)
54 #error CONFIG_PSC_CONSOLE must be in 1, 2 or 3
55 #elif CONFIG_PSC_CONSOLE == 4
56 #define PSC_BASE MPC5XXX_PSC4
57 #elif CONFIG_PSC_CONSOLE == 5
58 #define PSC_BASE MPC5XXX_PSC5
59 #elif CONFIG_PSC_CONSOLE == 6
60 #define PSC_BASE MPC5XXX_PSC6
62 #error CONFIG_PSC_CONSOLE must be in 1 ... 6
65 #if defined(CONFIG_SERIAL_MULTI) && !defined(CONFIG_PSC_CONSOLE2)
66 #error you must define CONFIG_PSC_CONSOLE2 if CONFIG_SERIAL_MULTI is set
69 #if defined(CONFIG_SERIAL_MULTI)
70 #if CONFIG_PSC_CONSOLE2 == 1
71 #define PSC_BASE2 MPC5XXX_PSC1
72 #elif CONFIG_PSC_CONSOLE2 == 2
73 #define PSC_BASE2 MPC5XXX_PSC2
74 #elif CONFIG_PSC_CONSOLE2 == 3
75 #define PSC_BASE2 MPC5XXX_PSC3
76 #elif defined(CONFIG_MGT5100)
77 #error CONFIG_PSC_CONSOLE2 must be in 1, 2 or 3
78 #elif CONFIG_PSC_CONSOLE2 == 4
79 #define PSC_BASE2 MPC5XXX_PSC4
80 #elif CONFIG_PSC_CONSOLE2 == 5
81 #define PSC_BASE2 MPC5XXX_PSC5
82 #elif CONFIG_PSC_CONSOLE2 == 6
83 #define PSC_BASE2 MPC5XXX_PSC6
85 #error CONFIG_PSC_CONSOLE2 must be in 1 ... 6
87 #endif /* CONFIG_SERIAL_MULTI */
89 #if defined(CONFIG_SERIAL_MULTI)
90 int serial_init_dev (unsigned long dev_base
)
92 int serial_init (void)
95 #if defined(CONFIG_SERIAL_MULTI)
96 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)dev_base
;
98 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)PSC_BASE
;
100 unsigned long baseclk
;
104 psc
->command
= PSC_SEL_MODE_REG_1
;
106 /* select clock sources */
107 #if defined(CONFIG_MGT5100)
108 psc
->psc_clock_select
= 0xdd00;
109 baseclk
= (CFG_MPC5XXX_CLKIN
+ 16) / 32;
110 #elif defined(CONFIG_MPC5200)
111 psc
->psc_clock_select
= 0;
112 baseclk
= (gd
->ipb_clk
+ 16) / 32;
115 /* switch to UART mode */
118 /* configure parity, bit length and so on */
119 #if defined(CONFIG_MGT5100)
120 psc
->mode
= PSC_MODE_ERR
| PSC_MODE_8_BITS
| PSC_MODE_PARNONE
;
121 #elif defined(CONFIG_MPC5200)
122 psc
->mode
= PSC_MODE_8_BITS
| PSC_MODE_PARNONE
;
124 psc
->mode
= PSC_MODE_ONE_STOP
;
126 /* set up UART divisor */
127 div
= (baseclk
+ (gd
->baudrate
/2)) / gd
->baudrate
;
128 psc
->ctur
= (div
>> 8) & 0xff;
129 psc
->ctlr
= div
& 0xff;
131 /* disable all interrupts */
134 /* reset and enable Rx/Tx */
135 psc
->command
= PSC_RST_RX
;
136 psc
->command
= PSC_RST_TX
;
137 psc
->command
= PSC_RX_ENABLE
| PSC_TX_ENABLE
;
142 #if defined(CONFIG_SERIAL_MULTI)
143 void serial_putc_dev (unsigned long dev_base
, const char c
)
145 void serial_putc(const char c
)
148 #if defined(CONFIG_SERIAL_MULTI)
149 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)dev_base
;
151 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)PSC_BASE
;
155 #if defined(CONFIG_SERIAL_MULTI)
156 serial_putc_dev (dev_base
, '\r');
161 /* Wait for last character to go. */
162 while (!(psc
->psc_status
& PSC_SR_TXEMP
))
165 psc
->psc_buffer_8
= c
;
168 #if defined(CONFIG_SERIAL_MULTI)
169 void serial_puts_dev (unsigned long dev_base
, const char *s
)
171 void serial_puts (const char *s
)
175 #if defined(CONFIG_SERIAL_MULTI)
176 serial_putc_dev (dev_base
, *s
++);
183 #if defined(CONFIG_SERIAL_MULTI)
184 int serial_getc_dev (unsigned long dev_base
)
186 int serial_getc(void)
189 #if defined(CONFIG_SERIAL_MULTI)
190 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)dev_base
;
192 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)PSC_BASE
;
195 /* Wait for a character to arrive. */
196 while (!(psc
->psc_status
& PSC_SR_RXRDY
))
199 return psc
->psc_buffer_8
;
202 #if defined(CONFIG_SERIAL_MULTI)
203 int serial_tstc_dev (unsigned long dev_base
)
205 int serial_tstc(void)
208 #if defined(CONFIG_SERIAL_MULTI)
209 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)dev_base
;
211 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)PSC_BASE
;
214 return (psc
->psc_status
& PSC_SR_RXRDY
);
217 #if defined(CONFIG_SERIAL_MULTI)
218 void serial_setbrg_dev (unsigned long dev_base
)
220 void serial_setbrg(void)
223 #if defined(CONFIG_SERIAL_MULTI)
224 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)dev_base
;
226 volatile struct mpc5xxx_psc
*psc
= (struct mpc5xxx_psc
*)PSC_BASE
;
228 unsigned long baseclk
, div
;
230 #if defined(CONFIG_MGT5100)
231 baseclk
= (CFG_MPC5XXX_CLKIN
+ 16) / 32;
232 #elif defined(CONFIG_MPC5200)
233 baseclk
= (gd
->ipb_clk
+ 16) / 32;
236 /* set up UART divisor */
237 div
= (baseclk
+ (gd
->baudrate
/2)) / gd
->baudrate
;
238 psc
->ctur
= (div
>> 8) & 0xFF;
239 psc
->ctlr
= div
& 0xff;
242 #if defined(CONFIG_SERIAL_MULTI)
243 int serial0_init(void)
245 return (serial_init_dev(PSC_BASE
));
248 int serial1_init(void)
250 return (serial_init_dev(PSC_BASE2
));
252 void serial0_setbrg (void)
254 serial_setbrg_dev(PSC_BASE
);
256 void serial1_setbrg (void)
258 serial_setbrg_dev(PSC_BASE2
);
261 void serial0_putc(const char c
)
263 serial_putc_dev(PSC_BASE
,c
);
266 void serial1_putc(const char c
)
268 serial_putc_dev(PSC_BASE2
, c
);
270 void serial0_puts(const char *s
)
272 serial_puts_dev(PSC_BASE
, s
);
275 void serial1_puts(const char *s
)
277 serial_puts_dev(PSC_BASE2
, s
);
280 int serial0_getc(void)
282 return(serial_getc_dev(PSC_BASE
));
285 int serial1_getc(void)
287 return(serial_getc_dev(PSC_BASE2
));
289 int serial0_tstc(void)
291 return (serial_tstc_dev(PSC_BASE
));
294 int serial1_tstc(void)
296 return (serial_tstc_dev(PSC_BASE2
));
299 struct serial_device serial0_device
=
311 struct serial_device serial1_device
=
322 #endif /* CONFIG_SERIAL_MULTI */
324 #endif /* CONFIG_PSC_CONSOLE */