2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Driver for CLPS711x serial ports
|
|
|
|
*
|
|
|
|
* Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* Copyright 1999 ARM Limited
|
|
|
|
* Copyright (C) 2000 Deep Blue Solutions Ltd.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(CONFIG_SERIAL_CLPS711X_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
|
|
|
|
#define SUPPORT_SYSRQ
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
2012-10-14 15:05:34 +08:00
|
|
|
#include <linux/console.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/serial_core.h>
|
|
|
|
#include <linux/serial.h>
|
2009-03-25 18:21:35 +08:00
|
|
|
#include <linux/io.h>
|
2012-10-14 15:05:26 +08:00
|
|
|
#include <linux/clk.h>
|
2012-10-14 15:05:34 +08:00
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/ioport.h>
|
2012-10-14 15:05:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-05 23:14:15 +08:00
|
|
|
#include <mach/hardware.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:23 +08:00
|
|
|
#define UART_CLPS711X_NAME "uart-clps711x"
|
2012-10-14 15:05:24 +08:00
|
|
|
#define UART_CLPS711X_NR 2
|
|
|
|
#define UART_CLPS711X_MAJOR 204
|
|
|
|
#define UART_CLPS711X_MINOR 40
|
2012-10-14 15:05:23 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
#define UBRLCR(port) ((port)->line ? UBRLCR2 : UBRLCR1)
|
|
|
|
#define UARTDR(port) ((port)->line ? UARTDR2 : UARTDR1)
|
|
|
|
#define SYSFLG(port) ((port)->line ? SYSFLG2 : SYSFLG1)
|
|
|
|
#define SYSCON(port) ((port)->line ? SYSCON2 : SYSCON1)
|
|
|
|
#define TX_IRQ(port) ((port)->line ? IRQ_UTXINT2 : IRQ_UTXINT1)
|
|
|
|
#define RX_IRQ(port) ((port)->line ? IRQ_URXINT2 : IRQ_URXINT1)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
struct clps711x_port {
|
|
|
|
struct uart_driver uart;
|
2012-10-14 15:05:26 +08:00
|
|
|
struct clk *uart_clk;
|
2012-10-14 15:05:24 +08:00
|
|
|
struct uart_port port[UART_CLPS711X_NR];
|
2012-10-14 15:05:25 +08:00
|
|
|
int tx_enabled[UART_CLPS711X_NR];
|
2012-10-14 15:05:24 +08:00
|
|
|
#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
|
|
|
|
struct console console;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_stop_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:25 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
|
|
|
|
|
|
|
if (s->tx_enabled[port->line]) {
|
2005-04-17 06:20:36 +08:00
|
|
|
disable_irq(TX_IRQ(port));
|
2012-10-14 15:05:25 +08:00
|
|
|
s->tx_enabled[port->line] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_start_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:25 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
|
|
|
|
|
|
|
if (!s->tx_enabled[port->line]) {
|
2005-04-17 06:20:36 +08:00
|
|
|
enable_irq(TX_IRQ(port));
|
2012-10-14 15:05:25 +08:00
|
|
|
s->tx_enabled[port->line] = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_stop_rx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
disable_irq(RX_IRQ(port));
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_enable_ms(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:34 +08:00
|
|
|
/* Do nothing */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:31 +08:00
|
|
|
static irqreturn_t uart_clps711x_int_rx(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_port *port = dev_id;
|
2005-09-24 17:12:47 +08:00
|
|
|
unsigned int status, ch, flg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
for (;;) {
|
|
|
|
status = clps_readl(SYSFLG(port));
|
|
|
|
if (status & SYSFLG_URXFE)
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
ch = clps_readw(UARTDR(port));
|
|
|
|
status = ch & (UARTDR_FRMERR | UARTDR_PARERR | UARTDR_OVERR);
|
|
|
|
ch &= 0xff;
|
|
|
|
|
|
|
|
port->icount.rx++;
|
2005-04-17 06:20:36 +08:00
|
|
|
flg = TTY_NORMAL;
|
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
if (unlikely(status)) {
|
|
|
|
if (status & UARTDR_PARERR)
|
2005-04-26 22:32:00 +08:00
|
|
|
port->icount.parity++;
|
2012-10-14 15:05:30 +08:00
|
|
|
else if (status & UARTDR_FRMERR)
|
2005-04-26 22:32:00 +08:00
|
|
|
port->icount.frame++;
|
2012-10-14 15:05:30 +08:00
|
|
|
else if (status & UARTDR_OVERR)
|
2005-04-26 22:32:00 +08:00
|
|
|
port->icount.overrun++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
status &= port->read_status_mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
if (status & UARTDR_PARERR)
|
2005-04-26 22:32:00 +08:00
|
|
|
flg = TTY_PARITY;
|
2012-10-14 15:05:30 +08:00
|
|
|
else if (status & UARTDR_FRMERR)
|
2005-04-26 22:32:00 +08:00
|
|
|
flg = TTY_FRAME;
|
2012-10-14 15:05:30 +08:00
|
|
|
else if (status & UARTDR_OVERR)
|
|
|
|
flg = TTY_OVERRUN;
|
2005-04-26 22:32:00 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
if (uart_handle_sysrq_char(port, ch))
|
2012-10-14 15:05:30 +08:00
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
if (status & port->ignore_status_mask)
|
|
|
|
continue;
|
2005-04-26 22:32:00 +08:00
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
uart_insert_char(port, status, UARTDR_OVERR, ch, flg);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2012-10-14 15:05:30 +08:00
|
|
|
|
2013-01-03 22:53:06 +08:00
|
|
|
tty_flip_buffer_push(&port->state->port);
|
2012-10-14 15:05:30 +08:00
|
|
|
|
2005-04-26 22:32:00 +08:00
|
|
|
return IRQ_HANDLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:31 +08:00
|
|
|
static irqreturn_t uart_clps711x_int_tx(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_port *port = dev_id;
|
2012-10-14 15:05:25 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
2009-09-20 04:13:28 +08:00
|
|
|
struct circ_buf *xmit = &port->state->xmit;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (port->x_char) {
|
2012-10-14 15:05:34 +08:00
|
|
|
clps_writew(port->x_char, UARTDR(port));
|
2005-04-17 06:20:36 +08:00
|
|
|
port->icount.tx++;
|
|
|
|
port->x_char = 0;
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2012-03-27 16:22:49 +08:00
|
|
|
|
2012-10-14 15:05:25 +08:00
|
|
|
if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
|
|
|
|
disable_irq_nosync(TX_IRQ(port));
|
|
|
|
s->tx_enabled[port->line] = 0;
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:27 +08:00
|
|
|
while (!uart_circ_empty(xmit)) {
|
|
|
|
clps_writew(xmit->buf[xmit->tail], UARTDR(port));
|
2005-04-17 06:20:36 +08:00
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
port->icount.tx++;
|
2012-10-14 15:05:27 +08:00
|
|
|
if (clps_readl(SYSFLG(port) & SYSFLG_UTXFF))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2012-10-14 15:05:27 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(port);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static unsigned int uart_clps711x_tx_empty(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:34 +08:00
|
|
|
return (clps_readl(SYSFLG(port) & SYSFLG_UBUSY)) ? 0 : TIOCSER_TEMT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static unsigned int uart_clps711x_get_mctrl(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:28 +08:00
|
|
|
unsigned int status, result = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:28 +08:00
|
|
|
if (port->line == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
status = clps_readl(SYSFLG1);
|
|
|
|
if (status & SYSFLG1_DCD)
|
|
|
|
result |= TIOCM_CAR;
|
|
|
|
if (status & SYSFLG1_DSR)
|
|
|
|
result |= TIOCM_DSR;
|
|
|
|
if (status & SYSFLG1_CTS)
|
|
|
|
result |= TIOCM_CTS;
|
2012-10-14 15:05:28 +08:00
|
|
|
} else
|
|
|
|
result = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:34 +08:00
|
|
|
/* Do nothing */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_break_ctl(struct uart_port *port, int break_state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int ubrlcr;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2012-10-14 15:05:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ubrlcr = clps_readl(UBRLCR(port));
|
2012-10-14 15:05:29 +08:00
|
|
|
if (break_state)
|
2005-04-17 06:20:36 +08:00
|
|
|
ubrlcr |= UBRLCR_BREAK;
|
|
|
|
else
|
|
|
|
ubrlcr &= ~UBRLCR_BREAK;
|
|
|
|
clps_writel(ubrlcr, UBRLCR(port));
|
2012-10-14 15:05:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static int uart_clps711x_startup(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:25 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
2012-10-14 15:05:31 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:25 +08:00
|
|
|
s->tx_enabled[port->line] = 1;
|
2012-10-14 15:05:31 +08:00
|
|
|
/* Allocate the IRQs */
|
|
|
|
ret = devm_request_irq(port->dev, TX_IRQ(port), uart_clps711x_int_tx,
|
|
|
|
0, UART_CLPS711X_NAME " TX", port);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = devm_request_irq(port->dev, RX_IRQ(port), uart_clps711x_int_rx,
|
|
|
|
0, UART_CLPS711X_NAME " RX", port);
|
|
|
|
if (ret) {
|
|
|
|
devm_free_irq(port->dev, TX_IRQ(port), port);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:32 +08:00
|
|
|
/* Disable break */
|
|
|
|
clps_writel(clps_readl(UBRLCR(port)) & ~UBRLCR_BREAK, UBRLCR(port));
|
|
|
|
|
|
|
|
/* Enable the port */
|
|
|
|
clps_writel(clps_readl(SYSCON(port)) | SYSCON_UARTEN, SYSCON(port));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_shutdown(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:31 +08:00
|
|
|
/* Free the interrupts */
|
|
|
|
devm_free_irq(port->dev, TX_IRQ(port), port);
|
|
|
|
devm_free_irq(port->dev, RX_IRQ(port), port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:32 +08:00
|
|
|
/* Disable the port */
|
|
|
|
clps_writel(clps_readl(SYSCON(port)) & ~SYSCON_UARTEN, SYSCON(port));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_set_termios(struct uart_port *port,
|
|
|
|
struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int ubrlcr, baud, quot;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2012-10-14 15:05:33 +08:00
|
|
|
/* Mask termios capabilities we don't support */
|
|
|
|
termios->c_cflag &= ~CMSPAR;
|
|
|
|
termios->c_iflag &= ~(BRKINT | IGNBRK);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:26 +08:00
|
|
|
/* Ask the core to calculate the divisor for us */
|
|
|
|
baud = uart_get_baud_rate(port, termios, old, port->uartclk / 4096,
|
|
|
|
port->uartclk / 16);
|
2005-04-17 06:20:36 +08:00
|
|
|
quot = uart_get_divisor(port, baud);
|
|
|
|
|
|
|
|
switch (termios->c_cflag & CSIZE) {
|
|
|
|
case CS5:
|
|
|
|
ubrlcr = UBRLCR_WRDLEN5;
|
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
ubrlcr = UBRLCR_WRDLEN6;
|
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
ubrlcr = UBRLCR_WRDLEN7;
|
|
|
|
break;
|
2012-10-14 15:05:34 +08:00
|
|
|
case CS8:
|
|
|
|
default:
|
2005-04-17 06:20:36 +08:00
|
|
|
ubrlcr = UBRLCR_WRDLEN8;
|
|
|
|
break;
|
|
|
|
}
|
2012-10-14 15:05:33 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (termios->c_cflag & CSTOPB)
|
|
|
|
ubrlcr |= UBRLCR_XSTOP;
|
2012-10-14 15:05:33 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (termios->c_cflag & PARENB) {
|
|
|
|
ubrlcr |= UBRLCR_PRTEN;
|
|
|
|
if (!(termios->c_cflag & PARODD))
|
|
|
|
ubrlcr |= UBRLCR_EVENPRT;
|
|
|
|
}
|
2012-10-14 15:05:27 +08:00
|
|
|
|
|
|
|
/* Enable FIFO */
|
|
|
|
ubrlcr |= UBRLCR_FIFOEN;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
|
2012-10-14 15:05:33 +08:00
|
|
|
/* Set read status mask */
|
2005-04-17 06:20:36 +08:00
|
|
|
port->read_status_mask = UARTDR_OVERR;
|
|
|
|
if (termios->c_iflag & INPCK)
|
|
|
|
port->read_status_mask |= UARTDR_PARERR | UARTDR_FRMERR;
|
|
|
|
|
2012-10-14 15:05:33 +08:00
|
|
|
/* Set status ignore mask */
|
2005-04-17 06:20:36 +08:00
|
|
|
port->ignore_status_mask = 0;
|
2012-10-14 15:05:33 +08:00
|
|
|
if (!(termios->c_cflag & CREAD))
|
|
|
|
port->ignore_status_mask |= UARTDR_OVERR | UARTDR_PARERR |
|
|
|
|
UARTDR_FRMERR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:33 +08:00
|
|
|
uart_update_timeout(port, termios->c_cflag, baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:33 +08:00
|
|
|
clps_writel(ubrlcr | (quot - 1), UBRLCR(port));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static const char *uart_clps711x_type(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:34 +08:00
|
|
|
return (port->type == PORT_CLPS711X) ? "CLPS711X" : NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_config_port(struct uart_port *port, int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (flags & UART_CONFIG_TYPE)
|
|
|
|
port->type = PORT_CLPS711X;
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static void uart_clps711x_release_port(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:34 +08:00
|
|
|
/* Do nothing */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static int uart_clps711x_request_port(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:34 +08:00
|
|
|
/* Do nothing */
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:34 +08:00
|
|
|
static const struct uart_ops uart_clps711x_ops = {
|
|
|
|
.tx_empty = uart_clps711x_tx_empty,
|
|
|
|
.set_mctrl = uart_clps711x_set_mctrl,
|
|
|
|
.get_mctrl = uart_clps711x_get_mctrl,
|
|
|
|
.stop_tx = uart_clps711x_stop_tx,
|
|
|
|
.start_tx = uart_clps711x_start_tx,
|
|
|
|
.stop_rx = uart_clps711x_stop_rx,
|
|
|
|
.enable_ms = uart_clps711x_enable_ms,
|
|
|
|
.break_ctl = uart_clps711x_break_ctl,
|
|
|
|
.startup = uart_clps711x_startup,
|
|
|
|
.shutdown = uart_clps711x_shutdown,
|
|
|
|
.set_termios = uart_clps711x_set_termios,
|
|
|
|
.type = uart_clps711x_type,
|
|
|
|
.config_port = uart_clps711x_config_port,
|
|
|
|
.release_port = uart_clps711x_release_port,
|
|
|
|
.request_port = uart_clps711x_request_port,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
|
2012-10-14 15:05:24 +08:00
|
|
|
static void uart_clps711x_console_putchar(struct uart_port *port, int ch)
|
2006-03-21 04:00:09 +08:00
|
|
|
{
|
|
|
|
while (clps_readl(SYSFLG(port)) & SYSFLG_UTXFF)
|
|
|
|
barrier();
|
2012-10-14 15:05:24 +08:00
|
|
|
|
|
|
|
clps_writew(ch, UARTDR(port));
|
2006-03-21 04:00:09 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
static void uart_clps711x_console_write(struct console *co, const char *c,
|
|
|
|
unsigned n)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:24 +08:00
|
|
|
struct clps711x_port *s = (struct clps711x_port *)co->data;
|
|
|
|
struct uart_port *port = &s->port[co->index];
|
|
|
|
u32 syscon;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
/* Ensure that the port is enabled */
|
2005-04-17 06:20:36 +08:00
|
|
|
syscon = clps_readl(SYSCON(port));
|
|
|
|
clps_writel(syscon | SYSCON_UARTEN, SYSCON(port));
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
uart_console_write(port, c, n, uart_clps711x_console_putchar);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
/* Wait for transmitter to become empty */
|
|
|
|
while (clps_readl(SYSFLG(port)) & SYSFLG_UBUSY)
|
|
|
|
barrier();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
/* Restore the uart state */
|
2005-04-17 06:20:36 +08:00
|
|
|
clps_writel(syscon, SYSCON(port));
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
static void uart_clps711x_console_get_options(struct uart_port *port,
|
|
|
|
int *baud, int *parity,
|
|
|
|
int *bits)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (clps_readl(SYSCON(port)) & SYSCON_UARTEN) {
|
|
|
|
unsigned int ubrlcr, quot;
|
|
|
|
|
|
|
|
ubrlcr = clps_readl(UBRLCR(port));
|
|
|
|
|
|
|
|
*parity = 'n';
|
|
|
|
if (ubrlcr & UBRLCR_PRTEN) {
|
|
|
|
if (ubrlcr & UBRLCR_EVENPRT)
|
|
|
|
*parity = 'e';
|
|
|
|
else
|
|
|
|
*parity = 'o';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ubrlcr & UBRLCR_WRDLEN_MASK) == UBRLCR_WRDLEN7)
|
|
|
|
*bits = 7;
|
|
|
|
else
|
|
|
|
*bits = 8;
|
|
|
|
|
|
|
|
quot = ubrlcr & UBRLCR_BAUD_MASK;
|
|
|
|
*baud = port->uartclk / (16 * (quot + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
static int uart_clps711x_console_setup(struct console *co, char *options)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:24 +08:00
|
|
|
int baud = 38400, bits = 8, parity = 'n', flow = 'n';
|
|
|
|
struct clps711x_port *s = (struct clps711x_port *)co->data;
|
|
|
|
struct uart_port *port = &s->port[(co->index > 0) ? co->index : 0];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (options)
|
|
|
|
uart_parse_options(options, &baud, &parity, &bits, &flow);
|
|
|
|
else
|
2012-10-14 15:05:24 +08:00
|
|
|
uart_clps711x_console_get_options(port, &baud, &parity, &bits);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return uart_set_options(port, co, baud, parity, bits, flow);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-20 02:21:50 +08:00
|
|
|
static int uart_clps711x_probe(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:24 +08:00
|
|
|
struct clps711x_port *s;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret, i;
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
s = devm_kzalloc(&pdev->dev, sizeof(struct clps711x_port), GFP_KERNEL);
|
|
|
|
if (!s) {
|
|
|
|
dev_err(&pdev->dev, "Error allocating port structure\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
platform_set_drvdata(pdev, s);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:26 +08:00
|
|
|
s->uart_clk = devm_clk_get(&pdev->dev, "uart");
|
|
|
|
if (IS_ERR(s->uart_clk)) {
|
|
|
|
dev_err(&pdev->dev, "Can't get UART clocks\n");
|
2013-06-25 09:08:49 +08:00
|
|
|
return PTR_ERR(s->uart_clk);
|
2012-10-14 15:05:26 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
s->uart.owner = THIS_MODULE;
|
|
|
|
s->uart.dev_name = "ttyCL";
|
|
|
|
s->uart.major = UART_CLPS711X_MAJOR;
|
|
|
|
s->uart.minor = UART_CLPS711X_MINOR;
|
|
|
|
s->uart.nr = UART_CLPS711X_NR;
|
|
|
|
#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
|
|
|
|
s->uart.cons = &s->console;
|
|
|
|
s->uart.cons->device = uart_console_device;
|
|
|
|
s->uart.cons->write = uart_clps711x_console_write;
|
|
|
|
s->uart.cons->setup = uart_clps711x_console_setup;
|
|
|
|
s->uart.cons->flags = CON_PRINTBUFFER;
|
|
|
|
s->uart.cons->index = -1;
|
|
|
|
s->uart.cons->data = s;
|
|
|
|
strcpy(s->uart.cons->name, "ttyCL");
|
|
|
|
#endif
|
|
|
|
ret = uart_register_driver(&s->uart);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Registering UART driver failed\n");
|
2013-06-25 09:08:49 +08:00
|
|
|
return ret;
|
2012-10-14 15:05:24 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
for (i = 0; i < UART_CLPS711X_NR; i++) {
|
|
|
|
s->port[i].line = i;
|
|
|
|
s->port[i].dev = &pdev->dev;
|
|
|
|
s->port[i].irq = TX_IRQ(&s->port[i]);
|
|
|
|
s->port[i].iobase = SYSCON(&s->port[i]);
|
|
|
|
s->port[i].type = PORT_CLPS711X;
|
|
|
|
s->port[i].fifosize = 16;
|
|
|
|
s->port[i].flags = UPF_SKIP_TEST | UPF_FIXED_TYPE;
|
2012-10-14 15:05:26 +08:00
|
|
|
s->port[i].uartclk = clk_get_rate(s->uart_clk);
|
2012-10-14 15:05:24 +08:00
|
|
|
s->port[i].ops = &uart_clps711x_ops;
|
|
|
|
WARN_ON(uart_add_one_port(&s->uart, &s->port[i]));
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:18 +08:00
|
|
|
static int uart_clps711x_remove(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-14 15:05:24 +08:00
|
|
|
struct clps711x_port *s = platform_get_drvdata(pdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
for (i = 0; i < UART_CLPS711X_NR; i++)
|
|
|
|
uart_remove_one_port(&s->uart, &s->port[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
uart_unregister_driver(&s->uart);
|
2012-10-14 15:05:23 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 15:05:23 +08:00
|
|
|
static struct platform_driver clps711x_uart_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = UART_CLPS711X_NAME,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = uart_clps711x_probe,
|
2012-11-20 02:21:34 +08:00
|
|
|
.remove = uart_clps711x_remove,
|
2012-10-14 15:05:23 +08:00
|
|
|
};
|
|
|
|
module_platform_driver(clps711x_uart_driver);
|
|
|
|
|
|
|
|
static struct platform_device clps711x_uart_device = {
|
|
|
|
.name = UART_CLPS711X_NAME,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init uart_clps711x_init(void)
|
|
|
|
{
|
|
|
|
return platform_device_register(&clps711x_uart_device);
|
|
|
|
}
|
|
|
|
module_init(uart_clps711x_init);
|
|
|
|
|
|
|
|
static void __exit uart_clps711x_exit(void)
|
|
|
|
{
|
|
|
|
platform_device_unregister(&clps711x_uart_device);
|
|
|
|
}
|
|
|
|
module_exit(uart_clps711x_exit);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Deep Blue Solutions Ltd");
|
2012-10-14 15:05:23 +08:00
|
|
|
MODULE_DESCRIPTION("CLPS711X serial driver");
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_LICENSE("GPL");
|