initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / ppc / syslib / gen550_dbg.c
blob4692ba719ce945361bcacd91a82296a21753efbc
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/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>
28 #include <asm/io.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);
39 static int shift;
41 unsigned long direct_inb(unsigned long addr)
43 return readb(addr);
46 void direct_outb(unsigned long addr, unsigned char val)
48 writeb(val, addr);
51 unsigned long io_inb(unsigned long port)
53 return inb(port);
56 void io_outb(unsigned long port, unsigned char val)
58 outb(val, port);
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) {
70 case SERIAL_IO_PORT:
71 com_port = rs_table[chan].port;
72 serial_outb = io_outb;
73 serial_inb = io_inb;
74 break;
75 case SERIAL_IO_MEM:
76 com_port = (unsigned long)rs_table[chan].iomem_base;
77 serial_outb = direct_outb;
78 serial_inb = direct_inb;
79 break;
80 default:
81 /* We can't deal with it. */
82 return -1;
85 /* How far apart the registers are. */
86 shift = rs_table[chan].iomem_reg_shift;
88 /* save the LCR */
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.
99 * -- paulus.
101 if ((dlm <= 4) && (lcr & 2)) {
102 /* port is configured, put the old LCR back */
103 serial_outb(com_port + (UART_LCR << shift), lcr);
105 else {
106 /* Input clock. */
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);
113 /* RTS/DTR */
114 serial_outb(com_port + (UART_MCR << shift), 0x03);
116 /* Clear & enable FIFOs */
117 serial_outb(com_port + (UART_FCR << shift), 0x07);
120 return (com_port);
123 void
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);
131 unsigned char
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);
145 void
146 serial_close(unsigned long com_port)
150 void
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
160 void
161 gen550_progress(char *s, unsigned short hex)
163 volatile unsigned int progress_debugport;
164 volatile char c;
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 */