2007-05-07 04:50:30 +07:00
|
|
|
/*
|
2008-01-11 14:56:26 +07:00
|
|
|
* Blackfin On-Chip Serial Driver
|
2007-05-07 04:50:30 +07:00
|
|
|
*
|
2012-05-16 13:22:23 +07:00
|
|
|
* Copyright 2006-2011 Analog Devices Inc.
|
2007-05-07 04:50:30 +07:00
|
|
|
*
|
2008-01-11 14:56:26 +07:00
|
|
|
* Enter bugs at http://blackfin.uclinux.org/
|
2007-05-07 04:50:30 +07:00
|
|
|
*
|
2008-01-11 14:56:26 +07:00
|
|
|
* Licensed under the GPL-2 or later.
|
2007-05-07 04:50:30 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(CONFIG_SERIAL_BFIN_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
|
|
|
|
#define SUPPORT_SYSRQ
|
|
|
|
#endif
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
#define DRIVER_NAME "bfin-uart"
|
|
|
|
#define pr_fmt(fmt) DRIVER_NAME ": " fmt
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ioport.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/gfp.h>
|
2010-01-19 18:13:13 +07:00
|
|
|
#include <linux/io.h>
|
2007-05-07 04:50:30 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/sysrq.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/serial_core.h>
|
2009-09-09 17:46:19 +07:00
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/irq.h>
|
2007-06-29 15:35:17 +07:00
|
|
|
#include <linux/kgdb.h>
|
2009-09-09 17:46:19 +07:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
#include <asm/portmux.h>
|
2007-05-07 04:50:30 +07:00
|
|
|
#include <asm/cacheflush.h>
|
2009-09-09 17:46:19 +07:00
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <asm/bfin_serial.h>
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-06-23 00:41:47 +07:00
|
|
|
#ifdef CONFIG_SERIAL_BFIN_MODULE
|
|
|
|
# undef CONFIG_EARLY_PRINTK
|
|
|
|
#endif
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
/* UART name and device definitions */
|
2009-09-09 17:46:19 +07:00
|
|
|
#define BFIN_SERIAL_DEV_NAME "ttyBF"
|
2007-05-07 04:50:30 +07:00
|
|
|
#define BFIN_SERIAL_MAJOR 204
|
|
|
|
#define BFIN_SERIAL_MINOR 64
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
static struct bfin_serial_port *bfin_serial_ports[BFIN_UART_NR_PORTS];
|
2008-10-13 16:33:16 +07:00
|
|
|
|
2009-01-02 20:40:14 +07:00
|
|
|
#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
|
|
|
|
defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
|
|
|
|
|
|
|
|
# ifndef CONFIG_SERIAL_BFIN_PIO
|
|
|
|
# error KGDB only support UART in PIO mode.
|
|
|
|
# endif
|
|
|
|
|
|
|
|
static int kgdboc_port_line;
|
|
|
|
static int kgdboc_break_enabled;
|
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
/*
|
|
|
|
* Setup for console. Argument comes from the menuconfig
|
|
|
|
*/
|
|
|
|
#define DMA_RX_XCOUNT 512
|
|
|
|
#define DMA_RX_YCOUNT (PAGE_SIZE / DMA_RX_XCOUNT)
|
|
|
|
|
2008-02-29 11:08:42 +07:00
|
|
|
#define DMA_RX_FLUSH_JIFFIES (HZ / 50)
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
|
|
|
static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart);
|
|
|
|
#else
|
|
|
|
static void bfin_serial_tx_chars(struct bfin_serial_port *uart);
|
|
|
|
#endif
|
|
|
|
|
2009-01-02 20:40:22 +07:00
|
|
|
static void bfin_serial_reset_irda(struct uart_port *port);
|
|
|
|
|
2015-04-12 22:54:35 +07:00
|
|
|
#if defined(SERIAL_BFIN_CTSRTS) || \
|
|
|
|
defined(SERIAL_BFIN_HARD_CTSRTS)
|
2009-04-07 22:52:26 +07:00
|
|
|
static unsigned int bfin_serial_get_mctrl(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
if (uart->cts_pin < 0)
|
|
|
|
return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
|
|
|
|
|
|
|
|
/* CTS PIN is negative assertive. */
|
|
|
|
if (UART_GET_CTS(uart))
|
|
|
|
return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
|
|
|
|
else
|
|
|
|
return TIOCM_DSR | TIOCM_CAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfin_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
if (uart->rts_pin < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* RTS PIN is negative assertive. */
|
|
|
|
if (mctrl & TIOCM_RTS)
|
|
|
|
UART_ENABLE_RTS(uart);
|
|
|
|
else
|
|
|
|
UART_DISABLE_RTS(uart);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle any change of modem status signal.
|
|
|
|
*/
|
|
|
|
static irqreturn_t bfin_serial_mctrl_cts_int(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = dev_id;
|
2014-09-11 02:06:26 +07:00
|
|
|
struct uart_port *uport = &uart->port;
|
|
|
|
unsigned int status = bfin_serial_get_mctrl(uport);
|
2015-04-12 22:54:35 +07:00
|
|
|
#ifdef SERIAL_BFIN_HARD_CTSRTS
|
2011-12-13 11:22:02 +07:00
|
|
|
|
2009-04-07 22:52:26 +07:00
|
|
|
UART_CLEAR_SCTS(uart);
|
2014-09-11 02:06:26 +07:00
|
|
|
if (uport->hw_stopped) {
|
2011-12-13 11:22:02 +07:00
|
|
|
if (status) {
|
2014-09-11 02:06:26 +07:00
|
|
|
uport->hw_stopped = 0;
|
|
|
|
uart_write_wakeup(uport);
|
2011-12-13 11:22:02 +07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!status)
|
2014-09-11 02:06:26 +07:00
|
|
|
uport->hw_stopped = 1;
|
2011-12-13 11:22:02 +07:00
|
|
|
}
|
2014-09-11 02:06:28 +07:00
|
|
|
#else
|
2014-09-11 02:06:26 +07:00
|
|
|
uart_handle_cts_change(uport, status & TIOCM_CTS);
|
2014-09-11 02:06:28 +07:00
|
|
|
#endif
|
2009-04-07 22:52:26 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static unsigned int bfin_serial_get_mctrl(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfin_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
/*
|
|
|
|
* interrupts are disabled on entry
|
|
|
|
*/
|
|
|
|
static void bfin_serial_stop_tx(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
2009-01-02 20:40:38 +07:00
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
2009-09-20 03:13:28 +07:00
|
|
|
struct circ_buf *xmit = &uart->port.state->xmit;
|
2009-01-02 20:40:38 +07:00
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2007-07-12 15:43:46 +07:00
|
|
|
while (!(UART_GET_LSR(uart) & TEMT))
|
2008-02-25 14:16:50 +07:00
|
|
|
cpu_relax();
|
2007-07-12 15:43:46 +07:00
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
|
|
|
disable_dma(uart->tx_dma_channel);
|
2008-02-25 14:16:50 +07:00
|
|
|
xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
|
|
|
|
uart->port.icount.tx += uart->tx_count;
|
|
|
|
uart->tx_count = 0;
|
|
|
|
uart->tx_done = 1;
|
2007-07-12 15:43:46 +07:00
|
|
|
#else
|
2012-05-16 13:22:23 +07:00
|
|
|
#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
|
2007-07-12 15:43:46 +07:00
|
|
|
/* Clear TFI bit */
|
|
|
|
UART_PUT_LSR(uart, TFI);
|
2007-05-07 04:50:30 +07:00
|
|
|
#endif
|
2008-05-07 10:41:26 +07:00
|
|
|
UART_CLEAR_IER(uart, ETBEI);
|
2007-07-12 15:43:46 +07:00
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* port is locked and interrupts are disabled
|
|
|
|
*/
|
|
|
|
static void bfin_serial_start_tx(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
2009-09-20 03:13:28 +07:00
|
|
|
struct tty_struct *tty = uart->port.state->port.tty;
|
2009-01-02 20:40:22 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To avoid losting RX interrupt, we reset IR function
|
|
|
|
* before sending data.
|
|
|
|
*/
|
2012-07-14 21:31:47 +07:00
|
|
|
if (tty->termios.c_line == N_IRDA)
|
2009-01-02 20:40:22 +07:00
|
|
|
bfin_serial_reset_irda(port);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
2008-02-25 14:16:50 +07:00
|
|
|
if (uart->tx_done)
|
|
|
|
bfin_serial_dma_tx_chars(uart);
|
2007-07-12 15:43:46 +07:00
|
|
|
#else
|
|
|
|
UART_SET_IER(uart, ETBEI);
|
2007-10-10 15:47:58 +07:00
|
|
|
bfin_serial_tx_chars(uart);
|
2007-07-12 15:43:46 +07:00
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupts are enabled
|
|
|
|
*/
|
|
|
|
static void bfin_serial_stop_rx(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
2009-01-02 20:40:14 +07:00
|
|
|
|
2007-07-12 15:43:46 +07:00
|
|
|
UART_CLEAR_IER(uart, ERBFI);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
2008-04-25 02:03:03 +07:00
|
|
|
#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
|
2007-12-24 18:48:04 +07:00
|
|
|
# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
|
|
|
|
# define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v))
|
|
|
|
#else
|
|
|
|
# define UART_GET_ANOMALY_THRESHOLD(uart) 0
|
|
|
|
# define UART_SET_ANOMALY_THRESHOLD(uart, v)
|
|
|
|
#endif
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
#ifdef CONFIG_SERIAL_BFIN_PIO
|
|
|
|
static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
|
|
|
|
{
|
|
|
|
unsigned int status, ch, flg;
|
2015-11-12 20:45:47 +07:00
|
|
|
static u64 anomaly_start;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2007-11-21 16:00:32 +07:00
|
|
|
status = UART_GET_LSR(uart);
|
2007-12-24 18:40:05 +07:00
|
|
|
UART_CLEAR_LSR(uart);
|
|
|
|
|
2011-07-19 17:09:24 +07:00
|
|
|
ch = UART_GET_CHAR(uart);
|
|
|
|
uart->port.icount.rx++;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-01-02 20:40:14 +07:00
|
|
|
#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
|
|
|
|
defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
|
2010-01-19 18:13:12 +07:00
|
|
|
if (kgdb_connected && kgdboc_port_line == uart->port.line
|
|
|
|
&& kgdboc_break_enabled)
|
2009-01-02 20:40:14 +07:00
|
|
|
if (ch == 0x3) {/* Ctrl + C */
|
|
|
|
kgdb_breakpoint();
|
2007-06-29 15:35:17 +07:00
|
|
|
return;
|
|
|
|
}
|
2009-01-02 20:40:14 +07:00
|
|
|
|
2013-01-03 21:53:06 +07:00
|
|
|
if (!uart->port.state)
|
2009-01-02 20:40:14 +07:00
|
|
|
return;
|
2007-06-29 15:35:17 +07:00
|
|
|
#endif
|
2008-04-25 02:03:03 +07:00
|
|
|
if (ANOMALY_05000363) {
|
2007-12-24 18:48:04 +07:00
|
|
|
/* The BF533 (and BF561) family of processors have a nice anomaly
|
|
|
|
* where they continuously generate characters for a "single" break.
|
2007-08-05 15:48:08 +07:00
|
|
|
* We have to basically ignore this flood until the "next" valid
|
2007-12-24 18:48:04 +07:00
|
|
|
* character comes across. Due to the nature of the flood, it is
|
|
|
|
* not possible to reliably catch bytes that are sent too quickly
|
|
|
|
* after this break. So application code talking to the Blackfin
|
|
|
|
* which sends a break signal must allow at least 1.5 character
|
|
|
|
* times after the end of the break for things to stabilize. This
|
|
|
|
* timeout was picked as it must absolutely be larger than 1
|
|
|
|
* character time +/- some percent. So 1.5 sounds good. All other
|
|
|
|
* Blackfin families operate properly. Woo.
|
2007-08-05 15:48:08 +07:00
|
|
|
*/
|
2015-11-12 20:45:47 +07:00
|
|
|
if (anomaly_start > 0) {
|
|
|
|
u64 curr, nsecs, threshold_ns;
|
2007-12-24 18:48:04 +07:00
|
|
|
|
|
|
|
if ((~ch & (~ch + 1)) & 0xff)
|
|
|
|
goto known_good_char;
|
|
|
|
|
2015-11-12 20:45:47 +07:00
|
|
|
curr = ktime_get_ns();
|
|
|
|
nsecs = curr - anomaly_start;
|
|
|
|
if (nsecs >> 32)
|
2007-12-24 18:48:04 +07:00
|
|
|
goto known_good_char;
|
|
|
|
|
2015-11-12 20:45:47 +07:00
|
|
|
threshold_ns = UART_GET_ANOMALY_THRESHOLD(uart)
|
|
|
|
* NSEC_PER_USEC;
|
|
|
|
if (nsecs > threshold_ns)
|
2007-12-24 18:48:04 +07:00
|
|
|
goto known_good_char;
|
|
|
|
|
|
|
|
if (ch)
|
2015-11-12 20:45:47 +07:00
|
|
|
anomaly_start = 0;
|
2007-12-24 18:48:04 +07:00
|
|
|
else
|
|
|
|
anomaly_start = curr;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
known_good_char:
|
2009-01-02 20:40:45 +07:00
|
|
|
status &= ~BI;
|
2015-11-12 20:45:47 +07:00
|
|
|
anomaly_start = 0;
|
2007-08-05 15:48:08 +07:00
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status & BI) {
|
2008-04-25 02:03:03 +07:00
|
|
|
if (ANOMALY_05000363)
|
2007-12-24 18:48:04 +07:00
|
|
|
if (bfin_revid() < 5)
|
2015-11-12 20:45:47 +07:00
|
|
|
anomaly_start = ktime_get_ns();
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->port.icount.brk++;
|
|
|
|
if (uart_handle_break(&uart->port))
|
|
|
|
goto ignore_char;
|
2007-06-11 14:31:30 +07:00
|
|
|
status &= ~(PE | FE);
|
2007-05-21 17:09:39 +07:00
|
|
|
}
|
|
|
|
if (status & PE)
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->port.icount.parity++;
|
2007-05-21 17:09:39 +07:00
|
|
|
if (status & OE)
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->port.icount.overrun++;
|
2007-05-21 17:09:39 +07:00
|
|
|
if (status & FE)
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->port.icount.frame++;
|
2007-05-21 17:09:39 +07:00
|
|
|
|
|
|
|
status &= uart->port.read_status_mask;
|
|
|
|
|
|
|
|
if (status & BI)
|
|
|
|
flg = TTY_BREAK;
|
|
|
|
else if (status & PE)
|
|
|
|
flg = TTY_PARITY;
|
|
|
|
else if (status & FE)
|
|
|
|
flg = TTY_FRAME;
|
|
|
|
else
|
2007-05-07 04:50:30 +07:00
|
|
|
flg = TTY_NORMAL;
|
|
|
|
|
|
|
|
if (uart_handle_sysrq_char(&uart->port, ch))
|
|
|
|
goto ignore_char;
|
|
|
|
|
2007-05-21 17:09:39 +07:00
|
|
|
uart_insert_char(&uart->port, status, OE, ch, flg);
|
|
|
|
|
|
|
|
ignore_char:
|
2013-01-03 21:53:06 +07:00
|
|
|
tty_flip_buffer_push(&uart->port.state->port);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
|
|
|
|
{
|
2009-09-20 03:13:28 +07:00
|
|
|
struct circ_buf *xmit = &uart->port.state->xmit;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
|
2012-05-16 13:22:23 +07:00
|
|
|
#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
|
2008-10-13 16:33:33 +07:00
|
|
|
/* Clear TFI bit */
|
|
|
|
UART_PUT_LSR(uart, TFI);
|
|
|
|
#endif
|
2009-06-11 19:45:07 +07:00
|
|
|
/* Anomaly notes:
|
|
|
|
* 05000215 - we always clear ETBEI within last UART TX
|
|
|
|
* interrupt to end a string. It is always set
|
|
|
|
* when start a new tx.
|
|
|
|
*/
|
2008-10-13 16:33:33 +07:00
|
|
|
UART_CLEAR_IER(uart, ETBEI);
|
2007-05-07 04:50:30 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-19 16:46:39 +07:00
|
|
|
if (uart->port.x_char) {
|
|
|
|
UART_PUT_CHAR(uart, uart->port.x_char);
|
|
|
|
uart->port.icount.tx++;
|
|
|
|
uart->port.x_char = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-21 16:00:32 +07:00
|
|
|
while ((UART_GET_LSR(uart) & THRE) && xmit->tail != xmit->head) {
|
|
|
|
UART_PUT_CHAR(uart, xmit->buf[xmit->tail]);
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
uart->port.icount.tx++;
|
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(&uart->port);
|
|
|
|
}
|
|
|
|
|
2007-05-21 17:09:38 +07:00
|
|
|
static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = dev_id;
|
|
|
|
|
2007-12-24 18:40:05 +07:00
|
|
|
while (UART_GET_LSR(uart) & DR)
|
2007-07-12 15:43:46 +07:00
|
|
|
bfin_serial_rx_chars(uart);
|
2007-11-21 16:00:32 +07:00
|
|
|
|
2007-05-21 17:09:38 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t bfin_serial_tx_int(int irq, void *dev_id)
|
2007-05-07 04:50:30 +07:00
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = dev_id;
|
|
|
|
|
2007-07-12 15:43:46 +07:00
|
|
|
spin_lock(&uart->port.lock);
|
2007-12-24 18:40:05 +07:00
|
|
|
if (UART_GET_LSR(uart) & THRE)
|
2007-07-12 15:43:46 +07:00
|
|
|
bfin_serial_tx_chars(uart);
|
|
|
|
spin_unlock(&uart->port.lock);
|
2007-11-21 16:00:32 +07:00
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2008-02-02 13:29:25 +07:00
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
|
|
|
static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
|
|
|
|
{
|
2009-09-20 03:13:28 +07:00
|
|
|
struct circ_buf *xmit = &uart->port.state->xmit;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
uart->tx_done = 0;
|
|
|
|
|
2007-12-21 15:45:12 +07:00
|
|
|
if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
|
2008-02-25 14:16:50 +07:00
|
|
|
uart->tx_count = 0;
|
2007-12-21 15:45:12 +07:00
|
|
|
uart->tx_done = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
if (uart->port.x_char) {
|
|
|
|
UART_PUT_CHAR(uart, uart->port.x_char);
|
|
|
|
uart->port.icount.tx++;
|
|
|
|
uart->port.x_char = 0;
|
|
|
|
}
|
2007-12-21 15:45:12 +07:00
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->tx_count = CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE);
|
|
|
|
if (uart->tx_count > (UART_XMIT_SIZE - xmit->tail))
|
|
|
|
uart->tx_count = UART_XMIT_SIZE - xmit->tail;
|
|
|
|
blackfin_dcache_flush_range((unsigned long)(xmit->buf+xmit->tail),
|
|
|
|
(unsigned long)(xmit->buf+xmit->tail+uart->tx_count));
|
|
|
|
set_dma_config(uart->tx_dma_channel,
|
|
|
|
set_bfin_dma_config(DIR_READ, DMA_FLOW_STOP,
|
|
|
|
INTR_ON_BUF,
|
|
|
|
DIMENSION_LINEAR,
|
2008-01-22 14:29:18 +07:00
|
|
|
DATA_SIZE_8,
|
|
|
|
DMA_SYNC_RESTART));
|
2007-05-07 04:50:30 +07:00
|
|
|
set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail));
|
|
|
|
set_dma_x_count(uart->tx_dma_channel, uart->tx_count);
|
|
|
|
set_dma_x_modify(uart->tx_dma_channel, 1);
|
2009-06-11 19:42:17 +07:00
|
|
|
SSYNC();
|
2007-05-07 04:50:30 +07:00
|
|
|
enable_dma(uart->tx_dma_channel);
|
2007-12-21 16:12:55 +07:00
|
|
|
|
2007-07-12 15:43:46 +07:00
|
|
|
UART_SET_IER(uart, ETBEI);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
2007-05-21 17:09:39 +07:00
|
|
|
static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
|
2007-05-07 04:50:30 +07:00
|
|
|
{
|
|
|
|
int i, flg, status;
|
|
|
|
|
|
|
|
status = UART_GET_LSR(uart);
|
2007-12-24 18:40:05 +07:00
|
|
|
UART_CLEAR_LSR(uart);
|
|
|
|
|
2008-02-25 14:19:09 +07:00
|
|
|
uart->port.icount.rx +=
|
|
|
|
CIRC_CNT(uart->rx_dma_buf.head, uart->rx_dma_buf.tail,
|
|
|
|
UART_XMIT_SIZE);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
if (status & BI) {
|
|
|
|
uart->port.icount.brk++;
|
|
|
|
if (uart_handle_break(&uart->port))
|
|
|
|
goto dma_ignore_char;
|
2007-06-11 14:31:30 +07:00
|
|
|
status &= ~(PE | FE);
|
2007-05-21 17:09:39 +07:00
|
|
|
}
|
|
|
|
if (status & PE)
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->port.icount.parity++;
|
2007-05-21 17:09:39 +07:00
|
|
|
if (status & OE)
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->port.icount.overrun++;
|
2007-05-21 17:09:39 +07:00
|
|
|
if (status & FE)
|
2007-05-07 04:50:30 +07:00
|
|
|
uart->port.icount.frame++;
|
2007-05-21 17:09:39 +07:00
|
|
|
|
|
|
|
status &= uart->port.read_status_mask;
|
|
|
|
|
|
|
|
if (status & BI)
|
|
|
|
flg = TTY_BREAK;
|
|
|
|
else if (status & PE)
|
|
|
|
flg = TTY_PARITY;
|
|
|
|
else if (status & FE)
|
|
|
|
flg = TTY_FRAME;
|
|
|
|
else
|
2007-05-07 04:50:30 +07:00
|
|
|
flg = TTY_NORMAL;
|
|
|
|
|
2009-04-06 23:32:42 +07:00
|
|
|
for (i = uart->rx_dma_buf.tail; ; i++) {
|
2008-02-25 14:19:09 +07:00
|
|
|
if (i >= UART_XMIT_SIZE)
|
|
|
|
i = 0;
|
2009-04-06 23:32:42 +07:00
|
|
|
if (i == uart->rx_dma_buf.head)
|
|
|
|
break;
|
2008-02-25 14:19:09 +07:00
|
|
|
if (!uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i]))
|
|
|
|
uart_insert_char(&uart->port, status, OE,
|
|
|
|
uart->rx_dma_buf.buf[i], flg);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
2007-05-21 17:09:39 +07:00
|
|
|
|
|
|
|
dma_ignore_char:
|
2013-01-03 21:53:06 +07:00
|
|
|
tty_flip_buffer_push(&uart->port.state->port);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
|
|
|
|
{
|
2009-04-06 23:32:28 +07:00
|
|
|
int x_pos, pos;
|
2012-11-07 12:27:56 +07:00
|
|
|
unsigned long flags;
|
2009-01-02 20:40:38 +07:00
|
|
|
|
2015-03-26 16:13:24 +07:00
|
|
|
dma_disable_irq_nosync(uart->rx_dma_channel);
|
2012-11-07 12:27:56 +07:00
|
|
|
spin_lock_irqsave(&uart->rx_lock, flags);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-06-11 19:38:16 +07:00
|
|
|
/* 2D DMA RX buffer ring is used. Because curr_y_count and
|
|
|
|
* curr_x_count can't be read as an atomic operation,
|
|
|
|
* curr_y_count should be read before curr_x_count. When
|
|
|
|
* curr_x_count is read, curr_y_count may already indicate
|
|
|
|
* next buffer line. But, the position calculated here is
|
|
|
|
* still indicate the old line. The wrong position data may
|
|
|
|
* be smaller than current buffer tail, which cause garbages
|
|
|
|
* are received if it is not prohibit.
|
|
|
|
*/
|
2008-02-25 14:19:09 +07:00
|
|
|
uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
|
|
|
|
x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
|
|
|
|
uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
|
2009-06-11 19:42:57 +07:00
|
|
|
if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0)
|
2008-02-25 14:19:09 +07:00
|
|
|
uart->rx_dma_nrows = 0;
|
|
|
|
x_pos = DMA_RX_XCOUNT - x_pos;
|
2007-05-07 04:50:30 +07:00
|
|
|
if (x_pos == DMA_RX_XCOUNT)
|
|
|
|
x_pos = 0;
|
|
|
|
|
|
|
|
pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos;
|
2009-06-11 19:38:16 +07:00
|
|
|
/* Ignore receiving data if new position is in the same line of
|
|
|
|
* current buffer tail and small.
|
|
|
|
*/
|
|
|
|
if (pos > uart->rx_dma_buf.tail ||
|
|
|
|
uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) {
|
2008-02-25 14:19:09 +07:00
|
|
|
uart->rx_dma_buf.head = pos;
|
2007-05-07 04:50:30 +07:00
|
|
|
bfin_serial_dma_rx_chars(uart);
|
2008-02-25 14:19:09 +07:00
|
|
|
uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
2008-02-29 11:08:42 +07:00
|
|
|
|
2012-11-07 12:27:56 +07:00
|
|
|
spin_unlock_irqrestore(&uart->rx_lock, flags);
|
2015-03-26 16:13:24 +07:00
|
|
|
dma_enable_irq(uart->rx_dma_channel);
|
2009-01-02 20:40:38 +07:00
|
|
|
|
2008-04-25 03:36:47 +07:00
|
|
|
mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = dev_id;
|
2009-09-20 03:13:28 +07:00
|
|
|
struct circ_buf *xmit = &uart->port.state->xmit;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
spin_lock(&uart->port.lock);
|
|
|
|
if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) {
|
|
|
|
disable_dma(uart->tx_dma_channel);
|
2008-02-25 14:16:50 +07:00
|
|
|
clear_dma_irqstat(uart->tx_dma_channel);
|
2009-06-11 19:45:07 +07:00
|
|
|
/* Anomaly notes:
|
|
|
|
* 05000215 - we always clear ETBEI within last UART TX
|
|
|
|
* interrupt to end a string. It is always set
|
|
|
|
* when start a new tx.
|
|
|
|
*/
|
2007-07-12 15:43:46 +07:00
|
|
|
UART_CLEAR_IER(uart, ETBEI);
|
2008-02-25 14:16:50 +07:00
|
|
|
uart->port.icount.tx += uart->tx_count;
|
2012-05-16 13:22:24 +07:00
|
|
|
if (!(xmit->tail == 0 && xmit->head == 0)) {
|
2012-03-13 14:51:55 +07:00
|
|
|
xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
|
2007-12-21 15:45:12 +07:00
|
|
|
|
2012-03-13 14:51:55 +07:00
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(&uart->port);
|
|
|
|
}
|
2008-02-25 14:19:09 +07:00
|
|
|
|
2007-12-21 15:45:12 +07:00
|
|
|
bfin_serial_dma_tx_chars(uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&uart->port.lock);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = dev_id;
|
2012-05-16 13:22:25 +07:00
|
|
|
unsigned int irqstat;
|
2009-06-11 19:42:57 +07:00
|
|
|
int x_pos, pos;
|
2008-02-25 14:16:50 +07:00
|
|
|
|
2011-01-11 12:16:43 +07:00
|
|
|
spin_lock(&uart->rx_lock);
|
2007-05-07 04:50:30 +07:00
|
|
|
irqstat = get_dma_curr_irqstat(uart->rx_dma_channel);
|
|
|
|
clear_dma_irqstat(uart->rx_dma_channel);
|
2009-06-11 19:38:16 +07:00
|
|
|
|
|
|
|
uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
|
2009-06-11 19:42:57 +07:00
|
|
|
x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
|
2009-06-11 19:38:16 +07:00
|
|
|
uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
|
2009-06-11 19:42:57 +07:00
|
|
|
if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0)
|
2009-06-11 19:38:16 +07:00
|
|
|
uart->rx_dma_nrows = 0;
|
|
|
|
|
|
|
|
pos = uart->rx_dma_nrows * DMA_RX_XCOUNT;
|
|
|
|
if (pos > uart->rx_dma_buf.tail ||
|
|
|
|
uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) {
|
|
|
|
uart->rx_dma_buf.head = pos;
|
|
|
|
bfin_serial_dma_rx_chars(uart);
|
|
|
|
uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
|
|
|
|
}
|
|
|
|
|
2011-01-11 12:16:43 +07:00
|
|
|
spin_unlock(&uart->rx_lock);
|
2008-02-29 11:08:42 +07:00
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TIOCSER_TEMT when transmitter is not busy.
|
|
|
|
*/
|
|
|
|
static unsigned int bfin_serial_tx_empty(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
2012-05-16 13:22:25 +07:00
|
|
|
unsigned int lsr;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
lsr = UART_GET_LSR(uart);
|
|
|
|
if (lsr & TEMT)
|
|
|
|
return TIOCSER_TEMT;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfin_serial_break_ctl(struct uart_port *port, int break_state)
|
|
|
|
{
|
2007-06-11 15:12:49 +07:00
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
2012-05-16 13:22:26 +07:00
|
|
|
u32 lcr = UART_GET_LCR(uart);
|
2007-06-11 15:12:49 +07:00
|
|
|
if (break_state)
|
|
|
|
lcr |= SB;
|
|
|
|
else
|
|
|
|
lcr &= ~SB;
|
|
|
|
UART_PUT_LCR(uart, lcr);
|
|
|
|
SSYNC();
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bfin_serial_startup(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
|
|
|
dma_addr_t dma_handle;
|
|
|
|
|
|
|
|
if (request_dma(uart->rx_dma_channel, "BFIN_UART_RX") < 0) {
|
|
|
|
printk(KERN_NOTICE "Unable to attach Blackfin UART RX DMA channel\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request_dma(uart->tx_dma_channel, "BFIN_UART_TX") < 0) {
|
|
|
|
printk(KERN_NOTICE "Unable to attach Blackfin UART TX DMA channel\n");
|
|
|
|
free_dma(uart->rx_dma_channel);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_dma_callback(uart->rx_dma_channel, bfin_serial_dma_rx_int, uart);
|
|
|
|
set_dma_callback(uart->tx_dma_channel, bfin_serial_dma_tx_int, uart);
|
|
|
|
|
|
|
|
uart->rx_dma_buf.buf = (unsigned char *)dma_alloc_coherent(NULL, PAGE_SIZE, &dma_handle, GFP_DMA);
|
|
|
|
uart->rx_dma_buf.head = 0;
|
|
|
|
uart->rx_dma_buf.tail = 0;
|
|
|
|
uart->rx_dma_nrows = 0;
|
|
|
|
|
|
|
|
set_dma_config(uart->rx_dma_channel,
|
|
|
|
set_bfin_dma_config(DIR_WRITE, DMA_FLOW_AUTO,
|
|
|
|
INTR_ON_ROW, DIMENSION_2D,
|
2008-01-22 14:29:18 +07:00
|
|
|
DATA_SIZE_8,
|
|
|
|
DMA_SYNC_RESTART));
|
2007-05-07 04:50:30 +07:00
|
|
|
set_dma_x_count(uart->rx_dma_channel, DMA_RX_XCOUNT);
|
|
|
|
set_dma_x_modify(uart->rx_dma_channel, 1);
|
|
|
|
set_dma_y_count(uart->rx_dma_channel, DMA_RX_YCOUNT);
|
|
|
|
set_dma_y_modify(uart->rx_dma_channel, 1);
|
|
|
|
set_dma_start_addr(uart->rx_dma_channel, (unsigned long)uart->rx_dma_buf.buf);
|
|
|
|
enable_dma(uart->rx_dma_channel);
|
|
|
|
|
|
|
|
uart->rx_dma_timer.data = (unsigned long)(uart);
|
|
|
|
uart->rx_dma_timer.function = (void *)bfin_serial_rx_dma_timeout;
|
|
|
|
uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
|
|
|
|
add_timer(&(uart->rx_dma_timer));
|
|
|
|
#else
|
2009-04-07 22:51:15 +07:00
|
|
|
# if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
|
2009-01-02 20:40:14 +07:00
|
|
|
defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
|
|
|
|
if (kgdboc_port_line == uart->port.line && kgdboc_break_enabled)
|
|
|
|
kgdboc_break_enabled = 0;
|
|
|
|
else {
|
|
|
|
# endif
|
2011-09-22 15:59:15 +07:00
|
|
|
if (request_irq(uart->rx_irq, bfin_serial_rx_int, 0,
|
2007-10-10 15:47:58 +07:00
|
|
|
"BFIN_UART_RX", uart)) {
|
2007-05-07 04:50:30 +07:00
|
|
|
printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request_irq
|
2011-09-22 15:59:15 +07:00
|
|
|
(uart->tx_irq, bfin_serial_tx_int, 0,
|
2007-05-07 04:50:30 +07:00
|
|
|
"BFIN_UART_TX", uart)) {
|
|
|
|
printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n");
|
2011-08-12 10:15:51 +07:00
|
|
|
free_irq(uart->rx_irq, uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
2008-10-13 16:33:51 +07:00
|
|
|
|
|
|
|
# ifdef CONFIG_BF54x
|
|
|
|
{
|
2010-10-27 15:16:47 +07:00
|
|
|
/*
|
|
|
|
* UART2 and UART3 on BF548 share interrupt PINs and DMA
|
|
|
|
* controllers with SPORT2 and SPORT3. UART rx and tx
|
|
|
|
* interrupts are generated in PIO mode only when configure
|
|
|
|
* their peripheral mapping registers properly, which means
|
|
|
|
* request corresponding DMA channels in PIO mode as well.
|
|
|
|
*/
|
2008-10-13 16:33:51 +07:00
|
|
|
unsigned uart_dma_ch_rx, uart_dma_ch_tx;
|
|
|
|
|
2011-08-12 10:15:51 +07:00
|
|
|
switch (uart->rx_irq) {
|
2008-10-13 16:33:51 +07:00
|
|
|
case IRQ_UART3_RX:
|
|
|
|
uart_dma_ch_rx = CH_UART3_RX;
|
|
|
|
uart_dma_ch_tx = CH_UART3_TX;
|
|
|
|
break;
|
|
|
|
case IRQ_UART2_RX:
|
|
|
|
uart_dma_ch_rx = CH_UART2_RX;
|
|
|
|
uart_dma_ch_tx = CH_UART2_TX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
uart_dma_ch_rx = uart_dma_ch_tx = 0;
|
|
|
|
break;
|
2013-10-09 06:14:21 +07:00
|
|
|
}
|
2008-10-13 16:33:51 +07:00
|
|
|
|
|
|
|
if (uart_dma_ch_rx &&
|
|
|
|
request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) {
|
|
|
|
printk(KERN_NOTICE"Fail to attach UART interrupt\n");
|
2011-08-12 10:15:51 +07:00
|
|
|
free_irq(uart->rx_irq, uart);
|
|
|
|
free_irq(uart->tx_irq, uart);
|
2008-10-13 16:33:51 +07:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
if (uart_dma_ch_tx &&
|
|
|
|
request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) {
|
|
|
|
printk(KERN_NOTICE "Fail to attach UART interrupt\n");
|
|
|
|
free_dma(uart_dma_ch_rx);
|
2011-08-12 10:15:51 +07:00
|
|
|
free_irq(uart->rx_irq, uart);
|
|
|
|
free_irq(uart->tx_irq, uart);
|
2008-10-13 16:33:51 +07:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
2009-04-07 22:51:15 +07:00
|
|
|
# if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
|
2009-01-02 20:40:14 +07:00
|
|
|
defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
|
|
|
|
}
|
|
|
|
# endif
|
2009-04-07 22:51:15 +07:00
|
|
|
#endif
|
|
|
|
|
2015-04-12 22:54:35 +07:00
|
|
|
#ifdef SERIAL_BFIN_CTSRTS
|
2009-04-07 22:51:15 +07:00
|
|
|
if (uart->cts_pin >= 0) {
|
|
|
|
if (request_irq(gpio_to_irq(uart->cts_pin),
|
|
|
|
bfin_serial_mctrl_cts_int,
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
|
2011-09-22 15:59:15 +07:00
|
|
|
0, "BFIN_UART_CTS", uart)) {
|
2009-04-07 22:51:15 +07:00
|
|
|
uart->cts_pin = -1;
|
2010-11-08 04:10:23 +07:00
|
|
|
pr_info("Unable to attach BlackFin UART CTS interrupt. So, disable it.\n");
|
2009-04-07 22:51:15 +07:00
|
|
|
}
|
|
|
|
}
|
2011-12-05 14:12:50 +07:00
|
|
|
if (uart->rts_pin >= 0) {
|
|
|
|
if (gpio_request(uart->rts_pin, DRIVER_NAME)) {
|
|
|
|
pr_info("fail to request RTS PIN at GPIO_%d\n", uart->rts_pin);
|
|
|
|
uart->rts_pin = -1;
|
|
|
|
} else
|
|
|
|
gpio_direction_output(uart->rts_pin, 0);
|
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
#endif
|
2015-04-12 22:54:35 +07:00
|
|
|
#ifdef SERIAL_BFIN_HARD_CTSRTS
|
2011-12-13 11:22:01 +07:00
|
|
|
if (uart->cts_pin >= 0) {
|
|
|
|
if (request_irq(uart->status_irq, bfin_serial_mctrl_cts_int,
|
2013-10-06 13:27:18 +07:00
|
|
|
0, "BFIN_UART_MODEM_STATUS", uart)) {
|
2011-12-13 11:22:01 +07:00
|
|
|
uart->cts_pin = -1;
|
|
|
|
dev_info(port->dev, "Unable to attach BlackFin UART Modem Status interrupt.\n");
|
|
|
|
}
|
2009-04-07 22:52:26 +07:00
|
|
|
|
2011-12-13 11:22:01 +07:00
|
|
|
/* CTS RTS PINs are negative assertive. */
|
2012-05-16 13:22:25 +07:00
|
|
|
UART_PUT_MCR(uart, UART_GET_MCR(uart) | ACTS);
|
2011-12-13 11:22:01 +07:00
|
|
|
UART_SET_IER(uart, EDSSI);
|
|
|
|
}
|
2009-04-07 22:52:26 +07:00
|
|
|
#endif
|
|
|
|
|
2007-07-12 15:43:46 +07:00
|
|
|
UART_SET_IER(uart, ERBFI);
|
2007-05-07 04:50:30 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfin_serial_shutdown(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
|
|
|
disable_dma(uart->tx_dma_channel);
|
|
|
|
free_dma(uart->tx_dma_channel);
|
|
|
|
disable_dma(uart->rx_dma_channel);
|
|
|
|
free_dma(uart->rx_dma_channel);
|
|
|
|
del_timer(&(uart->rx_dma_timer));
|
2007-12-21 16:03:39 +07:00
|
|
|
dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0);
|
2007-05-07 04:50:30 +07:00
|
|
|
#else
|
2008-10-13 16:33:51 +07:00
|
|
|
#ifdef CONFIG_BF54x
|
|
|
|
switch (uart->port.irq) {
|
|
|
|
case IRQ_UART3_RX:
|
|
|
|
free_dma(CH_UART3_RX);
|
|
|
|
free_dma(CH_UART3_TX);
|
|
|
|
break;
|
|
|
|
case IRQ_UART2_RX:
|
|
|
|
free_dma(CH_UART2_RX);
|
|
|
|
free_dma(CH_UART2_TX);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-10-09 06:14:21 +07:00
|
|
|
}
|
2007-06-29 15:35:17 +07:00
|
|
|
#endif
|
2011-08-12 10:15:51 +07:00
|
|
|
free_irq(uart->rx_irq, uart);
|
|
|
|
free_irq(uart->tx_irq, uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
#endif
|
2009-04-07 22:51:15 +07:00
|
|
|
|
2015-04-12 22:54:35 +07:00
|
|
|
#ifdef SERIAL_BFIN_CTSRTS
|
2009-04-07 22:51:15 +07:00
|
|
|
if (uart->cts_pin >= 0)
|
|
|
|
free_irq(gpio_to_irq(uart->cts_pin), uart);
|
2011-12-05 14:12:50 +07:00
|
|
|
if (uart->rts_pin >= 0)
|
|
|
|
gpio_free(uart->rts_pin);
|
2009-04-07 22:52:26 +07:00
|
|
|
#endif
|
2015-04-12 22:54:35 +07:00
|
|
|
#ifdef SERIAL_BFIN_HARD_CTSRTS
|
2009-09-09 17:46:19 +07:00
|
|
|
if (uart->cts_pin >= 0)
|
2009-04-07 22:52:26 +07:00
|
|
|
free_irq(uart->status_irq, uart);
|
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int baud, quot;
|
2012-05-16 13:22:25 +07:00
|
|
|
unsigned int ier, lcr = 0;
|
2012-11-19 13:40:56 +07:00
|
|
|
unsigned long timeout;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2015-04-12 22:54:35 +07:00
|
|
|
#ifdef SERIAL_BFIN_CTSRTS
|
2014-06-16 20:17:10 +07:00
|
|
|
if (old == NULL && uart->cts_pin != -1)
|
|
|
|
termios->c_cflag |= CRTSCTS;
|
|
|
|
else if (uart->cts_pin == -1)
|
|
|
|
termios->c_cflag &= ~CRTSCTS;
|
|
|
|
#endif
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
switch (termios->c_cflag & CSIZE) {
|
|
|
|
case CS8:
|
|
|
|
lcr = WLS(8);
|
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
lcr = WLS(7);
|
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
lcr = WLS(6);
|
|
|
|
break;
|
|
|
|
case CS5:
|
|
|
|
lcr = WLS(5);
|
|
|
|
break;
|
|
|
|
default:
|
2012-10-24 21:29:41 +07:00
|
|
|
printk(KERN_ERR "%s: word length not supported\n",
|
2008-04-30 14:55:10 +07:00
|
|
|
__func__);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
2009-06-11 19:50:20 +07:00
|
|
|
/* Anomaly notes:
|
|
|
|
* 05000231 - STOP bit is always set to 1 whatever the user is set.
|
|
|
|
*/
|
|
|
|
if (termios->c_cflag & CSTOPB) {
|
|
|
|
if (ANOMALY_05000231)
|
|
|
|
printk(KERN_WARNING "STOP bits other than 1 is not "
|
|
|
|
"supported in case of anomaly 05000231.\n");
|
|
|
|
else
|
|
|
|
lcr |= STB;
|
|
|
|
}
|
2007-06-11 15:16:45 +07:00
|
|
|
if (termios->c_cflag & PARENB)
|
2007-05-07 04:50:30 +07:00
|
|
|
lcr |= PEN;
|
2007-06-11 15:16:45 +07:00
|
|
|
if (!(termios->c_cflag & PARODD))
|
|
|
|
lcr |= EPS;
|
|
|
|
if (termios->c_cflag & CMSPAR)
|
|
|
|
lcr |= STP;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2010-10-27 15:16:50 +07:00
|
|
|
spin_lock_irqsave(&uart->port.lock, flags);
|
|
|
|
|
2007-05-21 17:09:39 +07:00
|
|
|
port->read_status_mask = OE;
|
|
|
|
if (termios->c_iflag & INPCK)
|
|
|
|
port->read_status_mask |= (FE | PE);
|
2014-06-16 19:10:41 +07:00
|
|
|
if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
|
2007-05-21 17:09:39 +07:00
|
|
|
port->read_status_mask |= BI;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2007-05-21 17:09:39 +07:00
|
|
|
/*
|
|
|
|
* Characters to ignore
|
|
|
|
*/
|
|
|
|
port->ignore_status_mask = 0;
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
|
|
|
port->ignore_status_mask |= FE | PE;
|
|
|
|
if (termios->c_iflag & IGNBRK) {
|
|
|
|
port->ignore_status_mask |= BI;
|
|
|
|
/*
|
|
|
|
* If we're ignoring parity and break indicators,
|
|
|
|
* ignore overruns too (for real raw support).
|
|
|
|
*/
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
|
|
|
port->ignore_status_mask |= OE;
|
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
|
2010-05-23 15:40:13 +07:00
|
|
|
quot = uart_get_divisor(port, baud);
|
|
|
|
|
|
|
|
/* If discipline is not IRDA, apply ANOMALY_05000230 */
|
|
|
|
if (termios->c_line != N_IRDA)
|
|
|
|
quot -= ANOMALY_05000230;
|
|
|
|
|
2007-12-24 18:48:04 +07:00
|
|
|
UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15);
|
|
|
|
|
2012-11-19 13:40:56 +07:00
|
|
|
/* Wait till the transfer buffer is empty */
|
|
|
|
timeout = jiffies + msecs_to_jiffies(10);
|
|
|
|
while (UART_GET_GCTL(uart) & UCEN && !(UART_GET_LSR(uart) & TEMT))
|
|
|
|
if (time_after(jiffies, timeout)) {
|
|
|
|
dev_warn(port->dev, "timeout waiting for TX buffer empty\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
/* Disable UART */
|
|
|
|
ier = UART_GET_IER(uart);
|
2012-05-16 13:22:25 +07:00
|
|
|
UART_PUT_GCTL(uart, UART_GET_GCTL(uart) & ~UCEN);
|
2008-06-03 11:19:45 +07:00
|
|
|
UART_DISABLE_INTS(uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2012-05-16 13:22:23 +07:00
|
|
|
/* Set DLAB in LCR to Access CLK */
|
2008-05-07 10:41:26 +07:00
|
|
|
UART_SET_DLAB(uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2012-05-16 13:22:23 +07:00
|
|
|
UART_PUT_CLK(uart, quot);
|
2007-05-07 04:50:30 +07:00
|
|
|
SSYNC();
|
|
|
|
|
|
|
|
/* Clear DLAB in LCR to Access THR RBR IER */
|
2008-05-07 10:41:26 +07:00
|
|
|
UART_CLEAR_DLAB(uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2012-05-16 13:22:25 +07:00
|
|
|
UART_PUT_LCR(uart, (UART_GET_LCR(uart) & ~LCR_MASK) | lcr);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
/* Enable UART */
|
2008-06-03 11:19:45 +07:00
|
|
|
UART_ENABLE_INTS(uart, ier);
|
2012-05-16 13:22:25 +07:00
|
|
|
UART_PUT_GCTL(uart, UART_GET_GCTL(uart) | UCEN);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2008-10-13 16:33:42 +07:00
|
|
|
/* Port speed changed, update the per-port timeout. */
|
|
|
|
uart_update_timeout(port, termios->c_cflag, baud);
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
spin_unlock_irqrestore(&uart->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *bfin_serial_type(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
|
|
|
|
return uart->port.type == PORT_BFIN ? "BFIN-UART" : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the memory region(s) being used by 'port'.
|
|
|
|
*/
|
|
|
|
static void bfin_serial_release_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request the memory region(s) being used by 'port'.
|
|
|
|
*/
|
|
|
|
static int bfin_serial_request_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure/autoconfigure the port.
|
|
|
|
*/
|
|
|
|
static void bfin_serial_config_port(struct uart_port *port, int flags)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
|
|
|
|
if (flags & UART_CONFIG_TYPE &&
|
|
|
|
bfin_serial_request_port(&uart->port) == 0)
|
|
|
|
uart->port.type = PORT_BFIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify the new serial_struct (for TIOCSSERIAL).
|
|
|
|
* The only change we allow are to the flags and type, and
|
|
|
|
* even then only between PORT_BFIN and PORT_UNKNOWN
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-29 10:31:08 +07:00
|
|
|
/*
|
|
|
|
* Enable the IrDA function if tty->ldisc.num is N_IRDA.
|
|
|
|
* In other cases, disable IrDA function.
|
|
|
|
*/
|
2014-11-06 01:11:43 +07:00
|
|
|
static void bfin_serial_set_ldisc(struct uart_port *port,
|
|
|
|
struct ktermios *termios)
|
2008-02-29 10:31:08 +07:00
|
|
|
{
|
2009-09-09 17:46:19 +07:00
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
2012-05-16 13:22:25 +07:00
|
|
|
unsigned int val;
|
2008-02-29 10:31:08 +07:00
|
|
|
|
2014-11-06 01:11:43 +07:00
|
|
|
switch (termios->c_line) {
|
2008-02-29 10:31:08 +07:00
|
|
|
case N_IRDA:
|
2009-09-09 17:46:19 +07:00
|
|
|
val = UART_GET_GCTL(uart);
|
2012-05-16 13:22:23 +07:00
|
|
|
val |= (UMOD_IRDA | RPOLC);
|
2009-09-09 17:46:19 +07:00
|
|
|
UART_PUT_GCTL(uart, val);
|
2008-02-29 10:31:08 +07:00
|
|
|
break;
|
|
|
|
default:
|
2009-09-09 17:46:19 +07:00
|
|
|
val = UART_GET_GCTL(uart);
|
2012-05-16 13:22:23 +07:00
|
|
|
val &= ~(UMOD_MASK | RPOLC);
|
2009-09-09 17:46:19 +07:00
|
|
|
UART_PUT_GCTL(uart, val);
|
2008-02-29 10:31:08 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 22:51:15 +07:00
|
|
|
static void bfin_serial_reset_irda(struct uart_port *port)
|
|
|
|
{
|
2009-09-09 17:46:19 +07:00
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
2012-05-16 13:22:25 +07:00
|
|
|
unsigned int val;
|
2009-04-07 22:51:15 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
val = UART_GET_GCTL(uart);
|
2012-05-16 13:22:23 +07:00
|
|
|
val &= ~(UMOD_MASK | RPOLC);
|
2009-09-09 17:46:19 +07:00
|
|
|
UART_PUT_GCTL(uart, val);
|
2009-04-07 22:51:15 +07:00
|
|
|
SSYNC();
|
2012-05-16 13:22:23 +07:00
|
|
|
val |= (UMOD_IRDA | RPOLC);
|
2009-09-09 17:46:19 +07:00
|
|
|
UART_PUT_GCTL(uart, val);
|
2009-04-07 22:51:15 +07:00
|
|
|
SSYNC();
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:40:14 +07:00
|
|
|
#ifdef CONFIG_CONSOLE_POLL
|
2009-06-11 19:45:07 +07:00
|
|
|
/* Anomaly notes:
|
|
|
|
* 05000099 - Because we only use THRE in poll_put and DR in poll_get,
|
|
|
|
* losing other bits of UART_LSR is not a problem here.
|
|
|
|
*/
|
2009-01-02 20:40:14 +07:00
|
|
|
static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
|
|
|
|
while (!(UART_GET_LSR(uart) & THRE))
|
|
|
|
cpu_relax();
|
|
|
|
|
|
|
|
UART_CLEAR_DLAB(uart);
|
|
|
|
UART_PUT_CHAR(uart, (unsigned char)chr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfin_serial_poll_get_char(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
unsigned char chr;
|
|
|
|
|
|
|
|
while (!(UART_GET_LSR(uart) & DR))
|
|
|
|
cpu_relax();
|
|
|
|
|
|
|
|
UART_CLEAR_DLAB(uart);
|
|
|
|
chr = UART_GET_CHAR(uart);
|
|
|
|
|
|
|
|
return chr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
static struct uart_ops bfin_serial_pops = {
|
|
|
|
.tx_empty = bfin_serial_tx_empty,
|
|
|
|
.set_mctrl = bfin_serial_set_mctrl,
|
|
|
|
.get_mctrl = bfin_serial_get_mctrl,
|
|
|
|
.stop_tx = bfin_serial_stop_tx,
|
|
|
|
.start_tx = bfin_serial_start_tx,
|
|
|
|
.stop_rx = bfin_serial_stop_rx,
|
|
|
|
.break_ctl = bfin_serial_break_ctl,
|
|
|
|
.startup = bfin_serial_startup,
|
|
|
|
.shutdown = bfin_serial_shutdown,
|
|
|
|
.set_termios = bfin_serial_set_termios,
|
2008-06-07 14:36:33 +07:00
|
|
|
.set_ldisc = bfin_serial_set_ldisc,
|
2007-05-07 04:50:30 +07:00
|
|
|
.type = bfin_serial_type,
|
|
|
|
.release_port = bfin_serial_release_port,
|
|
|
|
.request_port = bfin_serial_request_port,
|
|
|
|
.config_port = bfin_serial_config_port,
|
|
|
|
.verify_port = bfin_serial_verify_port,
|
2009-01-02 20:40:14 +07:00
|
|
|
#ifdef CONFIG_CONSOLE_POLL
|
|
|
|
.poll_put_char = bfin_serial_poll_put_char,
|
|
|
|
.poll_get_char = bfin_serial_poll_get_char,
|
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
};
|
|
|
|
|
2009-01-02 20:40:31 +07:00
|
|
|
#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
|
2007-05-07 04:50:30 +07:00
|
|
|
/*
|
|
|
|
* If the port was already initialised (eg, by a boot loader),
|
|
|
|
* try to determine the current setup.
|
|
|
|
*/
|
|
|
|
static void __init
|
|
|
|
bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
|
|
|
|
int *parity, int *bits)
|
|
|
|
{
|
2012-05-16 13:22:25 +07:00
|
|
|
unsigned int status;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
status = UART_GET_IER(uart) & (ERBFI | ETBEI);
|
|
|
|
if (status == (ERBFI | ETBEI)) {
|
|
|
|
/* ok, the port was enabled */
|
2012-05-16 13:22:26 +07:00
|
|
|
u32 lcr, clk;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
lcr = UART_GET_LCR(uart);
|
|
|
|
|
|
|
|
*parity = 'n';
|
|
|
|
if (lcr & PEN) {
|
|
|
|
if (lcr & EPS)
|
|
|
|
*parity = 'e';
|
|
|
|
else
|
|
|
|
*parity = 'o';
|
|
|
|
}
|
2012-05-16 13:22:26 +07:00
|
|
|
*bits = ((lcr & WLS_MASK) >> WLS_OFFSET) + 5;
|
|
|
|
|
2012-05-16 13:22:23 +07:00
|
|
|
/* Set DLAB in LCR to Access CLK */
|
2008-05-07 10:41:26 +07:00
|
|
|
UART_SET_DLAB(uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2012-05-16 13:22:23 +07:00
|
|
|
clk = UART_GET_CLK(uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
/* Clear DLAB in LCR to Access THR RBR IER */
|
2008-05-07 10:41:26 +07:00
|
|
|
UART_CLEAR_DLAB(uart);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2012-05-16 13:22:23 +07:00
|
|
|
*baud = get_sclk() / (16*clk);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
2008-04-30 14:55:10 +07:00
|
|
|
pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
2007-10-09 16:24:49 +07:00
|
|
|
|
|
|
|
static struct uart_driver bfin_serial_reg;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
static void bfin_serial_console_putchar(struct uart_port *port, int ch)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
|
|
|
|
while (!(UART_GET_LSR(uart) & THRE))
|
|
|
|
barrier();
|
|
|
|
UART_PUT_CHAR(uart, ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
|
|
|
|
defined (CONFIG_EARLY_PRINTK) */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_CONSOLE
|
|
|
|
#define CLASS_BFIN_CONSOLE "bfin-console"
|
|
|
|
/*
|
|
|
|
* Interrupts are disabled on entering
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
bfin_serial_console_write(struct console *co, const char *s, unsigned int count)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = bfin_serial_ports[co->index];
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&uart->port.lock, flags);
|
|
|
|
uart_console_write(&uart->port, s, count, bfin_serial_console_putchar);
|
|
|
|
spin_unlock_irqrestore(&uart->port.lock, flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
static int __init
|
|
|
|
bfin_serial_console_setup(struct console *co, char *options)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart;
|
|
|
|
int baud = 57600;
|
|
|
|
int bits = 8;
|
|
|
|
int parity = 'n';
|
2015-04-12 22:54:35 +07:00
|
|
|
# if defined(SERIAL_BFIN_CTSRTS) || \
|
|
|
|
defined(SERIAL_BFIN_HARD_CTSRTS)
|
2007-05-07 04:50:30 +07:00
|
|
|
int flow = 'r';
|
2009-01-02 20:40:31 +07:00
|
|
|
# else
|
2007-05-07 04:50:30 +07:00
|
|
|
int flow = 'n';
|
2007-10-09 16:24:49 +07:00
|
|
|
# endif
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether an invalid uart number has been specified, and
|
|
|
|
* if so, search for the first available port that does have
|
|
|
|
* console support.
|
|
|
|
*/
|
2009-09-09 17:46:19 +07:00
|
|
|
if (co->index < 0 || co->index >= BFIN_UART_NR_PORTS)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
uart = bfin_serial_ports[co->index];
|
|
|
|
if (!uart)
|
|
|
|
return -ENODEV;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
if (options)
|
|
|
|
uart_parse_options(options, &baud, &parity, &bits, &flow);
|
|
|
|
else
|
|
|
|
bfin_serial_console_get_options(uart, &baud, &parity, &bits);
|
|
|
|
|
|
|
|
return uart_set_options(&uart->port, co, baud, parity, bits, flow);
|
2007-10-09 16:24:49 +07:00
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
static struct console bfin_serial_console = {
|
2009-09-09 17:46:19 +07:00
|
|
|
.name = BFIN_SERIAL_DEV_NAME,
|
2007-05-07 04:50:30 +07:00
|
|
|
.write = bfin_serial_console_write,
|
|
|
|
.device = uart_console_device,
|
|
|
|
.setup = bfin_serial_console_setup,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
.data = &bfin_serial_reg,
|
|
|
|
};
|
2011-07-19 17:09:24 +07:00
|
|
|
#define BFIN_SERIAL_CONSOLE (&bfin_serial_console)
|
2007-05-07 04:50:30 +07:00
|
|
|
#else
|
|
|
|
#define BFIN_SERIAL_CONSOLE NULL
|
2007-10-09 16:24:49 +07:00
|
|
|
#endif /* CONFIG_SERIAL_BFIN_CONSOLE */
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
#ifdef CONFIG_EARLY_PRINTK
|
|
|
|
static struct bfin_serial_port bfin_earlyprintk_port;
|
|
|
|
#define CLASS_BFIN_EARLYPRINTK "bfin-earlyprintk"
|
2007-10-09 16:24:49 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
/*
|
|
|
|
* Interrupts are disabled on entering
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
bfin_earlyprintk_console_write(struct console *co, const char *s, unsigned int count)
|
2007-10-09 16:24:49 +07:00
|
|
|
{
|
2009-09-09 17:46:19 +07:00
|
|
|
unsigned long flags;
|
2007-10-09 16:24:49 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
if (bfin_earlyprintk_port.port.line != co->index)
|
|
|
|
return;
|
2007-10-09 16:24:49 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
spin_lock_irqsave(&bfin_earlyprintk_port.port.lock, flags);
|
|
|
|
uart_console_write(&bfin_earlyprintk_port.port, s, count,
|
|
|
|
bfin_serial_console_putchar);
|
|
|
|
spin_unlock_irqrestore(&bfin_earlyprintk_port.port.lock, flags);
|
2007-10-09 16:24:49 +07:00
|
|
|
}
|
|
|
|
|
2009-06-11 19:38:57 +07:00
|
|
|
/*
|
|
|
|
* This should have a .setup or .early_setup in it, but then things get called
|
|
|
|
* without the command line options, and the baud rate gets messed up - so
|
|
|
|
* don't let the common infrastructure play with things. (see calls to setup
|
|
|
|
* & earlysetup in ./kernel/printk.c:register_console()
|
|
|
|
*/
|
2013-08-08 18:40:51 +07:00
|
|
|
static struct console bfin_early_serial_console __initdata = {
|
2007-10-09 16:24:49 +07:00
|
|
|
.name = "early_BFuart",
|
2009-09-09 17:46:19 +07:00
|
|
|
.write = bfin_earlyprintk_console_write,
|
2007-10-09 16:24:49 +07:00
|
|
|
.device = uart_console_device,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
.data = &bfin_serial_reg,
|
|
|
|
};
|
2010-10-27 15:16:49 +07:00
|
|
|
#endif
|
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
static struct uart_driver bfin_serial_reg = {
|
|
|
|
.owner = THIS_MODULE,
|
2009-09-09 17:46:19 +07:00
|
|
|
.driver_name = DRIVER_NAME,
|
|
|
|
.dev_name = BFIN_SERIAL_DEV_NAME,
|
2007-05-07 04:50:30 +07:00
|
|
|
.major = BFIN_SERIAL_MAJOR,
|
|
|
|
.minor = BFIN_SERIAL_MINOR,
|
2008-04-25 01:55:49 +07:00
|
|
|
.nr = BFIN_UART_NR_PORTS,
|
2007-05-07 04:50:30 +07:00
|
|
|
.cons = BFIN_SERIAL_CONSOLE,
|
|
|
|
};
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
static int bfin_serial_suspend(struct platform_device *pdev, pm_message_t state)
|
2007-05-07 04:50:30 +07:00
|
|
|
{
|
2009-09-09 17:46:19 +07:00
|
|
|
struct bfin_serial_port *uart = platform_get_drvdata(pdev);
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
return uart_suspend_port(&bfin_serial_reg, &uart->port);
|
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
static int bfin_serial_resume(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct bfin_serial_port *uart = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
return uart_resume_port(&bfin_serial_reg, &uart->port);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
static int bfin_serial_probe(struct platform_device *pdev)
|
2007-05-07 04:50:30 +07:00
|
|
|
{
|
2009-09-09 17:46:19 +07:00
|
|
|
struct resource *res;
|
|
|
|
struct bfin_serial_port *uart = NULL;
|
|
|
|
int ret = 0;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
if (pdev->id < 0 || pdev->id >= BFIN_UART_NR_PORTS) {
|
|
|
|
dev_err(&pdev->dev, "Wrong bfin uart platform device id.\n");
|
|
|
|
return -ENOENT;
|
2008-10-13 16:32:44 +07:00
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
if (bfin_serial_ports[pdev->id] == NULL) {
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
uart = kzalloc(sizeof(*uart), GFP_KERNEL);
|
|
|
|
if (!uart) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"fail to malloc bfin_serial_port\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
bfin_serial_ports[pdev->id] = uart;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
#ifdef CONFIG_EARLY_PRINTK
|
|
|
|
if (!(bfin_earlyprintk_port.port.membase
|
|
|
|
&& bfin_earlyprintk_port.port.line == pdev->id)) {
|
|
|
|
/*
|
|
|
|
* If the peripheral PINs of current port is allocated
|
|
|
|
* in earlyprintk probe stage, don't do it again.
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
ret = peripheral_request_list(
|
2013-09-09 12:08:43 +07:00
|
|
|
dev_get_platdata(&pdev->dev),
|
2013-07-30 15:06:57 +07:00
|
|
|
DRIVER_NAME);
|
2009-09-09 17:46:19 +07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"fail to request bfin serial peripherals\n");
|
|
|
|
goto out_error_free_mem;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_EARLY_PRINTK
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
spin_lock_init(&uart->port.lock);
|
|
|
|
uart->port.uartclk = get_sclk();
|
|
|
|
uart->port.fifosize = BFIN_UART_TX_FIFO_SIZE;
|
|
|
|
uart->port.ops = &bfin_serial_pops;
|
|
|
|
uart->port.line = pdev->id;
|
|
|
|
uart->port.iotype = UPIO_MEM;
|
|
|
|
uart->port.flags = UPF_BOOT_AUTOCONF;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_error_free_peripherals;
|
|
|
|
}
|
|
|
|
|
2011-06-09 23:13:32 +07:00
|
|
|
uart->port.membase = ioremap(res->start, resource_size(res));
|
2009-09-09 17:46:19 +07:00
|
|
|
if (!uart->port.membase) {
|
|
|
|
dev_err(&pdev->dev, "Cannot map uart IO\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto out_error_free_peripherals;
|
|
|
|
}
|
|
|
|
uart->port.mapbase = res->start;
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2011-08-12 10:15:51 +07:00
|
|
|
uart->tx_irq = platform_get_irq(pdev, 0);
|
|
|
|
if (uart->tx_irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "No uart TX IRQ specified\n");
|
2009-09-09 17:46:19 +07:00
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_error_unmap;
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
2009-09-09 17:46:19 +07:00
|
|
|
|
2011-08-12 10:15:51 +07:00
|
|
|
uart->rx_irq = platform_get_irq(pdev, 1);
|
|
|
|
if (uart->rx_irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "No uart RX IRQ specified\n");
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_error_unmap;
|
|
|
|
}
|
|
|
|
uart->port.irq = uart->rx_irq;
|
|
|
|
|
|
|
|
uart->status_irq = platform_get_irq(pdev, 2);
|
2009-09-09 17:46:19 +07:00
|
|
|
if (uart->status_irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "No uart status IRQ specified\n");
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_error_unmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_DMA
|
2011-01-11 12:16:43 +07:00
|
|
|
spin_lock_init(&uart->rx_lock);
|
2009-09-09 17:46:19 +07:00
|
|
|
uart->tx_done = 1;
|
|
|
|
uart->tx_count = 0;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
|
|
|
|
if (res == NULL) {
|
|
|
|
dev_err(&pdev->dev, "No uart TX DMA channel specified\n");
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_error_unmap;
|
|
|
|
}
|
|
|
|
uart->tx_dma_channel = res->start;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
|
|
|
|
if (res == NULL) {
|
|
|
|
dev_err(&pdev->dev, "No uart RX DMA channel specified\n");
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_error_unmap;
|
|
|
|
}
|
|
|
|
uart->rx_dma_channel = res->start;
|
|
|
|
|
|
|
|
init_timer(&(uart->rx_dma_timer));
|
|
|
|
#endif
|
|
|
|
|
2015-04-12 22:54:35 +07:00
|
|
|
#if defined(SERIAL_BFIN_CTSRTS) || \
|
|
|
|
defined(SERIAL_BFIN_HARD_CTSRTS)
|
2009-09-09 17:46:19 +07:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
|
|
|
if (res == NULL)
|
|
|
|
uart->cts_pin = -1;
|
2014-06-16 20:17:10 +07:00
|
|
|
else
|
2009-09-09 17:46:19 +07:00
|
|
|
uart->cts_pin = res->start;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IO, 1);
|
|
|
|
if (res == NULL)
|
|
|
|
uart->rts_pin = -1;
|
|
|
|
else
|
|
|
|
uart->rts_pin = res->start;
|
|
|
|
#endif
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
#ifdef CONFIG_SERIAL_BFIN_CONSOLE
|
|
|
|
if (!is_early_platform_device(pdev)) {
|
|
|
|
#endif
|
|
|
|
uart = bfin_serial_ports[pdev->id];
|
|
|
|
uart->port.dev = &pdev->dev;
|
|
|
|
dev_set_drvdata(&pdev->dev, uart);
|
|
|
|
ret = uart_add_one_port(&bfin_serial_reg, &uart->port);
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_CONSOLE
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (uart) {
|
|
|
|
out_error_unmap:
|
|
|
|
iounmap(uart->port.membase);
|
|
|
|
out_error_free_peripherals:
|
2013-09-09 12:08:43 +07:00
|
|
|
peripheral_free_list(dev_get_platdata(&pdev->dev));
|
2009-09-09 17:46:19 +07:00
|
|
|
out_error_free_mem:
|
|
|
|
kfree(uart);
|
|
|
|
bfin_serial_ports[pdev->id] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
|
|
|
|
2012-11-20 01:26:18 +07:00
|
|
|
static int bfin_serial_remove(struct platform_device *pdev)
|
2007-05-07 04:50:30 +07:00
|
|
|
{
|
2009-09-09 17:46:19 +07:00
|
|
|
struct bfin_serial_port *uart = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
dev_set_drvdata(&pdev->dev, NULL);
|
|
|
|
|
|
|
|
if (uart) {
|
|
|
|
uart_remove_one_port(&bfin_serial_reg, &uart->port);
|
|
|
|
iounmap(uart->port.membase);
|
2013-09-09 12:08:43 +07:00
|
|
|
peripheral_free_list(dev_get_platdata(&pdev->dev));
|
2009-09-09 17:46:19 +07:00
|
|
|
kfree(uart);
|
|
|
|
bfin_serial_ports[pdev->id] = NULL;
|
2008-10-13 16:32:44 +07:00
|
|
|
}
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver bfin_serial_driver = {
|
|
|
|
.probe = bfin_serial_probe,
|
2012-11-20 01:21:34 +07:00
|
|
|
.remove = bfin_serial_remove,
|
2007-05-07 04:50:30 +07:00
|
|
|
.suspend = bfin_serial_suspend,
|
|
|
|
.resume = bfin_serial_resume,
|
|
|
|
.driver = {
|
2009-09-09 17:46:19 +07:00
|
|
|
.name = DRIVER_NAME,
|
2007-05-07 04:50:30 +07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
#if defined(CONFIG_SERIAL_BFIN_CONSOLE)
|
2013-08-08 18:40:51 +07:00
|
|
|
static struct early_platform_driver early_bfin_serial_driver __initdata = {
|
2009-09-09 17:46:19 +07:00
|
|
|
.class_str = CLASS_BFIN_CONSOLE,
|
|
|
|
.pdrv = &bfin_serial_driver,
|
|
|
|
.requested_id = EARLY_PLATFORM_ID_UNSET,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init bfin_serial_rs_console_init(void)
|
|
|
|
{
|
|
|
|
early_platform_driver_register(&early_bfin_serial_driver, DRIVER_NAME);
|
|
|
|
|
|
|
|
early_platform_driver_probe(CLASS_BFIN_CONSOLE, BFIN_UART_NR_PORTS, 0);
|
|
|
|
|
|
|
|
register_console(&bfin_serial_console);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
console_initcall(bfin_serial_rs_console_init);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_EARLY_PRINTK
|
|
|
|
/*
|
|
|
|
* Memory can't be allocated dynamically during earlyprink init stage.
|
|
|
|
* So, do individual probe for earlyprink with a static uart port variable.
|
|
|
|
*/
|
|
|
|
static int bfin_earlyprintk_probe(struct platform_device *pdev)
|
2007-05-07 04:50:30 +07:00
|
|
|
{
|
2009-09-09 17:46:19 +07:00
|
|
|
struct resource *res;
|
2007-05-07 04:50:30 +07:00
|
|
|
int ret;
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
if (pdev->id < 0 || pdev->id >= BFIN_UART_NR_PORTS) {
|
|
|
|
dev_err(&pdev->dev, "Wrong earlyprintk platform device id.\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-09-09 12:08:43 +07:00
|
|
|
ret = peripheral_request_list(dev_get_platdata(&pdev->dev),
|
|
|
|
DRIVER_NAME);
|
2009-09-09 17:46:19 +07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"fail to request bfin serial peripherals\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_error_free_peripherals;
|
|
|
|
}
|
|
|
|
|
|
|
|
bfin_earlyprintk_port.port.membase = ioremap(res->start,
|
2011-06-09 23:13:32 +07:00
|
|
|
resource_size(res));
|
2009-09-09 17:46:19 +07:00
|
|
|
if (!bfin_earlyprintk_port.port.membase) {
|
|
|
|
dev_err(&pdev->dev, "Cannot map uart IO\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto out_error_free_peripherals;
|
|
|
|
}
|
|
|
|
bfin_earlyprintk_port.port.mapbase = res->start;
|
|
|
|
bfin_earlyprintk_port.port.line = pdev->id;
|
|
|
|
bfin_earlyprintk_port.port.uartclk = get_sclk();
|
|
|
|
bfin_earlyprintk_port.port.fifosize = BFIN_UART_TX_FIFO_SIZE;
|
|
|
|
spin_lock_init(&bfin_earlyprintk_port.port.lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_error_free_peripherals:
|
2013-09-09 12:08:43 +07:00
|
|
|
peripheral_free_list(dev_get_platdata(&pdev->dev));
|
2009-09-09 17:46:19 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver bfin_earlyprintk_driver = {
|
|
|
|
.probe = bfin_earlyprintk_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-08-08 18:40:51 +07:00
|
|
|
static struct early_platform_driver early_bfin_earlyprintk_driver __initdata = {
|
2009-09-09 17:46:19 +07:00
|
|
|
.class_str = CLASS_BFIN_EARLYPRINTK,
|
|
|
|
.pdrv = &bfin_earlyprintk_driver,
|
|
|
|
.requested_id = EARLY_PLATFORM_ID_UNSET,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct console __init *bfin_earlyserial_init(unsigned int port,
|
|
|
|
unsigned int cflag)
|
|
|
|
{
|
|
|
|
struct ktermios t;
|
|
|
|
char port_name[20];
|
2007-05-07 04:50:30 +07:00
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
if (port < 0 || port >= BFIN_UART_NR_PORTS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only probe resource of the given port in earlyprintk boot arg.
|
|
|
|
* The expected port id should be indicated in port name string.
|
|
|
|
*/
|
|
|
|
snprintf(port_name, 20, DRIVER_NAME ".%d", port);
|
|
|
|
early_platform_driver_register(&early_bfin_earlyprintk_driver,
|
|
|
|
port_name);
|
|
|
|
early_platform_driver_probe(CLASS_BFIN_EARLYPRINTK, 1, 0);
|
|
|
|
|
|
|
|
if (!bfin_earlyprintk_port.port.membase)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_BFIN_CONSOLE
|
|
|
|
/*
|
|
|
|
* If we are using early serial, don't let the normal console rewind
|
|
|
|
* log buffer, since that causes things to be printed multiple times
|
|
|
|
*/
|
|
|
|
bfin_serial_console.flags &= ~CON_PRINTBUFFER;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bfin_early_serial_console.index = port;
|
|
|
|
t.c_cflag = cflag;
|
|
|
|
t.c_iflag = 0;
|
|
|
|
t.c_oflag = 0;
|
|
|
|
t.c_lflag = ICANON;
|
|
|
|
t.c_line = port;
|
|
|
|
bfin_serial_set_termios(&bfin_earlyprintk_port.port, &t, &t);
|
|
|
|
|
|
|
|
return &bfin_early_serial_console;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_EARLY_PRINTK */
|
|
|
|
|
|
|
|
static int __init bfin_serial_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pr_info("Blackfin serial driver\n");
|
2007-05-07 04:50:30 +07:00
|
|
|
|
|
|
|
ret = uart_register_driver(&bfin_serial_reg);
|
2009-09-09 17:46:19 +07:00
|
|
|
if (ret) {
|
|
|
|
pr_err("failed to register %s:%d\n",
|
|
|
|
bfin_serial_reg.driver_name, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = platform_driver_register(&bfin_serial_driver);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("fail to register bfin uart\n");
|
|
|
|
uart_unregister_driver(&bfin_serial_reg);
|
2007-05-07 04:50:30 +07:00
|
|
|
}
|
2009-09-09 17:46:19 +07:00
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit bfin_serial_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&bfin_serial_driver);
|
|
|
|
uart_unregister_driver(&bfin_serial_reg);
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:40:14 +07:00
|
|
|
|
2007-05-07 04:50:30 +07:00
|
|
|
module_init(bfin_serial_init);
|
|
|
|
module_exit(bfin_serial_exit);
|
|
|
|
|
2009-09-09 17:46:19 +07:00
|
|
|
MODULE_AUTHOR("Sonic Zhang, Aubrey Li");
|
2007-05-07 04:50:30 +07:00
|
|
|
MODULE_DESCRIPTION("Blackfin generic serial port driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR);
|
2008-04-16 04:34:35 +07:00
|
|
|
MODULE_ALIAS("platform:bfin-uart");
|