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/config.h>
12 #include <linux/types.h>
13 #include <asm/ppcdebug.h>
14 #include <asm/processor.h>
16 #include <asm/uaccess.h>
17 #include <asm/machdep.h>
21 extern u8
real_readb(volatile u8 __iomem
*addr
);
22 extern void real_writeb(u8 data
, volatile u8 __iomem
*addr
);
25 /* this struct must be packed */
26 unsigned char rbr
; /* 0 */
27 unsigned char ier
; /* 1 */
28 unsigned char fcr
; /* 2 */
29 unsigned char lcr
; /* 3 */
30 unsigned char mcr
; /* 4 */
31 unsigned char lsr
; /* 5 */
32 unsigned char msr
; /* 6 */
33 unsigned char scr
; /* 7 */
42 #define LSR_DR 0x01 /* Data ready */
43 #define LSR_OE 0x02 /* Overrun */
44 #define LSR_PE 0x04 /* Parity error */
45 #define LSR_FE 0x08 /* Framing error */
46 #define LSR_BI 0x10 /* Break */
47 #define LSR_THRE 0x20 /* Xmit holding register empty */
48 #define LSR_TEMT 0x40 /* Xmitter empty */
49 #define LSR_ERR 0x80 /* Error */
51 static volatile struct NS16550 __iomem
*udbg_comport
;
53 static void udbg_550_putc(unsigned char c
)
56 while ((in_8(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
58 out_8(&udbg_comport
->thr
, c
);
64 static int udbg_550_getc_poll(void)
67 if ((in_8(&udbg_comport
->lsr
) & LSR_DR
) != 0)
68 return in_8(&udbg_comport
->rbr
);
75 static unsigned char udbg_550_getc(void)
78 while ((in_8(&udbg_comport
->lsr
) & LSR_DR
) == 0)
80 return in_8(&udbg_comport
->rbr
);
85 void udbg_init_uart(void __iomem
*comport
, unsigned int speed
)
87 u16 dll
= speed
? (115200 / speed
) : 12;
90 udbg_comport
= (struct NS16550 __iomem
*)comport
;
91 out_8(&udbg_comport
->lcr
, 0x00);
92 out_8(&udbg_comport
->ier
, 0xff);
93 out_8(&udbg_comport
->ier
, 0x00);
94 out_8(&udbg_comport
->lcr
, 0x80); /* Access baud rate */
95 out_8(&udbg_comport
->dll
, dll
& 0xff); /* 1 = 115200, 2 = 57600,
96 3 = 38400, 12 = 9600 baud */
97 out_8(&udbg_comport
->dlm
, dll
>> 8); /* dll >> 8 which should be zero
99 out_8(&udbg_comport
->lcr
, 0x03); /* 8 data, 1 stop, no parity */
100 out_8(&udbg_comport
->mcr
, 0x03); /* RTS/DTR */
101 out_8(&udbg_comport
->fcr
,0x07); /* Clear & enable FIFOs */
102 ppc_md
.udbg_putc
= udbg_550_putc
;
103 ppc_md
.udbg_getc
= udbg_550_getc
;
104 ppc_md
.udbg_getc_poll
= udbg_550_getc_poll
;
108 #ifdef CONFIG_PPC_MAPLE
109 void udbg_maple_real_putc(unsigned char c
)
112 while ((real_readb(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
114 real_writeb(c
, &udbg_comport
->thr
); eieio();
116 udbg_maple_real_putc('\r');
120 void udbg_init_maple_realmode(void)
122 udbg_comport
= (volatile struct NS16550 __iomem
*)0xf40003f8;
124 ppc_md
.udbg_putc
= udbg_maple_real_putc
;
125 ppc_md
.udbg_getc
= NULL
;
126 ppc_md
.udbg_getc_poll
= NULL
;
128 #endif /* CONFIG_PPC_MAPLE */