2007-12-21 06:29:45 +08:00
|
|
|
/*
|
|
|
|
* Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Infineon IFAP DC COM CPE
|
|
|
|
* Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
|
|
|
|
* Copyright (C) 2007 John Crispin <blogic@openwrt.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/circ_buf.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/serial_core.h>
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/sysrq.h>
|
|
|
|
#include <linux/irq.h>
|
2008-06-29 00:56:04 +08:00
|
|
|
#include <linux/platform_device.h>
|
2008-12-16 22:07:55 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
|
2007-12-21 06:29:45 +08:00
|
|
|
#include <asm/system.h>
|
2008-12-16 22:07:55 +08:00
|
|
|
|
2007-12-22 21:55:14 +08:00
|
|
|
#include <asm/ifxmips/ifxmips.h>
|
|
|
|
#include <asm/ifxmips/ifxmips_irq.h>
|
2007-12-21 06:29:45 +08:00
|
|
|
|
2007-12-22 08:17:22 +08:00
|
|
|
#define PORT_IFXMIPSASC 111
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
#include <linux/serial_core.h>
|
|
|
|
|
|
|
|
#define UART_DUMMY_UER_RX 1
|
|
|
|
|
2007-12-22 21:55:14 +08:00
|
|
|
static void ifxmipsasc_tx_chars(struct uart_port *port);
|
2008-12-16 22:07:55 +08:00
|
|
|
extern void prom_printf(const char *fmt, ...);
|
2008-06-26 07:05:50 +08:00
|
|
|
static struct uart_port ifxmipsasc_port[2];
|
2007-12-22 21:55:14 +08:00
|
|
|
static struct uart_driver ifxmipsasc_reg;
|
|
|
|
extern unsigned int ifxmips_get_fpi_hz(void);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_stop_tx(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_start_tx(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
2007-12-22 21:55:14 +08:00
|
|
|
ifxmipsasc_tx_chars(port);
|
2007-12-21 06:29:45 +08:00
|
|
|
local_irq_restore(flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_stop_rx(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ASCWHBSTATE_CLRREN, port->membase + IFXMIPS_ASC_WHBSTATE);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_enable_ms(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
#include <linux/version.h>
|
|
|
|
|
|
|
|
static void ifxmipsasc_rx_chars(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 26))
|
|
|
|
struct tty_struct *tty = port->info->port.tty;
|
|
|
|
#else
|
2007-12-21 06:29:45 +08:00
|
|
|
struct tty_struct *tty = port->info->tty;
|
2008-12-16 22:07:55 +08:00
|
|
|
#endif
|
2007-12-21 06:29:45 +08:00
|
|
|
unsigned int ch = 0, rsr = 0, fifocnt;
|
|
|
|
|
2008-06-26 07:05:50 +08:00
|
|
|
fifocnt = ifxmips_r32(port->membase + IFXMIPS_ASC_FSTAT) & ASCFSTAT_RXFFLMASK;
|
2008-12-16 22:07:55 +08:00
|
|
|
while (fifocnt--) {
|
2007-12-21 06:29:45 +08:00
|
|
|
u8 flag = TTY_NORMAL;
|
2008-06-26 07:05:50 +08:00
|
|
|
ch = ifxmips_r32(port->membase + IFXMIPS_ASC_RBUF);
|
|
|
|
rsr = (ifxmips_r32(port->membase + IFXMIPS_ASC_STATE) & ASCSTATE_ANY) | UART_DUMMY_UER_RX;
|
2007-12-21 06:29:45 +08:00
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
port->icount.rx++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the error handling code is
|
|
|
|
* out of the main execution path
|
|
|
|
*/
|
2008-12-16 22:07:55 +08:00
|
|
|
if (rsr & ASCSTATE_ANY) {
|
|
|
|
if (rsr & ASCSTATE_PE) {
|
2007-12-21 06:29:45 +08:00
|
|
|
port->icount.parity++;
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRPE, port->membase + IFXMIPS_ASC_WHBSTATE);
|
2008-12-16 22:07:55 +08:00
|
|
|
} else if (rsr & ASCSTATE_FE) {
|
2007-12-21 06:29:45 +08:00
|
|
|
port->icount.frame++;
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRFE, port->membase + IFXMIPS_ASC_WHBSTATE);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
2008-12-16 22:07:55 +08:00
|
|
|
if (rsr & ASCSTATE_ROE) {
|
2007-12-21 06:29:45 +08:00
|
|
|
port->icount.overrun++;
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRROE, port->membase + IFXMIPS_ASC_WHBSTATE);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rsr &= port->read_status_mask;
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (rsr & ASCSTATE_PE)
|
2007-12-21 06:29:45 +08:00
|
|
|
flag = TTY_PARITY;
|
2008-12-16 22:07:55 +08:00
|
|
|
else if (rsr & ASCSTATE_FE)
|
2007-12-21 06:29:45 +08:00
|
|
|
flag = TTY_FRAME;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if ((rsr & port->ignore_status_mask) == 0)
|
2007-12-21 06:29:45 +08:00
|
|
|
tty_insert_flip_char(tty, ch, flag);
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (rsr & ASCSTATE_ROE)
|
2007-12-21 06:29:45 +08:00
|
|
|
/*
|
|
|
|
* Overrun is special, since it's reported
|
|
|
|
* immediately, and doesn't affect the current
|
|
|
|
* character
|
|
|
|
*/
|
|
|
|
tty_insert_flip_char(tty, 0, TTY_OVERRUN);
|
|
|
|
}
|
2008-12-16 22:07:55 +08:00
|
|
|
if (ch != 0)
|
2007-12-21 06:29:45 +08:00
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_tx_chars(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
struct circ_buf *xmit = &port->info->xmit;
|
2008-12-16 22:07:55 +08:00
|
|
|
if (uart_tx_stopped(port)) {
|
2007-12-22 21:55:14 +08:00
|
|
|
ifxmipsasc_stop_tx(port);
|
2007-12-21 06:29:45 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
while (((ifxmips_r32(port->membase + IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK)
|
|
|
|
>> ASCFSTAT_TXFFLOFF) != TXFIFO_FULL) {
|
|
|
|
if (port->x_char) {
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(port->x_char, port->membase + IFXMIPS_ASC_TBUF);
|
2007-12-21 06:29:45 +08:00
|
|
|
port->icount.tx++;
|
|
|
|
port->x_char = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (uart_circ_empty(xmit))
|
2007-12-21 06:29:45 +08:00
|
|
|
break;
|
|
|
|
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(port->info->xmit.buf[port->info->xmit.tail], port->membase + IFXMIPS_ASC_TBUF);
|
2007-12-21 06:29:45 +08:00
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
port->icount.tx++;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
2007-12-21 06:29:45 +08:00
|
|
|
uart_write_wakeup(port);
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static irqreturn_t ifxmipsasc_tx_int(int irq, void *_port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
struct uart_port *port = (struct uart_port *)_port;
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ASC_IRNCR_TIR, port->membase + IFXMIPS_ASC_IRNCR);
|
2007-12-22 21:55:14 +08:00
|
|
|
ifxmipsasc_start_tx(port);
|
2008-06-24 04:31:34 +08:00
|
|
|
ifxmips_mask_and_ack_irq(irq);
|
2007-12-21 06:29:45 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static irqreturn_t ifxmipsasc_er_int(int irq, void *_port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
struct uart_port *port = (struct uart_port *)_port;
|
2007-12-21 06:29:45 +08:00
|
|
|
/* clear any pending interrupts */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_WHBSTATE) | ASCWHBSTATE_CLRPE |
|
|
|
|
ASCWHBSTATE_CLRFE | ASCWHBSTATE_CLRROE, port->membase + IFXMIPS_ASC_WHBSTATE);
|
2007-12-21 06:29:45 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static irqreturn_t ifxmipsasc_rx_int(int irq, void *_port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
struct uart_port *port = (struct uart_port *)_port;
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ASC_IRNCR_RIR, port->membase + IFXMIPS_ASC_IRNCR);
|
2008-12-16 22:07:55 +08:00
|
|
|
ifxmipsasc_rx_chars((struct uart_port *)port);
|
2008-06-24 04:31:34 +08:00
|
|
|
ifxmips_mask_and_ack_irq(irq);
|
2007-12-21 06:29:45 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static unsigned int ifxmipsasc_tx_empty(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
int status;
|
2008-06-26 07:05:50 +08:00
|
|
|
status = ifxmips_r32(port->membase + IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK;
|
2007-12-21 06:29:45 +08:00
|
|
|
return status ? 0 : TIOCSER_TEMT;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static unsigned int ifxmipsasc_get_mctrl(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
return TIOCM_CTS | TIOCM_CAR | TIOCM_DSR;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_set_mctrl(struct uart_port *port, u_int mctrl)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_break_ctl(struct uart_port *port, int break_state)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static int ifxmipsasc_startup(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int retval;
|
|
|
|
|
2008-06-29 00:56:04 +08:00
|
|
|
port->uartclk = ifxmips_get_fpi_hz();
|
2007-12-21 06:29:45 +08:00
|
|
|
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CLC) & ~IFXMIPS_ASC_CLC_DISS, port->membase + IFXMIPS_ASC_CLC);
|
|
|
|
ifxmips_w32(((ifxmips_r32(port->membase + IFXMIPS_ASC_CLC) & ~ASCCLC_RMCMASK)) | (1 << ASCCLC_RMCOFFSET), port->membase + IFXMIPS_ASC_CLC);
|
|
|
|
ifxmips_w32(0, port->membase + IFXMIPS_ASC_PISEL);
|
2008-07-06 07:06:07 +08:00
|
|
|
ifxmips_w32(((TXFIFO_FL << ASCTXFCON_TXFITLOFF) & ASCTXFCON_TXFITLMASK) | ASCTXFCON_TXFEN | ASCTXFCON_TXFFLU, port->membase + IFXMIPS_ASC_TXFCON);
|
|
|
|
ifxmips_w32(((RXFIFO_FL << ASCRXFCON_RXFITLOFF) & ASCRXFCON_RXFITLMASK) | ASCRXFCON_RXFEN | ASCRXFCON_RXFFLU, port->membase + IFXMIPS_ASC_RXFCON);
|
2008-12-16 22:07:55 +08:00
|
|
|
wmb();
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) | ASCCON_M_8ASYNC | ASCCON_FEN | ASCCON_TOEN | ASCCON_ROEN, port->membase + IFXMIPS_ASC_CON);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
2008-06-29 00:56:04 +08:00
|
|
|
retval = request_irq(port->irq, ifxmipsasc_tx_int, IRQF_DISABLED, "asc_tx", port);
|
2008-12-16 22:07:55 +08:00
|
|
|
if (retval) {
|
|
|
|
printk(KERN_ERR "failed to request ifxmipsasc_tx_int\n");
|
2007-12-21 06:29:45 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-06-29 00:56:04 +08:00
|
|
|
retval = request_irq(port->irq + 2, ifxmipsasc_rx_int, IRQF_DISABLED, "asc_rx", port);
|
2008-12-16 22:07:55 +08:00
|
|
|
if (retval) {
|
|
|
|
printk(KERN_ERR "failed to request ifxmipsasc_rx_int\n");
|
2007-12-21 06:29:45 +08:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
2008-06-26 07:05:50 +08:00
|
|
|
retval = request_irq(port->irq + 3, ifxmipsasc_er_int, IRQF_DISABLED, "asc_er", port);
|
2008-12-16 22:07:55 +08:00
|
|
|
if (retval) {
|
|
|
|
printk(KERN_ERR "failed to request ifxmipsasc_er_int\n");
|
2007-12-21 06:29:45 +08:00
|
|
|
goto err2;
|
|
|
|
}
|
|
|
|
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ASC_IRNREN_RX_BUF | ASC_IRNREN_TX_BUF | ASC_IRNREN_ERR | ASC_IRNREN_TX, port->membase + IFXMIPS_ASC_IRNREN);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err2:
|
2008-06-26 07:05:50 +08:00
|
|
|
free_irq(port->irq + 2, port);
|
2007-12-21 06:29:45 +08:00
|
|
|
err1:
|
2008-06-26 07:05:50 +08:00
|
|
|
free_irq(port->irq, port);
|
2007-12-21 06:29:45 +08:00
|
|
|
local_irq_restore(flags);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_shutdown(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-06-26 07:05:50 +08:00
|
|
|
free_irq(port->irq, port);
|
|
|
|
free_irq(port->irq + 2, port);
|
|
|
|
free_irq(port->irq + 3, port);
|
|
|
|
|
|
|
|
ifxmips_w32(0, port->membase + IFXMIPS_ASC_CON);
|
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_RXFCON) | ASCRXFCON_RXFFLU, port->membase + IFXMIPS_ASC_RXFCON);
|
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_RXFCON) & ~ASCRXFCON_RXFEN, port->membase + IFXMIPS_ASC_RXFCON);
|
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_TXFCON) | ASCTXFCON_TXFFLU, port->membase + IFXMIPS_ASC_TXFCON);
|
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_TXFCON) & ~ASCTXFCON_TXFEN, port->membase + IFXMIPS_ASC_TXFCON);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
2007-12-22 21:55:14 +08:00
|
|
|
static void ifxmipsasc_set_termios(struct uart_port *port, struct ktermios *new, struct ktermios *old)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
unsigned int cflag;
|
|
|
|
unsigned int iflag;
|
|
|
|
unsigned int quot;
|
|
|
|
unsigned int baud;
|
|
|
|
unsigned int con = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
cflag = new->c_cflag;
|
|
|
|
iflag = new->c_iflag;
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
switch (cflag & CSIZE) {
|
2007-12-21 06:29:45 +08:00
|
|
|
case CS7:
|
|
|
|
con = ASCCON_M_7ASYNC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CS5:
|
|
|
|
case CS6:
|
|
|
|
default:
|
|
|
|
con = ASCCON_M_8ASYNC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (cflag & CSTOPB)
|
2007-12-21 06:29:45 +08:00
|
|
|
con |= ASCCON_STP;
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (cflag & PARENB) {
|
|
|
|
if (!(cflag & PARODD))
|
2007-12-21 06:29:45 +08:00
|
|
|
con &= ~ASCCON_ODD;
|
|
|
|
else
|
|
|
|
con |= ASCCON_ODD;
|
|
|
|
}
|
|
|
|
|
|
|
|
port->read_status_mask = ASCSTATE_ROE;
|
2008-12-16 22:07:55 +08:00
|
|
|
if (iflag & INPCK)
|
2007-12-21 06:29:45 +08:00
|
|
|
port->read_status_mask |= ASCSTATE_FE | ASCSTATE_PE;
|
|
|
|
|
|
|
|
port->ignore_status_mask = 0;
|
2008-12-16 22:07:55 +08:00
|
|
|
if (iflag & IGNPAR)
|
2007-12-21 06:29:45 +08:00
|
|
|
port->ignore_status_mask |= ASCSTATE_FE | ASCSTATE_PE;
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (iflag & IGNBRK) {
|
2007-12-21 06:29:45 +08:00
|
|
|
/*
|
|
|
|
* If we're ignoring parity and break indicators,
|
|
|
|
* ignore overruns too (for real raw support).
|
|
|
|
*/
|
2008-12-16 22:07:55 +08:00
|
|
|
if (iflag & IGNPAR)
|
2007-12-21 06:29:45 +08:00
|
|
|
port->ignore_status_mask |= ASCSTATE_ROE;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if ((cflag & CREAD) == 0)
|
2007-12-21 06:29:45 +08:00
|
|
|
port->ignore_status_mask |= UART_DUMMY_UER_RX;
|
|
|
|
|
|
|
|
/* set error signals - framing, parity and overrun, enable receiver */
|
|
|
|
con |= ASCCON_FEN | ASCCON_TOEN | ASCCON_ROEN;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
/* set up CON */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) | con, port->membase + IFXMIPS_ASC_CON);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
/* Set baud rate - take a divider of 2 into account */
|
2008-12-16 22:07:55 +08:00
|
|
|
baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16);
|
2007-12-21 06:29:45 +08:00
|
|
|
quot = uart_get_divisor(port, baud);
|
|
|
|
quot = quot / 2 - 1;
|
|
|
|
|
|
|
|
/* disable the baudrate generator */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) & ~ASCCON_R, port->membase + IFXMIPS_ASC_CON);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
/* make sure the fractional divider is off */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) & ~ASCCON_FDE, port->membase + IFXMIPS_ASC_CON);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
/* set up to use divisor of 2 */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) & ~ASCCON_BRS, port->membase + IFXMIPS_ASC_CON);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
/* now we can write the new baudrate into the register */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(quot, port->membase + IFXMIPS_ASC_BG);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
/* turn the baudrate generator back on */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ifxmips_r32(port->membase + IFXMIPS_ASC_CON) | ASCCON_R, port->membase + IFXMIPS_ASC_CON);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
/* enable rx */
|
2008-06-26 07:05:50 +08:00
|
|
|
ifxmips_w32(ASCWHBSTATE_SETREN, port->membase + IFXMIPS_ASC_WHBSTATE);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static const char *ifxmipsasc_type(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
if (port->type == PORT_IFXMIPSASC) {
|
|
|
|
if (port->membase == (void *)IFXMIPS_ASC_BASE_ADDR)
|
2008-06-29 00:56:04 +08:00
|
|
|
return "asc0";
|
|
|
|
else
|
|
|
|
return "asc1";
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_release_port(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static int ifxmipsasc_request_port(struct uart_port *port)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_config_port(struct uart_port *port, int flags)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
if (flags & UART_CONFIG_TYPE) {
|
2007-12-22 08:17:22 +08:00
|
|
|
port->type = PORT_IFXMIPSASC;
|
2007-12-22 21:55:14 +08:00
|
|
|
ifxmipsasc_request_port(port);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static int ifxmipsasc_verify_port(struct uart_port *port, struct serial_struct *ser)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-12-16 22:07:55 +08:00
|
|
|
if (ser->type != PORT_UNKNOWN && ser->type != PORT_IFXMIPSASC)
|
2007-12-21 06:29:45 +08:00
|
|
|
ret = -EINVAL;
|
2008-12-16 22:07:55 +08:00
|
|
|
if (ser->irq < 0 || ser->irq >= NR_IRQS)
|
2007-12-21 06:29:45 +08:00
|
|
|
ret = -EINVAL;
|
2008-12-16 22:07:55 +08:00
|
|
|
if (ser->baud_base < 9600)
|
2007-12-21 06:29:45 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static struct uart_ops ifxmipsasc_pops = {
|
|
|
|
.tx_empty = ifxmipsasc_tx_empty,
|
2007-12-22 21:55:14 +08:00
|
|
|
.set_mctrl = ifxmipsasc_set_mctrl,
|
|
|
|
.get_mctrl = ifxmipsasc_get_mctrl,
|
2008-12-16 22:07:55 +08:00
|
|
|
.stop_tx = ifxmipsasc_stop_tx,
|
|
|
|
.start_tx = ifxmipsasc_start_tx,
|
|
|
|
.stop_rx = ifxmipsasc_stop_rx,
|
2007-12-22 21:55:14 +08:00
|
|
|
.enable_ms = ifxmipsasc_enable_ms,
|
|
|
|
.break_ctl = ifxmipsasc_break_ctl,
|
2008-12-16 22:07:55 +08:00
|
|
|
.startup = ifxmipsasc_startup,
|
|
|
|
.shutdown = ifxmipsasc_shutdown,
|
2007-12-22 21:55:14 +08:00
|
|
|
.set_termios = ifxmipsasc_set_termios,
|
2008-12-16 22:07:55 +08:00
|
|
|
.type = ifxmipsasc_type,
|
2007-12-22 21:55:14 +08:00
|
|
|
.release_port = ifxmipsasc_release_port,
|
|
|
|
.request_port = ifxmipsasc_request_port,
|
|
|
|
.config_port = ifxmipsasc_config_port,
|
|
|
|
.verify_port = ifxmipsasc_verify_port,
|
2007-12-21 06:29:45 +08:00
|
|
|
};
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static struct uart_port ifxmipsasc_port[2] = {
|
2008-06-26 07:05:50 +08:00
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
.membase = (void *)IFXMIPS_ASC_BASE_ADDR,
|
|
|
|
.mapbase = IFXMIPS_ASC_BASE_ADDR,
|
|
|
|
.iotype = SERIAL_IO_MEM,
|
|
|
|
.irq = IFXMIPSASC_TIR(0),
|
|
|
|
.uartclk = 0,
|
|
|
|
.fifosize = 16,
|
|
|
|
.type = PORT_IFXMIPSASC,
|
|
|
|
.ops = &ifxmipsasc_pops,
|
|
|
|
.flags = ASYNC_BOOT_AUTOCONF,
|
|
|
|
.line = 0
|
2008-06-26 07:05:50 +08:00
|
|
|
}, {
|
2008-12-16 22:07:55 +08:00
|
|
|
.membase = (void *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_BASE_DIFF),
|
|
|
|
.mapbase = IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_BASE_DIFF,
|
|
|
|
.iotype = SERIAL_IO_MEM,
|
|
|
|
.irq = IFXMIPSASC_TIR(1),
|
|
|
|
.uartclk = 0,
|
|
|
|
.fifosize = 16,
|
|
|
|
.type = PORT_IFXMIPSASC,
|
|
|
|
.ops = &ifxmipsasc_pops,
|
|
|
|
.flags = ASYNC_BOOT_AUTOCONF,
|
|
|
|
.line = 1
|
2008-06-26 07:05:50 +08:00
|
|
|
}
|
2007-12-21 06:29:45 +08:00
|
|
|
};
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static void ifxmipsasc_console_write(struct console *co, const char *s, u_int count)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-06-29 00:56:04 +08:00
|
|
|
int port = co->index;
|
2007-12-21 06:29:45 +08:00
|
|
|
int i, fifocnt;
|
|
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
2008-12-16 22:07:55 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
2008-06-29 00:56:04 +08:00
|
|
|
do {
|
2008-12-16 22:07:55 +08:00
|
|
|
fifocnt = (ifxmips_r32((u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_FSTAT)) & ASCFSTAT_TXFFLMASK)
|
|
|
|
>> ASCFSTAT_TXFFLOFF;
|
|
|
|
} while (fifocnt == TXFIFO_FULL);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (s[i] == '\0')
|
2007-12-21 06:29:45 +08:00
|
|
|
break;
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
if (s[i] == '\n') {
|
|
|
|
ifxmips_w32('\r', (u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_TBUF));
|
2008-06-29 00:56:04 +08:00
|
|
|
do {
|
2008-12-16 22:07:55 +08:00
|
|
|
fifocnt = (ifxmips_r32((u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_FSTAT)) & ASCFSTAT_TXFFLMASK)
|
2007-12-21 06:29:45 +08:00
|
|
|
>> ASCFSTAT_TXFFLOFF;
|
2008-12-16 22:07:55 +08:00
|
|
|
} while (fifocnt == TXFIFO_FULL);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
2008-12-16 22:07:55 +08:00
|
|
|
ifxmips_w32(s[i], (u32 *)(IFXMIPS_ASC_BASE_ADDR + (port * IFXMIPS_ASC_BASE_DIFF) + IFXMIPS_ASC_TBUF));
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static int __init ifxmipsasc_console_setup(struct console *co, char *options)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-06-29 00:56:04 +08:00
|
|
|
int port = co->index;
|
2007-12-21 06:29:45 +08:00
|
|
|
int baud = 115200;
|
|
|
|
int bits = 8;
|
|
|
|
int parity = 'n';
|
|
|
|
int flow = 'n';
|
2008-06-29 00:56:04 +08:00
|
|
|
ifxmipsasc_port[port].uartclk = ifxmips_get_fpi_hz();
|
|
|
|
ifxmipsasc_port[port].type = PORT_IFXMIPSASC;
|
2008-12-16 22:07:55 +08:00
|
|
|
if (options)
|
2007-12-21 06:29:45 +08:00
|
|
|
uart_parse_options(options, &baud, &parity, &bits, &flow);
|
2008-06-29 00:56:04 +08:00
|
|
|
return uart_set_options(&ifxmipsasc_port[port], co, baud, parity, bits, flow);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
2008-06-26 07:05:50 +08:00
|
|
|
static struct console ifxmipsasc_console[2] =
|
|
|
|
{
|
|
|
|
{
|
2008-12-16 22:07:55 +08:00
|
|
|
.name = "ttyS",
|
|
|
|
.write = ifxmipsasc_console_write,
|
|
|
|
.device = uart_console_device,
|
|
|
|
.setup = ifxmipsasc_console_setup,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = 0,
|
|
|
|
.data = &ifxmipsasc_reg,
|
2008-06-26 07:05:50 +08:00
|
|
|
}, {
|
2008-12-16 22:07:55 +08:00
|
|
|
.name = "ttyS",
|
|
|
|
.write = ifxmipsasc_console_write,
|
|
|
|
.device = uart_console_device,
|
|
|
|
.setup = ifxmipsasc_console_setup,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = 1,
|
|
|
|
.data = &ifxmipsasc_reg,
|
2008-06-26 07:05:50 +08:00
|
|
|
}
|
2007-12-21 06:29:45 +08:00
|
|
|
};
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static int __init ifxmipsasc_console_init(void)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-06-26 07:05:50 +08:00
|
|
|
register_console(&ifxmipsasc_console[0]);
|
|
|
|
register_console(&ifxmipsasc_console[1]);
|
2007-12-21 06:29:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2007-12-22 21:55:14 +08:00
|
|
|
console_initcall(ifxmipsasc_console_init);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
static struct uart_driver ifxmipsasc_reg = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.driver_name = "serial",
|
|
|
|
.dev_name = "ttyS",
|
|
|
|
.major = TTY_MAJOR,
|
|
|
|
.minor = 64,
|
|
|
|
.nr = 2,
|
|
|
|
.cons = &ifxmipsasc_console[1],
|
2007-12-21 06:29:45 +08:00
|
|
|
};
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
int __init ifxmipsasc_init(void)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2008-06-29 00:56:04 +08:00
|
|
|
int ret;
|
2007-12-22 21:55:14 +08:00
|
|
|
uart_register_driver(&ifxmipsasc_reg);
|
2008-06-29 00:56:04 +08:00
|
|
|
ret = uart_add_one_port(&ifxmipsasc_reg, &ifxmipsasc_port[0]);
|
|
|
|
ret = uart_add_one_port(&ifxmipsasc_reg, &ifxmipsasc_port[1]);
|
|
|
|
return 0;
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
2008-12-16 22:07:55 +08:00
|
|
|
void __exit ifxmipsasc_exit(void)
|
2007-12-21 06:29:45 +08:00
|
|
|
{
|
2007-12-22 21:55:14 +08:00
|
|
|
uart_unregister_driver(&ifxmipsasc_reg);
|
2007-12-21 06:29:45 +08:00
|
|
|
}
|
|
|
|
|
2007-12-22 21:55:14 +08:00
|
|
|
module_init(ifxmipsasc_init);
|
|
|
|
module_exit(ifxmipsasc_exit);
|
2007-12-21 06:29:45 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
|
2007-12-22 21:55:14 +08:00
|
|
|
MODULE_DESCRIPTION("MIPS IFXMips serial port driver");
|
2007-12-21 06:29:45 +08:00
|
|
|
MODULE_LICENSE("GPL");
|