summaryrefslogtreecommitdiffstats
path: root/drivers/char/esp.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/char/esp.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/char/esp.c')
-rw-r--r--drivers/char/esp.c2630
1 files changed, 2630 insertions, 0 deletions
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
new file mode 100644
index 000000000000..9f53d2fcc360
--- /dev/null
+++ b/drivers/char/esp.c
@@ -0,0 +1,2630 @@
+/*
+ * esp.c - driver for Hayes ESP serial cards
+ *
+ * --- Notices from serial.c, upon which this driver is based ---
+ *
+ * Copyright (C) 1991, 1992 Linus Torvalds
+ *
+ * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now
+ * much more extensible to support other serial cards based on the
+ * 16450/16550A UART's. Added support for the AST FourPort and the
+ * Accent Async board.
+ *
+ * set_serial_info fixed to set the flags, custom divisor, and uart
+ * type fields. Fix suggested by Michael K. Johnson 12/12/92.
+ *
+ * 11/95: TIOCMIWAIT, TIOCGICOUNT by Angelo Haritsis <ah@doc.ic.ac.uk>
+ *
+ * 03/96: Modularised by Angelo Haritsis <ah@doc.ic.ac.uk>
+ *
+ * rs_set_termios fixed to look also for changes of the input
+ * flags INPCK, BRKINT, PARMRK, IGNPAR and IGNBRK.
+ * Bernd Anh�pl 05/17/96.
+ *
+ * --- End of notices from serial.c ---
+ *
+ * Support for the ESP serial card by Andrew J. Robinson
+ * <arobinso@nyx.net> (Card detection routine taken from a patch
+ * by Dennis J. Boylan). Patches to allow use with 2.1.x contributed
+ * by Chris Faylor.
+ *
+ * Most recent changes: (Andrew J. Robinson)
+ * Support for PIO mode. This allows the driver to work properly with
+ * multiport cards.
+ *
+ * Arnaldo Carvalho de Melo <acme@conectiva.com.br> -
+ * several cleanups, use module_init/module_exit, etc
+ *
+ * This module exports the following rs232 io functions:
+ *
+ * int espserial_init(void);
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial.h>
+#include <linux/serialP.h>
+#include <linux/serial_reg.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/fcntl.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/mm.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/bitops.h>
+
+#include <asm/dma.h>
+#include <linux/slab.h>
+#include <asm/uaccess.h>
+
+#include <linux/hayesesp.h>
+
+#define NR_PORTS 64 /* maximum number of ports */
+#define NR_PRIMARY 8 /* maximum number of primary ports */
+#define REGION_SIZE 8 /* size of io region to request */
+
+/* The following variables can be set by giving module options */
+static int irq[NR_PRIMARY]; /* IRQ for each base port */
+static unsigned int divisor[NR_PRIMARY]; /* custom divisor for each port */
+static unsigned int dma = ESP_DMA_CHANNEL; /* DMA channel */
+static unsigned int rx_trigger = ESP_RX_TRIGGER;
+static unsigned int tx_trigger = ESP_TX_TRIGGER;
+static unsigned int flow_off = ESP_FLOW_OFF;
+static unsigned int flow_on = ESP_FLOW_ON;
+static unsigned int rx_timeout = ESP_RX_TMOUT;
+static unsigned int pio_threshold = ESP_PIO_THRESHOLD;
+
+MODULE_LICENSE("GPL");
+
+module_param_array(irq, int, NULL, 0);
+module_param_array(divisor, uint, NULL, 0);
+module_param(dma, uint, 0);
+module_param(rx_trigger, uint, 0);
+module_param(tx_trigger, uint, 0);
+module_param(flow_off, uint, 0);
+module_param(flow_on, uint, 0);
+module_param(rx_timeout, uint, 0);
+module_param(pio_threshold, uint, 0);
+
+/* END */
+
+static char *dma_buffer;
+static int dma_bytes;
+static struct esp_pio_buffer *free_pio_buf;
+
+#define DMA_BUFFER_SZ 1024
+
+#define WAKEUP_CHARS 1024
+
+static char serial_name[] __initdata = "ESP serial driver";
+static char serial_version[] __initdata = "2.2";
+
+static struct tty_driver *esp_driver;
+
+/* serial subtype definitions */
+#define SERIAL_TYPE_NORMAL 1
+
+/*
+ * Serial driver configuration section. Here are the various options:
+ *
+ * SERIAL_PARANOIA_CHECK
+ * Check the magic number for the esp_structure where
+ * ever possible.
+ */
+
+#undef SERIAL_PARANOIA_CHECK
+#define SERIAL_DO_RESTART
+
+#undef SERIAL_DEBUG_INTR
+#undef SERIAL_DEBUG_OPEN
+#undef SERIAL_DEBUG_FLOW
+
+#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
+#define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
+ tty->name, (info->flags), serial_driver.refcount,info->count,tty->count,s)
+#else
+#define DBG_CNT(s)
+#endif
+
+static struct esp_struct *ports;
+
+static void change_speed(struct esp_struct *info);
+static void rs_wait_until_sent(struct tty_struct *, int);
+
+/*
+ * The ESP card has a clock rate of 14.7456 MHz (that is, 2**ESPC_SCALE
+ * times the normal 1.8432 Mhz clock of most serial boards).
+ */
+#define BASE_BAUD ((1843200 / 16) * (1 << ESPC_SCALE))
+
+/* Standard COM flags (except for COM4, because of the 8514 problem) */
+#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
+
+/*
+ * tmp_buf is used as a temporary buffer by serial_write. We need to
+ * lock it in case the memcpy_fromfs blocks while swapping in a page,
+ * and some other program tries to do a serial write at the same time.
+ * Since the lock will only come under contention when the system is
+ * swapping and available memory is low, it makes sense to share one
+ * buffer across all the serial ports, since it significantly saves
+ * memory if large numbers of serial ports are open.
+ */
+static unsigned char *tmp_buf;
+static DECLARE_MUTEX(tmp_buf_sem);
+
+static inline int serial_paranoia_check(struct esp_struct *info,
+ char *name, const char *routine)
+{
+#ifdef SERIAL_PARANOIA_CHECK
+ static const char badmagic[] = KERN_WARNING
+ "Warning: bad magic number for serial struct (%s) in %s\n";
+ static const char badinfo[] = KERN_WARNING
+ "Warning: null esp_struct for (%s) in %s\n";
+
+ if (!info) {
+ printk(badinfo, name, routine);
+ return 1;
+ }
+ if (info->magic != ESP_MAGIC) {
+ printk(badmagic, name, routine);
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+static inline unsigned int serial_in(struct esp_struct *info, int offset)
+{
+ return inb(info->port + offset);
+}
+
+static inline void serial_out(struct esp_struct *info, int offset,
+ unsigned char value)
+{
+ outb(value, info->port+offset);
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_stop() and rs_start()
+ *
+ * This routines are called before setting or resetting tty->stopped.
+ * They enable or disable transmitter interrupts, as necessary.
+ * ------------------------------------------------------------
+ */
+static void rs_stop(struct tty_struct *tty)
+{
+ struct esp_struct *info = (struct esp_struct *)tty->driver_data;
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->name, "rs_stop"))
+ return;
+
+ spin_lock_irqsave(&info->lock, flags);
+ if (info->IER & UART_IER_THRI) {
+ info->IER &= ~UART_IER_THRI;
+ serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, info->IER);
+ }
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+static void rs_start(struct tty_struct *tty)
+{
+ struct esp_struct *info = (struct esp_struct *)tty->driver_data;
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->name, "rs_start"))
+ return;
+
+ spin_lock_irqsave(&info->lock, flags);
+ if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
+ info->IER |= UART_IER_THRI;
+ serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, info->IER);
+ }
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+/*
+ * ----------------------------------------------------------------------
+ *
+ * Here starts the interrupt handling routines. All of the following
+ * subroutines are declared as inline and are folded into
+ * rs_interrupt(). They were separated out for readability's sake.
+ *
+ * Note: rs_interrupt() is a "fast" interrupt, which means that it
+ * runs with interrupts turned off. People who may want to modify
+ * rs_interrupt() should try to keep the interrupt handler as fast as
+ * possible. After you are done making modifications, it is not a bad
+ * idea to do:
+ *
+ * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
+ *
+ * and look at the resulting assemble code in serial.s.
+ *
+ * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
+ * -----------------------------------------------------------------------
+ */
+
+/*
+ * This routine is used by the interrupt handler to schedule
+ * processing in the software interrupt portion of the driver.
+ */
+static inline void rs_sched_event(struct esp_struct *info,
+ int event)
+{
+ info->event |= 1 << event;
+ schedule_work(&info->tqueue);
+}
+
+static DEFINE_SPINLOCK(pio_lock);
+
+static inline struct esp_pio_buffer *get_pio_buffer(void)
+{
+ struct esp_pio_buffer *buf;
+ unsigned long flags;
+
+ spin_lock_irqsave(&pio_lock, flags);
+ if (free_pio_buf) {
+ buf = free_pio_buf;
+ free_pio_buf = buf->next;
+ } else {
+ buf = kmalloc(sizeof(struct esp_pio_buffer), GFP_ATOMIC);
+ }
+ spin_unlock_irqrestore(&pio_lock, flags);
+ return buf;
+}
+
+static inline void release_pio_buffer(struct esp_pio_buffer *buf)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&pio_lock, flags);
+ buf->next = free_pio_buf;
+ free_pio_buf = buf;
+ spin_unlock_irqrestore(&pio_lock, flags);
+}
+
+static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
+{
+ struct tty_struct *tty = info->tty;
+ int i;
+ struct esp_pio_buffer *pio_buf;
+ struct esp_pio_buffer *err_buf;
+ unsigned char status_mask;
+
+ pio_buf = get_pio_buffer();
+
+ if (!pio_buf)
+ return;
+
+ err_buf = get_pio_buffer();
+
+ if (!err_buf) {
+ release_pio_buffer(pio_buf);
+ return;
+ }
+
+ status_mask = (info->read_status_mask >> 2) & 0x07;
+
+ for (i = 0; i < num_bytes - 1; i += 2) {
+ *((unsigned short *)(pio_buf->data + i)) =
+ inw(info->port + UART_ESI_RX);
+ err_buf->data[i] = serial_in(info, UART_ESI_RWS);
+ err_buf->data[i + 1] = (err_buf->data[i] >> 3) & status_mask;
+ err_buf->data[i] &= status_mask;
+ }
+
+ if (num_bytes & 0x0001) {
+ pio_buf->data[num_bytes - 1] = serial_in(info, UART_ESI_RX);
+ err_buf->data[num_bytes - 1] =
+ (serial_in(info, UART_ESI_RWS) >> 3) & status_mask;
+ }
+
+ /* make sure everything is still ok since interrupts were enabled */
+ tty = info->tty;
+
+ if (!tty) {
+ release_pio_buffer(pio_buf);
+ release_pio_buffer(err_buf);
+ info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
+ return;
+ }
+
+ status_mask = (info->ignore_status_mask >> 2) & 0x07;
+
+ for (i = 0; i < num_bytes; i++) {
+ if (!(err_buf->data[i] & status_mask)) {
+ *(tty->flip.char_buf_ptr++) = pio_buf->data[i];
+
+ if (err_buf->data[i] & 0x04) {
+ *(tty->flip.flag_buf_ptr++) = TTY_BREAK;
+
+ if (info->flags & ASYNC_SAK)
+ do_SAK(tty);
+ }
+ else if (err_buf->data[i] & 0x02)
+ *(tty->flip.flag_buf_ptr++) = TTY_FRAME;
+ else if (err_buf->data[i] & 0x01)
+ *(tty->flip.flag_buf_ptr++) = TTY_PARITY;
+ else
+ *(tty->flip.flag_buf_ptr++) = 0;
+
+ tty->flip.count++;
+ }
+ }
+
+ schedule_delayed_work(&tty->flip.work, 1);
+
+ info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
+ release_pio_buffer(pio_buf);
+ release_pio_buffer(err_buf);
+}
+
+static inline void receive_chars_dma(struct esp_struct *info, int num_bytes)
+{
+ unsigned long flags;
+ info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
+ dma_bytes = num_bytes;
+ info->stat_flags |= ESP_STAT_DMA_RX;
+
+ flags=claim_dma_lock();
+ disable_dma(dma);
+ clear_dma_ff(dma);
+ set_dma_mode(dma, DMA_MODE_READ);
+ set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
+ set_dma_count(dma, dma_bytes);
+ enable_dma(dma);
+ release_dma_lock(flags);
+
+ serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX);
+}
+
+static inline void receive_chars_dma_done(struct esp_struct *info,
+ int status)
+{
+ struct tty_struct *tty = info->tty;
+ int num_bytes;
+ unsigned long flags;
+
+
+ flags=claim_dma_lock();
+ disable_dma(dma);
+ clear_dma_ff(dma);
+
+ info->stat_flags &= ~ESP_STAT_DMA_RX;
+ num_bytes = dma_bytes - get_dma_residue(dma);
+ release_dma_lock(flags);
+
+ info->icount.rx += num_bytes;
+
+ memcpy(tty->flip.char_buf_ptr, dma_buffer, num_bytes);
+ tty->flip.char_buf_ptr += num_bytes;
+ tty->flip.count += num_bytes;
+ memset(tty->flip.flag_buf_ptr, 0, num_bytes);
+ tty->flip.flag_buf_ptr += num_bytes;
+
+ if (num_bytes > 0) {
+ tty->flip.flag_buf_ptr--;
+
+ status &= (0x1c & info->read_status_mask);
+
+ if (status & info->ignore_status_mask) {
+ tty->flip.count--;
+ tty->flip.char_buf_ptr--;
+ tty->flip.flag_buf_ptr--;
+ } else if (status & 0x10) {
+ *tty->flip.flag_buf_ptr = TTY_BREAK;
+ (info->icount.brk)++;
+ if (info->flags & ASYNC_SAK)
+ do_SAK(tty);
+ } else if (status & 0x08) {
+ *tty->flip.flag_buf_ptr = TTY_FRAME;
+ (info->icount.frame)++;
+ }
+ else if (status & 0x04) {
+ *tty->flip.flag_buf_ptr = TTY_PARITY;
+ (info->icount.parity)++;
+ }
+
+ tty->flip.flag_buf_ptr++;
+
+ schedule_delayed_work(&tty->flip.work, 1);
+ }
+
+ if (dma_bytes != num_bytes) {
+ num_bytes = dma_bytes - num_bytes;
+ dma_bytes = 0;
+ receive_chars_dma(info, num_bytes);
+ } else
+ dma_bytes = 0;
+}
+
+/* Caller must hold info->lock */
+
+static inline void transmit_chars_pio(struct esp_struct *info,
+ int space_avail)
+{
+ int i;
+ struct esp_pio_buffer *pio_buf;
+
+ pio_buf = get_pio_buffer();
+
+ if (!pio_buf)
+ return;
+
+ while (space_avail && info->xmit_cnt) {
+ if (info->xmit_tail + space_avail <= ESP_XMIT_SIZE) {
+ memcpy(pio_buf->data,
+ &(info->xmit_buf[info->xmit_tail]),
+ space_avail);
+ } else {
+ i = ESP_XMIT_SIZE - info->xmit_tail;
+ memcpy(pio_buf->data,
+ &(info->xmit_buf[info->xmit_tail]), i);
+ memcpy(&(pio_buf->data[i]), info->xmit_buf,
+ space_avail - i);
+ }
+
+ info->xmit_cnt -= space_avail;
+ info->xmit_tail = (info->xmit_tail + space_avail) &
+ (ESP_XMIT_SIZE - 1);
+
+ for (i = 0; i < space_avail - 1; i += 2) {
+ outw(*((unsigned short *)(pio_buf->data + i)),
+ info->port + UART_ESI_TX);
+ }
+
+ if (space_avail & 0x0001)
+ serial_out(info, UART_ESI_TX,
+ pio_buf->data[space_avail - 1]);
+
+ if (info->xmit_cnt) {
+ serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
+ serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
+ space_avail = serial_in(info, UART_ESI_STAT1) << 8;
+ space_avail |= serial_in(info, UART_ESI_STAT2);
+
+ if (space_avail > info->xmit_cnt)
+ space_avail = info->xmit_cnt;
+ }
+ }
+
+ if (info->xmit_cnt < WAKEUP_CHARS) {
+ rs_sched_event(info, ESP_EVENT_WRITE_WAKEUP);
+
+#ifdef SERIAL_DEBUG_INTR
+ printk("THRE...");
+#endif
+
+ if (info->xmit_cnt <= 0) {
+ info->IER &= ~UART_IER_THRI;
+ serial_out(info, UART_ESI_CMD1,
+ ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, info->IER);
+ }
+ }
+
+ release_pio_buffer(pio_buf);
+}
+
+/* Caller must hold info->lock */
+static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes)
+{
+ unsigned long flags;
+
+ dma_bytes = num_bytes;
+
+ if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) {
+ memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]),
+ dma_bytes);
+ } else {
+ int i = ESP_XMIT_SIZE - info->xmit_tail;
+ memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]),
+ i);
+ memcpy(&(dma_buffer[i]), info->xmit_buf, dma_bytes - i);
+ }
+
+ info->xmit_cnt -= dma_bytes;
+ info->xmit_tail = (info->xmit_tail + dma_bytes) & (ESP_XMIT_SIZE - 1);
+
+ if (info->xmit_cnt < WAKEUP_CHARS) {
+ rs_sched_event(info, ESP_EVENT_WRITE_WAKEUP);
+
+#ifdef SERIAL_DEBUG_INTR
+ printk("THRE...");
+#endif
+
+ if (info->xmit_cnt <= 0) {
+ info->IER &= ~UART_IER_THRI;
+ serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, info->IER);
+ }
+ }
+
+ info->stat_flags |= ESP_STAT_DMA_TX;
+
+ flags=claim_dma_lock();
+ disable_dma(dma);
+ clear_dma_ff(dma);
+ set_dma_mode(dma, DMA_MODE_WRITE);
+ set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
+ set_dma_count(dma, dma_bytes);
+ enable_dma(dma);
+ release_dma_lock(flags);
+
+ serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
+}
+
+static inline void transmit_chars_dma_done(struct esp_struct *info)
+{
+ int num_bytes;
+ unsigned long flags;
+
+
+ flags=claim_dma_lock();
+ disable_dma(dma);
+ clear_dma_ff(dma);
+
+ num_bytes = dma_bytes - get_dma_residue(dma);
+ info->icount.tx += dma_bytes;
+ release_dma_lock(flags);
+
+ if (dma_bytes != num_bytes) {
+ dma_bytes -= num_bytes;
+ memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes);
+
+ flags=claim_dma_lock();
+ disable_dma(dma);
+ clear_dma_ff(dma);
+ set_dma_mode(dma, DMA_MODE_WRITE);
+ set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
+ set_dma_count(dma, dma_bytes);
+ enable_dma(dma);
+ release_dma_lock(flags);
+
+ serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
+ } else {
+ dma_bytes = 0;
+ info->stat_flags &= ~ESP_STAT_DMA_TX;
+ }
+}
+
+static inline void check_modem_status(struct esp_struct *info)
+{
+ int status;
+
+ serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
+ status = serial_in(info, UART_ESI_STAT2);
+
+ if (status & UART_MSR_ANY_DELTA) {
+ /* update input line counters */
+ if (status & UART_MSR_TERI)
+ info->icount.rng++;
+ if (status & UART_MSR_DDSR)
+ info->icount.dsr++;
+ if (status & UART_MSR_DDCD)
+ info->icount.dcd++;
+ if (status & UART_MSR_DCTS)
+ info->icount.cts++;
+ wake_up_interruptible(&info->delta_msr_wait);
+ }
+
+ if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
+#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
+ printk("ttys%d CD now %s...", info->line,
+ (status & UART_MSR_DCD) ? "on" : "off");
+#endif
+ if (status & UART_MSR_DCD)
+ wake_up_interruptible(&info->open_wait);
+ else {
+#ifdef SERIAL_DEBUG_OPEN
+ printk("scheduling hangup...");
+#endif
+ schedule_work(&info->tqueue_hangup);
+ }
+ }
+}
+
+/*
+ * This is the serial driver's interrupt routine
+ */
+static irqreturn_t rs_interrupt_single(int irq, void *dev_id,
+ struct pt_regs *regs)
+{
+ struct esp_struct * info;
+ unsigned err_status;
+ unsigned int scratch;
+
+#ifdef SERIAL_DEBUG_INTR
+ printk("rs_interrupt_single(%d)...", irq);
+#endif
+ info = (struct esp_struct *)dev_id;
+ err_status = 0;
+ scratch = serial_in(info, UART_ESI_SID);
+
+ spin_lock(&info->lock);
+
+ if (!info->tty) {
+ spin_unlock(&info->lock);
+ return IRQ_NONE;
+ }
+
+ if (scratch & 0x04) { /* error */
+ serial_out(info, UART_ESI_CMD1, ESI_GET_ERR_STAT);
+ err_status = serial_in(info, UART_ESI_STAT1);
+ serial_in(info, UART_ESI_STAT2);
+
+ if (err_status & 0x01)
+ info->stat_flags |= ESP_STAT_RX_TIMEOUT;
+
+ if (err_status & 0x20) /* UART status */
+ check_modem_status(info);
+
+ if (err_status & 0x80) /* Start break */
+ wake_up_interruptible(&info->break_wait);
+ }
+
+ if ((scratch & 0x88) || /* DMA completed or timed out */
+ (err_status & 0x1c) /* receive error */) {
+ if (info->stat_flags & ESP_STAT_DMA_RX)
+ receive_chars_dma_done(info, err_status);
+ else if (info->stat_flags & ESP_STAT_DMA_TX)
+ transmit_chars_dma_done(info);
+ }
+
+ if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) &&
+ ((scratch & 0x01) || (info->stat_flags & ESP_STAT_RX_TIMEOUT)) &&
+ (info->IER & UART_IER_RDI)) {
+ int num_bytes;
+
+ serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
+ serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL);
+ num_bytes = serial_in(info, UART_ESI_STAT1) << 8;
+ num_bytes |= serial_in(info, UART_ESI_STAT2);
+
+ if (num_bytes > (TTY_FLIPBUF_SIZE - info->tty->flip.count))
+ num_bytes = TTY_FLIPBUF_SIZE - info->tty->flip.count;
+
+ if (num_bytes) {
+ if (dma_bytes ||
+ (info->stat_flags & ESP_STAT_USE_PIO) ||
+ (num_bytes <= info->config.pio_threshold))
+ receive_chars_pio(info, num_bytes);
+ else
+ receive_chars_dma(info, num_bytes);
+ }
+ }
+
+ if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) &&
+ (scratch & 0x02) && (info->IER & UART_IER_THRI)) {
+ if ((info->xmit_cnt <= 0) || info->tty->stopped) {
+ info->IER &= ~UART_IER_THRI;
+ serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, info->IER);
+ } else {
+ int num_bytes;
+
+ serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
+ serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
+ num_bytes = serial_in(info, UART_ESI_STAT1) << 8;
+ num_bytes |= serial_in(info, UART_ESI_STAT2);
+
+ if (num_bytes > info->xmit_cnt)
+ num_bytes = info->xmit_cnt;
+
+ if (num_bytes) {
+ if (dma_bytes ||
+ (info->stat_flags & ESP_STAT_USE_PIO) ||
+ (num_bytes <= info->config.pio_threshold))
+ transmit_chars_pio(info, num_bytes);
+ else
+ transmit_chars_dma(info, num_bytes);
+ }
+ }
+ }
+
+ info->last_active = jiffies;
+
+#ifdef SERIAL_DEBUG_INTR
+ printk("end.\n");
+#endif
+ spin_unlock(&info->lock);
+ return IRQ_HANDLED;
+}
+
+/*
+ * -------------------------------------------------------------------
+ * Here ends the serial interrupt routines.
+ * -------------------------------------------------------------------
+ */
+
+static void do_softint(void *private_)
+{
+ struct esp_struct *info = (struct esp_struct *) private_;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (!tty)
+ return;
+
+ if (test_and_clear_bit(ESP_EVENT_WRITE_WAKEUP, &info->event)) {
+ tty_wakeup(tty);
+ }
+}
+
+/*
+ * This routine is called from the scheduler tqueue when the interrupt
+ * routine has signalled that a hangup has occurred. The path of
+ * hangup processing is:
+ *
+ * serial interrupt routine -> (scheduler tqueue) ->
+ * do_serial_hangup() -> tty->hangup() -> esp_hangup()
+ *
+ */
+static void do_serial_hangup(void *private_)
+{
+ struct esp_struct *info = (struct esp_struct *) private_;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (tty)
+ tty_hangup(tty);
+}
+
+/*
+ * ---------------------------------------------------------------
+ * Low level utility subroutines for the serial driver: routines to
+ * figure out the appropriate timeout for an interrupt chain, routines
+ * to initialize and startup a serial port, and routines to shutdown a
+ * serial port. Useful stuff like that.
+ *
+ * Caller should hold lock
+ * ---------------------------------------------------------------
+ */
+
+static inline void esp_basic_init(struct esp_struct * info)
+{
+ /* put ESPC in enhanced mode */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_MODE);
+
+ if (info->stat_flags & ESP_STAT_NEVER_DMA)
+ serial_out(info, UART_ESI_CMD2, 0x01);
+ else
+ serial_out(info, UART_ESI_CMD2, 0x31);
+
+ /* disable interrupts for now */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, 0x00);
+
+ /* set interrupt and DMA channel */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_IRQ);
+
+ if (info->stat_flags & ESP_STAT_NEVER_DMA)
+ serial_out(info, UART_ESI_CMD2, 0x01);
+ else
+ serial_out(info, UART_ESI_CMD2, (dma << 4) | 0x01);
+
+ serial_out(info, UART_ESI_CMD1, ESI_SET_ENH_IRQ);
+
+ if (info->line % 8) /* secondary port */
+ serial_out(info, UART_ESI_CMD2, 0x0d); /* shared */
+ else if (info->irq == 9)
+ serial_out(info, UART_ESI_CMD2, 0x02);
+ else
+ serial_out(info, UART_ESI_CMD2, info->irq);
+
+ /* set error status mask (check this) */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_ERR_MASK);
+
+ if (info->stat_flags & ESP_STAT_NEVER_DMA)
+ serial_out(info, UART_ESI_CMD2, 0xa1);
+ else
+ serial_out(info, UART_ESI_CMD2, 0xbd);
+
+ serial_out(info, UART_ESI_CMD2, 0x00);
+
+ /* set DMA timeout */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_DMA_TMOUT);
+ serial_out(info, UART_ESI_CMD2, 0xff);
+
+ /* set FIFO trigger levels */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_TRIGGER);
+ serial_out(info, UART_ESI_CMD2, info->config.rx_trigger >> 8);
+ serial_out(info, UART_ESI_CMD2, info->config.rx_trigger);
+ serial_out(info, UART_ESI_CMD2, info->config.tx_trigger >> 8);
+ serial_out(info, UART_ESI_CMD2, info->config.tx_trigger);
+
+ /* Set clock scaling and wait states */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_PRESCALAR);
+ serial_out(info, UART_ESI_CMD2, 0x04 | ESPC_SCALE);
+
+ /* set reinterrupt pacing */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_REINTR);
+ serial_out(info, UART_ESI_CMD2, 0xff);
+}
+
+static int startup(struct esp_struct * info)
+{
+ unsigned long flags;
+ int retval=0;
+ unsigned int num_chars;
+
+ spin_lock_irqsave(&info->lock, flags);
+
+ if (info->flags & ASYNC_INITIALIZED)
+ goto out;
+
+ if (!info->xmit_buf) {
+ info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_ATOMIC);
+ retval = -ENOMEM;
+ if (!info->xmit_buf)
+ goto out;
+ }
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("starting up ttys%d (irq %d)...", info->line, info->irq);
+#endif
+
+ /* Flush the RX buffer. Using the ESI flush command may cause */
+ /* wild interrupts, so read all the data instead. */
+
+ serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
+ serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL);
+ num_chars = serial_in(info, UART_ESI_STAT1) << 8;
+ num_chars |= serial_in(info, UART_ESI_STAT2);
+
+ while (num_chars > 1) {
+ inw(info->port + UART_ESI_RX);
+ num_chars -= 2;
+ }
+
+ if (num_chars)
+ serial_in(info, UART_ESI_RX);
+
+ /* set receive character timeout */
+ serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
+ serial_out(info, UART_ESI_CMD2, info->config.rx_timeout);
+
+ /* clear all flags except the "never DMA" flag */
+ info->stat_flags &= ESP_STAT_NEVER_DMA;
+
+ if (info->stat_flags & ESP_STAT_NEVER_DMA)
+ info->stat_flags |= ESP_STAT_USE_PIO;
+
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ /*
+ * Allocate the IRQ
+ */
+
+ retval = request_irq(info->irq, rs_interrupt_single, SA_SHIRQ,
+ "esp serial", info);
+
+ if (retval) {
+ if (capable(CAP_SYS_ADMIN)) {
+ if (info->tty)
+ set_bit(TTY_IO_ERROR,
+ &info->tty->flags);
+ retval = 0;
+ }
+ goto out_unlocked;
+ }
+
+ if (!(info->stat_flags & ESP_STAT_USE_PIO) && !dma_buffer) {
+ dma_buffer = (char *)__get_dma_pages(
+ GFP_KERNEL, get_order(DMA_BUFFER_SZ));
+
+ /* use PIO mode if DMA buf/chan cannot be allocated */
+ if (!dma_buffer)
+ info->stat_flags |= ESP_STAT_USE_PIO;
+ else if (request_dma(dma, "esp serial")) {
+ free_pages((unsigned long)dma_buffer,
+ get_order(DMA_BUFFER_SZ));
+ dma_buffer = NULL;
+ info->stat_flags |= ESP_STAT_USE_PIO;
+ }
+
+ }
+
+ info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
+
+ spin_lock_irqsave(&info->lock, flags);
+ serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
+ serial_out(info, UART_ESI_CMD2, UART_MCR);
+ serial_out(info, UART_ESI_CMD2, info->MCR);
+
+ /*
+ * Finally, enable interrupts
+ */
+ /* info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI; */
+ info->IER = UART_IER_RLSI | UART_IER_RDI | UART_IER_DMA_TMOUT |
+ UART_IER_DMA_TC;
+ serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, info->IER);
+
+ if (info->tty)
+ clear_bit(TTY_IO_ERROR, &info->tty->flags);
+ info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ /*
+ * Set up the tty->alt_speed kludge
+ */
+ if (info->tty) {
+ if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
+ info->tty->alt_speed = 57600;
+ if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
+ info->tty->alt_speed = 115200;
+ if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
+ info->tty->alt_speed = 230400;
+ if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
+ info->tty->alt_speed = 460800;
+ }
+
+ /*
+ * set the speed of the serial port
+ */
+ change_speed(info);
+ info->flags |= ASYNC_INITIALIZED;
+ return 0;
+
+out:
+ spin_unlock_irqrestore(&info->lock, flags);
+out_unlocked:
+ return retval;
+}
+
+/*
+ * This routine will shutdown a serial port; interrupts are disabled, and
+ * DTR is dropped if the hangup on close termio flag is on.
+ */
+static void shutdown(struct esp_struct * info)
+{
+ unsigned long flags, f;
+
+ if (!(info->flags & ASYNC_INITIALIZED))
+ return;
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("Shutting down serial port %d (irq %d)....", info->line,
+ info->irq);
+#endif
+
+ spin_lock_irqsave(&info->lock, flags);
+ /*
+ * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
+ * here so the queue might never be waken up
+ */
+ wake_up_interruptible(&info->delta_msr_wait);
+ wake_up_interruptible(&info->break_wait);
+
+ /* stop a DMA transfer on the port being closed */
+ /* DMA lock is higher priority always */
+ if (info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) {
+ f=claim_dma_lock();
+ disable_dma(dma);
+ clear_dma_ff(dma);
+ release_dma_lock(f);
+
+ dma_bytes = 0;
+ }
+
+ /*
+ * Free the IRQ
+ */
+ free_irq(info->irq, info);
+
+ if (dma_buffer) {
+ struct esp_struct *current_port = ports;
+
+ while (current_port) {
+ if ((current_port != info) &&
+ (current_port->flags & ASYNC_INITIALIZED))
+ break;
+
+ current_port = current_port->next_port;
+ }
+
+ if (!current_port) {
+ free_dma(dma);
+ free_pages((unsigned long)dma_buffer,
+ get_order(DMA_BUFFER_SZ));
+ dma_buffer = NULL;
+ }
+ }
+
+ if (info->xmit_buf) {
+ free_page((unsigned long) info->xmit_buf);
+ info->xmit_buf = NULL;
+ }
+
+ info->IER = 0;
+ serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
+ serial_out(info, UART_ESI_CMD2, 0x00);
+
+ if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
+ info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
+
+ info->MCR &= ~UART_MCR_OUT2;
+ serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
+ serial_out(info, UART_ESI_CMD2, UART_MCR);
+ serial_out(info, UART_ESI_CMD2, info->MCR);
+
+ if (info->tty)
+ set_bit(TTY_IO_ERROR, &info->tty->flags);
+
+ info->flags &= ~ASYNC_INITIALIZED;
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+/*
+ * This routine is called to set the UART divisor registers to match
+ * the specified baud rate for a serial port.
+ */
+static void change_speed(struct esp_struct *info)
+{
+ unsigned short port;
+ int quot = 0;
+ unsigned cflag,cval;
+ int baud, bits;
+ unsigned char flow1 = 0, flow2 = 0;
+ unsigned long flags;
+
+ if (!info->tty || !info->tty->termios)
+ return;
+ cflag = info->tty->termios->c_cflag;
+ port = info->port;
+
+ /* byte size and parity */
+ switch (cflag & CSIZE) {
+ case CS5: cval = 0x00; bits = 7; break;
+ case CS6: cval = 0x01; bits = 8; break;
+ case CS7: cval = 0x02; bits = 9; break;
+ case CS8: cval = 0x03; bits = 10; break;
+ default: cval = 0x00; bits = 7; break;
+ }
+ if (cflag & CSTOPB) {
+ cval |= 0x04;
+ bits++;
+ }
+ if (cflag & PARENB) {
+ cval |= UART_LCR_PARITY;
+ bits++;
+ }
+ if (!(cflag & PARODD))
+ cval |= UART_LCR_EPAR;
+#ifdef CMSPAR
+ if (cflag & CMSPAR)
+ cval |= UART_LCR_SPAR;
+#endif
+
+ baud = tty_get_baud_rate(info->tty);
+ if (baud == 38400 &&
+ ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
+ quot = info->custom_divisor;
+ else {
+ if (baud == 134)
+ /* Special case since 134 is really 134.5 */
+ quot = (2*BASE_BAUD / 269);
+ else if (baud)
+ quot = BASE_BAUD / baud;
+ }
+ /* If the quotient is ever zero, default to 9600 bps */
+ if (!quot)
+ quot = BASE_BAUD / 9600;
+
+ info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50);
+
+ /* CTS flow control flag and modem status interrupts */
+ /* info->IER &= ~UART_IER_MSI; */
+ if (cflag & CRTSCTS) {
+ info->flags |= ASYNC_CTS_FLOW;
+ /* info->IER |= UART_IER_MSI; */
+ flow1 = 0x04;
+ flow2 = 0x10;
+ } else
+ info->flags &= ~ASYNC_CTS_FLOW;
+ if (cflag & CLOCAL)
+ info->flags &= ~ASYNC_CHECK_CD;
+ else {
+ info->flags |= ASYNC_CHECK_CD;
+ /* info->IER |= UART_IER_MSI; */
+ }
+
+ /*
+ * Set up parity check flag
+ */
+#d