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.
37 #include <linux/compiler.h>
40 #if defined (CONFIG_SERIAL_MULTI)
44 DECLARE_GLOBAL_DATA_PTR;
46 #if defined(CONFIG_PSC_CONSOLE)
48 #if CONFIG_PSC_CONSOLE == 1
49 #define PSC_BASE MPC5XXX_PSC1
50 #elif CONFIG_PSC_CONSOLE == 2
51 #define PSC_BASE MPC5XXX_PSC2
52 #elif CONFIG_PSC_CONSOLE == 3
53 #define PSC_BASE MPC5XXX_PSC3
54 #elif CONFIG_PSC_CONSOLE == 4
55 #define PSC_BASE MPC5XXX_PSC4
56 #elif CONFIG_PSC_CONSOLE == 5
57 #define PSC_BASE MPC5XXX_PSC5
58 #elif CONFIG_PSC_CONSOLE == 6
59 #define PSC_BASE MPC5XXX_PSC6
61 #error CONFIG_PSC_CONSOLE must be in 1 ... 6
64 #if defined(CONFIG_SERIAL_MULTI) && !defined(CONFIG_PSC_CONSOLE2)
65 #error you must define CONFIG_PSC_CONSOLE2 if CONFIG_SERIAL_MULTI is set
68 #if defined(CONFIG_SERIAL_MULTI)
69 #if CONFIG_PSC_CONSOLE2 == 1
70 #define PSC_BASE2 MPC5XXX_PSC1
71 #elif CONFIG_PSC_CONSOLE2 == 2
72 #define PSC_BASE2 MPC5XXX_PSC2
73 #elif CONFIG_PSC_CONSOLE2 == 3
74 #define PSC_BASE2 MPC5XXX_PSC3
75 #elif CONFIG_PSC_CONSOLE2 == 4
76 #define PSC_BASE2 MPC5XXX_PSC4
77 #elif CONFIG_PSC_CONSOLE2 == 5
78 #define PSC_BASE2 MPC5XXX_PSC5
79 #elif CONFIG_PSC_CONSOLE2 == 6
80 #define PSC_BASE2 MPC5XXX_PSC6
82 #error CONFIG_PSC_CONSOLE2 must be in 1 ... 6
84 #endif /* CONFIG_SERIAL_MULTI */
86 #if defined(CONFIG_SERIAL_MULTI)
87 int serial_init_dev (unsigned long dev_base)
89 int serial_init (void)
92 #if defined(CONFIG_SERIAL_MULTI)
93 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
95 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
97 unsigned long baseclk;
101 psc->command = PSC_SEL_MODE_REG_1;
103 /* select clock sources */
104 psc->psc_clock_select = 0;
105 baseclk = (gd->ipb_clk + 16) / 32;
107 /* switch to UART mode */
110 /* configure parity, bit length and so on */
111 psc->mode = PSC_MODE_8_BITS | PSC_MODE_PARNONE;
112 psc->mode = PSC_MODE_ONE_STOP;
114 /* set up UART divisor */
115 div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
116 psc->ctur = (div >> 8) & 0xff;
117 psc->ctlr = div & 0xff;
119 /* disable all interrupts */
122 /* reset and enable Rx/Tx */
123 psc->command = PSC_RST_RX;
124 psc->command = PSC_RST_TX;
125 psc->command = PSC_RX_ENABLE | PSC_TX_ENABLE;
130 #if defined(CONFIG_SERIAL_MULTI)
131 void serial_putc_dev (unsigned long dev_base, const char c)
133 void serial_putc(const char c)
136 #if defined(CONFIG_SERIAL_MULTI)
137 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
139 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
143 #if defined(CONFIG_SERIAL_MULTI)
144 serial_putc_dev (dev_base, '\r');
149 /* Wait for last character to go. */
150 while (!(psc->psc_status & PSC_SR_TXEMP))
153 psc->psc_buffer_8 = c;
156 #if defined(CONFIG_SERIAL_MULTI)
157 void serial_putc_raw_dev(unsigned long dev_base, const char c)
159 void serial_putc_raw(const char c)
162 #if defined(CONFIG_SERIAL_MULTI)
163 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
165 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
167 /* Wait for last character to go. */
168 while (!(psc->psc_status & PSC_SR_TXEMP))
171 psc->psc_buffer_8 = c;
175 #if defined(CONFIG_SERIAL_MULTI)
176 void serial_puts_dev (unsigned long dev_base, const char *s)
178 void serial_puts (const char *s)
182 #if defined(CONFIG_SERIAL_MULTI)
183 serial_putc_dev (dev_base, *s++);
190 #if defined(CONFIG_SERIAL_MULTI)
191 int serial_getc_dev (unsigned long dev_base)
193 int serial_getc(void)
196 #if defined(CONFIG_SERIAL_MULTI)
197 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
199 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
202 /* Wait for a character to arrive. */
203 while (!(psc->psc_status & PSC_SR_RXRDY))
206 return psc->psc_buffer_8;
209 #if defined(CONFIG_SERIAL_MULTI)
210 int serial_tstc_dev (unsigned long dev_base)
212 int serial_tstc(void)
215 #if defined(CONFIG_SERIAL_MULTI)
216 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
218 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
221 return (psc->psc_status & PSC_SR_RXRDY);
224 #if defined(CONFIG_SERIAL_MULTI)
225 void serial_setbrg_dev (unsigned long dev_base)
227 void serial_setbrg(void)
230 #if defined(CONFIG_SERIAL_MULTI)
231 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
233 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
235 unsigned long baseclk, div;
237 baseclk = (gd->ipb_clk + 16) / 32;
239 /* set up UART divisor */
240 div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
241 psc->ctur = (div >> 8) & 0xFF;
242 psc->ctlr = div & 0xff;
245 #if defined(CONFIG_SERIAL_MULTI)
246 void serial_setrts_dev (unsigned long dev_base, int s)
248 void serial_setrts(int s)
251 #if defined(CONFIG_SERIAL_MULTI)
252 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
254 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
258 /* Assert RTS (become LOW) */
262 /* Negate RTS (become HIGH) */
267 #if defined(CONFIG_SERIAL_MULTI)
268 int serial_getcts_dev (unsigned long dev_base)
270 int serial_getcts(void)
273 #if defined(CONFIG_SERIAL_MULTI)
274 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
276 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
279 return (psc->ip & 0x1) ? 0 : 1;
282 #if defined(CONFIG_SERIAL_MULTI)
283 int serial0_init(void)
285 return (serial_init_dev(PSC_BASE));
288 int serial1_init(void)
290 return (serial_init_dev(PSC_BASE2));
292 void serial0_setbrg (void)
294 serial_setbrg_dev(PSC_BASE);
296 void serial1_setbrg (void)
298 serial_setbrg_dev(PSC_BASE2);
301 void serial0_putc(const char c)
303 serial_putc_dev(PSC_BASE,c);
306 void serial1_putc(const char c)
308 serial_putc_dev(PSC_BASE2, c);
310 void serial0_puts(const char *s)
312 serial_puts_dev(PSC_BASE, s);
315 void serial1_puts(const char *s)
317 serial_puts_dev(PSC_BASE2, s);
320 int serial0_getc(void)
322 return(serial_getc_dev(PSC_BASE));
325 int serial1_getc(void)
327 return(serial_getc_dev(PSC_BASE2));
329 int serial0_tstc(void)
331 return (serial_tstc_dev(PSC_BASE));
334 int serial1_tstc(void)
336 return (serial_tstc_dev(PSC_BASE2));
339 struct serial_device serial0_device =
351 __weak struct serial_device *default_serial_console(void)
353 return &serial0_device;
356 struct serial_device serial1_device =
367 #endif /* CONFIG_SERIAL_MULTI */
369 #endif /* CONFIG_PSC_CONSOLE */