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/tty.h> /* For linux/serial_core.h */
21 #include <linux/serial_core.h>
22 #include <linux/serialP.h>
23 #include <linux/serial_reg.h>
24 #include <asm/machdep.h>
25 #include <asm/serial.h>
28 #define SERIAL_BAUD 9600
30 static struct serial_state rs_table
[RS_TABLE_SIZE
] = {
31 SERIAL_PORT_DFNS
/* defined in <asm/serial.h> */
34 static void (*serial_outb
)(unsigned long, unsigned char);
35 static unsigned long (*serial_inb
)(unsigned long);
39 unsigned long direct_inb(unsigned long addr
)
44 void direct_outb(unsigned long addr
, unsigned char val
)
49 unsigned long io_inb(unsigned long port
)
54 void io_outb(unsigned long port
, unsigned char val
)
59 unsigned long serial_init(int chan
, void *ignored
)
61 unsigned long com_port
;
62 unsigned char lcr
, dlm
;
64 /* We need to find out which type io we're expecting. If it's
65 * 'SERIAL_IO_PORT', we get an offset from the isa_io_base.
66 * If it's 'SERIAL_IO_MEM', we can the exact location. -- Tom */
67 switch (rs_table
[chan
].io_type
) {
69 com_port
= rs_table
[chan
].port
;
70 serial_outb
= io_outb
;
74 com_port
= (unsigned long)rs_table
[chan
].iomem_base
;
75 serial_outb
= direct_outb
;
76 serial_inb
= direct_inb
;
79 /* We can't deal with it. */
83 /* How far apart the registers are. */
84 shift
= rs_table
[chan
].iomem_reg_shift
;
87 lcr
= serial_inb(com_port
+ (UART_LCR
<< shift
));
89 /* Access baud rate */
90 serial_outb(com_port
+ (UART_LCR
<< shift
), UART_LCR_DLAB
);
91 dlm
= serial_inb(com_port
+ (UART_DLM
<< shift
));
94 * Test if serial port is unconfigured
95 * We assume that no-one uses less than 110 baud or
96 * less than 7 bits per character these days.
99 if ((dlm
<= 4) && (lcr
& 2)) {
100 /* port is configured, put the old LCR back */
101 serial_outb(com_port
+ (UART_LCR
<< shift
), lcr
);
105 serial_outb(com_port
+ (UART_DLL
<< shift
),
106 (rs_table
[chan
].baud_base
/ SERIAL_BAUD
) & 0xFF);
107 serial_outb(com_port
+ (UART_DLM
<< shift
),
108 (rs_table
[chan
].baud_base
/ SERIAL_BAUD
) >> 8);
109 /* 8 data, 1 stop, no parity */
110 serial_outb(com_port
+ (UART_LCR
<< shift
), 0x03);
112 serial_outb(com_port
+ (UART_MCR
<< shift
), 0x03);
114 /* Clear & enable FIFOs */
115 serial_outb(com_port
+ (UART_FCR
<< shift
), 0x07);
122 serial_putc(unsigned long com_port
, unsigned char c
)
124 while ((serial_inb(com_port
+ (UART_LSR
<< shift
)) & UART_LSR_THRE
) == 0)
126 serial_outb(com_port
, c
);
130 serial_getc(unsigned long com_port
)
132 while ((serial_inb(com_port
+ (UART_LSR
<< shift
)) & UART_LSR_DR
) == 0)
134 return serial_inb(com_port
);
138 serial_tstc(unsigned long com_port
)
140 return ((serial_inb(com_port
+ (UART_LSR
<< shift
)) & UART_LSR_DR
) != 0);
144 serial_close(unsigned long com_port
)
149 gen550_init(int i
, struct uart_port
*serial_req
)
151 rs_table
[i
].io_type
= serial_req
->iotype
;
152 rs_table
[i
].port
= serial_req
->line
;
153 rs_table
[i
].iomem_base
= serial_req
->membase
;
154 rs_table
[i
].iomem_reg_shift
= serial_req
->regshift
;
157 #ifdef CONFIG_SERIAL_TEXT_DEBUG
159 gen550_progress(char *s
, unsigned short hex
)
161 volatile unsigned int progress_debugport
;
164 progress_debugport
= serial_init(0, NULL
);
166 serial_putc(progress_debugport
, '\r');
168 while ((c
= *s
++) != 0)
169 serial_putc(progress_debugport
, c
);
171 serial_putc(progress_debugport
, '\n');
172 serial_putc(progress_debugport
, '\r');
174 #endif /* CONFIG_SERIAL_TEXT_DEBUG */