blob: 4f00c93ac870240cac5807aadb8c29c15120198c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Grant C. Likely1a42e532006-01-19 01:12:48 -070011#if defined(CONFIG_XILINX_VIRTEX)
12#include <platforms/4xx/xparameters/xparameters.h>
13#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "nonstdio.h"
15#include "serial.h"
16
17#define SERIAL_BAUD 9600
18
19extern unsigned long ISA_io;
20
21static struct serial_state rs_table[RS_TABLE_SIZE] = {
22 SERIAL_PORT_DFNS /* Defined in <asm/serial.h> */
23};
24
25static int shift;
26
27unsigned long serial_init(int chan, void *ignored)
28{
Tom Rini66b375b2005-09-09 13:01:47 -070029 unsigned long com_port, base_baud;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 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;
Tom Rini66b375b2005-09-09 13:01:47 -070049 /* Base baud.. */
50 base_baud = rs_table[chan].baud_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
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),
Tom Rini66b375b2005-09-09 13:01:47 -070070 (base_baud / SERIAL_BAUD) & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 outb(com_port + (UART_DLM << shift),
Tom Rini66b375b2005-09-09 13:01:47 -070072 (base_baud / SERIAL_BAUD) >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 /* 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
84void
85serial_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
92unsigned char
93serial_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
100int
101serial_tstc(unsigned long com_port)
102{
103 return ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) != 0);
104}