Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / arch / ppc / boot / common / ns16550.c
1 /*
2  * COM1 NS16550 support
3  */
4
5 #include <linux/config.h>
6 #include <linux/types.h>
7 #include <linux/serial.h>
8 #include <linux/serial_reg.h>
9 #include <asm/serial.h>
10
11 #if defined(CONFIG_XILINX_VIRTEX)
12 #include <platforms/4xx/xparameters/xparameters.h>
13 #endif
14 #include "nonstdio.h"
15 #include "serial.h"
16
17 #define SERIAL_BAUD     9600
18
19 extern unsigned long ISA_io;
20
21 static struct serial_state rs_table[RS_TABLE_SIZE] = {
22         SERIAL_PORT_DFNS        /* Defined in <asm/serial.h> */
23 };
24
25 static int shift;
26
27 unsigned long serial_init(int chan, void *ignored)
28 {
29         unsigned long com_port, base_baud;
30         unsigned char lcr, dlm;
31
32         /* We need to find out which type io we're expecting.  If it's
33          * 'SERIAL_IO_PORT', we get an offset from the isa_io_base.
34          * If it's 'SERIAL_IO_MEM', we can the exact location.  -- Tom */
35         switch (rs_table[chan].io_type) {
36                 case SERIAL_IO_PORT:
37                         com_port = rs_table[chan].port;
38                         break;
39                 case SERIAL_IO_MEM:
40                         com_port = (unsigned long)rs_table[chan].iomem_base;
41                         break;
42                 default:
43                         /* We can't deal with it. */
44                         return -1;
45         }
46
47         /* How far apart the registers are. */
48         shift = rs_table[chan].iomem_reg_shift;
49         /* Base baud.. */
50         base_baud = rs_table[chan].baud_base;
51         
52         /* save the LCR */
53         lcr = inb(com_port + (UART_LCR << shift));
54         /* Access baud rate */
55         outb(com_port + (UART_LCR << shift), 0x80);
56         dlm = inb(com_port + (UART_DLM << shift));
57         /*
58          * Test if serial port is unconfigured.
59          * We assume that no-one uses less than 110 baud or
60          * less than 7 bits per character these days.
61          *  -- paulus.
62          */
63
64         if ((dlm <= 4) && (lcr & 2))
65                 /* port is configured, put the old LCR back */
66                 outb(com_port + (UART_LCR << shift), lcr);
67         else {
68                 /* Input clock. */
69                 outb(com_port + (UART_DLL << shift),
70                      (base_baud / SERIAL_BAUD) & 0xFF);
71                 outb(com_port + (UART_DLM << shift),
72                      (base_baud / SERIAL_BAUD) >> 8);
73                 /* 8 data, 1 stop, no parity */
74                 outb(com_port + (UART_LCR << shift), 0x03);
75                 /* RTS/DTR */
76                 outb(com_port + (UART_MCR << shift), 0x03);
77         }
78         /* Clear & enable FIFOs */
79         outb(com_port + (UART_FCR << shift), 0x07);
80
81         return (com_port);
82 }
83
84 void
85 serial_putc(unsigned long com_port, unsigned char c)
86 {
87         while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_THRE) == 0)
88                 ;
89         outb(com_port, c);
90 }
91
92 unsigned char
93 serial_getc(unsigned long com_port)
94 {
95         while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) == 0)
96                 ;
97         return inb(com_port);
98 }
99
100 int
101 serial_tstc(unsigned long com_port)
102 {
103         return ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) != 0);
104 }