2 * arch/ppc/syslib/gen550_dbg.c
4 * A library of polled 16550 serial routines. These are intended to
5 * be used to support progress messages, xmon, kgdb, etc. on a
6 * variety of platforms.
8 * Adapted from lots of code ripped from the arch/ppc/boot/ polled
11 * Author: Matt Porter <mporter@mvista.com>
13 * 2002-2003 (c) MontaVista Software, Inc. This file is licensed under
14 * the terms of the GNU General Public License version 2. This program
15 * is licensed "as is" without any warranty of any kind, whether express
19 #include <linux/config.h>
20 #include <linux/types.h>
21 #include <linux/serial.h>
22 #include <linux/tty.h> /* For linux/serial_core.h */
23 #include <linux/serial_core.h>
24 #include <linux/serialP.h>
25 #include <linux/serial_reg.h>
26 #include <asm/machdep.h>
27 #include <asm/serial.h>
30 #define SERIAL_BAUD 9600
32 static struct serial_state rs_table
[RS_TABLE_SIZE
] = {
33 SERIAL_PORT_DFNS
/* defined in <asm/serial.h> */
36 static void (*serial_outb
)(unsigned long, unsigned char);
37 static unsigned long (*serial_inb
)(unsigned long);
41 unsigned long direct_inb(unsigned long addr
)
46 void direct_outb(unsigned long addr
, unsigned char val
)
51 unsigned long io_inb(unsigned long port
)
56 void io_outb(unsigned long port
, unsigned char val
)
61 unsigned long serial_init(int chan
, void *ignored
)
63 unsigned long com_port
;
64 unsigned char lcr
, dlm
;
66 /* We need to find out which type io we're expecting. If it's
67 * 'SERIAL_IO_PORT', we get an offset from the isa_io_base.
68 * If it's 'SERIAL_IO_MEM', we can the exact location. -- Tom */
69 switch (rs_table
[chan
].io_type
) {
71 com_port
= rs_table
[chan
].port
;
72 serial_outb
= io_outb
;
76 com_port
= (unsigned long)rs_table
[chan
].iomem_base
;
77 serial_outb
= direct_outb
;
78 serial_inb
= direct_inb
;
81 /* We can't deal with it. */
85 /* How far apart the registers are. */
86 shift
= rs_table
[chan
].iomem_reg_shift
;
89 lcr
= serial_inb(com_port
+ (UART_LCR
<< shift
));
91 /* Access baud rate */
92 serial_outb(com_port
+ (UART_LCR
<< shift
), UART_LCR_DLAB
);
93 dlm
= serial_inb(com_port
+ (UART_DLM
<< shift
));
96 * Test if serial port is unconfigured
97 * We assume that no-one uses less than 110 baud or
98 * less than 7 bits per character these days.
101 if ((dlm
<= 4) && (lcr
& 2)) {
102 /* port is configured, put the old LCR back */
103 serial_outb(com_port
+ (UART_LCR
<< shift
), lcr
);
107 serial_outb(com_port
+ (UART_DLL
<< shift
),
108 (rs_table
[chan
].baud_base
/ SERIAL_BAUD
) & 0xFF);
109 serial_outb(com_port
+ (UART_DLM
<< shift
),
110 (rs_table
[chan
].baud_base
/ SERIAL_BAUD
) >> 8);
111 /* 8 data, 1 stop, no parity */
112 serial_outb(com_port
+ (UART_LCR
<< shift
), 0x03);
114 serial_outb(com_port
+ (UART_MCR
<< shift
), 0x03);
116 /* Clear & enable FIFOs */
117 serial_outb(com_port
+ (UART_FCR
<< shift
), 0x07);
124 serial_putc(unsigned long com_port
, unsigned char c
)
126 while ((serial_inb(com_port
+ (UART_LSR
<< shift
)) & UART_LSR_THRE
) == 0)
128 serial_outb(com_port
, c
);
132 serial_getc(unsigned long com_port
)
134 while ((serial_inb(com_port
+ (UART_LSR
<< shift
)) & UART_LSR_DR
) == 0)
136 return serial_inb(com_port
);
140 serial_tstc(unsigned long com_port
)
142 return ((serial_inb(com_port
+ (UART_LSR
<< shift
)) & UART_LSR_DR
) != 0);
146 serial_close(unsigned long com_port
)
151 gen550_init(int i
, struct uart_port
*serial_req
)
153 rs_table
[i
].io_type
= serial_req
->iotype
;
154 rs_table
[i
].port
= serial_req
->iobase
;
155 rs_table
[i
].iomem_base
= serial_req
->membase
;
156 rs_table
[i
].iomem_reg_shift
= serial_req
->regshift
;
159 #ifdef CONFIG_SERIAL_TEXT_DEBUG
161 gen550_progress(char *s
, unsigned short hex
)
163 volatile unsigned int progress_debugport
;
166 progress_debugport
= serial_init(0, NULL
);
168 serial_putc(progress_debugport
, '\r');
170 while ((c
= *s
++) != 0)
171 serial_putc(progress_debugport
, c
);
173 serial_putc(progress_debugport
, '\n');
174 serial_putc(progress_debugport
, '\r');
176 #endif /* CONFIG_SERIAL_TEXT_DEBUG */