File: /usr/src/linux/arch/ppc/boot/common/ns16550.c
1 /*
2 * BK Id: SCCS/s.ns16550.c 1.9 07/30/01 17:19:40 trini
3 */
4 /*
5 * COM1 NS16550 support
6 */
7
8 #include <linux/config.h>
9 #include <linux/serialP.h>
10 #include <linux/serial_reg.h>
11 #include <asm/serial.h>
12
13 extern void outb(int port, unsigned char val);
14 extern unsigned char inb(int port);
15 extern unsigned long ISA_io;
16
17 static struct serial_state rs_table[RS_TABLE_SIZE] = {
18 SERIAL_PORT_DFNS /* Defined in <asm/serial.h> */
19 };
20
21 static int shift;
22
23 unsigned long serial_init(int chan) {
24 unsigned long com_port;
25
26 /* We need to find out which type io we're expecting. If it's
27 * 'SERIAL_IO_PORT', we get an offset from the isa_io_base.
28 * If it's 'SERIAL_IO_MEM', we can the exact location. -- Tom */
29 switch (rs_table[chan].io_type) {
30 case SERIAL_IO_PORT:
31 com_port = rs_table[chan].port;
32 break;
33 case SERIAL_IO_MEM:
34 com_port = (unsigned long)rs_table[chan].iomem_base;
35 break;
36 default:
37 /* We can't deal with it. */
38 return -1;
39 }
40
41 /* How far apart the registers are. */
42 shift = rs_table[chan].iomem_reg_shift;
43
44 /* See if port is present */
45 outb(com_port + (UART_LCR << shift), 0x00);
46 outb(com_port + (UART_IER << shift), 0x00);
47 /* Access baud rate */
48 outb(com_port + (UART_LCR << shift), 0x80);
49 #ifdef CONFIG_SERIAL_CONSOLE_NONSTD
50 /* Input clock. */
51 outb(com_port + (UART_DLL << shift),
52 (BASE_BAUD / CONFIG_SERIAL_CONSOLE_BAUD));
53 outb(com_port + (UART_DLM << shift),
54 (BASE_BAUD / CONFIG_SERIAL_CONSOLE_BAUD) >> 8);
55 #endif
56 /* 8 data, 1 stop, no parity */
57 outb(com_port + (UART_LCR << shift), 0x03);
58 /* RTS/DTR */
59 outb(com_port + (UART_MCR << shift), 0x03);
60 /* Clear & enable FIFOs */
61 outb(com_port + (UART_FCR << shift), 0x07);
62
63 return (com_port);
64 }
65
66 void
67 serial_putc(unsigned long com_port, unsigned char c)
68 {
69 while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_THRE) == 0)
70 ;
71 outb(com_port, c);
72 }
73
74 unsigned char
75 serial_getc(unsigned long com_port)
76 {
77 while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) == 0)
78 ;
79 return inb(com_port);
80 }
81
82 int
83 serial_tstc(unsigned long com_port)
84 {
85 return ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) != 0);
86 }
87