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>
|
2012-10-14 15:05:26 +08:00
|
|
|
#include <linux/clk.h>
|
2013-12-11 23:50:50 +08:00
|
|
|
#include <linux/io.h>
|
2012-10-14 15:05:34 +08:00
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/ioport.h>
|
2013-12-11 23:50:50 +08:00
|
|
|
#include <linux/of.h>
|
2012-10-14 15:05:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2013-12-11 23:50:50 +08:00
|
|
|
#include <linux/regmap.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
#include <linux/mfd/syscon.h>
|
|
|
|
#include <linux/mfd/syscon/clps711x.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-06 11:20:15 +08:00
|
|
|
#include "serial_mctrl_gpio.h"
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
#define UART_CLPS711X_DEVNAME "ttyCL"
|
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
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
#define UARTDR_OFFSET (0x00)
|
|
|
|
#define UBRLCR_OFFSET (0x40)
|
|
|
|
|
|
|
|
#define UARTDR_FRMERR (1 << 8)
|
|
|
|
#define UARTDR_PARERR (1 << 9)
|
|
|
|
#define UARTDR_OVERR (1 << 10)
|
|
|
|
|
|
|
|
#define UBRLCR_BAUD_MASK ((1 << 12) - 1)
|
|
|
|
#define UBRLCR_BREAK (1 << 12)
|
|
|
|
#define UBRLCR_PRTEN (1 << 13)
|
|
|
|
#define UBRLCR_EVENPRT (1 << 14)
|
|
|
|
#define UBRLCR_XSTOP (1 << 15)
|
|
|
|
#define UBRLCR_FIFOEN (1 << 16)
|
|
|
|
#define UBRLCR_WRDLEN5 (0 << 17)
|
|
|
|
#define UBRLCR_WRDLEN6 (1 << 17)
|
|
|
|
#define UBRLCR_WRDLEN7 (2 << 17)
|
|
|
|
#define UBRLCR_WRDLEN8 (3 << 17)
|
|
|
|
#define UBRLCR_WRDLEN_MASK (3 << 17)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
struct clps711x_port {
|
2013-12-11 23:50:50 +08:00
|
|
|
struct uart_port port;
|
|
|
|
unsigned int tx_enabled;
|
|
|
|
int rx_irq;
|
|
|
|
struct regmap *syscon;
|
2014-09-06 11:20:15 +08:00
|
|
|
struct mctrl_gpios *gpios;
|
2013-12-11 23:50:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct uart_driver clps711x_uart = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.driver_name = UART_CLPS711X_DEVNAME,
|
|
|
|
.dev_name = UART_CLPS711X_DEVNAME,
|
|
|
|
.major = UART_CLPS711X_MAJOR,
|
|
|
|
.minor = UART_CLPS711X_MINOR,
|
|
|
|
.nr = UART_CLPS711X_NR,
|
2012-10-14 15:05:24 +08:00
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
if (s->tx_enabled) {
|
|
|
|
disable_irq(port->irq);
|
|
|
|
s->tx_enabled = 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);
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
if (!s->tx_enabled) {
|
|
|
|
s->tx_enabled = 1;
|
|
|
|
enable_irq(port->irq);
|
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;
|
2013-12-11 23:50:50 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
|
|
|
unsigned int status, flg;
|
|
|
|
u16 ch;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:30 +08:00
|
|
|
for (;;) {
|
2014-01-01 00:49:42 +08:00
|
|
|
u32 sysflg = 0;
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg);
|
|
|
|
if (sysflg & SYSFLG_URXFE)
|
2012-10-14 15:05:30 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-01-01 00:49:42 +08:00
|
|
|
ch = readw(port->membase + UARTDR_OFFSET);
|
2012-10-14 15:05:30 +08:00
|
|
|
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) {
|
2014-01-01 00:49:42 +08:00
|
|
|
writew(port->x_char, port->membase + UARTDR_OFFSET);
|
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)) {
|
2013-12-11 23:50:50 +08:00
|
|
|
if (s->tx_enabled) {
|
|
|
|
disable_irq_nosync(port->irq);
|
|
|
|
s->tx_enabled = 0;
|
|
|
|
}
|
2012-10-14 15:05:25 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:27 +08:00
|
|
|
while (!uart_circ_empty(xmit)) {
|
2014-01-01 00:49:42 +08:00
|
|
|
u32 sysflg = 0;
|
|
|
|
|
|
|
|
writew(xmit->buf[xmit->tail], port->membase + UARTDR_OFFSET);
|
2005-04-17 06:20:36 +08:00
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
port->icount.tx++;
|
2013-12-11 23:50:50 +08:00
|
|
|
|
|
|
|
regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg);
|
|
|
|
if (sysflg & 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
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
2014-01-01 00:49:42 +08:00
|
|
|
u32 sysflg = 0;
|
2013-12-11 23:50:50 +08:00
|
|
|
|
|
|
|
regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg);
|
|
|
|
|
|
|
|
return (sysflg & 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
|
|
|
{
|
2014-09-06 11:20:15 +08:00
|
|
|
unsigned int result = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
|
2013-12-11 23:50:50 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-06 11:20:15 +08:00
|
|
|
return mctrl_gpio_get(s->gpios, &result);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-09-06 11:20:15 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
|
|
|
|
|
|
|
mctrl_gpio_set(s->gpios, mctrl);
|
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 int ubrlcr;
|
|
|
|
|
2014-01-01 00:49:42 +08:00
|
|
|
ubrlcr = readl(port->membase + UBRLCR_OFFSET);
|
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;
|
2014-01-01 00:49:42 +08:00
|
|
|
writel(ubrlcr, port->membase + UBRLCR_OFFSET);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-11-06 02:11:43 +08:00
|
|
|
static void uart_clps711x_set_ldisc(struct uart_port *port,
|
|
|
|
struct ktermios *termios)
|
2014-01-01 00:49:41 +08:00
|
|
|
{
|
|
|
|
if (!port->line) {
|
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
|
|
|
|
|
|
|
regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON1_SIREN,
|
2014-11-06 02:11:43 +08:00
|
|
|
(termios->c_line == N_IRDA) ? SYSCON1_SIREN : 0);
|
2014-01-01 00:49:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:32 +08:00
|
|
|
/* Disable break */
|
2014-01-01 00:49:42 +08:00
|
|
|
writel(readl(port->membase + UBRLCR_OFFSET) & ~UBRLCR_BREAK,
|
|
|
|
port->membase + UBRLCR_OFFSET);
|
2012-10-14 15:05:32 +08:00
|
|
|
|
|
|
|
/* Enable the port */
|
2013-12-11 23:50:50 +08:00
|
|
|
return regmap_update_bits(s->syscon, SYSCON_OFFSET,
|
|
|
|
SYSCON_UARTEN, SYSCON_UARTEN);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-14 15:05:32 +08:00
|
|
|
/* Disable the port */
|
2013-12-11 23:50:50 +08:00
|
|
|
regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON_UARTEN, 0);
|
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
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
u32 ubrlcr;
|
|
|
|
unsigned int baud, quot;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2014-01-01 00:49:42 +08:00
|
|
|
writel(ubrlcr | (quot - 1), port->membase + UBRLCR_OFFSET);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
static void uart_clps711x_nop_void(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
static int uart_clps711x_nop_int(struct uart_port *port)
|
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,
|
2013-12-11 23:50:50 +08:00
|
|
|
.stop_rx = uart_clps711x_nop_void,
|
2012-10-14 15:05:34 +08:00
|
|
|
.break_ctl = uart_clps711x_break_ctl,
|
2014-01-01 00:49:41 +08:00
|
|
|
.set_ldisc = uart_clps711x_set_ldisc,
|
2012-10-14 15:05:34 +08:00
|
|
|
.startup = uart_clps711x_startup,
|
|
|
|
.shutdown = uart_clps711x_shutdown,
|
|
|
|
.set_termios = uart_clps711x_set_termios,
|
|
|
|
.type = uart_clps711x_type,
|
|
|
|
.config_port = uart_clps711x_config_port,
|
2013-12-11 23:50:50 +08:00
|
|
|
.release_port = uart_clps711x_nop_void,
|
|
|
|
.request_port = uart_clps711x_nop_int,
|
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
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
2014-03-27 17:38:19 +08:00
|
|
|
u32 sysflg = 0;
|
2013-12-11 23:50:50 +08:00
|
|
|
|
2014-03-11 19:30:01 +08:00
|
|
|
/* Wait for FIFO is not full */
|
2014-03-27 17:38:19 +08:00
|
|
|
do {
|
2013-12-11 23:50:50 +08:00
|
|
|
regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg);
|
2014-03-27 17:38:19 +08:00
|
|
|
} while (sysflg & SYSFLG_UTXFF);
|
2012-10-14 15:05:24 +08:00
|
|
|
|
2014-01-01 00:49:42 +08:00
|
|
|
writew(ch, port->membase + UARTDR_OFFSET);
|
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
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
struct uart_port *port = clps711x_uart.state[co->index].uart_port;
|
|
|
|
struct clps711x_port *s = dev_get_drvdata(port->dev);
|
2014-03-27 17:38:19 +08:00
|
|
|
u32 sysflg = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
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 */
|
2014-03-27 17:38:19 +08:00
|
|
|
do {
|
2013-12-11 23:50:50 +08:00
|
|
|
regmap_read(s->syscon, SYSFLG_OFFSET, &sysflg);
|
2014-03-27 17:38:19 +08:00
|
|
|
} while (sysflg & SYSFLG_UBUSY);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
static int uart_clps711x_console_setup(struct console *co, char *options)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
int baud = 38400, bits = 8, parity = 'n', flow = 'n';
|
|
|
|
int ret, index = co->index;
|
|
|
|
struct clps711x_port *s;
|
|
|
|
struct uart_port *port;
|
|
|
|
unsigned int quot;
|
2014-01-01 00:49:42 +08:00
|
|
|
u32 ubrlcr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
if (index < 0 || index >= UART_CLPS711X_NR)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
port = clps711x_uart.state[index].uart_port;
|
|
|
|
if (!port)
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
s = dev_get_drvdata(port->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
if (!options) {
|
2014-01-01 00:49:42 +08:00
|
|
|
u32 syscon = 0;
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
regmap_read(s->syscon, SYSCON_OFFSET, &syscon);
|
|
|
|
if (syscon & SYSCON_UARTEN) {
|
2014-01-01 00:49:42 +08:00
|
|
|
ubrlcr = readl(port->membase + UBRLCR_OFFSET);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
if (ubrlcr & UBRLCR_PRTEN) {
|
|
|
|
if (ubrlcr & UBRLCR_EVENPRT)
|
|
|
|
parity = 'e';
|
|
|
|
else
|
|
|
|
parity = 'o';
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
if ((ubrlcr & UBRLCR_WRDLEN_MASK) == UBRLCR_WRDLEN7)
|
|
|
|
bits = 7;
|
|
|
|
|
|
|
|
quot = ubrlcr & UBRLCR_BAUD_MASK;
|
|
|
|
baud = port->uartclk / (16 * (quot + 1));
|
|
|
|
}
|
|
|
|
} else
|
2005-04-17 06:20:36 +08:00
|
|
|
uart_parse_options(options, &baud, &parity, &bits, &flow);
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
ret = uart_set_options(port, co, baud, parity, bits, flow);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return regmap_update_bits(s->syscon, SYSCON_OFFSET,
|
|
|
|
SYSCON_UARTEN, SYSCON_UARTEN);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-12-11 23:50:50 +08:00
|
|
|
|
|
|
|
static struct console clps711x_console = {
|
|
|
|
.name = UART_CLPS711X_DEVNAME,
|
|
|
|
.device = uart_console_device,
|
|
|
|
.write = uart_clps711x_console_write,
|
|
|
|
.setup = uart_clps711x_console_setup,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
#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
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
int ret, index = np ? of_alias_get_id(np, "serial") : pdev->id;
|
2012-10-14 15:05:24 +08:00
|
|
|
struct clps711x_port *s;
|
2013-12-11 23:50:50 +08:00
|
|
|
struct resource *res;
|
|
|
|
struct clk *uart_clk;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
if (index < 0 || index >= UART_CLPS711X_NR)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
|
|
|
|
if (!s)
|
2012-10-14 15:05:24 +08:00
|
|
|
return -ENOMEM;
|
2013-12-11 23:50:50 +08:00
|
|
|
|
|
|
|
uart_clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
|
if (IS_ERR(uart_clk))
|
|
|
|
return PTR_ERR(uart_clk);
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
s->port.membase = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(s->port.membase))
|
|
|
|
return PTR_ERR(s->port.membase);
|
|
|
|
|
|
|
|
s->port.irq = platform_get_irq(pdev, 0);
|
|
|
|
if (IS_ERR_VALUE(s->port.irq))
|
|
|
|
return s->port.irq;
|
|
|
|
|
|
|
|
s->rx_irq = platform_get_irq(pdev, 1);
|
|
|
|
if (IS_ERR_VALUE(s->rx_irq))
|
|
|
|
return s->rx_irq;
|
|
|
|
|
|
|
|
if (!np) {
|
|
|
|
char syscon_name[9];
|
|
|
|
|
|
|
|
sprintf(syscon_name, "syscon.%i", index + 1);
|
|
|
|
s->syscon = syscon_regmap_lookup_by_pdevname(syscon_name);
|
|
|
|
if (IS_ERR(s->syscon))
|
|
|
|
return PTR_ERR(s->syscon);
|
|
|
|
} else {
|
|
|
|
s->syscon = syscon_regmap_lookup_by_phandle(np, "syscon");
|
|
|
|
if (IS_ERR(s->syscon))
|
|
|
|
return PTR_ERR(s->syscon);
|
2012-10-14 15:05:24 +08:00
|
|
|
}
|
2013-12-11 23:50:50 +08:00
|
|
|
|
|
|
|
s->port.line = index;
|
|
|
|
s->port.dev = &pdev->dev;
|
|
|
|
s->port.iotype = UPIO_MEM32;
|
|
|
|
s->port.mapbase = res->start;
|
|
|
|
s->port.type = PORT_CLPS711X;
|
|
|
|
s->port.fifosize = 16;
|
|
|
|
s->port.flags = UPF_SKIP_TEST | UPF_FIXED_TYPE;
|
|
|
|
s->port.uartclk = clk_get_rate(uart_clk);
|
|
|
|
s->port.ops = &uart_clps711x_ops;
|
|
|
|
|
2012-10-14 15:05:24 +08:00
|
|
|
platform_set_drvdata(pdev, s);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-09-30 16:19:40 +08:00
|
|
|
s->gpios = mctrl_gpio_init_noauto(&pdev->dev, 0);
|
2015-02-12 22:24:39 +08:00
|
|
|
if (IS_ERR(s->gpios))
|
|
|
|
return PTR_ERR(s->gpios);
|
2014-09-06 11:20:15 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
ret = uart_add_one_port(&clps711x_uart, &s->port);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-10-14 15:05:26 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
/* Disable port */
|
|
|
|
if (!uart_console(&s->port))
|
|
|
|
regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON_UARTEN, 0);
|
|
|
|
|
|
|
|
s->tx_enabled = 1;
|
|
|
|
|
|
|
|
ret = devm_request_irq(&pdev->dev, s->port.irq, uart_clps711x_int_tx, 0,
|
|
|
|
dev_name(&pdev->dev), &s->port);
|
2012-10-14 15:05:24 +08:00
|
|
|
if (ret) {
|
2013-12-11 23:50:50 +08:00
|
|
|
uart_remove_one_port(&clps711x_uart, &s->port);
|
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
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, s->rx_irq, uart_clps711x_int_rx, 0,
|
|
|
|
dev_name(&pdev->dev), &s->port);
|
|
|
|
if (ret)
|
|
|
|
uart_remove_one_port(&clps711x_uart, &s->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2012-10-14 15:05:23 +08:00
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
return uart_remove_one_port(&clps711x_uart, &s->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-12-11 23:50:50 +08:00
|
|
|
static const struct of_device_id __maybe_unused clps711x_uart_dt_ids[] = {
|
|
|
|
{ .compatible = "cirrus,clps711x-uart", },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, clps711x_uart_dt_ids);
|
|
|
|
|
|
|
|
static struct platform_driver clps711x_uart_platform = {
|
2012-10-14 15:05:23 +08:00
|
|
|
.driver = {
|
2013-12-11 23:50:50 +08:00
|
|
|
.name = "clps711x-uart",
|
|
|
|
.of_match_table = of_match_ptr(clps711x_uart_dt_ids),
|
2012-10-14 15:05:23 +08:00
|
|
|
},
|
|
|
|
.probe = uart_clps711x_probe,
|
2012-11-20 02:21:34 +08:00
|
|
|
.remove = uart_clps711x_remove,
|
2012-10-14 15:05:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init uart_clps711x_init(void)
|
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
|
|
|
|
clps711x_uart.cons = &clps711x_console;
|
|
|
|
clps711x_console.data = &clps711x_uart;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ret = uart_register_driver(&clps711x_uart);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return platform_driver_register(&clps711x_uart_platform);
|
2012-10-14 15:05:23 +08:00
|
|
|
}
|
|
|
|
module_init(uart_clps711x_init);
|
|
|
|
|
|
|
|
static void __exit uart_clps711x_exit(void)
|
|
|
|
{
|
2013-12-11 23:50:50 +08:00
|
|
|
platform_driver_unregister(&clps711x_uart_platform);
|
|
|
|
uart_unregister_driver(&clps711x_uart);
|
2012-10-14 15:05:23 +08:00
|
|
|
}
|
|
|
|
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");
|