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