--- /dev/null
+/* 68328serial.c: Serial port driver for 68328 microcontroller
+ *
+ * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>
+ * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
+ * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>
+ * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>
+ * Copyright (C) 2002 David McCullough <davidm@snapgear.com>
+ * Copyright (C) 2002 Greg Ungerer <gerg@snapgear.com>
+ *
+ * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca>
+ * Multiple UART support Daniel Potts <danielp@cse.unsw.edu.au>
+ * Power management support Daniel Potts <danielp@cse.unsw.edu.au>
+ * VZ Second Serial Port enable Phil Wilshire
+ * 2.4/2.5 port David McCullough
+ */
+
+#include <asm/dbg.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/config.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/fcntl.h>
+#include <linux/mm.h>
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/reboot.h>
+#include <linux/keyboard.h>
+#include <linux/init.h>
+#include <linux/pm.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/system.h>
+#include <asm/segment.h>
+#include <asm/bitops.h>
+#include <asm/delay.h>
+#include <asm/uaccess.h>
+
+/* (es) */
+/* note: perhaps we can murge these files, so that you can just
+ * define 1 of them, and they can sort that out for themselves
+ */
+#if defined(CONFIG_M68EZ328)
+#include <asm/MC68EZ328.h>
+#else
+#if defined(CONFIG_M68VZ328)
+#include <asm/MC68VZ328.h>
+#else
+#include <asm/MC68328.h>
+#endif /* CONFIG_M68VZ328 */
+#endif /* CONFIG_M68EZ328 */
+
+#include "68328serial.h"
+
+/* Turn off usage of real serial interrupt code, to "support" Copilot */
+#ifdef CONFIG_XCOPILOT_BUGS
+#undef USE_INTS
+#else
+#define USE_INTS
+#endif
+
+static struct m68k_serial m68k_soft[NR_PORTS];
+struct m86k_serial *IRQ_ports[NR_IRQS];
+
+static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS;
+
+/* multiple ports are contiguous in memory */
+m68328_uart *uart_addr = USTCNT_ADDR;
+
+struct tty_struct m68k_ttys;
+struct m68k_serial *m68k_consinfo = 0;
+
+#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */
+
+#ifdef CONFIG_CONSOLE
+extern wait_queue_head_t keypress_wait;
+#endif
+
+struct tty_driver serial_driver, callout_driver;
+static int serial_refcount;
+
+/* serial subtype definitions */
+#define SERIAL_TYPE_NORMAL 1
+#define SERIAL_TYPE_CALLOUT 2
+
+/* number of characters left in xmit buffer before we ask for more */
+#define WAKEUP_CHARS 256
+
+/* Debugging... DEBUG_INTR is bad to use when one of the zs
+ * lines is your console ;(
+ */
+#undef SERIAL_DEBUG_INTR
+#undef SERIAL_DEBUG_OPEN
+#undef SERIAL_DEBUG_FLOW
+
+#define RS_ISR_PASS_LIMIT 256
+
+#define _INLINE_ inline
+
+static void change_speed(struct m68k_serial *info);
+
+static struct tty_struct *serial_table[NR_PORTS];
+static struct termios *serial_termios[NR_PORTS];
+static struct termios *serial_termios_locked[NR_PORTS];
+
+/*
+ * Setup for console. Argument comes from the boot command line.
+ */
+
+#if defined(CONFIG_M68EZ328ADS) || defined(CONFIG_ALMA_ANS) || defined(CONFIG_DRAGONIXVZ)
+#define CONSOLE_BAUD_RATE 115200
+#define DEFAULT_CBAUD B115200
+#else
+ /* (es) */
+ /* note: this is messy, but it works, again, perhaps defined somewhere else?*/
+ #ifdef CONFIG_M68VZ328
+ #define CONSOLE_BAUD_RATE 19200
+ #define DEFAULT_CBAUD B19200
+ #endif
+ /* (/es) */
+#endif
+
+#ifndef CONSOLE_BAUD_RATE
+#define CONSOLE_BAUD_RATE 9600
+#define DEFAULT_CBAUD B9600
+#endif
+
+
+static int m68328_console_initted = 0;
+static int m68328_console_baud = CONSOLE_BAUD_RATE;
+static int m68328_console_cbaud = DEFAULT_CBAUD;
+
+
+/*
+ * 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[SERIAL_XMIT_SIZE]; /* This is cheating */
+DECLARE_MUTEX(tmp_buf_sem);
+
+static inline int serial_paranoia_check(struct m68k_serial *info,
+ kdev_t device, const char *routine)
+{
+#ifdef SERIAL_PARANOIA_CHECK
+ static const char *badmagic =
+ "Warning: bad magic number for serial struct (%d, %d) in %s\n";
+ static const char *badinfo =
+ "Warning: null m68k_serial for (%d, %d) in %s\n";
+
+ if (!info) {
+ printk(badinfo, major(device), minor(device), routine);
+ return 1;
+ }
+ if (info->magic != SERIAL_MAGIC) {
+ printk(badmagic, major(device), minor(device), routine);
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+/*
+ * This is used to figure out the divisor speeds and the timeouts
+ */
+static int baud_table[] = {
+ 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
+ 9600, 19200, 38400, 57600, 115200, 0 };
+
+#define BAUD_TABLE_SIZE (sizeof(baud_table)/sizeof(baud_table[0]))
+
+/* Sets or clears DTR/RTS on the requested line */
+static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)
+{
+ if (set) {
+ /* set the RTS/CTS line */
+ } else {
+ /* clear it */
+ }
+ return;
+}
+
+/* Utility routines */
+static inline int get_baud(struct m68k_serial *ss)
+{
+ unsigned long result = 115200;
+ unsigned short int baud = uart_addr[ss->line].ubaud;
+ if (GET_FIELD(baud, UBAUD_PRESCALER) == 0x38) result = 38400;
+ result >>= GET_FIELD(baud, UBAUD_DIVIDE);
+
+ return result;
+}
+
+/*
+ * ------------------------------------------------------------
+ * 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 m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "rs_stop"))
+ return;
+
+ save_flags(flags); cli();
+ uart->ustcnt &= ~USTCNT_TXEN;
+ restore_flags(flags);
+}
+
+static void rs_put_char(char ch)
+{
+ int flags, loops = 0;
+
+ save_flags(flags); cli();
+
+ while (!(UTX & UTX_TX_AVAIL) && (loops < 1000)) {
+ loops++;
+ udelay(5);
+ }
+
+ UTX_TXDATA = ch;
+ udelay(5);
+ restore_flags(flags);
+}
+
+static void rs_start(struct tty_struct *tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "rs_start"))
+ return;
+
+ save_flags(flags); cli();
+ if (info->xmit_cnt && info->xmit_buf && !(uart->ustcnt & USTCNT_TXEN)) {
+#ifdef USE_INTS
+ uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
+#else
+ uart->ustcnt |= USTCNT_TXEN;
+#endif
+ }
+ restore_flags(flags);
+}
+
+/* Drop into either the boot monitor or kadb upon receiving a break
+ * from keyboard/console input.
+ */
+static void batten_down_hatches(void)
+{
+ /* Drop into the debugger */
+}
+
+static _INLINE_ void status_handle(struct m68k_serial *info, unsigned short status)
+{
+#if 0
+ if(status & DCD) {
+ if((info->tty->termios->c_cflag & CRTSCTS) &&
+ ((info->curregs[3] & AUTO_ENAB)==0)) {
+ info->curregs[3] |= AUTO_ENAB;
+ info->pendregs[3] |= AUTO_ENAB;
+ write_zsreg(info->m68k_channel, 3, info->curregs[3]);
+ }
+ } else {
+ if((info->curregs[3] & AUTO_ENAB)) {
+ info->curregs[3] &= ~AUTO_ENAB;
+ info->pendregs[3] &= ~AUTO_ENAB;
+ write_zsreg(info->m68k_channel, 3, info->curregs[3]);
+ }
+ }
+#endif
+ /* If this is console input and this is a
+ * 'break asserted' status change interrupt
+ * see if we can drop into the debugger
+ */
+ if((status & URX_BREAK) && info->break_abort)
+ batten_down_hatches();
+ return;
+}
+
+static _INLINE_ void receive_chars(struct m68k_serial *info, struct pt_regs *regs, unsigned short rx)
+{
+ struct tty_struct *tty = info->tty;
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned char ch;
+
+ /*
+ * This do { } while() loop will get ALL chars out of Rx FIFO
+ */
+#ifndef CONFIG_XCOPILOT_BUGS
+ do {
+#endif
+ ch = GET_FIELD(rx, URX_RXDATA);
+
+ if(info->is_cons) {
+ if(URX_BREAK & rx) { /* whee, break received */
+ status_handle(info, rx);
+ return;
+#ifdef CONFIG_MAGIC_SYSRQ
+ } else if (ch == 0x10) { /* ^P */
+ show_state();
+ show_free_areas();
+ show_buffers();
+/* show_net_buffers(); */
+ return;
+ } else if (ch == 0x12) { /* ^R */
+ machine_restart(NULL);
+ return;
+#endif /* CONFIG_MAGIC_SYSRQ */
+ }
+ /* It is a 'keyboard interrupt' ;-) */
+#ifdef CONFIG_CONSOLE
+ wake_up(&keypress_wait);
+#endif
+ }
+
+ if(!tty)
+ goto clear_and_exit;
+
+ /*
+ * Make sure that we do not overflow the buffer
+ */
+ if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
+ schedule_work(&tty->flip.work);
+ return;
+ }
+
+ if(rx & URX_PARITY_ERROR) {
+ *tty->flip.flag_buf_ptr++ = TTY_PARITY;
+ status_handle(info, rx);
+ } else if(rx & URX_OVRUN) {
+ *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
+ status_handle(info, rx);
+ } else if(rx & URX_FRAME_ERROR) {
+ *tty->flip.flag_buf_ptr++ = TTY_FRAME;
+ status_handle(info, rx);
+ } else {
+ *tty->flip.flag_buf_ptr++ = 0; /* XXX */
+ }
+ *tty->flip.char_buf_ptr++ = ch;
+ tty->flip.count++;
+
+#ifndef CONFIG_XCOPILOT_BUGS
+ } while((rx = uart->urx.w) & URX_DATA_READY);
+#endif
+
+ schedule_work(&tty->flip.work);
+
+clear_and_exit:
+ return;
+}
+
+static _INLINE_ void transmit_chars(struct m68k_serial *info)
+{
+ m68328_uart *uart = &uart_addr[info->line];
+
+ if (info->x_char) {
+ /* Send next char */
+ uart->utx.b.txdata = info->x_char;
+ info->x_char = 0;
+ goto clear_and_return;
+ }
+
+ if((info->xmit_cnt <= 0) || info->tty->stopped) {
+ /* That's peculiar... TX ints off */
+ uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
+ goto clear_and_return;
+ }
+
+ /* Send char */
+ uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
+ info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
+ info->xmit_cnt--;
+
+ if (info->xmit_cnt < WAKEUP_CHARS)
+ schedule_work(&info->tqueue);
+
+ if(info->xmit_cnt <= 0) {
+ /* All done for now... TX ints off */
+ uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
+ goto clear_and_return;
+ }
+
+clear_and_return:
+ /* Clear interrupt (should be auto)*/
+ return;
+}
+
+/*
+ * This is the serial driver's generic interrupt routine
+ */
+void rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
+{
+ struct m68k_serial * info;
+ m68328_uart *uart;
+ unsigned short rx;
+ unsigned short tx;
+
+ info = IRQ_ports[irq];
+ if(!info)
+ return;
+
+ uart = &uart_addr[info->line];
+ rx = uart->urx.w;
+
+#ifdef USE_INTS
+ tx = uart->utx.w;
+
+ if (rx & URX_DATA_READY) receive_chars(info, regs, rx);
+ if (tx & UTX_TX_AVAIL) transmit_chars(info);
+#else
+ receive_chars(info, regs, rx);
+#endif
+ return;
+}
+
+static void do_softint(void *private)
+{
+ struct m68k_serial *info = (struct m68k_serial *) private;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (!tty)
+ return;
+#if 0
+ if (clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
+ if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+ tty->ldisc.write_wakeup)
+ (tty->ldisc.write_wakeup)(tty);
+ wake_up_interruptible(&tty->write_wait);
+ }
+#endif
+}
+
+/*
+ * 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() -> rs_hangup()
+ *
+ */
+static void do_serial_hangup(void *private)
+{
+ struct m68k_serial *info = (struct m68k_serial *) private;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (!tty)
+ return;
+
+ tty_hangup(tty);
+}
+
+
+static int startup(struct m68k_serial * info)
+{
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+
+ if (info->flags & S_INITIALIZED)
+ return 0;
+
+ if (!info->xmit_buf) {
+ info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
+ if (!info->xmit_buf)
+ return -ENOMEM;
+ }
+
+ save_flags(flags); cli();
+
+ /*
+ * Clear the FIFO buffers and disable them
+ * (they will be reenabled in change_speed())
+ */
+
+ uart->ustcnt = USTCNT_UEN;
+ info->xmit_fifo_size = 1;
+ uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;
+ (void)uart->urx.w;
+
+ /*
+ * Finally, enable sequencing and interrupts
+ */
+#ifdef USE_INTS
+ uart->ustcnt = USTCNT_UEN | USTCNT_RXEN |
+ USTCNT_RX_INTR_MASK | USTCNT_TX_INTR_MASK;
+#else
+ uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;
+#endif
+
+ if (info->tty)
+ clear_bit(TTY_IO_ERROR, &info->tty->flags);
+ info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
+
+ /*
+ * and set the speed of the serial port
+ */
+
+ change_speed(info);
+
+ info->flags |= S_INITIALIZED;
+ restore_flags(flags);
+ return 0;
+}
+
+/*
+ * 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 m68k_serial * info)
+{
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+
+ uart->ustcnt = 0; /* All off! */
+ if (!(info->flags & S_INITIALIZED))
+ return;
+
+ save_flags(flags); cli(); /* Disable interrupts */
+
+ if (info->xmit_buf) {
+ free_page((unsigned long) info->xmit_buf);
+ info->xmit_buf = 0;
+ }
+
+ if (info->tty)
+ set_bit(TTY_IO_ERROR, &info->tty->flags);
+
+ info->flags &= ~S_INITIALIZED;
+ restore_flags(flags);
+}
+
+struct {
+ int divisor, prescale;
+}
+#ifndef CONFIG_M68VZ328
+ hw_baud_table[18] = {
+ {0,0}, /* 0 */
+ {0,0}, /* 50 */
+ {0,0}, /* 75 */
+ {0,0}, /* 110 */
+ {0,0}, /* 134 */
+ {0,0}, /* 150 */
+ {0,0}, /* 200 */
+ {7,0x26}, /* 300 */
+ {6,0x26}, /* 600 */
+ {5,0x26}, /* 1200 */
+ {0,0}, /* 1800 */
+ {4,0x26}, /* 2400 */
+ {3,0x26}, /* 4800 */
+ {2,0x26}, /* 9600 */
+ {1,0x26}, /* 19200 */
+ {0,0x26}, /* 38400 */
+ {1,0x38}, /* 57600 */
+ {0,0x38}, /* 115200 */
+};
+#else
+ hw_baud_table[18] = {
+ {0,0}, /* 0 */
+ {0,0}, /* 50 */
+ {0,0}, /* 75 */
+ {0,0}, /* 110 */
+ {0,0}, /* 134 */
+ {0,0}, /* 150 */
+ {0,0}, /* 200 */
+ {0,0}, /* 300 */
+ {7,0x26}, /* 600 */
+ {6,0x26}, /* 1200 */
+ {0,0}, /* 1800 */
+ {5,0x26}, /* 2400 */
+ {4,0x26}, /* 4800 */
+ {3,0x26}, /* 9600 */
+ {2,0x26}, /* 19200 */
+ {1,0x26}, /* 38400 */
+ {0,0x26}, /* 57600 */
+ {1,0x38}, /* 115200 */
+};
+#endif
+/* rate = 1036800 / ((65 - prescale) * (1<<divider)) */
+
+/*
+ * 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 m68k_serial *info)
+{
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned short port;
+ unsigned short ustcnt;
+ unsigned cflag;
+ int i;
+
+ if (!info->tty || !info->tty->termios)
+ return;
+ cflag = info->tty->termios->c_cflag;
+ if (!(port = info->port))
+ return;
+
+ ustcnt = uart->ustcnt;
+ uart->ustcnt = ustcnt & ~USTCNT_TXEN;
+
+ i = cflag & CBAUD;
+ if (i & CBAUDEX) {
+ i = (i & ~CBAUDEX) + B38400;
+ }
+
+ info->baud = baud_table[i];
+ uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
+ PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
+
+ ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);
+
+ if ((cflag & CSIZE) == CS8)
+ ustcnt |= USTCNT_8_7;
+
+ if (cflag & CSTOPB)
+ ustcnt |= USTCNT_STOP;
+
+ if (cflag & PARENB)
+ ustcnt |= USTCNT_PARITYEN;
+ if (cflag & PARODD)
+ ustcnt |= USTCNT_ODD_EVEN;
+
+#ifdef CONFIG_SERIAL_68328_RTS_CTS
+ if (cflag & CRTSCTS) {
+ uart->utx.w &= ~ UTX_NOCTS;
+ } else {
+ uart->utx.w |= UTX_NOCTS;
+ }
+#endif
+
+ ustcnt |= USTCNT_TXEN;
+
+ uart->ustcnt = ustcnt;
+ return;
+}
+
+/*
+ * Fair output driver allows a process to speak.
+ */
+static void rs_fair_output(void)
+{
+ int left; /* Output no more than that */
+ unsigned long flags;
+ struct m68k_serial *info = &m68k_soft[0];
+ char c;
+
+ if (info == 0) return;
+ if (info->xmit_buf == 0) return;
+
+ save_flags(flags); cli();
+ left = info->xmit_cnt;
+ while (left != 0) {
+ c = info->xmit_buf[info->xmit_tail];
+ info->xmit_tail = (info->xmit_tail+1) & (SERIAL_XMIT_SIZE-1);
+ info->xmit_cnt--;
+ restore_flags(flags);
+
+ rs_put_char(c);
+
+ save_flags(flags); cli();
+ left = min(info->xmit_cnt, left-1);
+ }
+
+ /* Last character is being transmitted now (hopefully). */
+ udelay(5);
+
+ restore_flags(flags);
+ return;
+}
+
+/*
+ * m68k_console_print is registered for printk.
+ */
+void console_print_68328(const char *p)
+{
+ char c;
+
+ while((c=*(p++)) != 0) {
+ if(c == '\n')
+ rs_put_char('\r');
+ rs_put_char(c);
+ }
+
+ /* Comment this if you want to have a strict interrupt-driven output */
+ rs_fair_output();
+
+ return;
+}
+
+static void rs_set_ldisc(struct tty_struct *tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_set_ldisc"))
+ return;
+
+ info->is_cons = (tty->termios->c_line == N_TTY);
+
+ printk("ttyS%d console mode %s\n", info->line, info->is_cons ? "on" : "off");
+}
+
+static void rs_flush_chars(struct tty_struct *tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
+ return;
+#ifndef USE_INTS
+ for(;;) {
+#endif
+
+ /* Enable transmitter */
+ save_flags(flags); cli();
+
+ if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
+ !info->xmit_buf) {
+ restore_flags(flags);
+ return;
+ }
+
+#ifdef USE_INTS
+ uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
+#else
+ uart->ustcnt |= USTCNT_TXEN;
+#endif
+
+#ifdef USE_INTS
+ if (uart->utx.w & UTX_TX_AVAIL) {
+#else
+ if (1) {
+#endif
+ /* Send char */
+ uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
+ info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
+ info->xmit_cnt--;
+ }
+
+#ifndef USE_INTS
+ while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5);
+ }
+#endif
+ restore_flags(flags);
+}
+
+extern void console_printn(const char * b, int count);
+
+static int rs_write(struct tty_struct * tty, int from_user,
+ const unsigned char *buf, int count)
+{
+ int c, total = 0;
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "rs_write"))
+ return 0;
+
+ if (!tty || !info->xmit_buf)
+ return 0;
+
+ save_flags(flags);
+ while (1) {
+ cli();
+ c = min(count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
+ SERIAL_XMIT_SIZE - info->xmit_head));
+ if (c <= 0)
+ break;
+
+ if (from_user) {
+ down(&tmp_buf_sem);
+ copy_from_user(tmp_buf, buf, c);
+ c = min(c, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
+ SERIAL_XMIT_SIZE - info->xmit_head));
+ memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
+ up(&tmp_buf_sem);
+ } else
+ memcpy(info->xmit_buf + info->xmit_head, buf, c);
+ info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
+ info->xmit_cnt += c;
+ restore_flags(flags);
+ buf += c;
+ count -= c;
+ total += c;
+ }
+
+ if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
+ /* Enable transmitter */
+ cli();
+#ifndef USE_INTS
+ while(info->xmit_cnt) {
+#endif
+
+ uart->ustcnt |= USTCNT_TXEN;
+#ifdef USE_INTS
+ uart->ustcnt |= USTCNT_TX_INTR_MASK;
+#else
+ while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5);
+#endif
+ if (uart->utx.w & UTX_TX_AVAIL) {
+ uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
+ info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
+ info->xmit_cnt--;
+ }
+
+#ifndef USE_INTS
+ }
+#endif
+ restore_flags(flags);
+ }
+ restore_flags(flags);
+ return total;
+}
+
+static int rs_write_room(struct tty_struct *tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+ int ret;
+
+ if (serial_paranoia_check(info, tty->device, "rs_write_room"))
+ return 0;
+ ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
+ if (ret < 0)
+ ret = 0;
+ return ret;
+}
+
+static int rs_chars_in_buffer(struct tty_struct *tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
+ return 0;
+ return info->xmit_cnt;
+}
+
+static void rs_flush_buffer(struct tty_struct *tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
+ return;
+ cli();
+ info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
+ sti();
+ wake_up_interruptible(&tty->write_wait);
+ if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+ tty->ldisc.write_wakeup)
+ (tty->ldisc.write_wakeup)(tty);
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_throttle()
+ *
+ * This routine is called by the upper-layer tty layer to signal that
+ * incoming characters should be throttled.
+ * ------------------------------------------------------------
+ */
+static void rs_throttle(struct tty_struct * tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_throttle"))
+ return;
+
+ if (I_IXOFF(tty))
+ info->x_char = STOP_CHAR(tty);
+
+ /* Turn off RTS line (do this atomic) */
+}
+
+static void rs_unthrottle(struct tty_struct * tty)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
+ return;
+
+ if (I_IXOFF(tty)) {
+ if (info->x_char)
+ info->x_char = 0;
+ else
+ info->x_char = START_CHAR(tty);
+ }
+
+ /* Assert RTS line (do this atomic) */
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_ioctl() and friends
+ * ------------------------------------------------------------
+ */
+
+static int get_serial_info(struct m68k_serial * info,
+ struct serial_struct * retinfo)
+{
+ struct serial_struct tmp;
+
+ if (!retinfo)
+ return -EFAULT;
+ memset(&tmp, 0, sizeof(tmp));
+ tmp.type = info->type;
+ tmp.line = info->line;
+ tmp.port = info->port;
+ tmp.irq = info->irq;
+ tmp.flags = info->flags;
+ tmp.baud_base = info->baud_base;
+ tmp.close_delay = info->close_delay;
+ tmp.closing_wait = info->closing_wait;
+ tmp.custom_divisor = info->custom_divisor;
+ copy_to_user(retinfo,&tmp,sizeof(*retinfo));
+ return 0;
+}
+
+static int set_serial_info(struct m68k_serial * info,
+ struct serial_struct * new_info)
+{
+ struct serial_struct new_serial;
+ struct m68k_serial old_info;
+ int retval = 0;
+
+ if (!new_info)
+ return -EFAULT;
+ copy_from_user(&new_serial,new_info,sizeof(new_serial));
+ old_info = *info;
+
+ if (!capable(CAP_SYS_ADMIN)) {
+ if ((new_serial.baud_base != info->baud_base) ||
+ (new_serial.type != info->type) ||
+ (new_serial.close_delay != info->close_delay) ||
+ ((new_serial.flags & ~S_USR_MASK) !=
+ (info->flags & ~S_USR_MASK)))
+ return -EPERM;
+ info->flags = ((info->flags & ~S_USR_MASK) |
+ (new_serial.flags & S_USR_MASK));
+ info->custom_divisor = new_serial.custom_divisor;
+ goto check_and_exit;
+ }
+
+ if (info->count > 1)
+ return -EBUSY;
+
+ /*
+ * OK, past this point, all the error checking has been done.
+ * At this point, we start making changes.....
+ */
+
+ info->baud_base = new_serial.baud_base;
+ info->flags = ((info->flags & ~S_FLAGS) |
+ (new_serial.flags & S_FLAGS));
+ info->type = new_serial.type;
+ info->close_delay = new_serial.close_delay;
+ info->closing_wait = new_serial.closing_wait;
+
+check_and_exit:
+ retval = startup(info);
+ return retval;
+}
+
+/*
+ * get_lsr_info - get line status register info
+ *
+ * Purpose: Let user call ioctl() to get info when the UART physically
+ * is emptied. On bus types like RS485, the transmitter must
+ * release the bus after transmitting. This must be done when
+ * the transmit shift register is empty, not be done when the
+ * transmit holding register is empty. This functionality
+ * allows an RS485 driver to be written in user space.
+ */
+static int get_lsr_info(struct m68k_serial * info, unsigned int *value)
+{
+#ifdef CONFIG_SERIAL_68328_RTS_CTS
+ m68328_uart *uart = &uart_addr[info->line];
+#endif
+ unsigned char status;
+
+ cli();
+#ifdef CONFIG_SERIAL_68328_RTS_CTS
+ status = (uart->utx.w & UTX_CTS_STAT) ? 1 : 0;
+#else
+ status = 0;
+#endif
+ sti();
+ put_user(status,value);
+ return 0;
+}
+
+/*
+ * This routine sends a break character out the serial port.
+ */
+static void send_break( struct m68k_serial * info, int duration)
+{
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+ if (!info->port)
+ return;
+ current->state = TASK_INTERRUPTIBLE;
+ save_flags(flags);
+ cli();
+#ifdef USE_INTS
+ uart->utx.w |= UTX_SEND_BREAK;
+ schedule_timeout(duration);
+ uart->utx.w &= ~UTX_SEND_BREAK;
+#endif
+ restore_flags(flags);
+}
+
+static int rs_ioctl(struct tty_struct *tty, struct file * file,
+ unsigned int cmd, unsigned long arg)
+{
+ int error;
+ struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
+ int retval;
+
+ if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
+ return -ENODEV;
+
+ if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
+ (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
+ (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
+ if (tty->flags & (1 << TTY_IO_ERROR))
+ return -EIO;
+ }
+
+ switch (cmd) {
+ case TCSBRK: /* SVID version: non-zero arg --> no break */
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ tty_wait_until_sent(tty, 0);
+ if (!arg)
+ send_break(info, HZ/4); /* 1/4 second */
+ return 0;
+ case TCSBRKP: /* support for POSIX tcsendbreak() */
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ tty_wait_until_sent(tty, 0);
+ send_break(info, arg ? arg*(HZ/10) : HZ/4);
+ return 0;
+ case TIOCGSOFTCAR:
+ error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
+ if (error)
+ return error;
+ put_user(C_CLOCAL(tty) ? 1 : 0,
+ (unsigned long *) arg);
+ return 0;
+ case TIOCSSOFTCAR:
+ get_user(arg, (unsigned long *) arg);
+ tty->termios->c_cflag =
+ ((tty->termios->c_cflag & ~CLOCAL) |
+ (arg ? CLOCAL : 0));
+ return 0;
+ case TIOCGSERIAL:
+ error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(struct serial_struct));
+ if (error)
+ return error;
+ return get_serial_info(info,
+ (struct serial_struct *) arg);
+ case TIOCSSERIAL:
+ return set_serial_info(info,
+ (struct serial_struct *) arg);
+ case TIOCSERGETLSR: /* Get line status register */
+ error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(unsigned int));
+ if (error)
+ return error;
+ else
+ return get_lsr_info(info, (unsigned int *) arg);
+
+ case TIOCSERGSTRUCT:
+ error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(struct m68k_serial));
+ if (error)
+ return error;
+ copy_to_user((struct m68k_serial *) arg,
+ info, sizeof(struct m68k_serial));
+ return 0;
+
+ default:
+ return -ENOIOCTLCMD;
+ }
+ return 0;
+}
+
+static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
+{
+ struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
+
+ if (tty->termios->c_cflag == old_termios->c_cflag)
+ return;
+
+ change_speed(info);
+
+ if ((old_termios->c_cflag & CRTSCTS) &&
+ !(tty->termios->c_cflag & CRTSCTS)) {
+ tty->hw_stopped = 0;
+ rs_start(tty);
+ }
+
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_close()
+ *
+ * This routine is called when the serial port gets closed. First, we
+ * wait for the last remaining data to be sent. Then, we unlink its
+ * S structure from the interrupt chain if necessary, and we free
+ * that IRQ if nothing is left in the chain.
+ * ------------------------------------------------------------
+ */
+static void rs_close(struct tty_struct *tty, struct file * filp)
+{
+ struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
+ m68328_uart *uart = &uart_addr[info->line];
+ unsigned long flags;
+
+ if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
+ return;
+
+ save_flags(flags); cli();
+
+ if (tty_hung_up_p(filp)) {
+ restore_flags(flags);
+ return;
+ }
+
+ 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("rs_close: bad serial port count; tty->count is 1, "
+ "info->count is %d\n", info->count);
+ info->count = 1;
+ }
+ if (--info->count < 0) {
+ printk("rs_close: bad serial port count for ttyS%d: %d\n",
+ info->line, info->count);
+ info->count = 0;
+ }
+ if (info->count) {
+ restore_flags(flags);
+ return;
+ }
+ info->flags |= S_CLOSING;
+ /*
+ * Save the termios structure, since this port may have
+ * separate termios for callout and dialin.
+ */
+ if (info->flags & S_NORMAL_ACTIVE)
+ info->normal_termios = *tty->termios;
+ if (info->flags & S_CALLOUT_ACTIVE)
+ info->callout_termios = *tty->termios;
+ /*
+ * Now we wait for the transmit buffer to clear; and we notify
+ * the line discipline to only process XON/XOFF characters.
+ */
+ tty->closing = 1;
+ if (info->closing_wait != S_CLOSING_WAIT_NONE)
+ tty_wait_until_sent(tty, info->closing_wait);
+ /*
+ * At this point we stop accepting input. To do this, we
+ * disable the receive line status interrupts, and tell the
+ * interrupt driver to stop checking the data ready bit in the
+ * line status register.
+ */
+
+ uart->ustcnt &= ~USTCNT_RXEN;
+ uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
+
+ shutdown(info);
+ if (tty->driver.flush_buffer)
+ tty->driver.flush_buffer(tty);
+ if (tty->ldisc.flush_buffer)
+ tty->ldisc.flush_buffer(tty);
+ tty->closing = 0;
+ info->event = 0;
+ info->tty = 0;
+ if (tty->ldisc.num != ldiscs[N_TTY].num) {
+ if (tty->ldisc.close)
+ (tty->ldisc.close)(tty);
+ tty->ldisc = ldiscs[N_TTY];
+ tty->termios->c_line = N_TTY;
+ if (tty->ldisc.open)
+ (tty->ldisc.open)(tty);
+ }
+ if (info->blocked_open) {
+ if (info->close_delay) {
+ current->state = TASK_INTERRUPTIBLE;
+ schedule_timeout(info->close_delay);
+ }
+ wake_up_interruptible(&info->open_wait);
+ }
+ info->flags &= ~(S_NORMAL_ACTIVE|S_CALLOUT_ACTIVE|
+ S_CLOSING);
+ wake_up_interruptible(&info->close_wait);
+ restore_flags(flags);
+}
+
+/*
+ * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
+ */
+void rs_hangup(struct tty_struct *tty)
+{
+ struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_hangup"))
+ return;
+
+ rs_flush_buffer(tty);
+ shutdown(info);
+ info->event = 0;
+ info->count = 0;
+ info->flags &= ~(S_NORMAL_ACTIVE|S_CALLOUT_ACTIVE);
+ info->tty = 0;
+ wake_up_interruptible(&info->open_wait);
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_open() and friends
+ * ------------------------------------------------------------
+ */
+static int block_til_ready(struct tty_struct *tty, struct file * filp,
+ struct m68k_serial *info)
+{
+ DECLARE_WAITQUEUE(wait, current);
+ int retval;
+ int do_clocal = 0;
+
+ /*
+ * If the device is in the middle of being closed, then block
+ * until it's done, and then try again.
+ */
+ if (info->flags & S_CLOSING) {
+ interruptible_sleep_on(&info->close_wait);
+#ifdef SERIAL_DO_RESTART
+ if (info->flags & S_HUP_NOTIFY)
+ return -EAGAIN;
+ else
+ return -ERESTARTSYS;
+#else
+ return -EAGAIN;
+#endif
+ }
+
+ /*
+ * If this is a callout device, then just make sure the normal
+ * device isn't being used.
+ */
+ if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
+ if (info->flags & S_NORMAL_ACTIVE)
+ return -EBUSY;
+ if ((info->flags & S_CALLOUT_ACTIVE) &&
+ (info->flags & S_SESSION_LOCKOUT) &&
+ (info->session != current->session))
+ return -EBUSY;
+ if ((info->flags & S_CALLOUT_ACTIVE) &&
+ (info->flags & S_PGRP_LOCKOUT) &&
+ (info->pgrp != current->pgrp))
+ return -EBUSY;
+ info->flags |= S_CALLOUT_ACTIVE;
+ return 0;
+ }
+
+ /*
+ * If non-blocking mode is set, or the port is not enabled,
+ * then make the check up front and then exit.
+ */
+ if ((filp->f_flags & O_NONBLOCK) ||
+ (tty->flags & (1 << TTY_IO_ERROR))) {
+ if (info->flags & S_CALLOUT_ACTIVE)
+ return -EBUSY;
+ info->flags |= S_NORMAL_ACTIVE;
+ return 0;
+ }
+
+ if (info->flags & S_CALLOUT_ACTIVE) {
+ if (info->normal_termios.c_cflag & CLOCAL)
+ do_clocal = 1;
+ } else {
+ if (tty->termios->c_cflag & CLOCAL)
+ do_clocal = 1;
+ }
+
+ /*
+ * 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
+ * rs_close() knows when to free things. We restore it upon
+ * exit, either normal or abnormal.
+ */
+ retval = 0;
+ add_wait_queue(&info->open_wait, &wait);
+
+ info->count--;
+ info->blocked_open++;
+ while (1) {
+ cli();
+ if (!(info->flags & S_CALLOUT_ACTIVE))
+ m68k_rtsdtr(info, 1);
+ sti();
+ current->state = TASK_INTERRUPTIBLE;
+ if (tty_hung_up_p(filp) ||
+ !(info->flags & S_INITIALIZED)) {
+#ifdef SERIAL_DO_RESTART
+ if (info->flags & S_HUP_NOTIFY)
+ retval = -EAGAIN;
+ else
+ retval = -ERESTARTSYS;
+#else
+ retval = -EAGAIN;
+#endif
+ break;
+ }
+ if (!(info->flags & S_CALLOUT_ACTIVE) &&
+ !(info->flags & S_CLOSING) && do_clocal)
+ break;
+ if (signal_pending(current)) {
+ retval = -ERESTARTSYS;
+ break;
+ }
+ schedule();
+ }
+ current->state = TASK_RUNNING;
+ remove_wait_queue(&info->open_wait, &wait);
+ if (!tty_hung_up_p(filp))
+ info->count++;
+ info->blocked_open--;
+
+ if (retval)
+ return retval;
+ info->flags |= S_NORMAL_ACTIVE;
+ return 0;
+}
+
+/*
+ * This routine is called whenever a serial port is opened. It
+ * enables interrupts for a serial port, linking in its S structure into
+ * the IRQ chain. It also performs the serial-specific
+ * initialization for the tty structure.
+ */
+int rs_open(struct tty_struct *tty, struct file * filp)
+{
+ struct m68k_serial *info;
+ int retval, line;
+
+ line = minor(tty->device) - tty->driver.minor_start;
+
+ if (line >= NR_PORTS || line < 0) /* we have exactly one */
+ return -ENODEV;
+
+ info = &m68k_soft[line];
+
+ if (serial_paranoia_check(info, tty->device, "rs_open"))
+ return -ENODEV;
+
+ info->count++;
+ 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) {
+ return retval;
+ }
+
+ if ((info->count == 1) && (info->flags & S_SPLIT_TERMIOS)) {
+ if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
+ *tty->termios = info->normal_termios;
+ else
+ *tty->termios = info->callout_termios;
+ change_speed(info);
+ }
+
+ info->session = current->session;
+ info->pgrp = current->pgrp;
+
+ return 0;
+}
+
+/* Finally, routines used to initialize the serial driver. */
+
+static void show_serial_version(void)
+{
+ printk("MC68328 serial driver version 1.00\n");
+}
+
+#ifdef CONFIG_PM
+/* Serial Power management
+ * The console (currently fixed at line 0) is a special case for power
+ * management because the kernel is so chatty. The console will be
+ * explicitly disabled my our power manager as the last minute, so we won't
+ * mess with it here.
+ */
+static struct pm_dev *serial_pm[NR_PORTS];
+
+static int serial_pm_callback(struct pm_dev *dev, pm_request_t request, void *data)
+{
+ struct m68k_serial *info = (struct m68k_serial *)dev->data;
+
+ if(info == NULL)
+ return -1;
+
+ /* special case for line 0 - pm restores it */
+ if(info->line == 0)
+ return 0;
+
+ switch (request) {
+ case PM_SUSPEND:
+ shutdown(info);
+ break;
+
+ case PM_RESUME:
+ startup(info);
+ break;
+ }
+ return 0;
+}
+
+void shutdown_console(void)
+{
+ struct m68k_serial *info = &m68k_soft[0];
+
+ /* HACK: wait a bit for any pending printk's to be dumped */
+ {
+ int i = 10000;
+ while(i--);
+ }
+
+ shutdown(info);
+}
+
+void startup_console(void)
+{
+ struct m68k_serial *info = &m68k_soft[0];
+ startup(info);
+}
+#endif
+
+
+/* rs_init inits the driver */
+static int __init
+rs68328_init(void)
+{
+ int flags, i;
+ struct m68k_serial *info;
+
+ show_serial_version();
+
+ /* Initialize the tty_driver structure */
+ /* SPARC: Not all of this is exactly right for us. */
+
+ memset(&serial_driver, 0, sizeof(struct tty_driver));
+ serial_driver.magic = TTY_DRIVER_MAGIC;
+ serial_driver.name = "ttyS";
+ serial_driver.major = TTY_MAJOR;
+ serial_driver.minor_start = 64;
+ serial_driver.num = NR_PORTS;
+ serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
+ serial_driver.subtype = SERIAL_TYPE_NORMAL;
+ serial_driver.init_termios = tty_std_termios;
+ serial_driver.init_termios.c_cflag =
+ m68328_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
+ serial_driver.flags = TTY_DRIVER_REAL_RAW;
+ serial_driver.refcount = &serial_refcount;
+ serial_driver.table = serial_table;
+ serial_driver.termios = serial_termios;
+ serial_driver.termios_locked = serial_termios_locked;
+
+ serial_driver.open = rs_open;
+ serial_driver.close = rs_close;
+ serial_driver.write = rs_write;
+ serial_driver.flush_chars = rs_flush_chars;
+ serial_driver.write_room = rs_write_room;
+ serial_driver.chars_in_buffer = rs_chars_in_buffer;
+ serial_driver.flush_buffer = rs_flush_buffer;
+ serial_driver.ioctl = rs_ioctl;
+ serial_driver.throttle = rs_throttle;
+ serial_driver.unthrottle = rs_unthrottle;
+ serial_driver.set_termios = rs_set_termios;
+ serial_driver.stop = rs_stop;
+ serial_driver.start = rs_start;
+ serial_driver.hangup = rs_hangup;
+ serial_driver.set_ldisc = rs_set_ldisc;
+
+ /*
+ * The callout device is just like normal device except for
+ * major number and the subtype code.
+ */
+ callout_driver = serial_driver;
+ callout_driver.name = "cua";
+ callout_driver.major = TTYAUX_MAJOR;
+ callout_driver.subtype = SERIAL_TYPE_CALLOUT;
+
+ if (tty_register_driver(&serial_driver))
+ panic("Couldn't register serial driver\n");
+ if (tty_register_driver(&callout_driver))
+ panic("Couldn't register callout driver\n");
+
+ save_flags(flags); cli();
+
+ for(i=0;i<NR_PORTS;i++) {
+
+ info = &m68k_soft[i];
+ info->magic = SERIAL_MAGIC;
+ info->port = (int) &uart_addr[i];
+ info->tty = 0;
+ info->irq = uart_irqs[i];
+ info->custom_divisor = 16;
+ info->close_delay = 50;
+ info->closing_wait = 3000;
+ info->x_char = 0;
+ info->event = 0;
+ info->count = 0;
+ info->blocked_open = 0;
+ INIT_WORK(&info->tqueue, do_softint, info);
+ INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
+ info->callout_termios =callout_driver.init_termios;
+ info->normal_termios = serial_driver.init_termios;
+ init_waitqueue_head(&info->open_wait);
+ init_waitqueue_head(&info->close_wait);
+ info->line = i;
+ info->is_cons = 1; /* Means shortcuts work */
+
+ printk("%s%d at 0x%08x (irq = %d)", serial_driver.name, info->line,
+ info->port, info->irq);
+ printk(" is a builtin MC68328 UART\n");
+
+ IRQ_ports[info->irq] = info; /* waste of space */
+
+#ifdef CONFIG_M68VZ328
+ if (i > 0 )
+ PJSEL &= 0xCF; /* PSW enable second port output */
+#endif
+
+ if (request_irq(uart_irqs[i],
+ rs_interrupt,
+ IRQ_FLG_STD,
+ "M68328_UART", NULL))
+ panic("Unable to attach 68328 serial interrupt\n");
+#ifdef CONFIG_PM
+ serial_pm[i] = pm_register(PM_SYS_DEV, PM_SYS_COM, serial_pm_callback);
+ if (serial_pm[i])
+ serial_pm[i]->data = info;
+#endif
+ }
+ restore_flags(flags);
+ return 0;
+}
+
+
+
+/*
+ * register_serial and unregister_serial allows for serial ports to be
+ * configured at run-time, to support PCMCIA modems.
+ */
+/* SPARC: Unused at this time, just here to make things link. */
+int register_serial(struct serial_struct *req)
+{
+ return -1;
+}
+
+void unregister_serial(int line)
+{
+ return;
+}
+
+module_init(rs68328_init);
+/* DAVIDM module_exit(rs68328_fini); */
+
+
+
+static void m68328_set_baud(void)
+{
+ unsigned short ustcnt;
+ int i;
+
+ ustcnt = USTCNT;
+ USTCNT = ustcnt & ~USTCNT_TXEN;
+
+again:
+ for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++)
+ if (baud_table[i] == m68328_console_baud)
+ break;
+ if (i >= sizeof(baud_table) / sizeof(baud_table[0])) {
+ m68328_console_baud = 9600;
+ goto again;
+ }
+
+ UBAUD = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
+ PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
+ ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);
+ ustcnt |= USTCNT_8_7;
+ ustcnt |= USTCNT_TXEN;
+ USTCNT = ustcnt;
+ m68328_console_initted = 1;
+ return;
+}
+
+
+int m68328_console_setup(struct console *cp, char *arg)
+{
+ int i, n = CONSOLE_BAUD_RATE;
+
+ if (!cp)
+ return(-1);
+
+ if (arg)
+ n = simple_strtoul(arg,NULL,0);
+
+ for (i = 0; i < BAUD_TABLE_SIZE; i++)
+ if (baud_table[i] == n)
+ break;
+ if (i < BAUD_TABLE_SIZE) {
+ m68328_console_baud = n;
+ m68328_console_cbaud = 0;
+ if (i > 15) {
+ m68328_console_cbaud |= CBAUDEX;
+ i -= 15;
+ }
+ m68328_console_cbaud |= i;
+ }
+
+ m68328_set_baud(); /* make sure baud rate changes */
+ return(0);
+}
+
+
+static kdev_t m68328_console_device(struct console *c)
+{
+ return mk_kdev(TTY_MAJOR, 64 + c->index);
+}
+
+
+void m68328_console_write (struct console *co, const char *str,
+ unsigned int count)
+{
+ if (!m68328_console_initted)
+ m68328_set_baud();
+ while (count--) {
+ if (*str == '\n')
+ rs_put_char('\r');
+ rs_put_char( *str++ );
+ }
+}
+
+
+static struct console m68328_driver = {
+ name: "ttyS",
+ write: m68328_console_write,
+ device: m68328_console_device,
+ setup: m68328_console_setup,
+ flags: CON_PRINTBUFFER,
+ index: -1,
+};
+
+
+void m68328_console_init(void)
+{
+ register_console(&m68328_driver);
+}
+
--- /dev/null
+/* 68328serial.h: Definitions for the mc68328 serial driver.
+ *
+ * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>
+ * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
+ * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>
+ * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>
+ *
+ * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca>
+ */
+
+#ifndef _MC683XX_SERIAL_H
+#define _MC683XX_SERIAL_H
+
+#include <linux/config.h>
+
+struct serial_struct {
+ int type;
+ int line;
+ int port;
+ int irq;
+ int flags;
+ int xmit_fifo_size;
+ int custom_divisor;
+ int baud_base;
+ unsigned short close_delay;
+ char reserved_char[2];
+ int hub6; /* FIXME: We don't have AT&T Hub6 boards! */
+ unsigned short closing_wait; /* time to wait before closing */
+ unsigned short closing_wait2; /* no longer used... */
+ int reserved[4];
+};
+
+/*
+ * For the close wait times, 0 means wait forever for serial port to
+ * flush its output. 65535 means don't wait at all.
+ */
+#define S_CLOSING_WAIT_INF 0
+#define S_CLOSING_WAIT_NONE 65535
+
+/*
+ * Definitions for S_struct (and serial_struct) flags field
+ */
+#define S_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes
+ on the callout port */
+#define S_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */
+#define S_SAK 0x0004 /* Secure Attention Key (Orange book) */
+#define S_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
+
+#define S_SPD_MASK 0x0030
+#define S_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */
+
+#define S_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */
+#define S_SPD_CUST 0x0030 /* Use user-specified divisor */
+
+#define S_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
+#define S_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */
+#define S_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
+#define S_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
+#define S_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */
+
+#define S_FLAGS 0x0FFF /* Possible legal S flags */
+#define S_USR_MASK 0x0430 /* Legal flags that non-privileged
+ * users can set or reset */
+
+/* Internal flags used only by kernel/chr_drv/serial.c */
+#define S_INITIALIZED 0x80000000 /* Serial port was initialized */
+#define S_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
+#define S_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
+#define S_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
+#define S_CLOSING 0x08000000 /* Serial port is closing */
+#define S_CTS_FLOW 0x04000000 /* Do CTS flow control */
+#define S_CHECK_CD 0x02000000 /* i.e., CLOCAL */
+
+/* Software state per channel */
+
+#ifdef __KERNEL__
+
+/*
+ * I believe this is the optimal setting that reduces the number of interrupts.
+ * At high speeds the output might become a little "bursted" (use USTCNT_TXHE
+ * if that bothers you), but in most cases it will not, since we try to
+ * transmit characters every time rs_interrupt is called. Thus, quite often
+ * you'll see that a receive interrupt occures before the transmit one.
+ * -- Vladimir Gurevich
+ */
+#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)
+
+/*
+ * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special
+ * "Old data interrupt" which occures whenever the data stay in the FIFO
+ * longer than 30 bits time. This allows us to use FIFO without compromising
+ * latency. '328 does not have this feature and without the real 328-based
+ * board I would assume that RXRE is the safest setting.
+ *
+ * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of
+ * interrupts. RXFE (receive queue full) causes the system to loose data
+ * at least at 115200 baud
+ *
+ * If your board is busy doing other stuff, you might consider to use
+ * RXRE (data ready intrrupt) instead.
+ *
+ * The other option is to make these INTR masks run-time configurable, so
+ * that people can dynamically adapt them according to the current usage.
+ * -- Vladimir Gurevich
+ */
+
+/* (es) */
+#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)
+#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)
+#elif defined(CONFIG_M68328)
+#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)
+#else
+#error Please, define the Rx interrupt events for your CPU
+#endif
+/* (/es) */
+
+/*
+ * This is our internal structure for each serial port's state.
+ *
+ * Many fields are paralleled by the structure used by the serial_struct
+ * structure.
+ *
+ * For definitions of the flags field, see tty.h
+ */
+
+struct m68k_serial {
+ char soft_carrier; /* Use soft carrier on this channel */
+ char break_abort; /* Is serial console in, so process brk/abrt */
+ char is_cons; /* Is this our console. */
+
+ /* We need to know the current clock divisor
+ * to read the bps rate the chip has currently
+ * loaded.
+ */
+ unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */
+ int baud;
+ int magic;
+ int baud_base;
+ int port;
+ int irq;
+ int flags; /* defined in tty.h */
+ int type; /* UART type */
+ struct tty_struct *tty;
+ int read_status_mask;
+ int ignore_status_mask;
+ int timeout;
+ int xmit_fifo_size;
+ int custom_divisor;
+ int x_char; /* xon/xoff character */
+ int close_delay;
+ unsigned short closing_wait;
+ unsigned short closing_wait2;
+ unsigned long event;
+ unsigned long last_active;
+ int line;
+ int count; /* # of fd on device */
+ int blocked_open; /* # of blocked opens */
+ long session; /* Session of opening process */
+ long pgrp; /* pgrp of opening process */
+ unsigned char *xmit_buf;
+ int xmit_head;
+ int xmit_tail;
+ int xmit_cnt;
+ struct workqueue tqueue;
+ struct workqueue tqueue_hangup;
+ struct termios normal_termios;
+ struct termios callout_termios;
+ wait_queue_head_t open_wait;
+ wait_queue_head_t close_wait;
+};
+
+
+#define SERIAL_MAGIC 0x5301
+
+/*
+ * The size of the serial xmit buffer is 1 page, or 4096 bytes
+ */
+#define SERIAL_XMIT_SIZE 4096
+
+/*
+ * Events are used to schedule things to happen at timer-interrupt
+ * time, instead of at rs interrupt time.
+ */
+#define RS_EVENT_WRITE_WAKEUP 0
+
+/*
+ * Define the number of ports supported and their irqs.
+ */
+#ifndef CONFIG_68328_SERIAL_UART2
+#define NR_PORTS 1
+#define UART_IRQ_DEFNS {UART_IRQ_NUM}
+#else
+#define NR_PORTS 2
+#define UART_IRQ_DEFNS {UART1_IRQ_NUM, UART2_IRQ_NUM}
+#endif
+
+#endif /* __KERNEL__ */
+#endif /* !(_MC683XX_SERIAL_H) */
--- /dev/null
+/*
+ * UART driver for 68360 CPM SCC or SMC
+ * Copyright (c) 2000 D. Jeff Dionne <jeff@uclinux.org>,
+ * Copyright (c) 2000 Michael Leslie <mleslie@lineo.ca>
+ * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
+ *
+ * I used the serial.c driver as the framework for this driver.
+ * Give credit to those guys.
+ * The original code was written for the MBX860 board. I tried to make
+ * it generic, but there may be some assumptions in the structures that
+ * have to be fixed later.
+ * To save porting time, I did not bother to change any object names
+ * that are not accessed outside of this file.
+ * It still needs lots of work........When it was easy, I included code
+ * to support the SCCs, but this has never been tested, nor is it complete.
+ * Only the SCCs support modem control, so that is not complete either.
+ *
+ * This module exports the following rs232 io functions:
+ *
+ * int rs_360_init(void);
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial.h>
+#include <linux/serialP.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/fcntl.h>
+#include <linux/ptrace.h>
+#include <linux/mm.h>
+#include <linux/malloc.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <asm/irq.h>
+#include <linux/compatmac.h>
+#include <asm/m68360.h>
+#include <asm/commproc.h>
+
+
+#ifdef CONFIG_KGDB
+extern void breakpoint(void);
+extern void set_debug_traps(void);
+extern int kgdb_output_string (const char* s, unsigned int count);
+#endif
+
+
+/* #ifdef CONFIG_SERIAL_CONSOLE */ /* This seems to be a post 2.0 thing - mles */
+#include <linux/console.h>
+
+/* this defines the index into rs_table for the port to use
+ */
+#ifndef CONFIG_SERIAL_CONSOLE_PORT
+#define CONFIG_SERIAL_CONSOLE_PORT 1 /* ie SMC2 - note USE_SMC2 must be defined */
+#endif
+/* #endif */
+
+#if 0
+/* SCC2 for console
+ */
+#undef CONFIG_SERIAL_CONSOLE_PORT
+#define CONFIG_SERIAL_CONSOLE_PORT 2
+#endif
+
+
+#define TX_WAKEUP ASYNC_SHARE_IRQ
+
+static char *serial_name = "CPM UART driver";
+static char *serial_version = "0.03";
+
+static DECLARE_TASK_QUEUE(tq_serial);
+
+static struct tty_driver serial_driver, callout_driver;
+static int serial_refcount;
+int serial_console_setup(struct console *co, char *options);
+
+/*
+ * Serial driver configuration section. Here are the various options:
+ */
+#define SERIAL_PARANOIA_CHECK
+#define CONFIG_SERIAL_NOPAUSE_IO
+#define SERIAL_DO_RESTART
+
+/* Set of debugging defines */
+
+#undef SERIAL_DEBUG_INTR
+#undef SERIAL_DEBUG_OPEN
+#undef SERIAL_DEBUG_FLOW
+#undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
+
+#define _INLINE_ inline
+
+#define DBG_CNT(s)
+
+/* We overload some of the items in the data structure to meet our
+ * needs. For example, the port address is the CPM parameter ram
+ * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
+ * 2 SMCs. The "hub6" field is used to indicate the channel number, with
+ * a flag indicating SCC or SMC, and the number is used as an index into
+ * the CPM parameter area for this device.
+ * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
+ * not currently used. I should probably use it to indicate the port
+ * type of SMC or SCC.
+ * The SMCs do not support any modem control signals.
+ */
+#define smc_scc_num hub6
+#define NUM_IS_SCC ((int)0x00010000)
+#define PORT_NUM(P) ((P) & 0x0000ffff)
+
+
+#if defined (CONFIG_UCQUICC)
+
+volatile extern void *_periph_base;
+/* sipex transceiver
+ * mode bits for are on pins
+ *
+ * SCC2 d16..19
+ * SCC3 d20..23
+ * SCC4 d24..27
+ */
+#define SIPEX_MODE(n,m) ((m & 0x0f)<<(16+4*(n-1)))
+
+static uint sipex_mode_bits = 0x00000000;
+
+#endif
+
+/* There is no `serial_state' defined back here in 2.0.
+ * Try to get by with serial_struct
+ */
+/* #define serial_state serial_struct */
+
+/* 2.4 -> 2.0 portability problem: async_icount in 2.4 has a few
+ * extras: */
+
+#if 0
+struct async_icount_24 {
+ __u32 cts, dsr, rng, dcd, tx, rx;
+ __u32 frame, parity, overrun, brk;
+ __u32 buf_overrun;
+} icount;
+#endif
+
+#if 0
+
+struct serial_state {
+ int magic;
+ int baud_base;
+ unsigned long port;
+ int irq;
+ int flags;
+ int hub6;
+ int type;
+ int line;
+ int revision; /* Chip revision (950) */
+ int xmit_fifo_size;
+ int custom_divisor;
+ int count;
+ u8 *iomem_base;
+ u16 iomem_reg_shift;
+ unsigned short close_delay;
+ unsigned short closing_wait; /* time to wait before closing */
+ struct async_icount_24 icount;
+ struct termios normal_termios;
+ struct termios callout_termios;
+ int io_type;
+ struct async_struct *info;
+};
+#endif
+
+#define SSTATE_MAGIC 0x5302
+
+
+
+/* SMC2 is sometimes used for low performance TDM interfaces. Define
+ * this as 1 if you want SMC2 as a serial port UART managed by this driver.
+ * Define this as 0 if you wish to use SMC2 for something else.
+ */
+#define USE_SMC2 1
+
+#if 0
+/* Define SCC to ttySx mapping. */
+#define SCC_NUM_BASE (USE_SMC2 + 1) /* SCC base tty "number" */
+
+/* Define which SCC is the first one to use for a serial port. These
+ * are 0-based numbers, i.e. this assumes the first SCC (SCC1) is used
+ * for Ethernet, and the first available SCC for serial UART is SCC2.
+ * NOTE: IF YOU CHANGE THIS, you have to change the PROFF_xxx and
+ * interrupt vectors in the table below to match.
+ */
+#define SCC_IDX_BASE 1 /* table index */
+#endif
+
+
+/* Processors other than the 860 only get SMCs configured by default.
+ * Either they don't have SCCs or they are allocated somewhere else.
+ * Of course, there are now 860s without some SCCs, so we will need to
+ * address that someday.
+ * The Embedded Planet Multimedia I/O cards use TDM interfaces to the
+ * stereo codec parts, and we use SMC2 to help support that.
+ */
+static struct serial_state rs_table[] = {
+/* type line PORT IRQ FLAGS smc_scc_num (F.K.A. hub6) */
+ { 0, 0, PRSLOT_SMC1, CPMVEC_SMC1, 0, 0 } /* SMC1 ttyS0 */
+#if USE_SMC2
+ ,{ 0, 0, PRSLOT_SMC2, CPMVEC_SMC2, 0, 1 } /* SMC2 ttyS1 */
+#endif
+
+#if defined(CONFIG_SERIAL_68360_SCC)
+ ,{ 0, 0, PRSLOT_SCC2, CPMVEC_SCC2, 0, (NUM_IS_SCC | 1) } /* SCC2 ttyS2 */
+ ,{ 0, 0, PRSLOT_SCC3, CPMVEC_SCC3, 0, (NUM_IS_SCC | 2) } /* SCC3 ttyS3 */
+ ,{ 0, 0, PRSLOT_SCC4, CPMVEC_SCC4, 0, (NUM_IS_SCC | 3) } /* SCC4 ttyS4 */
+#endif
+};
+
+#define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
+
+static struct tty_struct *serial_table[NR_PORTS];
+static struct termios *serial_termios[NR_PORTS];
+static struct termios *serial_termios_locked[NR_PORTS];
+
+/* The number of buffer descriptors and their sizes.
+ */
+#define RX_NUM_FIFO 4
+#define RX_BUF_SIZE 32
+#define TX_NUM_FIFO 4
+#define TX_BUF_SIZE 32
+
+#define CONSOLE_NUM_FIFO 2
+#define CONSOLE_BUF_SIZE 4
+
+char *console_fifos[CONSOLE_NUM_FIFO * CONSOLE_BUF_SIZE];
+
+/* The async_struct in serial.h does not really give us what we
+ * need, so define our own here.
+ */
+typedef struct serial_info {
+ int magic;
+ int flags;
+
+ struct serial_state *state;
+ /* struct serial_struct *state; */
+ /* struct async_struct *state; */
+
+ struct tty_struct *tty;
+ int read_status_mask;
+ int ignore_status_mask;
+ int timeout;
+ int line;
+ int x_char; /* xon/xoff character */
+ int close_delay;
+ unsigned short closing_wait;
+ unsigned short closing_wait2;
+ unsigned long event;
+ unsigned long last_active;
+ int blocked_open; /* # of blocked opens */
+ long session; /* Session of opening process */
+ long pgrp; /* pgrp of opening process */
+ struct tq_struct tqueue;
+ struct tq_struct tqueue_hangup;
+ wait_queue_head_t open_wait;
+ wait_queue_head_t close_wait;
+/* struct wait_queue *open_wait; */
+/* struct wait_queue *close_wait;i */
+
+
+/* CPM Buffer Descriptor pointers.
+ */
+ QUICC_BD *rx_bd_base;
+ QUICC_BD *rx_cur;
+ QUICC_BD *tx_bd_base;
+ QUICC_BD *tx_cur;
+} ser_info_t;
+
+
+/* since kmalloc_init() does not get called until much after this initialization: */
+static ser_info_t quicc_ser_info[NR_PORTS];
+static char rx_buf_pool[NR_PORTS * RX_NUM_FIFO * RX_BUF_SIZE];
+static char tx_buf_pool[NR_PORTS * TX_NUM_FIFO * TX_BUF_SIZE];
+
+static void change_speed(ser_info_t *info);
+static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout);
+
+static inline int serial_paranoia_check(ser_info_t *info,
+ kdev_t device, const char *routine)
+{
+#ifdef SERIAL_PARANOIA_CHECK
+ static const char *badmagic =
+ "Warning: bad magic number for serial struct (%s) in %s\n";
+ static const char *badinfo =
+ "Warning: null async_struct for (%s) in %s\n";
+
+ if (!info) {
+ printk(badinfo, kdevname(device), routine);
+ return 1;
+ }
+ if (info->magic != SERIAL_MAGIC) {
+ printk(badmagic, kdevname(device), routine);
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+/*
+ * This is used to figure out the divisor speeds and the timeouts,
+ * indexed by the termio value. The generic CPM functions are responsible
+ * for setting and assigning baud rate generators for us.
+ */
+static int baud_table[] = {
+ 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
+ 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
+
+/* This sucks. There is a better way: */
+#if defined(CONFIG_CONSOLE_9600)
+ #define CONSOLE_BAUDRATE 9600
+#elif defined(CONFIG_CONSOLE_19200)
+ #define CONSOLE_BAUDRATE 19200
+#elif defined(CONFIG_CONSOLE_115200)
+ #define CONSOLE_BAUDRATE 115200
+#else
+#error "console baud rate undefined"
+#endif
+
+/*
+ * ------------------------------------------------------------
+ * 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_360_stop(struct tty_struct *tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ int idx;
+ unsigned long flags;
+ volatile struct scc_regs *sccp;
+ volatile struct smc_regs *smcp;
+
+ if (serial_paranoia_check(info, tty->device, "rs_stop"))
+ return;
+
+ local_irq_save(flags);
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC) {
+ sccp = &pquicc->scc_regs[idx];
+ sccp->scc_sccm &= ~UART_SCCM_TX;
+ } else {
+ /* smcp = &cpmp->cp_smc[idx]; */
+ smcp = &pquicc->smc_regs[idx];
+ smcp->smc_smcm &= ~SMCM_TX;
+ }
+ local_irq_restore(flags);
+}
+
+
+static void rs_360_start(struct tty_struct *tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ int idx;
+ unsigned long flags;
+ volatile struct scc_regs *sccp;
+ volatile struct smc_regs *smcp;
+
+ if (serial_paranoia_check(info, tty->device, "rs_stop"))
+ return;
+
+ local_irq_save(flags);
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC) {
+ sccp = &pquicc->scc_regs[idx];
+ sccp->scc_sccm |= UART_SCCM_TX;
+ } else {
+ smcp = &pquicc->smc_regs[idx];
+ smcp->smc_smcm |= SMCM_TX;
+ }
+ local_irq_restore(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(ser_info_t *info,
+ int event)
+{
+ info->event |= 1 << event;
+ queue_task(&info->tqueue, &tq_serial);
+ mark_bh(SERIAL_BH);
+}
+
+static _INLINE_ void receive_chars(ser_info_t *info)
+{
+ struct tty_struct *tty = info->tty;
+ unsigned char ch, *cp;
+ /*int ignored = 0;*/
+ int i;
+ ushort status;
+ struct async_icount *icount;
+ /* struct async_icount_24 *icount; */
+ volatile QUICC_BD *bdp;
+
+ icount = &info->state->icount;
+
+ /* Just loop through the closed BDs and copy the characters into
+ * the buffer.
+ */
+ bdp = info->rx_cur;
+ for (;;) {
+ if (bdp->status & BD_SC_EMPTY) /* If this one is empty */
+ break; /* we are all done */
+
+ /* The read status mask tell us what we should do with
+ * incoming characters, especially if errors occur.
+ * One special case is the use of BD_SC_EMPTY. If
+ * this is not set, we are supposed to be ignoring
+ * inputs. In this case, just mark the buffer empty and
+ * continue.
+ */
+ if (!(info->read_status_mask & BD_SC_EMPTY)) {
+ bdp->status |= BD_SC_EMPTY;
+ bdp->status &=
+ ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
+
+ if (bdp->status & BD_SC_WRAP)
+ bdp = info->rx_bd_base;
+ else
+ bdp++;
+ continue;
+ }
+
+ /* Get the number of characters and the buffer pointer.
+ */
+ i = bdp->length;
+ /* cp = (unsigned char *)__va(bdp->buf); */
+ cp = (char *)bdp->buf;
+ status = bdp->status;
+
+ /* Check to see if there is room in the tty buffer for
+ * the characters in our BD buffer. If not, we exit
+ * now, leaving the BD with the characters. We'll pick
+ * them up again on the next receive interrupt (which could
+ * be a timeout).
+ */
+ if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE)
+ break;
+
+ while (i-- > 0) {
+ ch = *cp++;
+ *tty->flip.char_buf_ptr = ch;
+ icount->rx++;
+
+#ifdef SERIAL_DEBUG_INTR
+ printk("DR%02x:%02x...", ch, status);
+#endif
+ *tty->flip.flag_buf_ptr = 0;
+ if (status & (BD_SC_BR | BD_SC_FR |
+ BD_SC_PR | BD_SC_OV)) {
+ /*
+ * For statistics only
+ */
+ if (status & BD_SC_BR)
+ icount->brk++;
+ else if (status & BD_SC_PR)
+ icount->parity++;
+ else if (status & BD_SC_FR)
+ icount->frame++;
+ if (status & BD_SC_OV)
+ icount->overrun++;
+
+ /*
+ * Now check to see if character should be
+ * ignored, and mask off conditions which
+ * should be ignored.
+ if (status & info->ignore_status_mask) {
+ if (++ignored > 100)
+ break;
+ continue;
+ }
+ */
+ status &= info->read_status_mask;
+
+ if (status & (BD_SC_BR)) {
+#ifdef SERIAL_DEBUG_INTR
+ printk("handling break....");
+#endif
+ *tty->flip.flag_buf_ptr = TTY_BREAK;
+ if (info->flags & ASYNC_SAK)
+ do_SAK(tty);
+ } else if (status & BD_SC_PR)
+ *tty->flip.flag_buf_ptr = TTY_PARITY;
+ else if (status & BD_SC_FR)
+ *tty->flip.flag_buf_ptr = TTY_FRAME;
+ if (status & BD_SC_OV) {
+ /*
+ * Overrun is special, since it's
+ * reported immediately, and doesn't
+ * affect the current character
+ */
+ if (tty->flip.count < TTY_FLIPBUF_SIZE) {
+ tty->flip.count++;
+ tty->flip.flag_buf_ptr++;
+ tty->flip.char_buf_ptr++;
+ *tty->flip.flag_buf_ptr =
+ TTY_OVERRUN;
+ }
+ }
+ }
+ if (tty->flip.count >= TTY_FLIPBUF_SIZE)
+ break;
+
+ tty->flip.flag_buf_ptr++;
+ tty->flip.char_buf_ptr++;
+ tty->flip.count++;
+ }
+
+ /* This BD is ready to be used again. Clear status.
+ * Get next BD.
+ */
+ bdp->status |= BD_SC_EMPTY;
+ bdp->status &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
+
+ if (bdp->status & BD_SC_WRAP)
+ bdp = info->rx_bd_base;
+ else
+ bdp++;
+ }
+
+ info->rx_cur = (QUICC_BD *)bdp;
+
+ queue_task(&tty->flip.tqueue, &tq_timer);
+}
+
+static _INLINE_ void receive_break(ser_info_t *info)
+{
+ struct tty_struct *tty = info->tty;
+
+ info->state->icount.brk++;
+ /* Check to see if there is room in the tty buffer for
+ * the break. If not, we exit now, losing the break. FIXME
+ */
+ if ((tty->flip.count + 1) >= TTY_FLIPBUF_SIZE)
+ return;
+ *(tty->flip.flag_buf_ptr++) = TTY_BREAK;
+ *(tty->flip.char_buf_ptr++) = 0;
+ tty->flip.count++;
+
+ queue_task(&tty->flip.tqueue, &tq_timer);
+}
+
+static _INLINE_ void transmit_chars(ser_info_t *info)
+{
+
+ if ((info->flags & TX_WAKEUP) ||
+ (info->tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {
+ rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
+ }
+
+#ifdef SERIAL_DEBUG_INTR
+ printk("THRE...");
+#endif
+}
+
+#ifdef notdef
+ /* I need to do this for the SCCs, so it is left as a reminder.
+ */
+static _INLINE_ void check_modem_status(struct async_struct *info)
+{
+ int status;
+ /* struct async_icount *icount; */
+ struct async_icount_24 *icount;
+
+ status = serial_in(info, UART_MSR);
+
+ if (status & UART_MSR_ANY_DELTA) {
+ icount = &info->state->icount;
+ /* update input line counters */
+ if (status & UART_MSR_TERI)
+ icount->rng++;
+ if (status & UART_MSR_DDSR)
+ icount->dsr++;
+ if (status & UART_MSR_DDCD) {
+ icount->dcd++;
+#ifdef CONFIG_HARD_PPS
+ if ((info->flags & ASYNC_HARDPPS_CD) &&
+ (status & UART_MSR_DCD))
+ hardpps();
+#endif
+ }
+ if (status & UART_MSR_DCTS)
+ 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 if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ (info->flags & ASYNC_CALLOUT_NOHUP))) {
+#ifdef SERIAL_DEBUG_OPEN
+ printk("scheduling hangup...");
+#endif
+ queue_task(&info->tqueue_hangup,
+ &tq_scheduler);
+ }
+ }
+ if (info->flags & ASYNC_CTS_FLOW) {
+ if (info->tty->hw_stopped) {
+ if (status & UART_MSR_CTS) {
+#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
+ printk("CTS tx start...");
+#endif
+ info->tty->hw_stopped = 0;
+ info->IER |= UART_IER_THRI;
+ serial_out(info, UART_IER, info->IER);
+ rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
+ return;
+ }
+ } else {
+ if (!(status & UART_MSR_CTS)) {
+#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
+ printk("CTS tx stop...");
+#endif
+ info->tty->hw_stopped = 1;
+ info->IER &= ~UART_IER_THRI;
+ serial_out(info, UART_IER, info->IER);
+ }
+ }
+ }
+}
+#endif
+
+/*
+ * This is the serial driver's interrupt routine for a single port
+ */
+/* static void rs_360_interrupt(void *dev_id) */ /* until and if we start servicing irqs here */
+static void rs_360_interrupt(int vec, void *dev_id, struct pt_regs *fp)
+{
+ u_char events;
+ int idx;
+ ser_info_t *info;
+ volatile struct smc_regs *smcp;
+ volatile struct scc_regs *sccp;
+
+ info = (ser_info_t *)dev_id;
+
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC) {
+ sccp = &pquicc->scc_regs[idx];
+ events = sccp->scc_scce;
+ if (events & SCCM_RX)
+ receive_chars(info);
+ if (events & SCCM_TX)
+ transmit_chars(info);
+ sccp->scc_scce = events;
+ } else {
+ smcp = &pquicc->smc_regs[idx];
+ events = smcp->smc_smce;
+ if (events & SMCM_BRKE)
+ receive_break(info);
+ if (events & SMCM_RX)
+ receive_chars(info);
+ if (events & SMCM_TX)
+ transmit_chars(info);
+ smcp->smc_smce = events;
+ }
+
+#ifdef SERIAL_DEBUG_INTR
+ printk("rs_interrupt_single(%d, %x)...",
+ info->state->smc_scc_num, events);
+#endif
+#ifdef modem_control
+ check_modem_status(info);
+#endif
+ info->last_active = jiffies;
+#ifdef SERIAL_DEBUG_INTR
+ printk("end.\n");
+#endif
+}
+
+
+/*
+ * -------------------------------------------------------------------
+ * Here ends the serial interrupt routines.
+ * -------------------------------------------------------------------
+ */
+
+/*
+ * This routine is used to handle the "bottom half" processing for the
+ * serial driver, known also the "software interrupt" processing.
+ * This processing is done at the kernel interrupt level, after the
+ * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
+ * is where time-consuming activities which can not be done in the
+ * interrupt driver proper are done; the interrupt driver schedules
+ * them using rs_sched_event(), and they get done here.
+ */
+static void do_serial_bh(void)
+{
+ run_task_queue(&tq_serial);
+}
+
+static void do_softint(void *private_)
+{
+ ser_info_t *info = (ser_info_t *) private_;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (!tty)
+ return;
+
+ if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
+ if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+ tty->ldisc.write_wakeup)
+ (tty->ldisc.write_wakeup)(tty);
+ wake_up_interruptible(&tty->write_wait);
+ }
+}
+
+
+
+
+/*
+ * 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() -> rs_hangup()
+ *
+ */
+static void do_serial_hangup(void *private_)
+{
+ struct async_struct *info = (struct async_struct *) private_;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (!tty)
+ return;
+
+ tty_hangup(tty);
+}
+
+/*static void rs_360_timer(void)
+{
+ printk("rs_360_timer\n");
+}*/
+
+
+static int startup(ser_info_t *info)
+{
+ unsigned long flags;
+ int retval=0;
+ int idx;
+ /*struct serial_state *state = info->state;*/
+ volatile struct smc_regs *smcp;
+ volatile struct scc_regs *sccp;
+ volatile struct smc_uart_pram *up;
+ volatile struct uart_pram *scup;
+
+
+ local_irq_save(flags);
+
+ if (info->flags & ASYNC_INITIALIZED) {
+ goto errout;
+ }
+
+#ifdef maybe
+ if (!state->port || !state->type) {
+ if (info->tty)
+ set_bit(TTY_IO_ERROR, &info->tty->flags);
+ goto errout;
+ }
+#endif
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("starting up ttys%d (irq %d)...", info->line, state->irq);
+#endif
+
+
+#ifdef modem_control
+ info->MCR = 0;
+ if (info->tty->termios->c_cflag & CBAUD)
+ info->MCR = UART_MCR_DTR | UART_MCR_RTS;
+#endif
+
+ if (info->tty)
+ clear_bit(TTY_IO_ERROR, &info->tty->flags);
+
+ /*
+ * and set the speed of the serial port
+ */
+ change_speed(info);
+
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC) {
+ sccp = &pquicc->scc_regs[idx];
+ scup = &pquicc->pram[info->state->port].scc.pscc.u;
+
+ scup->mrblr = RX_BUF_SIZE;
+ scup->max_idl = RX_BUF_SIZE;
+
+ sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
+ sccp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
+
+ } else {
+ smcp = &pquicc->smc_regs[idx];
+
+ /* Enable interrupts and I/O.
+ */
+ smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
+ smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
+
+ /* We can tune the buffer length and idle characters
+ * to take advantage of the entire incoming buffer size.
+ * If mrblr is something other than 1, maxidl has to be
+ * non-zero or we never get an interrupt. The maxidl
+ * is the number of character times we wait after reception
+ * of the last character before we decide no more characters
+ * are coming.
+ */
+ /* up = (smc_uart_t *)&pquicc->cp_dparam[state->port]; */
+ /* holy unionized structures, Batman: */
+ up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
+
+ up->mrblr = RX_BUF_SIZE;
+ up->max_idl = RX_BUF_SIZE;
+
+ up->brkcr = 1; /* number of break chars */
+ }
+
+ info->flags |= ASYNC_INITIALIZED;
+ local_irq_restore(flags);
+ return 0;
+
+errout:
+ local_irq_restore(flags);
+ 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(ser_info_t *info)
+{
+ unsigned long flags;
+ struct serial_state *state;
+ int idx;
+ volatile struct smc_regs *smcp;
+ volatile struct scc_regs *sccp;
+
+ if (!(info->flags & ASYNC_INITIALIZED))
+ return;
+
+ state = info->state;
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("Shutting down serial port %d (irq %d)....", info->line,
+ state->irq);
+#endif
+
+ local_irq_save(flags);
+
+ idx = PORT_NUM(state->smc_scc_num);
+ if (state->smc_scc_num & NUM_IS_SCC) {
+ sccp = &pquicc->scc_regs[idx];
+ sccp->scc_gsmr.w.low &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
+#ifdef CONFIG_SERIAL_CONSOLE
+ /* We can't disable the transmitter if this is the
+ * system console.
+ */
+ if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
+#endif
+ sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
+ } else {
+ smcp = &pquicc->smc_regs[idx];
+
+ /* Disable interrupts and I/O.
+ */
+ smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
+#ifdef CONFIG_SERIAL_CONSOLE
+ /* We can't disable the transmitter if this is the
+ * system console.
+ */
+ if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
+#endif
+ smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
+ }
+
+ if (info->tty)
+ set_bit(TTY_IO_ERROR, &info->tty->flags);
+
+ info->flags &= ~ASYNC_INITIALIZED;
+ local_irq_restore(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(ser_info_t *info)
+{
+ int baud_rate;
+ unsigned cflag, cval, scval, prev_mode;
+ int i, bits, sbits, idx;
+ unsigned long flags;
+ struct serial_state *state;
+ volatile struct smc_regs *smcp;
+ volatile struct scc_regs *sccp;
+
+ if (!info->tty || !info->tty->termios)
+ return;
+ cflag = info->tty->termios->c_cflag;
+
+ state = info->state;
+
+ /* Character length programmed into the mode register is the
+ * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
+ * 1 or 2 stop bits, minus 1.
+ * The value 'bits' counts this for us.
+ */
+ cval = 0;
+ scval = 0;
+
+ /* byte size and parity */
+ switch (cflag & CSIZE) {
+ case CS5: bits = 5; break;
+ case CS6: bits = 6; break;
+ case CS7: bits = 7; break;
+ case CS8: bits = 8; break;
+ /* Never happens, but GCC is too dumb to figure it out */
+ default: bits = 8; break;
+ }
+ sbits = bits - 5;
+
+ if (cflag & CSTOPB) {
+ cval |= SMCMR_SL; /* Two stops */
+ scval |= SCU_PMSR_SL;
+ bits++;
+ }
+ if (cflag & PARENB) {
+ cval |= SMCMR_PEN;
+ scval |= SCU_PMSR_PEN;
+ bits++;
+ }
+ if (!(cflag & PARODD)) {
+ cval |= SMCMR_PM_EVEN;
+ scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
+ }
+
+ /* Determine divisor based on baud rate */
+ i = cflag & CBAUD;
+ if (i >= (sizeof(baud_table)/sizeof(int)))
+ baud_rate = 9600;
+ else
+ baud_rate = baud_table[i];
+
+ info->timeout = (TX_BUF_SIZE*HZ*bits);
+ info->timeout += HZ/50; /* Add .02 seconds of slop */
+
+#ifdef modem_control
+ /* CTS flow control flag and modem status interrupts */
+ info->IER &= ~UART_IER_MSI;
+ if (info->flags & ASYNC_HARDPPS_CD)
+ info->IER |= UART_IER_MSI;
+ if (cflag & CRTSCTS) {
+ info->flags |= ASYNC_CTS_FLOW;
+ info->IER |= UART_IER_MSI;
+ } 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;
+ }
+ serial_out(info, UART_IER, info->IER);
+#endif
+
+ /*
+ * Set up parity check flag
+ */
+#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
+
+ info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
+ if (I_INPCK(info->tty))
+ info->read_status_mask |= BD_SC_FR | BD_SC_PR;
+ if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
+ info->read_status_mask |= BD_SC_BR;
+
+ /*
+ * Characters to ignore
+ */
+ info->ignore_status_mask = 0;
+ if (I_IGNPAR(info->tty))
+ info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
+ if (I_IGNBRK(info->tty)) {
+ info->ignore_status_mask |= BD_SC_BR;
+ /*
+ * If we're ignore parity and break indicators, ignore
+ * overruns too. (For real raw support).
+ */
+ if (I_IGNPAR(info->tty))
+ info->ignore_status_mask |= BD_SC_OV;
+ }
+ /*
+ * !!! ignore all characters if CREAD is not set
+ */
+ if ((cflag & CREAD) == 0)
+ info->read_status_mask &= ~BD_SC_EMPTY;
+ local_irq_save(flags);
+
+ /* Start bit has not been added (so don't, because we would just
+ * subtract it later), and we need to add one for the number of
+ * stops bits (there is always at least one).
+ */
+ bits++;
+ idx = PORT_NUM(state->smc_scc_num);
+ if (state->smc_scc_num & NUM_IS_SCC) {
+ sccp = &pquicc->scc_regs[idx];
+ sccp->scc_psmr = (sbits << 12) | scval;
+ } else {
+ smcp = &pquicc->smc_regs[idx];
+
+ /* Set the mode register. We want to keep a copy of the
+ * enables, because we want to put them back if they were
+ * present.
+ */
+ prev_mode = smcp->smc_smcmr;
+ smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
+ smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
+ }
+
+ m360_cpm_setbrg((state - rs_table), baud_rate);
+
+ local_irq_restore(flags);
+}
+
+static void rs_360_put_char(struct tty_struct *tty, unsigned char ch)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ volatile QUICC_BD *bdp;
+
+ if (serial_paranoia_check(info, tty->device, "rs_put_char"))
+ return;
+
+ if (!tty)
+ return;
+
+ bdp = info->tx_cur;
+ while (bdp->status & BD_SC_READY);
+
+ /* *((char *)__va(bdp->buf)) = ch; */
+ *((char *)bdp->buf) = ch;
+ bdp->length = 1;
+ bdp->status |= BD_SC_READY;
+
+ /* Get next BD.
+ */
+ if (bdp->status & BD_SC_WRAP)
+ bdp = info->tx_bd_base;
+ else
+ bdp++;
+
+ info->tx_cur = (QUICC_BD *)bdp;
+
+}
+
+static int rs_360_write(struct tty_struct * tty, int from_user,
+ const unsigned char *buf, int count)
+{
+ int c, ret = 0;
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ volatile QUICC_BD *bdp;
+
+#ifdef CONFIG_KGDB
+ /* Try to let stub handle output. Returns true if it did. */
+ if (kgdb_output_string(buf, count))
+ return ret;
+#endif
+
+ if (serial_paranoia_check(info, tty->device, "rs_write"))
+ return 0;
+
+ if (!tty)
+ return 0;
+
+ bdp = info->tx_cur;
+
+ while (1) {
+ c = min(count, TX_BUF_SIZE);
+
+ if (c <= 0)
+ break;
+
+ if (bdp->status & BD_SC_READY) {
+ info->flags |= TX_WAKEUP;
+ break;
+ }
+
+ if (from_user) {
+ if (copy_from_user((void *)bdp->buf, buf, c)) {
+ if (!ret)
+ ret = -EFAULT;
+ break;
+ }
+ } else {
+ /* memcpy(__va(bdp->buf), buf, c); */
+ memcpy((void *)bdp->buf, buf, c);
+ }
+
+ bdp->length = c;
+ bdp->status |= BD_SC_READY;
+
+ buf += c;
+ count -= c;
+ ret += c;
+
+ /* Get next BD.
+ */
+ if (bdp->status & BD_SC_WRAP)
+ bdp = info->tx_bd_base;
+ else
+ bdp++;
+ info->tx_cur = (QUICC_BD *)bdp;
+ }
+ return ret;
+}
+
+static int rs_360_write_room(struct tty_struct *tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ int ret;
+
+ if (serial_paranoia_check(info, tty->device, "rs_write_room"))
+ return 0;
+
+ if ((info->tx_cur->status & BD_SC_READY) == 0) {
+ info->flags &= ~TX_WAKEUP;
+ ret = TX_BUF_SIZE;
+ }
+ else {
+ info->flags |= TX_WAKEUP;
+ ret = 0;
+ }
+ return ret;
+}
+
+/* I could track this with transmit counters....maybe later.
+*/
+static int rs_360_chars_in_buffer(struct tty_struct *tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
+ return 0;
+ return 0;
+}
+
+static void rs_360_flush_buffer(struct tty_struct *tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
+ return;
+
+ /* There is nothing to "flush", whatever we gave the CPM
+ * is on its way out.
+ */
+ wake_up_interruptible(&tty->write_wait);
+ if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+ tty->ldisc.write_wakeup)
+ (tty->ldisc.write_wakeup)(tty);
+ info->flags &= ~TX_WAKEUP;
+}
+
+/*
+ * This function is used to send a high-priority XON/XOFF character to
+ * the device
+ */
+static void rs_360_send_xchar(struct tty_struct *tty, char ch)
+{
+ volatile QUICC_BD *bdp;
+
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "rs_send_char"))
+ return;
+
+ bdp = info->tx_cur;
+ while (bdp->status & BD_SC_READY);
+
+ /* *((char *)__va(bdp->buf)) = ch; */
+ *((char *)bdp->buf) = ch;
+ bdp->length = 1;
+ bdp->status |= BD_SC_READY;
+
+ /* Get next BD.
+ */
+ if (bdp->status & BD_SC_WRAP)
+ bdp = info->tx_bd_base;
+ else
+ bdp++;
+
+ info->tx_cur = (QUICC_BD *)bdp;
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_throttle()
+ *
+ * This routine is called by the upper-layer tty layer to signal that
+ * incoming characters should be throttled.
+ * ------------------------------------------------------------
+ */
+static void rs_360_throttle(struct tty_struct * tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+#ifdef SERIAL_DEBUG_THROTTLE
+ char buf[64];
+
+ printk("throttle %s: %d....\n", _tty_name(tty, buf),
+ tty->ldisc.chars_in_buffer(tty));
+#endif
+
+ if (serial_paranoia_check(info, tty->device, "rs_throttle"))
+ return;
+
+ if (I_IXOFF(tty))
+ rs_360_send_xchar(tty, STOP_CHAR(tty));
+
+#ifdef modem_control
+ if (tty->termios->c_cflag & CRTSCTS)
+ info->MCR &= ~UART_MCR_RTS;
+
+ local_irq_disable();
+ serial_out(info, UART_MCR, info->MCR);
+ local_irq_enable();
+#endif
+}
+
+static void rs_360_unthrottle(struct tty_struct * tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+#ifdef SERIAL_DEBUG_THROTTLE
+ char buf[64];
+
+ printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
+ tty->ldisc.chars_in_buffer(tty));
+#endif
+
+ if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
+ return;
+
+ if (I_IXOFF(tty)) {
+ if (info->x_char)
+ info->x_char = 0;
+ else
+ rs_360_send_xchar(tty, START_CHAR(tty));
+ }
+#ifdef modem_control
+ if (tty->termios->c_cflag & CRTSCTS)
+ info->MCR |= UART_MCR_RTS;
+ local_irq_disable();
+ serial_out(info, UART_MCR, info->MCR);
+ local_irq_enable();
+#endif
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_ioctl() and friends
+ * ------------------------------------------------------------
+ */
+
+#ifdef maybe
+/*
+ * get_lsr_info - get line status register info
+ *
+ * Purpose: Let user call ioctl() to get info when the UART physically
+ * is emptied. On bus types like RS485, the transmitter must
+ * release the bus after transmitting. This must be done when
+ * the transmit shift register is empty, not be done when the
+ * transmit holding register is empty. This functionality
+ * allows an RS485 driver to be written in user space.
+ */
+static int get_lsr_info(struct async_struct * info, unsigned int *value)
+{
+ unsigned char status;
+ unsigned int result;
+
+ local_irq_disable();
+ status = serial_in(info, UART_LSR);
+ local_irq_enable();
+ result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
+ return put_user(result,value);
+}
+#endif
+
+static int get_modem_info(ser_info_t *info, unsigned int *value)
+{
+ unsigned int result = 0;
+#ifdef modem_control
+ unsigned char control, status;
+
+ control = info->MCR;
+ local_irq_disable();
+ status = serial_in(info, UART_MSR);
+ local_irq_enable();
+ result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
+ | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
+#ifdef TIOCM_OUT1
+ | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
+ | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
+#endif
+ | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
+ | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
+ | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
+ | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
+#endif
+ /* return put_user(result,value); */
+ put_user(result,value);
+ return (0);
+}
+
+static int set_modem_info(ser_info_t *info, unsigned int cmd,
+ unsigned int *value)
+{
+ int error;
+ unsigned int arg;
+
+ error = get_user(arg,value);
+ if (error)
+ return error;
+#ifdef modem_control
+ switch (cmd) {
+ case TIOCMBIS:
+ if (arg & TIOCM_RTS)
+ info->MCR |= UART_MCR_RTS;
+ if (arg & TIOCM_DTR)
+ info->MCR |= UART_MCR_DTR;
+#ifdef TIOCM_OUT1
+ if (arg & TIOCM_OUT1)
+ info->MCR |= UART_MCR_OUT1;
+ if (arg & TIOCM_OUT2)
+ info->MCR |= UART_MCR_OUT2;
+#endif
+ break;
+ case TIOCMBIC:
+ if (arg & TIOCM_RTS)
+ info->MCR &= ~UART_MCR_RTS;
+ if (arg & TIOCM_DTR)
+ info->MCR &= ~UART_MCR_DTR;
+#ifdef TIOCM_OUT1
+ if (arg & TIOCM_OUT1)
+ info->MCR &= ~UART_MCR_OUT1;
+ if (arg & TIOCM_OUT2)
+ info->MCR &= ~UART_MCR_OUT2;
+#endif
+ break;
+ case TIOCMSET:
+ info->MCR = ((info->MCR & ~(UART_MCR_RTS |
+#ifdef TIOCM_OUT1
+ UART_MCR_OUT1 |
+ UART_MCR_OUT2 |
+#endif
+ UART_MCR_DTR))
+ | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
+#ifdef TIOCM_OUT1
+ | ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
+ | ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
+#endif
+ | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
+ break;
+ default:
+ return -EINVAL;
+ }
+ local_irq_disable();
+ serial_out(info, UART_MCR, info->MCR);
+ local_irq_enable();
+#endif
+ return 0;
+}
+
+/* Sending a break is a two step process on the SMC/SCC. It is accomplished
+ * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
+ * command. We take advantage of the begin/end functions to make this
+ * happen.
+ */
+static ushort smc_chan_map[] = {
+ CPM_CR_CH_SMC1,
+ CPM_CR_CH_SMC2
+};
+
+static ushort scc_chan_map[] = {
+ CPM_CR_CH_SCC1,
+ CPM_CR_CH_SCC2,
+ CPM_CR_CH_SCC3,
+ CPM_CR_CH_SCC4
+};
+
+static void begin_break(ser_info_t *info)
+{
+ volatile QUICC *cp;
+ ushort chan;
+ int idx;
+
+ cp = pquicc;
+
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC)
+ chan = scc_chan_map[idx];
+ else
+ chan = smc_chan_map[idx];
+
+ cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG;
+ while (cp->cp_cr & CPM_CR_FLG);
+}
+
+static void end_break(ser_info_t *info)
+{
+ volatile QUICC *cp;
+ ushort chan;
+ int idx;
+
+ cp = pquicc;
+
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC)
+ chan = scc_chan_map[idx];
+ else
+ chan = smc_chan_map[idx];
+
+ cp->cp_cr = mk_cr_cmd(chan, CPM_CR_RESTART_TX) | CPM_CR_FLG;
+ while (cp->cp_cr & CPM_CR_FLG);
+}
+
+/*
+ * This routine sends a break character out the serial port.
+ */
+static void send_break(ser_info_t *info, int duration)
+{
+ current->state = TASK_INTERRUPTIBLE;
+#ifdef SERIAL_DEBUG_SEND_BREAK
+ printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
+#endif
+ begin_break(info);
+ schedule_timeout(duration);
+ end_break(info);
+#ifdef SERIAL_DEBUG_SEND_BREAK
+ printk("done jiffies=%lu\n", jiffies);
+#endif
+}
+
+
+static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
+ unsigned int cmd, unsigned long arg)
+{
+ int error;
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ int retval;
+ struct async_icount cnow;
+ /* struct async_icount_24 cnow;*/ /* kernel counter temps */
+ struct serial_icounter_struct *p_cuser; /* user space */
+
+ if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
+ return -ENODEV;
+
+ if ((cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
+ if (tty->flags & (1 << TTY_IO_ERROR))
+ return -EIO;
+ }
+
+ switch (cmd) {
+ case TCSBRK: /* SVID version: non-zero arg --> no break */
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ tty_wait_until_sent(tty, 0);
+ if (signal_pending(current))
+ return -EINTR;
+ if (!arg) {
+ send_break(info, HZ/4); /* 1/4 second */
+ if (signal_pending(current))
+ return -EINTR;
+ }
+ return 0;
+ case TCSBRKP: /* support for POSIX tcsendbreak() */
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ tty_wait_until_sent(tty, 0);
+ if (signal_pending(current))
+ return -EINTR;
+ send_break(info, arg ? arg*(HZ/10) : HZ/4);
+ if (signal_pending(current))
+ return -EINTR;
+ return 0;
+ case TIOCSBRK:
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ tty_wait_until_sent(tty, 0);
+ begin_break(info);
+ return 0;
+ case TIOCCBRK:
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ end_break(info);
+ return 0;
+ case TIOCGSOFTCAR:
+ /* return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg); */
+ put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
+ return 0;
+ case TIOCSSOFTCAR:
+ error = get_user(arg, (unsigned int *) arg);
+ if (error)
+ return error;
+ tty->termios->c_cflag =
+ ((tty->termios->c_cflag & ~CLOCAL) |
+ (arg ? CLOCAL : 0));
+ return 0;
+ case TIOCMGET:
+ return get_modem_info(info, (unsigned int *) arg);
+ case TIOCMBIS:
+ case TIOCMBIC:
+ case TIOCMSET:
+ return set_modem_info(info, cmd, (unsigned int *) arg);
+#ifdef maybe
+ case TIOCSERGETLSR: /* Get line status register */
+ return get_lsr_info(info, (unsigned int *) arg);
+#endif
+ /*
+ * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
+ * - mask passed in arg for lines of interest
+ * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
+ * Caller should use TIOCGICOUNT to see which one it was
+ */
+ case TIOCMIWAIT:
+#ifdef modem_control
+ local_irq_disable();
+ /* note the counters on entry */
+ cprev = info->state->icount;
+ local_irq_enable();
+ while (1) {
+ interruptible_sleep_on(&info->delta_msr_wait);
+ /* see if a signal did it */
+ if (signal_pending(current))
+ return -ERESTARTSYS;
+ local_irq_disable();
+ cnow = info->state->icount; /* atomic copy */
+ local_irq_enable();
+ if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
+ cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
+ return -EIO; /* no change => error */
+ if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
+ ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
+ ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
+ ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
+ return 0;
+ }
+ cprev = cnow;
+ }
+ /* NOTREACHED */
+#else
+ return 0;
+#endif
+
+ /*
+ * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
+ * Return: write counters to the user passed counter struct
+ * NB: both 1->0 and 0->1 transitions are counted except for
+ * RI where only 0->1 is counted.
+ */
+ case TIOCGICOUNT:
+ local_irq_disable();
+ cnow = info->state->icount;
+ local_irq_enable();
+ p_cuser = (struct serial_icounter_struct *) arg;
+/* error = put_user(cnow.cts, &p_cuser->cts); */
+/* if (error) return error; */
+/* error = put_user(cnow.dsr, &p_cuser->dsr); */
+/* if (error) return error; */
+/* error = put_user(cnow.rng, &p_cuser->rng); */
+/* if (error) return error; */
+/* error = put_user(cnow.dcd, &p_cuser->dcd); */
+/* if (error) return error; */
+
+ put_user(cnow.cts, &p_cuser->cts);
+ put_user(cnow.dsr, &p_cuser->dsr);
+ put_user(cnow.rng, &p_cuser->rng);
+ put_user(cnow.dcd, &p_cuser->dcd);
+ return 0;
+
+ default:
+ return -ENOIOCTLCMD;
+ }
+ return 0;
+}
+
+/* FIX UP modem control here someday......
+*/
+static void rs_360_set_termios(struct tty_struct *tty, struct termios *old_termios)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+
+ if ( (tty->termios->c_cflag == old_termios->c_cflag)
+ && ( RELEVANT_IFLAG(tty->termios->c_iflag)
+ == RELEVANT_IFLAG(old_termios->c_iflag)))
+ return;
+
+ change_speed(info);
+
+#ifdef modem_control
+ /* Handle transition to B0 status */
+ if ((old_termios->c_cflag & CBAUD) &&
+ !(tty->termios->c_cflag & CBAUD)) {
+ info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
+ local_irq_disable();
+ serial_out(info, UART_MCR, info->MCR);
+ local_irq_enable();
+ }
+
+ /* Handle transition away from B0 status */
+ if (!(old_termios->c_cflag & CBAUD) &&
+ (tty->termios->c_cflag & CBAUD)) {
+ info->MCR |= UART_MCR_DTR;
+ if (!tty->hw_stopped ||
+ !(tty->termios->c_cflag & CRTSCTS)) {
+ info->MCR |= UART_MCR_RTS;
+ }
+ local_irq_disable();
+ serial_out(info, UART_MCR, info->MCR);
+ local_irq_enable();
+ }
+
+ /* Handle turning off CRTSCTS */
+ if ((old_termios->c_cflag & CRTSCTS) &&
+ !(tty->termios->c_cflag & CRTSCTS)) {
+ tty->hw_stopped = 0;
+ rs_360_start(tty);
+ }
+#endif
+
+#if 0
+ /*
+ * No need to wake up processes in open wait, since they
+ * sample the CLOCAL flag once, and don't recheck it.
+ * XXX It's not clear whether the current behavior is correct
+ * or not. Hence, this may change.....
+ */
+ if (!(old_termios->c_cflag & CLOCAL) &&
+ (tty->termios->c_cflag & CLOCAL))
+ wake_up_interruptible(&info->open_wait);
+#endif
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_close()
+ *
+ * This routine is called when the serial port gets closed. First, we
+ * wait for the last remaining data to be sent. Then, we unlink its
+ * async structure from the interrupt chain if necessary, and we free
+ * that IRQ if nothing is left in the chain.
+ * ------------------------------------------------------------
+ */
+static void rs_360_close(struct tty_struct *tty, struct file * filp)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ /* struct async_state *state; */
+ struct serial_state *state;
+ unsigned long flags;
+ int idx;
+ volatile struct smc_regs *smcp;
+ volatile struct scc_regs *sccp;
+
+ if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
+ return;
+
+ state = info->state;
+
+ local_irq_save(flags);
+
+ if (tty_hung_up_p(filp)) {
+ DBG_CNT("before DEC-hung");
+ MOD_DEC_USE_COUNT;
+ local_irq_restore(flags);
+ return;
+ }
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("rs_close ttys%d, count = %d\n", info->line, state->count);
+#endif
+ if ((tty->count == 1) && (state->count != 1)) {
+ /*
+ * Uh, oh. tty->count is 1, which means that the tty
+ * structure will be freed. state->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("rs_close: bad serial port count; tty->count is 1, "
+ "state->count is %d\n", state->count);
+ state->count = 1;
+ }
+ if (--state->count < 0) {
+ printk("rs_close: bad serial port count for ttys%d: %d\n",
+ info->line, state->count);
+ state->count = 0;
+ }
+ if (state->count) {
+ DBG_CNT("before DEC-2");
+ MOD_DEC_USE_COUNT;
+ local_irq_restore(flags);
+ return;
+ }
+ info->flags |= ASYNC_CLOSING;
+ /*
+ * Save the termios structure, since this port may have
+ * separate termios for callout and dialin.
+ */
+ if (info->flags & ASYNC_NORMAL_ACTIVE)
+ info->state->normal_termios = *tty->termios;
+ if (info->flags & ASYNC_CALLOUT_ACTIVE)
+ info->state->callout_termios = *tty->termios;
+ /*
+ * Now we wait for the transmit buffer to clear; and we notify
+ * the line discipline to only process XON/XOFF characters.
+ */
+ tty->closing = 1;
+ if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
+ tty_wait_until_sent(tty, info->closing_wait);
+ /*
+ * At this point we stop accepting input. To do this, we
+ * disable the receive line status interrupts, and tell the
+ * interrupt driver to stop checking the data ready bit in the
+ * line status register.
+ */
+ info->read_status_mask &= ~BD_SC_EMPTY;
+ if (info->flags & ASYNC_INITIALIZED) {
+
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC) {
+ sccp = &pquicc->scc_regs[idx];
+ sccp->scc_sccm &= ~UART_SCCM_RX;
+ sccp->scc_gsmr.w.low &= ~SCC_GSMRL_ENR;
+ } else {
+ smcp = &pquicc->smc_regs[idx];
+ smcp->smc_smcm &= ~SMCM_RX;
+ smcp->smc_smcmr &= ~SMCMR_REN;
+ }
+ /*
+ * Before we drop DTR, make sure the UART transmitter
+ * has completely drained; this is especially
+ * important if there is a transmit FIFO!
+ */
+ rs_360_wait_until_sent(tty, info->timeout);
+ }
+ shutdown(info);
+ if (tty->driver.flush_buffer)
+ tty->driver.flush_buffer(tty);
+ if (tty->ldisc.flush_buffer)
+ tty->ldisc.flush_buffer(tty);
+ tty->closing = 0;
+ info->event = 0;
+ info->tty = 0;
+ if (info->blocked_open) {
+ if (info->close_delay) {
+ current->state = TASK_INTERRUPTIBLE;
+ schedule_timeout(info->close_delay);
+ }
+ wake_up_interruptible(&info->open_wait);
+ }
+ info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
+ ASYNC_CLOSING);
+ wake_up_interruptible(&info->close_wait);
+ MOD_DEC_USE_COUNT;
+ local_irq_restore(flags);
+}
+
+/*
+ * rs_wait_until_sent() --- wait until the transmitter is empty
+ */
+static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ unsigned long orig_jiffies, char_time;
+ /*int lsr;*/
+ volatile QUICC_BD *bdp;
+
+ if (serial_paranoia_check(info, tty->device, "rs_wait_until_sent"))
+ return;
+
+#ifdef maybe
+ if (info->state->type == PORT_UNKNOWN)
+ return;
+#endif
+
+ orig_jiffies = jiffies;
+ /*
+ * Set the check interval to be 1/5 of the estimated time to
+ * send a single character, and make it at least 1. The check
+ * interval should also be less than the timeout.
+ *
+ * Note: we have to use pretty tight timings here to satisfy
+ * the NIST-PCTS.
+ */
+ char_time = 1;
+ if (timeout)
+ char_time = min(char_time, timeout);
+#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
+ printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
+ printk("jiff=%lu...", jiffies);
+#endif
+
+ /* We go through the loop at least once because we can't tell
+ * exactly when the last character exits the shifter. There can
+ * be at least two characters waiting to be sent after the buffers
+ * are empty.
+ */
+ do {
+#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
+ printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
+#endif
+ current->state = TASK_INTERRUPTIBLE;
+/* current->counter = 0; make us low-priority */
+ schedule_timeout(char_time);
+ if (signal_pending(current))
+ break;
+ if (timeout && ((orig_jiffies + timeout) < jiffies))
+ break;
+ /* The 'tx_cur' is really the next buffer to send. We
+ * have to back up to the previous BD and wait for it
+ * to go. This isn't perfect, because all this indicates
+ * is the buffer is available. There are still characters
+ * in the CPM FIFO.
+ */
+ bdp = info->tx_cur;
+ if (bdp == info->tx_bd_base)
+ bdp += (TX_NUM_FIFO-1);
+ else
+ bdp--;
+ } while (bdp->status & BD_SC_READY);
+ current->state = TASK_RUNNING;
+#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
+ printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
+#endif
+}
+
+/*
+ * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
+ */
+static void rs_360_hangup(struct tty_struct *tty)
+{
+ ser_info_t *info = (ser_info_t *)tty->driver_data;
+ struct serial_state *state = info->state;
+
+ if (serial_paranoia_check(info, tty->device, "rs_hangup"))
+ return;
+
+ state = info->state;
+
+ rs_360_flush_buffer(tty);
+ shutdown(info);
+ info->event = 0;
+ state->count = 0;
+ info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
+ info->tty = 0;
+ wake_up_interruptible(&info->open_wait);
+}
+
+/*
+ * ------------------------------------------------------------
+ * rs_open() and friends
+ * ------------------------------------------------------------
+ */
+static int block_til_ready(struct tty_struct *tty, struct file * filp,
+ ser_info_t *info)
+{
+#ifdef DO_THIS_LATER
+ DECLARE_WAITQUEUE(wait, current);
+#endif
+ struct serial_state *state = info->state;
+ int retval;
+ int do_clocal = 0;
+
+ /*
+ * If the device is in the middle of being closed, then block
+ * until it's done, and then try again.
+ */
+ if (tty_hung_up_p(filp) ||
+ (info->flags & ASYNC_CLOSING)) {
+ if (info->flags & ASYNC_CLOSING)
+ interruptible_sleep_on(&info->close_wait);
+#ifdef SERIAL_DO_RESTART
+ if (info->flags & ASYNC_HUP_NOTIFY)
+ return -EAGAIN;
+ else
+ return -ERESTARTSYS;
+#else
+ return -EAGAIN;
+#endif
+ }
+
+
+#if 0 /* FIXME */
+ /*
+ * If this is a callout device, then just make sure the normal
+ * device isn't being used.
+ */
+ if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
+ if (info->flags & ASYNC_NORMAL_ACTIVE)
+ return -EBUSY;
+ if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ (info->flags & ASYNC_SESSION_LOCKOUT) &&
+ (info->session != current->session))
+ return -EBUSY;
+ if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ (info->flags & ASYNC_PGRP_LOCKOUT) &&
+ (info->pgrp != current->pgrp))
+ return -EBUSY;
+ info->flags |= ASYNC_CALLOUT_ACTIVE;
+ return 0;
+ }
+#endif
+
+ /*
+ * If non-blocking mode is set, or the port is not enabled,
+ * then make the check up front and then exit.
+ * If this is an SMC port, we don't have modem control to wait
+ * for, so just get out here.
+ */
+ if ((filp->f_flags & O_NONBLOCK) ||
+ (tty->flags & (1 << TTY_IO_ERROR)) ||
+ !(info->state->smc_scc_num & NUM_IS_SCC)) {
+ if (info->flags & ASYNC_CALLOUT_ACTIVE)
+ return -EBUSY;
+ info->flags |= ASYNC_NORMAL_ACTIVE;
+ return 0;
+ }
+
+ if (info->flags & ASYNC_CALLOUT_ACTIVE) {
+ if (state->normal_termios.c_cflag & CLOCAL)
+ do_clocal = 1;
+ } else {
+ if (tty->termios->c_cflag & CLOCAL)
+ do_clocal = 1;
+ }
+
+ /*
+ * 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, state->count is dropped by one, so that
+ * rs_close() knows when to free things. We restore it upon
+ * exit, either normal or abnormal.
+ */
+ retval = 0;
+#ifdef DO_THIS_LATER
+ add_wait_queue(&info->open_wait, &wait);
+#ifdef SERIAL_DEBUG_OPEN
+ printk("block_til_ready before block: ttys%d, count = %d\n",
+ state->line, state->count);
+#endif
+ local_irq_disable();
+ if (!tty_hung_up_p(filp))
+ state->count--;
+ local_irq_enable();
+ info->blocked_open++;
+ while (1) {
+ local_irq_disable();
+ if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ (tty->termios->c_cflag & CBAUD))
+ serial_out(info, UART_MCR,
+ serial_inp(info, UART_MCR) |
+ (UART_MCR_DTR | UART_MCR_RTS));
+ local_irq_enable();
+ set_current_state(TASK_INTERRUPTIBLE);
+ if (tty_hung_up_p(filp) ||
+ !(info->flags & ASYNC_INITIALIZED)) {
+#ifdef SERIAL_DO_RESTART
+ if (info->flags & ASYNC_HUP_NOTIFY)
+ retval = -EAGAIN;
+ else
+ retval = -ERESTARTSYS;
+#else
+ retval = -EAGAIN;
+#endif
+ break;
+ }
+ if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ !(info->flags & ASYNC_CLOSING) &&
+ (do_clocal || (serial_in(info, UART_MSR) &
+ UART_MSR_DCD)))
+ break;
+ if (signal_pending(current)) {
+ retval = -ERESTARTSYS;
+ break;
+ }
+#ifdef SERIAL_DEBUG_OPEN
+ printk("block_til_ready blocking: ttys%d, count = %d\n",
+ info->line, state->count);
+#endif
+ schedule();
+ }
+ current->state = TASK_RUNNING;
+ remove_wait_queue(&info->open_wait, &wait);
+ if (!tty_hung_up_p(filp))
+ state->count++;
+ info->blocked_open--;
+#ifdef SERIAL_DEBUG_OPEN
+ printk("block_til_ready after blocking: ttys%d, count = %d\n",
+ info->line, state->count);
+#endif
+#endif /* DO_THIS_LATER */
+ if (retval)
+ return retval;
+ info->flags |= ASYNC_NORMAL_ACTIVE;
+ return 0;
+}
+
+static int get_async_struct(int line, ser_info_t **ret_info)
+{
+ struct serial_state *sstate;
+
+ sstate = rs_table + line;
+ if (sstate->info) {
+ sstate->count++;
+ *ret_info = (ser_info_t *)sstate->info;
+ return 0;
+ }
+ else {
+ return -ENOMEM;
+ }
+}
+
+/*
+ * This routine is called whenever a serial port is opened. It
+ * enables interrupts for a serial port, linking in its async structure into
+ * the IRQ chain. It also performs the serial-specific
+ * initialization for the tty structure.
+ */
+static int rs_360_open(struct tty_struct *tty, struct file * filp)
+{
+ ser_info_t *info;
+ int retval, line;
+
+ line = MINOR(tty->device) - tty->driver.minor_start;
+ if ((line < 0) || (line >= NR_PORTS))
+ return -ENODEV;
+ retval = get_async_struct(line, &info);
+ if (retval)
+ return retval;
+ if (serial_paranoia_check(info, tty->device, "rs_open"))
+ return -ENODEV;
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
+ info->state->count);
+#endif
+ tty->driver_data = info;
+ info->tty = tty;
+
+ /*
+ * Start up serial port
+ */
+ retval = startup(info);
+ if (retval)
+ return retval;
+
+ MOD_INC_USE_COUNT;
+ retval = block_til_ready(tty, filp, info);
+ if (retval) {
+#ifdef SERIAL_DEBUG_OPEN
+ printk("rs_open returning after block_til_ready with %d\n",
+ retval);
+#endif
+ MOD_DEC_USE_COUNT;
+ return retval;
+ }
+
+ if ((info->state->count == 1) &&
+ (info->flags & ASYNC_SPLIT_TERMIOS)) {
+ if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
+ *tty->termios = info->state->normal_termios;
+ else
+ *tty->termios = info->state->callout_termios;
+ change_speed(info);
+ }
+
+ info->session = current->session;
+ info->pgrp = current->pgrp;
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("rs_open ttys%d successful...", info->line);
+#endif
+ return 0;
+}
+
+/*
+ * /proc fs routines....
+ */
+
+static int inline line_info(char *buf, struct serial_state *state)
+{
+#ifdef notdef
+ struct async_struct *info = state->info, scr_info;
+ char stat_buf[30], control, status;
+#endif
+ int ret;
+
+ ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
+ state->line,
+ (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC",
+ (unsigned int)(state->port), state->irq);
+
+ if (!state->port || (state->type == PORT_UNKNOWN)) {
+ ret += sprintf(buf+ret, "\n");
+ return ret;
+ }
+
+#ifdef notdef
+ /*
+ * Figure out the current RS-232 lines
+ */
+ if (!info) {
+ info = &scr_info; /* This is just for serial_{in,out} */
+
+ info->magic = SERIAL_MAGIC;
+ info->port = state->port;
+ info->flags = state->flags;
+ info->quot = 0;
+ info->tty = 0;
+ }
+ local_irq_disable();
+ status = serial_in(info, UART_MSR);
+ control = info ? info->MCR : serial_in(info, UART_MCR);
+ local_irq_enable();
+
+ stat_buf[0] = 0;
+ stat_buf[1] = 0;
+ if (control & UART_MCR_RTS)
+ strcat(stat_buf, "|RTS");
+ if (status & UART_MSR_CTS)
+ strcat(stat_buf, "|CTS");
+ if (control & UART_MCR_DTR)
+ strcat(stat_buf, "|DTR");
+ if (status & UART_MSR_DSR)
+ strcat(stat_buf, "|DSR");
+ if (status & UART_MSR_DCD)
+ strcat(stat_buf, "|CD");
+ if (status & UART_MSR_RI)
+ strcat(stat_buf, "|RI");
+
+ if (info->quot) {
+ ret += sprintf(buf+ret, " baud:%d",
+ state->baud_base / info->quot);
+ }
+
+ ret += sprintf(buf+ret, " tx:%d rx:%d",
+ state->icount.tx, state->icount.rx);
+
+ if (state->icount.frame)
+ ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
+
+ if (state->icount.parity)
+ ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
+
+ if (state->icount.brk)
+ ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
+
+ if (state->icount.overrun)
+ ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
+
+ /*
+ * Last thing is the RS-232 status lines
+ */
+ ret += sprintf(buf+ret, " %s\n", stat_buf+1);
+#endif
+ return ret;
+}
+
+int rs_360_read_proc(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ int i, len = 0;
+ off_t begin = 0;
+
+ len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
+ for (i = 0; i < NR_PORTS && len < 4000; i++) {
+ len += line_info(page + len, &rs_table[i]);
+ if (len+begin > off+count)
+ goto done;
+ if (len+begin < off) {
+ begin += len;
+ len = 0;
+ }
+ }
+ *eof = 1;
+done:
+ if (off >= len+begin)
+ return 0;
+ *start = page + (begin-off);
+ return ((count < begin+len-off) ? count : begin+len-off);
+}
+
+/*
+ * ---------------------------------------------------------------------
+ * rs_init() and friends
+ *
+ * rs_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 _INLINE_ void show_serial_version(void)
+{
+ printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
+}
+
+
+/*
+ * The serial console driver used during boot. Note that these names
+ * clash with those found in "serial.c", so we currently can't support
+ * the 16xxx uarts and these at the same time. I will fix this to become
+ * an indirect function call from tty_io.c (or something).
+ */
+
+#ifdef CONFIG_SERIAL_CONSOLE
+
+/*
+ * Print a string to the serial port trying not to disturb any possible
+ * real use of the port...
+ */
+static void my_console_write(int idx, const char *s,
+ unsigned count)
+{
+ struct serial_state *ser;
+ ser_info_t *info;
+ unsigned i;
+ QUICC_BD *bdp, *bdbase;
+ volatile struct smc_uart_pram *up;
+ volatile u_char *cp;
+
+ ser = rs_table + idx;
+
+
+ /* If the port has been initialized for general use, we have
+ * to use the buffer descriptors allocated there. Otherwise,
+ * we simply use the single buffer allocated.
+ */
+ if ((info = (ser_info_t *)ser->info) != NULL) {
+ bdp = info->tx_cur;
+ bdbase = info->tx_bd_base;
+ }
+ else {
+ /* Pointer to UART in parameter ram.
+ */
+ /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
+ up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
+
+ /* Get the address of the host memory buffer.
+ */
+ bdp = bdbase = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
+ }
+
+ /*
+ * We need to gracefully shut down the transmitter, disable
+ * interrupts, then send our bytes out.
+ */
+
+ /*
+ * Now, do each character. This is not as bad as it looks
+ * since this is a holding FIFO and not a transmitting FIFO.
+ * We could add the complexity of filling the entire transmit
+ * buffer, but we would just wait longer between accesses......
+ */
+ for (i = 0; i < count; i++, s++) {
+ /* Wait for transmitter fifo to empty.
+ * Ready indicates output is ready, and xmt is doing
+ * that, not that it is ready for us to send.
+ */
+ while (bdp->status & BD_SC_READY);
+
+ /* Send the character out.
+ */
+ cp = bdp->buf;
+ *cp = *s;
+
+ bdp->length = 1;
+ bdp->status |= BD_SC_READY;
+
+ if (bdp->status & BD_SC_WRAP)
+ bdp = bdbase;
+ else
+ bdp++;
+
+ /* if a LF, also do CR... */
+ if (*s == 10) {
+ while (bdp->status & BD_SC_READY);
+ /* cp = __va(bdp->buf); */
+ cp = bdp->buf;
+ *cp = 13;
+ bdp->length = 1;
+ bdp->status |= BD_SC_READY;
+
+ if (bdp->status & BD_SC_WRAP) {
+ bdp = bdbase;
+ }
+ else {
+ bdp++;
+ }
+ }
+ }
+
+ /*
+ * Finally, Wait for transmitter & holding register to empty
+ * and restore the IER
+ */
+ while (bdp->status & BD_SC_READY);
+
+ if (info)
+ info->tx_cur = (QUICC_BD *)bdp;
+}
+
+static void serial_console_write(struct console *c, const char *s,
+ unsigned count)
+{
+#ifdef CONFIG_KGDB
+ /* Try to let stub handle output. Returns true if it did. */
+ if (kgdb_output_string(s, count))
+ return;
+#endif
+ my_console_write(c->index, s, count);
+}
+
+
+
+/*void console_print_68360(const char *p)
+{
+ const char *cp = p;
+ int i;
+
+ for (i=0;cp[i]!=0;i++);
+
+ serial_console_write (p, i);
+
+ //Comment this if you want to have a strict interrupt-driven output
+ //rs_fair_output();
+
+ return;
+}*/
+
+
+
+
+
+
+#ifdef CONFIG_XMON
+int
+xmon_360_write(const char *s, unsigned count)
+{
+ my_console_write(0, s, count);
+ return(count);
+}
+#endif
+
+#ifdef CONFIG_KGDB
+void
+putDebugChar(char ch)
+{
+ my_console_write(0, &ch, 1);
+}
+#endif
+
+/*
+ * Receive character from the serial port. This only works well
+ * before the port is initialized for real use.
+ */
+static int my_console_wait_key(int idx, int xmon, char *obuf)
+{
+ struct serial_state *ser;
+ u_char c, *cp;
+ ser_info_t *info;
+ QUICC_BD *bdp;
+ volatile struct smc_uart_pram *up;
+ int i;
+
+ ser = rs_table + idx;
+
+ /* Get the address of the host memory buffer.
+ * If the port has been initialized for general use, we must
+ * use information from the port structure.
+ */
+ if ((info = (ser_info_t *)ser->info))
+ bdp = info->rx_cur;
+ else
+ /* bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase]; */
+ bdp = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
+
+ /* Pointer to UART in parameter ram.
+ */
+ /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
+ up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
+
+ /*
+ * We need to gracefully shut down the receiver, disable
+ * interrupts, then read the input.
+ * XMON just wants a poll. If no character, return -1, else
+ * return the character.
+ */
+ if (!xmon) {
+ while (bdp->status & BD_SC_EMPTY);
+ }
+ else {
+ if (bdp->status & BD_SC_EMPTY)
+ return -1;
+ }
+
+ cp = (char *)bdp->buf;
+
+ if (obuf) {
+ i = c = bdp->length;
+ while (i-- > 0)
+ *obuf++ = *cp++;
+ }
+ else {
+ c = *cp;
+ }
+ bdp->status |= BD_SC_EMPTY;
+
+ if (info) {
+ if (bdp->status & BD_SC_WRAP) {
+ bdp = info->rx_bd_base;
+ }
+ else {
+ bdp++;
+ }
+ info->rx_cur = (QUICC_BD *)bdp;
+ }
+
+ return((int)c);
+}
+
+static int serial_console_wait_key(struct console *co)
+{
+ return(my_console_wait_key(co->index, 0, NULL));
+}
+
+#ifdef CONFIG_XMON
+int
+xmon_360_read_poll(void)
+{
+ return(my_console_wait_key(0, 1, NULL));
+}
+
+int
+xmon_360_read_char(void)
+{
+ return(my_console_wait_key(0, 0, NULL));
+}
+#endif
+
+#ifdef CONFIG_KGDB
+static char kgdb_buf[RX_BUF_SIZE], *kgdp;
+static int kgdb_chars;
+
+unsigned char
+getDebugChar(void)
+{
+ if (kgdb_chars <= 0) {
+ kgdb_chars = my_console_wait_key(0, 0, kgdb_buf);
+ kgdp = kgdb_buf;
+ }
+ kgdb_chars--;
+
+ return(*kgdp++);
+}
+
+void kgdb_interruptible(int state)
+{
+}
+void kgdb_map_scc(void)
+{
+ struct serial_state *ser;
+ uint mem_addr;
+ volatile QUICC_BD *bdp;
+ volatile smc_uart_t *up;
+
+ cpmp = (cpm360_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
+
+ /* To avoid data cache CPM DMA coherency problems, allocate a
+ * buffer in the CPM DPRAM. This will work until the CPM and
+ * serial ports are initialized. At that time a memory buffer
+ * will be allocated.
+ * The port is already initialized from the boot procedure, all
+ * we do here is give it a different buffer and make it a FIFO.
+ */
+
+ ser = rs_table;
+
+ /* Right now, assume we are using SMCs.
+ */
+ up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
+
+ /* Allocate space for an input FIFO, plus a few bytes for output.
+ * Allocate bytes to maintain word alignment.
+ */
+ mem_addr = (uint)(&cpmp->cp_dpmem[0x1000]);
+
+ /* Set the physical address of the host memory buffers in
+ * the buffer descriptors.
+ */
+ bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase];
+ bdp->buf = mem_addr;
+
+ bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_tbase];
+ bdp->buf = mem_addr+RX_BUF_SIZE;
+
+ up->smc_mrblr = RX_BUF_SIZE; /* receive buffer length */
+ up->smc_maxidl = RX_BUF_SIZE;
+}
+#endif
+
+static kdev_t serial_console_device(struct console *c)
+{
+ return MKDEV(TTY_MAJOR, 64 + c->index);
+}
+
+
+struct console sercons = {
+ name: "ttyS",
+ write: serial_console_write,
+ device: serial_console_device,
+ wait_key: serial_console_wait_key,
+ setup: serial_console_setup,
+ flags: CON_PRINTBUFFER,
+ index: CONFIG_SERIAL_CONSOLE_PORT,
+};
+
+
+
+/*
+ * Register console.
+ */
+long console_360_init(long kmem_start, long kmem_end)
+{
+ register_console(&sercons);
+ /*register_console (console_print_68360); - 2.0.38 only required a write
+ function pointer. */
+ return kmem_start;
+}
+
+#endif
+
+/* Index in baud rate table of the default console baud rate.
+*/
+static int baud_idx;
+
+
+/* int __init rs_360_init(void) */
+int rs_360_init(void)
+{
+ struct serial_state * state;
+ ser_info_t *info;
+ void *mem_addr;
+ uint dp_addr, iobits;
+ int i, j, idx;
+ ushort chan;
+ QUICC_BD *bdp;
+ volatile QUICC *cp;
+ volatile struct smc_regs *sp;
+ volatile struct smc_uart_pram *up;
+ volatile struct scc_regs *scp;
+ volatile struct uart_pram *sup;
+ /* volatile immap_t *immap; */
+
+ init_bh(SERIAL_BH, do_serial_bh);
+
+ show_serial_version();
+
+ /* Initialize the tty_driver structure */
+
+ /* __clear_user(&serial_driver,sizeof(struct tty_driver)); */
+ memset(&serial_driver, 0, sizeof(struct tty_driver));
+
+ serial_driver.magic = TTY_DRIVER_MAGIC;
+ /* serial_driver.driver_name = "serial"; */
+ serial_driver.name = "ttyS";
+ serial_driver.major = TTY_MAJOR;
+ serial_driver.minor_start = 64;
+ serial_driver.num = NR_PORTS;
+ serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
+ serial_driver.subtype = SERIAL_TYPE_NORMAL;
+ serial_driver.init_termios = tty_std_termios;
+ serial_driver.init_termios.c_cflag =
+ baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
+ serial_driver.flags = TTY_DRIVER_REAL_RAW;
+ serial_driver.refcount = &serial_refcount;
+ serial_driver.table = serial_table;
+ serial_driver.termios = serial_termios;
+ serial_driver.termios_locked = serial_termios_locked;
+
+ serial_driver.open = rs_360_open;
+ serial_driver.close = rs_360_close;
+ serial_driver.write = rs_360_write;
+ serial_driver.put_char = rs_360_put_char;
+ serial_driver.write_room = rs_360_write_room;
+ serial_driver.chars_in_buffer = rs_360_chars_in_buffer;
+ serial_driver.flush_buffer = rs_360_flush_buffer;
+ serial_driver.ioctl = rs_360_ioctl;
+ serial_driver.throttle = rs_360_throttle;
+ serial_driver.unthrottle = rs_360_unthrottle;
+ /* serial_driver.send_xchar = rs_360_send_xchar; */
+ serial_driver.set_termios = rs_360_set_termios;
+ serial_driver.stop = rs_360_stop;
+ serial_driver.start = rs_360_start;
+ serial_driver.hangup = rs_360_hangup;
+ /* serial_driver.wait_until_sent = rs_360_wait_until_sent; */
+ /* serial_driver.read_proc = rs_360_read_proc; */
+
+ /*
+ * The callout device is just like normal device except for
+ * major number and the subtype code.
+ */
+ callout_driver = serial_driver;
+ callout_driver.name = "cua";
+ callout_driver.major = TTYAUX_MAJOR;
+ callout_driver.subtype = SERIAL_TYPE_CALLOUT;
+ /* callout_driver.read_proc = 0; */
+ /* callout_driver.proc_entry = 0; */
+
+ if (tty_register_driver(&serial_driver))
+ panic("Couldn't register serial driver\n");
+ if (tty_register_driver(&callout_driver))
+ panic("Couldn't register callout driver\n");
+
+ cp = pquicc; /* Get pointer to Communication Processor */
+ /* immap = (immap_t *)IMAP_ADDR; */ /* and to internal registers */
+
+
+ /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
+ */
+ /* The "standard" configuration through the 860.
+ */
+/* immap->im_ioport.iop_papar |= 0x00fc; */
+/* immap->im_ioport.iop_padir &= ~0x00fc; */
+/* immap->im_ioport.iop_paodr &= ~0x00fc; */
+ cp->pio_papar |= 0x00fc;
+ cp->pio_padir &= ~0x00fc;
+ /* cp->pio_paodr &= ~0x00fc; */
+
+
+ /* Since we don't yet do modem control, connect the port C pins
+ * as general purpose I/O. This will assert CTS and CD for the
+ * SCC ports.
+ */
+ /* FIXME: see 360um p.7-365 and 860um p.34-12
+ * I can't make sense of these bits - mleslie*/
+/* immap->im_ioport.iop_pcdir |= 0x03c6; */
+/* immap->im_ioport.iop_pcpar &= ~0x03c6; */
+
+/* cp->pio_pcdir |= 0x03c6; */
+/* cp->pio_pcpar &= ~0x03c6; */
+
+
+
+ /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
+ * BRG4 to SCC3.
+ */
+ cp->si_sicr &= ~0x00ffff00;
+ cp->si_sicr |= 0x001b1200;
+
+#ifdef CONFIG_PP04
+ /* Frequentis PP04 forced to RS-232 until we know better.
+ * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
+ */
+ immap->im_ioport.iop_pcdir |= 0x000c;
+ immap->im_ioport.iop_pcpar &= ~0x000c;
+ immap->im_ioport.iop_pcdat &= ~0x000c;
+
+ /* This enables the TX driver.
+ */
+ cp->cp_pbpar &= ~0x6000;
+ cp->cp_pbdat &= ~0x6000;
+#endif
+
+ for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
+ state->magic = SSTATE_MAGIC;
+ state->line = i;
+ state->type = PORT_UNKNOWN;
+ state->custom_divisor = 0;
+ state->close_delay = 5*HZ/10;
+ state->closing_wait = 30*HZ;
+ state->callout_termios = callout_driver.init_termios;
+ state->normal_termios = serial_driver.init_termios;
+ state->icount.cts = state->icount.dsr =
+ state->icount.rng = state->icount.dcd = 0;
+ state->icount.rx = state->icount.tx = 0;
+ state->icount.frame = state->icount.parity = 0;
+ state->icount.overrun = state->icount.brk = 0;
+ printk(KERN_INFO "ttyS%02d at irq 0x%02x is an %s\n",
+ i, (unsigned int)(state->irq),
+ (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC");
+
+#ifdef CONFIG_SERIAL_CONSOLE
+ /* If we just printed the message on the console port, and
+ * we are about to initialize it for general use, we have
+ * to wait a couple of character times for the CR/NL to
+ * make it out of the transmit buffer.
+ */
+ if (i == CONFIG_SERIAL_CONSOLE_PORT)
+ mdelay(8);
+
+
+/* idx = PORT_NUM(info->state->smc_scc_num); */
+/* if (info->state->smc_scc_num & NUM_IS_SCC) */
+/* chan = scc_chan_map[idx]; */
+/* else */
+/* chan = smc_chan_map[idx]; */
+
+/* cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG; */
+/* while (cp->cp_cr & CPM_CR_FLG); */
+
+#endif
+ /* info = kmalloc(sizeof(ser_info_t), GFP_KERNEL); */
+ info = &quicc_ser_info[i];
+ if (info) {
+ /* __clear_user(info,sizeof(ser_info_t)); */
+ memset (info, 0, sizeof(ser_info_t));
+ init_waitqueue_head(&info->open_wait);
+ init_waitqueue_head(&info->close_wait);
+ info->magic = SERIAL_MAGIC;
+ info->flags = state->flags;
+ info->tqueue.routine = do_softint;
+ info->tqueue.data = info;
+ info->tqueue_hangup.routine = do_serial_hangup;
+ info->tqueue_hangup.data = info;
+ info->line = i;
+ info->state = state;
+ state->info = (struct async_struct *)info;
+
+ /* We need to allocate a transmit and receive buffer
+ * descriptors from dual port ram, and a character
+ * buffer area from host mem.
+ */
+ dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * RX_NUM_FIFO);
+
+ /* Allocate space for FIFOs in the host memory.
+ * (for now this is from a static array of buffers :(
+ */
+ /* mem_addr = m360_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE); */
+ /* mem_addr = kmalloc (RX_NUM_FIFO * RX_BUF_SIZE, GFP_BUFFER); */
+ mem_addr = &rx_buf_pool[i * RX_NUM_FIFO * RX_BUF_SIZE];
+
+ /* Set the physical address of the host memory
+ * buffers in the buffer descriptors, and the
+ * virtual address for us to work with.
+ */
+ bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
+ info->rx_cur = info->rx_bd_base = bdp;
+
+ /* initialize rx buffer descriptors */
+ for (j=0; j<(RX_NUM_FIFO-1); j++) {
+ bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
+ bdp->status = BD_SC_EMPTY | BD_SC_INTRPT;
+ mem_addr += RX_BUF_SIZE;
+ bdp++;
+ }
+ bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
+ bdp->status = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
+
+
+ idx = PORT_NUM(info->state->smc_scc_num);
+ if (info->state->smc_scc_num & NUM_IS_SCC) {
+
+#if defined (CONFIG_UCQUICC) && 1
+ /* set the transceiver mode to RS232 */
+ sipex_mode_bits &= ~(uint)SIPEX_MODE(idx,0x0f); /* clear current mode */
+ sipex_mode_bits |= (uint)SIPEX_MODE(idx,0x02);
+ *(uint *)_periph_base = sipex_mode_bits;
+ /* printk ("sipex bits = 0x%08x\n", sipex_mode_bits); */
+#endif
+
+ scp = &pquicc->scc_regs[idx];
+ sup = &pquicc->pram[info->state->port].scc.pscc.u;
+ sup->rbase = dp_addr;
+ }
+ else {
+ sp = &cp->smc_regs[idx];
+ up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
+ up->rbase = dp_addr;
+ }
+
+ dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * TX_NUM_FIFO);
+
+ /* Allocate space for FIFOs in the host memory.
+ */
+ /* mem_addr = m360_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE); */
+ /* mem_addr = kmalloc (TX_NUM_FIFO * TX_BUF_SIZE, GFP_BUFFER); */
+ mem_addr = &tx_buf_pool[i * TX_NUM_FIFO * TX_BUF_SIZE];
+
+ /* Set the physical address of the host memory
+ * buffers in the buffer descriptors, and the
+ * virtual address for us to work with.
+ */
+ /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
+ bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
+ info->tx_cur = info->tx_bd_base = (QUICC_BD *)bdp;
+
+ /* initialize tx buffer descriptors */
+ for (j=0; j<(TX_NUM_FIFO-1); j++) {
+ bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
+ bdp->status = BD_SC_INTRPT;
+ mem_addr += TX_BUF_SIZE;
+ bdp++;
+ }
+ bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
+ bdp->status = (BD_SC_WRAP | BD_SC_INTRPT);
+
+ if (info->state->smc_scc_num & NUM_IS_SCC) {
+ sup->tbase = dp_addr;
+
+ /* Set up the uart parameters in the
+ * parameter ram.
+ */
+ sup->rfcr = SMC_EB;
+ sup->tfcr = SMC_EB;
+
+ /* Set this to 1 for now, so we get single
+ * character interrupts. Using idle charater
+ * time requires some additional tuning.
+ */
+ sup->mrblr = 1;
+ sup->max_idl = 0;
+ sup->brkcr = 1;
+ sup->parec = 0;
+ sup->frmer = 0;
+ sup->nosec = 0;
+ sup->brkec = 0;
+ sup->uaddr1 = 0;
+ sup->uaddr2 = 0;
+ sup->toseq = 0;
+ {
+ int i;
+ for (i=0;i<8;i++)
+ sup->cc[i] = 0x8000;
+ }
+ sup->rccm = 0xc0ff;
+
+ /* Send the CPM an initialize command.
+ */
+ chan = scc_chan_map[idx];
+
+ /* execute the INIT RX & TX PARAMS command for this channel. */
+ cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
+ while (cp->cp_cr & CPM_CR_FLG);
+
+ /* Set UART mode, 8 bit, no parity, one stop.
+ * Enable receive and transmit.
+ */
+ scp->scc_gsmr.w.high = 0;
+ scp->scc_gsmr.w.low =
+ (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
+
+ /* Disable all interrupts and clear all pending
+ * events.
+ */
+ scp->scc_sccm = 0;
+ scp->scc_scce = 0xffff;
+ scp->scc_dsr = 0x7e7e;
+ scp->scc_psmr = 0x3000;
+
+ /* If the port is the console, enable Rx and Tx.
+ */
+#ifdef CONFIG_SERIAL_CONSOLE
+ if (i == CONFIG_SERIAL_CONSOLE_PORT)
+ scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
+#endif
+ }
+ else {
+ /* Configure SMCs Tx/Rx instead of port B
+ * parallel I/O.
+ */
+
+ iobits = 0xc0 << (idx * 4);
+ cp->pip_pbpar |= iobits;
+ cp->pip_pbdir &= ~iobits;
+ cp->pip_pbodr &= ~iobits;
+
+
+ /* Connect the baud rate generator to the
+ * SMC based upon index in rs_table. Also
+ * make sure it is connected to NMSI.
+ */
+ cp->si_simode &= ~(0xffff << (idx * 16));
+ cp->si_simode |= (i << ((idx * 16) + 12));
+
+ up->tbase = dp_addr;
+
+ /* Set up the uart parameters in the
+ * parameter ram.
+ */
+ up->rfcr = SMC_EB;
+ up->tfcr = SMC_EB;
+
+ /* Set this to 1 for now, so we get single
+ * character interrupts. Using idle charater
+ * time requires some additional tuning.
+ */
+ up->mrblr = 1;
+ up->max_idl = 0;
+ up->brkcr = 1;
+
+ /* Send the CPM an initialize command.
+ */
+ chan = smc_chan_map[idx];
+
+ cp->cp_cr = mk_cr_cmd(chan,
+ CPM_CR_INIT_TRX) | CPM_CR_FLG;
+#ifdef CONFIG_SERIAL_CONSOLE
+ if (i == CONFIG_SERIAL_CONSOLE_PORT)
+ printk("");
+#endif
+ while (cp->cp_cr & CPM_CR_FLG);
+
+ /* Set UART mode, 8 bit, no parity, one stop.
+ * Enable receive and transmit.
+ */
+ sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
+
+ /* Disable all interrupts and clear all pending
+ * events.
+ */
+ sp->smc_smcm = 0;
+ sp->smc_smce = 0xff;
+
+ /* If the port is the console, enable Rx and Tx.
+ */
+#ifdef CONFIG_SERIAL_CONSOLE
+ if (i == CONFIG_SERIAL_CONSOLE_PORT)
+ sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
+#endif
+ }
+
+ /* Install interrupt handler.
+ */
+ /* cpm_install_handler(IRQ_MACHSPEC | state->irq, rs_360_interrupt, info); */
+ /*request_irq(IRQ_MACHSPEC | state->irq, rs_360_interrupt, */
+ request_irq(state->irq, rs_360_interrupt,
+ IRQ_FLG_LOCK, serial_driver.name, (void *)info);
+
+ /* Set up the baud rate generator.
+ */
+ m360_cpm_setbrg(i, baud_table[baud_idx]);
+
+ }
+ }
+
+ return 0;
+}
+
+
+
+
+
+/* This must always be called before the rs_360_init() function, otherwise
+ * it blows away the port control information.
+ */
+//static int __init serial_console_setup( struct console *co, char *options)
+int serial_console_setup( struct console *co, char *options)
+{
+ struct serial_state *ser;
+ uint mem_addr, dp_addr, bidx, idx, iobits;
+ int i;
+ ushort chan;
+ QUICC_BD *bdp;
+ volatile QUICC *cp;
+ volatile struct smc_regs *sp;
+ volatile struct scc_regs *scp;
+ volatile struct smc_uart_pram *up;
+ volatile struct uart_pram *sup;
+
+/* mleslie TODO:
+ * add something to the 68k bootloader to store a desired initial console baud rate */
+
+/* bd_t *bd; */ /* a board info struct used by EPPC-bug */
+/* bd = (bd_t *)__res; */
+
+ for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
+ /* if (bd->bi_baudrate == baud_table[bidx]) */
+ if (CONSOLE_BAUDRATE == baud_table[bidx])
+ break;
+
+ /* co->cflag = CREAD|CLOCAL|bidx|CS8; */
+ baud_idx = bidx;
+
+ ser = rs_table + CONFIG_SERIAL_CONSOLE_PORT;
+
+ cp = pquicc; /* Get pointer to Communication Processor */
+
+ idx = PORT_NUM(ser->smc_scc_num);
+ if (ser->smc_scc_num & NUM_IS_SCC) {
+ scp = &cp->scc_regs[idx];
+ /* sup = (scc_uart_t *)&cp->cp_dparam[ser->port]; */
+ sup = &pquicc->pram[ser->port].scc.pscc.u;
+
+ /* TODO: need to set up SCC pin assignment etc. here */
+
+ }
+ else {
+ sp = &cp->smc_regs[idx];
+ /* up = (smc_uart_t *)&cp->cp_dparam[ser->port]; */
+ up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
+
+ iobits = 0xc0 << (idx * 4);
+ cp->pip_pbpar |= iobits;
+ cp->pip_pbdir &= ~iobits;
+ cp->pip_pbodr &= ~iobits;
+
+ /* Connect the baud rate generator to the
+ * SMC based upon index in rs_table. Also
+ * make sure it is connected to NMSI.
+ */
+ cp->si_simode &= ~(0xffff << (idx * 16));
+ cp->si_simode |= (idx << ((idx * 16) + 12));
+ }
+
+ /* When we get here, the CPM has been reset, so we need
+ * to configure the port.
+ * We need to allocate a transmit and receive buffer descriptor
+ * from dual port ram, and a character buffer area from host mem.
+ */
+
+ /* Allocate space for two buffer descriptors in the DP ram.
+ */
+ dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * CONSOLE_NUM_FIFO);
+
+ /* Allocate space for two 2 byte FIFOs in the host memory.
+ */
+ /* mem_addr = m360_cpm_hostalloc(8); */
+ mem_addr = (uint)console_fifos;
+
+
+ /* Set the physical address of the host memory buffers in
+ * the buffer descriptors.
+ */
+ /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
+ bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
+ bdp->buf = (char *)mem_addr;
+ (bdp+1)->buf = (char *)(mem_addr+4);
+
+ /* For the receive, set empty and wrap.
+ * For transmit, set wrap.
+ */
+ bdp->status = BD_SC_EMPTY | BD_SC_WRAP;
+ (bdp+1)->status = BD_SC_WRAP;
+
+ /* Set up the uart parameters in the parameter ram.
+ */
+ if (ser->smc_scc_num & NUM_IS_SCC) {
+
+ sup->rbase = dp_addr;
+ sup->tbase = dp_addr + sizeof(QUICC_BD);
+
+ /* Set up the uart parameters in the
+ * parameter ram.
+ */
+ sup->rfcr = SMC_EB;
+ sup->tfcr = SMC_EB;
+
+ /* Set this to 1 for now, so we get single
+ * character interrupts. Using idle charater
+ * time requires some additional tuning.
+ */
+ sup->mrblr = 1;
+ sup->max_idl = 0;
+ sup->brkcr = 1;
+ sup->parec = 0;
+ sup->frmer = 0;
+ sup->nosec = 0;
+ sup->brkec = 0;
+ sup->uaddr1 = 0;
+ sup->uaddr2 = 0;
+ sup->toseq = 0;
+ {
+ int i;
+ for (i=0;i<8;i++)
+ sup->cc[i] = 0x8000;
+ }
+ sup->rccm = 0xc0ff;
+
+ /* Send the CPM an initialize command.
+ */
+ chan = scc_chan_map[idx];
+
+ cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
+ while (cp->cp_cr & CPM_CR_FLG);
+
+ /* Set UART mode, 8 bit, no parity, one stop.
+ * Enable receive and transmit.
+ */
+ scp->scc_gsmr.w.high = 0;
+ scp->scc_gsmr.w.low =
+ (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
+
+ /* Disable all interrupts and clear all pending
+ * events.
+ */
+ scp->scc_sccm = 0;
+ scp->scc_scce = 0xffff;
+ scp->scc_dsr = 0x7e7e;
+ scp->scc_psmr = 0x3000;
+
+ scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
+
+ }
+ else {
+ up->rbase = dp_addr; /* Base of receive buffer desc. */
+ up->tbase = dp_addr+sizeof(QUICC_BD); /* Base of xmt buffer desc. */
+ up->rfcr = SMC_EB;
+ up->tfcr = SMC_EB;
+
+ /* Set this to 1 for now, so we get single character interrupts.
+ */
+ up->mrblr = 1; /* receive buffer length */
+ up->max_idl = 0; /* wait forever for next char */
+
+ /* Send the CPM an initialize command.
+ */
+ chan = smc_chan_map[idx];
+ cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
+ printk("");
+ while (cp->cp_cr & CPM_CR_FLG);
+
+ /* Set UART mode, 8 bit, no parity, one stop.
+ * Enable receive and transmit.
+ */
+ sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
+
+ /* And finally, enable Rx and Tx.
+ */
+ sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
+ }
+
+ /* Set up the baud rate generator.
+ */
+ /* m360_cpm_setbrg((ser - rs_table), bd->bi_baudrate); */
+ m360_cpm_setbrg((ser - rs_table), CONSOLE_BAUDRATE);
+
+ return 0;
+}
+
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
(PCI) UltraSPARC systems. Say Y or M if you want to be able to these
serial ports.
+config V850E_NB85E_UART
+ bool "NEC V850E on-chip UART support"
+ depends on V850E_NB85E || V850E2_ANNA
+ default y
+
+config V850E_NB85E_UART_CONSOLE
+ bool "Use NEC V850E on-chip UART for console"
+ depends on V850E_NB85E_UART
+
config SERIAL_CORE
tristate
- default m if SERIAL_AMBA!=y && SERIAL_CLPS711X!=y && SERIAL_21285!=y && !SERIAL_SA1100 && !SERIAL_ANAKIN && !SERIAL_UART00 && SERIAL_8250!=y && !SERIAL_ROCKETPORT && !SERIAL_SUNCORE && (SERIAL_AMBA=m || SERIAL_CLPS711X=m || SERIAL_21285=m || SERIAL_8250=m)
- default y if SERIAL_AMBA=y || SERIAL_CLPS711X=y || SERIAL_21285=y || SERIAL_SA1100 || SERIAL_ANAKIN || SERIAL_UART00 || SERIAL_8250=y || SERIAL_ROCKETPORT || SERIAL_SUNCORE
+ default m if SERIAL_AMBA!=y && SERIAL_CLPS711X!=y && SERIAL_21285!=y && !SERIAL_SA1100 && !SERIAL_ANAKIN && !SERIAL_UART00 && SERIAL_8250!=y && !SERIAL_ROCKETPORT && !SERIAL_SUNCORE && !V850E_NB85E_UART && (SERIAL_AMBA=m || SERIAL_CLPS711X=m || SERIAL_21285=m || SERIAL_8250=m)
+ default y if SERIAL_AMBA=y || SERIAL_CLPS711X=y || SERIAL_21285=y || SERIAL_SA1100 || SERIAL_ANAKIN || SERIAL_UART00 || SERIAL_8250=y || SERIAL_ROCKETPORT || SERIAL_SUNCORE || V850E_NB85E_UART
config SERIAL_CORE_CONSOLE
bool
- depends on SERIAL_AMBA_CONSOLE || SERIAL_CLPS711X_CONSOLE || SERIAL_21285_CONSOLE || SERIAL_SA1100_CONSOLE || SERIAL_ANAKIN_CONSOLE || SERIAL_UART00_CONSOLE || SERIAL_8250_CONSOLE || SERIAL_SUNCORE
+ depends on SERIAL_AMBA_CONSOLE || SERIAL_CLPS711X_CONSOLE || SERIAL_21285_CONSOLE || SERIAL_SA1100_CONSOLE || SERIAL_ANAKIN_CONSOLE || SERIAL_UART00_CONSOLE || SERIAL_8250_CONSOLE || SERIAL_SUNCORE || V850E_NB85E_UART_CONSOLE
default y
+config SERIAL_68328
+ bool "68328 serial support"
+ depends on M68328 || M68EZ328 || M68VZ328
+ help
+ This driver supports the built-in serial port of the Motorola 68328
+ (standard, EZ and VZ varities).
+
+config SERIAL_68328_RTS_CTS
+ bool "Support RTS/CTS on 68328 serial port"
+ depends on SERIAL_68328
+
+config SERIAL_COLDFIRE
+ bool "ColdFire serial support"
+ depends on COLDFIRE
+ help
+ This driver supports the built-in serial ports of the Motorola ColdFire
+ family of CPUs.
+
+config SERIAL_68360_SMC
+ bool "68360 SMC uart support"
+ depends on M68360
+ help
+ This driver supports the SMC serial ports of the Motorola 68360 CPU.
+
+config SERIAL_68360_SCC
+ bool "68360 SCC uart support"
+ depends on M68360
+ help
+ This driver supports the SCC serial ports of the Motorola 68360 CPU.
+
+config 68360_SERIAL
+ bool
+ depends on SERIAL_68360_SMC || SERIAL_68630_SCC
+
endmenu
obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
obj-$(CONFIG_SERIAL_SUNSU) += sunsu.o
obj-$(CONFIG_SERIAL_SUNSAB) += sunsab.o
+obj-$(CONFIG_SERIAL_68328) += 68328serial.o
+obj-$(CONFIG_SERIAL_68360) += 68360serial.o
+obj-$(CONFIG_SERIAL_COLDFIRE) += mcfserial.o
+obj-$(CONFIG_V850E_NB85E_UART) += nb85e_uart.o
include $(TOPDIR)/Rules.make
--- /dev/null
+/*
+ * mcfserial.c -- serial driver for ColdFire internal UARTS.
+ *
+ * Copyright (C) 1999-2002 Greg Ungerer <gerg@snapgear.com>
+ * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
+ * Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com>
+ *
+ * Based on code from 68332serial.c which was:
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ * Copyright (C) 1998 TSHG
+ * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/timer.h>
+#include <linux/wait.h>
+#include <linux/interrupt.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/config.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/fcntl.h>
+#include <linux/mm.h>
+#include <linux/kernel.h>
+#include <linux/serial.h>
+#include <linux/serialP.h>
+#ifdef CONFIG_LEDMAN
+#include <linux/ledman.h>
+#endif
+#include <linux/console.h>
+#include <linux/version.h>
+#include <linux/init.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/system.h>
+#include <asm/segment.h>
+#include <asm/semaphore.h>
+#include <asm/bitops.h>
+#include <asm/delay.h>
+#include <asm/coldfire.h>
+#include <asm/mcfsim.h>
+#include <asm/mcfuart.h>
+#include <asm/nettel.h>
+#include <asm/uaccess.h>
+#include "mcfserial.h"
+
+/*
+ * the only event we use
+ */
+#undef RS_EVENT_WRITE_WAKEUP
+#define RS_EVENT_WRITE_WAKEUP 0
+
+struct timer_list mcfrs_timer_struct;
+
+/*
+ * Default console baud rate, we use this as the default
+ * for all ports so init can just open /dev/console and
+ * keep going. Perhaps one day the cflag settings for the
+ * console can be used instead.
+ */
+#if defined(CONFIG_ARNEWSH) || defined(CONFIG_MOTOROLA) || defined(CONFIG_senTec)
+#define CONSOLE_BAUD_RATE 19200
+#define DEFAULT_CBAUD B19200
+#endif
+
+#ifndef CONSOLE_BAUD_RATE
+#define CONSOLE_BAUD_RATE 9600
+#define DEFAULT_CBAUD B9600
+#endif
+
+int mcfrs_console_inited = 0;
+int mcfrs_console_port = -1;
+int mcfrs_console_baud = CONSOLE_BAUD_RATE;
+int mcfrs_console_cbaud = DEFAULT_CBAUD;
+
+/*
+ * Driver data structures.
+ */
+struct tty_driver mcfrs_serial_driver, mcfrs_callout_driver;
+static int mcfrs_serial_refcount;
+
+/* serial subtype definitions */
+#define SERIAL_TYPE_NORMAL 1
+#define SERIAL_TYPE_CALLOUT 2
+
+/* number of characters left in xmit buffer before we ask for more */
+#define WAKEUP_CHARS 256
+
+/* Debugging...
+ */
+#undef SERIAL_DEBUG_OPEN
+#undef SERIAL_DEBUG_FLOW
+
+#define _INLINE_ inline
+
+#define IRQBASE 73
+
+/*
+ * Configuration table, UARTs to look for at startup.
+ */
+static struct mcf_serial mcfrs_table[] = {
+ { 0, (MCF_MBAR+MCFUART_BASE1), IRQBASE, ASYNC_BOOT_AUTOCONF }, /* ttyS0 */
+ { 0, (MCF_MBAR+MCFUART_BASE2), IRQBASE+1, ASYNC_BOOT_AUTOCONF }, /* ttyS1 */
+};
+
+
+#define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
+
+static struct tty_struct *mcfrs_serial_table[NR_PORTS];
+static struct termios *mcfrs_serial_termios[NR_PORTS];
+static struct termios *mcfrs_serial_termios_locked[NR_PORTS];
+
+/*
+ * This is used to figure out the divisor speeds and the timeouts.
+ */
+static int mcfrs_baud_table[] = {
+ 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
+ 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
+};
+#define MCFRS_BAUD_TABLE_SIZE \
+ (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
+
+
+#ifdef CONFIG_MAGIC_SYSRQ
+/*
+ * Magic system request keys. Used for debugging...
+ */
+extern int magic_sysrq_key(int ch);
+#endif
+
+
+/*
+ * tmp_buf is used as a temporary buffer by serial_write. We need to
+ * lock it in case the copy_from_user 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 mcfrs_tmp_buf[4096]; /* This is cheating */
+static DECLARE_MUTEX(mcfrs_tmp_buf_sem);
+
+/*
+ * Forware declarations...
+ */
+static void mcfrs_change_speed(struct mcf_serial *info);
+
+
+static inline int serial_paranoia_check(struct mcf_serial *info,
+ kdev_t device, const char *routine)
+{
+#ifdef SERIAL_PARANOIA_CHECK
+ static const char *badmagic =
+ "MCFRS(warning): bad magic number for serial struct (%d, %d) in %s\n";
+ static const char *badinfo =
+ "MCFRS(warning): null mcf_serial for (%d, %d) in %s\n";
+
+ if (!info) {
+ printk(badinfo, MAJOR(device), MINOR(device), routine);
+ return 1;
+ }
+ if (info->magic != SERIAL_MAGIC) {
+ printk(badmagic, MAJOR(device), MINOR(device), routine);
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+/*
+ * Sets or clears DTR and RTS on the requested line.
+ */
+static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts)
+{
+ volatile unsigned char *uartp;
+ unsigned long flags;
+
+#if 0
+ printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
+ __FILE__, __LINE__, info, dtr, rts);
+#endif
+
+ local_irq_save(flags);
+ if (dtr >= 0) {
+#ifdef MCFPP_DTR0
+ if (info->line)
+ mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1));
+ else
+ mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0));
+#endif
+ }
+ if (rts >= 0) {
+ uartp = (volatile unsigned char *) info->addr;
+ if (rts) {
+ info->sigs |= TIOCM_RTS;
+ uartp[MCFUART_UOP1] = MCFUART_UOP_RTS;
+ } else {
+ info->sigs &= ~TIOCM_RTS;
+ uartp[MCFUART_UOP0] = MCFUART_UOP_RTS;
+ }
+ }
+ local_irq_restore(flags);
+ return;
+}
+
+/*
+ * Gets values of serial signals.
+ */
+static int mcfrs_getsignals(struct mcf_serial *info)
+{
+ volatile unsigned char *uartp;
+ unsigned long flags;
+ int sigs;
+#if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
+ unsigned short ppdata;
+#endif
+
+#if 0
+ printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__);
+#endif
+
+ local_irq_save(flags);
+ uartp = (volatile unsigned char *) info->addr;
+ sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS;
+ sigs |= (info->sigs & TIOCM_RTS);
+
+#ifdef MCFPP_DCD0
+{
+ unsigned int ppdata;
+ ppdata = mcf_getppdata();
+ if (info->line == 0) {
+ sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD;
+ sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR;
+ } else if (info->line == 1) {
+ sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD;
+ sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR;
+ }
+}
+#endif
+
+ local_irq_restore(flags);
+ return(sigs);
+}
+
+/*
+ * ------------------------------------------------------------
+ * mcfrs_stop() and mcfrs_start()
+ *
+ * This routines are called before setting or resetting tty->stopped.
+ * They enable or disable transmitter interrupts, as necessary.
+ * ------------------------------------------------------------
+ */
+static void mcfrs_stop(struct tty_struct *tty)
+{
+ volatile unsigned char *uartp;
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_stop"))
+ return;
+
+ local_irq_save(flags);
+ uartp = (volatile unsigned char *) info->addr;
+ info->imr &= ~MCFUART_UIR_TXREADY;
+ uartp[MCFUART_UIMR] = info->imr;
+ local_irq_restore(flags);
+}
+
+static void mcfrs_start(struct tty_struct *tty)
+{
+ volatile unsigned char *uartp;
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_start"))
+ return;
+
+ local_irq_save(flags);
+ if (info->xmit_cnt && info->xmit_buf) {
+ uartp = (volatile unsigned char *) info->addr;
+ info->imr |= MCFUART_UIR_TXREADY;
+ uartp[MCFUART_UIMR] = info->imr;
+ }
+ local_irq_restore(flags);
+}
+
+/*
+ * ----------------------------------------------------------------------
+ *
+ * Here starts the interrupt handling routines. All of the following
+ * subroutines are declared as inline and are folded into
+ * mcfrs_interrupt(). They were separated out for readability's sake.
+ *
+ * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
+ * runs with interrupts turned off. People who may want to modify
+ * mcfrs_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
+ * -----------------------------------------------------------------------
+ */
+
+static _INLINE_ void receive_chars(struct mcf_serial *info, struct pt_regs *regs, unsigned short rx)
+{
+ volatile unsigned char *uartp;
+ struct tty_struct *tty = info->tty;
+ unsigned char status, ch;
+
+ if (!tty)
+ return;
+
+#if defined(CONFIG_LEDMAN)
+ ledman_cmd(LEDMAN_CMD_SET, info->line ? LEDMAN_COM2_RX : LEDMAN_COM1_RX);
+#endif
+
+ uartp = (volatile unsigned char *) info->addr;
+
+ while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
+
+ if (tty->flip.count >= TTY_FLIPBUF_SIZE)
+ break;
+
+ ch = uartp[MCFUART_URB];
+ info->stats.rx++;
+
+#ifdef CONFIG_MAGIC_SYSRQ
+ if (mcfrs_console_inited && (info->line == mcfrs_console_port)) {
+ if (magic_sysrq_key(ch))
+ continue;
+ }
+#endif
+
+ tty->flip.count++;
+ if (status & MCFUART_USR_RXERR)
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
+ if (status & MCFUART_USR_RXBREAK) {
+ info->stats.rxbreak++;
+ *tty->flip.flag_buf_ptr++ = TTY_BREAK;
+ } else if (status & MCFUART_USR_RXPARITY) {
+ info->stats.rxparity++;
+ *tty->flip.flag_buf_ptr++ = TTY_PARITY;
+ } else if (status & MCFUART_USR_RXOVERRUN) {
+ info->stats.rxoverrun++;
+ *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
+ } else if (status & MCFUART_USR_RXFRAMING) {
+ info->stats.rxframing++;
+ *tty->flip.flag_buf_ptr++ = TTY_FRAME;
+ } else {
+ *tty->flip.flag_buf_ptr++ = 0;
+ }
+ *tty->flip.char_buf_ptr++ = ch;
+ }
+
+ schedule_work(&tty->flip.work);
+ return;
+}
+
+static _INLINE_ void transmit_chars(struct mcf_serial *info)
+{
+ volatile unsigned char *uartp;
+
+#if defined(CONFIG_LEDMAN)
+ ledman_cmd(LEDMAN_CMD_SET, info->line ? LEDMAN_COM2_TX : LEDMAN_COM1_TX);
+#endif
+
+ uartp = (volatile unsigned char *) info->addr;
+
+ if (info->x_char) {
+ /* Send special char - probably flow control */
+ uartp[MCFUART_UTB] = info->x_char;
+ info->x_char = 0;
+ info->stats.tx++;
+ }
+
+ if ((info->xmit_cnt <= 0) || info->tty->stopped) {
+ info->imr &= ~MCFUART_UIR_TXREADY;
+ uartp[MCFUART_UIMR] = info->imr;
+ return;
+ }
+
+ while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
+ uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
+ info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
+ info->stats.tx++;
+ if (--info->xmit_cnt <= 0)
+ break;
+ }
+
+ if (info->xmit_cnt < WAKEUP_CHARS)
+ schedule_work(&info->tqueue);
+ return;
+}
+
+/*
+ * This is the serial driver's generic interrupt routine
+ */
+void mcfrs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ struct mcf_serial *info;
+ unsigned char isr;
+
+ info = &mcfrs_table[(irq - IRQBASE)];
+ isr = (((volatile unsigned char *)info->addr)[MCFUART_UISR]) & info->imr;
+
+ if (isr & MCFUART_UIR_RXREADY)
+ receive_chars(info, regs, isr);
+ if (isr & MCFUART_UIR_TXREADY)
+ transmit_chars(info);
+#if 0
+ if (isr & MCFUART_UIR_DELTABREAK) {
+ printk("%s(%d): delta break!\n", __FILE__, __LINE__);
+ receive_chars(info, regs, isr);
+ }
+#endif
+
+ return;
+}
+
+/*
+ * -------------------------------------------------------------------
+ * Here ends the serial interrupt routines.
+ * -------------------------------------------------------------------
+ */
+
+static void mcfrs_offintr(void *private)
+{
+ struct mcf_serial *info = (struct mcf_serial *) private;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (!tty)
+ return;
+
+ if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
+ if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+ tty->ldisc.write_wakeup)
+ (tty->ldisc.write_wakeup)(tty);
+ wake_up_interruptible(&tty->write_wait);
+ }
+}
+
+
+/*
+ * Change of state on a DCD line.
+ */
+void mcfrs_modem_change(struct mcf_serial *info, int dcd)
+{
+ if (info->count == 0)
+ return;
+
+ if (info->flags & ASYNC_CHECK_CD) {
+ if (dcd) {
+ wake_up_interruptible(&info->open_wait);
+ } else if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ (info->flags & ASYNC_CALLOUT_NOHUP))) {
+ schedule_work(&info->tqueue_hangup);
+ }
+ }
+}
+
+
+#ifdef MCFPP_DCD0
+
+unsigned short mcfrs_ppstatus;
+
+/*
+ * This subroutine is called when the RS_TIMER goes off. It is used
+ * to monitor the state of the DCD lines - since they have no edge
+ * sensors and interrupt generators.
+ */
+static void mcfrs_timer(void)
+{
+ unsigned int ppstatus, dcdval, i;
+
+ ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
+
+ if (ppstatus != mcfrs_ppstatus) {
+ for (i = 0; (i < 2); i++) {
+ dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
+ if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
+ mcfrs_modem_change(&mcfrs_table[i],
+ ((ppstatus & dcdval) ? 0 : 1));
+ }
+ }
+ }
+ mcfrs_ppstatus = ppstatus;
+
+ /* Re-arm timer */
+ mcfrs_timer_struct.expires = jiffies + HZ/25;
+ add_timer(&mcfrs_timer_struct);
+}
+
+#endif /* MCFPP_DCD0 */
+
+
+/*
+ * 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() -> mcfrs_hangup()
+ *
+ */
+static void do_serial_hangup(void *private)
+{
+ struct mcf_serial *info = (struct mcf_serial *) private;
+ struct tty_struct *tty;
+
+ tty = info->tty;
+ if (!tty)
+ return;
+
+ tty_hangup(tty);
+}
+
+static int startup(struct mcf_serial * info)
+{
+ volatile unsigned char *uartp;
+ unsigned long flags;
+
+ if (info->flags & ASYNC_INITIALIZED)
+ return 0;
+
+ if (!info->xmit_buf) {
+ info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
+ if (!info->xmit_buf)
+ return -ENOMEM;
+ }
+
+ local_irq_save(flags);
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
+#endif
+
+ /*
+ * Reset UART, get it into known state...
+ */
+ uartp = (volatile unsigned char *) info->addr;
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
+ mcfrs_setsignals(info, 1, 1);
+
+ if (info->tty)
+ clear_bit(TTY_IO_ERROR, &info->tty->flags);
+ info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
+
+ /*
+ * and set the speed of the serial port
+ */
+ mcfrs_change_speed(info);
+
+ /*
+ * Lastly enable the UART transmitter and receiver, and
+ * interrupt enables.
+ */
+ info->imr = MCFUART_UIR_RXREADY;
+ uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
+ uartp[MCFUART_UIMR] = info->imr;
+
+ info->flags |= ASYNC_INITIALIZED;
+ local_irq_restore(flags);
+ return 0;
+}
+
+/*
+ * 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 mcf_serial * info)
+{
+ volatile unsigned char *uartp;
+ unsigned long flags;
+
+ if (!(info->flags & ASYNC_INITIALIZED))
+ return;
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("Shutting down serial port %d (irq %d)....\n", info->line,
+ info->irq);
+#endif
+
+ local_irq_save(flags);
+
+ uartp = (volatile unsigned char *) info->addr;
+ uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
+
+ if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
+ mcfrs_setsignals(info, 0, 0);
+
+ if (info->xmit_buf) {
+ free_page((unsigned long) info->xmit_buf);
+ info->xmit_buf = 0;
+ }
+
+ if (info->tty)
+ set_bit(TTY_IO_ERROR, &info->tty->flags);
+
+ info->flags &= ~ASYNC_INITIALIZED;
+ local_irq_restore(flags);
+}
+
+
+/*
+ * This routine is called to set the UART divisor registers to match
+ * the specified baud rate for a serial port.
+ */
+static void mcfrs_change_speed(struct mcf_serial *info)
+{
+ volatile unsigned char *uartp;
+ unsigned int baudclk, cflag;
+ unsigned long flags;
+ unsigned char mr1, mr2;
+ int i;
+
+ if (!info->tty || !info->tty->termios)
+ return;
+ cflag = info->tty->termios->c_cflag;
+ if (info->addr == 0)
+ return;
+
+#if 0
+ printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
+#endif
+
+ i = cflag & CBAUD;
+ if (i & CBAUDEX) {
+ i &= ~CBAUDEX;
+ if (i < 1 || i > 4)
+ info->tty->termios->c_cflag &= ~CBAUDEX;
+ else
+ i += 15;
+ }
+ if (i == 0) {
+ mcfrs_setsignals(info, 0, -1);
+ return;
+ }
+ baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
+ info->baud = mcfrs_baud_table[i];
+
+ mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
+ mr2 = 0;
+
+ switch (cflag & CSIZE) {
+ case CS5: mr1 |= MCFUART_MR1_CS5; break;
+ case CS6: mr1 |= MCFUART_MR1_CS6; break;
+ case CS7: mr1 |= MCFUART_MR1_CS7; break;
+ case CS8:
+ default: mr1 |= MCFUART_MR1_CS8; break;
+ }
+
+ if (cflag & PARENB) {
+ if (cflag & PARODD)
+ mr1 |= MCFUART_MR1_PARITYODD;
+ else
+ mr1 |= MCFUART_MR1_PARITYEVEN;
+ } else {
+ mr1 |= MCFUART_MR1_PARITYNONE;
+ }
+
+ if (cflag & CSTOPB)
+ mr2 |= MCFUART_MR2_STOP2;
+ else
+ mr2 |= MCFUART_MR2_STOP1;
+
+ if (cflag & CRTSCTS) {
+ mr1 |= MCFUART_MR1_RXRTS;
+ mr2 |= MCFUART_MR2_TXCTS;
+ }
+
+ if (cflag & CLOCAL)
+ info->flags &= ~ASYNC_CHECK_CD;
+ else
+ info->flags |= ASYNC_CHECK_CD;
+
+ uartp = (volatile unsigned char *) info->addr;
+
+ local_irq_save(flags);
+#if 0
+ printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
+ mr1, mr2, baudclk);
+#endif
+ /*
+ Note: pg 12-16 of MCF5206e User's Manual states that a
+ software reset should be performed prior to changing
+ UMR1,2, UCSR, UACR, bit 7
+ */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
+ uartp[MCFUART_UMR] = mr1;
+ uartp[MCFUART_UMR] = mr2;
+ uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
+ uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
+ uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
+ uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
+ mcfrs_setsignals(info, 1, -1);
+ local_irq_restore(flags);
+ return;
+}
+
+static void mcfrs_flush_chars(struct tty_struct *tty)
+{
+ volatile unsigned char *uartp;
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_flush_chars"))
+ return;
+
+ if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
+ !info->xmit_buf)
+ return;
+
+ /* Enable transmitter */
+ local_irq_save(flags);
+ uartp = (volatile unsigned char *) info->addr;
+ info->imr |= MCFUART_UIR_TXREADY;
+ uartp[MCFUART_UIMR] = info->imr;
+ local_irq_restore(flags);
+}
+
+static int mcfrs_write(struct tty_struct * tty, int from_user,
+ const unsigned char *buf, int count)
+{
+ volatile unsigned char *uartp;
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+ unsigned long flags;
+ int c, total = 0;
+
+#if 0
+ printk("%s(%d): mcfrs_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
+ __FILE__, __LINE__, tty, from_user, buf, count);
+#endif
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_write"))
+ return 0;
+
+ if (!tty || !info->xmit_buf)
+ return 0;
+
+ local_save_flags(flags);
+ while (1) {
+ local_irq_disable();
+ c = min(count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
+ SERIAL_XMIT_SIZE - info->xmit_head));
+
+ if (c <= 0) {
+ local_irq_restore(flags);
+ break;
+ }
+
+ if (from_user) {
+ down(&mcfrs_tmp_buf_sem);
+ copy_from_user(mcfrs_tmp_buf, buf, c);
+ local_irq_restore(flags);
+ local_irq_disable();
+ c = min(c, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
+ SERIAL_XMIT_SIZE - info->xmit_head));
+ memcpy(info->xmit_buf + info->xmit_head, mcfrs_tmp_buf, c);
+ up(&mcfrs_tmp_buf_sem);
+ } else
+ 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;
+ }
+
+ local_irq_disable();
+ uartp = (volatile unsigned char *) info->addr;
+ info->imr |= MCFUART_UIR_TXREADY;
+ uartp[MCFUART_UIMR] = info->imr;
+ local_irq_restore(flags);
+
+ return total;
+}
+
+static int mcfrs_write_room(struct tty_struct *tty)
+{
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+ int ret;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_write_room"))
+ return 0;
+ ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
+ if (ret < 0)
+ ret = 0;
+ return ret;
+}
+
+static int mcfrs_chars_in_buffer(struct tty_struct *tty)
+{
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_chars_in_buffer"))
+ return 0;
+ return info->xmit_cnt;
+}
+
+static void mcfrs_flush_buffer(struct tty_struct *tty)
+{
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+ unsigned long flags;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_flush_buffer"))
+ return;
+
+ local_irq_save(flags);
+ info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
+ local_irq_restore(flags);
+
+ wake_up_interruptible(&tty->write_wait);
+ if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+ tty->ldisc.write_wakeup)
+ (tty->ldisc.write_wakeup)(tty);
+}
+
+/*
+ * ------------------------------------------------------------
+ * mcfrs_throttle()
+ *
+ * This routine is called by the upper-layer tty layer to signal that
+ * incoming characters should be throttled.
+ * ------------------------------------------------------------
+ */
+static void mcfrs_throttle(struct tty_struct * tty)
+{
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+#ifdef SERIAL_DEBUG_THROTTLE
+ char buf[64];
+
+ printk("throttle %s: %d....\n", _tty_name(tty, buf),
+ tty->ldisc.chars_in_buffer(tty));
+#endif
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_throttle"))
+ return;
+
+ if (I_IXOFF(tty))
+ info->x_char = STOP_CHAR(tty);
+
+ /* Turn off RTS line (do this atomic) */
+}
+
+static void mcfrs_unthrottle(struct tty_struct * tty)
+{
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+#ifdef SERIAL_DEBUG_THROTTLE
+ char buf[64];
+
+ printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
+ tty->ldisc.chars_in_buffer(tty));
+#endif
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_unthrottle"))
+ return;
+
+ if (I_IXOFF(tty)) {
+ if (info->x_char)
+ info->x_char = 0;
+ else
+ info->x_char = START_CHAR(tty);
+ }
+
+ /* Assert RTS line (do this atomic) */
+}
+
+/*
+ * ------------------------------------------------------------
+ * mcfrs_ioctl() and friends
+ * ------------------------------------------------------------
+ */
+
+static int get_serial_info(struct mcf_serial * info,
+ struct serial_struct * retinfo)
+{
+ struct serial_struct tmp;
+
+ if (!retinfo)
+ return -EFAULT;
+ memset(&tmp, 0, sizeof(tmp));
+ tmp.type = info->type;
+ tmp.line = info->line;
+ tmp.port = info->addr;
+ tmp.irq = info->irq;
+ tmp.flags = info->flags;
+ tmp.baud_base = info->baud_base;
+ tmp.close_delay = info->close_delay;
+ tmp.closing_wait = info->closing_wait;
+ tmp.custom_divisor = info->custom_divisor;
+ copy_to_user(retinfo,&tmp,sizeof(*retinfo));
+ return 0;
+}
+
+static int set_serial_info(struct mcf_serial * info,
+ struct serial_struct * new_info)
+{
+ struct serial_struct new_serial;
+ struct mcf_serial old_info;
+ int retval = 0;
+
+ if (!new_info)
+ return -EFAULT;
+ copy_from_user(&new_serial,new_info,sizeof(new_serial));
+ old_info = *info;
+
+ if (!capable(CAP_SYS_ADMIN)) {
+ if ((new_serial.baud_base != info->baud_base) ||
+ (new_serial.type != info->type) ||
+ (new_serial.close_delay != info->close_delay) ||
+ ((new_serial.flags & ~ASYNC_USR_MASK) !=
+ (info->flags & ~ASYNC_USR_MASK)))
+ return -EPERM;
+ info->flags = ((info->flags & ~ASYNC_USR_MASK) |
+ (new_serial.flags & ASYNC_USR_MASK));
+ info->custom_divisor = new_serial.custom_divisor;
+ goto check_and_exit;
+ }
+
+ if (info->count > 1)
+ return -EBUSY;
+
+ /*
+ * OK, past this point, all the error checking has been done.
+ * At this point, we start making changes.....
+ */
+
+ info->baud_base = new_serial.baud_base;
+ info->flags = ((info->flags & ~ASYNC_FLAGS) |
+ (new_serial.flags & ASYNC_FLAGS));
+ info->type = new_serial.type;
+ info->close_delay = new_serial.close_delay;
+ info->closing_wait = new_serial.closing_wait;
+
+check_and_exit:
+ retval = startup(info);
+ return retval;
+}
+
+/*
+ * get_lsr_info - get line status register info
+ *
+ * Purpose: Let user call ioctl() to get info when the UART physically
+ * is emptied. On bus types like RS485, the transmitter must
+ * release the bus after transmitting. This must be done when
+ * the transmit shift register is empty, not be done when the
+ * transmit holding register is empty. This functionality
+ * allows an RS485 driver to be written in user space.
+ */
+static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
+{
+ volatile unsigned char *uartp;
+ unsigned long flags;
+ unsigned char status;
+
+ local_irq_save(flags);
+ uartp = (volatile unsigned char *) info->addr;
+ status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
+ local_irq_restore(flags);
+
+ put_user(status,value);
+ return 0;
+}
+
+/*
+ * This routine sends a break character out the serial port.
+ */
+static void send_break( struct mcf_serial * info, int duration)
+{
+ volatile unsigned char *uartp;
+ unsigned long flags;
+
+ if (!info->addr)
+ return;
+ current->state = TASK_INTERRUPTIBLE;
+ uartp = (volatile unsigned char *) info->addr;
+
+ local_irq_save(flags);
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART;
+ schedule_timeout(jiffies + duration);
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP;
+ local_irq_restore(flags);
+}
+
+static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
+ unsigned int val;
+ int retval, error;
+ int dtr, rts;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_ioctl"))
+ return -ENODEV;
+
+ if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
+ (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
+ (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
+ if (tty->flags & (1 << TTY_IO_ERROR))
+ return -EIO;
+ }
+
+ switch (cmd) {
+ case TCSBRK: /* SVID version: non-zero arg --> no break */
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ tty_wait_until_sent(tty, 0);
+ if (!arg)
+ send_break(info, HZ/4); /* 1/4 second */
+ return 0;
+ case TCSBRKP: /* support for POSIX tcsendbreak() */
+ retval = tty_check_change(tty);
+ if (retval)
+ return retval;
+ tty_wait_until_sent(tty, 0);
+ send_break(info, arg ? arg*(HZ/10) : HZ/4);
+ return 0;
+ case TIOCGSOFTCAR:
+ error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
+ if (error)
+ return error;
+ put_user(C_CLOCAL(tty) ? 1 : 0,
+ (unsigned long *) arg);
+ return 0;
+ case TIOCSSOFTCAR:
+ get_user(arg, (unsigned long *) arg);
+ tty->termios->c_cflag =
+ ((tty->termios->c_cflag & ~CLOCAL) |
+ (arg ? CLOCAL : 0));
+ return 0;
+ case TIOCGSERIAL:
+ error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(struct serial_struct));
+ if (error)
+ return error;
+ return get_serial_info(info,
+ (struct serial_struct *) arg);
+ case TIOCSSERIAL:
+ return set_serial_info(info,
+ (struct serial_struct *) arg);
+ case TIOCSERGETLSR: /* Get line status register */
+ error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(unsigned int));
+ if (error)
+ return error;
+ else
+ return get_lsr_info(info, (unsigned int *) arg);
+
+ case TIOCSERGSTRUCT:
+ error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(struct mcf_serial));
+ if (error)
+ return error;
+ copy_to_user((struct mcf_serial *) arg,
+ info, sizeof(struct mcf_serial));
+ return 0;
+
+ case TIOCMGET:
+ if ((error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(unsigned int))))
+ return(error);
+ val = mcfrs_getsignals(info);
+ put_user(val, (unsigned int *) arg);
+ break;
+
+ case TIOCMBIS:
+ if ((error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(unsigned int))))
+ return(error);
+
+ get_user(val, (unsigned int *) arg);
+ rts = (val & TIOCM_RTS) ? 1 : -1;
+ dtr = (val & TIOCM_DTR) ? 1 : -1;
+ mcfrs_setsignals(info, dtr, rts);
+ break;
+
+ case TIOCMBIC:
+ if ((error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(unsigned int))))
+ return(error);
+ get_user(val, (unsigned int *) arg);
+ rts = (val & TIOCM_RTS) ? 0 : -1;
+ dtr = (val & TIOCM_DTR) ? 0 : -1;
+ mcfrs_setsignals(info, dtr, rts);
+ break;
+
+ case TIOCMSET:
+ if ((error = verify_area(VERIFY_WRITE, (void *) arg,
+ sizeof(unsigned int))))
+ return(error);
+ get_user(val, (unsigned int *) arg);
+ rts = (val & TIOCM_RTS) ? 1 : 0;
+ dtr = (val & TIOCM_DTR) ? 1 : 0;
+ mcfrs_setsignals(info, dtr, rts);
+ break;
+
+#ifdef TIOCSET422
+ case TIOCSET422:
+ get_user(val, (unsigned int *) arg);
+ mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11));
+ break;
+ case TIOCGET422:
+ val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1;
+ put_user(val, (unsigned int *) arg);
+ break;
+#endif
+
+ default:
+ return -ENOIOCTLCMD;
+ }
+ return 0;
+}
+
+static void mcfrs_set_termios(struct tty_struct *tty, struct termios *old_termios)
+{
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+
+ if (tty->termios->c_cflag == old_termios->c_cflag)
+ return;
+
+ mcfrs_change_speed(info);
+
+ if ((old_termios->c_cflag & CRTSCTS) &&
+ !(tty->termios->c_cflag & CRTSCTS)) {
+ tty->hw_stopped = 0;
+ mcfrs_setsignals(info, -1, 1);
+#if 0
+ mcfrs_start(tty);
+#endif
+ }
+}
+
+/*
+ * ------------------------------------------------------------
+ * mcfrs_close()
+ *
+ * This routine is called when the serial port gets closed. First, we
+ * wait for the last remaining data to be sent. Then, we unlink its
+ * S structure from the interrupt chain if necessary, and we free
+ * that IRQ if nothing is left in the chain.
+ * ------------------------------------------------------------
+ */
+static void mcfrs_close(struct tty_struct *tty, struct file * filp)
+{
+ volatile unsigned char *uartp;
+ struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
+ unsigned long flags;
+
+ if (!info || serial_paranoia_check(info, tty->device, "mcfrs_close"))
+ return;
+
+ local_irq_save(flags);
+
+ if (tty_hung_up_p(filp)) {
+ local_irq_restore(flags);
+ return;
+ }
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("mcfrs_close ttyS%d, count = %d\n", info->line, 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("MCFRS: bad serial port count; tty->count is 1, "
+ "info->count is %d\n", info->count);
+ info->count = 1;
+ }
+ if (--info->count < 0) {
+ printk("MCFRS: bad serial port count for ttyS%d: %d\n",
+ info->line, info->count);
+ info->count = 0;
+ }
+ if (info->count) {
+ local_irq_restore(flags);
+ return;
+ }
+ info->flags |= ASYNC_CLOSING;
+
+ /*
+ * Save the termios structure, since this port may have
+ * separate termios for callout and dialin.
+ */
+ if (info->flags & ASYNC_NORMAL_ACTIVE)
+ info->normal_termios = *tty->termios;
+ if (info->flags & ASYNC_CALLOUT_ACTIVE)
+ info->callout_termios = *tty->termios;
+
+ /*
+ * Now we wait for the transmit buffer to clear; and we notify
+ * the line discipline to only process XON/XOFF characters.
+ */
+ tty->closing = 1;
+ if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
+ tty_wait_until_sent(tty, info->closing_wait);
+
+ /*
+ * At this point we stop accepting input. To do this, we
+ * disable the receive line status interrupts, and tell the
+ * interrupt driver to stop checking the data ready bit in the
+ * line status register.
+ */
+ info->imr &= ~MCFUART_UIR_RXREADY;
+ uartp = (volatile unsigned char *) info->addr;
+ uartp[MCFUART_UIMR] = info->imr;
+
+#if 0
+ /* FIXME: do we need to keep this enabled for console?? */
+ if (mcfrs_console_inited && (mcfrs_console_port == info->line)) {
+ /* Do not disable the UART */ ;
+ } else
+#endif
+ shutdown(info);
+ if (tty->driver.flush_buffer)
+ tty->driver.flush_buffer(tty);
+ if (tty->ldisc.flush_buffer)
+ tty->ldisc.flush_buffer(tty);
+ tty->closing = 0;
+ info->event = 0;
+ info->tty = 0;
+ if (tty->ldisc.num != ldiscs[N_TTY].num) {
+ if (tty->ldisc.close)
+ (tty->ldisc.close)(tty);
+ tty->ldisc = ldiscs[N_TTY];
+ tty->termios->c_line = N_TTY;
+ if (tty->ldisc.open)
+ (tty->ldisc.open)(tty);
+ }
+ if (info->blocked_open) {
+ if (info->close_delay) {
+ current->state = TASK_INTERRUPTIBLE;
+ schedule_timeout(info->close_delay);
+ }
+ wake_up_interruptible(&info->open_wait);
+ }
+ info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
+ ASYNC_CLOSING);
+ wake_up_interruptible(&info->close_wait);
+ local_irq_restore(flags);
+}
+
+/*
+ * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
+ */
+void mcfrs_hangup(struct tty_struct *tty)
+{
+ struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
+
+ if (serial_paranoia_check(info, tty->device, "mcfrs_hangup"))
+ return;
+
+ mcfrs_flush_buffer(tty);
+ shutdown(info);
+ info->event = 0;
+ info->count = 0;
+ info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
+ info->tty = 0;
+ wake_up_interruptible(&info->open_wait);
+}
+
+/*
+ * ------------------------------------------------------------
+ * mcfrs_open() and friends
+ * ------------------------------------------------------------
+ */
+static int block_til_ready(struct tty_struct *tty, struct file * filp,
+ struct mcf_serial *info)
+{
+ DECLARE_WAITQUEUE(wait, current);
+ int retval;
+ int do_clocal = 0;
+
+ /*
+ * 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);
+#ifdef SERIAL_DO_RESTART
+ if (info->flags & ASYNC_HUP_NOTIFY)
+ return -EAGAIN;
+ else
+ return -ERESTARTSYS;
+#else
+ return -EAGAIN;
+#endif
+ }
+
+ /*
+ * If this is a callout device, then just make sure the normal
+ * device isn't being used.
+ */
+ if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
+ if (info->flags & ASYNC_NORMAL_ACTIVE)
+ return -EBUSY;
+ if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ (info->flags & ASYNC_SESSION_LOCKOUT) &&
+ (info->session != current->session))
+ return -EBUSY;
+ if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ (info->flags & ASYNC_PGRP_LOCKOUT) &&
+ (info->pgrp != current->pgrp))
+ return -EBUSY;
+ info->flags |= ASYNC_CALLOUT_ACTIVE;
+ return 0;
+ }
+
+ /*
+ * If non-blocking mode is set, or the port is not enabled,
+ * then make the check up front and then exit.
+ */
+ if ((filp->f_flags & O_NONBLOCK) ||
+ (tty->flags & (1 << TTY_IO_ERROR))) {
+ if (info->flags & ASYNC_CALLOUT_ACTIVE)
+ return -EBUSY;
+ info->flags |= ASYNC_NORMAL_ACTIVE;
+ return 0;
+ }
+
+ if (info->flags & ASYNC_CALLOUT_ACTIVE) {
+ if (info->normal_termios.c_cflag & CLOCAL)
+ do_clocal = 1;
+ } else {
+ if (tty->termios->c_cflag & CLOCAL)
+ do_clocal = 1;
+ }
+
+ /*
+ * 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
+ * mcfrs_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: ttyS%d, count = %d\n",
+ info->line, info->count);
+#endif
+ info->count--;
+ info->blocked_open++;
+ while (1) {
+ local_irq_disable();
+ if (!(info->flags & ASYNC_CALLOUT_ACTIVE))
+ mcfrs_setsignals(info, 1, 1);
+ local_irq_enable();
+ current->state = TASK_INTERRUPTIBLE;
+ if (tty_hung_up_p(filp) ||
+ !(info->flags & ASYNC_INITIALIZED)) {
+#ifdef SERIAL_DO_RESTART
+ if (info->flags & ASYNC_HUP_NOTIFY)
+ retval = -EAGAIN;
+ else
+ retval = -ERESTARTSYS;
+#else
+ retval = -EAGAIN;
+#endif
+ break;
+ }
+ if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
+ !(info->flags & ASYNC_CLOSING) &&
+ (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD)))
+ break;
+ if (signal_pending(current)) {
+ retval = -ERESTARTSYS;
+ break;
+ }
+#ifdef SERIAL_DEBUG_OPEN
+ printk("block_til_ready blocking: ttyS%d, count = %d\n",
+ info->line, info->count);
+#endif
+ schedule();
+ }
+ current->state = TASK_RUNNING;
+ remove_wait_queue(&info->open_wait, &wait);
+ if (!tty_hung_up_p(filp))
+ info->count++;
+ info->blocked_open--;
+#ifdef SERIAL_DEBUG_OPEN
+ printk("block_til_ready after blocking: ttyS%d, count = %d\n",
+ info->line, info->count);
+#endif
+ if (retval)
+ return retval;
+ info->flags |= ASYNC_NORMAL_ACTIVE;
+ return 0;
+}
+
+/*
+ * This routine is called whenever a serial port is opened. It
+ * enables interrupts for a serial port, linking in its structure into
+ * the IRQ chain. It also performs the serial-specific
+ * initialization for the tty structure.
+ */
+int mcfrs_open(struct tty_struct *tty, struct file * filp)
+{
+ struct mcf_serial *info;
+ int retval, line;
+
+ line = minor(tty->device) - tty->driver.minor_start;
+ if ((line < 0) || (line >= NR_PORTS))
+ return -ENODEV;
+ info = mcfrs_table + line;
+ if (serial_paranoia_check(info, tty->device, "mcfrs_open"))
+ return -ENODEV;
+#ifdef SERIAL_DEBUG_OPEN
+ printk("mcfrs_open %s%d, count = %d\n", tty->driver.name, info->line,
+ info->count);
+#endif
+ info->count++;
+ 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("mcfrs_open returning after block_til_ready with %d\n",
+ retval);
+#endif
+ return retval;
+ }
+
+ if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
+ if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
+ *tty->termios = info->normal_termios;
+ else
+ *tty->termios = info->callout_termios;
+ mcfrs_change_speed(info);
+ }
+
+ info->session = current->session;
+ info->pgrp = current->pgrp;
+
+#ifdef SERIAL_DEBUG_OPEN
+ printk("mcfrs_open ttyS%d successful...\n", info->line);
+#endif
+ return 0;
+}
+
+/*
+ * Based on the line number set up the internal interrupt stuff.
+ */
+static void mcfrs_irqinit(struct mcf_serial *info)
+{
+#ifdef CONFIG_M5272
+ volatile unsigned long *icrp;
+ volatile unsigned long *portp;
+ volatile unsigned char *uartp;
+
+ uartp = (volatile unsigned char *) info->addr;
+ icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2);
+
+ switch (info->line) {
+ case 0:
+ *icrp = 0xe0000000;
+ break;
+ case 1:
+ *icrp = 0x0e000000;
+ break;
+ default:
+ printk("MCFRS: don't know how to handle UART %d interrupt?\n",
+ info->line);
+ return;
+ }
+
+ /* Enable the output lines for the serial ports */
+ portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT);
+ *portp = (*portp & ~0x000000ff) | 0x00000055;
+ portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
+ *portp = (*portp & ~0x000003fc) | 0x000002a8;
+#else
+ volatile unsigned char *icrp, *uartp;
+
+ switch (info->line) {
+ case 0:
+ icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR);
+ *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
+ MCFSIM_ICR_PRI1;
+ mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1);
+ break;
+ case 1:
+ icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR);
+ *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
+ MCFSIM_ICR_PRI2;
+ mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2);
+ break;
+ default:
+ printk("MCFRS: don't know how to handle UART %d interrupt?\n",
+ info->line);
+ return;
+ }
+
+ uartp = (volatile unsigned char *) info->addr;
+ uartp[MCFUART_UIVR] = info->irq;
+#endif
+
+ /* Clear mask, so no surprise interrupts. */
+ uartp[MCFUART_UIMR] = 0;
+
+ if (request_irq(info->irq, mcfrs_interrupt, SA_INTERRUPT,
+ "ColdFire UART", NULL)) {
+ printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
+ "vector=%d\n", info->line, info->irq);
+ }
+
+ return;
+}
+
+
+char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n";
+
+
+/*
+ * Serial stats reporting...
+ */
+int mcfrs_readproc(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct mcf_serial *info;
+ char str[20];
+ int len, sigs, i;
+
+ len = sprintf(page, mcfrs_drivername);
+ for (i = 0; (i < NR_PORTS); i++) {
+ info = &mcfrs_table[i];
+ len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
+ i, info->addr, info->irq, info->baud);
+ if (info->stats.rx || info->stats.tx)
+ len += sprintf((page + len), "tx:%d rx:%d ",
+ info->stats.tx, info->stats.rx);
+ if (info->stats.rxframing)
+ len += sprintf((page + len), "fe:%d ",
+ info->stats.rxframing);
+ if (info->stats.rxparity)
+ len += sprintf((page + len), "pe:%d ",
+ info->stats.rxparity);
+ if (info->stats.rxbreak)
+ len += sprintf((page + len), "brk:%d ",
+ info->stats.rxbreak);
+ if (info->stats.rxoverrun)
+ len += sprintf((page + len), "oe:%d ",
+ info->stats.rxoverrun);
+
+ str[0] = str[1] = 0;
+ if ((sigs = mcfrs_getsignals(info))) {
+ if (sigs & TIOCM_RTS)
+ strcat(str, "|RTS");
+ if (sigs & TIOCM_CTS)
+ strcat(str, "|CTS");
+ if (sigs & TIOCM_DTR)
+ strcat(str, "|DTR");
+ if (sigs & TIOCM_CD)
+ strcat(str, "|CD");
+ }
+
+ len += sprintf((page + len), "%s\n", &str[1]);
+ }
+
+ return(len);
+}
+
+
+/* Finally, routines used to initialize the serial driver. */
+
+static void show_serial_version(void)
+{
+ printk(mcfrs_drivername);
+}
+
+/* mcfrs_init inits the driver */
+static int __init
+mcfrs_init(void)
+{
+ struct mcf_serial *info;
+ unsigned long flags;
+ int i;
+
+ /* Setup base handler, and timer table. */
+#ifdef MCFPP_DCD0
+ init_timer(&mcfrs_timer_struct);
+ mcfrs_timer_struct.function = mcfrs_timer;
+ mcfrs_timer_struct.data = 0;
+ mcfrs_timer_struct.expires = jiffies + HZ/25;
+ add_timer(&mcfrs_timer_struct);
+ mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
+#endif
+
+ show_serial_version();
+
+ /* Initialize the tty_driver structure */
+ memset(&mcfrs_serial_driver, 0, sizeof(struct tty_driver));
+ mcfrs_serial_driver.magic = TTY_DRIVER_MAGIC;
+ mcfrs_serial_driver.name = "ttyS";
+ mcfrs_serial_driver.major = TTY_MAJOR;
+ mcfrs_serial_driver.minor_start = 64;
+ mcfrs_serial_driver.num = NR_PORTS;
+ mcfrs_serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
+ mcfrs_serial_driver.subtype = SERIAL_TYPE_NORMAL;
+ mcfrs_serial_driver.init_termios = tty_std_termios;
+
+ mcfrs_serial_driver.init_termios.c_cflag =
+ mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
+ mcfrs_serial_driver.flags = TTY_DRIVER_REAL_RAW;
+ mcfrs_serial_driver.refcount = &mcfrs_serial_refcount;
+ mcfrs_serial_driver.table = mcfrs_serial_table;
+ mcfrs_serial_driver.termios = mcfrs_serial_termios;
+ mcfrs_serial_driver.termios_locked = mcfrs_serial_termios_locked;
+
+ mcfrs_serial_driver.open = mcfrs_open;
+ mcfrs_serial_driver.close = mcfrs_close;
+ mcfrs_serial_driver.write = mcfrs_write;
+ mcfrs_serial_driver.flush_chars = mcfrs_flush_chars;
+ mcfrs_serial_driver.write_room = mcfrs_write_room;
+ mcfrs_serial_driver.chars_in_buffer = mcfrs_chars_in_buffer;
+ mcfrs_serial_driver.flush_buffer = mcfrs_flush_buffer;
+ mcfrs_serial_driver.ioctl = mcfrs_ioctl;
+ mcfrs_serial_driver.throttle = mcfrs_throttle;
+ mcfrs_serial_driver.unthrottle = mcfrs_unthrottle;
+ mcfrs_serial_driver.set_termios = mcfrs_set_termios;
+ mcfrs_serial_driver.stop = mcfrs_stop;
+ mcfrs_serial_driver.start = mcfrs_start;
+ mcfrs_serial_driver.hangup = mcfrs_hangup;
+ mcfrs_serial_driver.read_proc = mcfrs_readproc;
+ mcfrs_serial_driver.driver_name = "serial";
+
+ /*
+ * The callout device is just like normal device except for
+ * major number and the subtype code.
+ */
+ mcfrs_callout_driver = mcfrs_serial_driver;
+ mcfrs_callout_driver.name = "cua";
+ mcfrs_callout_driver.major = TTYAUX_MAJOR;
+ mcfrs_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
+ mcfrs_callout_driver.read_proc = 0;
+ mcfrs_callout_driver.proc_entry = 0;
+
+ if (tty_register_driver(&mcfrs_serial_driver)) {
+ printk("MCFRS: Couldn't register serial driver\n");
+ return(-EBUSY);
+ }
+ if (tty_register_driver(&mcfrs_callout_driver)) {
+ printk("MCFRS: Couldn't register callout driver\n");
+ return(-EBUSY);
+ }
+
+ local_irq_save(flags);
+
+ /*
+ * Configure all the attached serial ports.
+ */
+ for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) {
+ info->magic = SERIAL_MAGIC;
+ info->line = i;
+ info->tty = 0;
+ info->custom_divisor = 16;
+ info->close_delay = 50;
+ info->closing_wait = 3000;
+ info->x_char = 0;
+ info->event = 0;
+ info->count = 0;
+ info->blocked_open = 0;
+ INIT_WORK(&info->tqueue, mcfrs_offintr, info);
+ INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
+ info->callout_termios = mcfrs_callout_driver.init_termios;
+ info->normal_termios = mcfrs_serial_driver.init_termios;
+ init_waitqueue_head(&info->open_wait);
+ init_waitqueue_head(&info->close_wait);
+
+ info->imr = 0;
+ mcfrs_setsignals(info, 0, 0);
+ mcfrs_irqinit(info);
+
+ printk("%s%d at 0x%04x (irq = %d)", mcfrs_serial_driver.name,
+ info->line, info->addr, info->irq);
+ printk(" is a builtin ColdFire UART\n");
+ }
+
+ local_irq_restore(flags);
+ return 0;
+}
+
+module_init(mcfrs_init);
+/* DAVIDM module_exit(mcfrs_fini); */
+
+/****************************************************************************/
+/* Serial Console */
+/****************************************************************************/
+
+/*
+ * Quick and dirty UART initialization, for console output.
+ */
+
+void mcfrs_init_console(void)
+{
+ volatile unsigned char *uartp;
+ unsigned int clk;
+
+ /*
+ * Reset UART, get it into known state...
+ */
+ uartp = (volatile unsigned char *) (MCF_MBAR +
+ (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
+
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
+
+ /*
+ * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
+ */
+ uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
+ uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
+
+ clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */
+ uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8; /* set msb baud */
+ uartp[MCFUART_UBG2] = (clk & 0xff); /* set lsb baud */
+
+ uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
+ uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
+
+ mcfrs_console_inited++;
+ return;
+}
+
+
+/*
+ * Setup for console. Argument comes from the boot command line.
+ */
+
+int mcfrs_console_setup(struct console *cp, char *arg)
+{
+ int i, n = CONSOLE_BAUD_RATE;
+
+ if (!cp)
+ return(-1);
+
+ if (!strncmp(cp->name, "ttyS", 4))
+ mcfrs_console_port = cp->index;
+ else if (!strncmp(cp->name, "cua", 3))
+ mcfrs_console_port = cp->index;
+ else
+ return(-1);
+
+ if (arg)
+ n = simple_strtoul(arg,NULL,0);
+ for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++)
+ if (mcfrs_baud_table[i] == n)
+ break;
+ if (i < MCFRS_BAUD_TABLE_SIZE) {
+ mcfrs_console_baud = n;
+ mcfrs_console_cbaud = 0;
+ if (i > 15) {
+ mcfrs_console_cbaud |= CBAUDEX;
+ i -= 15;
+ }
+ mcfrs_console_cbaud |= i;
+ }
+ mcfrs_init_console(); /* make sure baud rate changes */
+ return(0);
+}
+
+
+static kdev_t mcfrs_console_device(struct console *c)
+{
+ return mk_kdev(TTY_MAJOR, 64 + c->index);
+}
+
+
+/*
+ * Output a single character, using UART polled mode.
+ * This is used for console output.
+ */
+
+void mcfrs_put_char(char ch)
+{
+ volatile unsigned char *uartp;
+ unsigned long flags;
+ int i;
+
+ uartp = (volatile unsigned char *) (MCF_MBAR +
+ (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
+
+ local_irq_save(flags);
+ for (i = 0; (i < 0x10000); i++) {
+ if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
+ break;
+ }
+ if (i < 0x10000) {
+ uartp[MCFUART_UTB] = ch;
+ for (i = 0; (i < 0x10000); i++)
+ if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY)
+ break;
+ }
+ if (i >= 0x10000)
+ mcfrs_init_console(); /* try and get it back */
+ local_irq_restore(flags);
+
+ return;
+}
+
+
+/*
+ * rs_console_write is registered for printk output.
+ */
+
+void mcfrs_console_write(struct console *cp, const char *p, unsigned len)
+{
+ if (!mcfrs_console_inited)
+ mcfrs_init_console();
+ while (len-- > 0) {
+ if (*p == '\n')
+ mcfrs_put_char('\r');
+ mcfrs_put_char(*p++);
+ }
+}
+
+/*
+ * declare our consoles
+ */
+
+struct console mcfrs_console = {
+ name: "ttyS",
+ write: mcfrs_console_write,
+ device: mcfrs_console_device,
+ setup: mcfrs_console_setup,
+ flags: CON_PRINTBUFFER,
+ index: -1,
+};
+
+void __init mcfrs_console_init(void)
+{
+ register_console(&mcfrs_console);
+}
+
+/****************************************************************************/
--- /dev/null
+/*
+ * mcfserial.c -- serial driver for ColdFire internal UARTS.
+ *
+ * Copyright (c) 1999 Greg Ungerer <gerg@snapgear.com>
+ * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
+ * Copyright (c) 2002 SnapGear Inc., <www.snapgear.com>
+ *
+ * Based on code from 68332serial.c which was:
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ * Copyright (C) 1998 TSHG
+ * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
+ */
+#ifndef _MCF_SERIAL_H
+#define _MCF_SERIAL_H
+
+#include <linux/config.h>
+#include <linux/serial.h>
+
+#ifdef __KERNEL__
+
+/*
+ * Define a local serial stats structure.
+ */
+
+struct mcf_stats {
+ unsigned int rx;
+ unsigned int tx;
+ unsigned int rxbreak;
+ unsigned int rxframing;
+ unsigned int rxparity;
+ unsigned int rxoverrun;
+};
+
+
+/*
+ * This is our internal structure for each serial port's state.
+ * Each serial port has one of these structures associated with it.
+ */
+
+struct mcf_serial {
+ int magic;
+ unsigned int addr; /* UART memory address */
+ int irq;
+ int flags; /* defined in tty.h */
+ int type; /* UART type */
+ struct tty_struct *tty;
+ unsigned char imr; /* Software imr register */
+ unsigned int baud;
+ int sigs;
+ int custom_divisor;
+ int x_char; /* xon/xoff character */
+ int baud_base;
+ int close_delay;
+ unsigned short closing_wait;
+ unsigned short closing_wait2;
+ unsigned long event;
+ int line;
+ int count; /* # of fd on device */
+ int blocked_open; /* # of blocked opens */
+ long session; /* Session of opening process */
+ long pgrp; /* pgrp of opening process */
+ unsigned char *xmit_buf;
+ int xmit_head;
+ int xmit_tail;
+ int xmit_cnt;
+ struct mcf_stats stats;
+ struct work_struct tqueue;
+ struct work_struct tqueue_hangup;
+ struct termios normal_termios;
+ struct termios callout_termios;
+#if LINUX_VERSION_CODE <= 0x020100
+ struct wait_queue *open_wait;
+ struct wait_queue *close_wait;
+#else
+ wait_queue_head_t open_wait;
+ wait_queue_head_t close_wait;
+#endif
+
+};
+
+#endif /* __KERNEL__ */
+
+#endif /* _MCF_SERIAL_H */
--- /dev/null
+/*
+ * drivers/serial/nb85e_uart.c -- Serial I/O using V850E/NB85E on-chip UART
+ *
+ * Copyright (C) 2001,02 NEC Corporation
+ * Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file COPYING in the main directory of this
+ * archive for more details.
+ *
+ * Written by Miles Bader <miles@gnu.org>
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/console.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial.h>
+#include <linux/serial_core.h>
+
+#include <asm/nb85e_uart.h>
+#include <asm/nb85e_utils.h>
+
+/* Initial UART state. This may be overridden by machine-dependent headers. */
+#ifndef NB85E_UART_INIT_BAUD
+#define NB85E_UART_INIT_BAUD 38400
+#endif
+#ifndef NB85E_UART_INIT_CFLAGS
+#define NB85E_UART_INIT_CFLAGS (B38400 | CS8 | CREAD)
+#endif
+
+/* A string used for prefixing printed descriptions; since the same UART
+ macro is actually used on other chips than the V850E/NB85E. This must
+ be a constant string. */
+#ifndef NB85E_UART_CHIP_NAME
+#define NB85E_UART_CHIP_NAME "V850E/NB85E"
+#endif
+
+\f
+/* Low-level UART functions. */
+
+/* These masks define which control bits affect TX/RX modes, respectively. */
+#define RX_BITS \
+ (NB85E_UART_ASIM_PS_MASK | NB85E_UART_ASIM_CL_8 | NB85E_UART_ASIM_ISRM)
+#define TX_BITS \
+ (NB85E_UART_ASIM_PS_MASK | NB85E_UART_ASIM_CL_8 | NB85E_UART_ASIM_SL_2)
+
+/* The UART require various delays after writing control registers. */
+static inline void nb85e_uart_delay (unsigned cycles)
+{
+ /* The loop takes 2 insns, so loop CYCLES / 2 times. */
+ register unsigned count = cycles >> 1;
+ while (--count != 0)
+ /* nothing */;
+}
+
+/* Configure and turn on uart channel CHAN, using the termios `control
+ modes' bits in CFLAGS, and a baud-rate of BAUD. */
+void nb85e_uart_configure (unsigned chan, unsigned cflags, unsigned baud)
+{
+ int cksr_min, flags;
+ unsigned new_config = 0; /* What we'll write to the control reg. */
+ unsigned new_clk_divlog2; /* New baud-rate generate clock divider. */
+ unsigned new_brgen_count; /* New counter max for baud-rate generator.*/
+ /* These are the current values corresponding to the above. */
+ unsigned old_config, old_clk_divlog2, old_brgen_count;
+
+ /* Calculate new baud-rate generator config values. */
+ cksr_min = 0;
+ while ((NB85E_UART_BASE_FREQ >> cksr_min) > NB85E_UART_CKSR_MAX_FREQ)
+ cksr_min++;
+ /* Calculate the log2 clock divider and baud-rate counter values
+ (note that the UART divides the resulting clock by 2, so
+ multiply BAUD by 2 here to compensate). */
+ calc_counter_params (NB85E_UART_BASE_FREQ, baud * 2,
+ cksr_min, NB85E_UART_CKSR_MAX, 8/*bits*/,
+ &new_clk_divlog2, &new_brgen_count);
+
+ /* Figure out new configuration of control register. */
+ if (cflags & CSTOPB)
+ /* Number of stop bits, 1 or 2. */
+ new_config |= NB85E_UART_ASIM_SL_2;
+ if ((cflags & CSIZE) == CS8)
+ /* Number of data bits, 7 or 8. */
+ new_config |= NB85E_UART_ASIM_CL_8;
+ if (! (cflags & PARENB))
+ /* No parity check/generation. */
+ new_config |= NB85E_UART_ASIM_PS_NONE;
+ else if (cflags & PARODD)
+ /* Odd parity check/generation. */
+ new_config |= NB85E_UART_ASIM_PS_ODD;
+ else
+ /* Even parity check/generation. */
+ new_config |= NB85E_UART_ASIM_PS_EVEN;
+ if (cflags & CREAD)
+ /* Reading enabled. */
+ new_config |= NB85E_UART_ASIM_RXE;
+
+ new_config |= NB85E_UART_ASIM_TXE; /* Writing is always enabled. */
+ new_config |= NB85E_UART_ASIM_CAE;
+ new_config |= NB85E_UART_ASIM_ISRM; /* Errors generate a read-irq. */
+
+ /* Disable interrupts while we're twiddling the hardware. */
+ local_irq_save (flags);
+
+#ifdef NB85E_UART_PRE_CONFIGURE
+ NB85E_UART_PRE_CONFIGURE (chan, cflags, baud);
+#endif
+
+ old_config = NB85E_UART_ASIM (chan);
+ old_clk_divlog2 = NB85E_UART_CKSR (chan);
+ old_brgen_count = NB85E_UART_BRGC (chan);
+
+ if (new_clk_divlog2 != old_clk_divlog2
+ || new_brgen_count != old_brgen_count)
+ {
+ /* The baud rate has changed. First, disable the UART. */
+ NB85E_UART_ASIM (chan) = 0;
+ old_config = 0;
+ /* Reprogram the baud-rate generator. */
+ NB85E_UART_CKSR (chan) = new_clk_divlog2;
+ NB85E_UART_BRGC (chan) = new_brgen_count;
+ }
+
+ if (! (old_config & NB85E_UART_ASIM_CAE)) {
+ /* If we are enabling the uart for the first time, start
+ by turning on the enable bit, which must be done
+ before turning on any other bits. */
+ NB85E_UART_ASIM (chan) = NB85E_UART_ASIM_CAE;
+ /* Enabling the uart also resets it. */
+ old_config = NB85E_UART_ASIM_CAE;
+ }
+
+ if (new_config != old_config) {
+ /* Which of the TXE/RXE bits we'll temporarily turn off
+ before changing other control bits. */
+ unsigned temp_disable = 0;
+ /* Which of the TXE/RXE bits will be enabled. */
+ unsigned enable = 0;
+ unsigned changed_bits = new_config ^ old_config;
+
+ /* Which of RX/TX will be enabled in the new configuration. */
+ if (new_config & RX_BITS)
+ enable |= (new_config & NB85E_UART_ASIM_RXE);
+ if (new_config & TX_BITS)
+ enable |= (new_config & NB85E_UART_ASIM_TXE);
+
+ /* Figure out which of RX/TX needs to be disabled; note
+ that this will only happen if they're not already
+ disabled. */
+ if (changed_bits & RX_BITS)
+ temp_disable |= (old_config & NB85E_UART_ASIM_RXE);
+ if (changed_bits & TX_BITS)
+ temp_disable |= (old_config & NB85E_UART_ASIM_TXE);
+
+ /* We have to turn off RX and/or TX mode before changing
+ any associated control bits. */
+ if (temp_disable)
+ NB85E_UART_ASIM (chan) = old_config & ~temp_disable;
+
+ /* Write the new control bits, while RX/TX are disabled. */
+ if (changed_bits & ~enable)
+ NB85E_UART_ASIM (chan) = new_config & ~enable;
+
+ /* The UART may not be reset properly unless we
+ wait at least 2 `basic-clocks' until turning
+ on the TXE/RXE bits again. A `basic clock'
+ is the clock used by the baud-rate generator, i.e.,
+ the cpu clock divided by the 2^new_clk_divlog2. */
+ nb85e_uart_delay (1 << (new_clk_divlog2 + 1));
+
+ /* Write the final version, with enable bits turned on. */
+ NB85E_UART_ASIM (chan) = new_config;
+ }
+
+ local_irq_restore (flags);
+}
+
+\f
+/* Low-level console. */
+
+#ifdef CONFIG_V850E_NB85E_UART_CONSOLE
+
+static void nb85e_uart_cons_write (struct console *co,
+ const char *s, unsigned count)
+{
+ if (count > 0) {
+ unsigned chan = co->index;
+ unsigned irq = IRQ_INTST (chan);
+ int irq_was_enabled, irq_was_pending, flags;
+
+ /* We don't want to get `transmission completed' (INTST)
+ interrupts, since we're busy-waiting, so we disable
+ them while sending (we don't disable interrupts
+ entirely because sending over a serial line is really
+ slow). We save the status of INTST and restore it
+ when we're done so that using printk doesn't
+ interfere with normal serial transmission (other than
+ interleaving the output, of course!). This should
+ work correctly even if this function is interrupted
+ and the interrupt printks something. */
+
+ /* Disable interrupts while fiddling with INTST. */
+ local_irq_save (flags);
+ /* Get current INTST status. */
+ irq_was_enabled = nb85e_intc_irq_enabled (irq);
+ irq_was_pending = nb85e_intc_irq_pending (irq);
+ /* Disable INTST if necessary. */
+ if (irq_was_enabled)
+ nb85e_intc_disable_irq (irq);
+ /* Turn interrupts back on. */
+ local_irq_restore (flags);
+
+ /* Send characters. */
+ while (count > 0) {
+ int ch = *s++;
+
+ if (ch == '\n') {
+ /* We don't have the benefit of a tty
+ driver, so translate NL into CR LF. */
+ nb85e_uart_wait_for_xmit_ok (chan);
+ nb85e_uart_putc (chan, '\r');
+ }
+
+ nb85e_uart_wait_for_xmit_ok (chan);
+ nb85e_uart_putc (chan, ch);
+
+ count--;
+ }
+
+ /* Restore saved INTST status. */
+ if (irq_was_enabled) {
+ /* Wait for the last character we sent to be
+ completely transmitted (as we'll get an INTST
+ interrupt at that point). */
+ nb85e_uart_wait_for_xmit_done (chan);
+ /* Clear pending interrupts received due
+ to our transmission, unless there was already
+ one pending, in which case we want the
+ handler to be called. */
+ if (! irq_was_pending)
+ nb85e_intc_clear_pending_irq (irq);
+ /* ... and then turn back on handling. */
+ nb85e_intc_enable_irq (irq);
+ }
+ }
+}
+
+static kdev_t nb85e_uart_cons_device (struct console *c)
+{
+ return mk_kdev (TTY_MAJOR, NB85E_UART_MINOR_BASE + c->index);
+}
+
+static struct console nb85e_uart_cons =
+{
+ name: "ttyS",
+ write: nb85e_uart_cons_write,
+ device: nb85e_uart_cons_device,
+ flags: CON_PRINTBUFFER,
+ cflag: NB85E_UART_INIT_CFLAGS,
+ index: -1,
+};
+
+void nb85e_uart_cons_init (unsigned chan)
+{
+ nb85e_uart_configure (chan, NB85E_UART_INIT_CFLAGS,
+ NB85E_UART_INIT_BAUD);
+ nb85e_uart_cons.index = chan;
+ register_console (&nb85e_uart_cons);
+ printk ("Console: %s on-chip UART channel %d\n",
+ NB85E_UART_CHIP_NAME, chan);
+}
+
+#define NB85E_UART_CONSOLE &nb85e_uart_cons
+
+#else /* !CONFIG_V850E_NB85E_UART_CONSOLE */
+#define NB85E_UART_CONSOLE 0
+#endif /* CONFIG_V850E_NB85E_UART_CONSOLE */
+\f
+/* TX/RX interrupt handlers. */
+
+static void nb85e_uart_stop_tx (struct uart_port *port, unsigned tty_stop);
+
+void nb85e_uart_tx (struct uart_port *port)
+{
+ struct circ_buf *xmit = &port->info->xmit;
+ int stopped = uart_tx_stopped (port);
+
+ if (nb85e_uart_xmit_ok (port->line)) {
+ int tx_ch;
+
+ if (port->x_char) {
+ tx_ch = port->x_char;
+ port->x_char = 0;
+ } else if (!uart_circ_empty (xmit) && !stopped) {
+ tx_ch = xmit->buf[xmit->tail];
+ xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+ } else
+ goto no_xmit;
+
+ nb85e_uart_putc (port->line, tx_ch);
+ port->icount.tx++;
+
+ if (uart_circ_chars_pending (xmit) < WAKEUP_CHARS)
+ uart_event (port, EVT_WRITE_WAKEUP);
+ }
+
+ no_xmit:
+ if (uart_circ_empty (xmit) || stopped)
+ nb85e_uart_stop_tx (port, stopped);
+}
+
+static void nb85e_uart_tx_irq (int irq, void *data, struct pt_regs *regs)
+{
+ struct uart_port *port = data;
+ nb85e_uart_tx (port);
+}
+
+static void nb85e_uart_rx_irq (int irq, void *data, struct pt_regs *regs)
+{
+ struct uart_port *port = data;
+ unsigned ch_stat = TTY_NORMAL;
+ unsigned ch = NB85E_UART_RXB (port->line);
+ unsigned err = NB85E_UART_ASIS (port->line);
+
+ if (err) {
+ if (err & NB85E_UART_ASIS_OVE) {
+ ch_stat = TTY_OVERRUN;
+ port->icount.overrun++;
+ } else if (err & NB85E_UART_ASIS_FE) {
+ ch_stat = TTY_FRAME;
+ port->icount.frame++;
+ } else if (err & NB85E_UART_ASIS_PE) {
+ ch_stat = TTY_PARITY;
+ port->icount.parity++;
+ }
+ }
+
+ port->icount.rx++;
+
+ tty_insert_flip_char (port->info->tty, ch, ch_stat);
+ tty_schedule_flip (port->info->tty);
+}
+\f
+/* Control functions for the serial framework. */
+
+static void nb85e_uart_nop (struct uart_port *port) { }
+static int nb85e_uart_success (struct uart_port *port) { return 0; }
+
+static unsigned nb85e_uart_tx_empty (struct uart_port *port)
+{
+ return TIOCSER_TEMT; /* Can't detect. */
+}
+
+static void nb85e_uart_set_mctrl (struct uart_port *port, unsigned mctrl)
+{
+#ifdef NB85E_UART_SET_RTS
+ NB85E_UART_SET_RTS (port->line, (mctrl & TIOCM_RTS));
+#endif
+}
+
+static unsigned nb85e_uart_get_mctrl (struct uart_port *port)
+{
+ /* We don't support DCD or DSR, so consider them permanently active. */
+ int mctrl = TIOCM_CAR | TIOCM_DSR;
+
+ /* We may support CTS. */
+#ifdef NB85E_UART_CTS
+ mctrl |= NB85E_UART_CTS(port->line) ? TIOCM_CTS : 0;
+#else
+ mctrl |= TIOCM_CTS;
+#endif
+
+ return mctrl;
+}
+
+static void nb85e_uart_start_tx (struct uart_port *port, unsigned tty_start)
+{
+ nb85e_intc_disable_irq (IRQ_INTST (port->line));
+ nb85e_uart_tx (port);
+ nb85e_intc_enable_irq (IRQ_INTST (port->line));
+}
+
+static void nb85e_uart_stop_tx (struct uart_port *port, unsigned tty_stop)
+{
+ nb85e_intc_disable_irq (IRQ_INTST (port->line));
+}
+
+static void nb85e_uart_start_rx (struct uart_port *port)
+{
+ nb85e_intc_enable_irq (IRQ_INTSR (port->line));
+}
+
+static void nb85e_uart_stop_rx (struct uart_port *port)
+{
+ nb85e_intc_disable_irq (IRQ_INTSR (port->line));
+}
+
+static void nb85e_uart_break_ctl (struct uart_port *port, int break_ctl)
+{
+ /* Umm, do this later. */
+}
+
+static int nb85e_uart_startup (struct uart_port *port)
+{
+ int err;
+
+ /* Alloc RX irq. */
+ err = request_irq (IRQ_INTSR (port->line), nb85e_uart_rx_irq,
+ SA_INTERRUPT, "nb85e_uart", port);
+ if (err)
+ return err;
+
+ /* Alloc TX irq. */
+ err = request_irq (IRQ_INTST (port->line), nb85e_uart_tx_irq,
+ SA_INTERRUPT, "nb85e_uart", port);
+ if (err) {
+ free_irq (IRQ_INTSR (port->line), port);
+ return err;
+ }
+
+ nb85e_uart_start_rx (port);
+
+ return 0;
+}
+
+static void nb85e_uart_shutdown (struct uart_port *port)
+{
+ /* Disable port interrupts. */
+ free_irq (IRQ_INTST (port->line), port);
+ free_irq (IRQ_INTSR (port->line), port);
+
+ /* Turn off xmit/recv enable bits. */
+ NB85E_UART_ASIM (port->line)
+ &= ~(NB85E_UART_ASIM_TXE | NB85E_UART_ASIM_RXE);
+ /* Then reset the channel. */
+ NB85E_UART_ASIM (port->line) = 0;
+}
+
+static void
+nb85e_uart_change_speed (struct uart_port *port, unsigned cflags,
+ unsigned iflag, unsigned quot)
+{
+ /* The serial framework doesn't give us the baud rate directly, but
+ insists on calculating a `quotient' from it, and giving us that
+ instead. Get the real baud rate from the tty code instead. */
+ int baud = tty_get_baud_rate (port->info->tty);
+
+ nb85e_uart_configure (port->line, cflags, baud);
+}
+
+static const char *nb85e_uart_type (struct uart_port *port)
+{
+ return port->type == PORT_NB85E_UART ? "nb85e_uart" : 0;
+}
+
+static void nb85e_uart_config_port (struct uart_port *port, int flags)
+{
+ if (flags & UART_CONFIG_TYPE)
+ port->type = PORT_NB85E_UART;
+}
+
+static int
+nb85e_uart_verify_port (struct uart_port *port, struct serial_struct *ser)
+{
+ if (ser->type != PORT_UNKNOWN && ser->type != PORT_NB85E_UART)
+ return -EINVAL;
+ if (ser->irq != IRQ_INTST (port->line))
+ return -EINVAL;
+ return 0;
+}
+
+static struct uart_ops nb85e_uart_ops = {
+ .tx_empty = nb85e_uart_tx_empty,
+ .get_mctrl = nb85e_uart_get_mctrl,
+ .set_mctrl = nb85e_uart_set_mctrl,
+ .start_tx = nb85e_uart_start_tx,
+ .stop_tx = nb85e_uart_stop_tx,
+ .stop_rx = nb85e_uart_stop_rx,
+ .enable_ms = nb85e_uart_nop,
+ .break_ctl = nb85e_uart_break_ctl,
+ .startup = nb85e_uart_startup,
+ .shutdown = nb85e_uart_shutdown,
+ .change_speed = nb85e_uart_change_speed,
+ .type = nb85e_uart_type,
+ .release_port = nb85e_uart_nop,
+ .request_port = nb85e_uart_success,
+ .config_port = nb85e_uart_config_port,
+ .verify_port = nb85e_uart_verify_port,
+};
+\f
+/* Initialization and cleanup. */
+
+static struct uart_driver nb85e_uart_driver = {
+ .owner = THIS_MODULE,
+ .driver_name = "nb85e_uart",
+#ifdef CONFIG_DEVFS_FS
+ .dev_name = "tts/%d",
+#else
+ .dev_name = "ttyS",
+#endif
+ .major = TTY_MAJOR,
+ .minor = NB85E_UART_MINOR_BASE,
+ .nr = NB85E_UART_NUM_CHANNELS,
+ .cons = NB85E_UART_CONSOLE,
+};
+
+
+static struct uart_port nb85e_uart_ports[NB85E_UART_NUM_CHANNELS];
+
+static int __init nb85e_uart_init (void)
+{
+ int rval;
+
+ printk (KERN_INFO "%s on-chip UART\n", NB85E_UART_CHIP_NAME);
+
+ rval = uart_register_driver (&nb85e_uart_driver);
+ if (rval == 0) {
+ unsigned chan;
+
+ for (chan = 0; chan < NB85E_UART_NUM_CHANNELS; chan++) {
+ int cksr_min;
+ struct uart_port *port = &nb85e_uart_ports[chan];
+
+ memset (port, 0, sizeof *port);
+
+ port->ops = &nb85e_uart_ops;
+ port->line = chan;
+ port->iotype = SERIAL_IO_MEM;
+ port->flags = UPF_BOOT_AUTOCONF;
+
+ /* We actually use multiple IRQs, but the serial
+ framework seems to mainly use this for
+ informational purposes anyway. Here we use the TX
+ irq. */
+ port->irq = IRQ_INTST (chan);
+
+ /* The serial framework doesn't really use these
+ membase/mapbase fields for anything useful, but
+ it requires that they be something non-zero to
+ consider the port `valid', and also uses them
+ for informational purposes. */
+ port->membase = (void *)NB85E_UART_BASE_ADDR (chan);
+ port->mapbase = NB85E_UART_BASE_ADDR (chan);
+
+ /* The framework insists on knowing the uart's master
+ clock freq, though it doesn't seem to do anything
+ useful for us with it. We must make it at least
+ higher than (the maximum baud rate * 16), otherwise
+ the framework will puke during its internal
+ calculations, and force the baud rate to be 9600.
+ To be accurate though, just repeat the calculation
+ we use when actually setting the speed. */
+ cksr_min = 0;
+ while ((NB85E_UART_BASE_FREQ >> cksr_min)
+ > NB85E_UART_CKSR_MAX_FREQ)
+ cksr_min++;
+ /* The `* 8' means `* 16 / 2': 16 to account for for
+ the serial framework's built-in bias, and 2 because
+ there's an additional / 2 in the hardware. */
+ port->uartclk = (NB85E_UART_BASE_FREQ >> cksr_min) * 8;
+
+ uart_add_one_port (&nb85e_uart_driver, port);
+ }
+ }
+
+ return rval;
+}
+
+static void __exit nb85e_uart_exit (void)
+{
+ unsigned chan;
+
+ for (chan = 0; chan < NB85E_UART_NUM_CHANNELS; chan++)
+ uart_remove_one_port (&nb85e_uart_driver,
+ &nb85e_uart_ports[chan]);
+
+ uart_unregister_driver (&nb85e_uart_driver);
+}
+
+module_init (nb85e_uart_init);
+module_exit (nb85e_uart_exit);
+
+EXPORT_NO_SYMBOLS;
+
+MODULE_AUTHOR ("Miles Bader");
+MODULE_DESCRIPTION ("NEC " NB85E_UART_CHIP_NAME " on-chip UART");
+MODULE_LICENSE ("GPL");