/* 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-2003 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/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 <linux/bitops.h>
#include <linux/delay.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.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 m68k_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 = (m68328_uart *)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;
/* 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
static void change_speed(struct m68k_serial *info);
/*
* 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;
static inline int serial_paranoia_check(struct m68k_serial *info,
char *name, 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 m68k_serial for %s in %s\n";
if (!info) {
printk(badinfo, name, routine);
return 1;
}
if (info->magic != SERIAL_MAGIC) {
printk(badmagic, name, 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->name, "rs_stop"))
return;
local_irq_save(flags);
uart->ustcnt &= ~USTCNT_TXEN;
local_irq_restore(flags);
}
static void rs_put_char(char ch)
{
int flags, loops = 0;
local_irq_save(flags);
while (!(UTX & UTX_TX_AVAIL) && (loops < 1000)) {
loops++;
udelay(5);
}
UTX_TXDATA = ch;
udelay(5);
local_irq_restore(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->name, "rs_start"))
return;
local_irq_save(flags);
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
}
local_irq_restore(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 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 void receive_chars(struct m68k_serial *info, unsigned short rx)
{
struct tty_struct *tty = info->tty;
m68328_uart *uart = &uart_addr[info->line];
unsigned char ch, flag;
/*
* 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 */
emergency_restart();
return;
#endif
|