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/powerpc/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 CONFIG_PSC_CONSOLE == 4
54 #define PSC_BASE MPC5XXX_PSC4
55 #elif CONFIG_PSC_CONSOLE == 5
56 #define PSC_BASE MPC5XXX_PSC5
57 #elif CONFIG_PSC_CONSOLE == 6
58 #define PSC_BASE MPC5XXX_PSC6
60 #error CONFIG_PSC_CONSOLE must be in 1 ... 6
63 #if defined(CONFIG_SERIAL_MULTI) && !defined(CONFIG_PSC_CONSOLE2)
64 #error you must define CONFIG_PSC_CONSOLE2 if CONFIG_SERIAL_MULTI is set
67 #if defined(CONFIG_SERIAL_MULTI)
68 #if CONFIG_PSC_CONSOLE2 == 1
69 #define PSC_BASE2 MPC5XXX_PSC1
70 #elif CONFIG_PSC_CONSOLE2 == 2
71 #define PSC_BASE2 MPC5XXX_PSC2
72 #elif CONFIG_PSC_CONSOLE2 == 3
73 #define PSC_BASE2 MPC5XXX_PSC3
74 #elif CONFIG_PSC_CONSOLE2 == 4
75 #define PSC_BASE2 MPC5XXX_PSC4
76 #elif CONFIG_PSC_CONSOLE2 == 5
77 #define PSC_BASE2 MPC5XXX_PSC5
78 #elif CONFIG_PSC_CONSOLE2 == 6
79 #define PSC_BASE2 MPC5XXX_PSC6
81 #error CONFIG_PSC_CONSOLE2 must be in 1 ... 6
83 #endif /* CONFIG_SERIAL_MULTI */
85 #if defined(CONFIG_SERIAL_MULTI)
86 int serial_init_dev (unsigned long dev_base)
88 int serial_init (void)
91 #if defined(CONFIG_SERIAL_MULTI)
92 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
94 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
96 unsigned long baseclk;
100 psc->command = PSC_SEL_MODE_REG_1;
102 /* select clock sources */
103 psc->psc_clock_select = 0;
104 baseclk = (gd->ipb_clk + 16) / 32;
106 /* switch to UART mode */
109 /* configure parity, bit length and so on */
110 psc->mode = PSC_MODE_8_BITS | PSC_MODE_PARNONE;
111 psc->mode = PSC_MODE_ONE_STOP;
113 /* set up UART divisor */
114 div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
115 psc->ctur = (div >> 8) & 0xff;
116 psc->ctlr = div & 0xff;
118 /* disable all interrupts */
121 /* reset and enable Rx/Tx */
122 psc->command = PSC_RST_RX;
123 psc->command = PSC_RST_TX;
124 psc->command = PSC_RX_ENABLE | PSC_TX_ENABLE;
129 #if defined(CONFIG_SERIAL_MULTI)
130 void serial_putc_dev (unsigned long dev_base, const char c)
132 void serial_putc(const char c)
135 #if defined(CONFIG_SERIAL_MULTI)
136 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
138 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
142 #if defined(CONFIG_SERIAL_MULTI)
143 serial_putc_dev (dev_base, '\r');
148 /* Wait for last character to go. */
149 while (!(psc->psc_status & PSC_SR_TXEMP))
152 psc->psc_buffer_8 = c;
155 #if defined(CONFIG_SERIAL_MULTI)
156 void serial_putc_raw_dev(unsigned long dev_base, const char c)
158 void serial_putc_raw(const char c)
161 #if defined(CONFIG_SERIAL_MULTI)
162 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
164 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
166 /* Wait for last character to go. */
167 while (!(psc->psc_status & PSC_SR_TXEMP))
170 psc->psc_buffer_8 = c;
174 #if defined(CONFIG_SERIAL_MULTI)
175 void serial_puts_dev (unsigned long dev_base, const char *s)
177 void serial_puts (const char *s)
181 #if defined(CONFIG_SERIAL_MULTI)
182 serial_putc_dev (dev_base, *s++);
189 #if defined(CONFIG_SERIAL_MULTI)
190 int serial_getc_dev (unsigned long dev_base)
192 int serial_getc(void)
195 #if defined(CONFIG_SERIAL_MULTI)
196 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
198 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
201 /* Wait for a character to arrive. */
202 while (!(psc->psc_status & PSC_SR_RXRDY))
205 return psc->psc_buffer_8;
208 #if defined(CONFIG_SERIAL_MULTI)
209 int serial_tstc_dev (unsigned long dev_base)
211 int serial_tstc(void)
214 #if defined(CONFIG_SERIAL_MULTI)
215 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
217 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
220 return (psc->psc_status & PSC_SR_RXRDY);
223 #if defined(CONFIG_SERIAL_MULTI)
224 void serial_setbrg_dev (unsigned long dev_base)
226 void serial_setbrg(void)
229 #if defined(CONFIG_SERIAL_MULTI)
230 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
232 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
234 unsigned long baseclk, div;
236 baseclk = (gd->ipb_clk + 16) / 32;
238 /* set up UART divisor */
239 div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
240 psc->ctur = (div >> 8) & 0xFF;
241 psc->ctlr = div & 0xff;
244 #if defined(CONFIG_SERIAL_MULTI)
245 void serial_setrts_dev (unsigned long dev_base, int s)
247 void serial_setrts(int s)
250 #if defined(CONFIG_SERIAL_MULTI)
251 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
253 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
257 /* Assert RTS (become LOW) */
261 /* Negate RTS (become HIGH) */
266 #if defined(CONFIG_SERIAL_MULTI)
267 int serial_getcts_dev (unsigned long dev_base)
269 int serial_getcts(void)
272 #if defined(CONFIG_SERIAL_MULTI)
273 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
275 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
278 return (psc->ip & 0x1) ? 0 : 1;
281 #if defined(CONFIG_SERIAL_MULTI)
282 int serial0_init(void)
284 return (serial_init_dev(PSC_BASE));
287 int serial1_init(void)
289 return (serial_init_dev(PSC_BASE2));
291 void serial0_setbrg (void)
293 serial_setbrg_dev(PSC_BASE);
295 void serial1_setbrg (void)
297 serial_setbrg_dev(PSC_BASE2);
300 void serial0_putc(const char c)
302 serial_putc_dev(PSC_BASE,c);
305 void serial1_putc(const char c)
307 serial_putc_dev(PSC_BASE2, c);
309 void serial0_puts(const char *s)
311 serial_puts_dev(PSC_BASE, s);
314 void serial1_puts(const char *s)
316 serial_puts_dev(PSC_BASE2, s);
319 int serial0_getc(void)
321 return(serial_getc_dev(PSC_BASE));
324 int serial1_getc(void)
326 return(serial_getc_dev(PSC_BASE2));
328 int serial0_tstc(void)
330 return (serial_tstc_dev(PSC_BASE));
333 int serial1_tstc(void)
335 return (serial_tstc_dev(PSC_BASE2));
338 struct serial_device serial0_device =
351 struct serial_device serial1_device =
363 #endif /* CONFIG_SERIAL_MULTI */
365 #endif /* CONFIG_PSC_CONSOLE */