Merge with 2.5.75.
[linux-2.6/linux-mips.git] / arch / ppc / syslib / gen550_dbg.c
blob7fb0b41a241c455c41dfd730400bc2c98d8ff097
1 /*
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
9 * 16550 support.
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
16 * or implied.
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>
26 #include <asm/io.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);
37 static int shift;
39 unsigned long direct_inb(unsigned long addr)
41 return readb(addr);
44 void direct_outb(unsigned long addr, unsigned char val)
46 writeb(val, addr);
49 unsigned long io_inb(unsigned long port)
51 return inb(port);
54 void io_outb(unsigned long port, unsigned char val)
56 outb(val, port);
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) {
68 case SERIAL_IO_PORT:
69 com_port = rs_table[chan].port;
70 serial_outb = io_outb;
71 serial_inb = io_inb;
72 break;
73 case SERIAL_IO_MEM:
74 com_port = (unsigned long)rs_table[chan].iomem_base;
75 serial_outb = direct_outb;
76 serial_inb = direct_inb;
77 break;
78 default:
79 /* We can't deal with it. */
80 return -1;
83 /* How far apart the registers are. */
84 shift = rs_table[chan].iomem_reg_shift;
86 /* save the LCR */
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.
97 * -- paulus.
99 if ((dlm <= 4) && (lcr & 2)) {
100 /* port is configured, put the old LCR back */
101 serial_outb(com_port + (UART_LCR << shift), lcr);
103 else {
104 /* Input clock. */
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);
111 /* RTS/DTR */
112 serial_outb(com_port + (UART_MCR << shift), 0x03);
114 /* Clear & enable FIFOs */
115 serial_outb(com_port + (UART_FCR << shift), 0x07);
118 return (com_port);
121 void
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);
129 unsigned char
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);
143 void
144 serial_close(unsigned long com_port)
148 void
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
158 void
159 gen550_progress(char *s, unsigned short hex)
161 volatile unsigned int progress_debugport;
162 volatile char c;
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 */