/*
 * linux/drivers/char/serial167.c
 *
 * Driver for MVME166/7 board serial ports, which are via a CD2401.
 * Based very much on cyclades.c.
 *
 * MVME166/7 work by Richard Hirst [richard@sleepie.demon.co.uk]
 *
 * ==============================================================
 *
 * static char rcsid[] =
 * "$Revision: 1.36.1.4 $$Date: 1995/03/29 06:14:14 $";
 *
 *  linux/kernel/cyclades.c
 *
 * Maintained by Marcio Saito (cyclades@netcom.com) and
 * Randolph Bentson (bentson@grieg.seaslug.org)
 *
 * Much of the design and some of the code came from serial.c
 * which was copyright (C) 1991, 1992  Linus Torvalds.  It was
 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
 * and then fixed as suggested by Michael K. Johnson 12/12/92.
 *
 * This version does not support shared irq's.
 *
 * $Log: cyclades.c,v $
 * Revision 1.36.1.4  1995/03/29  06:14:14  bentson
 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
 *
 * Changes:
 *
 * 200 lines of changes record removed - RGH 11-10-95, starting work on
 * converting this to drive serial ports on mvme166 (cd2401).
 *
 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/25
 * - get rid of verify_area
 * - use get_user to access memory from userspace in set_threshold,
 *   set_default_threshold and set_timeout
 * - don't use the panic function in serial167_init
 * - do resource release on failure on serial167_init
 * - include missing restore_flags in mvme167_serial_console_setup
 *
 * Kars de Jong <jongk@linux-m68k.org> - 2004/09/06
 * - replace bottom half handler with task queue handler
 */

#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/tty.h>
#include <linux/interrupt.h>
#include <linux/serial.h>
#include <linux/serialP.h>
#include <linux/string.h>
#include <linux/fcntl.h>
#include <linux/ptrace.h>
#include <linux/serial167.h>
#include <linux/delay.h>
#include <linux/major.h>
#include <linux/mm.h>
#include <linux/console.h>
#include <linux/module.h>
#include <linux/bitops.h>
#include <linux/tty_flip.h>

#include <asm/system.h>
#include <asm/io.h>
#include <asm/mvme16xhw.h>
#include <asm/bootinfo.h>
#include <asm/setup.h>

#include <linux/types.h>
#include <linux/kernel.h>

#include <asm/uaccess.h>
#include <linux/init.h>

#define SERIAL_PARANOIA_CHECK
#undef  SERIAL_DEBUG_OPEN
#undef  SERIAL_DEBUG_THROTTLE
#undef  SERIAL_DEBUG_OTHER
#undef  SERIAL_DEBUG_IO
#undef  SERIAL_DEBUG_COUNT
#undef  SERIAL_DEBUG_DTR
#undef  CYCLOM_16Y_HACK
#define  CYCLOM_ENABLE_MONITORING

#define WAKEUP_CHARS 256

#define STD_COM_FLAGS (0)

static struct tty_driver *cy_serial_driver;
extern int serial_console;
static struct cyclades_port *serial_console_info = NULL;
static unsigned int serial_console_cflag = 0;
u_char initial_console_speed;

/* Base address of cd2401 chip on mvme166/7 */

#define BASE_ADDR (0xfff45000)
#define pcc2chip	((volatile u_char *)0xfff42000)
#define PccSCCMICR	0x1d
#define PccSCCTICR	0x1e
#define PccSCCRICR	0x1f
#define PccTPIACKR	0x25
#define PccRPIACKR	0x27
#define PccIMLR		0x3f

/* This is the per-port data structure */
struct cyclades_port cy_port[] = {
	/* CARD#  */
	{-1},			/* ttyS0 */
	{-1},			/* ttyS1 */
	{-1},			/* ttyS2 */
	{-1},			/* ttyS3 */
};

#define NR_PORTS        ARRAY_SIZE(cy_port)

/*
 * This is used to look up the divisor speeds and the timeouts
 * We're normally limited to 15 distinct baud rates.  The extra
 * are accessed via settings in info->flags.
 *         0,     1,     2,     3,     4,     5,     6,     7,     8,     9,
 *        10,    11,    12,    13,    14,    15,    16,    17,    18,    19,
 *                                                  HI            VHI
 */
static int baud_table[] = {
	0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
	1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
	0
};

#if 0
static char baud_co[] = {	/* 25 MHz clock option table */
	/* value =>    00    01   02    03    04 */
	/* divide by    8    32   128   512  2048 */
	0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
	0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static char baud_bpr[] = {	/* 25 MHz baud rate period table */
	0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
	0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
};
#endif

/* I think 166 brd clocks 2401 at 20MHz.... */

/* These values are written directly to tcor, and >> 5 for writing to rcor */
static u_char baud_co[] = {	/* 20 MHz clock option table */
	0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
	0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

/* These values written directly to tbpr/rbpr */
static u_char baud_bpr[] = {	/* 20 MHz baud rate period table */
	0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
	0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10
};

static u_char baud_cor4[] = {	/* receive threshold */
	0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
	0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07
};

static void shutdown(struct cyclades_port *);
static int startup(struct cyclades_port *);
static void cy_throttle(struct tty_struct *);
static void cy_unthrottle(struct tty_struct *);
static void config_setup(struct cyclades_port *);
extern void console_print(const char *);
#ifdef CYCLOM_SHOW_STATUS
static void show_status(int);
#endif

#ifdef CONFIG_REMOTE_DEBUG
static void debug_setup(void);
void queueDebugChar(int c);
int getDebugChar(void);

#define DEBUG_PORT	1
#define DEBUG_LEN	256

typedef struct {
	int in;
	int out;
	unsigned char buf[DEBUG_LEN];
} debugq;

debugq debugiq;
#endif

/*
 * I have my own version of udelay(), as it is needed when initialising
 * the chip, before the delay loop has been calibrated.  Should probably
 * reference one of the vmechip2 or pccchip2 counter for an accurate
 * delay, but this wild guess will do for now.
 */

void my_udelay(long us)
{
	u_char x;
	volatile u_char *p = &x;
	int i;

	while (us--)
		for (i = 100; i; i--)
			x |= *p;
}

static inline int serial_paranoia_check(struct cyclades_port *info, char *name,
		const char *routine)
{
#ifdef SERIAL_PARANOIA_CHECK
	if (!info) {
		printk("Warning: null cyclades_port for (%s) in %s\n", name,
				routine);
		return 1;
	}

	if ((long)info < (long)(&cy_port[0])
	    || (long)(&cy_port[NR_PORTS]) < (long)info) {
		printk("Warning: cyclades_port out of range for (%s) in %s\n",
				name, routine);
		return 1;
	}

	if (info->magic != CYCLADES_MAGIC) {
		printk("Warning: bad magic number for serial struct (%s) in "
				"%s\n", name, routine);
		return 1;
	}
#endif
	return 0;
}				/* serial_paranoia_check */

#if 0
/* The following diagnostic routines allow the driver to spew
   information on the screen, even (especially!) during interrupts.
 */
void SP(char *data)
{
	unsigned long flags;
	local_irq_save(flags);
	console_print(data);
	local_irq_restore(flags);
}

char scrn[2];
void CP(char data)
{
	unsigned long flags;
	local_irq_save(flags);
	scrn[0] = data;
	console_print(scrn);
	local_irq_restore(flags);
}				/* CP */

void CP1(int data)
{
	(data < 10) ? CP(data + '0') : CP(data + 'A' - 10);
}				/* CP1 */
void CP2(int data)
{
	CP1((data >> 4) & 0x0f);
	CP1(data & 0x0f);
}				/* CP2 */
void CP4(int data)
{
	CP2((data >> 8) & 0xff);
	CP2(data & 0xff);
}				/* CP4 */
void CP8(long data)
{
	CP4((data >> 16) & 0xffff);
	CP4(data & 0xffff);
}				/* CP8 */
#endif

/* This routine waits up to 1000 micro-seconds for the previous
   command to the Cirrus chip to complete and then issues the
   new command.  An error is returned if the previous command
   didn't finish within the time limit.
 */
u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd)
{
	unsigned long flags;
	volatile int i;

	local_irq_save(flags);
	/* Check to see that the previous command has completed */
	for (i = 0; i < 100; i++) {
		if (base_addr[CyCCR] == 0) {
			break;
		}
		my_udelay(10L);
	}
	/* if the CCR never cleared, the previous command
	   didn't finish within the "reasonable time" */
	if (i == 10) {
		local_irq_restore(flags);
		return (-1);
	}

	/* Issue the new command */
	base_addr[CyCCR] = cmd;
	local_irq_restore(flags);
	return (0);
}				/* write_cy_cmd */

/* cy_start and cy_stop provide software output flow control as a
   function of XON/XOFF, software CTS, and other such stuff. */

static void cy_stop(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
	int channel;
	unsigned long flags;

#ifdef SERIAL_DEBUG_OTHER
	printk("cy_stop %s\n", tty->name);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_stop"))
		return;

	channel = info->line;

	local_irq_save(flags);
	base_addr[CyCAR] = (u_char) (channel);	/* index channel */
	base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
	local_irq_restore(flags);
}				/* cy_stop */

static void cy_start(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
	int channel;
	unsigned long flags;

#ifdef SERIAL_DEBUG_OTHER
	printk("cy_start %s\n", tty->name);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_start"))
		return;

	channel = info->line;

	local_irq_save(flags);
	base_addr[CyCAR] = (u_char) (channel);
	base_addr[CyIER] |= CyTxMpty;
	local_irq_restore(flags);
}				/* cy_start */

/* The real interrupt service routines are called
   whenever the card wants its hand held--chars
   received, out buffer empty, modem change, etc.
 */
static irqreturn_t cd2401_rxerr_interrupt(int irq, void *dev_id)
{
	struct tty_struct *tty;
	struct cyclades_port *info;
	volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
	unsigned char err, rfoc;
	int channel;
	char data;

	/* determine the channel and change to that context */
	channel = (u_short) (base_addr[CyLICR] >> 2);
	info = &cy_port[channel];
	info->last_active = jiffies;

	if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
		/* This is a receive timeout interrupt, ignore it */
		base_addr[CyREOIR] = CyNOTRANS;
		return IRQ_HANDLED;
	}

	/* Read a byte of data if there is any - assume the error
	 * is associated with this character */

	if ((rfoc = base_addr[CyRFOC]) != 0)
		data = base_addr[CyRDR];
	else
		data = 0;

	/* if there is nowhere to put the data, discard it */
	if (info->tty == 0) {
		base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
		return IRQ_HANDLED;
	} else {		/* there is an open port for this data */
		tty = info->tty;
		if (err & info->ignore_status_mask) {
			base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
			return IRQ_HANDLED;
		}
		if (tty_buffer_request_room(tty, 1) != 0) {
			if (err & info->read_status_mask) {
				if (err & CyBREAK) {
					tty_insert_flip_char(tty, data,
							     TTY_BREAK);
					if (info->flags & ASYNC_SAK) {
						do_SAK(tty);
					}
				} else if (err & CyFRAME) {
					tty_insert_flip_char(tty, data,
							     TTY_FRAME);
				} else if (err & CyPARITY) {
					tty_insert_flip_char(tty, data,
							     TTY_PARITY);
				} else if (err & CyOVERRUN) {
					tty_insert_flip_char(tty, 0,
							     TTY_OVERRUN);
					/*
					   If the flip buffer itself is
					   overflowing, we still loose
					   the next incoming character.
					 */
					if (tty_buffer_request_room(tty, 1) !=
					    0) {
						tty_insert_flip_char(tty, data,
								     TTY_FRAME);
					}
					/* These two conditions may imply */
					/* a normal read should be done. */
					/* else if(data & CyTIMEOUT) */
					/* else if(data & CySPECHAR) */
				} else {
					tty_insert_flip_char(tty, 0,
							     TTY_NORMAL);
				}
			} else {
				tty_insert_flip_char(tty, data, TTY_NORMAL);
			}
		} else {
			/* there was a software buffer overrun
			   and nothing could be done about it!!! */
		}
	}
	tty_schedule_flip(tty);
	/* end of service */
	base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
	return IRQ_HANDLED;
}				/* cy_rxerr_interrupt */

static irqreturn_t cd2401_modem_interrupt(int irq, void *dev_id)
{
	struct cyclades_port *info;
	volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
	int channel;
	int mdm_change;
	int mdm_status;

	/* determine the channel and change to that context */
	channel = (u_short) (base_addr[CyLICR] >> 2);
	info = &cy_port[channel];
	info->last_active = jiffies;

	mdm_change = base_addr[CyMISR];
	mdm_status = base_addr[CyMSVR1];

	if (info->tty == 0) {	/* nowhere to put the data, ignore it */
		;
	} else {
		if ((mdm_change & CyDCD)
		    && (info->flags & ASYNC_CHECK_CD)) {
			if (mdm_status & CyDCD) {
/* CP('!'); */
				wake_up_interruptible(&info->open_wait);
			} else {
/* CP('@'); */
				tty_hangup(info->tty);
				wake_up_interruptible(&info->open_wait);
				info->flags &= ~ASYNC_NORMAL_ACTIVE;
			}
		}
		if ((mdm_change & CyCTS)
		    && (info->flags & ASYNC_CTS_FLOW)) {
			if (info->tty->stopped) {
				if (mdm_status & CyCTS) {
					/* !!! cy_start isn't used because... */
					info->tty->stopped = 0;
					base_addr[CyIER] |= CyTxMpty;
					tty_wakeup(info->tty);
				}
			} else {
				if (!(mdm_status & CyCTS)) {
					/* !!! cy_stop isn't used because... */
					info->tty->stopped = 1;
					base_addr[CyIER] &=
					    ~(CyTxMpty | CyTxRdy);
				}
			}
		}
		if (mdm_status & CyDSR) {
		}
	}
	base_addr[CyMEOIR] = 0;
	return IRQ_HANDLED;
}				/* cy_modem_interrupt */

static irqreturn_t cd2401_tx_interrupt(int irq, void *dev_id)
{
	struct cyclades_port *info;
	volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
	int channel;
	int char_count, saved_cnt;
	int outch;

	/* determine the channel and change to that context */
	channel = (u_short) (base_addr[CyLICR] >> 2);

#ifdef CONFIG_REMOTE_DEBUG
	if (channel == DEBUG_PORT) {
		panic("TxInt on debug port!!!");
	}
#endif

	info = &cy_port[channel];

	/* validate the port number (as configured and open) */
	if ((channel < 0) || (NR_PORTS <= channel)) {
		base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
		base_addr[CyTEOIR] = CyNOTRANS;
		return IRQ_HANDLED;
	}
	info->last_active = jiffies;
	if (info->tty == 0) {
		base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
		base_addr[CyTEOIR] = CyNOTRANS;
		return IRQ_HANDLED;
	}

	/* load the on-chip space available for outbound data */
	saved_cnt = char_count = base_addr[CyTFTC];

	if (info->x_char) {	/* send special char */
		outch = info->x_char;
		base_addr[CyTDR] = outch;
		char_count--;
		info->x_char = 0;
	}

	if (info->x_break) {
		/*  The Cirrus chip requires the "Embedded Transmit
		   Commands" of start break, delay, and end break
		   sequences to be sent.  The duration of the
		   break is given in TICs, which runs at HZ
		   (typically 100) and the PPR runs at 200 Hz,
		   so the delay is duration * 200/HZ, and thus a
		   break can run from 1/100 sec to about 5/4 sec.
		   Need to check these values - RGH 141095.
		 */
		base_addr[CyTDR] = 0;	/* start break */
		base_addr[CyTDR] = 0x81;
		base_addr[CyTDR] = 0;	/* delay a bit */
		base_addr[CyTDR] = 0x82;
		base_addr[CyTDR] = info->x_break * 200 / HZ;
		base_addr[CyTDR] = 0;	/* terminate break */
		base_addr[CyTDR] = 0x83;
		char_count -= 7;
		info->x_break = 0;
	}

	while (char_count > 0) {
		if (!info->xmit_cnt) {
			base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
			break;
		}
		if (info->xmit_buf == 0) {
			base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
			break;
		}
		if (info->tty->stopped || info->tty->hw_stopped) {
			base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
			break;
		}
		/* Because the Embedded Transmit Commands have been
		   enabled, we must check to see if the escape
		   character, NULL, is being sent.  If it is, we
		   must ensure that there is room for it to be
		   doubled in the output stream.  Therefore we
		   no longer advance the pointer when the character
		   is fetched, but rather wait until after the check
		   for a NULL output character. (This is necessary
		   because there may not be room for the two chars
		   needed to send a NULL.
		 */
		outch = info->xmit_buf[info->xmit_tail];
		if (outch) {
			info->xmit_cnt--;
			info->xmit_tail = (info->xmit_tail + 1)
			    & (PAGE_SIZE - 1);
			base_addr[CyTDR] = outch;
			char_count--;
		} else {
			if (char_count > 1) {
				info->xmit_cnt--;
				info->xmit_tail = (info->xmit_tail + 1)
				    & (PAGE_SIZE - 1);
				base_addr[CyTDR] = outch;
				base_addr[CyTDR] = 0;
				char_count--;
				char_count--;
			} else {
				break;
			}
		}
	}

	if (info->xmit_cnt < WAKEUP_CHARS)
		tty_wakeup(info->tty);

	base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
	return IRQ_HANDLED;
}				/* cy_tx_interrupt */

static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
{
	struct tty_struct *tty;
	struct cyclades_port *info;
	volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
	int channel;
	char data;
	int char_count;
	int save_cnt;
	int len;

	/* determine the channel and change to that context */
	channel = (u_short) (base_addr[CyLICR] >> 2);
	info = &cy_port[channel];
	info->last_active = jiffies;
	save_cnt = char_count = base_addr[CyRFOC];

#ifdef CONFIG_REMOTE_DEBUG
	if (channel == DEBUG_PORT) {
		while (char_count--) {
			data = base_addr[CyRDR];
			queueDebugChar(data);
		}
	} else
#endif
		/* if there is nowhere to put the data, discard it */
	if (info->tty == 0) {
		while (char_count--) {
			data = base_addr[CyRDR];
		}
	} else {		/* there is an open port for this data */
		tty = info->tty;
		/* load # characters available from the chip */

#ifdef CYCLOM_ENABLE_MONITORING
		++info->mon.int_count;
		info->mon.char_count += char_count;
		if (char_count > info->mon.char_max)
			info->mon.char_max = char_count;
		info->mon.char_last = char_count;
#endif
		len = tty_buffer_request_room(tty, char_count);
		while (len--) {
			data = base_addr[CyRDR];
			tty_insert_flip_char(tty, data, TTY_NORMAL);
#ifdef CYCLOM_16Y_HACK
			udelay(10L);
#endif
		}
		tty_schedule_flip(tty);
	}
	/* end of service */
	base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
	return IRQ_HANDLED;
}				/* cy_rx_interrupt */

/* This is called whenever a port becomes active;
   interrupts are enabled and DTR & RTS are turned on.
 */
static int startup(struct cyclades_port *info)
{
	unsigned long flags;
	volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
	int channel;

	if (info->flags & ASYNC_INITIALIZED) {
		return 0;
	}

	if (!info->type) {
		if (info->tty) {
			set_bit(TTY_IO_ERROR, &info->tty->flags);
		}
		return 0;
	}
	if (!info->xmit_buf) {
		info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
		if (!info->xmit_buf) {
			return -ENOMEM;
		}
	}

	config_setup(info);

	channel = info->line;

#ifdef SERIAL_DEBUG_OPEN
	printk("startup channel %d\n", channel);
#endif

	local_irq_save(flags);
	base_addr[CyCAR] = (u_char) channel;
	write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);

	base_addr[CyCAR] = (u_char) channel;	/* !!! Is this needed? */
	base_addr[CyMSVR1] = CyRTS;
/* CP('S');CP('1'); */
	base_addr[CyMSVR2] = CyDTR;

#ifdef SERIAL_DEBUG_DTR
	printk("cyc: %d: raising DTR\n", __LINE__);
	printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
	       base_addr[CyMSVR2]);
#endif

	base_addr[CyIER] |= CyRxData;
	info->flags |= ASYNC_INITIALIZED;

	if (info->tty) {
		clear_bit(TTY_IO_ERROR, &info->tty->flags);
	}
	info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;

	local_irq_restore(flags);

#ifdef SERIAL_DEBUG_OPEN
	printk(" done\n");
#endif
	return 0;
}				/* startup */

void start_xmit(struct cyclades_port *info)
{
	unsigned long flags;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;

	channel = info->line;
	local_irq_save(flags);
	base_addr[CyCAR] = channel;
	base_addr[CyIER] |= CyTxMpty;
	local_irq_restore(flags);
}				/* start_xmit */

/*
 * This routine shuts down a serial port; interrupts are disabled,
 * and DTR is dropped if the hangup on close termio flag is on.
 */
static void shutdown(struct cyclades_port *info)
{
	unsigned long flags;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;

	if (!(info->flags & ASYNC_INITIALIZED)) {
/* CP('$'); */
		return;
	}

	channel = info->line;

#ifdef SERIAL_DEBUG_OPEN
	printk("shutdown channel %d\n", channel);
#endif

	/* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
	   SENT BEFORE DROPPING THE LINE !!!  (Perhaps
	   set some flag that is read when XMTY happens.)
	   Other choices are to delay some fixed interval
	   or schedule some later processing.
	 */
	local_irq_save(flags);
	if (info->xmit_buf) {
		free_page((unsigned long)info->xmit_buf);
		info->xmit_buf = NULL;
	}

	base_addr[CyCAR] = (u_char) channel;
	if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
		base_addr[CyMSVR1] = 0;
/* CP('C');CP('1'); */
		base_addr[CyMSVR2] = 0;
#ifdef SERIAL_DEBUG_DTR
		printk("cyc: %d: dropping DTR\n", __LINE__);
		printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
		       base_addr[CyMSVR2]);
#endif
	}
	write_cy_cmd(base_addr, CyDIS_RCVR);
	/* it may be appropriate to clear _XMIT at
	   some later date (after testing)!!! */

	if (info->tty) {
		set_bit(TTY_IO_ERROR, &info->tty->flags);
	}
	info->flags &= ~ASYNC_INITIALIZED;
	local_irq_restore(flags);

#ifdef SERIAL_DEBUG_OPEN
	printk(" done\n");
#endif
}				/* shutdown */

/*
 * This routine finds or computes the various line characteristics.
 */
static void config_setup(struct cyclades_port *info)
{
	unsigned long flags;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;
	unsigned cflag;
	int i;
	unsigned char ti, need_init_chan = 0;

	if (!info->tty || !info->tty->termios) {
		return;
	}
	if (info->line == -1) {
		return;
	}
	cflag = info->tty->termios->c_cflag;

	/* baud rate */
	i = cflag & CBAUD;
#ifdef CBAUDEX
/* Starting with kernel 1.1.65, there is direct support for
   higher baud rates.  The following code supports those
   changes.  The conditional aspect allows this driver to be
   used for earlier as well as later kernel versions.  (The
   mapping is slightly different from serial.c because there
   is still the possibility of supporting 75 kbit/sec with
   the Cyclades board.)
 */
	if (i & CBAUDEX) {
		if (i == B57600)
			i = 16;
		else if (i == B115200)
			i = 18;
#ifdef B78600
		else if (i == B78600)
			i = 17;
#endif
		else
			info->tty->termios->c_cflag &= ~CBAUDEX;
	}
#endif
	if (i == 15) {
		if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
			i += 1;
		if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
			i += 3;
	}
	/* Don't ever change the speed of the console port.  It will
	 * run at the speed specified in bootinfo, or at 19.2K */
	/* Actually, it should run at whatever speed 166Bug was using */
	/* Note info->timeout isn't used at present */
	if (info != serial_console_info) {
		info->tbpr = baud_bpr[i];	/* Tx BPR */
		info->tco = baud_co[i];	/* Tx CO */
		info->rbpr = baud_bpr[i];	/* Rx BPR */
		info->rco = baud_co[i] >> 5;	/* Rx CO */
		if (baud_table[i] == 134) {
			info->timeout =
			    (info->xmit_fifo_size * HZ * 30 / 269) + 2;
			/* get it right for 134.5 baud */
		} else if (baud_table[i]) {
			info->timeout =
			    (info->xmit_fifo_size * HZ * 15 / baud_table[i]) +
			    2;
			/* this needs to be propagated into the card info */
		} else {
			info->timeout = 0;
		}
	}
	/* By tradition (is it a standard?) a baud rate of zero
	   implies the line should be/has been closed.  A bit
	   later in this routine such a test is performed. */

	/* byte size and parity */
	info->cor7 = 0;
	info->cor6 = 0;
	info->cor5 = 0;
	info->cor4 = (info->default_threshold ? info->default_threshold : baud_cor4[i]);	/* receive threshold */
	/* Following two lines added 101295, RGH. */
	/* It is obviously wrong to access CyCORx, and not info->corx here,
	 * try and remember to fix it later! */
	channel = info->line;
	base_addr[CyCAR] = (u_char) channel;
	if (C_CLOCAL(info->tty)) {
		if (base_addr[CyIER] & CyMdmCh)
			base_addr[CyIER] &= ~CyMdmCh;	/* without modem intr */
		/* ignore 1->0 modem transitions */
		if (base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD))
			base_addr[CyCOR4] &= ~(CyDSR | CyCTS | CyDCD);
		/* ignore 0->1 modem transitions */
		if (base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD))
			base_addr[CyCOR5] &= ~(CyDSR | CyCTS | CyDCD);
	} else {
		if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
			base_addr[CyIER] |= CyMdmCh;	/* with modem intr */
		/* act on 1->0 modem transitions */
		if ((base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD)) !=
		    (CyDSR | CyCTS | CyDCD))
			base_addr[CyCOR4] |= CyDSR | CyCTS | CyDCD;
		/* act on 0->1 modem transitions */
		if ((base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD)) !=
		    (CyDSR | CyCTS | CyDCD))
			base_addr[CyCOR5] |= CyDSR | CyCTS | CyDCD;
	}
	info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
	info->cor2 = CyETC;
	switch (cflag & CSIZE) {
	case CS5:
		info->cor1 = Cy_5_BITS;
		break;
	case CS6:
		info->cor1 = Cy_6_BITS;
		break;
	case CS7:
		info->cor1 = Cy_7_BITS;
		break;
	case CS8:
		info->cor1 = Cy_8_BITS;
		break;
	}
	if (cflag & PARENB) {
		if (cflag & PARODD) {
			info->cor1 |= CyPARITY_O;
		} else {
			info->cor1 |= CyPARITY_E;
		}
	} else {
		info->cor1 |= CyPARITY_NONE;
	}

	/* CTS flow control flag */
#if 0
	/* Don't complcate matters for now! RGH 141095 */
	if (cflag & CRTSCTS) {
		info->flags |= ASYNC_CTS_FLOW;
		info->cor2 |= CyCtsAE;
	} else {
		info->flags &= ~ASYNC_CTS_FLOW;
		info->cor2 &= ~CyCtsAE;
	}
#endif
	if (cflag & CLOCAL)
		info->flags &= ~ASYNC_CHECK_CD;
	else
		info->flags |= ASYNC_CHECK_CD;

     /***********************************************
	The hardware option, CyRtsAO, presents RTS when
	the chip has characters to send.  Since most modems
	use RTS as reverse (inbound) flow control, this
	option is not used.  If inbound flow control is
	necessary, DTR can be programmed to provide the
	appropriate signals for use with a non-standard
	cable.  Contact Marcio Saito for details.
     ***********************************************/

	channel = info->line;

	local_irq_save(flags);
	base_addr[CyCAR] = (u_char) channel;

	/* CyCMR set once only in mvme167_init_serial() */
	if (base_addr[CyLICR] != channel << 2)
		base_addr[CyLICR] = channel << 2;
	if (base_addr[CyLIVR] != 0x5c)
		base_addr[CyLIVR] = 0x5c;

	/* tx and rx baud rate */

	if (base_addr[CyCOR1] != info->cor1)
		need_init_chan = 1;
	if (base_addr[CyTCOR] != info->tco)
		base_addr[CyTCOR] = info->tco;
	if (base_addr[CyTBPR] != info->tbpr)
		base_addr[CyTBPR] = info->tbpr;
	if (base_addr[CyRCOR] != info->rco)
		base_addr[CyRCOR] = info->rco;
	if (base_addr[CyRBPR] != info->rbpr)
		base_addr[CyRBPR] = info->rbpr;

	/* set line characteristics  according configuration */

	if (base_addr[CySCHR1] != START_CHAR(info->tty))
		base_addr[CySCHR1] = START_CHAR(info->tty);
	if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
		base_addr[CySCHR2] = STOP_CHAR(info->tty);
	if (base_addr[CySCRL] != START_CHAR(info->tty))
		base_addr[CySCRL] = START_CHAR(info->tty);
	if (base_addr[CySCRH] != START_CHAR(info->tty))
		base_addr[CySCRH] = START_CHAR(info->tty);
	if (base_addr[CyCOR1] != info->cor1)
		base_addr[CyCOR1] = info->cor1;
	if (base_addr[CyCOR2] != info->cor2)
		base_addr[CyCOR2] = info->cor2;
	if (base_addr[CyCOR3] != info->cor3)
		base_addr[CyCOR3] = info->cor3;
	if (base_addr[CyCOR4] != info->cor4)
		base_addr[CyCOR4] = info->cor4;
	if (base_addr[CyCOR5] != info->cor5)
		base_addr[CyCOR5] = info->cor5;
	if (base_addr[CyCOR6] != info->cor6)
		base_addr[CyCOR6] = info->cor6;
	if (base_addr[CyCOR7] != info->cor7)
		base_addr[CyCOR7] = info->cor7;

	if (need_init_chan)
		write_cy_cmd(base_addr, CyINIT_CHAN);

	base_addr[CyCAR] = (u_char) channel;	/* !!! Is this needed? */

	/* 2ms default rx timeout */
	ti = info->default_timeout ? info->default_timeout : 0x02;
	if (base_addr[CyRTPRL] != ti)
		base_addr[CyRTPRL] = ti;
	if (base_addr[CyRTPRH] != 0)
		base_addr[CyRTPRH] = 0;

	/* Set up RTS here also ????? RGH 141095 */
	if (i == 0) {		/* baud rate is zero, turn off line */
		if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
			base_addr[CyMSVR2] = 0;
#ifdef SERIAL_DEBUG_DTR
		printk("cyc: %d: dropping DTR\n", __LINE__);
		printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
		       base_addr[CyMSVR2]);
#endif
	} else {
		if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
			base_addr[CyMSVR2] = CyDTR;
#ifdef SERIAL_DEBUG_DTR
		printk("cyc: %d: raising DTR\n", __LINE__);
		printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
		       base_addr[CyMSVR2]);
#endif
	}

	if (info->tty) {
		clear_bit(TTY_IO_ERROR, &info->tty->flags);
	}

	local_irq_restore(flags);

}				/* config_setup */

static void cy_put_char(struct tty_struct *tty, unsigned char ch)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	unsigned long flags;

#ifdef SERIAL_DEBUG_IO
	printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
#endif

	if (serial_paranoia_check(info, tty->name, "cy_put_char"))
		return;

	if (!info->xmit_buf)
		return;

	local_irq_save(flags);
	if (info->xmit_cnt >= PAGE_SIZE - 1) {
		local_irq_restore(flags);
		return;
	}

	info->xmit_buf[info->xmit_head++] = ch;
	info->xmit_head &= PAGE_SIZE - 1;
	info->xmit_cnt++;
	local_irq_restore(flags);
}				/* cy_put_char */

static void cy_flush_chars(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	unsigned long flags;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;

#ifdef SERIAL_DEBUG_IO
	printk("cy_flush_chars %s\n", tty->name);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
		return;

	if (info->xmit_cnt <= 0 || tty->stopped
	    || tty->hw_stopped || !info->xmit_buf)
		return;

	channel = info->line;

	local_irq_save(flags);
	base_addr[CyCAR] = channel;
	base_addr[CyIER] |= CyTxMpty;
	local_irq_restore(flags);
}				/* cy_flush_chars */

/* This routine gets called when tty_write has put something into
    the write_queue.  If the port is not already transmitting stuff,
    start it off by enabling interrupts.  The interrupt service
    routine will then ensure that the characters are sent.  If the
    port is already active, there is no need to kick it.
 */
static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	unsigned long flags;
	int c, total = 0;

#ifdef SERIAL_DEBUG_IO
	printk("cy_write %s\n", tty->name);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_write")) {
		return 0;
	}

	if (!info->xmit_buf) {
		return 0;
	}

	while (1) {
		local_irq_save(flags);
		c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
					  SERIAL_XMIT_SIZE - info->xmit_head));
		if (c <= 0) {
			local_irq_restore(flags);
			break;
		}

		memcpy(info->xmit_buf + info->xmit_head, buf, c);
		info->xmit_head =
		    (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
		info->xmit_cnt += c;
		local_irq_restore(flags);

		buf += c;
		count -= c;
		total += c;
	}

	if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
		start_xmit(info);
	}
	return total;
}				/* cy_write */

static int cy_write_room(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	int ret;

#ifdef SERIAL_DEBUG_IO
	printk("cy_write_room %s\n", tty->name);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_write_room"))
		return 0;
	ret = PAGE_SIZE - info->xmit_cnt - 1;
	if (ret < 0)
		ret = 0;
	return ret;
}				/* cy_write_room */

static int cy_chars_in_buffer(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;

#ifdef SERIAL_DEBUG_IO
	printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
		return 0;

	return info->xmit_cnt;
}				/* cy_chars_in_buffer */

static void cy_flush_buffer(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	unsigned long flags;

#ifdef SERIAL_DEBUG_IO
	printk("cy_flush_buffer %s\n", tty->name);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
		return;
	local_irq_save(flags);
	info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
	local_irq_restore(flags);
	tty_wakeup(tty);
}				/* cy_flush_buffer */

/* This routine is called by the upper-layer tty layer to signal
   that incoming characters should be throttled or that the
   throttle should be released.
 */
static void cy_throttle(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	unsigned long flags;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;

#ifdef SERIAL_DEBUG_THROTTLE
	char buf[64];

	printk("throttle %s: %d....\n", tty_name(tty, buf),
	       tty->ldisc.chars_in_buffer(tty));
	printk("cy_throttle %s\n", tty->name);
#endif

	if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
		return;
	}

	if (I_IXOFF(tty)) {
		info->x_char = STOP_CHAR(tty);
		/* Should use the "Send Special Character" feature!!! */
	}

	channel = info->line;

	local_irq_save(flags);
	base_addr[CyCAR] = (u_char) channel;
	base_addr[CyMSVR1] = 0;
	local_irq_restore(flags);
}				/* cy_throttle */

static void cy_unthrottle(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	unsigned long flags;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;

#ifdef SERIAL_DEBUG_THROTTLE
	char buf[64];

	printk("throttle %s: %d....\n", tty_name(tty, buf),
	       tty->ldisc.chars_in_buffer(tty));
	printk("cy_unthrottle %s\n", tty->name);
#endif

	if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
		return;
	}

	if (I_IXOFF(tty)) {
		info->x_char = START_CHAR(tty);
		/* Should use the "Send Special Character" feature!!! */
	}

	channel = info->line;

	local_irq_save(flags);
	base_addr[CyCAR] = (u_char) channel;
	base_addr[CyMSVR1] = CyRTS;
	local_irq_restore(flags);
}				/* cy_unthrottle */

static int
get_serial_info(struct cyclades_port *info,
		struct serial_struct __user * retinfo)
{
	struct serial_struct tmp;

/* CP('g'); */
	if (!retinfo)
		return -EFAULT;
	memset(&tmp, 0, sizeof(tmp));
	tmp.type = info->type;
	tmp.line = info->line;
	tmp.port = info->line;
	tmp.irq = 0;
	tmp.flags = info->flags;
	tmp.baud_base = 0;	/*!!! */
	tmp.close_delay = info->close_delay;
	tmp.custom_divisor = 0;	/*!!! */
	tmp.hub6 = 0;		/*!!! */
	return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
}				/* get_serial_info */

static int
set_serial_info(struct cyclades_port *info,
		struct serial_struct __user * new_info)
{
	struct serial_struct new_serial;
	struct cyclades_port old_info;

/* CP('s'); */
	if (!new_info)
		return -EFAULT;
	if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
		return -EFAULT;
	old_info = *info;

	if (!capable(CAP_SYS_ADMIN)) {
		if ((new_serial.close_delay != info->close_delay) ||
		    ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
		     (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
			return -EPERM;
		info->flags = ((info->flags & ~ASYNC_USR_MASK) |
			       (new_serial.flags & ASYNC_USR_MASK));
		goto check_and_exit;
	}

	/*
	 * OK, past this point, all the error checking has been done.
	 * At this point, we start making changes.....
	 */

	info->flags = ((info->flags & ~ASYNC_FLAGS) |
		       (new_serial.flags & ASYNC_FLAGS));
	info->close_delay = new_serial.close_delay;

check_and_exit:
	if (info->flags & ASYNC_INITIALIZED) {
		config_setup(info);
		return 0;
	}
	return startup(info);
}				/* set_serial_info */

static int cy_tiocmget(struct tty_struct *tty, struct file *file)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	int channel;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	unsigned long flags;
	unsigned char status;

	channel = info->line;

	local_irq_save(flags);
	base_addr[CyCAR] = (u_char) channel;
	status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
	local_irq_restore(flags);

	return ((status & CyRTS) ? TIOCM_RTS : 0)
	    | ((status & CyDTR) ? TIOCM_DTR : 0)
	    | ((status & CyDCD) ? TIOCM_CAR : 0)
	    | ((status & CyDSR) ? TIOCM_DSR : 0)
	    | ((status & CyCTS) ? TIOCM_CTS : 0);
}				/* cy_tiocmget */

static int
cy_tiocmset(struct tty_struct *tty, struct file *file,
	    unsigned int set, unsigned int clear)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	int channel;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	unsigned long flags;

	channel = info->line;

	if (set & TIOCM_RTS) {
		local_irq_save(flags);
		base_addr[CyCAR] = (u_char) channel;
		base_addr[CyMSVR1] = CyRTS;
		local_irq_restore(flags);
	}
	if (set & TIOCM_DTR) {
		local_irq_save(flags);
		base_addr[CyCAR] = (u_char) channel;
/* CP('S');CP('2'); */
		base_addr[CyMSVR2] = CyDTR;
#ifdef SERIAL_DEBUG_DTR
		printk("cyc: %d: raising DTR\n", __LINE__);
		printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
		       base_addr[CyMSVR2]);
#endif
		local_irq_restore(flags);
	}

	if (clear & TIOCM_RTS) {
		local_irq_save(flags);
		base_addr[CyCAR] = (u_char) channel;
		base_addr[CyMSVR1] = 0;
		local_irq_restore(flags);
	}
	if (clear & TIOCM_DTR) {
		local_irq_save(flags);
		base_addr[CyCAR] = (u_char) channel;
/* CP('C');CP('2'); */
		base_addr[CyMSVR2] = 0;
#ifdef SERIAL_DEBUG_DTR
		printk("cyc: %d: dropping DTR\n", __LINE__);
		printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
		       base_addr[CyMSVR2]);
#endif
		local_irq_restore(flags);
	}

	return 0;
}				/* set_modem_info */

static void send_break(struct cyclades_port *info, int duration)
{				/* Let the transmit ISR take care of this (since it
				   requires stuffing characters into the output stream).
				 */
	info->x_break = duration;
	if (!info->xmit_cnt) {
		start_xmit(info);
	}
}				/* send_break */

static int
get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
{

	if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
		return -EFAULT;
	info->mon.int_count = 0;
	info->mon.char_count = 0;
	info->mon.char_max = 0;
	info->mon.char_last = 0;
	return 0;
}

static int set_threshold(struct cyclades_port *info, unsigned long __user * arg)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	unsigned long value;
	int channel;

	if (get_user(value, arg))
		return -EFAULT;

	channel = info->line;
	info->cor4 &= ~CyREC_FIFO;
	info->cor4 |= value & CyREC_FIFO;
	base_addr[CyCOR4] = info->cor4;
	return 0;
}

static int
get_threshold(struct cyclades_port *info, unsigned long __user * value)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;
	unsigned long tmp;

	channel = info->line;

	tmp = base_addr[CyCOR4] & CyREC_FIFO;
	return put_user(tmp, value);
}

static int
set_default_threshold(struct cyclades_port *info, unsigned long __user * arg)
{
	unsigned long value;

	if (get_user(value, arg))
		return -EFAULT;

	info->default_threshold = value & 0x0f;
	return 0;
}

static int
get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
{
	return put_user(info->default_threshold, value);
}

static int set_timeout(struct cyclades_port *info, unsigned long __user * arg)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;
	unsigned long value;

	if (get_user(value, arg))
		return -EFAULT;

	channel = info->line;

	base_addr[CyRTPRL] = value & 0xff;
	base_addr[CyRTPRH] = (value >> 8) & 0xff;
	return 0;
}

static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;
	unsigned long tmp;

	channel = info->line;

	tmp = base_addr[CyRTPRL];
	return put_user(tmp, value);
}

static int set_default_timeout(struct cyclades_port *info, unsigned long value)
{
	info->default_timeout = value & 0xff;
	return 0;
}

static int
get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
{
	return put_user(info->default_timeout, value);
}

static int
cy_ioctl(struct tty_struct *tty, struct file *file,
	 unsigned int cmd, unsigned long arg)
{
	unsigned long val;
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
	int ret_val = 0;
	void __user *argp = (void __user *)arg;

#ifdef SERIAL_DEBUG_OTHER
	printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg);	/* */
#endif

	lock_kernel();

	switch (cmd) {
	case CYGETMON:
		ret_val = get_mon_info(info, argp);
		break;
	case CYGETTHRESH:
		ret_val = get_threshold(info, argp);
		break;
	case CYSETTHRESH:
		ret_val = set_threshold(info, argp);
		break;
	case CYGETDEFTHRESH:
		ret_val = get_default_threshold(info, argp);
		break;
	case CYSETDEFTHRESH:
		ret_val = set_default_threshold(info, argp);
		break;
	case CYGETTIMEOUT:
		ret_val = get_timeout(info, argp);
		break;
	case CYSETTIMEOUT:
		ret_val = set_timeout(info, argp);
		break;
	case CYGETDEFTIMEOUT:
		ret_val = get_default_timeout(info, argp);
		break;
	case CYSETDEFTIMEOUT:
		ret_val = set_default_timeout(info, (unsigned long)arg);
		break;
	case TCSBRK:		/* SVID version: non-zero arg --> no break */
		ret_val = tty_check_change(tty);
		if (ret_val)
			break;
		tty_wait_until_sent(tty, 0);
		if (!arg)
			send_break(info, HZ / 4);	/* 1/4 second */
		break;
	case TCSBRKP:		/* support for POSIX tcsendbreak() */
		ret_val = tty_check_change(tty);
		if (ret_val)
			break;
		tty_wait_until_sent(tty, 0);
		send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
		break;

/* The following commands are incompletely implemented!!! */
	case TIOCGSERIAL:
		ret_val = get_serial_info(info, argp);
		break;
	case TIOCSSERIAL:
		ret_val = set_serial_info(info, argp);
		break;
	default:
		ret_val = -ENOIOCTLCMD;
	}
	unlock_kernel();

#ifdef SERIAL_DEBUG_OTHER
	printk("cy_ioctl done\n");
#endif

	return ret_val;
}				/* cy_ioctl */

static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;

#ifdef SERIAL_DEBUG_OTHER
	printk("cy_set_termios %s\n", tty->name);
#endif

	if (tty->termios->c_cflag == old_termios->c_cflag)
		return;
	config_setup(info);

	if ((old_termios->c_cflag & CRTSCTS) &&
	    !(tty->termios->c_cflag & CRTSCTS)) {
		tty->stopped = 0;
		cy_start(tty);
	}
#ifdef tytso_patch_94Nov25_1726
	if (!(old_termios->c_cflag & CLOCAL) &&
	    (tty->termios->c_cflag & CLOCAL))
		wake_up_interruptible(&info->open_wait);
#endif
}				/* cy_set_termios */

static void cy_close(struct tty_struct *tty, struct file *filp)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;

/* CP('C'); */
#ifdef SERIAL_DEBUG_OTHER
	printk("cy_close %s\n", tty->name);
#endif

	if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
		return;
	}
#ifdef SERIAL_DEBUG_OPEN
	printk("cy_close %s, count = %d\n", tty->name, info->count);
#endif

	if ((tty->count == 1) && (info->count != 1)) {
		/*
		 * Uh, oh.  tty->count is 1, which means that the tty
		 * structure will be freed.  Info->count should always
		 * be one in these conditions.  If it's greater than
		 * one, we've got real problems, since it means the
		 * serial port won't be shutdown.
		 */
		printk("cy_close: bad serial port count; tty->count is 1, "
		       "info->count is %d\n", info->count);
		info->count = 1;
	}
#ifdef SERIAL_DEBUG_COUNT
	printk("cyc: %d: decrementing count to %d\n", __LINE__,
	       info->count - 1);
#endif
	if (--info->count < 0) {
		printk("cy_close: bad serial port count for ttys%d: %d\n",
		       info->line, info->count);
#ifdef SERIAL_DEBUG_COUNT
		printk("cyc: %d: setting count to 0\n", __LINE__);
#endif
		info->count = 0;
	}
	if (info->count)
		return;
	info->flags |= ASYNC_CLOSING;
	if (info->flags & ASYNC_INITIALIZED)
		tty_wait_until_sent(tty, 3000);	/* 30 seconds timeout */
	shutdown(info);
	if (tty->driver->flush_buffer)
		tty->driver->flush_buffer(tty);
	tty_ldisc_flush(tty);
	info->tty = NULL;
	if (info->blocked_open) {
		if (info->close_delay) {
			msleep_interruptible(jiffies_to_msecs
					     (info->close_delay));
		}
		wake_up_interruptible(&info->open_wait);
	}
	info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
	wake_up_interruptible(&info->close_wait);

#ifdef SERIAL_DEBUG_OTHER
	printk("cy_close done\n");
#endif
}				/* cy_close */

/*
 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
 */
void cy_hangup(struct tty_struct *tty)
{
	struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;

#ifdef SERIAL_DEBUG_OTHER
	printk("cy_hangup %s\n", tty->name);	/* */
#endif

	if (serial_paranoia_check(info, tty->name, "cy_hangup"))
		return;

	shutdown(info);
#if 0
	info->event = 0;
	info->count = 0;
#ifdef SERIAL_DEBUG_COUNT
	printk("cyc: %d: setting count to 0\n", __LINE__);
#endif
	info->tty = 0;
#endif
	info->flags &= ~ASYNC_NORMAL_ACTIVE;
	wake_up_interruptible(&info->open_wait);
}				/* cy_hangup */

/*
 * ------------------------------------------------------------
 * cy_open() and friends
 * ------------------------------------------------------------
 */

static int
block_til_ready(struct tty_struct *tty, struct file *filp,
		struct cyclades_port *info)
{
	DECLARE_WAITQUEUE(wait, current);
	unsigned long flags;
	int channel;
	int retval;
	volatile u_char *base_addr = (u_char *) BASE_ADDR;

	/*
	 * If the device is in the middle of being closed, then block
	 * until it's done, and then try again.
	 */
	if (info->flags & ASYNC_CLOSING) {
		interruptible_sleep_on(&info->close_wait);
		if (info->flags & ASYNC_HUP_NOTIFY) {
			return -EAGAIN;
		} else {
			return -ERESTARTSYS;
		}
	}

	/*
	 * If non-blocking mode is set, then make the check up front
	 * and then exit.
	 */
	if (filp->f_flags & O_NONBLOCK) {
		info->flags |= ASYNC_NORMAL_ACTIVE;
		return 0;
	}

	/*
	 * Block waiting for the carrier detect and the line to become
	 * free (i.e., not in use by the callout).  While we are in
	 * this loop, info->count is dropped by one, so that
	 * cy_close() knows when to free things.  We restore it upon
	 * exit, either normal or abnormal.
	 */
	retval = 0;
	add_wait_queue(&info->open_wait, &wait);
#ifdef SERIAL_DEBUG_OPEN
	printk("block_til_ready before block: %s, count = %d\n",
	       tty->name, info->count);
	/**/
#endif
	    info->count--;
#ifdef SERIAL_DEBUG_COUNT
	printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
#endif
	info->blocked_open++;

	channel = info->line;

	while (1) {
		local_irq_save(flags);
		base_addr[CyCAR] = (u_char) channel;
		base_addr[CyMSVR1] = CyRTS;
/* CP('S');CP('4'); */
		base_addr[CyMSVR2] = CyDTR;
#ifdef SERIAL_DEBUG_DTR
		printk("cyc: %d: raising DTR\n", __LINE__);
		printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
		       base_addr[CyMSVR2]);
#endif
		local_irq_restore(flags);
		set_current_state(TASK_INTERRUPTIBLE);
		if (tty_hung_up_p(filp)
		    || !(info->flags & ASYNC_INITIALIZED)) {
			if (info->flags & ASYNC_HUP_NOTIFY) {
				retval = -EAGAIN;
			} else {
				retval = -ERESTARTSYS;
			}
			break;
		}
		local_irq_save(flags);
		base_addr[CyCAR] = (u_char) channel;
/* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
		if (!(info->flags & ASYNC_CLOSING)
		    && (C_CLOCAL(tty)
			|| (base_addr[CyMSVR1] & CyDCD))) {
			local_irq_restore(flags);
			break;
		}
		local_irq_restore(flags);
		if (signal_pending(current)) {
			retval = -ERESTARTSYS;
			break;
		}
#ifdef SERIAL_DEBUG_OPEN
		printk("block_til_ready blocking: %s, count = %d\n",
		       tty->name, info->count);
		/**/
#endif
		    schedule();
	}
	__set_current_state(TASK_RUNNING);
	remove_wait_queue(&info->open_wait, &wait);
	if (!tty_hung_up_p(filp)) {
		info->count++;
#ifdef SERIAL_DEBUG_COUNT
		printk("cyc: %d: incrementing count to %d\n", __LINE__,
		       info->count);
#endif
	}
	info->blocked_open--;
#ifdef SERIAL_DEBUG_OPEN
	printk("block_til_ready after blocking: %s, count = %d\n",
	       tty->name, info->count);
	/**/
#endif
	    if (retval)
		return retval;
	info->flags |= ASYNC_NORMAL_ACTIVE;
	return 0;
}				/* block_til_ready */

/*
 * This routine is called whenever a serial port is opened.  It
 * performs the serial-specific initialization for the tty structure.
 */
int cy_open(struct tty_struct *tty, struct file *filp)
{
	struct cyclades_port *info;
	int retval, line;

/* CP('O'); */
	line = tty->index;
	if ((line < 0) || (NR_PORTS <= line)) {
		return -ENODEV;
	}
	info = &cy_port[line];
	if (info->line < 0) {
		return -ENODEV;
	}
#ifdef SERIAL_DEBUG_OTHER
	printk("cy_open %s\n", tty->name);	/* */
#endif
	if (serial_paranoia_check(info, tty->name, "cy_open")) {
		return -ENODEV;
	}
#ifdef SERIAL_DEBUG_OPEN
	printk("cy_open %s, count = %d\n", tty->name, info->count);
	/**/
#endif
	    info->count++;
#ifdef SERIAL_DEBUG_COUNT
	printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
#endif
	tty->driver_data = info;
	info->tty = tty;

	/*
	 * Start up serial port
	 */
	retval = startup(info);
	if (retval) {
		return retval;
	}

	retval = block_til_ready(tty, filp, info);
	if (retval) {
#ifdef SERIAL_DEBUG_OPEN
		printk("cy_open returning after block_til_ready with %d\n",
		       retval);
#endif
		return retval;
	}
#ifdef SERIAL_DEBUG_OPEN
	printk("cy_open done\n");
	/**/
#endif
	    return 0;
}				/* cy_open */

/*
 * ---------------------------------------------------------------------
 * serial167_init() and friends
 *
 * serial167_init() is called at boot-time to initialize the serial driver.
 * ---------------------------------------------------------------------
 */

/*
 * This routine prints out the appropriate serial driver version
 * number, and identifies which options were configured into this
 * driver.
 */
static void show_version(void)
{
	printk("MVME166/167 cd2401 driver\n");
}				/* show_version */

/* initialize chips on card -- return number of valid
   chips (which is number of ports/4) */

/*
 * This initialises the hardware to a reasonable state.  It should
 * probe the chip first so as to copy 166-Bug setup as a default for
 * port 0.  It initialises CMR to CyASYNC; that is never done again, so
 * as to limit the number of CyINIT_CHAN commands in normal running.
 *
 * ... I wonder what I should do if this fails ...
 */

void mvme167_serial_console_setup(int cflag)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int ch;
	u_char spd;
	u_char rcor, rbpr, badspeed = 0;
	unsigned long flags;

	local_irq_save(flags);

	/*
	 * First probe channel zero of the chip, to see what speed has
	 * been selected.
	 */

	base_addr[CyCAR] = 0;

	rcor = base_addr[CyRCOR] << 5;
	rbpr = base_addr[CyRBPR];

	for (spd = 0; spd < sizeof(baud_bpr); spd++)
		if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
			break;
	if (spd >= sizeof(baud_bpr)) {
		spd = 14;	/* 19200 */
		badspeed = 1;	/* Failed to identify speed */
	}
	initial_console_speed = spd;

	/* OK, we have chosen a speed, now reset and reinitialise */

	my_udelay(20000L);	/* Allow time for any active o/p to complete */
	if (base_addr[CyCCR] != 0x00) {
		local_irq_restore(flags);
		/* printk(" chip is never idle (CCR != 0)\n"); */
		return;
	}

	base_addr[CyCCR] = CyCHIP_RESET;	/* Reset the chip */
	my_udelay(1000L);

	if (base_addr[CyGFRCR] == 0x00) {
		local_irq_restore(flags);
		/* printk(" chip is not responding (GFRCR stayed 0)\n"); */
		return;
	}

	/*
	 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
	 * tick
	 */

	base_addr[CyTPR] = 10;

	base_addr[CyPILR1] = 0x01;	/* Interrupt level for modem change */
	base_addr[CyPILR2] = 0x02;	/* Interrupt level for tx ints */
	base_addr[CyPILR3] = 0x03;	/* Interrupt level for rx ints */

	/*
	 * Attempt to set up all channels to something reasonable, and
	 * bang out a INIT_CHAN command.  We should then be able to limit
	 * the ammount of fiddling we have to do in normal running.
	 */

	for (ch = 3; ch >= 0; ch--) {
		base_addr[CyCAR] = (u_char) ch;
		base_addr[CyIER] = 0;
		base_addr[CyCMR] = CyASYNC;
		base_addr[CyLICR] = (u_char) ch << 2;
		base_addr[CyLIVR] = 0x5c;
		base_addr[CyTCOR] = baud_co[spd];
		base_addr[CyTBPR] = baud_bpr[spd];
		base_addr[CyRCOR] = baud_co[spd] >> 5;
		base_addr[CyRBPR] = baud_bpr[spd];
		base_addr[CySCHR1] = 'Q' & 0x1f;
		base_addr[CySCHR2] = 'X' & 0x1f;
		base_addr[CySCRL] = 0;
		base_addr[CySCRH] = 0;
		base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
		base_addr[CyCOR2] = 0;
		base_addr[CyCOR3] = Cy_1_STOP;
		base_addr[CyCOR4] = baud_cor4[spd];
		base_addr[CyCOR5] = 0;
		base_addr[CyCOR6] = 0;
		base_addr[CyCOR7] = 0;
		base_addr[CyRTPRL] = 2;
		base_addr[CyRTPRH] = 0;
		base_addr[CyMSVR1] = 0;
		base_addr[CyMSVR2] = 0;
		write_cy_cmd(base_addr, CyINIT_CHAN | CyDIS_RCVR | CyDIS_XMTR);
	}

	/*
	 * Now do specials for channel zero....
	 */

	base_addr[CyMSVR1] = CyRTS;
	base_addr[CyMSVR2] = CyDTR;
	base_addr[CyIER] = CyRxData;
	write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);

	local_irq_restore(flags);

	my_udelay(20000L);	/* Let it all settle down */

	printk("CD2401 initialised,  chip is rev 0x%02x\n", base_addr[CyGFRCR]);
	if (badspeed)
		printk
		    ("  WARNING:  Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
		     rcor >> 5, rbpr);
}				/* serial_console_init */

static const struct tty_operations cy_ops = {
	.open = cy_open,
	.close = cy_close,
	.write = cy_write,
	.put_char = cy_put_char,
	.flush_chars = cy_flush_chars,
	.write_room = cy_write_room,
	.chars_in_buffer = cy_chars_in_buffer,
	.flush_buffer = cy_flush_buffer,
	.ioctl = cy_ioctl,
	.throttle = cy_throttle,
	.unthrottle = cy_unthrottle,
	.set_termios = cy_set_termios,
	.stop = cy_stop,
	.start = cy_start,
	.hangup = cy_hangup,
	.tiocmget = cy_tiocmget,
	.tiocmset = cy_tiocmset,
};

/* The serial driver boot-time initialization code!
    Hardware I/O ports are mapped to character special devices on a
    first found, first allocated manner.  That is, this code searches
    for Cyclom cards in the system.  As each is found, it is probed
    to discover how many chips (and thus how many ports) are present.
    These ports are mapped to the tty ports 64 and upward in monotonic
    fashion.  If an 8-port card is replaced with a 16-port card, the
    port mapping on a following card will shift.

    This approach is different from what is used in the other serial
    device driver because the Cyclom is more properly a multiplexer,
    not just an aggregation of serial ports on one card.

    If there are more cards with more ports than have been statically
    allocated above, a warning is printed and the extra ports are ignored.
 */
static int __init serial167_init(void)
{
	struct cyclades_port *info;
	int ret = 0;
	int good_ports = 0;
	int port_num = 0;
	int index;
	int DefSpeed;
#ifdef notyet
	struct sigaction sa;
#endif

	if (!(mvme16x_config & MVME16x_CONFIG_GOT_CD2401))
		return 0;

	cy_serial_driver = alloc_tty_driver(NR_PORTS);
	if (!cy_serial_driver)
		return -ENOMEM;

#if 0
	scrn[1] = '\0';
#endif

	show_version();

	/* Has "console=0,9600n8" been used in bootinfo to change speed? */
	if (serial_console_cflag)
		DefSpeed = serial_console_cflag & 0017;
	else {
		DefSpeed = initial_console_speed;
		serial_console_info = &cy_port[0];
		serial_console_cflag = DefSpeed | CS8;
#if 0
		serial_console = 64;	/*callout_driver.minor_start */
#endif
	}

	/* Initialize the tty_driver structure */

	cy_serial_driver->owner = THIS_MODULE;
	cy_serial_driver->name = "ttyS";
	cy_serial_driver->major = TTY_MAJOR;
	cy_serial_driver->minor_start = 64;
	cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
	cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
	cy_serial_driver->init_termios = tty_std_termios;
	cy_serial_driver->init_termios.c_cflag =
	    B9600 | CS8 | CREAD | HUPCL | CLOCAL;
	cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
	tty_set_operations(cy_serial_driver, &cy_ops);

	ret = tty_register_driver(cy_serial_driver);
	if (ret) {
		printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
		put_tty_driver(cy_serial_driver);
		return ret;
	}

	port_num = 0;
	info = cy_port;
	for (index = 0; index < 1; index++) {

		good_ports = 4;

		if (port_num < NR_PORTS) {
			while (good_ports-- && port_num < NR_PORTS) {
		/*** initialize port ***/
				info->magic = CYCLADES_MAGIC;
				info->type = PORT_CIRRUS;
				info->card = index;
				info->line = port_num;
				info->flags = STD_COM_FLAGS;
				info->tty = NULL;
				info->xmit_fifo_size = 12;
				info->cor1 = CyPARITY_NONE | Cy_8_BITS;
				info->cor2 = CyETC;
				info->cor3 = Cy_1_STOP;
				info->cor4 = 0x08;	/* _very_ small receive threshold */
				info->cor5 = 0;
				info->cor6 = 0;
				info->cor7 = 0;
				info->tbpr = baud_bpr[DefSpeed];	/* Tx BPR */
				info->tco = baud_co[DefSpeed];	/* Tx CO */
				info->rbpr = baud_bpr[DefSpeed];	/* Rx BPR */
				info->rco = baud_co[DefSpeed] >> 5;	/* Rx CO */
				info->close_delay = 0;
				info->x_char = 0;
				info->count = 0;
#ifdef SERIAL_DEBUG_COUNT
				printk("cyc: %d: setting count to 0\n",
				       __LINE__);
#endif
				info->blocked_open = 0;
				info->default_threshold = 0;
				info->default_timeout = 0;
				init_waitqueue_head(&info->open_wait);
				init_waitqueue_head(&info->close_wait);
				/* info->session */
				/* info->pgrp */
/*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
				info->read_status_mask =
				    CyTIMEOUT | CySPECHAR | CyBREAK | CyPARITY |
				    CyFRAME | CyOVERRUN;
				/* info->timeout */

				printk("ttyS%d ", info->line);
				port_num++;
				info++;
				if (!(port_num & 7)) {
					printk("\n               ");
				}
			}
		}
		printk("\n");
	}
	while (port_num < NR_PORTS) {
		info->line = -1;
		port_num++;
		info++;
	}
#ifdef CONFIG_REMOTE_DEBUG
	debug_setup();
#endif
	ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
			  "cd2401_errors", cd2401_rxerr_interrupt);
	if (ret) {
		printk(KERN_ERR "Could't get cd2401_errors IRQ");
		goto cleanup_serial_driver;
	}

	ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
			  "cd2401_modem", cd2401_modem_interrupt);
	if (ret) {
		printk(KERN_ERR "Could't get cd2401_modem IRQ");
		goto cleanup_irq_cd2401_errors;
	}

	ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
			  "cd2401_txints", cd2401_tx_interrupt);
	if (ret) {
		printk(KERN_ERR "Could't get cd2401_txints IRQ");
		goto cleanup_irq_cd2401_modem;
	}

	ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
			  "cd2401_rxints", cd2401_rx_interrupt);
	if (ret) {
		printk(KERN_ERR "Could't get cd2401_rxints IRQ");
		goto cleanup_irq_cd2401_txints;
	}

	/* Now we have registered the interrupt handlers, allow the interrupts */

	pcc2chip[PccSCCMICR] = 0x15;	/* Serial ints are level 5 */
	pcc2chip[PccSCCTICR] = 0x15;
	pcc2chip[PccSCCRICR] = 0x15;

	pcc2chip[PccIMLR] = 3;	/* Allow PCC2 ints above 3!? */

	return 0;
cleanup_irq_cd2401_txints:
	free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
cleanup_irq_cd2401_modem:
	free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
cleanup_irq_cd2401_errors:
	free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
cleanup_serial_driver:
	if (tty_unregister_driver(cy_serial_driver))
		printk(KERN_ERR
		       "Couldn't unregister MVME166/7 serial driver\n");
	put_tty_driver(cy_serial_driver);
	return ret;
}				/* serial167_init */

module_init(serial167_init);

#ifdef CYCLOM_SHOW_STATUS
static void show_status(int line_num)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int channel;
	struct cyclades_port *info;
	unsigned long flags;

	info = &cy_port[line_num];
	channel = info->line;
	printk("  channel %d\n", channel);
	/**/ printk(" cy_port\n");
	printk("  card line flags = %d %d %x\n",
	       info->card, info->line, info->flags);
	printk
	    ("  *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
	     (long)info->tty, info->read_status_mask, info->timeout,
	     info->xmit_fifo_size);
	printk("  cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
	       info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
	       info->cor6, info->cor7);
	printk("  tbpr,tco,rbpr,rco = %d %d %d %d\n", info->tbpr, info->tco,
	       info->rbpr, info->rco);
	printk("  close_delay event count = %d %d %d\n", info->close_delay,
	       info->event, info->count);
	printk("  x_char blocked_open = %x %x\n", info->x_char,
	       info->blocked_open);
	printk("  open_wait = %lx %lx %lx\n", (long)info->open_wait);

	local_irq_save(flags);

/* Global Registers */

	printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
	printk(" CyCAR %x\n", base_addr[CyCAR]);
	printk(" CyRISR %x\n", base_addr[CyRISR]);
	printk(" CyTISR %x\n", base_addr[CyTISR]);
	printk(" CyMISR %x\n", base_addr[CyMISR]);
	printk(" CyRIR %x\n", base_addr[CyRIR]);
	printk(" CyTIR %x\n", base_addr[CyTIR]);
	printk(" CyMIR %x\n", base_addr[CyMIR]);
	printk(" CyTPR %x\n", base_addr[CyTPR]);

	base_addr[CyCAR] = (u_char) channel;

/* Virtual Registers */

#if 0
	printk(" CyRIVR %x\n", base_addr[CyRIVR]);
	printk(" CyTIVR %x\n", base_addr[CyTIVR]);
	printk(" CyMIVR %x\n", base_addr[CyMIVR]);
	printk(" CyMISR %x\n", base_addr[CyMISR]);
#endif

/* Channel Registers */

	printk(" CyCCR %x\n", base_addr[CyCCR]);
	printk(" CyIER %x\n", base_addr[CyIER]);
	printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
	printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
	printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
	printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
	printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
#if 0
	printk(" CyCCSR %x\n", base_addr[CyCCSR]);
	printk(" CyRDCR %x\n", base_addr[CyRDCR]);
#endif
	printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
	printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
#if 0
	printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
	printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
	printk(" CySCRL %x\n", base_addr[CySCRL]);
	printk(" CySCRH %x\n", base_addr[CySCRH]);
	printk(" CyLNC %x\n", base_addr[CyLNC]);
	printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
	printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
#endif
	printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
	printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
	printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
	printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
	printk(" CyRBPR %x\n", base_addr[CyRBPR]);
	printk(" CyRCOR %x\n", base_addr[CyRCOR]);
	printk(" CyTBPR %x\n", base_addr[CyTBPR]);
	printk(" CyTCOR %x\n", base_addr[CyTCOR]);

	local_irq_restore(flags);
}				/* show_status */
#endif

#if 0
/* Dummy routine in mvme16x/config.c for now */

/* Serial console setup. Called from linux/init/main.c */

void console_setup(char *str, int *ints)
{
	char *s;
	int baud, bits, parity;
	int cflag = 0;

	/* Sanity check. */
	if (ints[0] > 3 || ints[1] > 3)
		return;

	/* Get baud, bits and parity */
	baud = 2400;
	bits = 8;
	parity = 'n';
	if (ints[2])
		baud = ints[2];
	if ((s = strchr(str, ','))) {
		do {
			s++;
		} while (*s >= '0' && *s <= '9');
		if (*s)
			parity = *s++;
		if (*s)
			bits = *s - '0';
	}

	/* Now construct a cflag setting. */
	switch (baud) {
	case 1200:
		cflag |= B1200;
		break;
	case 9600:
		cflag |= B9600;
		break;
	case 19200:
		cflag |= B19200;
		break;
	case 38400:
		cflag |= B38400;
		break;
	case 2400:
	default:
		cflag |= B2400;
		break;
	}
	switch (bits) {
	case 7:
		cflag |= CS7;
		break;
	default:
	case 8:
		cflag |= CS8;
		break;
	}
	switch (parity) {
	case 'o':
	case 'O':
		cflag |= PARODD;
		break;
	case 'e':
	case 'E':
		cflag |= PARENB;
		break;
	}

	serial_console_info = &cy_port[ints[1]];
	serial_console_cflag = cflag;
	serial_console = ints[1] + 64;	/*callout_driver.minor_start */
}
#endif

/*
 * The following is probably out of date for 2.1.x serial console stuff.
 *
 * The console is registered early on from arch/m68k/kernel/setup.c, and
 * it therefore relies on the chip being setup correctly by 166-Bug.  This
 * seems reasonable, as the serial port has been used to invoke the system
 * boot.  It also means that this function must not rely on any data
 * initialisation performed by serial167_init() etc.
 *
 * Of course, once the console has been registered, we had better ensure
 * that serial167_init() doesn't leave the chip non-functional.
 *
 * The console must be locked when we get here.
 */

void serial167_console_write(struct console *co, const char *str,
			     unsigned count)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	unsigned long flags;
	volatile u_char sink;
	u_char ier;
	int port;
	u_char do_lf = 0;
	int i = 0;

	local_irq_save(flags);

	/* Ensure transmitter is enabled! */

	port = 0;
	base_addr[CyCAR] = (u_char) port;
	while (base_addr[CyCCR])
		;
	base_addr[CyCCR] = CyENB_XMTR;

	ier = base_addr[CyIER];
	base_addr[CyIER] = CyTxMpty;

	while (1) {
		if (pcc2chip[PccSCCTICR] & 0x20) {
			/* We have a Tx int. Acknowledge it */
			sink = pcc2chip[PccTPIACKR];
			if ((base_addr[CyLICR] >> 2) == port) {
				if (i == count) {
					/* Last char of string is now output */
					base_addr[CyTEOIR] = CyNOTRANS;
					break;
				}
				if (do_lf) {
					base_addr[CyTDR] = '\n';
					str++;
					i++;
					do_lf = 0;
				} else if (*str == '\n') {
					base_addr[CyTDR] = '\r';
					do_lf = 1;
				} else {
					base_addr[CyTDR] = *str++;
					i++;
				}
				base_addr[CyTEOIR] = 0;
			} else
				base_addr[CyTEOIR] = CyNOTRANS;
		}
	}

	base_addr[CyIER] = ier;

	local_irq_restore(flags);
}

static struct tty_driver *serial167_console_device(struct console *c,
						   int *index)
{
	*index = c->index;
	return cy_serial_driver;
}

static struct console sercons = {
	.name = "ttyS",
	.write = serial167_console_write,
	.device = serial167_console_device,
	.flags = CON_PRINTBUFFER,
	.index = -1,
};

static int __init serial167_console_init(void)
{
	if (vme_brdtype == VME_TYPE_MVME166 ||
	    vme_brdtype == VME_TYPE_MVME167 ||
	    vme_brdtype == VME_TYPE_MVME177) {
		mvme167_serial_console_setup(0);
		register_console(&sercons);
	}
	return 0;
}

console_initcall(serial167_console_init);

#ifdef CONFIG_REMOTE_DEBUG
void putDebugChar(int c)
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	unsigned long flags;
	volatile u_char sink;
	u_char ier;
	int port;

	local_irq_save(flags);

	/* Ensure transmitter is enabled! */

	port = DEBUG_PORT;
	base_addr[CyCAR] = (u_char) port;
	while (base_addr[CyCCR])
		;
	base_addr[CyCCR] = CyENB_XMTR;

	ier = base_addr[CyIER];
	base_addr[CyIER] = CyTxMpty;

	while (1) {
		if (pcc2chip[PccSCCTICR] & 0x20) {
			/* We have a Tx int. Acknowledge it */
			sink = pcc2chip[PccTPIACKR];
			if ((base_addr[CyLICR] >> 2) == port) {
				base_addr[CyTDR] = c;
				base_addr[CyTEOIR] = 0;
				break;
			} else
				base_addr[CyTEOIR] = CyNOTRANS;
		}
	}

	base_addr[CyIER] = ier;

	local_irq_restore(flags);
}

int getDebugChar()
{
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	unsigned long flags;
	volatile u_char sink;
	u_char ier;
	int port;
	int i, c;

	i = debugiq.out;
	if (i != debugiq.in) {
		c = debugiq.buf[i];
		if (++i == DEBUG_LEN)
			i = 0;
		debugiq.out = i;
		return c;
	}
	/* OK, nothing in queue, wait in poll loop */

	local_irq_save(flags);

	/* Ensure receiver is enabled! */

	port = DEBUG_PORT;
	base_addr[CyCAR] = (u_char) port;
#if 0
	while (base_addr[CyCCR])
		;
	base_addr[CyCCR] = CyENB_RCVR;
#endif
	ier = base_addr[CyIER];
	base_addr[CyIER] = CyRxData;

	while (1) {
		if (pcc2chip[PccSCCRICR] & 0x20) {
			/* We have a Rx int. Acknowledge it */
			sink = pcc2chip[PccRPIACKR];
			if ((base_addr[CyLICR] >> 2) == port) {
				int cnt = base_addr[CyRFOC];
				while (cnt-- > 0) {
					c = base_addr[CyRDR];
					if (c == 0)
						printk
						    ("!! debug char is null (cnt=%d) !!",
						     cnt);
					else
						queueDebugChar(c);
				}
				base_addr[CyREOIR] = 0;
				i = debugiq.out;
				if (i == debugiq.in)
					panic("Debug input queue empty!");
				c = debugiq.buf[i];
				if (++i == DEBUG_LEN)
					i = 0;
				debugiq.out = i;
				break;
			} else
				base_addr[CyREOIR] = CyNOTRANS;
		}
	}

	base_addr[CyIER] = ier;

	local_irq_restore(flags);

	return (c);
}

void queueDebugChar(int c)
{
	int i;

	i = debugiq.in;
	debugiq.buf[i] = c;
	if (++i == DEBUG_LEN)
		i = 0;
	if (i != debugiq.out)
		debugiq.in = i;
}

static void debug_setup()
{
	unsigned long flags;
	volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
	int i, cflag;

	cflag = B19200;

	local_irq_save(flags);

	for (i = 0; i < 4; i++) {
		base_addr[CyCAR] = i;
		base_addr[CyLICR] = i << 2;
	}

	debugiq.in = debugiq.out = 0;

	base_addr[CyCAR] = DEBUG_PORT;

	/* baud rate */
	i = cflag & CBAUD;

	base_addr[CyIER] = 0;

	base_addr[CyCMR] = CyASYNC;
	base_addr[CyLICR] = DEBUG_PORT << 2;
	base_addr[CyLIVR] = 0x5c;

	/* tx and rx baud rate */

	base_addr[CyTCOR] = baud_co[i];
	base_addr[CyTBPR] = baud_bpr[i];
	base_addr[CyRCOR] = baud_co[i] >> 5;
	base_addr[CyRBPR] = baud_bpr[i];

	/* set line characteristics  according configuration */

	base_addr[CySCHR1] = 0;
	base_addr[CySCHR2] = 0;
	base_addr[CySCRL] = 0;
	base_addr[CySCRH] = 0;
	base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
	base_addr[CyCOR2] = 0;
	base_addr[CyCOR3] = Cy_1_STOP;
	base_addr[CyCOR4] = baud_cor4[i];
	base_addr[CyCOR5] = 0;
	base_addr[CyCOR6] = 0;
	base_addr[CyCOR7] = 0;

	write_cy_cmd(base_addr, CyINIT_CHAN);
	write_cy_cmd(base_addr, CyENB_RCVR);

	base_addr[CyCAR] = DEBUG_PORT;	/* !!! Is this needed? */

	base_addr[CyRTPRL] = 2;
	base_addr[CyRTPRH] = 0;

	base_addr[CyMSVR1] = CyRTS;
	base_addr[CyMSVR2] = CyDTR;

	base_addr[CyIER] = CyRxData;

	local_irq_restore(flags);

}				/* debug_setup */

#endif

MODULE_LICENSE("GPL");
