2 * arch/ppc/kernel/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 * Matt Porter <mporter@mvista.com>
13 * Copyright 2002 MontaVista Software Inc.
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
21 #include <linux/config.h>
22 #include <linux/serialP.h>
23 #include <linux/serial_reg.h>
24 #include <asm/serial.h>
27 #define SERIAL_BAUD 9600
29 extern struct serial_state rs_table[];
31 static void (*serial_outb)(unsigned long, unsigned char);
32 static unsigned long (*serial_inb)(unsigned long);
36 unsigned long direct_inb(unsigned long addr)
41 void direct_outb(unsigned long addr, unsigned char val)
46 unsigned long io_inb(unsigned long port)
51 void io_outb(unsigned long port, unsigned char val)
56 unsigned long serial_init(int chan, void *ignored)
58 unsigned long com_port;
59 unsigned char lcr, dlm;
61 /* We need to find out which type io we're expecting. If it's
62 * 'SERIAL_IO_PORT', we get an offset from the isa_io_base.
63 * If it's 'SERIAL_IO_MEM', we can the exact location. -- Tom */
64 switch (rs_table[chan].io_type) {
66 com_port = rs_table[chan].port;
67 serial_outb = io_outb;
71 com_port = (unsigned long)rs_table[chan].iomem_base;
72 serial_outb = direct_outb;
73 serial_inb = direct_inb;
76 /* We can't deal with it. */
80 /* How far apart the registers are. */
81 shift = rs_table[chan].iomem_reg_shift;
84 lcr = serial_inb(com_port + (UART_LCR << shift));
85 /* Access baud rate */
86 serial_outb(com_port + (UART_LCR << shift), 0x80);
87 dlm = serial_inb(com_port + (UART_DLM << shift));
89 * Test if serial port is unconfigured.
90 * We assume that no-one uses less than 110 baud or
91 * less than 7 bits per character these days.
96 serial_outb(com_port + (UART_DLL << shift),
97 (BASE_BAUD / SERIAL_BAUD) & 0xFF);
98 serial_outb(com_port + (UART_DLM << shift),
99 (BASE_BAUD / SERIAL_BAUD) >> 8);
100 /* 8 data, 1 stop, no parity */
101 serial_outb(com_port + (UART_LCR << shift), 0x03);
103 serial_outb(com_port + (UART_MCR << shift), 0x03);
105 /* Clear & enable FIFOs */
106 serial_outb(com_port + (UART_FCR << shift), 0x07);
112 serial_putc(unsigned long com_port, unsigned char c)
114 while ((serial_inb(com_port + (UART_LSR << shift)) & UART_LSR_THRE) == 0)
116 serial_outb(com_port, c);
120 serial_getc(unsigned long com_port)
122 while ((serial_inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) == 0)
124 return serial_inb(com_port);
128 serial_tstc(unsigned long com_port)
130 return ((serial_inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) != 0);
134 serial_close(unsigned long com_port)
139 gen550_init(int i, struct serial_struct *serial_req)
141 rs_table[i].io_type = serial_req->io_type;
142 rs_table[i].iomem_base = serial_req->iomem_base;
143 rs_table[i].iomem_reg_shift = serial_req->iomem_reg_shift;
146 #ifdef CONFIG_SERIAL_TEXT_DEBUG
148 gen550_progress(char *s, unsigned short hex)
150 volatile unsigned int progress_debugport;
153 progress_debugport = serial_init(0, NULL);
155 serial_putc(progress_debugport, '\r');
157 while ((c = *s++) != 0)
158 serial_putc(progress_debugport, c);
160 serial_putc(progress_debugport, '\n');
161 serial_putc(progress_debugport, '\r');
163 #endif /* CONFIG_SERIAL_TEXT_DEBUG */