2017-11-06 17:11:51 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* mxser.c -- MOXA Smartio/Industio family multiport serial driver.
|
|
|
|
*
|
2008-02-07 08:16:51 +00:00
|
|
|
* Copyright (C) 1999-2006 Moxa Technologies (support@moxa.com).
|
|
|
|
* Copyright (C) 2006-2008 Jiri Slaby <jirislaby@gmail.com>
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2008-02-07 08:16:46 +00:00
|
|
|
* This code is loosely based on the 1.8 moxa driver which is based on
|
|
|
|
* Linux serial driver, written by Linus Torvalds, Theodore T'so and
|
|
|
|
* others.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
|
2008-11-11 14:48:44 +00:00
|
|
|
* <alan@lxorguk.ukuu.org.uk>. The original 1.8 code is available on
|
|
|
|
* www.moxa.com.
|
2005-04-16 22:20:36 +00:00
|
|
|
* - Fixed x86_64 cleanness
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/serial_reg.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/pci.h>
|
2007-10-19 06:40:25 +00:00
|
|
|
#include <linux/bitops.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2011-06-16 12:07:22 +00:00
|
|
|
#include <linux/ratelimit.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:10 +00:00
|
|
|
/*
|
|
|
|
* Semi-public control interfaces
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MOXA ioctls
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MOXA 0x400
|
|
|
|
#define MOXA_SET_OP_MODE (MOXA + 66)
|
|
|
|
#define MOXA_GET_OP_MODE (MOXA + 67)
|
|
|
|
|
|
|
|
#define RS232_MODE 0
|
|
|
|
#define RS485_2WIRE_MODE 1
|
|
|
|
#define RS422_MODE 2
|
|
|
|
#define RS485_4WIRE_MODE 3
|
|
|
|
#define OP_MODE_MASK 3
|
|
|
|
|
|
|
|
/* --------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Follow just what Moxa Must chip defines.
|
|
|
|
*
|
|
|
|
* When LCR register (offset 0x03) writes the following value, the Must chip
|
|
|
|
* will enter enchance mode. And write value on EFR (offset 0x02) bit 6,7 to
|
|
|
|
* change bank.
|
|
|
|
*/
|
|
|
|
#define MOXA_MUST_ENTER_ENCHANCE 0xBF
|
|
|
|
|
|
|
|
/* when enhance mode enabled, access on general bank register */
|
|
|
|
#define MOXA_MUST_GDL_REGISTER 0x07
|
|
|
|
#define MOXA_MUST_GDL_MASK 0x7F
|
|
|
|
#define MOXA_MUST_GDL_HAS_BAD_DATA 0x80
|
|
|
|
|
|
|
|
#define MOXA_MUST_LSR_RERR 0x80 /* error in receive FIFO */
|
|
|
|
/* enchance register bank select and enchance mode setting register */
|
|
|
|
/* when LCR register equals to 0xBF */
|
|
|
|
#define MOXA_MUST_EFR_REGISTER 0x02
|
|
|
|
#define MOXA_MUST_EFR_EFRB_ENABLE 0x10 /* enchance mode enable */
|
|
|
|
/* enchance register bank set 0, 1, 2 */
|
|
|
|
#define MOXA_MUST_EFR_BANK0 0x00
|
|
|
|
#define MOXA_MUST_EFR_BANK1 0x40
|
|
|
|
#define MOXA_MUST_EFR_BANK2 0x80
|
|
|
|
#define MOXA_MUST_EFR_BANK3 0xC0
|
|
|
|
#define MOXA_MUST_EFR_BANK_MASK 0xC0
|
|
|
|
|
|
|
|
/* set XON1 value register, when LCR=0xBF and change to bank0 */
|
|
|
|
#define MOXA_MUST_XON1_REGISTER 0x04
|
|
|
|
|
|
|
|
/* set XON2 value register, when LCR=0xBF and change to bank0 */
|
|
|
|
#define MOXA_MUST_XON2_REGISTER 0x05
|
|
|
|
|
|
|
|
/* set XOFF1 value register, when LCR=0xBF and change to bank0 */
|
|
|
|
#define MOXA_MUST_XOFF1_REGISTER 0x06
|
|
|
|
|
|
|
|
/* set XOFF2 value register, when LCR=0xBF and change to bank0 */
|
|
|
|
#define MOXA_MUST_XOFF2_REGISTER 0x07
|
|
|
|
|
|
|
|
#define MOXA_MUST_RBRTL_REGISTER 0x04
|
|
|
|
#define MOXA_MUST_RBRTH_REGISTER 0x05
|
|
|
|
#define MOXA_MUST_RBRTI_REGISTER 0x06
|
|
|
|
#define MOXA_MUST_THRTL_REGISTER 0x07
|
|
|
|
#define MOXA_MUST_ENUM_REGISTER 0x04
|
|
|
|
#define MOXA_MUST_HWID_REGISTER 0x05
|
|
|
|
#define MOXA_MUST_ECR_REGISTER 0x06
|
|
|
|
#define MOXA_MUST_CSR_REGISTER 0x07
|
|
|
|
|
|
|
|
#define MOXA_MUST_FCR_GDA_MODE_ENABLE 0x20 /* good data mode enable */
|
|
|
|
#define MOXA_MUST_FCR_GDA_ONLY_ENABLE 0x10 /* only good data put into RxFIFO */
|
|
|
|
|
|
|
|
#define MOXA_MUST_IER_ECTSI 0x80 /* enable CTS interrupt */
|
|
|
|
#define MOXA_MUST_IER_ERTSI 0x40 /* enable RTS interrupt */
|
|
|
|
#define MOXA_MUST_IER_XINT 0x20 /* enable Xon/Xoff interrupt */
|
|
|
|
#define MOXA_MUST_IER_EGDAI 0x10 /* enable GDA interrupt */
|
|
|
|
|
|
|
|
#define MOXA_MUST_RECV_ISR (UART_IER_RDI | MOXA_MUST_IER_EGDAI)
|
|
|
|
|
|
|
|
/* GDA interrupt pending */
|
|
|
|
#define MOXA_MUST_IIR_GDA 0x1C
|
|
|
|
#define MOXA_MUST_IIR_RDA 0x04
|
|
|
|
#define MOXA_MUST_IIR_RTO 0x0C
|
|
|
|
#define MOXA_MUST_IIR_LSR 0x06
|
|
|
|
|
|
|
|
/* received Xon/Xoff or specical interrupt pending */
|
|
|
|
#define MOXA_MUST_IIR_XSC 0x10
|
|
|
|
|
|
|
|
/* RTS/CTS change state interrupt pending */
|
|
|
|
#define MOXA_MUST_IIR_RTSCTS 0x20
|
|
|
|
#define MOXA_MUST_IIR_MASK 0x3E
|
|
|
|
|
|
|
|
#define MOXA_MUST_MCR_XON_FLAG 0x40
|
|
|
|
#define MOXA_MUST_MCR_XON_ANY 0x80
|
|
|
|
#define MOXA_MUST_MCR_TX_XON 0x08
|
|
|
|
|
|
|
|
#define MOXA_MUST_EFR_SF_MASK 0x0F /* software flow control on chip mask value */
|
|
|
|
#define MOXA_MUST_EFR_SF_TX1 0x08 /* send Xon1/Xoff1 */
|
|
|
|
#define MOXA_MUST_EFR_SF_TX2 0x04 /* send Xon2/Xoff2 */
|
|
|
|
#define MOXA_MUST_EFR_SF_TX12 0x0C /* send Xon1,Xon2/Xoff1,Xoff2 */
|
|
|
|
#define MOXA_MUST_EFR_SF_TX_NO 0x00 /* don't send Xon/Xoff */
|
|
|
|
#define MOXA_MUST_EFR_SF_TX_MASK 0x0C /* Tx software flow control mask */
|
|
|
|
#define MOXA_MUST_EFR_SF_RX_NO 0x00 /* don't receive Xon/Xoff */
|
|
|
|
#define MOXA_MUST_EFR_SF_RX1 0x02 /* receive Xon1/Xoff1 */
|
|
|
|
#define MOXA_MUST_EFR_SF_RX2 0x01 /* receive Xon2/Xoff2 */
|
|
|
|
#define MOXA_MUST_EFR_SF_RX12 0x03 /* receive Xon1,Xon2/Xoff1,Xoff2 */
|
|
|
|
#define MOXA_MUST_EFR_SF_RX_MASK 0x03 /* Rx software flow control mask */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define MXSERMAJOR 174
|
|
|
|
|
|
|
|
#define MXSER_BOARDS 4 /* Max. boards */
|
|
|
|
#define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
|
2008-02-07 08:16:46 +00:00
|
|
|
#define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
|
|
|
|
#define MXSER_ISR_PASS_LIMIT 100
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define WAKEUP_CHARS 256
|
|
|
|
|
2021-06-18 06:14:41 +00:00
|
|
|
#define MXSER_BAUD_BASE 921600
|
2021-06-18 06:14:42 +00:00
|
|
|
#define MXSER_CUSTOM_DIVISOR (MXSER_BAUD_BASE * 16)
|
2021-06-18 06:14:41 +00:00
|
|
|
|
2008-07-22 10:20:34 +00:00
|
|
|
#define PCI_DEVICE_ID_POS104UL 0x1044
|
2008-02-07 08:16:46 +00:00
|
|
|
#define PCI_DEVICE_ID_CB108 0x1080
|
2008-07-22 10:20:34 +00:00
|
|
|
#define PCI_DEVICE_ID_CP102UF 0x1023
|
2009-09-10 10:20:07 +00:00
|
|
|
#define PCI_DEVICE_ID_CP112UL 0x1120
|
2008-02-07 08:16:46 +00:00
|
|
|
#define PCI_DEVICE_ID_CB114 0x1142
|
2008-02-07 08:16:51 +00:00
|
|
|
#define PCI_DEVICE_ID_CP114UL 0x1143
|
2008-02-07 08:16:46 +00:00
|
|
|
#define PCI_DEVICE_ID_CB134I 0x1341
|
|
|
|
#define PCI_DEVICE_ID_CP138U 0x1380
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:54 +00:00
|
|
|
#define MXSER_NPORTS(ddata) ((ddata) & 0xffU)
|
|
|
|
#define MXSER_HIGHBAUD 0x0100
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:14 +00:00
|
|
|
enum mxser_must_hwid {
|
|
|
|
MOXA_OTHER_UART = 0x00,
|
|
|
|
MOXA_MUST_MU150_HWID = 0x01,
|
|
|
|
MOXA_MUST_MU860_HWID = 0x02,
|
|
|
|
};
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
static const struct {
|
2021-06-18 06:14:11 +00:00
|
|
|
u8 type;
|
|
|
|
u8 fifo_size;
|
|
|
|
u8 rx_high_water;
|
|
|
|
u8 rx_low_water;
|
|
|
|
speed_t max_baud;
|
2008-02-07 08:16:46 +00:00
|
|
|
} Gpci_uart_info[] = {
|
2021-06-18 06:14:11 +00:00
|
|
|
{ MOXA_OTHER_UART, 16, 14, 1, 921600 },
|
|
|
|
{ MOXA_MUST_MU150_HWID, 64, 48, 16, 230400 },
|
|
|
|
{ MOXA_MUST_MU860_HWID, 128, 96, 32, 921600 }
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
2008-02-07 08:16:46 +00:00
|
|
|
#define UART_INFO_NUM ARRAY_SIZE(Gpci_uart_info)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/* driver_data correspond to the lines in the structure above
|
|
|
|
see also ISA probe function before you change something */
|
2017-07-23 10:01:01 +00:00
|
|
|
static const struct pci_device_id mxser_pcibrds[] = {
|
2021-06-18 06:14:54 +00:00
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168), .driver_data = 8 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104), .driver_data = 4 },
|
2021-06-18 06:14:08 +00:00
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132), .driver_data = 2 },
|
2021-06-18 06:14:54 +00:00
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114), .driver_data = 4 },
|
2021-06-18 06:14:08 +00:00
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CT114), .driver_data = 4 },
|
2021-06-18 06:14:54 +00:00
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102), .driver_data = 2 | MXSER_HIGHBAUD },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104U), .driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168U), .driver_data = 8 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132U), .driver_data = 2 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134U), .driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104JU),.driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_RC7000), .driver_data = 8 }, /* RC7000 */
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118U), .driver_data = 8 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102UL),.driver_data = 2 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102U), .driver_data = 2 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL),.driver_data = 8 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL),.driver_data = 8 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL),.driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB108), .driver_data = 8 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB114), .driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB134I), .driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U), .driver_data = 8 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_POS104UL), .driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL), .driver_data = 4 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP102UF), .driver_data = 2 },
|
|
|
|
{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP112UL), .driver_data = 2 },
|
2008-02-07 08:16:46 +00:00
|
|
|
{ }
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
|
|
|
|
|
|
|
|
static int ttymajor = MXSERMAJOR;
|
|
|
|
|
|
|
|
/* Variables for insmod */
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Casper Yang");
|
|
|
|
MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
|
2006-03-25 11:07:05 +00:00
|
|
|
module_param(ttymajor, int, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_board;
|
|
|
|
|
|
|
|
struct mxser_port {
|
2008-07-16 20:56:10 +00:00
|
|
|
struct tty_port port;
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_board *board;
|
|
|
|
|
|
|
|
unsigned long ioaddr;
|
|
|
|
unsigned long opmode_ioaddr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:11 +00:00
|
|
|
u8 rx_high_water;
|
|
|
|
u8 rx_low_water;
|
2005-04-16 22:20:36 +00:00
|
|
|
int type; /* UART type */
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:24 +00:00
|
|
|
unsigned char x_char; /* xon/xoff character */
|
|
|
|
u8 IER; /* Interrupt Enable Register */
|
|
|
|
u8 MCR; /* Modem control register */
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
unsigned char ldisc_stop_rx;
|
|
|
|
|
|
|
|
struct async_icount icount; /* kernel counters for 4 input interrupts */
|
2017-09-12 10:39:54 +00:00
|
|
|
unsigned int timeout;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:24 +00:00
|
|
|
u8 read_status_mask;
|
|
|
|
u8 ignore_status_mask;
|
2021-06-18 06:14:11 +00:00
|
|
|
u8 xmit_fifo_size;
|
2021-06-18 06:14:25 +00:00
|
|
|
unsigned int xmit_head;
|
|
|
|
unsigned int xmit_tail;
|
|
|
|
unsigned int xmit_cnt;
|
2016-01-10 22:51:38 +00:00
|
|
|
int closing;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spinlock_t slock;
|
2008-02-07 08:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mxser_board {
|
|
|
|
unsigned int idx;
|
2021-06-18 06:14:54 +00:00
|
|
|
unsigned short nports;
|
2008-02-07 08:16:46 +00:00
|
|
|
int irq;
|
|
|
|
unsigned long vector;
|
|
|
|
|
2021-06-18 06:14:14 +00:00
|
|
|
enum mxser_must_hwid must_hwid;
|
2021-06-18 06:14:16 +00:00
|
|
|
speed_t max_baud;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:59 +00:00
|
|
|
struct mxser_port ports[];
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2021-06-18 06:14:58 +00:00
|
|
|
static DECLARE_BITMAP(mxser_boards, MXSER_BOARDS);
|
2005-04-16 22:20:36 +00:00
|
|
|
static struct tty_driver *mxvar_sdriver;
|
|
|
|
|
2021-06-18 06:14:46 +00:00
|
|
|
static u8 __mxser_must_set_EFR(unsigned long baseio, u8 clear, u8 set,
|
|
|
|
bool restore_LCR)
|
2008-04-30 07:54:29 +00:00
|
|
|
{
|
2021-06-18 06:14:46 +00:00
|
|
|
u8 oldlcr, efr;
|
2008-04-30 07:54:29 +00:00
|
|
|
|
|
|
|
oldlcr = inb(baseio + UART_LCR);
|
|
|
|
outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
|
|
|
|
|
|
|
|
efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
|
2021-06-18 06:14:46 +00:00
|
|
|
efr &= ~clear;
|
|
|
|
efr |= set;
|
2008-04-30 07:54:29 +00:00
|
|
|
|
|
|
|
outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
|
|
|
|
|
2021-06-18 06:14:46 +00:00
|
|
|
if (restore_LCR)
|
|
|
|
outb(oldlcr, baseio + UART_LCR);
|
2008-04-30 07:54:29 +00:00
|
|
|
|
2021-06-18 06:14:46 +00:00
|
|
|
return oldlcr;
|
2008-04-30 07:54:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:47 +00:00
|
|
|
static u8 mxser_must_select_bank(unsigned long baseio, u8 bank)
|
2008-04-30 07:54:29 +00:00
|
|
|
{
|
2021-06-18 06:14:47 +00:00
|
|
|
return __mxser_must_set_EFR(baseio, MOXA_MUST_EFR_BANK_MASK, bank,
|
|
|
|
false);
|
|
|
|
}
|
2008-04-30 07:54:29 +00:00
|
|
|
|
2021-06-18 06:14:47 +00:00
|
|
|
static void mxser_set_must_xon1_value(unsigned long baseio, u8 value)
|
|
|
|
{
|
|
|
|
u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK0);
|
2008-04-30 07:54:29 +00:00
|
|
|
outb(value, baseio + MOXA_MUST_XON1_REGISTER);
|
|
|
|
outb(oldlcr, baseio + UART_LCR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxser_set_must_xoff1_value(unsigned long baseio, u8 value)
|
|
|
|
{
|
2021-06-18 06:14:47 +00:00
|
|
|
u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK0);
|
2008-04-30 07:54:29 +00:00
|
|
|
outb(value, baseio + MOXA_MUST_XOFF1_REGISTER);
|
|
|
|
outb(oldlcr, baseio + UART_LCR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxser_set_must_fifo_value(struct mxser_port *info)
|
|
|
|
{
|
2021-06-18 06:14:47 +00:00
|
|
|
u8 oldlcr = mxser_must_select_bank(info->ioaddr, MOXA_MUST_EFR_BANK1);
|
2021-06-18 06:14:11 +00:00
|
|
|
outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTH_REGISTER);
|
|
|
|
outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTI_REGISTER);
|
|
|
|
outb(info->rx_low_water, info->ioaddr + MOXA_MUST_RBRTL_REGISTER);
|
2008-04-30 07:54:29 +00:00
|
|
|
outb(oldlcr, info->ioaddr + UART_LCR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxser_set_must_enum_value(unsigned long baseio, u8 value)
|
|
|
|
{
|
2021-06-18 06:14:47 +00:00
|
|
|
u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK2);
|
2008-04-30 07:54:29 +00:00
|
|
|
outb(value, baseio + MOXA_MUST_ENUM_REGISTER);
|
|
|
|
outb(oldlcr, baseio + UART_LCR);
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:47 +00:00
|
|
|
static u8 mxser_get_must_hardware_id(unsigned long baseio)
|
2008-04-30 07:54:29 +00:00
|
|
|
{
|
2021-06-18 06:14:47 +00:00
|
|
|
u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK2);
|
|
|
|
u8 id = inb(baseio + MOXA_MUST_HWID_REGISTER);
|
2008-04-30 07:54:29 +00:00
|
|
|
outb(oldlcr, baseio + UART_LCR);
|
2021-06-18 06:14:47 +00:00
|
|
|
|
|
|
|
return id;
|
2008-04-30 07:54:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:46 +00:00
|
|
|
static void mxser_must_set_EFR(unsigned long baseio, u8 clear, u8 set)
|
|
|
|
{
|
|
|
|
__mxser_must_set_EFR(baseio, clear, set, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxser_must_set_enhance_mode(unsigned long baseio, bool enable)
|
|
|
|
{
|
|
|
|
mxser_must_set_EFR(baseio,
|
|
|
|
enable ? 0 : MOXA_MUST_EFR_EFRB_ENABLE,
|
|
|
|
enable ? MOXA_MUST_EFR_EFRB_ENABLE : 0);
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:48 +00:00
|
|
|
static void mxser_must_no_sw_flow_control(unsigned long baseio)
|
2008-04-30 07:54:29 +00:00
|
|
|
{
|
2021-06-18 06:14:48 +00:00
|
|
|
mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_MASK, 0);
|
2008-04-30 07:54:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:48 +00:00
|
|
|
static void mxser_must_set_tx_sw_flow_control(unsigned long baseio, bool enable)
|
2008-04-30 07:54:29 +00:00
|
|
|
{
|
2021-06-18 06:14:48 +00:00
|
|
|
mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_TX_MASK,
|
|
|
|
enable ? MOXA_MUST_EFR_SF_TX1 : 0);
|
2008-04-30 07:54:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:48 +00:00
|
|
|
static void mxser_must_set_rx_sw_flow_control(unsigned long baseio, bool enable)
|
2008-04-30 07:54:29 +00:00
|
|
|
{
|
2021-06-18 06:14:48 +00:00
|
|
|
mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_RX_MASK,
|
|
|
|
enable ? MOXA_MUST_EFR_SF_RX1 : 0);
|
2008-04-30 07:54:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:14 +00:00
|
|
|
static enum mxser_must_hwid mxser_must_get_hwid(unsigned long io)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
u8 oldmcr, hwid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
outb(0, io + UART_LCR);
|
2021-06-18 06:14:46 +00:00
|
|
|
mxser_must_set_enhance_mode(io, false);
|
2005-04-16 22:20:36 +00:00
|
|
|
oldmcr = inb(io + UART_MCR);
|
|
|
|
outb(0, io + UART_MCR);
|
2008-04-30 07:54:29 +00:00
|
|
|
mxser_set_must_xon1_value(io, 0x11);
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((hwid = inb(io + UART_MCR)) != 0) {
|
|
|
|
outb(oldmcr, io + UART_MCR);
|
2006-06-25 12:47:54 +00:00
|
|
|
return MOXA_OTHER_UART;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:47 +00:00
|
|
|
hwid = mxser_get_must_hardware_id(io);
|
2021-06-18 06:14:14 +00:00
|
|
|
for (i = 1; i < UART_INFO_NUM; i++) /* 0 = OTHER_UART */
|
2008-02-07 08:16:46 +00:00
|
|
|
if (hwid == Gpci_uart_info[i].type)
|
2021-06-18 06:14:14 +00:00
|
|
|
return hwid;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return MOXA_OTHER_UART;
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:55 +00:00
|
|
|
static void mxser_process_txrx_fifo(struct mxser_port *info)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-06-18 06:14:55 +00:00
|
|
|
unsigned int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:55 +00:00
|
|
|
if (info->type == PORT_16450 || info->type == PORT_8250) {
|
2005-04-16 22:20:36 +00:00
|
|
|
info->rx_high_water = 1;
|
|
|
|
info->rx_low_water = 1;
|
|
|
|
info->xmit_fifo_size = 1;
|
2021-06-18 06:14:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < UART_INFO_NUM; i++)
|
|
|
|
if (info->board->must_hwid == Gpci_uart_info[i].type) {
|
|
|
|
info->rx_low_water = Gpci_uart_info[i].rx_low_water;
|
|
|
|
info->rx_high_water = Gpci_uart_info[i].rx_high_water;
|
|
|
|
info->xmit_fifo_size = Gpci_uart_info[i].fifo_size;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 13:45:05 +00:00
|
|
|
static int mxser_carrier_raised(struct tty_port *port)
|
|
|
|
{
|
|
|
|
struct mxser_port *mp = container_of(port, struct mxser_port, port);
|
|
|
|
return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0;
|
|
|
|
}
|
|
|
|
|
2009-06-11 11:24:17 +00:00
|
|
|
static void mxser_dtr_rts(struct tty_port *port, int on)
|
2009-01-02 13:45:19 +00:00
|
|
|
{
|
|
|
|
struct mxser_port *mp = container_of(port, struct mxser_port, port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&mp->slock, flags);
|
2009-06-11 11:24:17 +00:00
|
|
|
if (on)
|
|
|
|
outb(inb(mp->ioaddr + UART_MCR) |
|
|
|
|
UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR);
|
|
|
|
else
|
|
|
|
outb(inb(mp->ioaddr + UART_MCR)&~(UART_MCR_DTR | UART_MCR_RTS),
|
|
|
|
mp->ioaddr + UART_MCR);
|
2009-01-02 13:45:19 +00:00
|
|
|
spin_unlock_irqrestore(&mp->slock, flags);
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:11 +00:00
|
|
|
static int mxser_set_baud(struct tty_struct *tty, speed_t newspd)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-10-13 09:40:19 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2017-09-12 10:39:54 +00:00
|
|
|
unsigned int quot = 0, baud;
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned char cval;
|
2017-09-12 10:39:54 +00:00
|
|
|
u64 timeout;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-10-13 09:40:19 +00:00
|
|
|
if (!info->ioaddr)
|
2008-02-07 08:16:46 +00:00
|
|
|
return -1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:16 +00:00
|
|
|
if (newspd > info->board->max_baud)
|
2008-02-07 08:16:46 +00:00
|
|
|
return -1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (newspd == 134) {
|
2021-06-18 06:14:41 +00:00
|
|
|
quot = 2 * MXSER_BAUD_BASE / 269;
|
2008-10-13 09:40:19 +00:00
|
|
|
tty_encode_baud_rate(tty, 134, 134);
|
2008-02-07 08:16:46 +00:00
|
|
|
} else if (newspd) {
|
2021-06-18 06:14:41 +00:00
|
|
|
quot = MXSER_BAUD_BASE / newspd;
|
2008-02-07 08:16:46 +00:00
|
|
|
if (quot == 0)
|
|
|
|
quot = 1;
|
2021-06-18 06:14:41 +00:00
|
|
|
baud = MXSER_BAUD_BASE / quot;
|
2008-10-13 09:40:19 +00:00
|
|
|
tty_encode_baud_rate(tty, baud, baud);
|
2008-02-07 08:16:46 +00:00
|
|
|
} else {
|
|
|
|
quot = 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-09-12 10:39:54 +00:00
|
|
|
/*
|
|
|
|
* worst case (128 * 1000 * 10 * 18432) needs 35 bits, so divide in the
|
|
|
|
* u64 domain
|
|
|
|
*/
|
|
|
|
timeout = (u64)info->xmit_fifo_size * HZ * 10 * quot;
|
2021-06-18 06:14:41 +00:00
|
|
|
do_div(timeout, MXSER_BAUD_BASE);
|
2017-09-12 10:39:54 +00:00
|
|
|
info->timeout = timeout + HZ / 50; /* Add .02 seconds of slop */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (quot) {
|
|
|
|
info->MCR |= UART_MCR_DTR;
|
|
|
|
outb(info->MCR, info->ioaddr + UART_MCR);
|
|
|
|
} else {
|
|
|
|
info->MCR &= ~UART_MCR_DTR;
|
|
|
|
outb(info->MCR, info->ioaddr + UART_MCR);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
cval = inb(info->ioaddr + UART_LCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(cval | UART_LCR_DLAB, info->ioaddr + UART_LCR); /* set DLAB */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(quot & 0xff, info->ioaddr + UART_DLL); /* LS of divisor */
|
|
|
|
outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */
|
|
|
|
outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
#ifdef BOTHER
|
2008-10-13 09:40:19 +00:00
|
|
|
if (C_BAUD(tty) == BOTHER) {
|
2021-06-18 06:14:41 +00:00
|
|
|
quot = MXSER_BAUD_BASE % newspd;
|
2008-02-07 08:16:46 +00:00
|
|
|
quot *= 8;
|
|
|
|
if (quot % newspd > newspd / 2) {
|
|
|
|
quot /= newspd;
|
|
|
|
quot++;
|
|
|
|
} else
|
|
|
|
quot /= newspd;
|
|
|
|
|
2008-04-30 07:54:29 +00:00
|
|
|
mxser_set_must_enum_value(info->ioaddr, quot);
|
2008-02-07 08:16:46 +00:00
|
|
|
} else
|
|
|
|
#endif
|
2008-04-30 07:54:29 +00:00
|
|
|
mxser_set_must_enum_value(info->ioaddr, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-25 12:47:54 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* This routine is called to set the UART divisor registers to match
|
|
|
|
* the specified baud rate for a serial port.
|
|
|
|
*/
|
2020-05-06 06:17:35 +00:00
|
|
|
static void mxser_change_speed(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-10-13 09:40:19 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned cflag, cval, fcr;
|
|
|
|
unsigned char status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-07-14 14:31:47 +00:00
|
|
|
cflag = tty->termios.c_cflag;
|
2008-10-13 09:40:19 +00:00
|
|
|
if (!info->ioaddr)
|
2020-05-06 06:17:35 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:29 +00:00
|
|
|
mxser_set_baud(tty, tty_get_baud_rate(tty));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/* byte size and parity */
|
|
|
|
switch (cflag & CSIZE) {
|
2021-06-18 06:14:43 +00:00
|
|
|
default:
|
2008-02-07 08:16:46 +00:00
|
|
|
case CS5:
|
2021-06-18 06:14:43 +00:00
|
|
|
cval = UART_LCR_WLEN5;
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
|
|
|
case CS6:
|
2021-06-18 06:14:43 +00:00
|
|
|
cval = UART_LCR_WLEN6;
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
|
|
|
case CS7:
|
2021-06-18 06:14:43 +00:00
|
|
|
cval = UART_LCR_WLEN7;
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
|
|
|
case CS8:
|
2021-06-18 06:14:43 +00:00
|
|
|
cval = UART_LCR_WLEN8;
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-06-18 06:14:43 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (cflag & CSTOPB)
|
2021-06-18 06:14:43 +00:00
|
|
|
cval |= UART_LCR_STOP;
|
2008-02-07 08:16:46 +00:00
|
|
|
if (cflag & PARENB)
|
|
|
|
cval |= UART_LCR_PARITY;
|
|
|
|
if (!(cflag & PARODD))
|
|
|
|
cval |= UART_LCR_EPAR;
|
|
|
|
if (cflag & CMSPAR)
|
|
|
|
cval |= UART_LCR_SPAR;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid) {
|
2008-02-07 08:16:46 +00:00
|
|
|
fcr = UART_FCR_ENABLE_FIFO;
|
|
|
|
fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
|
2008-04-30 07:54:29 +00:00
|
|
|
mxser_set_must_fifo_value(info);
|
2008-02-07 08:16:46 +00:00
|
|
|
} else
|
|
|
|
fcr = 0;
|
|
|
|
} else {
|
|
|
|
fcr = UART_FCR_ENABLE_FIFO;
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid) {
|
2008-02-07 08:16:46 +00:00
|
|
|
fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
|
2008-04-30 07:54:29 +00:00
|
|
|
mxser_set_must_fifo_value(info);
|
2008-02-07 08:16:46 +00:00
|
|
|
} else {
|
2021-06-18 06:14:11 +00:00
|
|
|
switch (info->rx_high_water) {
|
2008-02-07 08:16:46 +00:00
|
|
|
case 1:
|
|
|
|
fcr |= UART_FCR_TRIGGER_1;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
fcr |= UART_FCR_TRIGGER_4;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
fcr |= UART_FCR_TRIGGER_8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fcr |= UART_FCR_TRIGGER_14;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/* CTS flow control flag and modem status interrupts */
|
|
|
|
info->IER &= ~UART_IER_MSI;
|
|
|
|
info->MCR &= ~UART_MCR_AFE;
|
2016-04-10 00:53:21 +00:00
|
|
|
tty_port_set_cts_flow(&info->port, cflag & CRTSCTS);
|
2008-02-07 08:16:46 +00:00
|
|
|
if (cflag & CRTSCTS) {
|
|
|
|
info->IER |= UART_IER_MSI;
|
2021-06-18 06:14:13 +00:00
|
|
|
if ((info->type == PORT_16550A) || (info->board->must_hwid)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->MCR |= UART_MCR_AFE;
|
|
|
|
} else {
|
|
|
|
status = inb(info->ioaddr + UART_MSR);
|
2008-10-13 09:40:19 +00:00
|
|
|
if (tty->hw_stopped) {
|
2008-02-07 08:16:46 +00:00
|
|
|
if (status & UART_MSR_CTS) {
|
2008-10-13 09:40:19 +00:00
|
|
|
tty->hw_stopped = 0;
|
2008-02-07 08:16:46 +00:00
|
|
|
if (info->type != PORT_16550A &&
|
2021-06-18 06:14:13 +00:00
|
|
|
!info->board->must_hwid) {
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER & ~UART_IER_THRI,
|
|
|
|
info->ioaddr +
|
|
|
|
UART_IER);
|
|
|
|
info->IER |= UART_IER_THRI;
|
|
|
|
outb(info->IER, info->ioaddr +
|
|
|
|
UART_IER);
|
|
|
|
}
|
2008-10-13 09:40:19 +00:00
|
|
|
tty_wakeup(tty);
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(status & UART_MSR_CTS)) {
|
2008-10-13 09:40:19 +00:00
|
|
|
tty->hw_stopped = 1;
|
2008-02-07 08:16:46 +00:00
|
|
|
if ((info->type != PORT_16550A) &&
|
2021-06-18 06:14:13 +00:00
|
|
|
(!info->board->must_hwid)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->IER &= ~UART_IER_THRI;
|
|
|
|
outb(info->IER, info->ioaddr +
|
|
|
|
UART_IER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
|
|
|
outb(info->MCR, info->ioaddr + UART_MCR);
|
2016-04-10 00:53:23 +00:00
|
|
|
tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL);
|
|
|
|
if (~cflag & CLOCAL)
|
2008-02-07 08:16:46 +00:00
|
|
|
info->IER |= UART_IER_MSI;
|
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up parity check flag
|
|
|
|
*/
|
|
|
|
info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
|
2008-10-13 09:40:19 +00:00
|
|
|
if (I_INPCK(tty))
|
2008-02-07 08:16:46 +00:00
|
|
|
info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
|
2008-10-13 09:40:19 +00:00
|
|
|
if (I_BRKINT(tty) || I_PARMRK(tty))
|
2008-02-07 08:16:46 +00:00
|
|
|
info->read_status_mask |= UART_LSR_BI;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
info->ignore_status_mask = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-10-13 09:40:19 +00:00
|
|
|
if (I_IGNBRK(tty)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->ignore_status_mask |= UART_LSR_BI;
|
|
|
|
info->read_status_mask |= UART_LSR_BI;
|
2006-06-25 12:47:54 +00:00
|
|
|
/*
|
2008-02-07 08:16:46 +00:00
|
|
|
* If we're ignore parity and break indicators, ignore
|
|
|
|
* overruns too. (For real raw support).
|
2006-06-25 12:47:54 +00:00
|
|
|
*/
|
2008-10-13 09:40:19 +00:00
|
|
|
if (I_IGNPAR(tty)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->ignore_status_mask |=
|
|
|
|
UART_LSR_OE |
|
|
|
|
UART_LSR_PE |
|
|
|
|
UART_LSR_FE;
|
|
|
|
info->read_status_mask |=
|
|
|
|
UART_LSR_OE |
|
|
|
|
UART_LSR_PE |
|
|
|
|
UART_LSR_FE;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid) {
|
2008-10-13 09:40:19 +00:00
|
|
|
mxser_set_must_xon1_value(info->ioaddr, START_CHAR(tty));
|
|
|
|
mxser_set_must_xoff1_value(info->ioaddr, STOP_CHAR(tty));
|
2021-06-18 06:14:48 +00:00
|
|
|
mxser_must_set_rx_sw_flow_control(info->ioaddr, I_IXON(tty));
|
|
|
|
mxser_must_set_tx_sw_flow_control(info->ioaddr, I_IXOFF(tty));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(fcr, info->ioaddr + UART_FCR); /* set fcr */
|
|
|
|
outb(cval, info->ioaddr + UART_LCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 09:40:19 +00:00
|
|
|
static void mxser_check_modem_status(struct tty_struct *tty,
|
|
|
|
struct mxser_port *port, int status)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
/* update input line counters */
|
|
|
|
if (status & UART_MSR_TERI)
|
|
|
|
port->icount.rng++;
|
|
|
|
if (status & UART_MSR_DDSR)
|
|
|
|
port->icount.dsr++;
|
|
|
|
if (status & UART_MSR_DDCD)
|
|
|
|
port->icount.dcd++;
|
|
|
|
if (status & UART_MSR_DCTS)
|
|
|
|
port->icount.cts++;
|
2009-09-19 20:13:31 +00:00
|
|
|
wake_up_interruptible(&port->port.delta_msr_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-04-10 00:53:23 +00:00
|
|
|
if (tty_port_check_carrier(&port->port) && (status & UART_MSR_DDCD)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
if (status & UART_MSR_DCD)
|
2008-07-16 20:56:10 +00:00
|
|
|
wake_up_interruptible(&port->port.open_wait);
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-08-23 02:13:36 +00:00
|
|
|
if (tty_port_cts_enabled(&port->port)) {
|
2008-10-13 09:40:19 +00:00
|
|
|
if (tty->hw_stopped) {
|
2008-02-07 08:16:46 +00:00
|
|
|
if (status & UART_MSR_CTS) {
|
2008-10-13 09:40:19 +00:00
|
|
|
tty->hw_stopped = 0;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
if ((port->type != PORT_16550A) &&
|
2021-06-18 06:14:13 +00:00
|
|
|
(!port->board->must_hwid)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(port->IER & ~UART_IER_THRI,
|
|
|
|
port->ioaddr + UART_IER);
|
|
|
|
port->IER |= UART_IER_THRI;
|
|
|
|
outb(port->IER, port->ioaddr +
|
|
|
|
UART_IER);
|
|
|
|
}
|
2008-10-13 09:40:19 +00:00
|
|
|
tty_wakeup(tty);
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(status & UART_MSR_CTS)) {
|
2008-10-13 09:40:19 +00:00
|
|
|
tty->hw_stopped = 1;
|
2008-02-07 08:16:46 +00:00
|
|
|
if (port->type != PORT_16550A &&
|
2021-06-18 06:14:13 +00:00
|
|
|
!port->board->must_hwid) {
|
2008-02-07 08:16:46 +00:00
|
|
|
port->IER &= ~UART_IER_THRI;
|
|
|
|
outb(port->IER, port->ioaddr +
|
|
|
|
UART_IER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-30 13:17:35 +00:00
|
|
|
static int mxser_activate(struct tty_port *port, struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-11-30 13:17:35 +00:00
|
|
|
struct mxser_port *info = container_of(port, struct mxser_port, port);
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned long page;
|
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
page = __get_free_page(GFP_KERNEL);
|
|
|
|
if (!page)
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (!info->ioaddr || !info->type) {
|
2008-10-13 09:40:19 +00:00
|
|
|
set_bit(TTY_IO_ERROR, &tty->flags);
|
2008-02-07 08:16:46 +00:00
|
|
|
free_page(page);
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
2009-11-30 13:17:35 +00:00
|
|
|
info->port.xmit_buf = (unsigned char *) page;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
2008-02-07 08:16:46 +00:00
|
|
|
* Clear the FIFO buffers and disable them
|
|
|
|
* (they will be reenabled in mxser_change_speed())
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid)
|
2008-02-07 08:16:46 +00:00
|
|
|
outb((UART_FCR_CLEAR_RCVR |
|
|
|
|
UART_FCR_CLEAR_XMIT |
|
|
|
|
MOXA_MUST_FCR_GDA_MODE_ENABLE), info->ioaddr + UART_FCR);
|
|
|
|
else
|
|
|
|
outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
|
|
|
|
info->ioaddr + UART_FCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00: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.
|
|
|
|
*/
|
|
|
|
if (inb(info->ioaddr + UART_LSR) == 0xff) {
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
if (capable(CAP_SYS_ADMIN)) {
|
2009-12-09 20:34:15 +00:00
|
|
|
set_bit(TTY_IO_ERROR, &tty->flags);
|
2008-02-07 08:16:46 +00:00
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* Clear the interrupt registers.
|
|
|
|
*/
|
|
|
|
(void) inb(info->ioaddr + UART_LSR);
|
|
|
|
(void) inb(info->ioaddr + UART_RX);
|
|
|
|
(void) inb(info->ioaddr + UART_IIR);
|
|
|
|
(void) inb(info->ioaddr + UART_MSR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, initialize the UART
|
|
|
|
*/
|
|
|
|
outb(UART_LCR_WLEN8, info->ioaddr + UART_LCR); /* reset DLAB */
|
|
|
|
info->MCR = UART_MCR_DTR | UART_MCR_RTS;
|
|
|
|
outb(info->MCR, info->ioaddr + UART_MCR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, enable interrupts
|
|
|
|
*/
|
|
|
|
info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
|
|
|
|
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid)
|
2008-02-07 08:16:46 +00:00
|
|
|
info->IER |= MOXA_MUST_IER_EGDAI;
|
|
|
|
outb(info->IER, info->ioaddr + UART_IER); /* enable interrupts */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And clear the interrupt registers again for luck.
|
|
|
|
*/
|
|
|
|
(void) inb(info->ioaddr + UART_LSR);
|
|
|
|
(void) inb(info->ioaddr + UART_RX);
|
|
|
|
(void) inb(info->ioaddr + UART_IIR);
|
|
|
|
(void) inb(info->ioaddr + UART_MSR);
|
|
|
|
|
2008-10-13 09:40:19 +00:00
|
|
|
clear_bit(TTY_IO_ERROR, &tty->flags);
|
2008-02-07 08:16:46 +00:00
|
|
|
info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* and set the speed of the serial port
|
|
|
|
*/
|
2017-09-12 10:39:55 +00:00
|
|
|
mxser_change_speed(tty);
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-11-30 13:17:35 +00:00
|
|
|
* This routine will shutdown a serial port
|
2008-02-07 08:16:46 +00:00
|
|
|
*/
|
2009-11-30 13:17:35 +00:00
|
|
|
static void mxser_shutdown_port(struct tty_port *port)
|
2008-02-07 08:16:46 +00:00
|
|
|
{
|
2009-11-30 13:17:35 +00:00
|
|
|
struct mxser_port *info = container_of(port, struct mxser_port, port);
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clear delta_msr_wait queue to avoid mem leaks: we may free the irq
|
|
|
|
* here so the queue might never be waken up
|
|
|
|
*/
|
2009-09-19 20:13:31 +00:00
|
|
|
wake_up_interruptible(&info->port.delta_msr_wait);
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
/*
|
2009-11-30 13:17:35 +00:00
|
|
|
* Free the xmit buffer, if necessary
|
2008-02-07 08:16:46 +00:00
|
|
|
*/
|
2008-07-16 20:56:10 +00:00
|
|
|
if (info->port.xmit_buf) {
|
|
|
|
free_page((unsigned long) info->port.xmit_buf);
|
|
|
|
info->port.xmit_buf = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
info->IER = 0;
|
|
|
|
outb(0x00, info->ioaddr + UART_IER);
|
|
|
|
|
|
|
|
/* clear Rx/Tx FIFO's */
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid)
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT |
|
|
|
|
MOXA_MUST_FCR_GDA_MODE_ENABLE,
|
|
|
|
info->ioaddr + UART_FCR);
|
|
|
|
else
|
|
|
|
outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
|
|
|
|
info->ioaddr + UART_FCR);
|
|
|
|
|
|
|
|
/* read data port to reset things */
|
|
|
|
(void) inb(info->ioaddr + UART_RX);
|
|
|
|
|
|
|
|
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid)
|
2021-06-18 06:14:48 +00:00
|
|
|
mxser_must_no_sw_flow_control(info->ioaddr);
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called whenever a serial port is opened. It
|
|
|
|
* enables interrupts for a serial port, linking in its async structure into
|
|
|
|
* the IRQ chain. It also performs the serial-specific
|
|
|
|
* initialization for the tty structure.
|
|
|
|
*/
|
|
|
|
static int mxser_open(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
2021-06-18 06:14:56 +00:00
|
|
|
struct tty_port *tport = tty->port;
|
|
|
|
struct mxser_port *port = container_of(tport, struct mxser_port, port);
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:56 +00:00
|
|
|
tty->driver_data = port;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:56 +00:00
|
|
|
return tty_port_open(tport, tty, filp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-30 07:53:59 +00:00
|
|
|
static void mxser_flush_buffer(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
char fcr;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
|
|
|
|
|
|
|
|
fcr = inb(info->ioaddr + UART_FCR);
|
|
|
|
outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
|
|
|
|
info->ioaddr + UART_FCR);
|
|
|
|
outb(fcr, info->ioaddr + UART_FCR);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
|
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-30 13:17:35 +00:00
|
|
|
static void mxser_close_port(struct tty_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-09-19 20:13:21 +00:00
|
|
|
struct mxser_port *info = container_of(port, struct mxser_port, port);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long timeout;
|
|
|
|
/*
|
|
|
|
* At this point we stop accepting input. To do this, we
|
|
|
|
* disable the receive line status interrupts, and tell the
|
|
|
|
* interrupt driver to stop checking the data ready bit in the
|
|
|
|
* line status register.
|
|
|
|
*/
|
|
|
|
info->IER &= ~UART_IER_RLSI;
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid)
|
2005-04-16 22:20:36 +00:00
|
|
|
info->IER &= ~MOXA_MUST_RECV_ISR;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2009-11-30 13:17:35 +00:00
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
|
|
|
/*
|
|
|
|
* Before we drop DTR, make sure the UART transmitter
|
|
|
|
* has completely drained; this is especially
|
|
|
|
* important if there is a transmit FIFO!
|
|
|
|
*/
|
|
|
|
timeout = jiffies + HZ;
|
|
|
|
while (!(inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) {
|
|
|
|
schedule_timeout_interruptible(5);
|
|
|
|
if (time_after(jiffies, timeout))
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-09-19 20:13:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called when the serial port gets closed. First, we
|
|
|
|
* wait for the last remaining data to be sent. Then, we unlink its
|
|
|
|
* async structure from the interrupt chain if necessary, and we free
|
|
|
|
* that IRQ if nothing is left in the chain.
|
|
|
|
*/
|
|
|
|
static void mxser_close(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
struct tty_port *port = &info->port;
|
|
|
|
|
2021-06-18 06:14:38 +00:00
|
|
|
if (info == NULL)
|
2009-09-19 20:13:21 +00:00
|
|
|
return;
|
|
|
|
if (tty_port_close_start(port, tty, filp) == 0)
|
|
|
|
return;
|
2016-01-10 22:51:38 +00:00
|
|
|
info->closing = 1;
|
2009-11-30 13:17:35 +00:00
|
|
|
mutex_lock(&port->mutex);
|
|
|
|
mxser_close_port(port);
|
2009-09-19 20:13:21 +00:00
|
|
|
mxser_flush_buffer(tty);
|
2016-04-10 00:53:25 +00:00
|
|
|
if (tty_port_initialized(port) && C_HUPCL(tty))
|
|
|
|
tty_port_lower_dtr_rts(port);
|
2009-11-30 13:17:35 +00:00
|
|
|
mxser_shutdown_port(port);
|
2016-04-10 00:53:25 +00:00
|
|
|
tty_port_set_initialized(port, 0);
|
2009-11-30 13:17:35 +00:00
|
|
|
mutex_unlock(&port->mutex);
|
2016-01-10 22:51:38 +00:00
|
|
|
info->closing = 0;
|
2009-01-02 13:46:50 +00:00
|
|
|
/* Right now the tty_port set is done outside of the close_end helper
|
|
|
|
as we don't yet have everyone using refcounts */
|
|
|
|
tty_port_close_end(port, tty);
|
|
|
|
tty_port_tty_set(port, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
|
|
|
|
{
|
|
|
|
int c, total = 0;
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-07-16 20:56:10 +00:00
|
|
|
if (!info->port.xmit_buf)
|
2006-06-25 12:47:54 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
while (1) {
|
2006-06-25 12:47:54 +00:00
|
|
|
c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
|
|
|
|
SERIAL_XMIT_SIZE - info->xmit_head));
|
2005-04-16 22:20:36 +00:00
|
|
|
if (c <= 0)
|
|
|
|
break;
|
|
|
|
|
2008-07-16 20:56:10 +00:00
|
|
|
memcpy(info->port.xmit_buf + info->xmit_head, buf, c);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2006-06-25 12:47:54 +00:00
|
|
|
info->xmit_head = (info->xmit_head + c) &
|
|
|
|
(SERIAL_XMIT_SIZE - 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
info->xmit_cnt += c;
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
|
|
|
|
buf += c;
|
|
|
|
count -= c;
|
|
|
|
total += c;
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:19:05 +00:00
|
|
|
if (info->xmit_cnt && !tty->flow.stopped) {
|
2006-06-25 12:47:54 +00:00
|
|
|
if (!tty->hw_stopped ||
|
|
|
|
(info->type == PORT_16550A) ||
|
2021-06-18 06:14:13 +00:00
|
|
|
(info->board->must_hwid)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER & ~UART_IER_THRI, info->ioaddr +
|
|
|
|
UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
info->IER |= UART_IER_THRI;
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2008-04-30 07:54:03 +00:00
|
|
|
static int mxser_put_char(struct tty_struct *tty, unsigned char ch)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-07-16 20:56:10 +00:00
|
|
|
if (!info->port.xmit_buf)
|
2008-04-30 07:54:03 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
|
2008-04-30 07:54:03 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2008-07-16 20:56:10 +00:00
|
|
|
info->port.xmit_buf[info->xmit_head++] = ch;
|
2005-04-16 22:20:36 +00:00
|
|
|
info->xmit_head &= SERIAL_XMIT_SIZE - 1;
|
|
|
|
info->xmit_cnt++;
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
2021-05-05 09:19:05 +00:00
|
|
|
if (!tty->flow.stopped) {
|
2006-06-25 12:47:54 +00:00
|
|
|
if (!tty->hw_stopped ||
|
|
|
|
(info->type == PORT_16550A) ||
|
2021-06-18 06:14:13 +00:00
|
|
|
info->board->must_hwid) {
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
info->IER |= UART_IER_THRI;
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
}
|
|
|
|
}
|
2008-04-30 07:54:03 +00:00
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void mxser_flush_chars(struct tty_struct *tty)
|
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2021-05-05 09:19:05 +00:00
|
|
|
if (info->xmit_cnt <= 0 || tty->flow.stopped || !info->port.xmit_buf ||
|
2008-07-25 08:48:22 +00:00
|
|
|
(tty->hw_stopped && info->type != PORT_16550A &&
|
2021-06-18 06:14:13 +00:00
|
|
|
!info->board->must_hwid))
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
info->IER |= UART_IER_THRI;
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:19:15 +00:00
|
|
|
static unsigned int mxser_write_room(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
|
2008-07-25 08:48:22 +00:00
|
|
|
return ret < 0 ? 0 : ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 09:19:19 +00:00
|
|
|
static unsigned int mxser_chars_in_buffer(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
return info->xmit_cnt;
|
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* friends of mxser_ioctl()
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*/
|
2008-10-13 09:40:19 +00:00
|
|
|
static int mxser_get_serial_info(struct tty_struct *tty,
|
2018-09-12 02:22:06 +00:00
|
|
|
struct serial_struct *ss)
|
2008-02-07 08:16:46 +00:00
|
|
|
{
|
2008-10-13 09:40:19 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2018-09-12 02:22:06 +00:00
|
|
|
struct tty_port *port = &info->port;
|
2021-04-07 10:23:31 +00:00
|
|
|
unsigned int closing_wait, close_delay;
|
2018-09-12 02:22:06 +00:00
|
|
|
|
|
|
|
mutex_lock(&port->mutex);
|
2021-04-07 10:23:31 +00:00
|
|
|
|
|
|
|
close_delay = jiffies_to_msecs(info->port.close_delay) / 10;
|
|
|
|
closing_wait = info->port.closing_wait;
|
|
|
|
if (closing_wait != ASYNC_CLOSING_WAIT_NONE)
|
|
|
|
closing_wait = jiffies_to_msecs(closing_wait) / 10;
|
|
|
|
|
2018-09-12 02:22:06 +00:00
|
|
|
ss->type = info->type,
|
|
|
|
ss->line = tty->index,
|
|
|
|
ss->port = info->ioaddr,
|
|
|
|
ss->irq = info->board->irq,
|
|
|
|
ss->flags = info->port.flags,
|
2021-06-18 06:14:41 +00:00
|
|
|
ss->baud_base = MXSER_BAUD_BASE,
|
2021-04-07 10:23:31 +00:00
|
|
|
ss->close_delay = close_delay;
|
|
|
|
ss->closing_wait = closing_wait;
|
2021-06-18 06:14:42 +00:00
|
|
|
ss->custom_divisor = MXSER_CUSTOM_DIVISOR,
|
2018-09-12 02:22:06 +00:00
|
|
|
mutex_unlock(&port->mutex);
|
2008-02-07 08:16:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-13 09:40:19 +00:00
|
|
|
static int mxser_set_serial_info(struct tty_struct *tty,
|
2018-09-12 02:22:06 +00:00
|
|
|
struct serial_struct *ss)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-10-13 09:40:19 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2009-11-30 13:17:41 +00:00
|
|
|
struct tty_port *port = &info->port;
|
2008-02-07 08:16:51 +00:00
|
|
|
speed_t baud;
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned long sl_flags;
|
2021-04-07 10:23:31 +00:00
|
|
|
unsigned int flags, close_delay, closing_wait;
|
2008-02-07 08:16:46 +00:00
|
|
|
int retval = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-09-12 02:22:06 +00:00
|
|
|
if (tty_io_error(tty))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
mutex_lock(&port->mutex);
|
|
|
|
if (!info->ioaddr) {
|
|
|
|
mutex_unlock(&port->mutex);
|
2008-02-07 08:16:51 +00:00
|
|
|
return -ENODEV;
|
2018-09-12 02:22:06 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-09-12 02:22:06 +00:00
|
|
|
if (ss->irq != info->board->irq ||
|
|
|
|
ss->port != info->ioaddr) {
|
|
|
|
mutex_unlock(&port->mutex);
|
2008-02-07 08:16:51 +00:00
|
|
|
return -EINVAL;
|
2018-09-12 02:22:06 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-11-30 13:17:41 +00:00
|
|
|
flags = port->flags & ASYNC_SPD_MASK;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-04-07 10:23:31 +00:00
|
|
|
close_delay = msecs_to_jiffies(ss->close_delay * 10);
|
|
|
|
closing_wait = ss->closing_wait;
|
|
|
|
if (closing_wait != ASYNC_CLOSING_WAIT_NONE)
|
|
|
|
closing_wait = msecs_to_jiffies(closing_wait * 10);
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
2021-06-18 06:14:41 +00:00
|
|
|
if ((ss->baud_base != MXSER_BAUD_BASE) ||
|
2021-04-07 10:23:31 +00:00
|
|
|
(close_delay != info->port.close_delay) ||
|
2021-04-07 10:23:32 +00:00
|
|
|
(closing_wait != info->port.closing_wait) ||
|
2018-09-12 02:22:06 +00:00
|
|
|
((ss->flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) {
|
|
|
|
mutex_unlock(&port->mutex);
|
2008-02-07 08:16:46 +00:00
|
|
|
return -EPERM;
|
2018-09-12 02:22:06 +00:00
|
|
|
}
|
2008-07-16 20:56:10 +00:00
|
|
|
info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) |
|
2018-09-12 02:22:06 +00:00
|
|
|
(ss->flags & ASYNC_USR_MASK));
|
2008-02-07 08:16:46 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2008-02-07 08:16:46 +00:00
|
|
|
* OK, past this point, all the error checking has been done.
|
|
|
|
* At this point, we start making changes.....
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2009-11-30 13:17:41 +00:00
|
|
|
port->flags = ((port->flags & ~ASYNC_FLAGS) |
|
2018-09-12 02:22:06 +00:00
|
|
|
(ss->flags & ASYNC_FLAGS));
|
2021-04-07 10:23:31 +00:00
|
|
|
port->close_delay = close_delay;
|
|
|
|
port->closing_wait = closing_wait;
|
2009-11-30 13:17:41 +00:00
|
|
|
if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
|
2021-06-18 06:14:41 +00:00
|
|
|
(ss->baud_base != MXSER_BAUD_BASE ||
|
2018-09-12 02:22:06 +00:00
|
|
|
ss->custom_divisor !=
|
2021-06-18 06:14:42 +00:00
|
|
|
MXSER_CUSTOM_DIVISOR)) {
|
2018-09-12 02:22:06 +00:00
|
|
|
if (ss->custom_divisor == 0) {
|
|
|
|
mutex_unlock(&port->mutex);
|
2009-11-30 13:17:41 +00:00
|
|
|
return -EINVAL;
|
2018-09-12 02:22:06 +00:00
|
|
|
}
|
|
|
|
baud = ss->baud_base / ss->custom_divisor;
|
2008-10-13 09:40:19 +00:00
|
|
|
tty_encode_baud_rate(tty, baud, baud);
|
2008-02-07 08:16:51 +00:00
|
|
|
}
|
2007-04-23 21:41:04 +00:00
|
|
|
|
2021-04-07 10:23:32 +00:00
|
|
|
info->type = ss->type;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:55 +00:00
|
|
|
mxser_process_txrx_fifo(info);
|
2021-04-07 10:23:32 +00:00
|
|
|
}
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2016-04-10 00:53:25 +00:00
|
|
|
if (tty_port_initialized(port)) {
|
2009-11-30 13:17:41 +00:00
|
|
|
if (flags != (port->flags & ASYNC_SPD_MASK)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, sl_flags);
|
2017-09-12 10:39:55 +00:00
|
|
|
mxser_change_speed(tty);
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, sl_flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-11-30 13:17:35 +00:00
|
|
|
} else {
|
2009-11-30 13:17:41 +00:00
|
|
|
retval = mxser_activate(port, tty);
|
2009-11-30 13:17:35 +00:00
|
|
|
if (retval == 0)
|
2016-04-10 00:53:25 +00:00
|
|
|
tty_port_set_initialized(port, 1);
|
2009-11-30 13:17:35 +00:00
|
|
|
}
|
2018-09-12 02:22:06 +00:00
|
|
|
mutex_unlock(&port->mutex);
|
2008-02-07 08:16:46 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* mxser_get_lsr_info - get line status register info
|
|
|
|
*
|
|
|
|
* Purpose: Let user call ioctl() to get info when the UART physically
|
|
|
|
* is emptied. On bus types like RS485, the transmitter must
|
|
|
|
* release the bus after transmitting. This must be done when
|
|
|
|
* the transmit shift register is empty, not be done when the
|
|
|
|
* transmit holding register is empty. This functionality
|
|
|
|
* allows an RS485 driver to be written in user space.
|
|
|
|
*/
|
|
|
|
static int mxser_get_lsr_info(struct mxser_port *info,
|
|
|
|
unsigned int __user *value)
|
|
|
|
{
|
|
|
|
unsigned char status;
|
|
|
|
unsigned int result;
|
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
status = inb(info->ioaddr + UART_LSR);
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
|
|
|
|
return put_user(result, value);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-02-14 16:26:14 +00:00
|
|
|
static int mxser_tiocmget(struct tty_struct *tty)
|
2008-02-07 08:16:46 +00:00
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
unsigned char control, status;
|
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-04-10 00:06:48 +00:00
|
|
|
if (tty_io_error(tty))
|
2008-02-07 08:16:46 +00:00
|
|
|
return -EIO;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
control = info->MCR;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
status = inb(info->ioaddr + UART_MSR);
|
|
|
|
if (status & UART_MSR_ANY_DELTA)
|
2008-10-13 09:40:19 +00:00
|
|
|
mxser_check_modem_status(tty, info, status);
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
|
|
|
|
((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
|
|
|
|
((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
|
|
|
|
((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
|
|
|
|
((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
|
|
|
|
((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-02-14 16:26:50 +00:00
|
|
|
static int mxser_tiocmset(struct tty_struct *tty,
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned int set, unsigned int clear)
|
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-04-10 00:06:48 +00:00
|
|
|
if (tty_io_error(tty))
|
2008-02-07 08:16:46 +00:00
|
|
|
return -EIO;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (set & TIOCM_RTS)
|
|
|
|
info->MCR |= UART_MCR_RTS;
|
|
|
|
if (set & TIOCM_DTR)
|
|
|
|
info->MCR |= UART_MCR_DTR;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (clear & TIOCM_RTS)
|
|
|
|
info->MCR &= ~UART_MCR_RTS;
|
|
|
|
if (clear & TIOCM_DTR)
|
|
|
|
info->MCR &= ~UART_MCR_DTR;
|
2006-06-25 12:47:54 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->MCR, info->ioaddr + UART_MCR);
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
static int mxser_cflags_changed(struct mxser_port *info, unsigned long arg,
|
|
|
|
struct async_icount *cprev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct async_icount cnow;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
cnow = info->icount; /* atomic copy */
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
|
|
|
|
((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
|
|
|
|
((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
|
|
|
|
((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
*cprev = cnow;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:44 +00:00
|
|
|
/* We should likely switch to TIOCGRS485/TIOCSRS485. */
|
|
|
|
static int mxser_ioctl_op_mode(struct mxser_port *port, int index, bool set,
|
|
|
|
int __user *u_opmode)
|
|
|
|
{
|
|
|
|
int opmode, p = index % 4;
|
|
|
|
int shiftbit = p * 2;
|
2021-06-18 06:14:45 +00:00
|
|
|
u8 val;
|
2021-06-18 06:14:44 +00:00
|
|
|
|
|
|
|
if (port->board->must_hwid != MOXA_MUST_MU860_HWID)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
if (get_user(opmode, u_opmode))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2021-06-18 06:14:45 +00:00
|
|
|
if (opmode & ~OP_MODE_MASK)
|
|
|
|
return -EINVAL;
|
2021-06-18 06:14:44 +00:00
|
|
|
|
|
|
|
spin_lock_irq(&port->slock);
|
|
|
|
val = inb(port->opmode_ioaddr);
|
2021-06-18 06:14:45 +00:00
|
|
|
val &= ~(OP_MODE_MASK << shiftbit);
|
2021-06-18 06:14:44 +00:00
|
|
|
val |= (opmode << shiftbit);
|
|
|
|
outb(val, port->opmode_ioaddr);
|
|
|
|
spin_unlock_irq(&port->slock);
|
|
|
|
|
2021-06-18 06:14:45 +00:00
|
|
|
return 0;
|
2021-06-18 06:14:44 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:45 +00:00
|
|
|
spin_lock_irq(&port->slock);
|
|
|
|
opmode = inb(port->opmode_ioaddr) >> shiftbit;
|
|
|
|
spin_unlock_irq(&port->slock);
|
|
|
|
|
|
|
|
return put_user(opmode & OP_MODE_MASK, u_opmode);
|
2021-06-18 06:14:44 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 16:27:22 +00:00
|
|
|
static int mxser_ioctl(struct tty_struct *tty,
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned int cmd, unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
struct async_icount cnow;
|
|
|
|
unsigned long flags;
|
|
|
|
void __user *argp = (void __user *)arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:44 +00:00
|
|
|
if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE)
|
|
|
|
return mxser_ioctl_op_mode(info, tty->index,
|
|
|
|
cmd == MOXA_SET_OP_MODE, argp);
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2018-09-12 02:22:06 +00:00
|
|
|
if (cmd != TIOCMIWAIT && tty_io_error(tty))
|
2008-02-07 08:16:46 +00:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TIOCSERGETLSR: /* Get line status register */
|
2008-04-30 07:53:20 +00:00
|
|
|
return mxser_get_lsr_info(info, argp);
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
|
|
|
|
* - mask passed in arg for lines of interest
|
|
|
|
* (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
|
|
|
|
* Caller should use TIOCGICOUNT to see which one it was
|
|
|
|
*/
|
|
|
|
case TIOCMIWAIT:
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
cnow = info->icount; /* note the counters on entry */
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
|
2009-09-19 20:13:31 +00:00
|
|
|
return wait_event_interruptible(info->port.delta_msr_wait,
|
2008-02-07 08:16:46 +00:00
|
|
|
mxser_cflags_changed(info, arg, &cnow));
|
|
|
|
default:
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-16 17:21:52 +00:00
|
|
|
/*
|
|
|
|
* Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
|
|
|
|
* Return: write counters to the user passed counter struct
|
|
|
|
* NB: both 1->0 and 0->1 transitions are counted except for
|
|
|
|
* RI where only 0->1 is counted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int mxser_get_icount(struct tty_struct *tty,
|
|
|
|
struct serial_icounter_struct *icount)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
struct async_icount cnow;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
cnow = info->icount;
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
|
|
|
|
icount->frame = cnow.frame;
|
|
|
|
icount->brk = cnow.brk;
|
|
|
|
icount->overrun = cnow.overrun;
|
|
|
|
icount->buf_overrun = cnow.buf_overrun;
|
|
|
|
icount->parity = cnow.parity;
|
|
|
|
icount->rx = cnow.rx;
|
|
|
|
icount->tx = cnow.tx;
|
|
|
|
icount->cts = cnow.cts;
|
|
|
|
icount->dsr = cnow.dsr;
|
|
|
|
icount->rng = cnow.rng;
|
|
|
|
icount->dcd = cnow.dcd;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
static void mxser_stoprx(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
|
|
|
|
info->ldisc_stop_rx = 1;
|
|
|
|
if (I_IXOFF(tty)) {
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->IER &= ~MOXA_MUST_RECV_ISR;
|
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
|
|
|
} else {
|
|
|
|
info->x_char = STOP_CHAR(tty);
|
|
|
|
outb(0, info->ioaddr + UART_IER);
|
|
|
|
info->IER |= UART_IER_THRI;
|
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 04:36:15 +00:00
|
|
|
if (C_CRTSCTS(tty)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->MCR &= ~UART_MCR_RTS;
|
|
|
|
outb(info->MCR, info->ioaddr + UART_MCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called by the upper-layer tty layer to signal that
|
|
|
|
* incoming characters should be throttled.
|
|
|
|
*/
|
|
|
|
static void mxser_throttle(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
mxser_stoprx(tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxser_unthrottle(struct tty_struct *tty)
|
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/* startrx */
|
|
|
|
info->ldisc_stop_rx = 0;
|
|
|
|
if (I_IXOFF(tty)) {
|
|
|
|
if (info->x_char)
|
|
|
|
info->x_char = 0;
|
|
|
|
else {
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->IER |= MOXA_MUST_RECV_ISR;
|
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
|
|
|
} else {
|
|
|
|
info->x_char = START_CHAR(tty);
|
|
|
|
outb(0, info->ioaddr + UART_IER);
|
|
|
|
info->IER |= UART_IER_THRI;
|
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-01-11 04:36:15 +00:00
|
|
|
if (C_CRTSCTS(tty)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info->MCR |= UART_MCR_RTS;
|
|
|
|
outb(info->MCR, info->ioaddr + UART_MCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mxser_stop() and mxser_start()
|
|
|
|
*
|
2021-05-05 09:19:05 +00:00
|
|
|
* This routines are called before setting or resetting tty->flow.stopped.
|
2005-04-16 22:20:36 +00:00
|
|
|
* They enable or disable transmitter interrupts, as necessary.
|
|
|
|
*/
|
|
|
|
static void mxser_stop(struct tty_struct *tty)
|
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
if (info->IER & UART_IER_THRI) {
|
|
|
|
info->IER &= ~UART_IER_THRI;
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxser_start(struct tty_struct *tty)
|
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2008-07-16 20:56:10 +00:00
|
|
|
if (info->xmit_cnt && info->port.xmit_buf) {
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
info->IER |= UART_IER_THRI;
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(info->IER, info->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
|
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2017-09-12 10:39:55 +00:00
|
|
|
mxser_change_speed(tty);
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
|
2016-01-11 04:36:15 +00:00
|
|
|
if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) {
|
2008-02-07 08:16:46 +00:00
|
|
|
tty->hw_stopped = 0;
|
|
|
|
mxser_start(tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle sw stopped */
|
2016-01-11 04:36:15 +00:00
|
|
|
if ((old_termios->c_iflag & IXON) && !I_IXON(tty)) {
|
2021-05-05 09:19:05 +00:00
|
|
|
tty->flow.stopped = 0;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:13 +00:00
|
|
|
if (info->board->must_hwid) {
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2021-06-18 06:14:48 +00:00
|
|
|
mxser_must_set_rx_sw_flow_control(info->ioaddr, false);
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
mxser_start(tty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* mxser_wait_until_sent() --- wait until the transmitter is empty
|
|
|
|
*/
|
|
|
|
static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
|
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long orig_jiffies, char_time;
|
2009-11-30 13:17:41 +00:00
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
int lsr;
|
|
|
|
|
|
|
|
if (info->type == PORT_UNKNOWN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info->xmit_fifo_size == 0)
|
|
|
|
return; /* Just in case.... */
|
|
|
|
|
|
|
|
orig_jiffies = jiffies;
|
|
|
|
/*
|
|
|
|
* Set the check interval to be 1/5 of the estimated time to
|
|
|
|
* send a single character, and make it at least 1. The check
|
|
|
|
* interval should also be less than the timeout.
|
|
|
|
*
|
|
|
|
* Note: we have to use pretty tight timings here to satisfy
|
|
|
|
* the NIST-PCTS.
|
|
|
|
*/
|
|
|
|
char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
|
|
|
|
char_time = char_time / 5;
|
|
|
|
if (char_time == 0)
|
|
|
|
char_time = 1;
|
|
|
|
if (timeout && timeout < char_time)
|
|
|
|
char_time = timeout;
|
|
|
|
/*
|
|
|
|
* If the transmitter hasn't cleared in twice the approximate
|
|
|
|
* amount of time to send the entire FIFO, it probably won't
|
|
|
|
* ever clear. This assumes the UART isn't doing flow
|
|
|
|
* control, which is currently the case. Hence, if it ever
|
|
|
|
* takes longer than info->timeout, this is probably due to a
|
|
|
|
* UART bug of some kind. So, we clamp the timeout parameter at
|
|
|
|
* 2*info->timeout.
|
|
|
|
*/
|
|
|
|
if (!timeout || timeout > 2 * info->timeout)
|
|
|
|
timeout = 2 * info->timeout;
|
2011-07-14 12:35:15 +00:00
|
|
|
|
2009-11-30 13:17:41 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2008-02-07 08:16:46 +00:00
|
|
|
while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
|
2009-11-30 13:17:41 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
2005-09-10 07:27:30 +00:00
|
|
|
schedule_timeout_interruptible(char_time);
|
2009-11-30 13:17:41 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (signal_pending(current))
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
|
|
|
if (timeout && time_after(jiffies, orig_jiffies + timeout))
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-11-30 13:17:41 +00:00
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
2008-02-07 08:16:46 +00:00
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* This routine is called by tty_hangup() when a hangup is signaled.
|
|
|
|
*/
|
|
|
|
static void mxser_hangup(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
mxser_flush_buffer(tty);
|
2009-01-02 13:45:58 +00:00
|
|
|
tty_port_hangup(&info->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* mxser_rs_break() --- routine which turns the break handling on or off
|
|
|
|
*/
|
2008-07-22 10:18:03 +00:00
|
|
|
static int mxser_rs_break(struct tty_struct *tty, int break_state)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_irqsave(&info->slock, flags);
|
|
|
|
if (break_state == -1)
|
|
|
|
outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
|
|
|
|
info->ioaddr + UART_LCR);
|
|
|
|
else
|
|
|
|
outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
|
|
|
|
info->ioaddr + UART_LCR);
|
|
|
|
spin_unlock_irqrestore(&info->slock, flags);
|
2008-07-22 10:18:03 +00:00
|
|
|
return 0;
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:21 +00:00
|
|
|
static bool mxser_receive_chars_new(struct tty_struct *tty,
|
2021-06-18 06:14:37 +00:00
|
|
|
struct mxser_port *port, u8 status)
|
2021-06-18 06:14:21 +00:00
|
|
|
{
|
|
|
|
enum mxser_must_hwid hwid = port->board->must_hwid;
|
|
|
|
u8 gdl;
|
|
|
|
|
|
|
|
if (hwid == MOXA_OTHER_UART)
|
|
|
|
return false;
|
2021-06-18 06:14:26 +00:00
|
|
|
if (status & UART_LSR_BRK_ERROR_BITS)
|
2021-06-18 06:14:21 +00:00
|
|
|
return false;
|
|
|
|
if (hwid == MOXA_MUST_MU860_HWID && (status & MOXA_MUST_LSR_RERR))
|
|
|
|
return false;
|
|
|
|
if (status & MOXA_MUST_LSR_RERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
gdl = inb(port->ioaddr + MOXA_MUST_GDL_REGISTER);
|
|
|
|
if (hwid == MOXA_MUST_MU150_HWID)
|
|
|
|
gdl &= MOXA_MUST_GDL_MASK;
|
|
|
|
|
|
|
|
if (gdl >= tty->receive_room && !port->ldisc_stop_rx)
|
|
|
|
mxser_stoprx(tty);
|
|
|
|
|
|
|
|
while (gdl--) {
|
|
|
|
u8 ch = inb(port->ioaddr + UART_RX);
|
|
|
|
tty_insert_flip_char(&port->port, ch, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:22 +00:00
|
|
|
static u8 mxser_receive_chars_old(struct tty_struct *tty,
|
2021-06-18 06:14:37 +00:00
|
|
|
struct mxser_port *port, u8 status)
|
2008-02-07 08:16:46 +00:00
|
|
|
{
|
2021-06-18 06:14:22 +00:00
|
|
|
enum mxser_must_hwid hwid = port->board->must_hwid;
|
|
|
|
int recv_room = tty->receive_room;
|
2008-02-07 08:16:46 +00:00
|
|
|
int ignored = 0;
|
|
|
|
int max = 256;
|
2021-06-18 06:14:37 +00:00
|
|
|
int cnt = 0;
|
2021-06-18 06:14:22 +00:00
|
|
|
u8 ch;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (max-- < 0)
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
ch = inb(port->ioaddr + UART_RX);
|
2021-06-18 06:14:22 +00:00
|
|
|
if (hwid && (status & UART_LSR_OE))
|
2008-02-07 08:16:46 +00:00
|
|
|
outb(0x23, port->ioaddr + UART_FCR);
|
2021-06-18 06:14:18 +00:00
|
|
|
status &= port->read_status_mask;
|
|
|
|
if (status & port->ignore_status_mask) {
|
2008-02-07 08:16:46 +00:00
|
|
|
if (++ignored > 100)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
char flag = 0;
|
2021-06-18 06:14:26 +00:00
|
|
|
if (status & UART_LSR_BRK_ERROR_BITS) {
|
2021-06-18 06:14:18 +00:00
|
|
|
if (status & UART_LSR_BI) {
|
2008-02-07 08:16:46 +00:00
|
|
|
flag = TTY_BREAK;
|
|
|
|
port->icount.brk++;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-16 20:56:10 +00:00
|
|
|
if (port->port.flags & ASYNC_SAK)
|
2008-02-07 08:16:46 +00:00
|
|
|
do_SAK(tty);
|
2021-06-18 06:14:18 +00:00
|
|
|
} else if (status & UART_LSR_PE) {
|
2008-02-07 08:16:46 +00:00
|
|
|
flag = TTY_PARITY;
|
|
|
|
port->icount.parity++;
|
2021-06-18 06:14:18 +00:00
|
|
|
} else if (status & UART_LSR_FE) {
|
2008-02-07 08:16:46 +00:00
|
|
|
flag = TTY_FRAME;
|
|
|
|
port->icount.frame++;
|
2021-06-18 06:14:18 +00:00
|
|
|
} else if (status & UART_LSR_OE) {
|
2008-02-07 08:16:46 +00:00
|
|
|
flag = TTY_OVERRUN;
|
|
|
|
port->icount.overrun++;
|
2021-06-18 06:14:23 +00:00
|
|
|
}
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
2013-01-03 14:53:03 +00:00
|
|
|
tty_insert_flip_char(&port->port, ch, flag);
|
2021-06-18 06:14:37 +00:00
|
|
|
cnt++;
|
|
|
|
if (cnt >= recv_room) {
|
2008-02-07 08:16:46 +00:00
|
|
|
if (!port->ldisc_stop_rx)
|
|
|
|
mxser_stoprx(tty);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:22 +00:00
|
|
|
if (hwid)
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:18 +00:00
|
|
|
status = inb(port->ioaddr + UART_LSR);
|
|
|
|
} while (status & UART_LSR_DR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:22 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 mxser_receive_chars(struct tty_struct *tty,
|
|
|
|
struct mxser_port *port, u8 status)
|
|
|
|
{
|
|
|
|
if (tty->receive_room == 0 && !port->ldisc_stop_rx)
|
|
|
|
mxser_stoprx(tty);
|
|
|
|
|
2021-06-18 06:14:37 +00:00
|
|
|
if (!mxser_receive_chars_new(tty, port, status))
|
|
|
|
status = mxser_receive_chars_old(tty, port, status);
|
2021-06-18 06:14:22 +00:00
|
|
|
|
2013-01-03 14:53:06 +00:00
|
|
|
tty_flip_buffer_push(&port->port);
|
2021-06-18 06:14:18 +00:00
|
|
|
|
|
|
|
return status;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 09:40:19 +00:00
|
|
|
static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
int count, cnt;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
if (port->x_char) {
|
|
|
|
outb(port->x_char, port->ioaddr + UART_TX);
|
|
|
|
port->x_char = 0;
|
|
|
|
port->icount.tx++;
|
|
|
|
return;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-16 20:56:10 +00:00
|
|
|
if (port->port.xmit_buf == NULL)
|
2008-02-07 08:16:46 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-05-05 09:19:05 +00:00
|
|
|
if (port->xmit_cnt <= 0 || tty->flow.stopped ||
|
2008-10-13 09:40:19 +00:00
|
|
|
(tty->hw_stopped &&
|
2008-02-07 08:16:46 +00:00
|
|
|
(port->type != PORT_16550A) &&
|
2021-06-18 06:14:13 +00:00
|
|
|
(!port->board->must_hwid))) {
|
2008-02-07 08:16:46 +00:00
|
|
|
port->IER &= ~UART_IER_THRI;
|
|
|
|
outb(port->IER, port->ioaddr + UART_IER);
|
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
cnt = port->xmit_cnt;
|
|
|
|
count = port->xmit_fifo_size;
|
|
|
|
do {
|
2008-07-16 20:56:10 +00:00
|
|
|
outb(port->port.xmit_buf[port->xmit_tail++],
|
2008-02-07 08:16:46 +00:00
|
|
|
port->ioaddr + UART_TX);
|
|
|
|
port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE - 1);
|
|
|
|
if (--port->xmit_cnt <= 0)
|
|
|
|
break;
|
|
|
|
} while (--count > 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
port->icount.tx += (cnt - port->xmit_cnt);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-07-23 16:34:53 +00:00
|
|
|
if (port->xmit_cnt < WAKEUP_CHARS)
|
2008-10-13 09:40:19 +00:00
|
|
|
tty_wakeup(tty);
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
if (port->xmit_cnt <= 0) {
|
|
|
|
port->IER &= ~UART_IER_THRI;
|
|
|
|
outb(port->IER, port->ioaddr + UART_IER);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:19 +00:00
|
|
|
static bool mxser_port_isr(struct mxser_port *port)
|
|
|
|
{
|
|
|
|
struct tty_struct *tty;
|
|
|
|
u8 iir, msr, status;
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
iir = inb(port->ioaddr + UART_IIR);
|
|
|
|
if (iir & UART_IIR_NO_INT)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
iir &= MOXA_MUST_IIR_MASK;
|
|
|
|
tty = tty_port_tty_get(&port->port);
|
|
|
|
if (!tty || port->closing || !tty_port_initialized(&port->port)) {
|
|
|
|
status = inb(port->ioaddr + UART_LSR);
|
|
|
|
outb(0x27, port->ioaddr + UART_FCR);
|
|
|
|
inb(port->ioaddr + UART_MSR);
|
|
|
|
|
|
|
|
error = true;
|
|
|
|
goto put_tty;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = inb(port->ioaddr + UART_LSR);
|
|
|
|
|
|
|
|
if (port->board->must_hwid) {
|
|
|
|
if (iir == MOXA_MUST_IIR_GDA ||
|
|
|
|
iir == MOXA_MUST_IIR_RDA ||
|
|
|
|
iir == MOXA_MUST_IIR_RTO ||
|
|
|
|
iir == MOXA_MUST_IIR_LSR)
|
|
|
|
status = mxser_receive_chars(tty, port, status);
|
|
|
|
} else {
|
|
|
|
status &= port->read_status_mask;
|
|
|
|
if (status & UART_LSR_DR)
|
|
|
|
status = mxser_receive_chars(tty, port, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
msr = inb(port->ioaddr + UART_MSR);
|
|
|
|
if (msr & UART_MSR_ANY_DELTA)
|
|
|
|
mxser_check_modem_status(tty, port, msr);
|
|
|
|
|
|
|
|
if (port->board->must_hwid) {
|
|
|
|
if (iir == 0x02 && (status & UART_LSR_THRE))
|
|
|
|
mxser_transmit_chars(tty, port);
|
|
|
|
} else {
|
|
|
|
if (status & UART_LSR_THRE)
|
|
|
|
mxser_transmit_chars(tty, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
put_tty:
|
|
|
|
tty_kref_put(tty);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2008-02-07 08:16:46 +00:00
|
|
|
* This is the serial driver's generic interrupt routine
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2008-02-07 08:16:46 +00:00
|
|
|
static irqreturn_t mxser_interrupt(int irq, void *dev_id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-06-18 06:14:17 +00:00
|
|
|
struct mxser_board *brd = dev_id;
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *port;
|
|
|
|
unsigned int int_cnt, pass_counter = 0;
|
2021-06-18 06:14:54 +00:00
|
|
|
unsigned int i, max = brd->nports;
|
2008-02-07 08:16:46 +00:00
|
|
|
int handled = IRQ_NONE;
|
2021-06-18 06:14:20 +00:00
|
|
|
u8 irqbits, bits, mask = BIT(max) - 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
while (pass_counter++ < MXSER_ISR_PASS_LIMIT) {
|
2021-06-18 06:14:20 +00:00
|
|
|
irqbits = inb(brd->vector) & mask;
|
|
|
|
if (irqbits == mask)
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
|
2021-06-18 06:14:20 +00:00
|
|
|
if (irqbits == mask)
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
|
|
|
if (bits & irqbits)
|
|
|
|
continue;
|
|
|
|
port = &brd->ports[i];
|
|
|
|
|
|
|
|
int_cnt = 0;
|
|
|
|
spin_lock(&port->slock);
|
|
|
|
do {
|
2021-06-18 06:14:19 +00:00
|
|
|
if (mxser_port_isr(port))
|
2008-02-07 08:16:46 +00:00
|
|
|
break;
|
|
|
|
} while (int_cnt++ < MXSER_ISR_PASS_LIMIT);
|
|
|
|
spin_unlock(&port->slock);
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
return handled;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
static const struct tty_operations mxser_ops = {
|
|
|
|
.open = mxser_open,
|
|
|
|
.close = mxser_close,
|
|
|
|
.write = mxser_write,
|
|
|
|
.put_char = mxser_put_char,
|
|
|
|
.flush_chars = mxser_flush_chars,
|
|
|
|
.write_room = mxser_write_room,
|
|
|
|
.chars_in_buffer = mxser_chars_in_buffer,
|
|
|
|
.flush_buffer = mxser_flush_buffer,
|
|
|
|
.ioctl = mxser_ioctl,
|
|
|
|
.throttle = mxser_throttle,
|
|
|
|
.unthrottle = mxser_unthrottle,
|
|
|
|
.set_termios = mxser_set_termios,
|
|
|
|
.stop = mxser_stop,
|
|
|
|
.start = mxser_start,
|
|
|
|
.hangup = mxser_hangup,
|
|
|
|
.break_ctl = mxser_rs_break,
|
|
|
|
.wait_until_sent = mxser_wait_until_sent,
|
|
|
|
.tiocmget = mxser_tiocmget,
|
|
|
|
.tiocmset = mxser_tiocmset,
|
2018-09-12 02:22:06 +00:00
|
|
|
.set_serial = mxser_set_serial_info,
|
|
|
|
.get_serial = mxser_get_serial_info,
|
2010-09-16 17:21:52 +00:00
|
|
|
.get_icount = mxser_get_icount,
|
2008-02-07 08:16:46 +00:00
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-12-14 23:53:36 +00:00
|
|
|
static const struct tty_port_operations mxser_port_ops = {
|
2009-01-02 13:45:05 +00:00
|
|
|
.carrier_raised = mxser_carrier_raised,
|
2009-06-11 11:24:17 +00:00
|
|
|
.dtr_rts = mxser_dtr_rts,
|
2009-11-30 13:17:35 +00:00
|
|
|
.activate = mxser_activate,
|
|
|
|
.shutdown = mxser_shutdown_port,
|
2009-01-02 13:45:05 +00:00
|
|
|
};
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/*
|
|
|
|
* The MOXA Smartio/Industio serial driver boot-time initialization code!
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:54 +00:00
|
|
|
static void mxser_initbrd(struct mxser_board *brd, bool high_baud)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_port *info;
|
|
|
|
unsigned int i;
|
2021-06-18 06:14:49 +00:00
|
|
|
bool is_mu860;
|
|
|
|
|
|
|
|
brd->must_hwid = mxser_must_get_hwid(brd->ports[0].ioaddr);
|
|
|
|
is_mu860 = brd->must_hwid == MOXA_MUST_MU860_HWID;
|
|
|
|
|
|
|
|
for (i = 0; i < UART_INFO_NUM; i++) {
|
|
|
|
if (Gpci_uart_info[i].type == brd->must_hwid) {
|
|
|
|
brd->max_baud = Gpci_uart_info[i].max_baud;
|
|
|
|
|
|
|
|
/* exception....CP-102 */
|
2021-06-18 06:14:54 +00:00
|
|
|
if (high_baud)
|
2021-06-18 06:14:49 +00:00
|
|
|
brd->max_baud = 921600;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_mu860) {
|
|
|
|
/* set to RS232 mode by default */
|
|
|
|
outb(0, brd->vector + 4);
|
|
|
|
outb(0, brd->vector + 0x0c);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:54 +00:00
|
|
|
for (i = 0; i < brd->nports; i++) {
|
2008-02-07 08:16:46 +00:00
|
|
|
info = &brd->ports[i];
|
2021-06-18 06:14:49 +00:00
|
|
|
if (is_mu860) {
|
|
|
|
if (i < 4)
|
|
|
|
info->opmode_ioaddr = brd->vector + 4;
|
|
|
|
else
|
|
|
|
info->opmode_ioaddr = brd->vector + 0x0c;
|
|
|
|
}
|
2008-07-16 20:57:18 +00:00
|
|
|
tty_port_init(&info->port);
|
2009-01-02 13:45:05 +00:00
|
|
|
info->port.ops = &mxser_port_ops;
|
2008-02-07 08:16:46 +00:00
|
|
|
info->board = brd;
|
|
|
|
info->ldisc_stop_rx = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/* Enhance mode enabled here */
|
2021-06-18 06:14:13 +00:00
|
|
|
if (brd->must_hwid != MOXA_OTHER_UART)
|
2021-06-18 06:14:46 +00:00
|
|
|
mxser_must_set_enhance_mode(info->ioaddr, true);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:15 +00:00
|
|
|
info->type = PORT_16550A;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:55 +00:00
|
|
|
mxser_process_txrx_fifo(info);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-16 20:57:18 +00:00
|
|
|
info->port.close_delay = 5 * HZ / 10;
|
|
|
|
info->port.closing_wait = 30 * HZ;
|
2008-02-07 08:16:46 +00:00
|
|
|
spin_lock_init(&info->slock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
/* before set INT ISR, disable all int */
|
|
|
|
outb(inb(info->ioaddr + UART_IER) & 0xf0,
|
|
|
|
info->ioaddr + UART_IER);
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-19 18:21:50 +00:00
|
|
|
static int mxser_probe(struct pci_dev *pdev,
|
2008-02-07 08:16:46 +00:00
|
|
|
const struct pci_device_id *ent)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_board *brd;
|
2021-06-18 06:14:57 +00:00
|
|
|
unsigned int i, base;
|
2008-02-07 08:16:46 +00:00
|
|
|
unsigned long ioaddress;
|
2021-06-18 06:14:54 +00:00
|
|
|
unsigned short nports = MXSER_NPORTS(ent->driver_data);
|
2013-02-16 22:24:37 +00:00
|
|
|
struct device *tty_dev;
|
2008-02-07 08:16:46 +00:00
|
|
|
int retval = -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:58 +00:00
|
|
|
i = find_first_zero_bit(mxser_boards, MXSER_BOARDS);
|
2008-02-07 08:16:46 +00:00
|
|
|
if (i >= MXSER_BOARDS) {
|
2008-07-25 08:48:21 +00:00
|
|
|
dev_err(&pdev->dev, "too many boards found (maximum %d), board "
|
|
|
|
"not configured\n", MXSER_BOARDS);
|
2008-02-07 08:16:46 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:14:59 +00:00
|
|
|
brd = devm_kzalloc(&pdev->dev, struct_size(brd, ports, nports),
|
|
|
|
GFP_KERNEL);
|
2021-06-18 06:14:58 +00:00
|
|
|
if (!brd)
|
|
|
|
goto err;
|
|
|
|
|
2021-06-18 06:14:57 +00:00
|
|
|
brd->idx = i;
|
2021-06-18 06:14:58 +00:00
|
|
|
__set_bit(brd->idx, mxser_boards);
|
2021-06-18 06:14:57 +00:00
|
|
|
base = i * MXSER_PORTS_PER_BOARD;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:51 +00:00
|
|
|
retval = pcim_enable_device(pdev);
|
2008-02-07 08:16:46 +00:00
|
|
|
if (retval) {
|
2008-07-25 08:48:21 +00:00
|
|
|
dev_err(&pdev->dev, "PCI enable failed\n");
|
2021-06-18 06:14:58 +00:00
|
|
|
goto err_zero;
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* io address */
|
|
|
|
ioaddress = pci_resource_start(pdev, 2);
|
|
|
|
retval = pci_request_region(pdev, 2, "mxser(IO)");
|
|
|
|
if (retval)
|
2021-06-18 06:14:58 +00:00
|
|
|
goto err_zero;
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:54 +00:00
|
|
|
brd->nports = nports;
|
|
|
|
for (i = 0; i < nports; i++)
|
2008-02-07 08:16:46 +00:00
|
|
|
brd->ports[i].ioaddr = ioaddress + 8 * i;
|
|
|
|
|
|
|
|
/* vector */
|
|
|
|
ioaddress = pci_resource_start(pdev, 3);
|
|
|
|
retval = pci_request_region(pdev, 3, "mxser(vector)");
|
|
|
|
if (retval)
|
2010-09-03 08:31:37 +00:00
|
|
|
goto err_zero;
|
2008-02-07 08:16:46 +00:00
|
|
|
brd->vector = ioaddress;
|
|
|
|
|
|
|
|
/* irq */
|
|
|
|
brd->irq = pdev->irq;
|
|
|
|
|
2021-06-18 06:14:54 +00:00
|
|
|
mxser_initbrd(brd, ent->driver_data & MXSER_HIGHBAUD);
|
2021-06-18 06:14:52 +00:00
|
|
|
|
|
|
|
retval = devm_request_irq(&pdev->dev, brd->irq, mxser_interrupt,
|
|
|
|
IRQF_SHARED, "mxser", brd);
|
|
|
|
if (retval) {
|
|
|
|
dev_err(&pdev->dev, "request irq failed");
|
|
|
|
goto err_relbrd;
|
|
|
|
}
|
2008-02-07 08:16:46 +00:00
|
|
|
|
2021-06-18 06:14:54 +00:00
|
|
|
for (i = 0; i < nports; i++) {
|
2013-02-16 22:24:37 +00:00
|
|
|
tty_dev = tty_port_register_device(&brd->ports[i].port,
|
2021-06-18 06:14:57 +00:00
|
|
|
mxvar_sdriver, base + i, &pdev->dev);
|
2013-02-16 22:24:37 +00:00
|
|
|
if (IS_ERR(tty_dev)) {
|
|
|
|
retval = PTR_ERR(tty_dev);
|
2013-04-07 19:46:47 +00:00
|
|
|
for (; i > 0; i--)
|
2013-02-16 22:24:37 +00:00
|
|
|
tty_unregister_device(mxvar_sdriver,
|
2021-06-18 06:14:57 +00:00
|
|
|
base + i - 1);
|
2013-02-16 22:24:37 +00:00
|
|
|
goto err_relbrd;
|
|
|
|
}
|
|
|
|
}
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
pci_set_drvdata(pdev, brd);
|
|
|
|
|
|
|
|
return 0;
|
2013-02-16 22:24:37 +00:00
|
|
|
err_relbrd:
|
2021-06-18 06:14:54 +00:00
|
|
|
for (i = 0; i < nports; i++)
|
2013-02-16 22:24:37 +00:00
|
|
|
tty_port_destroy(&brd->ports[i].port);
|
2010-09-03 08:31:37 +00:00
|
|
|
err_zero:
|
2021-06-18 06:14:58 +00:00
|
|
|
__clear_bit(brd->idx, mxser_boards);
|
2008-02-07 08:16:46 +00:00
|
|
|
err:
|
|
|
|
return retval;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:18 +00:00
|
|
|
static void mxser_remove(struct pci_dev *pdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-07 08:16:46 +00:00
|
|
|
struct mxser_board *brd = pci_get_drvdata(pdev);
|
2021-06-18 06:14:57 +00:00
|
|
|
unsigned int i, base = brd->idx * MXSER_PORTS_PER_BOARD;
|
2021-06-18 06:14:50 +00:00
|
|
|
|
2021-06-18 06:14:54 +00:00
|
|
|
for (i = 0; i < brd->nports; i++) {
|
2021-06-18 06:14:57 +00:00
|
|
|
tty_unregister_device(mxvar_sdriver, base + i);
|
2021-06-18 06:14:50 +00:00
|
|
|
tty_port_destroy(&brd->ports[i].port);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:58 +00:00
|
|
|
__clear_bit(brd->idx, mxser_boards);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:16:46 +00:00
|
|
|
static struct pci_driver mxser_driver = {
|
|
|
|
.name = "mxser",
|
|
|
|
.id_table = mxser_pcibrds,
|
|
|
|
.probe = mxser_probe,
|
2012-11-19 18:21:06 +00:00
|
|
|
.remove = mxser_remove
|
2008-02-07 08:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mxser_module_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-25 08:48:22 +00:00
|
|
|
int retval;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-18 06:14:38 +00:00
|
|
|
mxvar_sdriver = alloc_tty_driver(MXSER_PORTS);
|
2008-02-07 08:16:46 +00:00
|
|
|
if (!mxvar_sdriver)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Initialize the tty_driver structure */
|
|
|
|
mxvar_sdriver->name = "ttyMI";
|
|
|
|
mxvar_sdriver->major = ttymajor;
|
|
|
|
mxvar_sdriver->minor_start = 0;
|
|
|
|
mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
|
|
|
|
mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
|
|
|
|
mxvar_sdriver->init_termios = tty_std_termios;
|
|
|
|
mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
|
|
|
|
mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV;
|
|
|
|
tty_set_operations(mxvar_sdriver, &mxser_ops);
|
|
|
|
|
|
|
|
retval = tty_register_driver(mxvar_sdriver);
|
|
|
|
if (retval) {
|
|
|
|
printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family "
|
|
|
|
"tty driver !\n");
|
|
|
|
goto err_put;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-02-07 08:16:46 +00:00
|
|
|
|
|
|
|
retval = pci_register_driver(&mxser_driver);
|
|
|
|
if (retval) {
|
2008-07-25 08:48:21 +00:00
|
|
|
printk(KERN_ERR "mxser: can't register pci driver\n");
|
2021-06-18 06:14:07 +00:00
|
|
|
goto err_unr;
|
2008-02-07 08:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err_unr:
|
|
|
|
tty_unregister_driver(mxvar_sdriver);
|
|
|
|
err_put:
|
|
|
|
put_tty_driver(mxvar_sdriver);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mxser_module_exit(void)
|
|
|
|
{
|
|
|
|
pci_unregister_driver(&mxser_driver);
|
|
|
|
tty_unregister_driver(mxvar_sdriver);
|
|
|
|
put_tty_driver(mxvar_sdriver);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mxser_module_init);
|
|
|
|
module_exit(mxser_module_exit);
|