2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Driver for 8250/16550-type serial ports
|
|
|
|
*
|
|
|
|
* Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Russell King.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* A note about mapbase / membase
|
|
|
|
*
|
|
|
|
* mapbase is the physical address of the IO port.
|
|
|
|
* membase is an 'ioremapped' cookie.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
|
|
|
|
#define SUPPORT_SYSRQ
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/sysrq.h>
|
|
|
|
#include <linux/delay.h>
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/tty.h>
|
2010-10-21 07:00:48 +08:00
|
|
|
#include <linux/ratelimit.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/serial_core.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/serial_8250.h>
|
2005-11-07 16:59:13 +08:00
|
|
|
#include <linux/nmi.h>
|
2006-01-13 02:44:32 +08:00
|
|
|
#include <linux/mutex.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2014-09-09 13:17:45 +08:00
|
|
|
#include <linux/uaccess.h>
|
2012-02-10 07:48:19 +08:00
|
|
|
#ifdef CONFIG_SPARC
|
|
|
|
#include <linux/sunserialcore.h>
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
#include "8250.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configuration:
|
2006-07-02 10:29:43 +08:00
|
|
|
* share_irqs - whether we pass IRQF_SHARED to request_irq(). This option
|
2005-04-17 06:20:36 +08:00
|
|
|
* is unsafe when used on edge-triggered interrupts.
|
|
|
|
*/
|
2005-05-01 23:59:29 +08:00
|
|
|
static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-08 07:18:19 +08:00
|
|
|
static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS;
|
|
|
|
|
2008-10-13 17:45:26 +08:00
|
|
|
static struct uart_driver serial8250_reg;
|
|
|
|
|
|
|
|
static int serial_index(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return (serial8250_reg.minor - 64) + port->line;
|
|
|
|
}
|
|
|
|
|
2009-10-02 06:44:26 +08:00
|
|
|
static unsigned int skip_txen_test; /* force skip of txen test at init time */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Debugging.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
#define DEBUG_AUTOCONF(fmt...) printk(fmt)
|
|
|
|
#else
|
|
|
|
#define DEBUG_AUTOCONF(fmt...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define DEBUG_INTR(fmt...) printk(fmt)
|
|
|
|
#else
|
|
|
|
#define DEBUG_INTR(fmt...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2011-06-06 04:51:49 +08:00
|
|
|
#define PASS_LIMIT 512
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-12-10 04:31:34 +08:00
|
|
|
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_SERIAL_8250_DETECT_IRQ
|
|
|
|
#define CONFIG_SERIAL_DETECT_IRQ 1
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SERIAL_8250_MANY_PORTS
|
|
|
|
#define CONFIG_SERIAL_MANY_PORTS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HUB6 is always on. This will be removed once the header
|
|
|
|
* files have been cleaned.
|
|
|
|
*/
|
|
|
|
#define CONFIG_HUB6 1
|
|
|
|
|
2008-05-31 16:10:04 +08:00
|
|
|
#include <asm/serial.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* SERIAL_PORT_DFNS tells us about built-in ports that have no
|
|
|
|
* standard enumeration mechanism. Platforms that can find all
|
|
|
|
* serial ports via mechanisms like ACPI or PCI need not supply it.
|
|
|
|
*/
|
|
|
|
#ifndef SERIAL_PORT_DFNS
|
|
|
|
#define SERIAL_PORT_DFNS
|
|
|
|
#endif
|
|
|
|
|
2005-11-29 05:04:11 +08:00
|
|
|
static const struct old_serial_port old_serial_port[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
SERIAL_PORT_DFNS /* defined in asm/serial.h */
|
|
|
|
};
|
|
|
|
|
2005-06-30 01:45:19 +08:00
|
|
|
#define UART_NR CONFIG_SERIAL_8250_NR_UARTS
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
|
|
|
|
#define PORT_RSA_MAX 4
|
|
|
|
static unsigned long probe_rsa[PORT_RSA_MAX];
|
|
|
|
static unsigned int probe_rsa_count;
|
|
|
|
#endif /* CONFIG_SERIAL_8250_RSA */
|
|
|
|
|
|
|
|
struct irq_info {
|
2008-08-20 11:49:40 +08:00
|
|
|
struct hlist_node node;
|
|
|
|
int irq;
|
|
|
|
spinlock_t lock; /* Protects list not the hash */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct list_head *head;
|
|
|
|
};
|
|
|
|
|
2008-08-20 11:49:40 +08:00
|
|
|
#define NR_IRQ_HASH 32 /* Can be adjusted later */
|
|
|
|
static struct hlist_head irq_lists[NR_IRQ_HASH];
|
|
|
|
static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here we define the default xmit fifo size used for each type of UART.
|
|
|
|
*/
|
|
|
|
static const struct serial8250_config uart_config[] = {
|
|
|
|
[PORT_UNKNOWN] = {
|
|
|
|
.name = "unknown",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1,
|
|
|
|
},
|
|
|
|
[PORT_8250] = {
|
|
|
|
.name = "8250",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1,
|
|
|
|
},
|
|
|
|
[PORT_16450] = {
|
|
|
|
.name = "16450",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1,
|
|
|
|
},
|
|
|
|
[PORT_16550] = {
|
|
|
|
.name = "16550",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1,
|
|
|
|
},
|
|
|
|
[PORT_16550A] = {
|
|
|
|
.name = "16550A",
|
|
|
|
.fifo_size = 16,
|
|
|
|
.tx_loadsz = 16,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
.rxtrig_bytes = {1, 4, 8, 14},
|
2005-04-17 06:20:36 +08:00
|
|
|
.flags = UART_CAP_FIFO,
|
|
|
|
},
|
|
|
|
[PORT_CIRRUS] = {
|
|
|
|
.name = "Cirrus",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1,
|
|
|
|
},
|
|
|
|
[PORT_16650] = {
|
|
|
|
.name = "ST16650",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
|
|
|
|
},
|
|
|
|
[PORT_16650V2] = {
|
|
|
|
.name = "ST16650V2",
|
|
|
|
.fifo_size = 32,
|
|
|
|
.tx_loadsz = 16,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
|
|
|
|
UART_FCR_T_TRIG_00,
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
.rxtrig_bytes = {8, 16, 24, 28},
|
2005-04-17 06:20:36 +08:00
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
|
|
|
|
},
|
|
|
|
[PORT_16750] = {
|
|
|
|
.name = "TI16750",
|
|
|
|
.fifo_size = 64,
|
|
|
|
.tx_loadsz = 64,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
|
|
|
|
UART_FCR7_64BYTE,
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
.rxtrig_bytes = {1, 16, 32, 56},
|
2005-04-17 06:20:36 +08:00
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE,
|
|
|
|
},
|
|
|
|
[PORT_STARTECH] = {
|
|
|
|
.name = "Startech",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1,
|
|
|
|
},
|
|
|
|
[PORT_16C950] = {
|
|
|
|
.name = "16C950/954",
|
|
|
|
.fifo_size = 128,
|
|
|
|
.tx_loadsz = 128,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
2011-01-09 15:38:48 +08:00
|
|
|
/* UART_CAP_EFR breaks billionon CF bluetooth card. */
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_SLEEP,
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
|
|
|
[PORT_16654] = {
|
|
|
|
.name = "ST16654",
|
|
|
|
.fifo_size = 64,
|
|
|
|
.tx_loadsz = 32,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
|
|
|
|
UART_FCR_T_TRIG_10,
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
.rxtrig_bytes = {8, 16, 56, 60},
|
2005-04-17 06:20:36 +08:00
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
|
|
|
|
},
|
|
|
|
[PORT_16850] = {
|
|
|
|
.name = "XR16850",
|
|
|
|
.fifo_size = 128,
|
|
|
|
.tx_loadsz = 128,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
|
|
|
|
},
|
|
|
|
[PORT_RSA] = {
|
|
|
|
.name = "RSA",
|
|
|
|
.fifo_size = 2048,
|
|
|
|
.tx_loadsz = 2048,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11,
|
|
|
|
.flags = UART_CAP_FIFO,
|
|
|
|
},
|
|
|
|
[PORT_NS16550A] = {
|
|
|
|
.name = "NS16550A",
|
|
|
|
.fifo_size = 16,
|
|
|
|
.tx_loadsz = 16,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
|
|
|
.flags = UART_CAP_FIFO | UART_NATSEMI,
|
|
|
|
},
|
|
|
|
[PORT_XSCALE] = {
|
|
|
|
.name = "XScale",
|
|
|
|
.fifo_size = 32,
|
|
|
|
.tx_loadsz = 32,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
2011-05-18 06:12:36 +08:00
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_UUE | UART_CAP_RTOIE,
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
2009-01-02 21:50:00 +08:00
|
|
|
[PORT_OCTEON] = {
|
|
|
|
.name = "OCTEON",
|
|
|
|
.fifo_size = 64,
|
|
|
|
.tx_loadsz = 64,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
2007-05-07 05:48:47 +08:00
|
|
|
.flags = UART_CAP_FIFO,
|
|
|
|
},
|
2009-06-11 20:21:24 +08:00
|
|
|
[PORT_AR7] = {
|
|
|
|
.name = "AR7",
|
|
|
|
.fifo_size = 16,
|
|
|
|
.tx_loadsz = 16,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_AFE,
|
|
|
|
},
|
U6715 16550A serial driver support
UART Features extract from STEricsson U6715 data-sheet (arm926 SoC for mobile phone):
* Fully compatible with industry standard 16C550 and 16C450 from various
manufacturers
* RX and TX 64 byte FIFO reduces CPU interrupts
* Full double buffering
* Modem control signals include CTS, RTS, (and DSR, DTR on UART1 only)
* Automatic baud rate selection
* Manual or automatic RTS/CTS smart hardware flow control
* Programmable serial characteristics:
– Baud rate generation (50 to 3.25M baud)
– 5, 6, 7 or 8-bit characters
– Even, odd or no-parity bit generation and detection
– 1, 1.5 or 2 stop bit generation
* Independent control of transmit, receive, line status, data set interrupts and FIFOs
* Full status-reporting capabilities
* Separate DMA signaling for RX and TX
* Timed interrupt to spread receive interrupt on known duration
* DMA time-out interrupt to allow detection of end of reception
* Carkit pulse coding and decoding compliant with USB carkit control interface [40]
In 16550A auto-configuration, if the fifo size is 64 then it's an U6 16550A port
Add set_termios hook & export serial8250_do_set_termios to change uart
clock following baudrate
Signed-off-by: Philippe Langlais <philippe.langlais@stericsson.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-07-29 23:13:57 +08:00
|
|
|
[PORT_U6_16550A] = {
|
|
|
|
.name = "U6_16550A",
|
|
|
|
.fifo_size = 64,
|
|
|
|
.tx_loadsz = 64,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_AFE,
|
|
|
|
},
|
2011-05-18 06:12:36 +08:00
|
|
|
[PORT_TEGRA] = {
|
|
|
|
.name = "Tegra",
|
|
|
|
.fifo_size = 32,
|
|
|
|
.tx_loadsz = 8,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
|
|
|
|
UART_FCR_T_TRIG_01,
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
.rxtrig_bytes = {1, 4, 8, 14},
|
2011-05-18 06:12:36 +08:00
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_RTOIE,
|
|
|
|
},
|
2011-09-03 04:55:37 +08:00
|
|
|
[PORT_XR17D15X] = {
|
|
|
|
.name = "XR17D15X",
|
|
|
|
.fifo_size = 64,
|
|
|
|
.tx_loadsz = 64,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
2012-11-21 23:39:07 +08:00
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR |
|
|
|
|
UART_CAP_SLEEP,
|
2011-09-03 04:55:37 +08:00
|
|
|
},
|
2012-11-19 23:12:04 +08:00
|
|
|
[PORT_XR17V35X] = {
|
|
|
|
.name = "XR17V35X",
|
|
|
|
.fifo_size = 256,
|
|
|
|
.tx_loadsz = 256,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11 |
|
|
|
|
UART_FCR_T_TRIG_11,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR |
|
|
|
|
UART_CAP_SLEEP,
|
|
|
|
},
|
2012-06-12 03:57:13 +08:00
|
|
|
[PORT_LPC3220] = {
|
|
|
|
.name = "LPC3220",
|
|
|
|
.fifo_size = 64,
|
|
|
|
.tx_loadsz = 32,
|
|
|
|
.fcr = UART_FCR_DMA_SELECT | UART_FCR_ENABLE_FIFO |
|
|
|
|
UART_FCR_R_TRIG_00 | UART_FCR_T_TRIG_00,
|
|
|
|
.flags = UART_CAP_FIFO,
|
|
|
|
},
|
2013-01-18 06:14:53 +08:00
|
|
|
[PORT_BRCM_TRUMANAGE] = {
|
|
|
|
.name = "TruManage",
|
|
|
|
.fifo_size = 1,
|
|
|
|
.tx_loadsz = 1024,
|
|
|
|
.flags = UART_CAP_HFIFO,
|
|
|
|
},
|
2012-09-08 02:06:24 +08:00
|
|
|
[PORT_8250_CIR] = {
|
|
|
|
.name = "CIR port"
|
2013-03-07 10:28:37 +08:00
|
|
|
},
|
|
|
|
[PORT_ALTR_16550_F32] = {
|
|
|
|
.name = "Altera 16550 FIFO32",
|
|
|
|
.fifo_size = 32,
|
|
|
|
.tx_loadsz = 32,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_AFE,
|
|
|
|
},
|
|
|
|
[PORT_ALTR_16550_F64] = {
|
|
|
|
.name = "Altera 16550 FIFO64",
|
|
|
|
.fifo_size = 64,
|
|
|
|
.tx_loadsz = 64,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_AFE,
|
|
|
|
},
|
|
|
|
[PORT_ALTR_16550_F128] = {
|
|
|
|
.name = "Altera 16550 FIFO128",
|
|
|
|
.fifo_size = 128,
|
|
|
|
.tx_loadsz = 128,
|
|
|
|
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
|
|
|
|
.flags = UART_CAP_FIFO | UART_CAP_AFE,
|
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2012-05-02 20:46:51 +08:00
|
|
|
/* Uart divisor latch read */
|
2012-05-02 20:47:18 +08:00
|
|
|
static int default_serial_dl_read(struct uart_8250_port *up)
|
2012-05-02 20:46:51 +08:00
|
|
|
{
|
|
|
|
return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Uart divisor latch write */
|
2012-05-02 20:47:18 +08:00
|
|
|
static void default_serial_dl_write(struct uart_8250_port *up, int value)
|
2012-05-02 20:46:51 +08:00
|
|
|
{
|
|
|
|
serial_out(up, UART_DLL, value & 0xff);
|
|
|
|
serial_out(up, UART_DLM, value >> 8 & 0xff);
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:39:51 +08:00
|
|
|
#if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X)
|
2005-11-06 17:07:03 +08:00
|
|
|
|
2013-01-26 02:39:51 +08:00
|
|
|
/* Au1x00/RT288x UART hardware has a weird register layout */
|
2005-11-06 17:07:03 +08:00
|
|
|
static const u8 au_io_in_map[] = {
|
|
|
|
[UART_RX] = 0,
|
|
|
|
[UART_IER] = 2,
|
|
|
|
[UART_IIR] = 3,
|
|
|
|
[UART_LCR] = 5,
|
|
|
|
[UART_MCR] = 6,
|
|
|
|
[UART_LSR] = 7,
|
|
|
|
[UART_MSR] = 8,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 au_io_out_map[] = {
|
|
|
|
[UART_TX] = 1,
|
|
|
|
[UART_IER] = 2,
|
|
|
|
[UART_FCR] = 4,
|
|
|
|
[UART_LCR] = 5,
|
|
|
|
[UART_MCR] = 6,
|
|
|
|
};
|
|
|
|
|
2012-05-02 20:47:00 +08:00
|
|
|
static unsigned int au_serial_in(struct uart_port *p, int offset)
|
2005-11-06 17:07:03 +08:00
|
|
|
{
|
2012-05-02 20:47:00 +08:00
|
|
|
offset = au_io_in_map[offset] << p->regshift;
|
|
|
|
return __raw_readl(p->membase + offset);
|
2005-11-06 17:07:03 +08:00
|
|
|
}
|
|
|
|
|
2012-05-02 20:47:00 +08:00
|
|
|
static void au_serial_out(struct uart_port *p, int offset, int value)
|
2005-11-06 17:07:03 +08:00
|
|
|
{
|
2012-05-02 20:47:00 +08:00
|
|
|
offset = au_io_out_map[offset] << p->regshift;
|
|
|
|
__raw_writel(value, p->membase + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Au1x00 haven't got a standard divisor latch */
|
|
|
|
static int au_serial_dl_read(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
return __raw_readl(up->port.membase + 0x28);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au_serial_dl_write(struct uart_8250_port *up, int value)
|
|
|
|
{
|
|
|
|
__raw_writel(value, up->port.membase + 0x28);
|
2005-11-06 17:07:03 +08:00
|
|
|
}
|
|
|
|
|
2012-05-02 20:47:00 +08:00
|
|
|
#endif
|
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
static unsigned int hub6_serial_in(struct uart_port *p, int offset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
outb(p->hub6 - 1 + offset, p->iobase);
|
|
|
|
return inb(p->iobase + 1);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
static void hub6_serial_out(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
outb(p->hub6 - 1 + offset, p->iobase);
|
|
|
|
outb(value, p->iobase + 1);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
static unsigned int mem_serial_in(struct uart_port *p, int offset)
|
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
return readb(p->membase + offset);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
static void mem_serial_out(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
writeb(value, p->membase + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mem32_serial_out(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
writel(value, p->membase + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int mem32_serial_in(struct uart_port *p, int offset)
|
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
return readl(p->membase + offset);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
static unsigned int io_serial_in(struct uart_port *p, int offset)
|
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
return inb(p->iobase + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void io_serial_out(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
2012-05-02 20:47:18 +08:00
|
|
|
offset = offset << p->regshift;
|
2009-01-02 21:49:47 +08:00
|
|
|
outb(value, p->iobase + offset);
|
|
|
|
}
|
|
|
|
|
2011-08-15 17:17:52 +08:00
|
|
|
static int serial8250_default_handle_irq(struct uart_port *port);
|
2012-11-19 23:12:04 +08:00
|
|
|
static int exar_handle_irq(struct uart_port *port);
|
2011-08-15 17:17:52 +08:00
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
static void set_io_from_upio(struct uart_port *p)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(p);
|
2012-05-02 20:46:51 +08:00
|
|
|
|
2012-05-02 20:47:18 +08:00
|
|
|
up->dl_read = default_serial_dl_read;
|
|
|
|
up->dl_write = default_serial_dl_write;
|
2012-05-02 20:46:51 +08:00
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
switch (p->iotype) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case UPIO_HUB6:
|
2009-01-02 21:49:47 +08:00
|
|
|
p->serial_in = hub6_serial_in;
|
|
|
|
p->serial_out = hub6_serial_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPIO_MEM:
|
2009-01-02 21:49:47 +08:00
|
|
|
p->serial_in = mem_serial_in;
|
|
|
|
p->serial_out = mem_serial_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPIO_MEM32:
|
2009-01-02 21:49:47 +08:00
|
|
|
p->serial_in = mem32_serial_in;
|
|
|
|
p->serial_out = mem32_serial_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
2013-01-26 02:39:51 +08:00
|
|
|
#if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X)
|
2005-11-06 17:07:03 +08:00
|
|
|
case UPIO_AU:
|
2009-01-02 21:49:47 +08:00
|
|
|
p->serial_in = au_serial_in;
|
|
|
|
p->serial_out = au_serial_out;
|
2012-05-02 20:47:00 +08:00
|
|
|
up->dl_read = au_serial_dl_read;
|
|
|
|
up->dl_write = au_serial_dl_write;
|
2005-11-06 17:07:03 +08:00
|
|
|
break;
|
2012-05-02 20:47:00 +08:00
|
|
|
#endif
|
2010-07-16 03:45:05 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
2009-01-02 21:49:47 +08:00
|
|
|
p->serial_in = io_serial_in;
|
|
|
|
p->serial_out = io_serial_out;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-05-28 21:01:35 +08:00
|
|
|
/* Remember loaded iotype */
|
|
|
|
up->cur_iotype = p->iotype;
|
2011-08-15 17:17:52 +08:00
|
|
|
p->handle_irq = serial8250_default_handle_irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-14 16:33:04 +08:00
|
|
|
static void
|
2012-03-09 08:12:14 +08:00
|
|
|
serial_port_out_sync(struct uart_port *p, int offset, int value)
|
2007-02-14 16:33:04 +08:00
|
|
|
{
|
2009-01-02 21:49:47 +08:00
|
|
|
switch (p->iotype) {
|
2007-02-14 16:33:04 +08:00
|
|
|
case UPIO_MEM:
|
|
|
|
case UPIO_MEM32:
|
|
|
|
case UPIO_AU:
|
2009-01-02 21:49:47 +08:00
|
|
|
p->serial_out(p, offset, value);
|
|
|
|
p->serial_in(p, UART_LCR); /* safe, no side-effects */
|
2007-02-14 16:33:04 +08:00
|
|
|
break;
|
|
|
|
default:
|
2009-01-02 21:49:47 +08:00
|
|
|
p->serial_out(p, offset, value);
|
2007-02-14 16:33:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* For the 16C950
|
|
|
|
*/
|
|
|
|
static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
|
|
|
|
{
|
|
|
|
serial_out(up, UART_SCR, offset);
|
|
|
|
serial_out(up, UART_ICR, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
|
|
|
|
{
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
|
|
|
|
serial_out(up, UART_SCR, offset);
|
|
|
|
value = serial_in(up, UART_ICR);
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIFO support.
|
|
|
|
*/
|
2008-10-13 17:36:21 +08:00
|
|
|
static void serial8250_clear_fifos(struct uart_8250_port *p)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (p->capabilities & UART_CAP_FIFO) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO |
|
2005-04-17 06:20:36 +08:00
|
|
|
UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(p, UART_FCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 05:10:58 +08:00
|
|
|
void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p)
|
|
|
|
{
|
|
|
|
serial8250_clear_fifos(p);
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
serial_out(p, UART_FCR, p->fcr);
|
2012-04-11 05:10:58 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* IER sleep support. UARTs which have EFRs need the "extended
|
|
|
|
* capability" bit enabled. Note that on XR16C850s, we need to
|
|
|
|
* reset LCR to write to IER.
|
|
|
|
*/
|
2008-10-13 17:36:21 +08:00
|
|
|
static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-11-19 23:12:04 +08:00
|
|
|
/*
|
|
|
|
* Exar UARTs have a SLEEP register that enables or disables
|
|
|
|
* each UART to enter sleep mode separately. On the XR17V35x the
|
|
|
|
* register is accessible to each UART at the UART_EXAR_SLEEP
|
|
|
|
* offset but the UART channel may only write to the corresponding
|
|
|
|
* bit.
|
|
|
|
*/
|
2012-11-21 23:39:07 +08:00
|
|
|
if ((p->port.type == PORT_XR17V35X) ||
|
|
|
|
(p->port.type == PORT_XR17D15X)) {
|
2014-04-26 08:27:48 +08:00
|
|
|
serial_out(p, UART_EXAR_SLEEP, sleep ? 0xff : 0);
|
2012-11-19 23:12:04 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (p->capabilities & UART_CAP_SLEEP) {
|
|
|
|
if (p->capabilities & UART_CAP_EFR) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B);
|
|
|
|
serial_out(p, UART_EFR, UART_EFR_ECB);
|
|
|
|
serial_out(p, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (p->capabilities & UART_CAP_EFR) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B);
|
|
|
|
serial_out(p, UART_EFR, 0);
|
|
|
|
serial_out(p, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
/*
|
|
|
|
* Attempts to turn on the RSA FIFO. Returns zero on failure.
|
|
|
|
* We set the port uart clock rate if we succeed.
|
|
|
|
*/
|
|
|
|
static int __enable_rsa(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned char mode;
|
|
|
|
int result;
|
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
mode = serial_in(up, UART_RSA_MSR);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = mode & UART_RSA_MSR_FIFO;
|
|
|
|
|
|
|
|
if (!result) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
|
|
|
|
mode = serial_in(up, UART_RSA_MSR);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = mode & UART_RSA_MSR_FIFO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void enable_rsa(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
if (up->port.type == PORT_RSA) {
|
|
|
|
if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
|
|
|
|
spin_lock_irq(&up->port.lock);
|
|
|
|
__enable_rsa(up);
|
|
|
|
spin_unlock_irq(&up->port.lock);
|
|
|
|
}
|
|
|
|
if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_RSA_FRR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempts to turn off the RSA FIFO. Returns zero on failure.
|
|
|
|
* It is unknown why interrupts were disabled in here. However,
|
|
|
|
* the caller is expected to preserve this behaviour by grabbing
|
|
|
|
* the spinlock before calling this function.
|
|
|
|
*/
|
|
|
|
static void disable_rsa(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned char mode;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (up->port.type == PORT_RSA &&
|
|
|
|
up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
|
|
|
|
spin_lock_irq(&up->port.lock);
|
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
mode = serial_in(up, UART_RSA_MSR);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = !(mode & UART_RSA_MSR_FIFO);
|
|
|
|
|
|
|
|
if (!result) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
|
|
|
|
mode = serial_in(up, UART_RSA_MSR);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = !(mode & UART_RSA_MSR_FIFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
|
|
|
|
spin_unlock_irq(&up->port.lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SERIAL_8250_RSA */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a quickie test to see how big the FIFO is.
|
|
|
|
* It doesn't work at all the time, more's the pity.
|
|
|
|
*/
|
|
|
|
static int size_fifo(struct uart_8250_port *up)
|
|
|
|
{
|
2006-04-30 18:20:56 +08:00
|
|
|
unsigned char old_fcr, old_mcr, old_lcr;
|
|
|
|
unsigned short old_dl;
|
2005-04-17 06:20:36 +08:00
|
|
|
int count;
|
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
old_lcr = serial_in(up, UART_LCR);
|
|
|
|
serial_out(up, UART_LCR, 0);
|
|
|
|
old_fcr = serial_in(up, UART_FCR);
|
|
|
|
old_mcr = serial_in(up, UART_MCR);
|
|
|
|
serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
|
2005-04-17 06:20:36 +08:00
|
|
|
UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_MCR, UART_MCR_LOOP);
|
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
|
2006-04-30 18:20:56 +08:00
|
|
|
old_dl = serial_dl_read(up);
|
|
|
|
serial_dl_write(up, 0x0001);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0x03);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (count = 0; count < 256; count++)
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_TX, count);
|
2005-04-17 06:20:36 +08:00
|
|
|
mdelay(20);/* FIXME - schedule_timeout */
|
2012-03-09 08:12:08 +08:00
|
|
|
for (count = 0; (serial_in(up, UART_LSR) & UART_LSR_DR) &&
|
2005-04-17 06:20:36 +08:00
|
|
|
(count < 256); count++)
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_in(up, UART_RX);
|
|
|
|
serial_out(up, UART_FCR, old_fcr);
|
|
|
|
serial_out(up, UART_MCR, old_mcr);
|
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
|
2006-04-30 18:20:56 +08:00
|
|
|
serial_dl_write(up, old_dl);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, old_lcr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read UART ID using the divisor method - set DLL and DLM to zero
|
|
|
|
* and the revision will be in DLL and device type in DLM. We
|
|
|
|
* preserve the device state across this.
|
|
|
|
*/
|
|
|
|
static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p)
|
|
|
|
{
|
|
|
|
unsigned char old_dll, old_dlm, old_lcr;
|
|
|
|
unsigned int id;
|
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
old_lcr = serial_in(p, UART_LCR);
|
|
|
|
serial_out(p, UART_LCR, UART_LCR_CONF_MODE_A);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
old_dll = serial_in(p, UART_DLL);
|
|
|
|
old_dlm = serial_in(p, UART_DLM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(p, UART_DLL, 0);
|
|
|
|
serial_out(p, UART_DLM, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
id = serial_in(p, UART_DLL) | serial_in(p, UART_DLM) << 8;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(p, UART_DLL, old_dll);
|
|
|
|
serial_out(p, UART_DLM, old_dlm);
|
|
|
|
serial_out(p, UART_LCR, old_lcr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
|
|
|
|
* When this function is called we know it is at least a StarTech
|
|
|
|
* 16650 V2, but it might be one of several StarTech UARTs, or one of
|
|
|
|
* its clones. (We treat the broken original StarTech 16650 V1 as a
|
|
|
|
* 16550, and why not? Startech doesn't seem to even acknowledge its
|
|
|
|
* existence.)
|
2007-05-07 05:48:47 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* What evil have men's minds wrought...
|
|
|
|
*/
|
|
|
|
static void autoconfig_has_efr(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned int id1, id2, id3, rev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Everything with an EFR has SLEEP
|
|
|
|
*/
|
|
|
|
up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First we check to see if it's an Oxford Semiconductor UART.
|
|
|
|
*
|
|
|
|
* If we have to do this here because some non-National
|
|
|
|
* Semiconductor clone chips lock up if you try writing to the
|
|
|
|
* LSR register (which serial_icr_read does)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for Oxford Semiconductor 16C950.
|
|
|
|
*
|
|
|
|
* EFR [4] must be set else this test fails.
|
|
|
|
*
|
|
|
|
* This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca)
|
|
|
|
* claims that it's needed for 952 dual UART's (which are not
|
|
|
|
* recommended for new designs).
|
|
|
|
*/
|
|
|
|
up->acr = 0;
|
2010-12-01 06:11:49 +08:00
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
|
2005-04-17 06:20:36 +08:00
|
|
|
serial_out(up, UART_EFR, UART_EFR_ECB);
|
|
|
|
serial_out(up, UART_LCR, 0x00);
|
|
|
|
id1 = serial_icr_read(up, UART_ID1);
|
|
|
|
id2 = serial_icr_read(up, UART_ID2);
|
|
|
|
id3 = serial_icr_read(up, UART_ID3);
|
|
|
|
rev = serial_icr_read(up, UART_REV);
|
|
|
|
|
|
|
|
DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
|
|
|
|
|
|
|
|
if (id1 == 0x16 && id2 == 0xC9 &&
|
|
|
|
(id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
|
|
|
|
up->port.type = PORT_16C950;
|
2005-06-23 17:43:04 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable work around for the Oxford Semiconductor 952 rev B
|
|
|
|
* chip which causes it to seriously miscalculate baud rates
|
|
|
|
* when DLL is 0.
|
|
|
|
*/
|
|
|
|
if (id3 == 0x52 && rev == 0x01)
|
|
|
|
up->bugs |= UART_BUG_QUOT;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2007-05-07 05:48:47 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We check for a XR16C850 by setting DLL and DLM to 0, and then
|
|
|
|
* reading back DLL and DLM. The chip type depends on the DLM
|
|
|
|
* value read back:
|
|
|
|
* 0x10 - XR16C850 and the DLL contains the chip revision.
|
|
|
|
* 0x12 - XR16C2850.
|
|
|
|
* 0x14 - XR16C854.
|
|
|
|
*/
|
|
|
|
id1 = autoconfig_read_divisor_id(up);
|
|
|
|
DEBUG_AUTOCONF("850id=%04x ", id1);
|
|
|
|
|
|
|
|
id2 = id1 >> 8;
|
|
|
|
if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
|
|
|
|
up->port.type = PORT_16850;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It wasn't an XR16C850.
|
|
|
|
*
|
|
|
|
* We distinguish between the '654 and the '650 by counting
|
|
|
|
* how many bytes are in the FIFO. I'm using this for now,
|
|
|
|
* since that's the technique that was sent to me in the
|
|
|
|
* serial driver update, but I'm not convinced this works.
|
|
|
|
* I've had problems doing this in the past. -TYT
|
|
|
|
*/
|
|
|
|
if (size_fifo(up) == 64)
|
|
|
|
up->port.type = PORT_16654;
|
|
|
|
else
|
|
|
|
up->port.type = PORT_16650V2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We detected a chip without a FIFO. Only two fall into
|
|
|
|
* this category - the original 8250 and the 16450. The
|
|
|
|
* 16450 has a scratch register (accessible with LCR=0)
|
|
|
|
*/
|
|
|
|
static void autoconfig_8250(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned char scratch, status1, status2;
|
|
|
|
|
|
|
|
up->port.type = PORT_8250;
|
|
|
|
|
|
|
|
scratch = serial_in(up, UART_SCR);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_SCR, 0xa5);
|
2005-04-17 06:20:36 +08:00
|
|
|
status1 = serial_in(up, UART_SCR);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_SCR, 0x5a);
|
2005-04-17 06:20:36 +08:00
|
|
|
status2 = serial_in(up, UART_SCR);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_SCR, scratch);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (status1 == 0xa5 && status2 == 0x5a)
|
|
|
|
up->port.type = PORT_16450;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int broken_efr(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Exar ST16C2550 "A2" devices incorrectly detect as
|
|
|
|
* having an EFR, and report an ID of 0x0201. See
|
2010-10-18 17:03:14 +08:00
|
|
|
* http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-09 11:35:18 +08:00
|
|
|
static inline int ns16550a_goto_highspeed(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned char status;
|
|
|
|
|
|
|
|
status = serial_in(up, 0x04); /* EXCR2 */
|
|
|
|
#define PRESL(x) ((x) & 0x30)
|
|
|
|
if (PRESL(status) == 0x10) {
|
|
|
|
/* already in high speed mode */
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
|
|
|
|
status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, 0x04, status);
|
2011-02-09 11:35:18 +08:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We know that the chip has FIFOs. Does it have an EFR? The
|
|
|
|
* EFR is located in the same register position as the IIR and
|
|
|
|
* we know the top two bits of the IIR are currently set. The
|
|
|
|
* EFR should contain zero. Try to read the EFR.
|
|
|
|
*/
|
|
|
|
static void autoconfig_16550a(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned char status1, status2;
|
|
|
|
unsigned int iersave;
|
|
|
|
|
|
|
|
up->port.type = PORT_16550A;
|
|
|
|
up->capabilities |= UART_CAP_FIFO;
|
|
|
|
|
2012-11-19 23:12:04 +08:00
|
|
|
/*
|
|
|
|
* XR17V35x UARTs have an extra divisor register, DLD
|
|
|
|
* that gets enabled with when DLAB is set which will
|
|
|
|
* cause the device to incorrectly match and assign
|
|
|
|
* port type to PORT_16650. The EFR for this UART is
|
|
|
|
* found at offset 0x09. Instead check the Deice ID (DVID)
|
|
|
|
* register for a 2, 4 or 8 port UART.
|
|
|
|
*/
|
2012-11-21 01:23:56 +08:00
|
|
|
if (up->port.flags & UPF_EXAR_EFR) {
|
|
|
|
status1 = serial_in(up, UART_EXAR_DVID);
|
|
|
|
if (status1 == 0x82 || status1 == 0x84 || status1 == 0x88) {
|
2012-11-19 23:12:04 +08:00
|
|
|
DEBUG_AUTOCONF("Exar XR17V35x ");
|
|
|
|
up->port.type = PORT_XR17V35X;
|
|
|
|
up->capabilities |= UART_CAP_AFE | UART_CAP_EFR |
|
|
|
|
UART_CAP_SLEEP;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Check for presence of the EFR when DLAB is set.
|
|
|
|
* Only ST16C650V1 UARTs pass this test.
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serial_in(up, UART_EFR) == 0) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_EFR, 0xA8);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serial_in(up, UART_EFR) != 0) {
|
|
|
|
DEBUG_AUTOCONF("EFRv1 ");
|
|
|
|
up->port.type = PORT_16650;
|
|
|
|
up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
|
|
|
|
} else {
|
|
|
|
DEBUG_AUTOCONF("Motorola 8xxx DUART ");
|
|
|
|
}
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_EFR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maybe it requires 0xbf to be written to the LCR.
|
|
|
|
* (other ST16C650V2 UARTs, TI16C752A, etc)
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
|
|
|
|
DEBUG_AUTOCONF("EFRv2 ");
|
|
|
|
autoconfig_has_efr(up);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for a National Semiconductor SuperIO chip.
|
|
|
|
* Attempt to switch to bank 2, read the value of the LOOP bit
|
|
|
|
* from EXCR1. Switch back to bank 0, change it in MCR. Then
|
|
|
|
* switch back to bank 2, read it from EXCR1 again and check
|
|
|
|
* it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
status1 = serial_in(up, UART_MCR);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0xE0);
|
2005-04-17 06:20:36 +08:00
|
|
|
status2 = serial_in(up, 0x02); /* EXCR1 */
|
|
|
|
|
|
|
|
if (!((status2 ^ status1) & UART_MCR_LOOP)) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0);
|
|
|
|
serial_out(up, UART_MCR, status1 ^ UART_MCR_LOOP);
|
|
|
|
serial_out(up, UART_LCR, 0xE0);
|
2005-04-17 06:20:36 +08:00
|
|
|
status2 = serial_in(up, 0x02); /* EXCR1 */
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0);
|
|
|
|
serial_out(up, UART_MCR, status1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((status2 ^ status1) & UART_MCR_LOOP) {
|
2005-05-21 22:52:23 +08:00
|
|
|
unsigned short quot;
|
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0xE0);
|
2005-05-21 22:52:23 +08:00
|
|
|
|
2006-04-30 18:20:56 +08:00
|
|
|
quot = serial_dl_read(up);
|
2005-05-21 22:52:23 +08:00
|
|
|
quot <<= 3;
|
|
|
|
|
2011-02-09 11:35:18 +08:00
|
|
|
if (ns16550a_goto_highspeed(up))
|
|
|
|
serial_dl_write(up, quot);
|
2005-05-21 22:52:23 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-21 22:52:23 +08:00
|
|
|
up->port.uartclk = 921600*16;
|
2005-04-17 06:20:36 +08:00
|
|
|
up->port.type = PORT_NS16550A;
|
|
|
|
up->capabilities |= UART_NATSEMI;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No EFR. Try to detect a TI16750, which only sets bit 5 of
|
|
|
|
* the IIR when 64 byte FIFO mode is enabled when DLAB is set.
|
|
|
|
* Try setting it with and without DLAB set. Cheap clones
|
|
|
|
* set bit 5 without DLAB set.
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, 0);
|
|
|
|
serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
|
2005-04-17 06:20:36 +08:00
|
|
|
status1 = serial_in(up, UART_IIR) >> 5;
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
|
|
|
|
serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
|
2005-04-17 06:20:36 +08:00
|
|
|
status2 = serial_in(up, UART_IIR) >> 5;
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
serial_out(up, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
|
|
|
|
|
|
|
|
if (status1 == 6 && status2 == 7) {
|
|
|
|
up->port.type = PORT_16750;
|
|
|
|
up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try writing and reading the UART_IER_UUE bit (b6).
|
|
|
|
* If it works, this is probably one of the Xscale platform's
|
|
|
|
* internal UARTs.
|
|
|
|
* We're going to explicitly set the UUE bit to 0 before
|
|
|
|
* trying to write and read a 1 just to make sure it's not
|
|
|
|
* already a 1 and maybe locked there before we even start start.
|
|
|
|
*/
|
|
|
|
iersave = serial_in(up, UART_IER);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_IER, iersave & ~UART_IER_UUE);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(serial_in(up, UART_IER) & UART_IER_UUE)) {
|
|
|
|
/*
|
|
|
|
* OK it's in a known zero state, try writing and reading
|
|
|
|
* without disturbing the current state of the other bits.
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_IER, iersave | UART_IER_UUE);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serial_in(up, UART_IER) & UART_IER_UUE) {
|
|
|
|
/*
|
|
|
|
* It's an Xscale.
|
|
|
|
* We'll leave the UART_IER_UUE bit set to 1 (enabled).
|
|
|
|
*/
|
|
|
|
DEBUG_AUTOCONF("Xscale ");
|
|
|
|
up->port.type = PORT_XSCALE;
|
2011-06-17 23:45:07 +08:00
|
|
|
up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If we got here we couldn't force the IER_UUE bit to 0.
|
|
|
|
* Log it and continue.
|
|
|
|
*/
|
|
|
|
DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
|
|
|
|
}
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_IER, iersave);
|
U6715 16550A serial driver support
UART Features extract from STEricsson U6715 data-sheet (arm926 SoC for mobile phone):
* Fully compatible with industry standard 16C550 and 16C450 from various
manufacturers
* RX and TX 64 byte FIFO reduces CPU interrupts
* Full double buffering
* Modem control signals include CTS, RTS, (and DSR, DTR on UART1 only)
* Automatic baud rate selection
* Manual or automatic RTS/CTS smart hardware flow control
* Programmable serial characteristics:
– Baud rate generation (50 to 3.25M baud)
– 5, 6, 7 or 8-bit characters
– Even, odd or no-parity bit generation and detection
– 1, 1.5 or 2 stop bit generation
* Independent control of transmit, receive, line status, data set interrupts and FIFOs
* Full status-reporting capabilities
* Separate DMA signaling for RX and TX
* Timed interrupt to spread receive interrupt on known duration
* DMA time-out interrupt to allow detection of end of reception
* Carkit pulse coding and decoding compliant with USB carkit control interface [40]
In 16550A auto-configuration, if the fifo size is 64 then it's an U6 16550A port
Add set_termios hook & export serial8250_do_set_termios to change uart
clock following baudrate
Signed-off-by: Philippe Langlais <philippe.langlais@stericsson.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-07-29 23:13:57 +08:00
|
|
|
|
2011-09-03 04:55:37 +08:00
|
|
|
/*
|
|
|
|
* Exar uarts have EFR in a weird location
|
|
|
|
*/
|
|
|
|
if (up->port.flags & UPF_EXAR_EFR) {
|
2012-11-21 23:39:07 +08:00
|
|
|
DEBUG_AUTOCONF("Exar XR17D15x ");
|
2011-09-03 04:55:37 +08:00
|
|
|
up->port.type = PORT_XR17D15X;
|
2012-11-21 23:39:07 +08:00
|
|
|
up->capabilities |= UART_CAP_AFE | UART_CAP_EFR |
|
|
|
|
UART_CAP_SLEEP;
|
|
|
|
|
|
|
|
return;
|
2011-09-03 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
U6715 16550A serial driver support
UART Features extract from STEricsson U6715 data-sheet (arm926 SoC for mobile phone):
* Fully compatible with industry standard 16C550 and 16C450 from various
manufacturers
* RX and TX 64 byte FIFO reduces CPU interrupts
* Full double buffering
* Modem control signals include CTS, RTS, (and DSR, DTR on UART1 only)
* Automatic baud rate selection
* Manual or automatic RTS/CTS smart hardware flow control
* Programmable serial characteristics:
– Baud rate generation (50 to 3.25M baud)
– 5, 6, 7 or 8-bit characters
– Even, odd or no-parity bit generation and detection
– 1, 1.5 or 2 stop bit generation
* Independent control of transmit, receive, line status, data set interrupts and FIFOs
* Full status-reporting capabilities
* Separate DMA signaling for RX and TX
* Timed interrupt to spread receive interrupt on known duration
* DMA time-out interrupt to allow detection of end of reception
* Carkit pulse coding and decoding compliant with USB carkit control interface [40]
In 16550A auto-configuration, if the fifo size is 64 then it's an U6 16550A port
Add set_termios hook & export serial8250_do_set_termios to change uart
clock following baudrate
Signed-off-by: Philippe Langlais <philippe.langlais@stericsson.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-07-29 23:13:57 +08:00
|
|
|
/*
|
|
|
|
* We distinguish between 16550A and U6 16550A by counting
|
|
|
|
* how many bytes are in the FIFO.
|
|
|
|
*/
|
|
|
|
if (up->port.type == PORT_16550A && size_fifo(up) == 64) {
|
|
|
|
up->port.type = PORT_U6_16550A;
|
|
|
|
up->capabilities |= UART_CAP_AFE;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called by rs_init() to initialize a specific serial
|
|
|
|
* port. It determines what type of UART chip this serial port is
|
|
|
|
* using: 8250, 16450, 16550, 16550A. The important question is
|
|
|
|
* whether or not this UART is a 16550A or not, since this will
|
|
|
|
* determine whether or not we can use its FIFO features or not.
|
|
|
|
*/
|
|
|
|
static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
|
|
|
|
{
|
|
|
|
unsigned char status1, scratch, scratch2, scratch3;
|
|
|
|
unsigned char save_lcr, save_mcr;
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
2012-09-19 03:21:32 +08:00
|
|
|
unsigned int old_capabilities;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!port->iobase && !port->mapbase && !port->membase)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2009-11-12 06:26:41 +08:00
|
|
|
DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ",
|
2012-03-09 08:12:11 +08:00
|
|
|
serial_index(port), port->iobase, port->membase);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We really do need global IRQs disabled here - we're going to
|
|
|
|
* be frobbing the chips IRQ enable register to see if it exists.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
up->capabilities = 0;
|
2005-06-23 17:43:04 +08:00
|
|
|
up->bugs = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!(port->flags & UPF_BUGGY_UART)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Do a simple existence test first; if we fail this,
|
|
|
|
* there's no point trying anything else.
|
2007-05-07 05:48:47 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* 0x80 is used as a nonsense port to prevent against
|
|
|
|
* false positives due to ISA bus float. The
|
|
|
|
* assumption is that 0x80 is a non-existent port;
|
|
|
|
* which should be safe since include/asm/io.h also
|
|
|
|
* makes this assumption.
|
|
|
|
*
|
|
|
|
* Note: this is safe as long as MCR bit 4 is clear
|
|
|
|
* and the device is in "PC" mode.
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
scratch = serial_in(up, UART_IER);
|
|
|
|
serial_out(up, UART_IER, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef __i386__
|
|
|
|
outb(0xff, 0x080);
|
|
|
|
#endif
|
2007-02-10 17:46:05 +08:00
|
|
|
/*
|
|
|
|
* Mask out IER[7:4] bits for test as some UARTs (e.g. TL
|
|
|
|
* 16C754B) allow only to modify them if an EFR bit is set.
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
scratch2 = serial_in(up, UART_IER) & 0x0f;
|
|
|
|
serial_out(up, UART_IER, 0x0F);
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef __i386__
|
|
|
|
outb(0, 0x080);
|
|
|
|
#endif
|
2012-03-09 08:12:08 +08:00
|
|
|
scratch3 = serial_in(up, UART_IER) & 0x0f;
|
|
|
|
serial_out(up, UART_IER, scratch);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (scratch2 != 0 || scratch3 != 0x0F) {
|
|
|
|
/*
|
|
|
|
* We failed; there's nothing here
|
|
|
|
*/
|
2012-09-19 03:21:32 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
|
|
|
|
scratch2, scratch3);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
save_mcr = serial_in(up, UART_MCR);
|
|
|
|
save_lcr = serial_in(up, UART_LCR);
|
|
|
|
|
2007-05-07 05:48:47 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Check to see if a UART is really there. Certain broken
|
|
|
|
* internal modems based on the Rockwell chipset fail this
|
|
|
|
* test, because they apparently don't implement the loopback
|
|
|
|
* test mode. So this test is skipped on the COM 1 through
|
|
|
|
* COM 4 ports. This *should* be safe, since no board
|
|
|
|
* manufacturer would be stupid enough to design a board
|
|
|
|
* that conflicts with COM 1-4 --- we hope!
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!(port->flags & UPF_SKIP_TEST)) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_MCR, UART_MCR_LOOP | 0x0A);
|
|
|
|
status1 = serial_in(up, UART_MSR) & 0xF0;
|
|
|
|
serial_out(up, UART_MCR, save_mcr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status1 != 0x90) {
|
2012-09-19 03:21:32 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
DEBUG_AUTOCONF("LOOP test failed (%02x) ",
|
|
|
|
status1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're pretty sure there's a port here. Lets find out what
|
|
|
|
* type of port it is. The IIR top two bits allows us to find
|
2005-09-09 23:17:58 +08:00
|
|
|
* out if it's 8250 or 16450, 16550, 16550A or later. This
|
2005-04-17 06:20:36 +08:00
|
|
|
* determines what we test for next.
|
|
|
|
*
|
|
|
|
* We also initialise the EFR (if any) to zero for later. The
|
|
|
|
* EFR occupies the same register location as the FCR and IIR.
|
|
|
|
*/
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
|
|
|
|
serial_out(up, UART_EFR, 0);
|
|
|
|
serial_out(up, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
2005-04-17 06:20:36 +08:00
|
|
|
scratch = serial_in(up, UART_IIR) >> 6;
|
|
|
|
|
|
|
|
switch (scratch) {
|
|
|
|
case 0:
|
|
|
|
autoconfig_8250(up);
|
|
|
|
break;
|
|
|
|
case 1:
|
2012-03-09 08:12:11 +08:00
|
|
|
port->type = PORT_UNKNOWN;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-03-09 08:12:11 +08:00
|
|
|
port->type = PORT_16550;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
autoconfig_16550a(up);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
/*
|
|
|
|
* Only probe for RSA ports if we got the region.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_16550A && probeflags & PROBE_RSA) {
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < probe_rsa_count; ++i) {
|
2012-03-09 08:12:11 +08:00
|
|
|
if (probe_rsa[i] == port->iobase && __enable_rsa(up)) {
|
|
|
|
port->type = PORT_RSA;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-11-06 17:07:03 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, save_lcr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
port->fifosize = uart_config[up->port.type].fifo_size;
|
2012-09-19 03:21:32 +08:00
|
|
|
old_capabilities = up->capabilities;
|
2012-03-09 08:12:11 +08:00
|
|
|
up->capabilities = uart_config[port->type].flags;
|
|
|
|
up->tx_loadsz = uart_config[port->type].tx_loadsz;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_UNKNOWN)
|
2012-09-19 03:21:32 +08:00
|
|
|
goto out_lock;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the UART.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_RSA)
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_RSA_FRR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_MCR, save_mcr);
|
2005-04-17 06:20:36 +08:00
|
|
|
serial8250_clear_fifos(up);
|
2007-02-14 16:33:04 +08:00
|
|
|
serial_in(up, UART_RX);
|
2005-11-13 05:58:05 +08:00
|
|
|
if (up->capabilities & UART_CAP_UUE)
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_IER, UART_IER_UUE);
|
2005-11-13 05:58:05 +08:00
|
|
|
else
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_IER, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-19 03:21:32 +08:00
|
|
|
out_lock:
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2012-09-19 03:21:32 +08:00
|
|
|
if (up->capabilities != old_capabilities) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"ttyS%d: detected caps %08x should be %08x\n",
|
|
|
|
serial_index(port), old_capabilities,
|
|
|
|
up->capabilities);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
DEBUG_AUTOCONF("iir=%d ", scratch);
|
2012-03-09 08:12:11 +08:00
|
|
|
DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void autoconfig_irq(struct uart_8250_port *up)
|
|
|
|
{
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char save_mcr, save_ier;
|
|
|
|
unsigned char save_ICP = 0;
|
|
|
|
unsigned int ICP = 0;
|
|
|
|
unsigned long irqs;
|
|
|
|
int irq;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->flags & UPF_FOURPORT) {
|
|
|
|
ICP = (port->iobase & 0xfe0) | 0x1f;
|
2005-04-17 06:20:36 +08:00
|
|
|
save_ICP = inb_p(ICP);
|
|
|
|
outb_p(0x80, ICP);
|
2012-03-09 08:12:10 +08:00
|
|
|
inb_p(ICP);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* forget possible initially masked and pending IRQ */
|
|
|
|
probe_irq_off(probe_irq_on());
|
2012-03-09 08:12:08 +08:00
|
|
|
save_mcr = serial_in(up, UART_MCR);
|
|
|
|
save_ier = serial_in(up, UART_IER);
|
|
|
|
serial_out(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
|
2007-05-07 05:48:47 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
irqs = probe_irq_on();
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_MCR, 0);
|
2008-02-08 20:18:52 +08:00
|
|
|
udelay(10);
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->flags & UPF_FOURPORT) {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_MCR,
|
2005-04-17 06:20:36 +08:00
|
|
|
UART_MCR_DTR | UART_MCR_RTS);
|
|
|
|
} else {
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_MCR,
|
2005-04-17 06:20:36 +08:00
|
|
|
UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
|
|
|
|
}
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_IER, 0x0f); /* enable all intrs */
|
2012-03-09 08:12:10 +08:00
|
|
|
serial_in(up, UART_LSR);
|
|
|
|
serial_in(up, UART_RX);
|
|
|
|
serial_in(up, UART_IIR);
|
|
|
|
serial_in(up, UART_MSR);
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_TX, 0xFF);
|
2008-02-08 20:18:52 +08:00
|
|
|
udelay(20);
|
2005-04-17 06:20:36 +08:00
|
|
|
irq = probe_irq_off(irqs);
|
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_MCR, save_mcr);
|
|
|
|
serial_out(up, UART_IER, save_ier);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->flags & UPF_FOURPORT)
|
2005-04-17 06:20:36 +08:00
|
|
|
outb_p(save_ICP, ICP);
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
port->irq = (irq > 0) ? irq : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-06-30 01:41:51 +08:00
|
|
|
static inline void __stop_tx(struct uart_8250_port *p)
|
|
|
|
{
|
|
|
|
if (p->ier & UART_IER_THRI) {
|
|
|
|
p->ier &= ~UART_IER_THRI;
|
|
|
|
serial_out(p, UART_IER, p->ier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-31 17:12:14 +08:00
|
|
|
static void serial8250_stop_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-30 01:41:51 +08:00
|
|
|
__stop_tx(up);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2005-06-30 01:41:51 +08:00
|
|
|
* We really want to stop the transmitter from sending.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_16C950) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->acr |= UART_ACR_TXDIS;
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-31 17:12:14 +08:00
|
|
|
static void serial8250_start_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-01-10 17:25:11 +08:00
|
|
|
if (up->dma && !serial8250_tx_dma(up)) {
|
|
|
|
return;
|
|
|
|
} else if (!(up->ier & UART_IER_THRI)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->ier |= UART_IER_THRI;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, up->ier);
|
2005-06-23 22:05:41 +08:00
|
|
|
|
2005-06-24 05:26:43 +08:00
|
|
|
if (up->bugs & UART_BUG_TXEN) {
|
2009-11-18 18:08:11 +08:00
|
|
|
unsigned char lsr;
|
2005-06-23 22:05:41 +08:00
|
|
|
lsr = serial_in(up, UART_LSR);
|
2007-08-23 05:01:18 +08:00
|
|
|
up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
|
2012-12-18 18:41:14 +08:00
|
|
|
if (lsr & UART_LSR_TEMT)
|
2011-12-05 07:42:20 +08:00
|
|
|
serial8250_tx_chars(up);
|
2005-06-23 22:05:41 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-06-30 01:41:51 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-06-30 01:41:51 +08:00
|
|
|
* Re-enable the transmitter if we disabled it.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->acr &= ~UART_ACR_TXDIS;
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_stop_rx(struct uart_port *port)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
up->ier &= ~UART_IER_RLSI;
|
|
|
|
up->port.read_status_mask &= ~UART_LSR_DR;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, up->ier);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_enable_ms(struct uart_port *port)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-06 17:07:03 +08:00
|
|
|
/* no MSR capabilities */
|
|
|
|
if (up->bugs & UART_BUG_NOMSR)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
up->ier |= UART_IER_MSI;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, up->ier);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:42:19 +08:00
|
|
|
/*
|
2011-12-05 07:42:20 +08:00
|
|
|
* serial8250_rx_chars: processes according to the passed in LSR
|
2011-12-05 07:42:19 +08:00
|
|
|
* value, and returns the remaining LSR bits not handled
|
|
|
|
* by this Rx routine.
|
|
|
|
*/
|
2011-12-05 07:42:20 +08:00
|
|
|
unsigned char
|
|
|
|
serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2011-12-05 07:42:19 +08:00
|
|
|
unsigned char ch;
|
2005-04-17 06:20:36 +08:00
|
|
|
int max_count = 256;
|
|
|
|
char flag;
|
|
|
|
|
|
|
|
do {
|
2008-07-24 12:29:45 +08:00
|
|
|
if (likely(lsr & UART_LSR_DR))
|
2012-03-09 08:12:08 +08:00
|
|
|
ch = serial_in(up, UART_RX);
|
2008-07-24 12:29:45 +08:00
|
|
|
else
|
|
|
|
/*
|
|
|
|
* Intel 82571 has a Serial Over Lan device that will
|
|
|
|
* set UART_LSR_BI without setting UART_LSR_DR when
|
|
|
|
* it receives a break. To avoid reading from the
|
|
|
|
* receive buffer without UART_LSR_DR bit set, we
|
|
|
|
* just force the read character to be 0
|
|
|
|
*/
|
|
|
|
ch = 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
flag = TTY_NORMAL;
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.rx++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-08-23 05:01:18 +08:00
|
|
|
lsr |= up->lsr_saved_flags;
|
|
|
|
up->lsr_saved_flags = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-08-23 05:01:18 +08:00
|
|
|
if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lsr & UART_LSR_BI) {
|
|
|
|
lsr &= ~(UART_LSR_FE | UART_LSR_PE);
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.brk++;
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We do the SysRQ and SAK checking
|
|
|
|
* here because otherwise the break
|
|
|
|
* may get masked by ignore_status_mask
|
|
|
|
* or read_status_mask.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (uart_handle_break(port))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto ignore_char;
|
|
|
|
} else if (lsr & UART_LSR_PE)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.parity++;
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (lsr & UART_LSR_FE)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.frame++;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lsr & UART_LSR_OE)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.overrun++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2005-04-17 06:26:39 +08:00
|
|
|
* Mask off conditions which should be ignored.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
lsr &= port->read_status_mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (lsr & UART_LSR_BI) {
|
|
|
|
DEBUG_INTR("handling break....");
|
|
|
|
flag = TTY_BREAK;
|
|
|
|
} else if (lsr & UART_LSR_PE)
|
|
|
|
flag = TTY_PARITY;
|
|
|
|
else if (lsr & UART_LSR_FE)
|
|
|
|
flag = TTY_FRAME;
|
|
|
|
}
|
2012-03-09 08:12:11 +08:00
|
|
|
if (uart_handle_sysrq_char(port, ch))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto ignore_char;
|
2005-05-10 06:21:59 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
uart_insert_char(port, lsr, UART_LSR_OE, ch, flag);
|
2005-05-10 06:21:59 +08:00
|
|
|
|
2008-02-08 20:18:52 +08:00
|
|
|
ignore_char:
|
2012-03-09 08:12:08 +08:00
|
|
|
lsr = serial_in(up, UART_LSR);
|
2008-07-24 12:29:45 +08:00
|
|
|
} while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_unlock(&port->lock);
|
2013-01-03 22:53:06 +08:00
|
|
|
tty_flip_buffer_push(&port->state->port);
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock(&port->lock);
|
2011-12-05 07:42:19 +08:00
|
|
|
return lsr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-12-05 07:42:20 +08:00
|
|
|
EXPORT_SYMBOL_GPL(serial8250_rx_chars);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-05 07:42:20 +08:00
|
|
|
void serial8250_tx_chars(struct uart_8250_port *up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
|
|
|
struct circ_buf *xmit = &port->state->xmit;
|
2005-04-17 06:20:36 +08:00
|
|
|
int count;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->x_char) {
|
|
|
|
serial_out(up, UART_TX, port->x_char);
|
|
|
|
port->icount.tx++;
|
|
|
|
port->x_char = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-03-09 08:12:11 +08:00
|
|
|
if (uart_tx_stopped(port)) {
|
|
|
|
serial8250_stop_tx(port);
|
2005-08-31 17:12:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (uart_circ_empty(xmit)) {
|
2005-06-30 01:41:51 +08:00
|
|
|
__stop_tx(up);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = up->tx_loadsz;
|
|
|
|
do {
|
|
|
|
serial_out(up, UART_TX, xmit->buf[xmit->tail]);
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.tx++;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (uart_circ_empty(xmit))
|
|
|
|
break;
|
2013-01-18 06:14:53 +08:00
|
|
|
if (up->capabilities & UART_CAP_HFIFO) {
|
|
|
|
if ((serial_port_in(port, UART_LSR) & BOTH_EMPTY) !=
|
|
|
|
BOTH_EMPTY)
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
} while (--count > 0);
|
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
2012-03-09 08:12:11 +08:00
|
|
|
uart_write_wakeup(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
DEBUG_INTR("THRE...");
|
|
|
|
|
|
|
|
if (uart_circ_empty(xmit))
|
2005-06-30 01:41:51 +08:00
|
|
|
__stop_tx(up);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-12-05 07:42:20 +08:00
|
|
|
EXPORT_SYMBOL_GPL(serial8250_tx_chars);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-03 05:39:20 +08:00
|
|
|
/* Caller holds uart port lock */
|
2011-12-05 07:42:20 +08:00
|
|
|
unsigned int serial8250_modem_status(struct uart_8250_port *up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2006-01-05 00:55:09 +08:00
|
|
|
unsigned int status = serial_in(up, UART_MSR);
|
|
|
|
|
2007-08-23 05:01:18 +08:00
|
|
|
status |= up->msr_saved_flags;
|
|
|
|
up->msr_saved_flags = 0;
|
2007-04-24 05:41:00 +08:00
|
|
|
if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI &&
|
2012-03-09 08:12:11 +08:00
|
|
|
port->state != NULL) {
|
2006-01-05 00:55:09 +08:00
|
|
|
if (status & UART_MSR_TERI)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.rng++;
|
2006-01-05 00:55:09 +08:00
|
|
|
if (status & UART_MSR_DDSR)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->icount.dsr++;
|
2006-01-05 00:55:09 +08:00
|
|
|
if (status & UART_MSR_DDCD)
|
2012-03-09 08:12:11 +08:00
|
|
|
uart_handle_dcd_change(port, status & UART_MSR_DCD);
|
2006-01-05 00:55:09 +08:00
|
|
|
if (status & UART_MSR_DCTS)
|
2012-03-09 08:12:11 +08:00
|
|
|
uart_handle_cts_change(port, status & UART_MSR_CTS);
|
2006-01-05 00:55:09 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
wake_up_interruptible(&port->state->port.delta_msr_wait);
|
2006-01-05 00:55:09 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-05 00:55:09 +08:00
|
|
|
return status;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-12-05 07:42:20 +08:00
|
|
|
EXPORT_SYMBOL_GPL(serial8250_modem_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This handles the interrupt from one port.
|
|
|
|
*/
|
2011-12-05 07:42:22 +08:00
|
|
|
int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-12-05 07:42:19 +08:00
|
|
|
unsigned char status;
|
2007-04-24 05:41:21 +08:00
|
|
|
unsigned long flags;
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2013-01-10 17:25:11 +08:00
|
|
|
int dma_err = 0;
|
2011-12-05 07:42:22 +08:00
|
|
|
|
|
|
|
if (iir & UART_IIR_NO_INT)
|
|
|
|
return 0;
|
2006-01-05 03:19:06 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2006-01-05 03:19:06 +08:00
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
status = serial_port_in(port, UART_LSR);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
DEBUG_INTR("status = %x...", status);
|
|
|
|
|
2013-01-10 17:25:11 +08:00
|
|
|
if (status & (UART_LSR_DR | UART_LSR_BI)) {
|
|
|
|
if (up->dma)
|
|
|
|
dma_err = serial8250_rx_dma(up, iir);
|
|
|
|
|
|
|
|
if (!up->dma || dma_err)
|
|
|
|
status = serial8250_rx_chars(up, status);
|
|
|
|
}
|
2011-12-05 07:42:20 +08:00
|
|
|
serial8250_modem_status(up);
|
2014-04-24 17:38:56 +08:00
|
|
|
if (!up->dma && (status & UART_LSR_THRE))
|
2011-12-05 07:42:20 +08:00
|
|
|
serial8250_tx_chars(up);
|
2006-01-05 03:19:06 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2011-12-05 07:42:22 +08:00
|
|
|
return 1;
|
2011-08-15 17:17:52 +08:00
|
|
|
}
|
2011-08-27 02:04:49 +08:00
|
|
|
EXPORT_SYMBOL_GPL(serial8250_handle_irq);
|
2011-08-15 17:17:52 +08:00
|
|
|
|
|
|
|
static int serial8250_default_handle_irq(struct uart_port *port)
|
|
|
|
{
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
unsigned int iir = serial_port_in(port, UART_IIR);
|
2011-08-15 17:17:52 +08:00
|
|
|
|
|
|
|
return serial8250_handle_irq(port, iir);
|
|
|
|
}
|
|
|
|
|
2012-11-19 23:12:04 +08:00
|
|
|
/*
|
|
|
|
* These Exar UARTs have an extra interrupt indicator that could
|
|
|
|
* fire for a few unimplemented interrupts. One of which is a
|
|
|
|
* wakeup event when coming out of sleep. Put this here just
|
|
|
|
* to be on the safe side that these interrupts don't go unhandled.
|
|
|
|
*/
|
|
|
|
static int exar_handle_irq(struct uart_port *port)
|
|
|
|
{
|
|
|
|
unsigned char int0, int1, int2, int3;
|
|
|
|
unsigned int iir = serial_port_in(port, UART_IIR);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = serial8250_handle_irq(port, iir);
|
|
|
|
|
2012-11-21 23:40:49 +08:00
|
|
|
if ((port->type == PORT_XR17V35X) ||
|
|
|
|
(port->type == PORT_XR17D15X)) {
|
2012-11-19 23:12:04 +08:00
|
|
|
int0 = serial_port_in(port, 0x80);
|
|
|
|
int1 = serial_port_in(port, 0x81);
|
|
|
|
int2 = serial_port_in(port, 0x82);
|
|
|
|
int3 = serial_port_in(port, 0x83);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* This is the serial driver's interrupt routine.
|
|
|
|
*
|
|
|
|
* Arjan thinks the old way was overly complex, so it got simplified.
|
|
|
|
* Alan disagrees, saying that need the complexity to handle the weird
|
|
|
|
* nature of ISA shared interrupts. (This is a special exception.)
|
|
|
|
*
|
|
|
|
* In order to handle ISA shared interrupts properly, we need to check
|
|
|
|
* that all ports have been serviced, and therefore the ISA interrupt
|
|
|
|
* line has been de-asserted.
|
|
|
|
*
|
|
|
|
* This means we need to loop through all ports. checking that they
|
|
|
|
* don't have an interrupt pending.
|
|
|
|
*/
|
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
|
|
|
static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct irq_info *i = dev_id;
|
|
|
|
struct list_head *l, *end = NULL;
|
|
|
|
int pass_counter = 0, handled = 0;
|
|
|
|
|
|
|
|
DEBUG_INTR("serial8250_interrupt(%d)...", irq);
|
|
|
|
|
|
|
|
spin_lock(&i->lock);
|
|
|
|
|
|
|
|
l = i->head;
|
|
|
|
do {
|
|
|
|
struct uart_8250_port *up;
|
2011-08-15 17:17:52 +08:00
|
|
|
struct uart_port *port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
up = list_entry(l, struct uart_8250_port, list);
|
2011-08-15 17:17:52 +08:00
|
|
|
port = &up->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-04-07 02:49:44 +08:00
|
|
|
if (port->handle_irq(port)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
handled = 1;
|
|
|
|
end = NULL;
|
|
|
|
} else if (end == NULL)
|
|
|
|
end = l;
|
|
|
|
|
|
|
|
l = l->next;
|
|
|
|
|
|
|
|
if (l == i->head && pass_counter++ > PASS_LIMIT) {
|
|
|
|
/* If we hit this, we're dead. */
|
2010-10-21 07:00:48 +08:00
|
|
|
printk_ratelimited(KERN_ERR
|
|
|
|
"serial8250: too much work for irq%d\n", irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (l != end);
|
|
|
|
|
|
|
|
spin_unlock(&i->lock);
|
|
|
|
|
|
|
|
DEBUG_INTR("end.\n");
|
|
|
|
|
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To support ISA shared interrupts, we need to have one interrupt
|
|
|
|
* handler that ensures that the IRQ line has been deasserted
|
|
|
|
* before returning. Failing to do this will result in the IRQ
|
|
|
|
* line being stuck active, and, since ISA irqs are edge triggered,
|
|
|
|
* no more IRQs will be seen.
|
|
|
|
*/
|
|
|
|
static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
spin_lock_irq(&i->lock);
|
|
|
|
|
|
|
|
if (!list_empty(i->head)) {
|
|
|
|
if (i->head == &up->list)
|
|
|
|
i->head = i->head->next;
|
|
|
|
list_del(&up->list);
|
|
|
|
} else {
|
|
|
|
BUG_ON(i->head != &up->list);
|
|
|
|
i->head = NULL;
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&i->lock);
|
2008-08-20 11:49:40 +08:00
|
|
|
/* List empty so throw away the hash node */
|
|
|
|
if (i->head == NULL) {
|
|
|
|
hlist_del(&i->node);
|
|
|
|
kfree(i);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int serial_link_irq_chain(struct uart_8250_port *up)
|
|
|
|
{
|
2008-08-20 11:49:40 +08:00
|
|
|
struct hlist_head *h;
|
|
|
|
struct hlist_node *n;
|
|
|
|
struct irq_info *i;
|
2006-07-02 10:29:43 +08:00
|
|
|
int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-20 11:49:40 +08:00
|
|
|
mutex_lock(&hash_mutex);
|
|
|
|
|
|
|
|
h = &irq_lists[up->port.irq % NR_IRQ_HASH];
|
|
|
|
|
|
|
|
hlist_for_each(n, h) {
|
|
|
|
i = hlist_entry(n, struct irq_info, node);
|
|
|
|
if (i->irq == up->port.irq)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == NULL) {
|
|
|
|
i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
|
|
|
|
if (i == NULL) {
|
|
|
|
mutex_unlock(&hash_mutex);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
spin_lock_init(&i->lock);
|
|
|
|
i->irq = up->port.irq;
|
|
|
|
hlist_add_head(&i->node, h);
|
|
|
|
}
|
|
|
|
mutex_unlock(&hash_mutex);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irq(&i->lock);
|
|
|
|
|
|
|
|
if (i->head) {
|
|
|
|
list_add(&up->list, i->head);
|
|
|
|
spin_unlock_irq(&i->lock);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
INIT_LIST_HEAD(&up->list);
|
|
|
|
i->head = &up->list;
|
|
|
|
spin_unlock_irq(&i->lock);
|
2009-09-20 04:13:19 +08:00
|
|
|
irq_flags |= up->port.irqflags;
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = request_irq(up->port.irq, serial8250_interrupt,
|
|
|
|
irq_flags, "serial", i);
|
|
|
|
if (ret < 0)
|
|
|
|
serial_do_unlink(i, up);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serial_unlink_irq_chain(struct uart_8250_port *up)
|
|
|
|
{
|
2014-02-20 04:00:13 +08:00
|
|
|
/*
|
|
|
|
* yes, some broken gcc emit "warning: 'i' may be used uninitialized"
|
|
|
|
* but no, we are not going to take a patch that assigns NULL below.
|
|
|
|
*/
|
2008-08-20 11:49:40 +08:00
|
|
|
struct irq_info *i;
|
|
|
|
struct hlist_node *n;
|
|
|
|
struct hlist_head *h;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-20 11:49:40 +08:00
|
|
|
mutex_lock(&hash_mutex);
|
|
|
|
|
|
|
|
h = &irq_lists[up->port.irq % NR_IRQ_HASH];
|
|
|
|
|
|
|
|
hlist_for_each(n, h) {
|
|
|
|
i = hlist_entry(n, struct irq_info, node);
|
|
|
|
if (i->irq == up->port.irq)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
BUG_ON(n == NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
BUG_ON(i->head == NULL);
|
|
|
|
|
|
|
|
if (list_empty(i->head))
|
|
|
|
free_irq(up->port.irq, i);
|
|
|
|
|
|
|
|
serial_do_unlink(i, up);
|
2008-08-20 11:49:40 +08:00
|
|
|
mutex_unlock(&hash_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is used to handle ports that do not have an
|
|
|
|
* interrupt. This doesn't work very well for 16450's, but gives
|
|
|
|
* barely passable results for a 16550A. (Although at the expense
|
|
|
|
* of much CPU overhead).
|
|
|
|
*/
|
|
|
|
static void serial8250_timeout(unsigned long data)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *up = (struct uart_8250_port *)data;
|
|
|
|
|
2011-12-05 07:42:21 +08:00
|
|
|
up->port.handle_irq(&up->port);
|
2010-10-01 21:21:25 +08:00
|
|
|
mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port));
|
2007-02-14 16:33:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_backup_timeout(unsigned long data)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *up = (struct uart_8250_port *)data;
|
2007-08-23 05:01:18 +08:00
|
|
|
unsigned int iir, ier = 0, lsr;
|
|
|
|
unsigned long flags;
|
2007-02-14 16:33:04 +08:00
|
|
|
|
2011-07-26 04:19:52 +08:00
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
2007-02-14 16:33:04 +08:00
|
|
|
/*
|
|
|
|
* Must disable interrupts or else we risk racing with the interrupt
|
|
|
|
* based handler.
|
|
|
|
*/
|
2012-01-27 01:44:09 +08:00
|
|
|
if (up->port.irq) {
|
2007-02-14 16:33:04 +08:00
|
|
|
ier = serial_in(up, UART_IER);
|
|
|
|
serial_out(up, UART_IER, 0);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-14 16:33:04 +08:00
|
|
|
iir = serial_in(up, UART_IIR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This should be a safe test for anyone who doesn't trust the
|
|
|
|
* IIR bits on their UART, but it's specifically designed for
|
|
|
|
* the "Diva" UART used on the management processor on many HP
|
|
|
|
* ia64 and parisc boxes.
|
|
|
|
*/
|
2007-08-23 05:01:18 +08:00
|
|
|
lsr = serial_in(up, UART_LSR);
|
|
|
|
up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
|
2007-02-14 16:33:04 +08:00
|
|
|
if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) &&
|
2009-09-20 04:13:28 +08:00
|
|
|
(!uart_circ_empty(&up->port.state->xmit) || up->port.x_char) &&
|
2007-08-23 05:01:18 +08:00
|
|
|
(lsr & UART_LSR_THRE)) {
|
2007-02-14 16:33:04 +08:00
|
|
|
iir &= ~(UART_IIR_ID | UART_IIR_NO_INT);
|
|
|
|
iir |= UART_IIR_THRI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(iir & UART_IIR_NO_INT))
|
2011-12-05 07:42:20 +08:00
|
|
|
serial8250_tx_chars(up);
|
2007-02-14 16:33:04 +08:00
|
|
|
|
2012-01-27 01:44:09 +08:00
|
|
|
if (up->port.irq)
|
2007-02-14 16:33:04 +08:00
|
|
|
serial_out(up, UART_IER, ier);
|
|
|
|
|
2011-07-26 04:19:52 +08:00
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
|
2007-02-14 16:33:04 +08:00
|
|
|
/* Standard timer interval plus 0.2s to keep the port running */
|
2008-02-08 20:18:52 +08:00
|
|
|
mod_timer(&up->timer,
|
2010-10-01 21:21:25 +08:00
|
|
|
jiffies + uart_poll_timeout(&up->port) + HZ / 5);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int serial8250_tx_empty(struct uart_port *port)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
2007-08-23 05:01:18 +08:00
|
|
|
unsigned int lsr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
lsr = serial_port_in(port, UART_LSR);
|
2007-08-23 05:01:18 +08:00
|
|
|
up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-12-10 04:31:34 +08:00
|
|
|
return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int serial8250_get_mctrl(struct uart_port *port)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2006-01-05 00:55:09 +08:00
|
|
|
unsigned int status;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int ret;
|
|
|
|
|
2011-12-05 07:42:20 +08:00
|
|
|
status = serial8250_modem_status(up);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
if (status & UART_MSR_DCD)
|
|
|
|
ret |= TIOCM_CAR;
|
|
|
|
if (status & UART_MSR_RI)
|
|
|
|
ret |= TIOCM_RNG;
|
|
|
|
if (status & UART_MSR_DSR)
|
|
|
|
ret |= TIOCM_DSR;
|
|
|
|
if (status & UART_MSR_CTS)
|
|
|
|
ret |= TIOCM_CTS;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char mcr = 0;
|
|
|
|
|
|
|
|
if (mctrl & TIOCM_RTS)
|
|
|
|
mcr |= UART_MCR_RTS;
|
|
|
|
if (mctrl & TIOCM_DTR)
|
|
|
|
mcr |= UART_MCR_DTR;
|
|
|
|
if (mctrl & TIOCM_OUT1)
|
|
|
|
mcr |= UART_MCR_OUT1;
|
|
|
|
if (mctrl & TIOCM_OUT2)
|
|
|
|
mcr |= UART_MCR_OUT2;
|
|
|
|
if (mctrl & TIOCM_LOOP)
|
|
|
|
mcr |= UART_MCR_LOOP;
|
|
|
|
|
|
|
|
mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr;
|
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_MCR, mcr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_break_ctl(struct uart_port *port, int break_state)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (break_state == -1)
|
|
|
|
up->lcr |= UART_LCR_SBC;
|
|
|
|
else
|
|
|
|
up->lcr &= ~UART_LCR_SBC;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, up->lcr);
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-14 16:33:04 +08:00
|
|
|
/*
|
|
|
|
* Wait for transmitter & holding register to empty
|
|
|
|
*/
|
2008-10-13 17:36:21 +08:00
|
|
|
static void wait_for_xmitr(struct uart_8250_port *up, int bits)
|
2007-02-14 16:33:04 +08:00
|
|
|
{
|
|
|
|
unsigned int status, tmout = 10000;
|
|
|
|
|
|
|
|
/* Wait up to 10ms for the character(s) to be sent. */
|
2010-10-06 02:40:07 +08:00
|
|
|
for (;;) {
|
2007-02-14 16:33:04 +08:00
|
|
|
status = serial_in(up, UART_LSR);
|
|
|
|
|
2007-08-23 05:01:18 +08:00
|
|
|
up->lsr_saved_flags |= status & LSR_SAVE_FLAGS;
|
2007-02-14 16:33:04 +08:00
|
|
|
|
2010-10-06 02:40:07 +08:00
|
|
|
if ((status & bits) == bits)
|
|
|
|
break;
|
2007-02-14 16:33:04 +08:00
|
|
|
if (--tmout == 0)
|
|
|
|
break;
|
|
|
|
udelay(1);
|
2010-10-06 02:40:07 +08:00
|
|
|
}
|
2007-02-14 16:33:04 +08:00
|
|
|
|
|
|
|
/* Wait up to 1s for flow control if necessary */
|
|
|
|
if (up->port.flags & UPF_CONS_FLOW) {
|
2007-08-23 05:01:18 +08:00
|
|
|
unsigned int tmout;
|
|
|
|
for (tmout = 1000000; tmout; tmout--) {
|
|
|
|
unsigned int msr = serial_in(up, UART_MSR);
|
|
|
|
up->msr_saved_flags |= msr & MSR_SAVE_FLAGS;
|
|
|
|
if (msr & UART_MSR_CTS)
|
|
|
|
break;
|
2007-02-14 16:33:04 +08:00
|
|
|
udelay(1);
|
|
|
|
touch_nmi_watchdog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-18 02:05:37 +08:00
|
|
|
#ifdef CONFIG_CONSOLE_POLL
|
|
|
|
/*
|
|
|
|
* Console polling routines for writing and reading from the uart while
|
|
|
|
* in an interrupt or debug context.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int serial8250_get_poll_char(struct uart_port *port)
|
|
|
|
{
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
unsigned char lsr = serial_port_in(port, UART_LSR);
|
2008-04-18 02:05:37 +08:00
|
|
|
|
2010-05-21 10:04:22 +08:00
|
|
|
if (!(lsr & UART_LSR_DR))
|
|
|
|
return NO_POLL_CHAR;
|
2008-04-18 02:05:37 +08:00
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
return serial_port_in(port, UART_RX);
|
2008-04-18 02:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void serial8250_put_poll_char(struct uart_port *port,
|
|
|
|
unsigned char c)
|
|
|
|
{
|
|
|
|
unsigned int ier;
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2008-04-18 02:05:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First save the IER then disable the interrupts
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
ier = serial_port_in(port, UART_IER);
|
2008-04-18 02:05:37 +08:00
|
|
|
if (up->capabilities & UART_CAP_UUE)
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, UART_IER_UUE);
|
2008-04-18 02:05:37 +08:00
|
|
|
else
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, 0);
|
2008-04-18 02:05:37 +08:00
|
|
|
|
|
|
|
wait_for_xmitr(up, BOTH_EMPTY);
|
|
|
|
/*
|
|
|
|
* Send the character out.
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_TX, c);
|
2008-04-18 02:05:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, wait for transmitter to become empty
|
|
|
|
* and restore the IER
|
|
|
|
*/
|
|
|
|
wait_for_xmitr(up, BOTH_EMPTY);
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, ier);
|
2008-04-18 02:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_CONSOLE_POLL */
|
|
|
|
|
2014-09-06 03:02:37 +08:00
|
|
|
int serial8250_do_startup(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
2005-06-23 22:05:41 +08:00
|
|
|
unsigned char lsr, iir;
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval;
|
|
|
|
|
2012-09-08 02:06:24 +08:00
|
|
|
if (port->type == PORT_8250_CIR)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2013-01-10 17:25:05 +08:00
|
|
|
if (!port->fifosize)
|
|
|
|
port->fifosize = uart_config[port->type].fifo_size;
|
|
|
|
if (!up->tx_loadsz)
|
|
|
|
up->tx_loadsz = uart_config[port->type].tx_loadsz;
|
|
|
|
if (!up->capabilities)
|
|
|
|
up->capabilities = uart_config[port->type].flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
up->mcr = 0;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->iotype != up->cur_iotype)
|
2009-05-28 21:01:35 +08:00
|
|
|
set_io_from_upio(port);
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_16C950) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Wake up and initialize UART */
|
|
|
|
up->acr = 0;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
|
|
|
|
serial_port_out(port, UART_EFR, UART_EFR_ECB);
|
|
|
|
serial_port_out(port, UART_IER, 0);
|
|
|
|
serial_port_out(port, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
|
|
|
|
serial_port_out(port, UART_EFR, UART_EFR_ECB);
|
|
|
|
serial_port_out(port, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
/*
|
|
|
|
* If this is an RSA port, see if we can kick it up to the
|
|
|
|
* higher speed clock.
|
|
|
|
*/
|
|
|
|
enable_rsa(up);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the FIFO buffers and disable them.
|
2006-03-28 17:56:53 +08:00
|
|
|
* (they will be reenabled in set_termios())
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
serial8250_clear_fifos(up);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the interrupt registers.
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_in(port, UART_LSR);
|
|
|
|
serial_port_in(port, UART_RX);
|
|
|
|
serial_port_in(port, UART_IIR);
|
|
|
|
serial_port_in(port, UART_MSR);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, there's no way the LSR could still be 0xff;
|
|
|
|
* if it is, then bail out, because there's likely no UART
|
|
|
|
* here.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!(port->flags & UPF_BUGGY_UART) &&
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
(serial_port_in(port, UART_LSR) == 0xff)) {
|
2011-09-26 21:14:34 +08:00
|
|
|
printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n",
|
2012-03-09 08:12:11 +08:00
|
|
|
serial_index(port));
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For a XR16C850, we need to set the trigger levels
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_16850) {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char fctr;
|
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:08 +08:00
|
|
|
fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_FCTR,
|
|
|
|
fctr | UART_FCTR_TRGD | UART_FCTR_RX);
|
|
|
|
serial_port_out(port, UART_TRG, UART_TRG_96);
|
|
|
|
serial_port_out(port, UART_FCTR,
|
|
|
|
fctr | UART_FCTR_TRGD | UART_FCTR_TX);
|
|
|
|
serial_port_out(port, UART_TRG, UART_TRG_96);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->irq) {
|
2008-04-28 17:14:09 +08:00
|
|
|
unsigned char iir1;
|
2007-02-14 16:33:04 +08:00
|
|
|
/*
|
|
|
|
* Test for UARTs that do not reassert THRE when the
|
|
|
|
* transmitter is idle and the interrupt has already
|
|
|
|
* been cleared. Real 16550s should always reassert
|
|
|
|
* this interrupt whenever the transmitter is idle and
|
|
|
|
* the interrupt is enabled. Delays are necessary to
|
|
|
|
* allow register changes to become visible.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2009-09-20 04:13:19 +08:00
|
|
|
if (up->port.irqflags & IRQF_SHARED)
|
2012-03-09 08:12:11 +08:00
|
|
|
disable_irq_nosync(port->irq);
|
2007-02-14 16:33:04 +08:00
|
|
|
|
|
|
|
wait_for_xmitr(up, UART_LSR_THRE);
|
2012-03-09 08:12:14 +08:00
|
|
|
serial_port_out_sync(port, UART_IER, UART_IER_THRI);
|
2007-02-14 16:33:04 +08:00
|
|
|
udelay(1); /* allow THRE to set */
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
iir1 = serial_port_in(port, UART_IIR);
|
|
|
|
serial_port_out(port, UART_IER, 0);
|
2012-03-09 08:12:14 +08:00
|
|
|
serial_port_out_sync(port, UART_IER, UART_IER_THRI);
|
2007-02-14 16:33:04 +08:00
|
|
|
udelay(1); /* allow a working UART time to re-assert THRE */
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
iir = serial_port_in(port, UART_IIR);
|
|
|
|
serial_port_out(port, UART_IER, 0);
|
2007-02-14 16:33:04 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->irqflags & IRQF_SHARED)
|
|
|
|
enable_irq(port->irq);
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2007-02-14 16:33:04 +08:00
|
|
|
|
|
|
|
/*
|
2012-04-07 02:49:50 +08:00
|
|
|
* If the interrupt is not reasserted, or we otherwise
|
|
|
|
* don't trust the iir, setup a timer to kick the UART
|
|
|
|
* on a regular basis.
|
2007-02-14 16:33:04 +08:00
|
|
|
*/
|
2012-04-07 02:49:50 +08:00
|
|
|
if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) ||
|
|
|
|
up->port.flags & UPF_BUG_THRE) {
|
2008-09-03 05:35:44 +08:00
|
|
|
up->bugs |= UART_BUG_THRE;
|
2008-10-13 17:45:26 +08:00
|
|
|
pr_debug("ttyS%d - using backup timer\n",
|
|
|
|
serial_index(port));
|
2007-02-14 16:33:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-03 05:35:44 +08:00
|
|
|
/*
|
|
|
|
* The above check will only give an accurate result the first time
|
|
|
|
* the port is opened so this value needs to be preserved.
|
|
|
|
*/
|
|
|
|
if (up->bugs & UART_BUG_THRE) {
|
|
|
|
up->timer.function = serial8250_backup_timeout;
|
|
|
|
up->timer.data = (unsigned long)up;
|
|
|
|
mod_timer(&up->timer, jiffies +
|
2010-10-01 21:21:25 +08:00
|
|
|
uart_poll_timeout(port) + HZ / 5);
|
2008-09-03 05:35:44 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* If the "interrupt" for this port doesn't correspond with any
|
|
|
|
* hardware interrupt, we use a timer-based system. The original
|
|
|
|
* driver used to do this with IRQ0.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!port->irq) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->timer.data = (unsigned long)up;
|
2010-10-01 21:21:25 +08:00
|
|
|
mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
retval = serial_link_irq_chain(up);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, initialize the UART
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (up->port.flags & UPF_FOURPORT) {
|
2012-01-27 01:44:09 +08:00
|
|
|
if (!up->port.irq)
|
2005-04-17 06:20:36 +08:00
|
|
|
up->port.mctrl |= TIOCM_OUT1;
|
|
|
|
} else
|
|
|
|
/*
|
|
|
|
* Most PC uarts need OUT2 raised to enable interrupts.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->irq)
|
2005-04-17 06:20:36 +08:00
|
|
|
up->port.mctrl |= TIOCM_OUT2;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
serial8250_set_mctrl(port, port->mctrl);
|
2005-06-23 22:05:41 +08:00
|
|
|
|
8250: fix boot hang with serial console when using with Serial Over Lan port
Intel 8257x Ethernet boards have a feature called Serial Over Lan.
This feature works by emulating a serial port, and it is detected by
kernel as a normal 8250 port. However, this emulation is not perfect, as
also noticed on changeset 7500b1f602aad75901774a67a687ee985d85893f.
Before this patch, the kernel were trying to check if the serial TX is
capable of work using IRQ's.
This were done with a code similar this:
serial_outp(up, UART_IER, UART_IER_THRI);
lsr = serial_in(up, UART_LSR);
iir = serial_in(up, UART_IIR);
serial_outp(up, UART_IER, 0);
if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT)
up->bugs |= UART_BUG_TXEN;
This works fine for other 8250 ports, but, on 8250-emulated SoL port, the
chip is a little lazy to down UART_IIR_NO_INT at UART_IIR register.
Due to that, UART_BUG_TXEN is sometimes enabled. However, as TX IRQ keeps
working, and the TX polling is now enabled, the driver miss-interprets the
IRQ received later, hanging up the machine until a key is pressed at the
serial console.
This is the 6 version of this patch. Previous versions were trying to
introduce a large enough delay between serial_outp and serial_in(up,
UART_IIR), but not taking forever. However, the needed delay couldn't be
safely determined.
At the experimental tests, a delay of 1us solves most of the cases, but
still hangs sometimes. Increasing the delay to 5us was better, but still
doesn't solve. A very high delay of 50 ms seemed to work every time.
However, poking around with delays and pray for it to be enough doesn't
seem to be a good approach, even for a quirk.
So, instead of playing with random large arbitrary delays, let's just
disable UART_BUG_TXEN for all SoL ports.
[akpm@linux-foundation.org: fix warnings]
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-02-21 07:38:52 +08:00
|
|
|
/* Serial over Lan (SoL) hack:
|
|
|
|
Intel 8257x Gigabit ethernet chips have a
|
|
|
|
16550 emulation, to be used for Serial Over Lan.
|
|
|
|
Those chips take a longer time than a normal
|
|
|
|
serial device to signalize that a transmission
|
|
|
|
data was queued. Due to that, the above test generally
|
|
|
|
fails. One solution would be to delay the reading of
|
|
|
|
iir. However, this is not reliable, since the timeout
|
|
|
|
is variable. So, let's just don't test if we receive
|
|
|
|
TX irq. This way, we'll never enable UART_BUG_TXEN.
|
|
|
|
*/
|
2009-10-02 06:44:26 +08:00
|
|
|
if (skip_txen_test || up->port.flags & UPF_NO_TXEN_TEST)
|
8250: fix boot hang with serial console when using with Serial Over Lan port
Intel 8257x Ethernet boards have a feature called Serial Over Lan.
This feature works by emulating a serial port, and it is detected by
kernel as a normal 8250 port. However, this emulation is not perfect, as
also noticed on changeset 7500b1f602aad75901774a67a687ee985d85893f.
Before this patch, the kernel were trying to check if the serial TX is
capable of work using IRQ's.
This were done with a code similar this:
serial_outp(up, UART_IER, UART_IER_THRI);
lsr = serial_in(up, UART_LSR);
iir = serial_in(up, UART_IIR);
serial_outp(up, UART_IER, 0);
if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT)
up->bugs |= UART_BUG_TXEN;
This works fine for other 8250 ports, but, on 8250-emulated SoL port, the
chip is a little lazy to down UART_IIR_NO_INT at UART_IIR register.
Due to that, UART_BUG_TXEN is sometimes enabled. However, as TX IRQ keeps
working, and the TX polling is now enabled, the driver miss-interprets the
IRQ received later, hanging up the machine until a key is pressed at the
serial console.
This is the 6 version of this patch. Previous versions were trying to
introduce a large enough delay between serial_outp and serial_in(up,
UART_IIR), but not taking forever. However, the needed delay couldn't be
safely determined.
At the experimental tests, a delay of 1us solves most of the cases, but
still hangs sometimes. Increasing the delay to 5us was better, but still
doesn't solve. A very high delay of 50 ms seemed to work every time.
However, poking around with delays and pray for it to be enough doesn't
seem to be a good approach, even for a quirk.
So, instead of playing with random large arbitrary delays, let's just
disable UART_BUG_TXEN for all SoL ports.
[akpm@linux-foundation.org: fix warnings]
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-02-21 07:38:52 +08:00
|
|
|
goto dont_test_tx_en;
|
|
|
|
|
2005-06-23 22:05:41 +08:00
|
|
|
/*
|
|
|
|
* Do a quick test to see if we receive an
|
|
|
|
* interrupt when we enable the TX irq.
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, UART_IER_THRI);
|
|
|
|
lsr = serial_port_in(port, UART_LSR);
|
|
|
|
iir = serial_port_in(port, UART_IIR);
|
|
|
|
serial_port_out(port, UART_IER, 0);
|
2005-06-23 22:05:41 +08:00
|
|
|
|
|
|
|
if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
|
2005-06-24 05:26:43 +08:00
|
|
|
if (!(up->bugs & UART_BUG_TXEN)) {
|
|
|
|
up->bugs |= UART_BUG_TXEN;
|
2005-06-23 22:05:41 +08:00
|
|
|
pr_debug("ttyS%d - enabling bad tx status workarounds\n",
|
2008-10-13 17:45:26 +08:00
|
|
|
serial_index(port));
|
2005-06-23 22:05:41 +08:00
|
|
|
}
|
|
|
|
} else {
|
2005-06-24 05:26:43 +08:00
|
|
|
up->bugs &= ~UART_BUG_TXEN;
|
2005-06-23 22:05:41 +08:00
|
|
|
}
|
|
|
|
|
8250: fix boot hang with serial console when using with Serial Over Lan port
Intel 8257x Ethernet boards have a feature called Serial Over Lan.
This feature works by emulating a serial port, and it is detected by
kernel as a normal 8250 port. However, this emulation is not perfect, as
also noticed on changeset 7500b1f602aad75901774a67a687ee985d85893f.
Before this patch, the kernel were trying to check if the serial TX is
capable of work using IRQ's.
This were done with a code similar this:
serial_outp(up, UART_IER, UART_IER_THRI);
lsr = serial_in(up, UART_LSR);
iir = serial_in(up, UART_IIR);
serial_outp(up, UART_IER, 0);
if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT)
up->bugs |= UART_BUG_TXEN;
This works fine for other 8250 ports, but, on 8250-emulated SoL port, the
chip is a little lazy to down UART_IIR_NO_INT at UART_IIR register.
Due to that, UART_BUG_TXEN is sometimes enabled. However, as TX IRQ keeps
working, and the TX polling is now enabled, the driver miss-interprets the
IRQ received later, hanging up the machine until a key is pressed at the
serial console.
This is the 6 version of this patch. Previous versions were trying to
introduce a large enough delay between serial_outp and serial_in(up,
UART_IIR), but not taking forever. However, the needed delay couldn't be
safely determined.
At the experimental tests, a delay of 1us solves most of the cases, but
still hangs sometimes. Increasing the delay to 5us was better, but still
doesn't solve. A very high delay of 50 ms seemed to work every time.
However, poking around with delays and pray for it to be enough doesn't
seem to be a good approach, even for a quirk.
So, instead of playing with random large arbitrary delays, let's just
disable UART_BUG_TXEN for all SoL ports.
[akpm@linux-foundation.org: fix warnings]
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-02-21 07:38:52 +08:00
|
|
|
dont_test_tx_en:
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-08-23 05:01:18 +08:00
|
|
|
/*
|
|
|
|
* Clear the interrupt registers again for luck, and clear the
|
|
|
|
* saved flags to avoid getting false values from polling
|
|
|
|
* routines or the previous session.
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_in(port, UART_LSR);
|
|
|
|
serial_port_in(port, UART_RX);
|
|
|
|
serial_port_in(port, UART_IIR);
|
|
|
|
serial_port_in(port, UART_MSR);
|
2007-08-23 05:01:18 +08:00
|
|
|
up->lsr_saved_flags = 0;
|
|
|
|
up->msr_saved_flags = 0;
|
|
|
|
|
2013-01-10 17:25:11 +08:00
|
|
|
/*
|
|
|
|
* Request DMA channels for both RX and TX.
|
|
|
|
*/
|
|
|
|
if (up->dma) {
|
|
|
|
retval = serial8250_request_dma(up);
|
|
|
|
if (retval) {
|
|
|
|
pr_warn_ratelimited("ttyS%d - failed to request DMA\n",
|
|
|
|
serial_index(port));
|
|
|
|
up->dma = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Finally, enable interrupts. Note: Modem status interrupts
|
|
|
|
* are set via set_termios(), which will be occurring imminently
|
|
|
|
* anyway, so we don't enable them here.
|
|
|
|
*/
|
|
|
|
up->ier = UART_IER_RLSI | UART_IER_RDI;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, up->ier);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->flags & UPF_FOURPORT) {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int icp;
|
|
|
|
/*
|
|
|
|
* Enable interrupts on the AST Fourport board
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
icp = (port->iobase & 0xfe0) | 0x01f;
|
2005-04-17 06:20:36 +08:00
|
|
|
outb_p(0x80, icp);
|
2012-03-09 08:12:10 +08:00
|
|
|
inb_p(icp);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-06 03:02:37 +08:00
|
|
|
EXPORT_SYMBOL_GPL(serial8250_do_startup);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-06 03:02:37 +08:00
|
|
|
static int serial8250_startup(struct uart_port *port)
|
|
|
|
{
|
|
|
|
if (port->startup)
|
|
|
|
return port->startup(port);
|
|
|
|
return serial8250_do_startup(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial8250_do_shutdown(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable interrupts from this port
|
|
|
|
*/
|
|
|
|
up->ier = 0;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-01-10 17:25:11 +08:00
|
|
|
if (up->dma)
|
|
|
|
serial8250_release_dma(up);
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
if (port->flags & UPF_FOURPORT) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* reset interrupts on the AST Fourport board */
|
2012-03-09 08:12:11 +08:00
|
|
|
inb((port->iobase & 0xfe0) | 0x1f);
|
|
|
|
port->mctrl |= TIOCM_OUT1;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else
|
2012-03-09 08:12:11 +08:00
|
|
|
port->mctrl &= ~TIOCM_OUT2;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
serial8250_set_mctrl(port, port->mctrl);
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable break condition and FIFOs
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR,
|
|
|
|
serial_port_in(port, UART_LCR) & ~UART_LCR_SBC);
|
2005-04-17 06:20:36 +08:00
|
|
|
serial8250_clear_fifos(up);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
/*
|
|
|
|
* Reset the RSA board back to 115kbps compat mode.
|
|
|
|
*/
|
|
|
|
disable_rsa(up);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read data port to reset things, and then unlink from
|
|
|
|
* the IRQ chain.
|
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_in(port, UART_RX);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-14 16:33:04 +08:00
|
|
|
del_timer_sync(&up->timer);
|
|
|
|
up->timer.function = serial8250_timeout;
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->irq)
|
2005-04-17 06:20:36 +08:00
|
|
|
serial_unlink_irq_chain(up);
|
|
|
|
}
|
2014-09-06 03:02:37 +08:00
|
|
|
EXPORT_SYMBOL_GPL(serial8250_do_shutdown);
|
|
|
|
|
|
|
|
static void serial8250_shutdown(struct uart_port *port)
|
|
|
|
{
|
|
|
|
if (port->shutdown)
|
|
|
|
port->shutdown(port);
|
|
|
|
else
|
|
|
|
serial8250_do_shutdown(port);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
|
|
|
|
{
|
|
|
|
unsigned int quot;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle magic divisors for baud rates above baud_base on
|
|
|
|
* SMSC SuperIO chips.
|
|
|
|
*/
|
|
|
|
if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
|
|
|
|
baud == (port->uartclk/4))
|
|
|
|
quot = 0x8001;
|
|
|
|
else if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
|
|
|
|
baud == (port->uartclk/8))
|
|
|
|
quot = 0x8002;
|
|
|
|
else
|
|
|
|
quot = uart_get_divisor(port, baud);
|
|
|
|
|
|
|
|
return quot;
|
|
|
|
}
|
|
|
|
|
U6715 16550A serial driver support
UART Features extract from STEricsson U6715 data-sheet (arm926 SoC for mobile phone):
* Fully compatible with industry standard 16C550 and 16C450 from various
manufacturers
* RX and TX 64 byte FIFO reduces CPU interrupts
* Full double buffering
* Modem control signals include CTS, RTS, (and DSR, DTR on UART1 only)
* Automatic baud rate selection
* Manual or automatic RTS/CTS smart hardware flow control
* Programmable serial characteristics:
– Baud rate generation (50 to 3.25M baud)
– 5, 6, 7 or 8-bit characters
– Even, odd or no-parity bit generation and detection
– 1, 1.5 or 2 stop bit generation
* Independent control of transmit, receive, line status, data set interrupts and FIFOs
* Full status-reporting capabilities
* Separate DMA signaling for RX and TX
* Timed interrupt to spread receive interrupt on known duration
* DMA time-out interrupt to allow detection of end of reception
* Carkit pulse coding and decoding compliant with USB carkit control interface [40]
In 16550A auto-configuration, if the fifo size is 64 then it's an U6 16550A port
Add set_termios hook & export serial8250_do_set_termios to change uart
clock following baudrate
Signed-off-by: Philippe Langlais <philippe.langlais@stericsson.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-07-29 23:13:57 +08:00
|
|
|
void
|
|
|
|
serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
unsigned char cval;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned int baud, quot;
|
|
|
|
|
|
|
|
switch (termios->c_cflag & CSIZE) {
|
|
|
|
case CS5:
|
2005-06-25 02:48:22 +08:00
|
|
|
cval = UART_LCR_WLEN5;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CS6:
|
2005-06-25 02:48:22 +08:00
|
|
|
cval = UART_LCR_WLEN6;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case CS7:
|
2005-06-25 02:48:22 +08:00
|
|
|
cval = UART_LCR_WLEN7;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case CS8:
|
2005-06-25 02:48:22 +08:00
|
|
|
cval = UART_LCR_WLEN8;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (termios->c_cflag & CSTOPB)
|
2005-06-25 02:48:22 +08:00
|
|
|
cval |= UART_LCR_STOP;
|
2012-07-12 20:00:31 +08:00
|
|
|
if (termios->c_cflag & PARENB) {
|
2005-04-17 06:20:36 +08:00
|
|
|
cval |= UART_LCR_PARITY;
|
2012-07-12 20:00:31 +08:00
|
|
|
if (up->bugs & UART_BUG_PARITY)
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
up->fifo_bug = true;
|
2012-07-12 20:00:31 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(termios->c_cflag & PARODD))
|
|
|
|
cval |= UART_LCR_EPAR;
|
|
|
|
#ifdef CMSPAR
|
|
|
|
if (termios->c_cflag & CMSPAR)
|
|
|
|
cval |= UART_LCR_SPAR;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ask the core to calculate the divisor for us.
|
|
|
|
*/
|
8250: Now honours baud rate lower bounds
A platform clock drives 8250 ports in most SOC systems, the clock
might run at high frequencies, and so it's not always possible to
downscale uart clock to a desired value.
Currently the 8250 uart driver accepts not supported baud rates, and
what is worse, it is doing this silently, and then passes not accepted
values to a new termios, so userspace has no chance to catch this kind
of errors (userspace verifies that settings were accepted by reading
back and comparing the settings).
This patch fixes the issue by passing minimum baud rate to the
uart_get_baud_rate() call, the call should take care of all bounds,
so userspace should now report:
# stty -F /dev/ttyS0 speed 300
115200
stty: /dev/ttyS0: unable to perform all requested operations
p.s. uart_get_baud_rate() falls back to 9600, which still might be too
low for some 10 GHz platforms, but that's a separate issue, and
we can wait with fixing this till we find such a platform.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-09-20 04:13:20 +08:00
|
|
|
baud = uart_get_baud_rate(port, termios, old,
|
|
|
|
port->uartclk / 16 / 0xffff,
|
|
|
|
port->uartclk / 16);
|
2005-04-17 06:20:36 +08:00
|
|
|
quot = serial8250_get_divisor(port, baud);
|
|
|
|
|
|
|
|
/*
|
2005-06-23 17:43:04 +08:00
|
|
|
* Oxford Semi 952 rev B workaround
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-06-23 17:43:04 +08:00
|
|
|
if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0)
|
2008-02-05 14:27:53 +08:00
|
|
|
quot++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
/* NOTE: If fifo_bug is not set, a user can set RX_trigger. */
|
|
|
|
if ((baud < 2400 && !up->dma) || up->fifo_bug) {
|
|
|
|
up->fcr &= ~UART_FCR_TRIGGER_MASK;
|
|
|
|
up->fcr |= UART_FCR_TRIGGER_1;
|
2012-04-30 17:21:26 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MCR-based auto flow control. When AFE is enabled, RTS will be
|
|
|
|
* deasserted when the receive FIFO contains more characters than
|
|
|
|
* the trigger, or the MCR RTS bit is cleared. In the case where
|
|
|
|
* the remote UART is not using CTS auto flow control, we must
|
|
|
|
* have sufficient FIFO entries for the latency of the remote
|
2014-09-03 05:39:10 +08:00
|
|
|
* UART to respond. IOW, at least 32 bytes of FIFO.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2014-09-03 05:39:10 +08:00
|
|
|
if (up->capabilities & UART_CAP_AFE && port->fifosize >= 32) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->mcr &= ~UART_MCR_AFE;
|
|
|
|
if (termios->c_cflag & CRTSCTS)
|
|
|
|
up->mcr |= UART_MCR_AFE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, we're now changing the port state. Do it with
|
|
|
|
* interrupts disabled.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the per-port timeout.
|
|
|
|
*/
|
|
|
|
uart_update_timeout(port, termios->c_cflag, baud);
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (termios->c_iflag & INPCK)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
|
2014-06-16 20:10:41 +08:00
|
|
|
if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
|
2012-03-09 08:12:11 +08:00
|
|
|
port->read_status_mask |= UART_LSR_BI;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Characteres to ignore
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
port->ignore_status_mask = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (termios->c_iflag & IGNPAR)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (termios->c_iflag & IGNBRK) {
|
2012-03-09 08:12:11 +08:00
|
|
|
port->ignore_status_mask |= UART_LSR_BI;
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* If we're ignoring parity and break indicators,
|
|
|
|
* ignore overruns too (for real raw support).
|
|
|
|
*/
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->ignore_status_mask |= UART_LSR_OE;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ignore all characters if CREAD is not set
|
|
|
|
*/
|
|
|
|
if ((termios->c_cflag & CREAD) == 0)
|
2012-03-09 08:12:11 +08:00
|
|
|
port->ignore_status_mask |= UART_LSR_DR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CTS flow control flag and modem status interrupts
|
|
|
|
*/
|
2010-11-13 23:21:58 +08:00
|
|
|
up->ier &= ~UART_IER_MSI;
|
2005-11-06 17:07:03 +08:00
|
|
|
if (!(up->bugs & UART_BUG_NOMSR) &&
|
|
|
|
UART_ENABLE_MS(&up->port, termios->c_cflag))
|
2005-04-17 06:20:36 +08:00
|
|
|
up->ier |= UART_IER_MSI;
|
|
|
|
if (up->capabilities & UART_CAP_UUE)
|
2011-05-18 06:12:36 +08:00
|
|
|
up->ier |= UART_IER_UUE;
|
|
|
|
if (up->capabilities & UART_CAP_RTOIE)
|
|
|
|
up->ier |= UART_IER_RTOIE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, up->ier);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (up->capabilities & UART_CAP_EFR) {
|
|
|
|
unsigned char efr = 0;
|
|
|
|
/*
|
|
|
|
* TI16C752/Startech hardware flow control. FIXME:
|
|
|
|
* - TI16C752 requires control thresholds to be set.
|
|
|
|
* - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
|
|
|
|
*/
|
|
|
|
if (termios->c_cflag & CRTSCTS)
|
|
|
|
efr |= UART_EFR_CTS;
|
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->flags & UPF_EXAR_EFR)
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_XR_EFR, efr);
|
2011-09-03 04:55:37 +08:00
|
|
|
else
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_EFR, efr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-08-15 14:05:32 +08:00
|
|
|
/* Workaround to enable 115200 baud on OMAP1510 internal ports */
|
2012-10-04 06:31:58 +08:00
|
|
|
if (is_omap1510_8250(up)) {
|
2006-08-15 14:05:32 +08:00
|
|
|
if (baud == 115200) {
|
|
|
|
quot = 1;
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1);
|
2006-08-15 14:05:32 +08:00
|
|
|
} else
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0);
|
2006-08-15 14:05:32 +08:00
|
|
|
}
|
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
/*
|
|
|
|
* For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2,
|
|
|
|
* otherwise just set DLAB
|
|
|
|
*/
|
|
|
|
if (up->capabilities & UART_NATSEMI)
|
|
|
|
serial_port_out(port, UART_LCR, 0xe0);
|
|
|
|
else
|
|
|
|
serial_port_out(port, UART_LCR, cval | UART_LCR_DLAB);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-04-30 18:20:56 +08:00
|
|
|
serial_dl_write(up, quot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-12 08:30:01 +08:00
|
|
|
/*
|
|
|
|
* XR17V35x UARTs have an extra fractional divisor register (DLD)
|
|
|
|
*
|
|
|
|
* We need to recalculate all of the registers, because DLM and DLL
|
|
|
|
* are already rounded to a whole integer.
|
|
|
|
*
|
|
|
|
* When recalculating we use a 32x clock instead of a 16x clock to
|
|
|
|
* allow 1-bit for rounding in the fractional part.
|
|
|
|
*/
|
|
|
|
if (up->port.type == PORT_XR17V35X) {
|
|
|
|
unsigned int baud_x32 = (port->uartclk * 2) / baud;
|
|
|
|
u16 quot = baud_x32 / 32;
|
|
|
|
u8 quot_frac = DIV_ROUND_CLOSEST(baud_x32 % 32, 2);
|
|
|
|
|
|
|
|
serial_dl_write(up, quot);
|
|
|
|
serial_port_out(port, 0x2, quot_frac & 0xf);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
|
|
|
|
* is written without DLAB set, this mode will be disabled.
|
|
|
|
*/
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_16750)
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
serial_port_out(port, UART_FCR, up->fcr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, cval); /* reset DLAB */
|
2005-04-17 06:20:36 +08:00
|
|
|
up->lcr = cval; /* Save LCR */
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type != PORT_16750) {
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
/* emulated UARTs (Lucent Venus 167x) need two steps */
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
if (up->fcr & UART_FCR_ENABLE_FIFO)
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
serial_port_out(port, UART_FCR, up->fcr); /* set fcr */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2012-03-09 08:12:11 +08:00
|
|
|
serial8250_set_mctrl(port, port->mctrl);
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2008-04-28 17:14:06 +08:00
|
|
|
/* Don't rewrite B0 */
|
|
|
|
if (tty_termios_baud_rate(termios))
|
|
|
|
tty_termios_encode_baud_rate(termios, baud, baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
U6715 16550A serial driver support
UART Features extract from STEricsson U6715 data-sheet (arm926 SoC for mobile phone):
* Fully compatible with industry standard 16C550 and 16C450 from various
manufacturers
* RX and TX 64 byte FIFO reduces CPU interrupts
* Full double buffering
* Modem control signals include CTS, RTS, (and DSR, DTR on UART1 only)
* Automatic baud rate selection
* Manual or automatic RTS/CTS smart hardware flow control
* Programmable serial characteristics:
– Baud rate generation (50 to 3.25M baud)
– 5, 6, 7 or 8-bit characters
– Even, odd or no-parity bit generation and detection
– 1, 1.5 or 2 stop bit generation
* Independent control of transmit, receive, line status, data set interrupts and FIFOs
* Full status-reporting capabilities
* Separate DMA signaling for RX and TX
* Timed interrupt to spread receive interrupt on known duration
* DMA time-out interrupt to allow detection of end of reception
* Carkit pulse coding and decoding compliant with USB carkit control interface [40]
In 16550A auto-configuration, if the fifo size is 64 then it's an U6 16550A port
Add set_termios hook & export serial8250_do_set_termios to change uart
clock following baudrate
Signed-off-by: Philippe Langlais <philippe.langlais@stericsson.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-07-29 23:13:57 +08:00
|
|
|
EXPORT_SYMBOL(serial8250_do_set_termios);
|
|
|
|
|
|
|
|
static void
|
|
|
|
serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
|
|
|
{
|
|
|
|
if (port->set_termios)
|
|
|
|
port->set_termios(port, termios, old);
|
|
|
|
else
|
|
|
|
serial8250_do_set_termios(port, termios, old);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-03-11 07:23:48 +08:00
|
|
|
static void
|
2010-06-02 04:53:11 +08:00
|
|
|
serial8250_set_ldisc(struct uart_port *port, int new)
|
2010-03-11 07:23:48 +08:00
|
|
|
{
|
2010-06-02 04:53:11 +08:00
|
|
|
if (new == N_PPS) {
|
2010-03-11 07:23:48 +08:00
|
|
|
port->flags |= UPF_HARDPPS_CD;
|
|
|
|
serial8250_enable_ms(port);
|
|
|
|
} else
|
|
|
|
port->flags &= ~UPF_HARDPPS_CD;
|
|
|
|
}
|
|
|
|
|
2010-09-25 21:13:45 +08:00
|
|
|
|
|
|
|
void serial8250_do_pm(struct uart_port *port, unsigned int state,
|
|
|
|
unsigned int oldstate)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *p = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
serial8250_set_sleep(p, state != 0);
|
2010-09-25 21:13:45 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(serial8250_do_pm);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-25 21:13:45 +08:00
|
|
|
static void
|
|
|
|
serial8250_pm(struct uart_port *port, unsigned int state,
|
|
|
|
unsigned int oldstate)
|
|
|
|
{
|
|
|
|
if (port->pm)
|
|
|
|
port->pm(port, state, oldstate);
|
|
|
|
else
|
|
|
|
serial8250_do_pm(port, state, oldstate);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-02 04:47:59 +08:00
|
|
|
static unsigned int serial8250_port_size(struct uart_8250_port *pt)
|
|
|
|
{
|
|
|
|
if (pt->port.iotype == UPIO_AU)
|
2009-10-29 04:37:28 +08:00
|
|
|
return 0x1000;
|
2012-10-04 06:31:58 +08:00
|
|
|
if (is_omap1_8250(pt))
|
2008-09-02 04:47:59 +08:00
|
|
|
return 0x16 << pt->port.regshift;
|
2012-10-04 06:31:58 +08:00
|
|
|
|
2008-09-02 04:47:59 +08:00
|
|
|
return 8 << pt->port.regshift;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Resource handling.
|
|
|
|
*/
|
|
|
|
static int serial8250_request_std_resource(struct uart_8250_port *up)
|
|
|
|
{
|
2008-09-02 04:47:59 +08:00
|
|
|
unsigned int size = serial8250_port_size(up);
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
switch (port->iotype) {
|
2006-04-30 18:15:58 +08:00
|
|
|
case UPIO_AU:
|
2006-09-10 02:23:56 +08:00
|
|
|
case UPIO_TSI:
|
|
|
|
case UPIO_MEM32:
|
2005-04-17 06:20:36 +08:00
|
|
|
case UPIO_MEM:
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!port->mapbase)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!request_mem_region(port->mapbase, size, "serial")) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->flags & UPF_IOREMAP) {
|
|
|
|
port->membase = ioremap_nocache(port->mapbase, size);
|
|
|
|
if (!port->membase) {
|
|
|
|
release_mem_region(port->mapbase, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UPIO_HUB6:
|
|
|
|
case UPIO_PORT:
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!request_region(port->iobase, size, "serial"))
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_release_std_resource(struct uart_8250_port *up)
|
|
|
|
{
|
2008-09-02 04:47:59 +08:00
|
|
|
unsigned int size = serial8250_port_size(up);
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
switch (port->iotype) {
|
2006-04-30 18:15:58 +08:00
|
|
|
case UPIO_AU:
|
2006-09-10 02:23:56 +08:00
|
|
|
case UPIO_TSI:
|
|
|
|
case UPIO_MEM32:
|
2005-04-17 06:20:36 +08:00
|
|
|
case UPIO_MEM:
|
2012-03-09 08:12:11 +08:00
|
|
|
if (!port->mapbase)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->flags & UPF_IOREMAP) {
|
|
|
|
iounmap(port->membase);
|
|
|
|
port->membase = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
release_mem_region(port->mapbase, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPIO_HUB6:
|
|
|
|
case UPIO_PORT:
|
2012-03-09 08:12:11 +08:00
|
|
|
release_region(port->iobase, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serial8250_request_rsa_resource(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned long start = UART_RSA_BASE << up->port.regshift;
|
|
|
|
unsigned int size = 8 << up->port.regshift;
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2006-09-10 02:23:56 +08:00
|
|
|
int ret = -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
switch (port->iotype) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case UPIO_HUB6:
|
|
|
|
case UPIO_PORT:
|
2012-03-09 08:12:11 +08:00
|
|
|
start += port->iobase;
|
2006-09-10 02:23:56 +08:00
|
|
|
if (request_region(start, size, "serial-rsa"))
|
|
|
|
ret = 0;
|
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_release_rsa_resource(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
unsigned long offset = UART_RSA_BASE << up->port.regshift;
|
|
|
|
unsigned int size = 8 << up->port.regshift;
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
switch (port->iotype) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case UPIO_HUB6:
|
|
|
|
case UPIO_PORT:
|
2012-03-09 08:12:11 +08:00
|
|
|
release_region(port->iobase + offset, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serial8250_release_port(struct uart_port *port)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
serial8250_release_std_resource(up);
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_RSA)
|
2005-04-17 06:20:36 +08:00
|
|
|
serial8250_release_rsa_resource(up);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serial8250_request_port(struct uart_port *port)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2012-09-08 02:06:24 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (port->type == PORT_8250_CIR)
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ret = serial8250_request_std_resource(up);
|
2012-03-09 08:12:11 +08:00
|
|
|
if (ret == 0 && port->type == PORT_RSA) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = serial8250_request_rsa_resource(up);
|
|
|
|
if (ret < 0)
|
|
|
|
serial8250_release_std_resource(up);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
static int fcr_get_rxtrig_bytes(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
const struct serial8250_config *conf_type = &uart_config[up->port.type];
|
|
|
|
unsigned char bytes;
|
|
|
|
|
|
|
|
bytes = conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(up->fcr)];
|
|
|
|
|
|
|
|
return bytes ? bytes : -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bytes_to_fcr_rxtrig(struct uart_8250_port *up, unsigned char bytes)
|
|
|
|
{
|
|
|
|
const struct serial8250_config *conf_type = &uart_config[up->port.type];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)])
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
for (i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) {
|
|
|
|
if (bytes < conf_type->rxtrig_bytes[i])
|
|
|
|
/* Use the nearest lower value */
|
|
|
|
return (--i) << UART_FCR_R_TRIG_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UART_FCR_R_TRIG_11;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_get_rxtrig(struct tty_port *port)
|
|
|
|
{
|
|
|
|
struct uart_state *state = container_of(port, struct uart_state, port);
|
|
|
|
struct uart_port *uport = state->uart_port;
|
|
|
|
struct uart_8250_port *up =
|
|
|
|
container_of(uport, struct uart_8250_port, port);
|
|
|
|
|
|
|
|
if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return fcr_get_rxtrig_bytes(up);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_serial8250_get_rxtrig(struct tty_port *port)
|
|
|
|
{
|
|
|
|
int rxtrig_bytes;
|
|
|
|
|
|
|
|
mutex_lock(&port->mutex);
|
|
|
|
rxtrig_bytes = do_get_rxtrig(port);
|
|
|
|
mutex_unlock(&port->mutex);
|
|
|
|
|
|
|
|
return rxtrig_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t serial8250_get_attr_rx_trig_bytes(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct tty_port *port = dev_get_drvdata(dev);
|
|
|
|
int rxtrig_bytes;
|
|
|
|
|
|
|
|
rxtrig_bytes = do_serial8250_get_rxtrig(port);
|
|
|
|
if (rxtrig_bytes < 0)
|
|
|
|
return rxtrig_bytes;
|
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", rxtrig_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_set_rxtrig(struct tty_port *port, unsigned char bytes)
|
|
|
|
{
|
|
|
|
struct uart_state *state = container_of(port, struct uart_state, port);
|
|
|
|
struct uart_port *uport = state->uart_port;
|
|
|
|
struct uart_8250_port *up =
|
|
|
|
container_of(uport, struct uart_8250_port, port);
|
|
|
|
int rxtrig;
|
|
|
|
|
|
|
|
if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1 ||
|
|
|
|
up->fifo_bug)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
rxtrig = bytes_to_fcr_rxtrig(up, bytes);
|
|
|
|
if (rxtrig < 0)
|
|
|
|
return rxtrig;
|
|
|
|
|
|
|
|
serial8250_clear_fifos(up);
|
|
|
|
up->fcr &= ~UART_FCR_TRIGGER_MASK;
|
|
|
|
up->fcr |= (unsigned char)rxtrig;
|
|
|
|
serial_out(up, UART_FCR, up->fcr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_serial8250_set_rxtrig(struct tty_port *port, unsigned char bytes)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&port->mutex);
|
|
|
|
ret = do_set_rxtrig(port, bytes);
|
|
|
|
mutex_unlock(&port->mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t serial8250_set_attr_rx_trig_bytes(struct device *dev,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct tty_port *port = dev_get_drvdata(dev);
|
|
|
|
unsigned char bytes;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ret = kstrtou8(buf, 10, &bytes);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = do_serial8250_set_rxtrig(port, bytes);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(rx_trig_bytes, S_IRUSR | S_IWUSR | S_IRGRP,
|
|
|
|
serial8250_get_attr_rx_trig_bytes,
|
|
|
|
serial8250_set_attr_rx_trig_bytes);
|
|
|
|
|
|
|
|
static struct attribute *serial8250_dev_attrs[] = {
|
|
|
|
&dev_attr_rx_trig_bytes.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group serial8250_dev_attr_group = {
|
|
|
|
.attrs = serial8250_dev_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_dev_spec_attr_grp(struct uart_8250_port *up)
|
|
|
|
{
|
|
|
|
const struct serial8250_config *conf_type = &uart_config[up->port.type];
|
|
|
|
|
|
|
|
if (conf_type->rxtrig_bytes[0])
|
|
|
|
up->port.attr_group = &serial8250_dev_attr_group;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void serial8250_config_port(struct uart_port *port, int flags)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
int probeflags = PROBE_ANY;
|
|
|
|
int ret;
|
|
|
|
|
2012-09-08 02:06:24 +08:00
|
|
|
if (port->type == PORT_8250_CIR)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Find the region that we can probe for. This in turn
|
|
|
|
* tells us whether we can probe for the type of port.
|
|
|
|
*/
|
|
|
|
ret = serial8250_request_std_resource(up);
|
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = serial8250_request_rsa_resource(up);
|
|
|
|
if (ret < 0)
|
|
|
|
probeflags &= ~PROBE_RSA;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->iotype != up->cur_iotype)
|
2009-05-28 21:01:35 +08:00
|
|
|
set_io_from_upio(port);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (flags & UART_CONFIG_TYPE)
|
|
|
|
autoconfig(up, probeflags);
|
2009-10-29 04:37:28 +08:00
|
|
|
|
|
|
|
/* if access method is AU, it is a 16550 with a quirk */
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_16550A && port->iotype == UPIO_AU)
|
2009-10-29 04:37:28 +08:00
|
|
|
up->bugs |= UART_BUG_NOMSR;
|
|
|
|
|
serial: 8250: enable UART_BUG_NOMSR for Tegra
Tegra chips have 4 or 5 identical UART modules embedded. UARTs C..E have
their MODEM-control signals tied off to a static state. However UARTs A
and B can optionally route those signals to/from package pins, depending
on the exact pinmux configuration.
When these signals are not routed to package pins, false interrupts may
trigger either temporarily, or permanently, all while not showing up in
the IIR; it will read as NO_INT. This will eventually lead to the UART
IRQ being disabled due to unhandled interrupts. When this happens, the
kernel may print e.g.:
irq 68: nobody cared (try booting with the "irqpoll" option)
In order to prevent this, enable UART_BUG_NOMSR. This prevents
UART_IER_MSI from being enabled, which prevents the false interrupts
from triggering.
In practice, this is not needed under any of the following conditions:
* On Tegra chips after Tegra30, since the HW bug has apparently been
fixed.
* On UARTs C..E since their MODEM control signals are tied to the correct
static state which doesn't trigger the issue.
* On UARTs A..B if the MODEM control signals are routed out to package
pins, since they will then carry valid signals.
However, we ignore these exceptions for now, since they are only relevant
if a board actually hooks up more than a 4-wire UART, and no currently
supported board does this. If we ever support a board that does, we can
refine the algorithm that enables UART_BUG_NOMSR to take those exceptions
into account, and/or read a flag from DT/... that indicates that the
board has hooked up and pinmux'd more than a 4-wire UART.
Reported-by: Olof Johansson <olof@lixom.net> # autotester
Cc: <stable@vger.kernel.org>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-08 06:00:12 +08:00
|
|
|
/* HW bugs may trigger IRQ while IIR == NO_INT */
|
|
|
|
if (port->type == PORT_TEGRA)
|
|
|
|
up->bugs |= UART_BUG_NOMSR;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
|
2005-04-17 06:20:36 +08:00
|
|
|
autoconfig_irq(up);
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type != PORT_RSA && probeflags & PROBE_RSA)
|
2005-04-17 06:20:36 +08:00
|
|
|
serial8250_release_rsa_resource(up);
|
2012-03-09 08:12:11 +08:00
|
|
|
if (port->type == PORT_UNKNOWN)
|
2005-04-17 06:20:36 +08:00
|
|
|
serial8250_release_std_resource(up);
|
2012-11-19 23:12:04 +08:00
|
|
|
|
|
|
|
/* Fixme: probably not the best place for this */
|
2012-11-21 23:40:49 +08:00
|
|
|
if ((port->type == PORT_XR17V35X) ||
|
|
|
|
(port->type == PORT_XR17D15X))
|
2012-11-19 23:12:04 +08:00
|
|
|
port->handle_irq = exar_handle_irq;
|
serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers
Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX
interrupt should be triggered for each data.
According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.
This patch makes some devices change RX interrupt trigger from userland.
<How to use>
- Read current setting
# cat /sys/class/tty/ttyS0/rx_trig_bytes
8
- Write user setting
# echo 1 > /sys/class/tty/ttyS0/rx_trig_bytes
# cat /sys/class/tty/ttyS0/rx_trig_bytes
1
<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)
<Change log>
Changes in V9:
- Use attr_group instead of dev_spec_attr_group of uart_port structure
Changes in V8:
- Divide this patch from V7's patch based on Greg's comment
Changes in V7:
- Add Documentation
- Change I/F name from rx_int_trig to rx_trig_bytes because the name
rx_int_trig is hard to understand how users specify the value
Changes in V6:
- Move FCR_RX_TRIG_* definition in 8250.h to include/uapi/linux/serial_reg.h,
rename those to UART_FCR_R_TRIG_*, and use UART_FCR_TRIGGER_MASK to
UART_FCR_R_TRIG_BITS()
- Change following function names:
convert_fcr2val() => fcr_get_rxtrig_bytes()
convert_val2rxtrig() => bytes_to_fcr_rxtrig()
- Fix typo in serial8250_do_set_termios()
- Delete the verbose error message pr_info() in bytes_to_fcr_rxtrig()
- Rename *rx_int_trig/rx_trig* to *rxtrig* for several functions or variables
(but UI remains rx_int_trig)
- Change the meaningless variable name 'val' to 'bytes' following functions:
fcr_get_rxtrig_bytes(), bytes_to_fcr_rxtrig(), do_set_rxtrig(),
do_serial8250_set_rxtrig(), and serial8250_set_attr_rxtrig()
- Use up->fcr in order to get rxtrig_bytes instead of rx_trig_raw in
fcr_get_rxtrig_bytes()
- Use conf_type->rxtrig_bytes[0] instead of switch statement for support check
in register_dev_spec_attr_grp()
- Delete the checking whether a user changed FCR or not when minimum buffer
is needed in serial8250_do_set_termios()
Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition
Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[]
in convert_fcr2val() and convert_val2rxtrig()
Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled
for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and
at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at
convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()
Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)
Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-16 09:19:36 +08:00
|
|
|
|
|
|
|
register_dev_spec_attr_grp(up);
|
|
|
|
up->fcr = uart_config[up->port.type].fcr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|
|
|
{
|
2008-08-20 11:49:55 +08:00
|
|
|
if (ser->irq >= nr_irqs || ser->irq < 0 ||
|
2005-04-17 06:20:36 +08:00
|
|
|
ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
|
|
|
|
ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS ||
|
|
|
|
ser->type == PORT_STARTECH)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-05 17:45:59 +08:00
|
|
|
static int serial8250_ioctl(struct uart_port *port, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *up =
|
|
|
|
container_of(port, struct uart_8250_port, port);
|
|
|
|
int ret;
|
|
|
|
struct serial_rs485 rs485_config;
|
|
|
|
|
|
|
|
if (!up->rs485_config)
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TIOCSRS485:
|
|
|
|
if (copy_from_user(&rs485_config, (void __user *)arg,
|
|
|
|
sizeof(rs485_config)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
ret = up->rs485_config(up, &rs485_config);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
memcpy(&up->rs485, &rs485_config, sizeof(rs485_config));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
case TIOCGRS485:
|
|
|
|
if (copy_to_user((void __user *)arg, &up->rs485,
|
|
|
|
sizeof(up->rs485)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static const char *
|
|
|
|
serial8250_type(struct uart_port *port)
|
|
|
|
{
|
|
|
|
int type = port->type;
|
|
|
|
|
|
|
|
if (type >= ARRAY_SIZE(uart_config))
|
|
|
|
type = 0;
|
|
|
|
return uart_config[type].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct uart_ops serial8250_pops = {
|
|
|
|
.tx_empty = serial8250_tx_empty,
|
|
|
|
.set_mctrl = serial8250_set_mctrl,
|
|
|
|
.get_mctrl = serial8250_get_mctrl,
|
|
|
|
.stop_tx = serial8250_stop_tx,
|
|
|
|
.start_tx = serial8250_start_tx,
|
|
|
|
.stop_rx = serial8250_stop_rx,
|
|
|
|
.enable_ms = serial8250_enable_ms,
|
|
|
|
.break_ctl = serial8250_break_ctl,
|
|
|
|
.startup = serial8250_startup,
|
|
|
|
.shutdown = serial8250_shutdown,
|
|
|
|
.set_termios = serial8250_set_termios,
|
2010-03-11 07:23:48 +08:00
|
|
|
.set_ldisc = serial8250_set_ldisc,
|
2005-04-17 06:20:36 +08:00
|
|
|
.pm = serial8250_pm,
|
|
|
|
.type = serial8250_type,
|
|
|
|
.release_port = serial8250_release_port,
|
|
|
|
.request_port = serial8250_request_port,
|
|
|
|
.config_port = serial8250_config_port,
|
|
|
|
.verify_port = serial8250_verify_port,
|
2014-08-05 17:45:59 +08:00
|
|
|
.ioctl = serial8250_ioctl,
|
2008-04-18 02:05:37 +08:00
|
|
|
#ifdef CONFIG_CONSOLE_POLL
|
|
|
|
.poll_get_char = serial8250_get_poll_char,
|
|
|
|
.poll_put_char = serial8250_put_poll_char,
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct uart_8250_port serial8250_ports[UART_NR];
|
|
|
|
|
2014-09-06 03:02:36 +08:00
|
|
|
/**
|
|
|
|
* serial8250_get_port - retrieve struct uart_8250_port
|
|
|
|
* @line: serial line number
|
|
|
|
*
|
|
|
|
* This function retrieves struct uart_8250_port for the specific line.
|
|
|
|
* This struct *must* *not* be used to perform a 8250 or serial core operation
|
|
|
|
* which is not accessible otherwise. Its only purpose is to make the struct
|
|
|
|
* accessible to the runtime-pm callbacks for context suspend/restore.
|
|
|
|
* The lock assumption made here is none because runtime-pm suspend/resume
|
|
|
|
* callbacks should not be invoked if there is any operation performed on the
|
|
|
|
* port.
|
|
|
|
*/
|
|
|
|
struct uart_8250_port *serial8250_get_port(int line)
|
|
|
|
{
|
|
|
|
return &serial8250_ports[line];
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(serial8250_get_port);
|
|
|
|
|
2010-10-19 02:38:02 +08:00
|
|
|
static void (*serial8250_isa_config)(int port, struct uart_port *up,
|
|
|
|
unsigned short *capabilities);
|
|
|
|
|
|
|
|
void serial8250_set_isa_configurator(
|
|
|
|
void (*v)(int port, struct uart_port *up, unsigned short *capabilities))
|
|
|
|
{
|
|
|
|
serial8250_isa_config = v;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(serial8250_set_isa_configurator);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void __init serial8250_isa_init_ports(void)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *up;
|
|
|
|
static int first = 1;
|
2009-10-25 22:01:34 +08:00
|
|
|
int i, irqflag = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!first)
|
|
|
|
return;
|
|
|
|
first = 0;
|
|
|
|
|
2012-09-08 02:06:23 +08:00
|
|
|
if (nr_uarts > UART_NR)
|
|
|
|
nr_uarts = UART_NR;
|
|
|
|
|
2013-06-03 21:38:26 +08:00
|
|
|
for (i = 0; i < nr_uarts; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct uart_8250_port *up = &serial8250_ports[i];
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
port->line = i;
|
|
|
|
spin_lock_init(&port->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
init_timer(&up->timer);
|
|
|
|
up->timer.function = serial8250_timeout;
|
2012-09-08 02:06:23 +08:00
|
|
|
up->cur_iotype = 0xFF;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ALPHA_KLUDGE_MCR needs to be killed.
|
|
|
|
*/
|
|
|
|
up->mcr_mask = ~ALPHA_KLUDGE_MCR;
|
|
|
|
up->mcr_force = ALPHA_KLUDGE_MCR;
|
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
port->ops = &serial8250_pops;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-10-25 22:01:34 +08:00
|
|
|
if (share_irqs)
|
|
|
|
irqflag = IRQF_SHARED;
|
|
|
|
|
2005-07-01 05:41:22 +08:00
|
|
|
for (i = 0, up = serial8250_ports;
|
2006-01-08 07:18:19 +08:00
|
|
|
i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
|
2005-04-17 06:20:36 +08:00
|
|
|
i++, up++) {
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
|
|
|
|
|
|
|
port->iobase = old_serial_port[i].port;
|
|
|
|
port->irq = irq_canonicalize(old_serial_port[i].irq);
|
|
|
|
port->irqflags = old_serial_port[i].irqflags;
|
|
|
|
port->uartclk = old_serial_port[i].baud_base * 16;
|
|
|
|
port->flags = old_serial_port[i].flags;
|
|
|
|
port->hub6 = old_serial_port[i].hub6;
|
|
|
|
port->membase = old_serial_port[i].iomem_base;
|
|
|
|
port->iotype = old_serial_port[i].io_type;
|
|
|
|
port->regshift = old_serial_port[i].iomem_reg_shift;
|
|
|
|
set_io_from_upio(port);
|
|
|
|
port->irqflags |= irqflag;
|
2010-10-19 02:38:02 +08:00
|
|
|
if (serial8250_isa_config != NULL)
|
|
|
|
serial8250_isa_config(i, &up->port, &up->capabilities);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 04:31:29 +08:00
|
|
|
static void
|
|
|
|
serial8250_init_fixed_type_port(struct uart_8250_port *up, unsigned int type)
|
|
|
|
{
|
|
|
|
up->port.type = type;
|
2013-01-10 17:25:05 +08:00
|
|
|
if (!up->port.fifosize)
|
|
|
|
up->port.fifosize = uart_config[type].fifo_size;
|
|
|
|
if (!up->tx_loadsz)
|
|
|
|
up->tx_loadsz = uart_config[type].tx_loadsz;
|
|
|
|
if (!up->capabilities)
|
|
|
|
up->capabilities = uart_config[type].flags;
|
2009-12-10 04:31:29 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void __init
|
|
|
|
serial8250_register_ports(struct uart_driver *drv, struct device *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-05-28 21:01:35 +08:00
|
|
|
for (i = 0; i < nr_uarts; i++) {
|
|
|
|
struct uart_8250_port *up = &serial8250_ports[i];
|
|
|
|
|
2012-09-08 02:06:23 +08:00
|
|
|
if (up->port.dev)
|
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
up->port.dev = dev;
|
2009-12-10 04:31:29 +08:00
|
|
|
|
|
|
|
if (up->port.flags & UPF_FIXED_TYPE)
|
|
|
|
serial8250_init_fixed_type_port(up, up->port.type);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
uart_add_one_port(drv, &up->port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_CONSOLE
|
|
|
|
|
2006-03-21 04:00:09 +08:00
|
|
|
static void serial8250_console_putchar(struct uart_port *port, int ch)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(port);
|
2006-03-21 04:00:09 +08:00
|
|
|
|
|
|
|
wait_for_xmitr(up, UART_LSR_THRE);
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_TX, ch);
|
2006-03-21 04:00:09 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Print a string to the serial port trying not to disturb
|
|
|
|
* any possible real use of the port...
|
|
|
|
*
|
|
|
|
* The console_lock must be held when we get here.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
serial8250_console_write(struct console *co, const char *s, unsigned int count)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *up = &serial8250_ports[co->index];
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2006-05-02 23:04:29 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int ier;
|
2006-05-02 23:04:29 +08:00
|
|
|
int locked = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-07 16:59:13 +08:00
|
|
|
touch_nmi_watchdog();
|
|
|
|
|
2014-03-07 21:58:39 +08:00
|
|
|
if (port->sysrq || oops_in_progress)
|
|
|
|
locked = spin_trylock_irqsave(&port->lock, flags);
|
|
|
|
else
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2006-05-02 23:04:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2006-02-15 17:59:47 +08:00
|
|
|
* First save the IER then disable the interrupts
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
ier = serial_port_in(port, UART_IER);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (up->capabilities & UART_CAP_UUE)
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, UART_IER_UUE);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-09 08:12:11 +08:00
|
|
|
uart_console_write(port, s, count, serial8250_console_putchar);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, wait for transmitter to become empty
|
|
|
|
* and restore the IER
|
|
|
|
*/
|
2006-01-21 22:59:12 +08:00
|
|
|
wait_for_xmitr(up, BOTH_EMPTY);
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_IER, ier);
|
2006-05-02 23:04:29 +08:00
|
|
|
|
2007-08-23 05:01:18 +08:00
|
|
|
/*
|
|
|
|
* The receive handling will happen properly because the
|
|
|
|
* receive ready bit will still be set; it is not cleared
|
|
|
|
* on read. However, modem control will not, we must
|
|
|
|
* call it if we have saved something in the saved flags
|
|
|
|
* while processing with interrupts off.
|
|
|
|
*/
|
|
|
|
if (up->msr_saved_flags)
|
2011-12-05 07:42:20 +08:00
|
|
|
serial8250_modem_status(up);
|
2007-08-23 05:01:18 +08:00
|
|
|
|
2006-05-02 23:04:29 +08:00
|
|
|
if (locked)
|
2014-03-07 21:58:39 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-01-11 08:52:44 +08:00
|
|
|
static int __init serial8250_console_setup(struct console *co, char *options)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_port *port;
|
|
|
|
int baud = 9600;
|
|
|
|
int bits = 8;
|
|
|
|
int parity = 'n';
|
|
|
|
int flow = 'n';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether an invalid uart number has been specified, and
|
|
|
|
* if so, search for the first available port that does have
|
|
|
|
* console support.
|
|
|
|
*/
|
2013-06-03 21:38:26 +08:00
|
|
|
if (co->index >= nr_uarts)
|
2005-04-17 06:20:36 +08:00
|
|
|
co->index = 0;
|
|
|
|
port = &serial8250_ports[co->index].port;
|
|
|
|
if (!port->iobase && !port->membase)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (options)
|
|
|
|
uart_parse_options(options, &baud, &parity, &bits, &flow);
|
|
|
|
|
|
|
|
return uart_set_options(port, co, baud, parity, bits, flow);
|
|
|
|
}
|
|
|
|
|
2007-08-03 22:07:43 +08:00
|
|
|
static int serial8250_console_early_setup(void)
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 14:37:59 +08:00
|
|
|
{
|
|
|
|
return serial8250_find_port_for_earlycon();
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct console serial8250_console = {
|
|
|
|
.name = "ttyS",
|
|
|
|
.write = serial8250_console_write,
|
|
|
|
.device = uart_console_device,
|
|
|
|
.setup = serial8250_console_setup,
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 14:37:59 +08:00
|
|
|
.early_setup = serial8250_console_early_setup,
|
2010-11-16 04:11:12 +08:00
|
|
|
.flags = CON_PRINTBUFFER | CON_ANYTIME,
|
2005-04-17 06:20:36 +08:00
|
|
|
.index = -1,
|
|
|
|
.data = &serial8250_reg,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init serial8250_console_init(void)
|
|
|
|
{
|
|
|
|
serial8250_isa_init_ports();
|
|
|
|
register_console(&serial8250_console);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
console_initcall(serial8250_console_init);
|
|
|
|
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 14:37:59 +08:00
|
|
|
int serial8250_find_port(struct uart_port *p)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int line;
|
|
|
|
struct uart_port *port;
|
|
|
|
|
2013-06-03 21:38:26 +08:00
|
|
|
for (line = 0; line < nr_uarts; line++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
port = &serial8250_ports[line].port;
|
2006-01-05 02:13:03 +08:00
|
|
|
if (uart_match_port(p, port))
|
2005-04-17 06:20:36 +08:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SERIAL8250_CONSOLE &serial8250_console
|
|
|
|
#else
|
|
|
|
#define SERIAL8250_CONSOLE NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct uart_driver serial8250_reg = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.driver_name = "serial",
|
|
|
|
.dev_name = "ttyS",
|
|
|
|
.major = TTY_MAJOR,
|
|
|
|
.minor = 64,
|
|
|
|
.cons = SERIAL8250_CONSOLE,
|
|
|
|
};
|
|
|
|
|
2006-02-23 18:22:13 +08:00
|
|
|
/*
|
|
|
|
* early_serial_setup - early registration for 8250 ports
|
|
|
|
*
|
|
|
|
* Setup an 8250 port structure prior to console initialisation. Use
|
|
|
|
* after console initialisation will cause undefined behaviour.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int __init early_serial_setup(struct uart_port *port)
|
|
|
|
{
|
2009-01-02 21:49:41 +08:00
|
|
|
struct uart_port *p;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (port->line >= ARRAY_SIZE(serial8250_ports))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
serial8250_isa_init_ports();
|
2009-01-02 21:49:41 +08:00
|
|
|
p = &serial8250_ports[port->line].port;
|
|
|
|
p->iobase = port->iobase;
|
|
|
|
p->membase = port->membase;
|
|
|
|
p->irq = port->irq;
|
2009-09-20 04:13:19 +08:00
|
|
|
p->irqflags = port->irqflags;
|
2009-01-02 21:49:41 +08:00
|
|
|
p->uartclk = port->uartclk;
|
|
|
|
p->fifosize = port->fifosize;
|
|
|
|
p->regshift = port->regshift;
|
|
|
|
p->iotype = port->iotype;
|
|
|
|
p->flags = port->flags;
|
|
|
|
p->mapbase = port->mapbase;
|
|
|
|
p->private_data = port->private_data;
|
2009-01-14 05:51:07 +08:00
|
|
|
p->type = port->type;
|
|
|
|
p->line = port->line;
|
2009-01-02 21:49:47 +08:00
|
|
|
|
|
|
|
set_io_from_upio(p);
|
|
|
|
if (port->serial_in)
|
|
|
|
p->serial_in = port->serial_in;
|
|
|
|
if (port->serial_out)
|
|
|
|
p->serial_out = port->serial_out;
|
2011-08-15 17:17:52 +08:00
|
|
|
if (port->handle_irq)
|
|
|
|
p->handle_irq = port->handle_irq;
|
|
|
|
else
|
|
|
|
p->handle_irq = serial8250_default_handle_irq;
|
2009-01-02 21:49:47 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* serial8250_suspend_port - suspend one serial port
|
|
|
|
* @line: serial line number
|
|
|
|
*
|
|
|
|
* Suspend one serial port.
|
|
|
|
*/
|
|
|
|
void serial8250_suspend_port(int line)
|
|
|
|
{
|
|
|
|
uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* serial8250_resume_port - resume one serial port
|
|
|
|
* @line: serial line number
|
|
|
|
*
|
|
|
|
* Resume one serial port.
|
|
|
|
*/
|
|
|
|
void serial8250_resume_port(int line)
|
|
|
|
{
|
2007-05-17 14:27:39 +08:00
|
|
|
struct uart_8250_port *up = &serial8250_ports[line];
|
2012-03-09 08:12:11 +08:00
|
|
|
struct uart_port *port = &up->port;
|
2007-05-17 14:27:39 +08:00
|
|
|
|
|
|
|
if (up->capabilities & UART_NATSEMI) {
|
|
|
|
/* Ensure it's still in high speed mode */
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, 0xE0);
|
2007-05-17 14:27:39 +08:00
|
|
|
|
2011-02-09 11:35:18 +08:00
|
|
|
ns16550a_goto_highspeed(up);
|
2007-05-17 14:27:39 +08:00
|
|
|
|
serial: use serial_port_in/out vs serial_in/out in 8250
The serial_in and serial_out helpers are expecting to operate
on an 8250_port struct. These in turn go after the contained
normal port struct which actually has the actual in/out accessors.
But what is happening in some cases, is that a function is passed
in a port struct, and it runs container_of to get the 8250_port
struct, and then it uses serial_in/out helpers on that. But when
you do, it goes full circle, since it jumps back inside the 8250_port
to find the contained port struct (which we already knew!).
So, if we are operating in a scope where we know the struct port,
then use the serial_port_in/out helpers and avoid the bouncing
around. If we don't have the struct port handy, and it isn't
worth making a local for it, then just leave things as-is which
uses the serial_in/out helpers that will resolve the 8250_port
onto the struct port.
Mostly, gcc figures this out on its own -- so this doesn't bring to
the table any revolutionary runtime delta. However, it is somewhat
misleading to always hammer away on 8250 structs, when the actual
underlying property isn't at all 8250 specific -- and this change
makes that clear.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-09 08:12:13 +08:00
|
|
|
serial_port_out(port, UART_LCR, 0);
|
2012-03-09 08:12:11 +08:00
|
|
|
port->uartclk = 921600*16;
|
2007-05-17 14:27:39 +08:00
|
|
|
}
|
2012-03-09 08:12:11 +08:00
|
|
|
uart_resume_port(&serial8250_reg, port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a set of serial devices attached to a platform device. The
|
|
|
|
* list is terminated with a zero flags entry, which means we expect
|
|
|
|
* all entries to have at least UPF_BOOT_AUTOCONF set.
|
|
|
|
*/
|
2012-11-20 02:21:50 +08:00
|
|
|
static int serial8250_probe(struct platform_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-07-30 16:06:57 +08:00
|
|
|
struct plat_serial8250_port *p = dev_get_platdata(&dev->dev);
|
2012-07-12 19:59:50 +08:00
|
|
|
struct uart_8250_port uart;
|
2009-10-25 22:01:34 +08:00
|
|
|
int ret, i, irqflag = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-07-12 19:59:50 +08:00
|
|
|
memset(&uart, 0, sizeof(uart));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-10-25 22:01:34 +08:00
|
|
|
if (share_irqs)
|
|
|
|
irqflag = IRQF_SHARED;
|
|
|
|
|
2005-06-27 18:12:54 +08:00
|
|
|
for (i = 0; p && p->flags != 0; p++, i++) {
|
2012-07-12 19:59:50 +08:00
|
|
|
uart.port.iobase = p->iobase;
|
|
|
|
uart.port.membase = p->membase;
|
|
|
|
uart.port.irq = p->irq;
|
|
|
|
uart.port.irqflags = p->irqflags;
|
|
|
|
uart.port.uartclk = p->uartclk;
|
|
|
|
uart.port.regshift = p->regshift;
|
|
|
|
uart.port.iotype = p->iotype;
|
|
|
|
uart.port.flags = p->flags;
|
|
|
|
uart.port.mapbase = p->mapbase;
|
|
|
|
uart.port.hub6 = p->hub6;
|
|
|
|
uart.port.private_data = p->private_data;
|
|
|
|
uart.port.type = p->type;
|
|
|
|
uart.port.serial_in = p->serial_in;
|
|
|
|
uart.port.serial_out = p->serial_out;
|
|
|
|
uart.port.handle_irq = p->handle_irq;
|
|
|
|
uart.port.handle_break = p->handle_break;
|
|
|
|
uart.port.set_termios = p->set_termios;
|
|
|
|
uart.port.pm = p->pm;
|
|
|
|
uart.port.dev = &dev->dev;
|
|
|
|
uart.port.irqflags |= irqflag;
|
|
|
|
ret = serial8250_register_8250_port(&uart);
|
2005-06-27 18:12:54 +08:00
|
|
|
if (ret < 0) {
|
2005-11-10 06:32:44 +08:00
|
|
|
dev_err(&dev->dev, "unable to register port at index %d "
|
2007-07-24 09:43:44 +08:00
|
|
|
"(IO%lx MEM%llx IRQ%d): %d\n", i,
|
|
|
|
p->iobase, (unsigned long long)p->mapbase,
|
|
|
|
p->irq, ret);
|
2005-06-27 18:12:54 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove serial ports registered against a platform device.
|
|
|
|
*/
|
2012-11-20 02:26:18 +08:00
|
|
|
static int serial8250_remove(struct platform_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-06-03 21:38:26 +08:00
|
|
|
for (i = 0; i < nr_uarts; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct uart_8250_port *up = &serial8250_ports[i];
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
if (up->port.dev == &dev->dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
serial8250_unregister_port(i);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int serial8250_suspend(struct platform_device *dev, pm_message_t state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < UART_NR; i++) {
|
|
|
|
struct uart_8250_port *up = &serial8250_ports[i];
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
uart_suspend_port(&serial8250_reg, &up->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int serial8250_resume(struct platform_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < UART_NR; i++) {
|
|
|
|
struct uart_8250_port *up = &serial8250_ports[i];
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
|
2007-05-17 14:27:39 +08:00
|
|
|
serial8250_resume_port(i);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static struct platform_driver serial8250_isa_driver = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.probe = serial8250_probe,
|
2012-11-20 02:21:34 +08:00
|
|
|
.remove = serial8250_remove,
|
2005-04-17 06:20:36 +08:00
|
|
|
.suspend = serial8250_suspend,
|
|
|
|
.resume = serial8250_resume,
|
2005-11-10 06:32:44 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "serial8250",
|
2006-01-14 06:06:43 +08:00
|
|
|
.owner = THIS_MODULE,
|
2005-11-10 06:32:44 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This "device" covers _all_ ISA 8250-compatible serial devices listed
|
|
|
|
* in the table in include/asm/serial.h
|
|
|
|
*/
|
|
|
|
static struct platform_device *serial8250_isa_devs;
|
|
|
|
|
|
|
|
/*
|
2012-07-12 19:59:50 +08:00
|
|
|
* serial8250_register_8250_port and serial8250_unregister_port allows for
|
2005-04-17 06:20:36 +08:00
|
|
|
* 16x50 serial ports to be configured at run-time, to support PCMCIA
|
|
|
|
* modems and PCI multiport cards.
|
|
|
|
*/
|
2006-01-13 02:44:32 +08:00
|
|
|
static DEFINE_MUTEX(serial_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, find a port entry which matches.
|
|
|
|
*/
|
2013-06-03 21:38:26 +08:00
|
|
|
for (i = 0; i < nr_uarts; i++)
|
2005-04-17 06:20:36 +08:00
|
|
|
if (uart_match_port(&serial8250_ports[i].port, port))
|
|
|
|
return &serial8250_ports[i];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We didn't find a matching entry, so look for the first
|
|
|
|
* free entry. We look for one which hasn't been previously
|
|
|
|
* used (indicated by zero iobase).
|
|
|
|
*/
|
2013-06-03 21:38:26 +08:00
|
|
|
for (i = 0; i < nr_uarts; i++)
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serial8250_ports[i].port.type == PORT_UNKNOWN &&
|
|
|
|
serial8250_ports[i].port.iobase == 0)
|
|
|
|
return &serial8250_ports[i];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* That also failed. Last resort is to find any entry which
|
|
|
|
* doesn't have a real port associated with it.
|
|
|
|
*/
|
2013-06-03 21:38:26 +08:00
|
|
|
for (i = 0; i < nr_uarts; i++)
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serial8250_ports[i].port.type == PORT_UNKNOWN)
|
|
|
|
return &serial8250_ports[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-02 20:47:27 +08:00
|
|
|
* serial8250_register_8250_port - register a serial port
|
2012-06-09 09:51:23 +08:00
|
|
|
* @up: serial port template
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Configure the serial port specified by the request. If the
|
|
|
|
* port exists and is in use, it is hung up and unregistered
|
|
|
|
* first.
|
|
|
|
*
|
|
|
|
* The port is then probed and if necessary the IRQ is autodetected
|
|
|
|
* If this fails an error is returned.
|
|
|
|
*
|
|
|
|
* On success the port is ready to use and the line number is returned.
|
|
|
|
*/
|
2012-05-02 20:47:27 +08:00
|
|
|
int serial8250_register_8250_port(struct uart_8250_port *up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_8250_port *uart;
|
|
|
|
int ret = -ENOSPC;
|
|
|
|
|
2012-05-02 20:47:27 +08:00
|
|
|
if (up->port.uartclk == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2006-01-13 02:44:32 +08:00
|
|
|
mutex_lock(&serial_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-05-02 20:47:27 +08:00
|
|
|
uart = serial8250_find_match_or_unused(&up->port);
|
2012-09-08 02:06:24 +08:00
|
|
|
if (uart && uart->port.type != PORT_8250_CIR) {
|
2012-09-08 02:06:23 +08:00
|
|
|
if (uart->port.dev)
|
|
|
|
uart_remove_one_port(&serial8250_reg, &uart->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-05-02 20:47:27 +08:00
|
|
|
uart->port.iobase = up->port.iobase;
|
|
|
|
uart->port.membase = up->port.membase;
|
|
|
|
uart->port.irq = up->port.irq;
|
|
|
|
uart->port.irqflags = up->port.irqflags;
|
|
|
|
uart->port.uartclk = up->port.uartclk;
|
|
|
|
uart->port.fifosize = up->port.fifosize;
|
|
|
|
uart->port.regshift = up->port.regshift;
|
|
|
|
uart->port.iotype = up->port.iotype;
|
|
|
|
uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF;
|
2012-07-12 20:00:06 +08:00
|
|
|
uart->bugs = up->bugs;
|
2012-05-02 20:47:27 +08:00
|
|
|
uart->port.mapbase = up->port.mapbase;
|
|
|
|
uart->port.private_data = up->port.private_data;
|
2013-01-10 17:25:05 +08:00
|
|
|
uart->port.fifosize = up->port.fifosize;
|
|
|
|
uart->tx_loadsz = up->tx_loadsz;
|
|
|
|
uart->capabilities = up->capabilities;
|
2014-08-05 17:45:59 +08:00
|
|
|
uart->rs485_config = up->rs485_config;
|
|
|
|
uart->rs485 = up->rs485;
|
2013-01-10 17:25:05 +08:00
|
|
|
|
2013-03-25 19:34:44 +08:00
|
|
|
/* Take tx_loadsz from fifosize if it wasn't set separately */
|
|
|
|
if (uart->port.fifosize && !uart->tx_loadsz)
|
|
|
|
uart->tx_loadsz = uart->port.fifosize;
|
|
|
|
|
2012-05-02 20:47:27 +08:00
|
|
|
if (up->port.dev)
|
|
|
|
uart->port.dev = up->port.dev;
|
|
|
|
|
|
|
|
if (up->port.flags & UPF_FIXED_TYPE)
|
|
|
|
serial8250_init_fixed_type_port(uart, up->port.type);
|
2009-01-02 21:49:54 +08:00
|
|
|
|
2009-01-02 21:49:47 +08:00
|
|
|
set_io_from_upio(&uart->port);
|
|
|
|
/* Possibly override default I/O functions. */
|
2012-05-02 20:47:27 +08:00
|
|
|
if (up->port.serial_in)
|
|
|
|
uart->port.serial_in = up->port.serial_in;
|
|
|
|
if (up->port.serial_out)
|
|
|
|
uart->port.serial_out = up->port.serial_out;
|
|
|
|
if (up->port.handle_irq)
|
|
|
|
uart->port.handle_irq = up->port.handle_irq;
|
U6715 16550A serial driver support
UART Features extract from STEricsson U6715 data-sheet (arm926 SoC for mobile phone):
* Fully compatible with industry standard 16C550 and 16C450 from various
manufacturers
* RX and TX 64 byte FIFO reduces CPU interrupts
* Full double buffering
* Modem control signals include CTS, RTS, (and DSR, DTR on UART1 only)
* Automatic baud rate selection
* Manual or automatic RTS/CTS smart hardware flow control
* Programmable serial characteristics:
– Baud rate generation (50 to 3.25M baud)
– 5, 6, 7 or 8-bit characters
– Even, odd or no-parity bit generation and detection
– 1, 1.5 or 2 stop bit generation
* Independent control of transmit, receive, line status, data set interrupts and FIFOs
* Full status-reporting capabilities
* Separate DMA signaling for RX and TX
* Timed interrupt to spread receive interrupt on known duration
* DMA time-out interrupt to allow detection of end of reception
* Carkit pulse coding and decoding compliant with USB carkit control interface [40]
In 16550A auto-configuration, if the fifo size is 64 then it's an U6 16550A port
Add set_termios hook & export serial8250_do_set_termios to change uart
clock following baudrate
Signed-off-by: Philippe Langlais <philippe.langlais@stericsson.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-07-29 23:13:57 +08:00
|
|
|
/* Possibly override set_termios call */
|
2012-05-02 20:47:27 +08:00
|
|
|
if (up->port.set_termios)
|
|
|
|
uart->port.set_termios = up->port.set_termios;
|
2014-09-06 03:02:37 +08:00
|
|
|
if (up->port.startup)
|
|
|
|
uart->port.startup = up->port.startup;
|
|
|
|
if (up->port.shutdown)
|
|
|
|
uart->port.shutdown = up->port.shutdown;
|
2012-05-02 20:47:27 +08:00
|
|
|
if (up->port.pm)
|
|
|
|
uart->port.pm = up->port.pm;
|
|
|
|
if (up->port.handle_break)
|
|
|
|
uart->port.handle_break = up->port.handle_break;
|
|
|
|
if (up->dl_read)
|
|
|
|
uart->dl_read = up->dl_read;
|
|
|
|
if (up->dl_write)
|
|
|
|
uart->dl_write = up->dl_write;
|
2013-01-10 17:25:11 +08:00
|
|
|
if (up->dma)
|
|
|
|
uart->dma = up->dma;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-19 02:38:02 +08:00
|
|
|
if (serial8250_isa_config != NULL)
|
|
|
|
serial8250_isa_config(0, &uart->port,
|
|
|
|
&uart->capabilities);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = uart_add_one_port(&serial8250_reg, &uart->port);
|
|
|
|
if (ret == 0)
|
|
|
|
ret = uart->port.line;
|
|
|
|
}
|
2006-01-13 02:44:32 +08:00
|
|
|
mutex_unlock(&serial_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-05-02 20:47:27 +08:00
|
|
|
EXPORT_SYMBOL(serial8250_register_8250_port);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* serial8250_unregister_port - remove a 16x50 serial port at runtime
|
|
|
|
* @line: serial line number
|
|
|
|
*
|
|
|
|
* Remove one serial port. This may not be called from interrupt
|
|
|
|
* context. We hand the port back to the our control.
|
|
|
|
*/
|
|
|
|
void serial8250_unregister_port(int line)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *uart = &serial8250_ports[line];
|
|
|
|
|
2006-01-13 02:44:32 +08:00
|
|
|
mutex_lock(&serial_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
uart_remove_one_port(&serial8250_reg, &uart->port);
|
|
|
|
if (serial8250_isa_devs) {
|
|
|
|
uart->port.flags &= ~UPF_BOOT_AUTOCONF;
|
|
|
|
uart->port.type = PORT_UNKNOWN;
|
|
|
|
uart->port.dev = &serial8250_isa_devs->dev;
|
2011-05-26 22:18:39 +08:00
|
|
|
uart->capabilities = uart_config[uart->port.type].flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
uart_add_one_port(&serial8250_reg, &uart->port);
|
|
|
|
} else {
|
|
|
|
uart->port.dev = NULL;
|
|
|
|
}
|
2006-01-13 02:44:32 +08:00
|
|
|
mutex_unlock(&serial_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(serial8250_unregister_port);
|
|
|
|
|
|
|
|
static int __init serial8250_init(void)
|
|
|
|
{
|
2008-08-20 11:49:40 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-08 02:06:23 +08:00
|
|
|
serial8250_isa_init_ports();
|
2006-01-08 07:18:19 +08:00
|
|
|
|
2008-12-30 21:06:43 +08:00
|
|
|
printk(KERN_INFO "Serial: 8250/16550 driver, "
|
2006-01-08 07:18:19 +08:00
|
|
|
"%d ports, IRQ sharing %sabled\n", nr_uarts,
|
2005-04-17 06:20:36 +08:00
|
|
|
share_irqs ? "en" : "dis");
|
|
|
|
|
2008-10-13 17:36:31 +08:00
|
|
|
#ifdef CONFIG_SPARC
|
|
|
|
ret = sunserial_register_minors(&serial8250_reg, UART_NR);
|
|
|
|
#else
|
|
|
|
serial8250_reg.nr = UART_NR;
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = uart_register_driver(&serial8250_reg);
|
2008-10-13 17:36:31 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2012-09-08 02:06:23 +08:00
|
|
|
ret = serial8250_pnp_init();
|
|
|
|
if (ret)
|
|
|
|
goto unreg_uart_drv;
|
|
|
|
|
2006-01-14 06:06:43 +08:00
|
|
|
serial8250_isa_devs = platform_device_alloc("serial8250",
|
|
|
|
PLAT8250_DEV_LEGACY);
|
|
|
|
if (!serial8250_isa_devs) {
|
|
|
|
ret = -ENOMEM;
|
2012-09-08 02:06:23 +08:00
|
|
|
goto unreg_pnp;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-01-14 06:06:43 +08:00
|
|
|
ret = platform_device_add(serial8250_isa_devs);
|
|
|
|
if (ret)
|
|
|
|
goto put_dev;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);
|
|
|
|
|
2006-01-18 17:54:29 +08:00
|
|
|
ret = platform_driver_register(&serial8250_isa_driver);
|
|
|
|
if (ret == 0)
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-18 17:54:29 +08:00
|
|
|
platform_device_del(serial8250_isa_devs);
|
2008-08-20 11:49:40 +08:00
|
|
|
put_dev:
|
2006-01-14 06:06:43 +08:00
|
|
|
platform_device_put(serial8250_isa_devs);
|
2012-09-08 02:06:23 +08:00
|
|
|
unreg_pnp:
|
|
|
|
serial8250_pnp_exit();
|
2008-08-20 11:49:40 +08:00
|
|
|
unreg_uart_drv:
|
2008-10-13 17:36:31 +08:00
|
|
|
#ifdef CONFIG_SPARC
|
|
|
|
sunserial_unregister_minors(&serial8250_reg, UART_NR);
|
|
|
|
#else
|
2005-04-17 06:20:36 +08:00
|
|
|
uart_unregister_driver(&serial8250_reg);
|
2008-10-13 17:36:31 +08:00
|
|
|
#endif
|
2008-08-20 11:49:40 +08:00
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit serial8250_exit(void)
|
|
|
|
{
|
|
|
|
struct platform_device *isa_dev = serial8250_isa_devs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This tells serial8250_unregister_port() not to re-register
|
|
|
|
* the ports (thereby making serial8250_isa_driver permanently
|
|
|
|
* in use.)
|
|
|
|
*/
|
|
|
|
serial8250_isa_devs = NULL;
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_driver_unregister(&serial8250_isa_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
platform_device_unregister(isa_dev);
|
|
|
|
|
2012-09-08 02:06:23 +08:00
|
|
|
serial8250_pnp_exit();
|
|
|
|
|
2008-10-13 17:36:31 +08:00
|
|
|
#ifdef CONFIG_SPARC
|
|
|
|
sunserial_unregister_minors(&serial8250_reg, UART_NR);
|
|
|
|
#else
|
2005-04-17 06:20:36 +08:00
|
|
|
uart_unregister_driver(&serial8250_reg);
|
2008-10-13 17:36:31 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(serial8250_init);
|
|
|
|
module_exit(serial8250_exit);
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(serial8250_suspend_port);
|
|
|
|
EXPORT_SYMBOL(serial8250_resume_port);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-07-17 04:53:31 +08:00
|
|
|
MODULE_DESCRIPTION("Generic 8250/16x50 serial driver");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
module_param(share_irqs, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices"
|
|
|
|
" (unsafe)");
|
|
|
|
|
2006-01-08 07:18:19 +08:00
|
|
|
module_param(nr_uarts, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
|
|
|
|
|
2009-10-02 06:44:26 +08:00
|
|
|
module_param(skip_txen_test, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time");
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444);
|
|
|
|
MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
|
|
|
|
#endif
|
|
|
|
MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
|
2013-03-10 22:33:40 +08:00
|
|
|
|
2013-03-19 18:34:57 +08:00
|
|
|
#ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
|
2013-03-10 22:33:40 +08:00
|
|
|
#ifndef MODULE
|
|
|
|
/* This module was renamed to 8250_core in 3.7. Keep the old "8250" name
|
|
|
|
* working as well for the module options so we don't break people. We
|
|
|
|
* need to keep the names identical and the convenient macros will happily
|
|
|
|
* refuse to let us do that by failing the build with redefinition errors
|
|
|
|
* of global variables. So we stick them inside a dummy function to avoid
|
|
|
|
* those conflicts. The options still get parsed, and the redefined
|
|
|
|
* MODULE_PARAM_PREFIX lets us keep the "8250." syntax alive.
|
|
|
|
*
|
|
|
|
* This is hacky. I'm sorry.
|
|
|
|
*/
|
|
|
|
static void __used s8250_options(void)
|
|
|
|
{
|
|
|
|
#undef MODULE_PARAM_PREFIX
|
2013-03-19 18:34:56 +08:00
|
|
|
#define MODULE_PARAM_PREFIX "8250_core."
|
2013-03-10 22:33:40 +08:00
|
|
|
|
|
|
|
module_param_cb(share_irqs, ¶m_ops_uint, &share_irqs, 0644);
|
|
|
|
module_param_cb(nr_uarts, ¶m_ops_uint, &nr_uarts, 0644);
|
|
|
|
module_param_cb(skip_txen_test, ¶m_ops_uint, &skip_txen_test, 0644);
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
__module_param_call(MODULE_PARAM_PREFIX, probe_rsa,
|
|
|
|
¶m_array_ops, .arr = &__param_arr_probe_rsa,
|
|
|
|
0444, -1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#else
|
2013-03-19 18:34:56 +08:00
|
|
|
MODULE_ALIAS("8250_core");
|
2013-03-10 22:33:40 +08:00
|
|
|
#endif
|
|
|
|
#endif
|