2 * udbg for for NS16550 compatable serial ports
4 * Copyright (C) 2001-2005 PPC 64 Team, IBM Corp
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 #include <linux/types.h>
15 extern u8
real_readb(volatile u8 __iomem
*addr
);
16 extern void real_writeb(u8 data
, volatile u8 __iomem
*addr
);
17 extern u8
real_205_readb(volatile u8 __iomem
*addr
);
18 extern void real_205_writeb(u8 data
, volatile u8 __iomem
*addr
);
21 /* this struct must be packed */
22 unsigned char rbr
; /* 0 */
23 unsigned char ier
; /* 1 */
24 unsigned char fcr
; /* 2 */
25 unsigned char lcr
; /* 3 */
26 unsigned char mcr
; /* 4 */
27 unsigned char lsr
; /* 5 */
28 unsigned char msr
; /* 6 */
29 unsigned char scr
; /* 7 */
38 #define LSR_DR 0x01 /* Data ready */
39 #define LSR_OE 0x02 /* Overrun */
40 #define LSR_PE 0x04 /* Parity error */
41 #define LSR_FE 0x08 /* Framing error */
42 #define LSR_BI 0x10 /* Break */
43 #define LSR_THRE 0x20 /* Xmit holding register empty */
44 #define LSR_TEMT 0x40 /* Xmitter empty */
45 #define LSR_ERR 0x80 /* Error */
49 static struct NS16550 __iomem
*udbg_comport
;
51 static void udbg_550_flush(void)
54 while ((in_8(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
59 static void udbg_550_putc(char c
)
65 out_8(&udbg_comport
->thr
, c
);
69 static int udbg_550_getc_poll(void)
72 if ((in_8(&udbg_comport
->lsr
) & LSR_DR
) != 0)
73 return in_8(&udbg_comport
->rbr
);
80 static int udbg_550_getc(void)
83 while ((in_8(&udbg_comport
->lsr
) & LSR_DR
) == 0)
85 return in_8(&udbg_comport
->rbr
);
90 void udbg_init_uart(void __iomem
*comport
, unsigned int speed
,
93 unsigned int dll
, base_bauds
;
100 base_bauds
= clock
/ 16;
101 dll
= base_bauds
/ speed
;
104 udbg_comport
= (struct NS16550 __iomem
*)comport
;
105 out_8(&udbg_comport
->lcr
, 0x00);
106 out_8(&udbg_comport
->ier
, 0xff);
107 out_8(&udbg_comport
->ier
, 0x00);
108 out_8(&udbg_comport
->lcr
, LCR_DLAB
);
109 out_8(&udbg_comport
->dll
, dll
& 0xff);
110 out_8(&udbg_comport
->dlm
, dll
>> 8);
111 /* 8 data, 1 stop, no parity */
112 out_8(&udbg_comport
->lcr
, 0x03);
114 out_8(&udbg_comport
->mcr
, 0x03);
115 /* Clear & enable FIFOs */
116 out_8(&udbg_comport
->fcr
,0x07);
117 udbg_putc
= udbg_550_putc
;
118 udbg_flush
= udbg_550_flush
;
119 udbg_getc
= udbg_550_getc
;
120 udbg_getc_poll
= udbg_550_getc_poll
;
124 unsigned int udbg_probe_uart_speed(void __iomem
*comport
, unsigned int clock
)
126 unsigned int dll
, dlm
, divisor
, prescaler
, speed
;
128 struct NS16550 __iomem
*port
= comport
;
130 old_lcr
= in_8(&port
->lcr
);
132 /* select divisor latch registers. */
133 out_8(&port
->lcr
, LCR_DLAB
);
135 /* now, read the divisor */
136 dll
= in_8(&port
->dll
);
137 dlm
= in_8(&port
->dlm
);
138 divisor
= dlm
<< 8 | dll
;
140 /* check prescaling */
141 if (in_8(&port
->mcr
) & 0x80)
146 /* restore the LCR */
147 out_8(&port
->lcr
, old_lcr
);
149 /* calculate speed */
150 speed
= (clock
/ prescaler
) / (divisor
* 16);
153 if (speed
> (clock
/ 16))
159 #ifdef CONFIG_PPC_MAPLE
160 void udbg_maple_real_flush(void)
163 while ((real_readb(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
168 void udbg_maple_real_putc(char c
)
172 udbg_maple_real_putc('\r');
173 udbg_maple_real_flush();
174 real_writeb(c
, &udbg_comport
->thr
); eieio();
178 void __init
udbg_init_maple_realmode(void)
180 udbg_comport
= (struct NS16550 __iomem
*)0xf40003f8;
182 udbg_putc
= udbg_maple_real_putc
;
183 udbg_flush
= udbg_maple_real_flush
;
185 udbg_getc_poll
= NULL
;
187 #endif /* CONFIG_PPC_MAPLE */
189 #ifdef CONFIG_PPC_PASEMI
190 void udbg_pas_real_flush(void)
193 while ((real_205_readb(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
198 void udbg_pas_real_putc(char c
)
202 udbg_pas_real_putc('\r');
203 udbg_pas_real_flush();
204 real_205_writeb(c
, &udbg_comport
->thr
); eieio();
208 void udbg_init_pas_realmode(void)
210 udbg_comport
= (struct NS16550 __iomem
*)0xfcff03f8UL
;
212 udbg_putc
= udbg_pas_real_putc
;
213 udbg_flush
= udbg_pas_real_flush
;
215 udbg_getc_poll
= NULL
;
217 #endif /* CONFIG_PPC_MAPLE */
219 #ifdef CONFIG_PPC_EARLY_DEBUG_44x
220 #include <platforms/44x/44x.h>
222 static int udbg_44x_as1_flush(void)
225 while ((as1_readb(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
230 static void udbg_44x_as1_putc(char c
)
234 udbg_44x_as1_putc('\r');
235 udbg_44x_as1_flush();
236 as1_writeb(c
, &udbg_comport
->thr
); eieio();
240 static int udbg_44x_as1_getc(void)
243 while ((as1_readb(&udbg_comport
->lsr
) & LSR_DR
) == 0)
244 ; /* wait for char */
245 return as1_readb(&udbg_comport
->rbr
);
250 void __init
udbg_init_44x_as1(void)
253 (struct NS16550 __iomem
*)PPC44x_EARLY_DEBUG_VIRTADDR
;
255 udbg_putc
= udbg_44x_as1_putc
;
256 udbg_flush
= udbg_44x_as1_flush
;
257 udbg_getc
= udbg_44x_as1_getc
;
259 #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
261 #ifdef CONFIG_PPC_EARLY_DEBUG_40x
262 static void udbg_40x_real_flush(void)
265 while ((real_readb(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
270 static void udbg_40x_real_putc(char c
)
274 udbg_40x_real_putc('\r');
275 udbg_40x_real_flush();
276 real_writeb(c
, &udbg_comport
->thr
); eieio();
280 static int udbg_40x_real_getc(void)
283 while ((real_readb(&udbg_comport
->lsr
) & LSR_DR
) == 0)
284 ; /* wait for char */
285 return real_readb(&udbg_comport
->rbr
);
290 void __init
udbg_init_40x_realmode(void)
292 udbg_comport
= (struct NS16550 __iomem
*)
293 CONFIG_PPC_EARLY_DEBUG_40x_PHYSADDR
;
295 udbg_putc
= udbg_40x_real_putc
;
296 udbg_flush
= udbg_40x_real_flush
;
297 udbg_getc
= udbg_40x_real_getc
;
298 udbg_getc_poll
= NULL
;
300 #endif /* CONFIG_PPC_EARLY_DEBUG_40x */