1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
2a6afd9f3SGreg Kroah-Hartman /*
3a6afd9f3SGreg Kroah-Hartman * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
4a6afd9f3SGreg Kroah-Hartman *
5a6afd9f3SGreg Kroah-Hartman * Copyright (C) 1999-2006 Moxa Technologies ([email protected]).
6a6afd9f3SGreg Kroah-Hartman * Copyright (C) 2006-2008 Jiri Slaby <[email protected]>
7a6afd9f3SGreg Kroah-Hartman *
8a6afd9f3SGreg Kroah-Hartman * This code is loosely based on the 1.8 moxa driver which is based on
9a6afd9f3SGreg Kroah-Hartman * Linux serial driver, written by Linus Torvalds, Theodore T'so and
10a6afd9f3SGreg Kroah-Hartman * others.
11a6afd9f3SGreg Kroah-Hartman *
12a6afd9f3SGreg Kroah-Hartman * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
13a6afd9f3SGreg Kroah-Hartman * <[email protected]>. The original 1.8 code is available on
14a6afd9f3SGreg Kroah-Hartman * www.moxa.com.
15a6afd9f3SGreg Kroah-Hartman * - Fixed x86_64 cleanness
16a6afd9f3SGreg Kroah-Hartman */
17a6afd9f3SGreg Kroah-Hartman
18a6afd9f3SGreg Kroah-Hartman #include <linux/module.h>
19a6afd9f3SGreg Kroah-Hartman #include <linux/errno.h>
20a6afd9f3SGreg Kroah-Hartman #include <linux/signal.h>
21a6afd9f3SGreg Kroah-Hartman #include <linux/sched.h>
22a6afd9f3SGreg Kroah-Hartman #include <linux/timer.h>
23a6afd9f3SGreg Kroah-Hartman #include <linux/interrupt.h>
24a6afd9f3SGreg Kroah-Hartman #include <linux/tty.h>
25a6afd9f3SGreg Kroah-Hartman #include <linux/tty_flip.h>
26a6afd9f3SGreg Kroah-Hartman #include <linux/serial.h>
27a6afd9f3SGreg Kroah-Hartman #include <linux/serial_reg.h>
28a6afd9f3SGreg Kroah-Hartman #include <linux/major.h>
29a6afd9f3SGreg Kroah-Hartman #include <linux/string.h>
30a6afd9f3SGreg Kroah-Hartman #include <linux/fcntl.h>
31a6afd9f3SGreg Kroah-Hartman #include <linux/ptrace.h>
32a6afd9f3SGreg Kroah-Hartman #include <linux/ioport.h>
33a6afd9f3SGreg Kroah-Hartman #include <linux/mm.h>
34a6afd9f3SGreg Kroah-Hartman #include <linux/delay.h>
35a6afd9f3SGreg Kroah-Hartman #include <linux/pci.h>
36a6afd9f3SGreg Kroah-Hartman #include <linux/bitops.h>
37a6afd9f3SGreg Kroah-Hartman #include <linux/slab.h>
385a3c6b25SManuel Zerpies #include <linux/ratelimit.h>
39a6afd9f3SGreg Kroah-Hartman
40a6afd9f3SGreg Kroah-Hartman #include <asm/io.h>
41a6afd9f3SGreg Kroah-Hartman #include <asm/irq.h>
427c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
43a6afd9f3SGreg Kroah-Hartman
444463cc5bSJiri Slaby /*
454463cc5bSJiri Slaby * Semi-public control interfaces
464463cc5bSJiri Slaby */
474463cc5bSJiri Slaby
484463cc5bSJiri Slaby /*
494463cc5bSJiri Slaby * MOXA ioctls
504463cc5bSJiri Slaby */
514463cc5bSJiri Slaby
524463cc5bSJiri Slaby #define MOXA 0x400
534463cc5bSJiri Slaby #define MOXA_SET_OP_MODE (MOXA + 66)
544463cc5bSJiri Slaby #define MOXA_GET_OP_MODE (MOXA + 67)
554463cc5bSJiri Slaby
564463cc5bSJiri Slaby #define RS232_MODE 0
574463cc5bSJiri Slaby #define RS485_2WIRE_MODE 1
584463cc5bSJiri Slaby #define RS422_MODE 2
594463cc5bSJiri Slaby #define RS485_4WIRE_MODE 3
604463cc5bSJiri Slaby #define OP_MODE_MASK 3
614463cc5bSJiri Slaby
624463cc5bSJiri Slaby /* --------------------------------------------------- */
634463cc5bSJiri Slaby
644463cc5bSJiri Slaby /*
654463cc5bSJiri Slaby * Follow just what Moxa Must chip defines.
664463cc5bSJiri Slaby *
67464fbf6cSJiri Slaby * When LCR register (offset 0x03) is written the following value, the Must chip
68464fbf6cSJiri Slaby * will enter enhanced mode. And a write to EFR (offset 0x02) bit 6,7 will
694463cc5bSJiri Slaby * change bank.
704463cc5bSJiri Slaby */
71464fbf6cSJiri Slaby #define MOXA_MUST_ENTER_ENHANCED 0xBF
724463cc5bSJiri Slaby
73464fbf6cSJiri Slaby /* when enhanced mode is enabled, access to general bank register */
744463cc5bSJiri Slaby #define MOXA_MUST_GDL_REGISTER 0x07
754463cc5bSJiri Slaby #define MOXA_MUST_GDL_MASK 0x7F
764463cc5bSJiri Slaby #define MOXA_MUST_GDL_HAS_BAD_DATA 0x80
774463cc5bSJiri Slaby
784463cc5bSJiri Slaby #define MOXA_MUST_LSR_RERR 0x80 /* error in receive FIFO */
79464fbf6cSJiri Slaby /* enhanced register bank select and enhanced mode setting register */
80464fbf6cSJiri Slaby /* This works only when LCR register equals to 0xBF */
814463cc5bSJiri Slaby #define MOXA_MUST_EFR_REGISTER 0x02
82464fbf6cSJiri Slaby #define MOXA_MUST_EFR_EFRB_ENABLE 0x10 /* enhanced mode enable */
83464fbf6cSJiri Slaby /* enhanced register bank set 0, 1, 2 */
844463cc5bSJiri Slaby #define MOXA_MUST_EFR_BANK0 0x00
854463cc5bSJiri Slaby #define MOXA_MUST_EFR_BANK1 0x40
864463cc5bSJiri Slaby #define MOXA_MUST_EFR_BANK2 0x80
874463cc5bSJiri Slaby #define MOXA_MUST_EFR_BANK3 0xC0
884463cc5bSJiri Slaby #define MOXA_MUST_EFR_BANK_MASK 0xC0
894463cc5bSJiri Slaby
904463cc5bSJiri Slaby /* set XON1 value register, when LCR=0xBF and change to bank0 */
914463cc5bSJiri Slaby #define MOXA_MUST_XON1_REGISTER 0x04
924463cc5bSJiri Slaby
934463cc5bSJiri Slaby /* set XON2 value register, when LCR=0xBF and change to bank0 */
944463cc5bSJiri Slaby #define MOXA_MUST_XON2_REGISTER 0x05
954463cc5bSJiri Slaby
964463cc5bSJiri Slaby /* set XOFF1 value register, when LCR=0xBF and change to bank0 */
974463cc5bSJiri Slaby #define MOXA_MUST_XOFF1_REGISTER 0x06
984463cc5bSJiri Slaby
994463cc5bSJiri Slaby /* set XOFF2 value register, when LCR=0xBF and change to bank0 */
1004463cc5bSJiri Slaby #define MOXA_MUST_XOFF2_REGISTER 0x07
1014463cc5bSJiri Slaby
1024463cc5bSJiri Slaby #define MOXA_MUST_RBRTL_REGISTER 0x04
1034463cc5bSJiri Slaby #define MOXA_MUST_RBRTH_REGISTER 0x05
1044463cc5bSJiri Slaby #define MOXA_MUST_RBRTI_REGISTER 0x06
1054463cc5bSJiri Slaby #define MOXA_MUST_THRTL_REGISTER 0x07
1064463cc5bSJiri Slaby #define MOXA_MUST_ENUM_REGISTER 0x04
1074463cc5bSJiri Slaby #define MOXA_MUST_HWID_REGISTER 0x05
1084463cc5bSJiri Slaby #define MOXA_MUST_ECR_REGISTER 0x06
1094463cc5bSJiri Slaby #define MOXA_MUST_CSR_REGISTER 0x07
1104463cc5bSJiri Slaby
1114463cc5bSJiri Slaby #define MOXA_MUST_FCR_GDA_MODE_ENABLE 0x20 /* good data mode enable */
1124463cc5bSJiri Slaby #define MOXA_MUST_FCR_GDA_ONLY_ENABLE 0x10 /* only good data put into RxFIFO */
1134463cc5bSJiri Slaby
1144463cc5bSJiri Slaby #define MOXA_MUST_IER_ECTSI 0x80 /* enable CTS interrupt */
1154463cc5bSJiri Slaby #define MOXA_MUST_IER_ERTSI 0x40 /* enable RTS interrupt */
1164463cc5bSJiri Slaby #define MOXA_MUST_IER_XINT 0x20 /* enable Xon/Xoff interrupt */
1174463cc5bSJiri Slaby #define MOXA_MUST_IER_EGDAI 0x10 /* enable GDA interrupt */
1184463cc5bSJiri Slaby
1194463cc5bSJiri Slaby #define MOXA_MUST_RECV_ISR (UART_IER_RDI | MOXA_MUST_IER_EGDAI)
1204463cc5bSJiri Slaby
1214463cc5bSJiri Slaby /* GDA interrupt pending */
1224463cc5bSJiri Slaby #define MOXA_MUST_IIR_GDA 0x1C
1234463cc5bSJiri Slaby #define MOXA_MUST_IIR_RDA 0x04
1244463cc5bSJiri Slaby #define MOXA_MUST_IIR_RTO 0x0C
1254463cc5bSJiri Slaby #define MOXA_MUST_IIR_LSR 0x06
1264463cc5bSJiri Slaby
1274463cc5bSJiri Slaby /* received Xon/Xoff or specical interrupt pending */
1284463cc5bSJiri Slaby #define MOXA_MUST_IIR_XSC 0x10
1294463cc5bSJiri Slaby
1304463cc5bSJiri Slaby /* RTS/CTS change state interrupt pending */
1314463cc5bSJiri Slaby #define MOXA_MUST_IIR_RTSCTS 0x20
1324463cc5bSJiri Slaby #define MOXA_MUST_IIR_MASK 0x3E
1334463cc5bSJiri Slaby
1344463cc5bSJiri Slaby #define MOXA_MUST_MCR_XON_FLAG 0x40
1354463cc5bSJiri Slaby #define MOXA_MUST_MCR_XON_ANY 0x80
1364463cc5bSJiri Slaby #define MOXA_MUST_MCR_TX_XON 0x08
1374463cc5bSJiri Slaby
1384463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_MASK 0x0F /* software flow control on chip mask value */
1394463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_TX1 0x08 /* send Xon1/Xoff1 */
1404463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_TX2 0x04 /* send Xon2/Xoff2 */
1414463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_TX12 0x0C /* send Xon1,Xon2/Xoff1,Xoff2 */
1424463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_TX_NO 0x00 /* don't send Xon/Xoff */
1434463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_TX_MASK 0x0C /* Tx software flow control mask */
1444463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_RX_NO 0x00 /* don't receive Xon/Xoff */
1454463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_RX1 0x02 /* receive Xon1/Xoff1 */
1464463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_RX2 0x01 /* receive Xon2/Xoff2 */
1474463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_RX12 0x03 /* receive Xon1,Xon2/Xoff1,Xoff2 */
1484463cc5bSJiri Slaby #define MOXA_MUST_EFR_SF_RX_MASK 0x03 /* Rx software flow control mask */
149a6afd9f3SGreg Kroah-Hartman
150a6afd9f3SGreg Kroah-Hartman #define MXSERMAJOR 174
151a6afd9f3SGreg Kroah-Hartman
152a6afd9f3SGreg Kroah-Hartman #define MXSER_BOARDS 4 /* Max. boards */
153a6afd9f3SGreg Kroah-Hartman #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
154a6afd9f3SGreg Kroah-Hartman #define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
155a6afd9f3SGreg Kroah-Hartman #define MXSER_ISR_PASS_LIMIT 100
156a6afd9f3SGreg Kroah-Hartman
157a6afd9f3SGreg Kroah-Hartman #define WAKEUP_CHARS 256
158a6afd9f3SGreg Kroah-Hartman
159a6970c39SJiri Slaby #define MXSER_BAUD_BASE 921600
160d811b26bSJiri Slaby #define MXSER_CUSTOM_DIVISOR (MXSER_BAUD_BASE * 16)
161a6970c39SJiri Slaby
1624167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_RC7000 0x0001
1634167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP102 0x1020
1644167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP102UL 0x1021
1654167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP102U 0x1022
1664167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP102UF 0x1023
1674167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_C104 0x1040
1684167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP104U 0x1041
1694167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP104JU 0x1042
1704167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP104EL 0x1043
17116add04fSJiri Slaby #define PCI_DEVICE_ID_MOXA_POS104UL 0x1044
17216add04fSJiri Slaby #define PCI_DEVICE_ID_MOXA_CB108 0x1080
17316add04fSJiri Slaby #define PCI_DEVICE_ID_MOXA_CP112UL 0x1120
1744167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CT114 0x1140
1754167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP114 0x1141
17616add04fSJiri Slaby #define PCI_DEVICE_ID_MOXA_CB114 0x1142
17716add04fSJiri Slaby #define PCI_DEVICE_ID_MOXA_CP114UL 0x1143
1784167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP118U 0x1180
1794167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP118EL 0x1181
1804167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP132 0x1320
1814167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP132U 0x1321
1824167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP134U 0x1340
18316add04fSJiri Slaby #define PCI_DEVICE_ID_MOXA_CB134I 0x1341
18416add04fSJiri Slaby #define PCI_DEVICE_ID_MOXA_CP138U 0x1380
1854167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_C168 0x1680
1864167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP168U 0x1681
1874167bd25SJiri Slaby #define PCI_DEVICE_ID_MOXA_CP168EL 0x1682
188a6afd9f3SGreg Kroah-Hartman
189c24c31ffSJiri Slaby #define MXSER_NPORTS(ddata) ((ddata) & 0xffU)
190c24c31ffSJiri Slaby #define MXSER_HIGHBAUD 0x0100
191a6afd9f3SGreg Kroah-Hartman
192e4558366SJiri Slaby enum mxser_must_hwid {
193e4558366SJiri Slaby MOXA_OTHER_UART = 0x00,
194e4558366SJiri Slaby MOXA_MUST_MU150_HWID = 0x01,
195e4558366SJiri Slaby MOXA_MUST_MU860_HWID = 0x02,
196e4558366SJiri Slaby };
197e4558366SJiri Slaby
198a6afd9f3SGreg Kroah-Hartman static const struct {
199dc33f644SJiri Slaby u8 type;
200dc33f644SJiri Slaby u8 fifo_size;
201dc33f644SJiri Slaby u8 rx_high_water;
202dc33f644SJiri Slaby u8 rx_low_water;
203dc33f644SJiri Slaby speed_t max_baud;
204a6afd9f3SGreg Kroah-Hartman } Gpci_uart_info[] = {
205dc33f644SJiri Slaby { MOXA_OTHER_UART, 16, 14, 1, 921600 },
206dc33f644SJiri Slaby { MOXA_MUST_MU150_HWID, 64, 48, 16, 230400 },
207dc33f644SJiri Slaby { MOXA_MUST_MU860_HWID, 128, 96, 32, 921600 }
208a6afd9f3SGreg Kroah-Hartman };
209a6afd9f3SGreg Kroah-Hartman #define UART_INFO_NUM ARRAY_SIZE(Gpci_uart_info)
210a6afd9f3SGreg Kroah-Hartman
2113385ecf8SArvind Yadav static const struct pci_device_id mxser_pcibrds[] = {
212c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, C168, 8) },
213c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, C104, 4) },
214c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP132, 2) },
215c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP114, 4) },
216c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CT114, 4) },
217c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP102, 2 | MXSER_HIGHBAUD) },
218c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP104U, 4) },
219c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP168U, 8) },
220c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP132U, 2) },
221c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP134U, 4) },
222c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP104JU, 4) },
223c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, RC7000, 8) }, /* RC7000 */
224c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP118U, 8) },
225c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP102UL, 2) },
226c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP102U, 2) },
227c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP118EL, 8) },
228c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP168EL, 8) },
229c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP104EL, 4) },
230c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CB108, 8) },
231c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CB114, 4) },
232c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CB134I, 4) },
233c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP138U, 8) },
234c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, POS104UL, 4) },
235c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP114UL, 4) },
236c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP102UF, 2) },
237c668d567SJiri Slaby { PCI_DEVICE_DATA(MOXA, CP112UL, 2) },
238a6afd9f3SGreg Kroah-Hartman { }
239a6afd9f3SGreg Kroah-Hartman };
240a6afd9f3SGreg Kroah-Hartman MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
241a6afd9f3SGreg Kroah-Hartman
242a6afd9f3SGreg Kroah-Hartman static int ttymajor = MXSERMAJOR;
243a6afd9f3SGreg Kroah-Hartman
244a6afd9f3SGreg Kroah-Hartman /* Variables for insmod */
245a6afd9f3SGreg Kroah-Hartman
246a6afd9f3SGreg Kroah-Hartman MODULE_AUTHOR("Casper Yang");
247a6afd9f3SGreg Kroah-Hartman MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
248a6afd9f3SGreg Kroah-Hartman module_param(ttymajor, int, 0);
249a6afd9f3SGreg Kroah-Hartman MODULE_LICENSE("GPL");
250a6afd9f3SGreg Kroah-Hartman
251a6afd9f3SGreg Kroah-Hartman struct mxser_board;
252a6afd9f3SGreg Kroah-Hartman
253a6afd9f3SGreg Kroah-Hartman struct mxser_port {
254a6afd9f3SGreg Kroah-Hartman struct tty_port port;
255a6afd9f3SGreg Kroah-Hartman struct mxser_board *board;
256a6afd9f3SGreg Kroah-Hartman
257a6afd9f3SGreg Kroah-Hartman unsigned long ioaddr;
258a6afd9f3SGreg Kroah-Hartman unsigned long opmode_ioaddr;
259a6afd9f3SGreg Kroah-Hartman
260dc33f644SJiri Slaby u8 rx_high_water;
261dc33f644SJiri Slaby u8 rx_low_water;
262a6afd9f3SGreg Kroah-Hartman int type; /* UART type */
263a6afd9f3SGreg Kroah-Hartman
26459b94335SJiri Slaby (SUSE) u8 x_char; /* xon/xoff character */
265a93963e4SJiri Slaby u8 IER; /* Interrupt Enable Register */
266a93963e4SJiri Slaby u8 MCR; /* Modem control register */
267d249e662SJiri Slaby u8 FCR; /* FIFO control register */
268a6afd9f3SGreg Kroah-Hartman
269a6afd9f3SGreg Kroah-Hartman struct async_icount icount; /* kernel counters for 4 input interrupts */
270104583b5SJiri Slaby unsigned int timeout;
271a6afd9f3SGreg Kroah-Hartman
272a93963e4SJiri Slaby u8 read_status_mask;
273a93963e4SJiri Slaby u8 ignore_status_mask;
274dc33f644SJiri Slaby u8 xmit_fifo_size;
275a6afd9f3SGreg Kroah-Hartman
276a6afd9f3SGreg Kroah-Hartman spinlock_t slock;
277a6afd9f3SGreg Kroah-Hartman };
278a6afd9f3SGreg Kroah-Hartman
279a6afd9f3SGreg Kroah-Hartman struct mxser_board {
280a6afd9f3SGreg Kroah-Hartman unsigned int idx;
281c24c31ffSJiri Slaby unsigned short nports;
282a6afd9f3SGreg Kroah-Hartman int irq;
283a6afd9f3SGreg Kroah-Hartman unsigned long vector;
284a6afd9f3SGreg Kroah-Hartman
285e4558366SJiri Slaby enum mxser_must_hwid must_hwid;
286928f9464SJiri Slaby speed_t max_baud;
287a6afd9f3SGreg Kroah-Hartman
2881c07c9beSNathan Chancellor struct mxser_port ports[] /* __counted_by(nports) */;
289a6afd9f3SGreg Kroah-Hartman };
290a6afd9f3SGreg Kroah-Hartman
291f8b6b327SJiri Slaby static DECLARE_BITMAP(mxser_boards, MXSER_BOARDS);
292a6afd9f3SGreg Kroah-Hartman static struct tty_driver *mxvar_sdriver;
293a6afd9f3SGreg Kroah-Hartman
__mxser_must_set_EFR(unsigned long baseio,u8 clear,u8 set,bool restore_LCR)294edb7d27cSJiri Slaby static u8 __mxser_must_set_EFR(unsigned long baseio, u8 clear, u8 set,
295edb7d27cSJiri Slaby bool restore_LCR)
296a6afd9f3SGreg Kroah-Hartman {
297edb7d27cSJiri Slaby u8 oldlcr, efr;
298a6afd9f3SGreg Kroah-Hartman
299a6afd9f3SGreg Kroah-Hartman oldlcr = inb(baseio + UART_LCR);
300464fbf6cSJiri Slaby outb(MOXA_MUST_ENTER_ENHANCED, baseio + UART_LCR);
301a6afd9f3SGreg Kroah-Hartman
302a6afd9f3SGreg Kroah-Hartman efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
303edb7d27cSJiri Slaby efr &= ~clear;
304edb7d27cSJiri Slaby efr |= set;
305a6afd9f3SGreg Kroah-Hartman
306a6afd9f3SGreg Kroah-Hartman outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
307edb7d27cSJiri Slaby
308edb7d27cSJiri Slaby if (restore_LCR)
309a6afd9f3SGreg Kroah-Hartman outb(oldlcr, baseio + UART_LCR);
310a6afd9f3SGreg Kroah-Hartman
311edb7d27cSJiri Slaby return oldlcr;
312a6afd9f3SGreg Kroah-Hartman }
313a6afd9f3SGreg Kroah-Hartman
mxser_must_select_bank(unsigned long baseio,u8 bank)314b286484bSJiri Slaby static u8 mxser_must_select_bank(unsigned long baseio, u8 bank)
315b286484bSJiri Slaby {
316b286484bSJiri Slaby return __mxser_must_set_EFR(baseio, MOXA_MUST_EFR_BANK_MASK, bank,
317b286484bSJiri Slaby false);
318b286484bSJiri Slaby }
319b286484bSJiri Slaby
mxser_set_must_xon1_value(unsigned long baseio,u8 value)320a6afd9f3SGreg Kroah-Hartman static void mxser_set_must_xon1_value(unsigned long baseio, u8 value)
321a6afd9f3SGreg Kroah-Hartman {
322b286484bSJiri Slaby u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK0);
323a6afd9f3SGreg Kroah-Hartman outb(value, baseio + MOXA_MUST_XON1_REGISTER);
324a6afd9f3SGreg Kroah-Hartman outb(oldlcr, baseio + UART_LCR);
325a6afd9f3SGreg Kroah-Hartman }
326a6afd9f3SGreg Kroah-Hartman
mxser_set_must_xoff1_value(unsigned long baseio,u8 value)327a6afd9f3SGreg Kroah-Hartman static void mxser_set_must_xoff1_value(unsigned long baseio, u8 value)
328a6afd9f3SGreg Kroah-Hartman {
329b286484bSJiri Slaby u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK0);
330a6afd9f3SGreg Kroah-Hartman outb(value, baseio + MOXA_MUST_XOFF1_REGISTER);
331a6afd9f3SGreg Kroah-Hartman outb(oldlcr, baseio + UART_LCR);
332a6afd9f3SGreg Kroah-Hartman }
333a6afd9f3SGreg Kroah-Hartman
mxser_set_must_fifo_value(struct mxser_port * info)334a6afd9f3SGreg Kroah-Hartman static void mxser_set_must_fifo_value(struct mxser_port *info)
335a6afd9f3SGreg Kroah-Hartman {
336b286484bSJiri Slaby u8 oldlcr = mxser_must_select_bank(info->ioaddr, MOXA_MUST_EFR_BANK1);
337dc33f644SJiri Slaby outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTH_REGISTER);
338dc33f644SJiri Slaby outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTI_REGISTER);
339dc33f644SJiri Slaby outb(info->rx_low_water, info->ioaddr + MOXA_MUST_RBRTL_REGISTER);
340a6afd9f3SGreg Kroah-Hartman outb(oldlcr, info->ioaddr + UART_LCR);
341a6afd9f3SGreg Kroah-Hartman }
342a6afd9f3SGreg Kroah-Hartman
mxser_set_must_enum_value(unsigned long baseio,u8 value)343a6afd9f3SGreg Kroah-Hartman static void mxser_set_must_enum_value(unsigned long baseio, u8 value)
344a6afd9f3SGreg Kroah-Hartman {
345b286484bSJiri Slaby u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK2);
346a6afd9f3SGreg Kroah-Hartman outb(value, baseio + MOXA_MUST_ENUM_REGISTER);
347a6afd9f3SGreg Kroah-Hartman outb(oldlcr, baseio + UART_LCR);
348a6afd9f3SGreg Kroah-Hartman }
349a6afd9f3SGreg Kroah-Hartman
mxser_get_must_hardware_id(unsigned long baseio)350b286484bSJiri Slaby static u8 mxser_get_must_hardware_id(unsigned long baseio)
351a6afd9f3SGreg Kroah-Hartman {
352b286484bSJiri Slaby u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK2);
353b286484bSJiri Slaby u8 id = inb(baseio + MOXA_MUST_HWID_REGISTER);
354a6afd9f3SGreg Kroah-Hartman outb(oldlcr, baseio + UART_LCR);
355b286484bSJiri Slaby
356b286484bSJiri Slaby return id;
357a6afd9f3SGreg Kroah-Hartman }
358a6afd9f3SGreg Kroah-Hartman
mxser_must_set_EFR(unsigned long baseio,u8 clear,u8 set)359edb7d27cSJiri Slaby static void mxser_must_set_EFR(unsigned long baseio, u8 clear, u8 set)
360edb7d27cSJiri Slaby {
361edb7d27cSJiri Slaby __mxser_must_set_EFR(baseio, clear, set, true);
362edb7d27cSJiri Slaby }
363edb7d27cSJiri Slaby
mxser_must_set_enhance_mode(unsigned long baseio,bool enable)364edb7d27cSJiri Slaby static void mxser_must_set_enhance_mode(unsigned long baseio, bool enable)
365edb7d27cSJiri Slaby {
366edb7d27cSJiri Slaby mxser_must_set_EFR(baseio,
367edb7d27cSJiri Slaby enable ? 0 : MOXA_MUST_EFR_EFRB_ENABLE,
368edb7d27cSJiri Slaby enable ? MOXA_MUST_EFR_EFRB_ENABLE : 0);
369edb7d27cSJiri Slaby }
370edb7d27cSJiri Slaby
mxser_must_no_sw_flow_control(unsigned long baseio)371b441eb0fSJiri Slaby static void mxser_must_no_sw_flow_control(unsigned long baseio)
372a6afd9f3SGreg Kroah-Hartman {
373b441eb0fSJiri Slaby mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_MASK, 0);
374a6afd9f3SGreg Kroah-Hartman }
375a6afd9f3SGreg Kroah-Hartman
mxser_must_set_tx_sw_flow_control(unsigned long baseio,bool enable)376b441eb0fSJiri Slaby static void mxser_must_set_tx_sw_flow_control(unsigned long baseio, bool enable)
377a6afd9f3SGreg Kroah-Hartman {
378b441eb0fSJiri Slaby mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_TX_MASK,
379b441eb0fSJiri Slaby enable ? MOXA_MUST_EFR_SF_TX1 : 0);
380a6afd9f3SGreg Kroah-Hartman }
381a6afd9f3SGreg Kroah-Hartman
mxser_must_set_rx_sw_flow_control(unsigned long baseio,bool enable)382b441eb0fSJiri Slaby static void mxser_must_set_rx_sw_flow_control(unsigned long baseio, bool enable)
383a6afd9f3SGreg Kroah-Hartman {
384b441eb0fSJiri Slaby mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_RX_MASK,
385b441eb0fSJiri Slaby enable ? MOXA_MUST_EFR_SF_RX1 : 0);
386a6afd9f3SGreg Kroah-Hartman }
387a6afd9f3SGreg Kroah-Hartman
mxser_must_get_hwid(unsigned long io)388e4558366SJiri Slaby static enum mxser_must_hwid mxser_must_get_hwid(unsigned long io)
389a6afd9f3SGreg Kroah-Hartman {
390a6afd9f3SGreg Kroah-Hartman u8 oldmcr, hwid;
391a6afd9f3SGreg Kroah-Hartman int i;
392a6afd9f3SGreg Kroah-Hartman
393a6afd9f3SGreg Kroah-Hartman outb(0, io + UART_LCR);
394edb7d27cSJiri Slaby mxser_must_set_enhance_mode(io, false);
395a6afd9f3SGreg Kroah-Hartman oldmcr = inb(io + UART_MCR);
396a6afd9f3SGreg Kroah-Hartman outb(0, io + UART_MCR);
397a6afd9f3SGreg Kroah-Hartman mxser_set_must_xon1_value(io, 0x11);
398e4cdd25cSColin Ian King if (inb(io + UART_MCR) != 0) {
399a6afd9f3SGreg Kroah-Hartman outb(oldmcr, io + UART_MCR);
400a6afd9f3SGreg Kroah-Hartman return MOXA_OTHER_UART;
401a6afd9f3SGreg Kroah-Hartman }
402a6afd9f3SGreg Kroah-Hartman
403b286484bSJiri Slaby hwid = mxser_get_must_hardware_id(io);
404e4558366SJiri Slaby for (i = 1; i < UART_INFO_NUM; i++) /* 0 = OTHER_UART */
405a6afd9f3SGreg Kroah-Hartman if (hwid == Gpci_uart_info[i].type)
406e4558366SJiri Slaby return hwid;
407e4558366SJiri Slaby
408a6afd9f3SGreg Kroah-Hartman return MOXA_OTHER_UART;
409a6afd9f3SGreg Kroah-Hartman }
410a6afd9f3SGreg Kroah-Hartman
mxser_16550A_or_MUST(struct mxser_port * info)4115d1ea1adSJiri Slaby static bool mxser_16550A_or_MUST(struct mxser_port *info)
4125d1ea1adSJiri Slaby {
4135d1ea1adSJiri Slaby return info->type == PORT_16550A || info->board->must_hwid;
4145d1ea1adSJiri Slaby }
4155d1ea1adSJiri Slaby
mxser_process_txrx_fifo(struct mxser_port * info)416c3db20c3SJiri Slaby static void mxser_process_txrx_fifo(struct mxser_port *info)
417a6afd9f3SGreg Kroah-Hartman {
418c3db20c3SJiri Slaby unsigned int i;
419a6afd9f3SGreg Kroah-Hartman
420c3db20c3SJiri Slaby if (info->type == PORT_16450 || info->type == PORT_8250) {
421a6afd9f3SGreg Kroah-Hartman info->rx_high_water = 1;
422a6afd9f3SGreg Kroah-Hartman info->rx_low_water = 1;
423a6afd9f3SGreg Kroah-Hartman info->xmit_fifo_size = 1;
424c3db20c3SJiri Slaby return;
425c3db20c3SJiri Slaby }
426c3db20c3SJiri Slaby
427a6afd9f3SGreg Kroah-Hartman for (i = 0; i < UART_INFO_NUM; i++)
428292955a7SJiri Slaby if (info->board->must_hwid == Gpci_uart_info[i].type) {
429a6afd9f3SGreg Kroah-Hartman info->rx_low_water = Gpci_uart_info[i].rx_low_water;
430a6afd9f3SGreg Kroah-Hartman info->rx_high_water = Gpci_uart_info[i].rx_high_water;
431dc33f644SJiri Slaby info->xmit_fifo_size = Gpci_uart_info[i].fifo_size;
432a6afd9f3SGreg Kroah-Hartman break;
433a6afd9f3SGreg Kroah-Hartman }
434a6afd9f3SGreg Kroah-Hartman }
435a6afd9f3SGreg Kroah-Hartman
__mxser_start_tx(struct mxser_port * info)436740165f7SJiri Slaby static void __mxser_start_tx(struct mxser_port *info)
437740165f7SJiri Slaby {
438740165f7SJiri Slaby outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
439740165f7SJiri Slaby info->IER |= UART_IER_THRI;
440740165f7SJiri Slaby outb(info->IER, info->ioaddr + UART_IER);
441740165f7SJiri Slaby }
442740165f7SJiri Slaby
mxser_start_tx(struct mxser_port * info)443740165f7SJiri Slaby static void mxser_start_tx(struct mxser_port *info)
444740165f7SJiri Slaby {
445740165f7SJiri Slaby unsigned long flags;
446740165f7SJiri Slaby
447740165f7SJiri Slaby spin_lock_irqsave(&info->slock, flags);
448740165f7SJiri Slaby __mxser_start_tx(info);
449740165f7SJiri Slaby spin_unlock_irqrestore(&info->slock, flags);
450740165f7SJiri Slaby }
451740165f7SJiri Slaby
__mxser_stop_tx(struct mxser_port * info)452740165f7SJiri Slaby static void __mxser_stop_tx(struct mxser_port *info)
453740165f7SJiri Slaby {
454740165f7SJiri Slaby info->IER &= ~UART_IER_THRI;
455740165f7SJiri Slaby outb(info->IER, info->ioaddr + UART_IER);
456740165f7SJiri Slaby }
457740165f7SJiri Slaby
mxser_carrier_raised(struct tty_port * port)458b300fb26SIlpo Järvinen static bool mxser_carrier_raised(struct tty_port *port)
459a6afd9f3SGreg Kroah-Hartman {
460a6afd9f3SGreg Kroah-Hartman struct mxser_port *mp = container_of(port, struct mxser_port, port);
461b300fb26SIlpo Järvinen
462b300fb26SIlpo Järvinen return inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD;
463a6afd9f3SGreg Kroah-Hartman }
464a6afd9f3SGreg Kroah-Hartman
mxser_dtr_rts(struct tty_port * port,bool active)4655701cb8bSIlpo Järvinen static void mxser_dtr_rts(struct tty_port *port, bool active)
466a6afd9f3SGreg Kroah-Hartman {
467a6afd9f3SGreg Kroah-Hartman struct mxser_port *mp = container_of(port, struct mxser_port, port);
468a6afd9f3SGreg Kroah-Hartman unsigned long flags;
469007bbdc8SJiri Slaby u8 mcr;
470a6afd9f3SGreg Kroah-Hartman
471a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&mp->slock, flags);
472007bbdc8SJiri Slaby mcr = inb(mp->ioaddr + UART_MCR);
4735701cb8bSIlpo Järvinen if (active)
474007bbdc8SJiri Slaby mcr |= UART_MCR_DTR | UART_MCR_RTS;
475a6afd9f3SGreg Kroah-Hartman else
476007bbdc8SJiri Slaby mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
477007bbdc8SJiri Slaby outb(mcr, mp->ioaddr + UART_MCR);
478a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&mp->slock, flags);
479a6afd9f3SGreg Kroah-Hartman }
480a6afd9f3SGreg Kroah-Hartman
mxser_set_baud(struct tty_struct * tty,speed_t newspd)481dc33f644SJiri Slaby static int mxser_set_baud(struct tty_struct *tty, speed_t newspd)
482a6afd9f3SGreg Kroah-Hartman {
483a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
484104583b5SJiri Slaby unsigned int quot = 0, baud;
485a6afd9f3SGreg Kroah-Hartman unsigned char cval;
486104583b5SJiri Slaby u64 timeout;
487a6afd9f3SGreg Kroah-Hartman
488928f9464SJiri Slaby if (newspd > info->board->max_baud)
489a6afd9f3SGreg Kroah-Hartman return -1;
490a6afd9f3SGreg Kroah-Hartman
491a6afd9f3SGreg Kroah-Hartman if (newspd == 134) {
492a6970c39SJiri Slaby quot = 2 * MXSER_BAUD_BASE / 269;
493a6afd9f3SGreg Kroah-Hartman tty_encode_baud_rate(tty, 134, 134);
494a6afd9f3SGreg Kroah-Hartman } else if (newspd) {
495a6970c39SJiri Slaby quot = MXSER_BAUD_BASE / newspd;
496a6afd9f3SGreg Kroah-Hartman if (quot == 0)
497a6afd9f3SGreg Kroah-Hartman quot = 1;
498a6970c39SJiri Slaby baud = MXSER_BAUD_BASE / quot;
499a6afd9f3SGreg Kroah-Hartman tty_encode_baud_rate(tty, baud, baud);
500a6afd9f3SGreg Kroah-Hartman } else {
501a6afd9f3SGreg Kroah-Hartman quot = 0;
502a6afd9f3SGreg Kroah-Hartman }
503a6afd9f3SGreg Kroah-Hartman
504104583b5SJiri Slaby /*
505104583b5SJiri Slaby * worst case (128 * 1000 * 10 * 18432) needs 35 bits, so divide in the
506104583b5SJiri Slaby * u64 domain
507104583b5SJiri Slaby */
508104583b5SJiri Slaby timeout = (u64)info->xmit_fifo_size * HZ * 10 * quot;
509a6970c39SJiri Slaby do_div(timeout, MXSER_BAUD_BASE);
510104583b5SJiri Slaby info->timeout = timeout + HZ / 50; /* Add .02 seconds of slop */
511a6afd9f3SGreg Kroah-Hartman
512a6afd9f3SGreg Kroah-Hartman if (quot) {
513a6afd9f3SGreg Kroah-Hartman info->MCR |= UART_MCR_DTR;
514a6afd9f3SGreg Kroah-Hartman outb(info->MCR, info->ioaddr + UART_MCR);
515a6afd9f3SGreg Kroah-Hartman } else {
516a6afd9f3SGreg Kroah-Hartman info->MCR &= ~UART_MCR_DTR;
517a6afd9f3SGreg Kroah-Hartman outb(info->MCR, info->ioaddr + UART_MCR);
518a6afd9f3SGreg Kroah-Hartman return 0;
519a6afd9f3SGreg Kroah-Hartman }
520a6afd9f3SGreg Kroah-Hartman
521a6afd9f3SGreg Kroah-Hartman cval = inb(info->ioaddr + UART_LCR);
522a6afd9f3SGreg Kroah-Hartman
523a6afd9f3SGreg Kroah-Hartman outb(cval | UART_LCR_DLAB, info->ioaddr + UART_LCR); /* set DLAB */
524a6afd9f3SGreg Kroah-Hartman
525a6afd9f3SGreg Kroah-Hartman outb(quot & 0xff, info->ioaddr + UART_DLL); /* LS of divisor */
526a6afd9f3SGreg Kroah-Hartman outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */
527a6afd9f3SGreg Kroah-Hartman outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */
528a6afd9f3SGreg Kroah-Hartman
529a6afd9f3SGreg Kroah-Hartman if (C_BAUD(tty) == BOTHER) {
530a6970c39SJiri Slaby quot = MXSER_BAUD_BASE % newspd;
531a6afd9f3SGreg Kroah-Hartman quot *= 8;
532a6afd9f3SGreg Kroah-Hartman if (quot % newspd > newspd / 2) {
533a6afd9f3SGreg Kroah-Hartman quot /= newspd;
534a6afd9f3SGreg Kroah-Hartman quot++;
535a6afd9f3SGreg Kroah-Hartman } else
536a6afd9f3SGreg Kroah-Hartman quot /= newspd;
537a6afd9f3SGreg Kroah-Hartman
538a6afd9f3SGreg Kroah-Hartman mxser_set_must_enum_value(info->ioaddr, quot);
53969648d7bSIlpo Järvinen } else {
540a6afd9f3SGreg Kroah-Hartman mxser_set_must_enum_value(info->ioaddr, 0);
54169648d7bSIlpo Järvinen }
542a6afd9f3SGreg Kroah-Hartman
543a6afd9f3SGreg Kroah-Hartman return 0;
544a6afd9f3SGreg Kroah-Hartman }
545a6afd9f3SGreg Kroah-Hartman
mxser_handle_cts(struct tty_struct * tty,struct mxser_port * info,u8 msr)546be486667SJiri Slaby static void mxser_handle_cts(struct tty_struct *tty, struct mxser_port *info,
547be486667SJiri Slaby u8 msr)
548be486667SJiri Slaby {
549be486667SJiri Slaby bool cts = msr & UART_MSR_CTS;
550be486667SJiri Slaby
551be486667SJiri Slaby if (tty->hw_stopped) {
552be486667SJiri Slaby if (cts) {
553035173c9SIlpo Järvinen tty->hw_stopped = false;
554be486667SJiri Slaby
5555d1ea1adSJiri Slaby if (!mxser_16550A_or_MUST(info))
556740165f7SJiri Slaby __mxser_start_tx(info);
557be486667SJiri Slaby tty_wakeup(tty);
558be486667SJiri Slaby }
559be486667SJiri Slaby return;
560be486667SJiri Slaby } else if (cts)
561be486667SJiri Slaby return;
562be486667SJiri Slaby
563035173c9SIlpo Järvinen tty->hw_stopped = true;
5645d1ea1adSJiri Slaby if (!mxser_16550A_or_MUST(info))
565740165f7SJiri Slaby __mxser_stop_tx(info);
566be486667SJiri Slaby }
567be486667SJiri Slaby
568a6afd9f3SGreg Kroah-Hartman /*
569a6afd9f3SGreg Kroah-Hartman * This routine is called to set the UART divisor registers to match
570a6afd9f3SGreg Kroah-Hartman * the specified baud rate for a serial port.
571a6afd9f3SGreg Kroah-Hartman */
mxser_change_speed(struct tty_struct * tty,const struct ktermios * old_termios)572a8c11c15SIlpo Järvinen static void mxser_change_speed(struct tty_struct *tty,
573a8c11c15SIlpo Järvinen const struct ktermios *old_termios)
574a6afd9f3SGreg Kroah-Hartman {
575a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
576d249e662SJiri Slaby unsigned cflag, cval;
577a6afd9f3SGreg Kroah-Hartman
578adc8d746SAlan Cox cflag = tty->termios.c_cflag;
579a6afd9f3SGreg Kroah-Hartman
5803fdfa165SJiri Slaby if (mxser_set_baud(tty, tty_get_baud_rate(tty))) {
5813fdfa165SJiri Slaby /* Use previous rate on a failure */
5823fdfa165SJiri Slaby if (old_termios) {
5833fdfa165SJiri Slaby speed_t baud = tty_termios_baud_rate(old_termios);
5843fdfa165SJiri Slaby tty_encode_baud_rate(tty, baud, baud);
5853fdfa165SJiri Slaby }
5863fdfa165SJiri Slaby }
587a6afd9f3SGreg Kroah-Hartman
588a6afd9f3SGreg Kroah-Hartman /* byte size and parity */
589e7d6f84cSJiri Slaby cval = UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag));
5902c21832bSJiri Slaby
591a6afd9f3SGreg Kroah-Hartman if (cflag & CSTOPB)
5922c21832bSJiri Slaby cval |= UART_LCR_STOP;
593a6afd9f3SGreg Kroah-Hartman if (cflag & PARENB)
594a6afd9f3SGreg Kroah-Hartman cval |= UART_LCR_PARITY;
595a6afd9f3SGreg Kroah-Hartman if (!(cflag & PARODD))
596a6afd9f3SGreg Kroah-Hartman cval |= UART_LCR_EPAR;
597a6afd9f3SGreg Kroah-Hartman if (cflag & CMSPAR)
598a6afd9f3SGreg Kroah-Hartman cval |= UART_LCR_SPAR;
599a6afd9f3SGreg Kroah-Hartman
600d249e662SJiri Slaby info->FCR = 0;
601292955a7SJiri Slaby if (info->board->must_hwid) {
602d249e662SJiri Slaby info->FCR |= UART_FCR_ENABLE_FIFO |
603bf1434c1SJiri Slaby MOXA_MUST_FCR_GDA_MODE_ENABLE;
604a6afd9f3SGreg Kroah-Hartman mxser_set_must_fifo_value(info);
605bf1434c1SJiri Slaby } else if (info->type != PORT_8250 && info->type != PORT_16450) {
606d249e662SJiri Slaby info->FCR |= UART_FCR_ENABLE_FIFO;
607dc33f644SJiri Slaby switch (info->rx_high_water) {
608a6afd9f3SGreg Kroah-Hartman case 1:
609d249e662SJiri Slaby info->FCR |= UART_FCR_TRIGGER_1;
610a6afd9f3SGreg Kroah-Hartman break;
611a6afd9f3SGreg Kroah-Hartman case 4:
612d249e662SJiri Slaby info->FCR |= UART_FCR_TRIGGER_4;
613a6afd9f3SGreg Kroah-Hartman break;
614a6afd9f3SGreg Kroah-Hartman case 8:
615d249e662SJiri Slaby info->FCR |= UART_FCR_TRIGGER_8;
616a6afd9f3SGreg Kroah-Hartman break;
617a6afd9f3SGreg Kroah-Hartman default:
618d249e662SJiri Slaby info->FCR |= UART_FCR_TRIGGER_14;
619a6afd9f3SGreg Kroah-Hartman break;
620a6afd9f3SGreg Kroah-Hartman }
621a6afd9f3SGreg Kroah-Hartman }
622a6afd9f3SGreg Kroah-Hartman
623a6afd9f3SGreg Kroah-Hartman /* CTS flow control flag and modem status interrupts */
624a6afd9f3SGreg Kroah-Hartman info->IER &= ~UART_IER_MSI;
625a6afd9f3SGreg Kroah-Hartman info->MCR &= ~UART_MCR_AFE;
6265604a98eSPeter Hurley tty_port_set_cts_flow(&info->port, cflag & CRTSCTS);
627a6afd9f3SGreg Kroah-Hartman if (cflag & CRTSCTS) {
628a6afd9f3SGreg Kroah-Hartman info->IER |= UART_IER_MSI;
6295d1ea1adSJiri Slaby if (mxser_16550A_or_MUST(info)) {
630a6afd9f3SGreg Kroah-Hartman info->MCR |= UART_MCR_AFE;
631a6afd9f3SGreg Kroah-Hartman } else {
632be486667SJiri Slaby mxser_handle_cts(tty, info,
633be486667SJiri Slaby inb(info->ioaddr + UART_MSR));
634a6afd9f3SGreg Kroah-Hartman }
635a6afd9f3SGreg Kroah-Hartman }
636a6afd9f3SGreg Kroah-Hartman outb(info->MCR, info->ioaddr + UART_MCR);
6372d68655dSPeter Hurley tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL);
6382d68655dSPeter Hurley if (~cflag & CLOCAL)
639a6afd9f3SGreg Kroah-Hartman info->IER |= UART_IER_MSI;
640a6afd9f3SGreg Kroah-Hartman outb(info->IER, info->ioaddr + UART_IER);
641a6afd9f3SGreg Kroah-Hartman
642a6afd9f3SGreg Kroah-Hartman /*
643a6afd9f3SGreg Kroah-Hartman * Set up parity check flag
644a6afd9f3SGreg Kroah-Hartman */
645a6afd9f3SGreg Kroah-Hartman info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
646a6afd9f3SGreg Kroah-Hartman if (I_INPCK(tty))
647a6afd9f3SGreg Kroah-Hartman info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
648a6afd9f3SGreg Kroah-Hartman if (I_BRKINT(tty) || I_PARMRK(tty))
649a6afd9f3SGreg Kroah-Hartman info->read_status_mask |= UART_LSR_BI;
650a6afd9f3SGreg Kroah-Hartman
651a6afd9f3SGreg Kroah-Hartman info->ignore_status_mask = 0;
652a6afd9f3SGreg Kroah-Hartman
653a6afd9f3SGreg Kroah-Hartman if (I_IGNBRK(tty)) {
654a6afd9f3SGreg Kroah-Hartman info->ignore_status_mask |= UART_LSR_BI;
655a6afd9f3SGreg Kroah-Hartman info->read_status_mask |= UART_LSR_BI;
656a6afd9f3SGreg Kroah-Hartman /*
657a6afd9f3SGreg Kroah-Hartman * If we're ignore parity and break indicators, ignore
658a6afd9f3SGreg Kroah-Hartman * overruns too. (For real raw support).
659a6afd9f3SGreg Kroah-Hartman */
660a6afd9f3SGreg Kroah-Hartman if (I_IGNPAR(tty)) {
661a6afd9f3SGreg Kroah-Hartman info->ignore_status_mask |=
662a6afd9f3SGreg Kroah-Hartman UART_LSR_OE |
663a6afd9f3SGreg Kroah-Hartman UART_LSR_PE |
664a6afd9f3SGreg Kroah-Hartman UART_LSR_FE;
665a6afd9f3SGreg Kroah-Hartman info->read_status_mask |=
666a6afd9f3SGreg Kroah-Hartman UART_LSR_OE |
667a6afd9f3SGreg Kroah-Hartman UART_LSR_PE |
668a6afd9f3SGreg Kroah-Hartman UART_LSR_FE;
669a6afd9f3SGreg Kroah-Hartman }
670a6afd9f3SGreg Kroah-Hartman }
671292955a7SJiri Slaby if (info->board->must_hwid) {
672a6afd9f3SGreg Kroah-Hartman mxser_set_must_xon1_value(info->ioaddr, START_CHAR(tty));
673a6afd9f3SGreg Kroah-Hartman mxser_set_must_xoff1_value(info->ioaddr, STOP_CHAR(tty));
674b441eb0fSJiri Slaby mxser_must_set_rx_sw_flow_control(info->ioaddr, I_IXON(tty));
675b441eb0fSJiri Slaby mxser_must_set_tx_sw_flow_control(info->ioaddr, I_IXOFF(tty));
676a6afd9f3SGreg Kroah-Hartman }
677a6afd9f3SGreg Kroah-Hartman
678a6afd9f3SGreg Kroah-Hartman
679d249e662SJiri Slaby outb(info->FCR, info->ioaddr + UART_FCR);
680a6afd9f3SGreg Kroah-Hartman outb(cval, info->ioaddr + UART_LCR);
681a6afd9f3SGreg Kroah-Hartman }
682a6afd9f3SGreg Kroah-Hartman
mxser_check_modem_status(struct tty_struct * tty,struct mxser_port * port)68330f6027fSJiri Slaby static u8 mxser_check_modem_status(struct tty_struct *tty,
68430f6027fSJiri Slaby struct mxser_port *port)
685a6afd9f3SGreg Kroah-Hartman {
68630f6027fSJiri Slaby u8 msr = inb(port->ioaddr + UART_MSR);
68730f6027fSJiri Slaby
68830f6027fSJiri Slaby if (!(msr & UART_MSR_ANY_DELTA))
68930f6027fSJiri Slaby return msr;
69030f6027fSJiri Slaby
691a6afd9f3SGreg Kroah-Hartman /* update input line counters */
69230f6027fSJiri Slaby if (msr & UART_MSR_TERI)
693a6afd9f3SGreg Kroah-Hartman port->icount.rng++;
69430f6027fSJiri Slaby if (msr & UART_MSR_DDSR)
695a6afd9f3SGreg Kroah-Hartman port->icount.dsr++;
69630f6027fSJiri Slaby if (msr & UART_MSR_DDCD)
697a6afd9f3SGreg Kroah-Hartman port->icount.dcd++;
69830f6027fSJiri Slaby if (msr & UART_MSR_DCTS)
699a6afd9f3SGreg Kroah-Hartman port->icount.cts++;
700a6afd9f3SGreg Kroah-Hartman wake_up_interruptible(&port->port.delta_msr_wait);
701a6afd9f3SGreg Kroah-Hartman
70230f6027fSJiri Slaby if (tty_port_check_carrier(&port->port) && (msr & UART_MSR_DDCD)) {
70330f6027fSJiri Slaby if (msr & UART_MSR_DCD)
704a6afd9f3SGreg Kroah-Hartman wake_up_interruptible(&port->port.open_wait);
705a6afd9f3SGreg Kroah-Hartman }
706a6afd9f3SGreg Kroah-Hartman
707be486667SJiri Slaby if (tty_port_cts_enabled(&port->port))
70830f6027fSJiri Slaby mxser_handle_cts(tty, port, msr);
70930f6027fSJiri Slaby
71030f6027fSJiri Slaby return msr;
711a6afd9f3SGreg Kroah-Hartman }
712a6afd9f3SGreg Kroah-Hartman
mxser_disable_and_clear_FIFO(struct mxser_port * info)713ee7e5e66SJiri Slaby static void mxser_disable_and_clear_FIFO(struct mxser_port *info)
714ee7e5e66SJiri Slaby {
715ee7e5e66SJiri Slaby u8 fcr = UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT;
716ee7e5e66SJiri Slaby
717ee7e5e66SJiri Slaby if (info->board->must_hwid)
718ee7e5e66SJiri Slaby fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
719ee7e5e66SJiri Slaby
720ee7e5e66SJiri Slaby outb(fcr, info->ioaddr + UART_FCR);
721ee7e5e66SJiri Slaby }
722ee7e5e66SJiri Slaby
mxser_activate(struct tty_port * port,struct tty_struct * tty)723a6afd9f3SGreg Kroah-Hartman static int mxser_activate(struct tty_port *port, struct tty_struct *tty)
724a6afd9f3SGreg Kroah-Hartman {
725a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = container_of(port, struct mxser_port, port);
726a6afd9f3SGreg Kroah-Hartman unsigned long flags;
727cd3a4907SJiri Slaby int ret;
728a6afd9f3SGreg Kroah-Hartman
72992cc9d1dSJiri Slaby ret = tty_port_alloc_xmit_buf(port);
73092cc9d1dSJiri Slaby if (ret < 0)
73192cc9d1dSJiri Slaby return ret;
732a6afd9f3SGreg Kroah-Hartman
733a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
734a6afd9f3SGreg Kroah-Hartman
735987a4cfeSJiri Slaby if (!info->type) {
736a6afd9f3SGreg Kroah-Hartman set_bit(TTY_IO_ERROR, &tty->flags);
737a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
738cd3a4907SJiri Slaby ret = 0;
739cd3a4907SJiri Slaby goto err_free_xmit;
740a6afd9f3SGreg Kroah-Hartman }
741a6afd9f3SGreg Kroah-Hartman
742a6afd9f3SGreg Kroah-Hartman /*
743a6afd9f3SGreg Kroah-Hartman * Clear the FIFO buffers and disable them
744a6afd9f3SGreg Kroah-Hartman * (they will be reenabled in mxser_change_speed())
745a6afd9f3SGreg Kroah-Hartman */
746ee7e5e66SJiri Slaby mxser_disable_and_clear_FIFO(info);
747a6afd9f3SGreg Kroah-Hartman
748a6afd9f3SGreg Kroah-Hartman /*
749a6afd9f3SGreg Kroah-Hartman * At this point there's no way the LSR could still be 0xFF;
750a6afd9f3SGreg Kroah-Hartman * if it is, then bail out, because there's likely no UART
751a6afd9f3SGreg Kroah-Hartman * here.
752a6afd9f3SGreg Kroah-Hartman */
753a6afd9f3SGreg Kroah-Hartman if (inb(info->ioaddr + UART_LSR) == 0xff) {
754a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
755a6afd9f3SGreg Kroah-Hartman if (capable(CAP_SYS_ADMIN)) {
756a6afd9f3SGreg Kroah-Hartman set_bit(TTY_IO_ERROR, &tty->flags);
757a6afd9f3SGreg Kroah-Hartman return 0;
758cd3a4907SJiri Slaby }
759cd3a4907SJiri Slaby
760cd3a4907SJiri Slaby ret = -ENODEV;
761cd3a4907SJiri Slaby goto err_free_xmit;
762a6afd9f3SGreg Kroah-Hartman }
763a6afd9f3SGreg Kroah-Hartman
764a6afd9f3SGreg Kroah-Hartman /*
765a6afd9f3SGreg Kroah-Hartman * Clear the interrupt registers.
766a6afd9f3SGreg Kroah-Hartman */
767a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_LSR);
768a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_RX);
769a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_IIR);
770a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_MSR);
771a6afd9f3SGreg Kroah-Hartman
772a6afd9f3SGreg Kroah-Hartman /*
773a6afd9f3SGreg Kroah-Hartman * Now, initialize the UART
774a6afd9f3SGreg Kroah-Hartman */
775a6afd9f3SGreg Kroah-Hartman outb(UART_LCR_WLEN8, info->ioaddr + UART_LCR); /* reset DLAB */
776a6afd9f3SGreg Kroah-Hartman info->MCR = UART_MCR_DTR | UART_MCR_RTS;
777a6afd9f3SGreg Kroah-Hartman outb(info->MCR, info->ioaddr + UART_MCR);
778a6afd9f3SGreg Kroah-Hartman
779a6afd9f3SGreg Kroah-Hartman /*
780a6afd9f3SGreg Kroah-Hartman * Finally, enable interrupts
781a6afd9f3SGreg Kroah-Hartman */
782a6afd9f3SGreg Kroah-Hartman info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
783a6afd9f3SGreg Kroah-Hartman
784292955a7SJiri Slaby if (info->board->must_hwid)
785a6afd9f3SGreg Kroah-Hartman info->IER |= MOXA_MUST_IER_EGDAI;
786a6afd9f3SGreg Kroah-Hartman outb(info->IER, info->ioaddr + UART_IER); /* enable interrupts */
787a6afd9f3SGreg Kroah-Hartman
788a6afd9f3SGreg Kroah-Hartman /*
789a6afd9f3SGreg Kroah-Hartman * And clear the interrupt registers again for luck.
790a6afd9f3SGreg Kroah-Hartman */
791a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_LSR);
792a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_RX);
793a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_IIR);
794a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_MSR);
795a6afd9f3SGreg Kroah-Hartman
796a6afd9f3SGreg Kroah-Hartman clear_bit(TTY_IO_ERROR, &tty->flags);
79732330c83SJiri Slaby kfifo_reset(&port->xmit_fifo);
798a6afd9f3SGreg Kroah-Hartman
799a6afd9f3SGreg Kroah-Hartman /*
800a6afd9f3SGreg Kroah-Hartman * and set the speed of the serial port
801a6afd9f3SGreg Kroah-Hartman */
8023fdfa165SJiri Slaby mxser_change_speed(tty, NULL);
803a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
804a6afd9f3SGreg Kroah-Hartman
805a6afd9f3SGreg Kroah-Hartman return 0;
806cd3a4907SJiri Slaby err_free_xmit:
80792cc9d1dSJiri Slaby tty_port_free_xmit_buf(port);
808cd3a4907SJiri Slaby return ret;
809a6afd9f3SGreg Kroah-Hartman }
810a6afd9f3SGreg Kroah-Hartman
811a6afd9f3SGreg Kroah-Hartman /*
81247b722d4SJiri Slaby * To stop accepting input, we disable the receive line status interrupts, and
81347b722d4SJiri Slaby * tell the interrupt driver to stop checking the data ready bit in the line
81447b722d4SJiri Slaby * status register.
81547b722d4SJiri Slaby */
mxser_stop_rx(struct mxser_port * info)81647b722d4SJiri Slaby static void mxser_stop_rx(struct mxser_port *info)
81747b722d4SJiri Slaby {
81847b722d4SJiri Slaby info->IER &= ~UART_IER_RLSI;
81947b722d4SJiri Slaby if (info->board->must_hwid)
82047b722d4SJiri Slaby info->IER &= ~MOXA_MUST_RECV_ISR;
82147b722d4SJiri Slaby
82247b722d4SJiri Slaby outb(info->IER, info->ioaddr + UART_IER);
82347b722d4SJiri Slaby }
82447b722d4SJiri Slaby
82547b722d4SJiri Slaby /*
826a6afd9f3SGreg Kroah-Hartman * This routine will shutdown a serial port
827a6afd9f3SGreg Kroah-Hartman */
mxser_shutdown_port(struct tty_port * port)828a6afd9f3SGreg Kroah-Hartman static void mxser_shutdown_port(struct tty_port *port)
829a6afd9f3SGreg Kroah-Hartman {
830a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = container_of(port, struct mxser_port, port);
831a6afd9f3SGreg Kroah-Hartman unsigned long flags;
832a6afd9f3SGreg Kroah-Hartman
833a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
834a6afd9f3SGreg Kroah-Hartman
83547b722d4SJiri Slaby mxser_stop_rx(info);
83647b722d4SJiri Slaby
837a6afd9f3SGreg Kroah-Hartman /*
838a6afd9f3SGreg Kroah-Hartman * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
839a6afd9f3SGreg Kroah-Hartman * here so the queue might never be waken up
840a6afd9f3SGreg Kroah-Hartman */
841a6afd9f3SGreg Kroah-Hartman wake_up_interruptible(&info->port.delta_msr_wait);
842a6afd9f3SGreg Kroah-Hartman
843a6afd9f3SGreg Kroah-Hartman info->IER = 0;
844a6afd9f3SGreg Kroah-Hartman outb(0x00, info->ioaddr + UART_IER);
845a6afd9f3SGreg Kroah-Hartman
846a6afd9f3SGreg Kroah-Hartman /* clear Rx/Tx FIFO's */
847ee7e5e66SJiri Slaby mxser_disable_and_clear_FIFO(info);
848a6afd9f3SGreg Kroah-Hartman
849a6afd9f3SGreg Kroah-Hartman /* read data port to reset things */
850a6afd9f3SGreg Kroah-Hartman (void) inb(info->ioaddr + UART_RX);
851a6afd9f3SGreg Kroah-Hartman
852a6afd9f3SGreg Kroah-Hartman
853292955a7SJiri Slaby if (info->board->must_hwid)
854b441eb0fSJiri Slaby mxser_must_no_sw_flow_control(info->ioaddr);
855a6afd9f3SGreg Kroah-Hartman
856a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
85792cc9d1dSJiri Slaby
85892cc9d1dSJiri Slaby /* make sure ISR is not running while we free the buffer */
85992cc9d1dSJiri Slaby synchronize_irq(info->board->irq);
86092cc9d1dSJiri Slaby
86192cc9d1dSJiri Slaby tty_port_free_xmit_buf(port);
862a6afd9f3SGreg Kroah-Hartman }
863a6afd9f3SGreg Kroah-Hartman
864a6afd9f3SGreg Kroah-Hartman /*
865a6afd9f3SGreg Kroah-Hartman * This routine is called whenever a serial port is opened. It
866a6afd9f3SGreg Kroah-Hartman * enables interrupts for a serial port, linking in its async structure into
867a6afd9f3SGreg Kroah-Hartman * the IRQ chain. It also performs the serial-specific
868a6afd9f3SGreg Kroah-Hartman * initialization for the tty structure.
869a6afd9f3SGreg Kroah-Hartman */
mxser_open(struct tty_struct * tty,struct file * filp)870a6afd9f3SGreg Kroah-Hartman static int mxser_open(struct tty_struct *tty, struct file *filp)
871a6afd9f3SGreg Kroah-Hartman {
87242ad25fcSJiri Slaby struct tty_port *tport = tty->port;
87342ad25fcSJiri Slaby struct mxser_port *port = container_of(tport, struct mxser_port, port);
874a6afd9f3SGreg Kroah-Hartman
87542ad25fcSJiri Slaby tty->driver_data = port;
876a6afd9f3SGreg Kroah-Hartman
87742ad25fcSJiri Slaby return tty_port_open(tport, tty, filp);
878a6afd9f3SGreg Kroah-Hartman }
879a6afd9f3SGreg Kroah-Hartman
mxser_flush_buffer(struct tty_struct * tty)880a6afd9f3SGreg Kroah-Hartman static void mxser_flush_buffer(struct tty_struct *tty)
881a6afd9f3SGreg Kroah-Hartman {
882a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
883a6afd9f3SGreg Kroah-Hartman unsigned long flags;
884a6afd9f3SGreg Kroah-Hartman
885a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
88632330c83SJiri Slaby kfifo_reset(&info->port.xmit_fifo);
887a6afd9f3SGreg Kroah-Hartman
888d249e662SJiri Slaby outb(info->FCR | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
889a6afd9f3SGreg Kroah-Hartman info->ioaddr + UART_FCR);
890a6afd9f3SGreg Kroah-Hartman
891a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
892a6afd9f3SGreg Kroah-Hartman
893a6afd9f3SGreg Kroah-Hartman tty_wakeup(tty);
894a6afd9f3SGreg Kroah-Hartman }
895a6afd9f3SGreg Kroah-Hartman
mxser_close(struct tty_struct * tty,struct file * filp)896a6afd9f3SGreg Kroah-Hartman static void mxser_close(struct tty_struct *tty, struct file *filp)
897a6afd9f3SGreg Kroah-Hartman {
898c7ec012fSJiri Slaby tty_port_close(tty->port, tty, filp);
899a6afd9f3SGreg Kroah-Hartman }
900a6afd9f3SGreg Kroah-Hartman
mxser_write(struct tty_struct * tty,const u8 * buf,size_t count)90195713967SJiri Slaby (SUSE) static ssize_t mxser_write(struct tty_struct *tty, const u8 *buf, size_t count)
902a6afd9f3SGreg Kroah-Hartman {
903a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
904a6afd9f3SGreg Kroah-Hartman unsigned long flags;
90559b94335SJiri Slaby (SUSE) size_t written;
90632330c83SJiri Slaby bool is_empty;
907a6afd9f3SGreg Kroah-Hartman
908a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
90932330c83SJiri Slaby written = kfifo_in(&info->port.xmit_fifo, buf, count);
91032330c83SJiri Slaby is_empty = kfifo_is_empty(&info->port.xmit_fifo);
911a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
912a6afd9f3SGreg Kroah-Hartman
91332330c83SJiri Slaby if (!is_empty && !tty->flow.stopped)
9145d1ea1adSJiri Slaby if (!tty->hw_stopped || mxser_16550A_or_MUST(info))
915740165f7SJiri Slaby mxser_start_tx(info);
9165d1ea1adSJiri Slaby
91732330c83SJiri Slaby return written;
918a6afd9f3SGreg Kroah-Hartman }
919a6afd9f3SGreg Kroah-Hartman
mxser_put_char(struct tty_struct * tty,u8 ch)920dcaafbe6SJiri Slaby (SUSE) static int mxser_put_char(struct tty_struct *tty, u8 ch)
921a6afd9f3SGreg Kroah-Hartman {
922a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
923a6afd9f3SGreg Kroah-Hartman unsigned long flags;
92432330c83SJiri Slaby int ret;
925a6afd9f3SGreg Kroah-Hartman
926a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
92732330c83SJiri Slaby ret = kfifo_put(&info->port.xmit_fifo, ch);
928a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
9298aff64e0SJiri Slaby
93032330c83SJiri Slaby return ret;
931a6afd9f3SGreg Kroah-Hartman }
932a6afd9f3SGreg Kroah-Hartman
933a6afd9f3SGreg Kroah-Hartman
mxser_flush_chars(struct tty_struct * tty)934a6afd9f3SGreg Kroah-Hartman static void mxser_flush_chars(struct tty_struct *tty)
935a6afd9f3SGreg Kroah-Hartman {
936a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
937a6afd9f3SGreg Kroah-Hartman
93832330c83SJiri Slaby if (kfifo_is_empty(&info->port.xmit_fifo) || tty->flow.stopped ||
9395d1ea1adSJiri Slaby (tty->hw_stopped && !mxser_16550A_or_MUST(info)))
940a6afd9f3SGreg Kroah-Hartman return;
941a6afd9f3SGreg Kroah-Hartman
942740165f7SJiri Slaby mxser_start_tx(info);
943a6afd9f3SGreg Kroah-Hartman }
944a6afd9f3SGreg Kroah-Hartman
mxser_write_room(struct tty_struct * tty)94503b3b1a2SJiri Slaby static unsigned int mxser_write_room(struct tty_struct *tty)
946a6afd9f3SGreg Kroah-Hartman {
947a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
948a6afd9f3SGreg Kroah-Hartman
94932330c83SJiri Slaby return kfifo_avail(&info->port.xmit_fifo);
950a6afd9f3SGreg Kroah-Hartman }
951a6afd9f3SGreg Kroah-Hartman
mxser_chars_in_buffer(struct tty_struct * tty)952fff4ef17SJiri Slaby static unsigned int mxser_chars_in_buffer(struct tty_struct *tty)
953a6afd9f3SGreg Kroah-Hartman {
954a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
95532330c83SJiri Slaby
95632330c83SJiri Slaby return kfifo_len(&info->port.xmit_fifo);
957a6afd9f3SGreg Kroah-Hartman }
958a6afd9f3SGreg Kroah-Hartman
959a6afd9f3SGreg Kroah-Hartman /*
960a6afd9f3SGreg Kroah-Hartman * ------------------------------------------------------------
961a6afd9f3SGreg Kroah-Hartman * friends of mxser_ioctl()
962a6afd9f3SGreg Kroah-Hartman * ------------------------------------------------------------
963a6afd9f3SGreg Kroah-Hartman */
mxser_get_serial_info(struct tty_struct * tty,struct serial_struct * ss)964a6afd9f3SGreg Kroah-Hartman static int mxser_get_serial_info(struct tty_struct *tty,
9656da5b587SAl Viro struct serial_struct *ss)
966a6afd9f3SGreg Kroah-Hartman {
967a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
9686da5b587SAl Viro struct tty_port *port = &info->port;
969be6cf583SJohan Hovold unsigned int closing_wait, close_delay;
9706da5b587SAl Viro
9716da5b587SAl Viro mutex_lock(&port->mutex);
972be6cf583SJohan Hovold
973be6cf583SJohan Hovold close_delay = jiffies_to_msecs(info->port.close_delay) / 10;
974be6cf583SJohan Hovold closing_wait = info->port.closing_wait;
975be6cf583SJohan Hovold if (closing_wait != ASYNC_CLOSING_WAIT_NONE)
976be6cf583SJohan Hovold closing_wait = jiffies_to_msecs(closing_wait) / 10;
977be6cf583SJohan Hovold
9782285c496SDan Carpenter ss->type = info->type;
9792285c496SDan Carpenter ss->line = tty->index;
9802285c496SDan Carpenter ss->port = info->ioaddr;
9812285c496SDan Carpenter ss->irq = info->board->irq;
9822285c496SDan Carpenter ss->flags = info->port.flags;
9832285c496SDan Carpenter ss->baud_base = MXSER_BAUD_BASE;
984be6cf583SJohan Hovold ss->close_delay = close_delay;
985be6cf583SJohan Hovold ss->closing_wait = closing_wait;
986*1c70238aSChen Ni ss->custom_divisor = MXSER_CUSTOM_DIVISOR;
9876da5b587SAl Viro mutex_unlock(&port->mutex);
988a6afd9f3SGreg Kroah-Hartman return 0;
989a6afd9f3SGreg Kroah-Hartman }
990a6afd9f3SGreg Kroah-Hartman
mxser_set_serial_info(struct tty_struct * tty,struct serial_struct * ss)991a6afd9f3SGreg Kroah-Hartman static int mxser_set_serial_info(struct tty_struct *tty,
9926da5b587SAl Viro struct serial_struct *ss)
993a6afd9f3SGreg Kroah-Hartman {
994a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
995a6afd9f3SGreg Kroah-Hartman struct tty_port *port = &info->port;
996a6afd9f3SGreg Kroah-Hartman speed_t baud;
997a6afd9f3SGreg Kroah-Hartman unsigned long sl_flags;
99806cc52efSJiri Slaby unsigned int old_speed, close_delay, closing_wait;
999a6afd9f3SGreg Kroah-Hartman int retval = 0;
1000a6afd9f3SGreg Kroah-Hartman
10016da5b587SAl Viro if (tty_io_error(tty))
10026da5b587SAl Viro return -EIO;
1003a6afd9f3SGreg Kroah-Hartman
10046da5b587SAl Viro mutex_lock(&port->mutex);
10056da5b587SAl Viro
10066da5b587SAl Viro if (ss->irq != info->board->irq ||
10076da5b587SAl Viro ss->port != info->ioaddr) {
10086da5b587SAl Viro mutex_unlock(&port->mutex);
1009a6afd9f3SGreg Kroah-Hartman return -EINVAL;
10106da5b587SAl Viro }
1011a6afd9f3SGreg Kroah-Hartman
101206cc52efSJiri Slaby old_speed = port->flags & ASYNC_SPD_MASK;
1013a6afd9f3SGreg Kroah-Hartman
1014be6cf583SJohan Hovold close_delay = msecs_to_jiffies(ss->close_delay * 10);
1015be6cf583SJohan Hovold closing_wait = ss->closing_wait;
1016be6cf583SJohan Hovold if (closing_wait != ASYNC_CLOSING_WAIT_NONE)
1017be6cf583SJohan Hovold closing_wait = msecs_to_jiffies(closing_wait * 10);
1018be6cf583SJohan Hovold
1019a6afd9f3SGreg Kroah-Hartman if (!capable(CAP_SYS_ADMIN)) {
1020a6970c39SJiri Slaby if ((ss->baud_base != MXSER_BAUD_BASE) ||
10211b3086b6SJiri Slaby (close_delay != port->close_delay) ||
10221b3086b6SJiri Slaby (closing_wait != port->closing_wait) ||
10231b3086b6SJiri Slaby ((ss->flags & ~ASYNC_USR_MASK) != (port->flags & ~ASYNC_USR_MASK))) {
10246da5b587SAl Viro mutex_unlock(&port->mutex);
1025a6afd9f3SGreg Kroah-Hartman return -EPERM;
10266da5b587SAl Viro }
10271b3086b6SJiri Slaby port->flags = (port->flags & ~ASYNC_USR_MASK) |
10281b3086b6SJiri Slaby (ss->flags & ASYNC_USR_MASK);
1029a6afd9f3SGreg Kroah-Hartman } else {
1030a6afd9f3SGreg Kroah-Hartman /*
1031a6afd9f3SGreg Kroah-Hartman * OK, past this point, all the error checking has been done.
1032a6afd9f3SGreg Kroah-Hartman * At this point, we start making changes.....
1033a6afd9f3SGreg Kroah-Hartman */
1034a6afd9f3SGreg Kroah-Hartman port->flags = ((port->flags & ~ASYNC_FLAGS) |
10356da5b587SAl Viro (ss->flags & ASYNC_FLAGS));
1036be6cf583SJohan Hovold port->close_delay = close_delay;
1037be6cf583SJohan Hovold port->closing_wait = closing_wait;
1038a6afd9f3SGreg Kroah-Hartman if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
1039a6970c39SJiri Slaby (ss->baud_base != MXSER_BAUD_BASE ||
10406da5b587SAl Viro ss->custom_divisor !=
1041d811b26bSJiri Slaby MXSER_CUSTOM_DIVISOR)) {
10426da5b587SAl Viro if (ss->custom_divisor == 0) {
10436da5b587SAl Viro mutex_unlock(&port->mutex);
1044a6afd9f3SGreg Kroah-Hartman return -EINVAL;
10456da5b587SAl Viro }
10466da5b587SAl Viro baud = ss->baud_base / ss->custom_divisor;
1047a6afd9f3SGreg Kroah-Hartman tty_encode_baud_rate(tty, baud, baud);
1048a6afd9f3SGreg Kroah-Hartman }
1049a6afd9f3SGreg Kroah-Hartman
10506da5b587SAl Viro info->type = ss->type;
1051a6afd9f3SGreg Kroah-Hartman
1052c3db20c3SJiri Slaby mxser_process_txrx_fifo(info);
1053b91cfb25SJohan Hovold }
1054a6afd9f3SGreg Kroah-Hartman
1055d41861caSPeter Hurley if (tty_port_initialized(port)) {
105606cc52efSJiri Slaby if (old_speed != (port->flags & ASYNC_SPD_MASK)) {
1057a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, sl_flags);
10583fdfa165SJiri Slaby mxser_change_speed(tty, NULL);
1059a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, sl_flags);
1060a6afd9f3SGreg Kroah-Hartman }
1061a6afd9f3SGreg Kroah-Hartman } else {
1062a6afd9f3SGreg Kroah-Hartman retval = mxser_activate(port, tty);
1063a6afd9f3SGreg Kroah-Hartman if (retval == 0)
1064515be7baSIlpo Järvinen tty_port_set_initialized(port, true);
1065a6afd9f3SGreg Kroah-Hartman }
10666da5b587SAl Viro mutex_unlock(&port->mutex);
1067a6afd9f3SGreg Kroah-Hartman return retval;
1068a6afd9f3SGreg Kroah-Hartman }
1069a6afd9f3SGreg Kroah-Hartman
1070a6afd9f3SGreg Kroah-Hartman /*
1071a6afd9f3SGreg Kroah-Hartman * mxser_get_lsr_info - get line status register info
1072a6afd9f3SGreg Kroah-Hartman *
1073a6afd9f3SGreg Kroah-Hartman * Purpose: Let user call ioctl() to get info when the UART physically
1074a6afd9f3SGreg Kroah-Hartman * is emptied. On bus types like RS485, the transmitter must
1075a6afd9f3SGreg Kroah-Hartman * release the bus after transmitting. This must be done when
1076a6afd9f3SGreg Kroah-Hartman * the transmit shift register is empty, not be done when the
1077a6afd9f3SGreg Kroah-Hartman * transmit holding register is empty. This functionality
1078a6afd9f3SGreg Kroah-Hartman * allows an RS485 driver to be written in user space.
1079a6afd9f3SGreg Kroah-Hartman */
mxser_get_lsr_info(struct mxser_port * info,unsigned int __user * value)1080a6afd9f3SGreg Kroah-Hartman static int mxser_get_lsr_info(struct mxser_port *info,
1081a6afd9f3SGreg Kroah-Hartman unsigned int __user *value)
1082a6afd9f3SGreg Kroah-Hartman {
1083a6afd9f3SGreg Kroah-Hartman unsigned char status;
1084a6afd9f3SGreg Kroah-Hartman unsigned int result;
1085a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1086a6afd9f3SGreg Kroah-Hartman
1087a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1088a6afd9f3SGreg Kroah-Hartman status = inb(info->ioaddr + UART_LSR);
1089a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1090a6afd9f3SGreg Kroah-Hartman result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1091a6afd9f3SGreg Kroah-Hartman return put_user(result, value);
1092a6afd9f3SGreg Kroah-Hartman }
1093a6afd9f3SGreg Kroah-Hartman
mxser_tiocmget(struct tty_struct * tty)1094a6afd9f3SGreg Kroah-Hartman static int mxser_tiocmget(struct tty_struct *tty)
1095a6afd9f3SGreg Kroah-Hartman {
1096a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
109730f6027fSJiri Slaby unsigned char control;
1098a6afd9f3SGreg Kroah-Hartman unsigned long flags;
109930f6027fSJiri Slaby u8 msr;
1100a6afd9f3SGreg Kroah-Hartman
110118900ca6SPeter Hurley if (tty_io_error(tty))
1102a6afd9f3SGreg Kroah-Hartman return -EIO;
1103a6afd9f3SGreg Kroah-Hartman
1104a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1105202acdaaSJiri Slaby control = info->MCR;
110630f6027fSJiri Slaby msr = mxser_check_modem_status(tty, info);
1107a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1108202acdaaSJiri Slaby
1109a6afd9f3SGreg Kroah-Hartman return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
1110a6afd9f3SGreg Kroah-Hartman ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
111130f6027fSJiri Slaby ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) |
111230f6027fSJiri Slaby ((msr & UART_MSR_RI) ? TIOCM_RNG : 0) |
111330f6027fSJiri Slaby ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0) |
111430f6027fSJiri Slaby ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0);
1115a6afd9f3SGreg Kroah-Hartman }
1116a6afd9f3SGreg Kroah-Hartman
mxser_tiocmset(struct tty_struct * tty,unsigned int set,unsigned int clear)1117a6afd9f3SGreg Kroah-Hartman static int mxser_tiocmset(struct tty_struct *tty,
1118a6afd9f3SGreg Kroah-Hartman unsigned int set, unsigned int clear)
1119a6afd9f3SGreg Kroah-Hartman {
1120a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1121a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1122a6afd9f3SGreg Kroah-Hartman
112318900ca6SPeter Hurley if (tty_io_error(tty))
1124a6afd9f3SGreg Kroah-Hartman return -EIO;
1125a6afd9f3SGreg Kroah-Hartman
1126a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1127a6afd9f3SGreg Kroah-Hartman
1128a6afd9f3SGreg Kroah-Hartman if (set & TIOCM_RTS)
1129a6afd9f3SGreg Kroah-Hartman info->MCR |= UART_MCR_RTS;
1130a6afd9f3SGreg Kroah-Hartman if (set & TIOCM_DTR)
1131a6afd9f3SGreg Kroah-Hartman info->MCR |= UART_MCR_DTR;
1132a6afd9f3SGreg Kroah-Hartman
1133a6afd9f3SGreg Kroah-Hartman if (clear & TIOCM_RTS)
1134a6afd9f3SGreg Kroah-Hartman info->MCR &= ~UART_MCR_RTS;
1135a6afd9f3SGreg Kroah-Hartman if (clear & TIOCM_DTR)
1136a6afd9f3SGreg Kroah-Hartman info->MCR &= ~UART_MCR_DTR;
1137a6afd9f3SGreg Kroah-Hartman
1138a6afd9f3SGreg Kroah-Hartman outb(info->MCR, info->ioaddr + UART_MCR);
1139a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1140a6afd9f3SGreg Kroah-Hartman return 0;
1141a6afd9f3SGreg Kroah-Hartman }
1142a6afd9f3SGreg Kroah-Hartman
mxser_cflags_changed(struct mxser_port * info,unsigned long arg,struct async_icount * cprev)1143a6afd9f3SGreg Kroah-Hartman static int mxser_cflags_changed(struct mxser_port *info, unsigned long arg,
1144a6afd9f3SGreg Kroah-Hartman struct async_icount *cprev)
1145a6afd9f3SGreg Kroah-Hartman {
1146a6afd9f3SGreg Kroah-Hartman struct async_icount cnow;
1147a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1148a6afd9f3SGreg Kroah-Hartman int ret;
1149a6afd9f3SGreg Kroah-Hartman
1150a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1151a6afd9f3SGreg Kroah-Hartman cnow = info->icount; /* atomic copy */
1152a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1153a6afd9f3SGreg Kroah-Hartman
1154a6afd9f3SGreg Kroah-Hartman ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
1155a6afd9f3SGreg Kroah-Hartman ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
1156a6afd9f3SGreg Kroah-Hartman ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
1157a6afd9f3SGreg Kroah-Hartman ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
1158a6afd9f3SGreg Kroah-Hartman
1159a6afd9f3SGreg Kroah-Hartman *cprev = cnow;
1160a6afd9f3SGreg Kroah-Hartman
1161a6afd9f3SGreg Kroah-Hartman return ret;
1162a6afd9f3SGreg Kroah-Hartman }
1163a6afd9f3SGreg Kroah-Hartman
11649fae5f85SJiri Slaby /* We should likely switch to TIOCGRS485/TIOCSRS485. */
mxser_ioctl_op_mode(struct mxser_port * port,int index,bool set,int __user * u_opmode)11659fae5f85SJiri Slaby static int mxser_ioctl_op_mode(struct mxser_port *port, int index, bool set,
11669fae5f85SJiri Slaby int __user *u_opmode)
11679fae5f85SJiri Slaby {
11689fae5f85SJiri Slaby int opmode, p = index % 4;
11699fae5f85SJiri Slaby int shiftbit = p * 2;
1170238d117dSJiri Slaby u8 val;
11719fae5f85SJiri Slaby
11729fae5f85SJiri Slaby if (port->board->must_hwid != MOXA_MUST_MU860_HWID)
11739fae5f85SJiri Slaby return -EFAULT;
11749fae5f85SJiri Slaby
11759fae5f85SJiri Slaby if (set) {
11769fae5f85SJiri Slaby if (get_user(opmode, u_opmode))
11779fae5f85SJiri Slaby return -EFAULT;
11789fae5f85SJiri Slaby
1179238d117dSJiri Slaby if (opmode & ~OP_MODE_MASK)
1180238d117dSJiri Slaby return -EINVAL;
11819fae5f85SJiri Slaby
11829fae5f85SJiri Slaby spin_lock_irq(&port->slock);
11839fae5f85SJiri Slaby val = inb(port->opmode_ioaddr);
1184238d117dSJiri Slaby val &= ~(OP_MODE_MASK << shiftbit);
11859fae5f85SJiri Slaby val |= (opmode << shiftbit);
11869fae5f85SJiri Slaby outb(val, port->opmode_ioaddr);
11879fae5f85SJiri Slaby spin_unlock_irq(&port->slock);
1188238d117dSJiri Slaby
1189238d117dSJiri Slaby return 0;
1190238d117dSJiri Slaby }
1191238d117dSJiri Slaby
11929fae5f85SJiri Slaby spin_lock_irq(&port->slock);
11939fae5f85SJiri Slaby opmode = inb(port->opmode_ioaddr) >> shiftbit;
11949fae5f85SJiri Slaby spin_unlock_irq(&port->slock);
11959fae5f85SJiri Slaby
1196238d117dSJiri Slaby return put_user(opmode & OP_MODE_MASK, u_opmode);
11979fae5f85SJiri Slaby }
11989fae5f85SJiri Slaby
mxser_ioctl(struct tty_struct * tty,unsigned int cmd,unsigned long arg)1199a6afd9f3SGreg Kroah-Hartman static int mxser_ioctl(struct tty_struct *tty,
1200a6afd9f3SGreg Kroah-Hartman unsigned int cmd, unsigned long arg)
1201a6afd9f3SGreg Kroah-Hartman {
1202a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1203a6afd9f3SGreg Kroah-Hartman struct async_icount cnow;
1204a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1205a6afd9f3SGreg Kroah-Hartman void __user *argp = (void __user *)arg;
1206a6afd9f3SGreg Kroah-Hartman
12079fae5f85SJiri Slaby if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE)
12089fae5f85SJiri Slaby return mxser_ioctl_op_mode(info, tty->index,
12099fae5f85SJiri Slaby cmd == MOXA_SET_OP_MODE, argp);
1210a6afd9f3SGreg Kroah-Hartman
12116da5b587SAl Viro if (cmd != TIOCMIWAIT && tty_io_error(tty))
1212a6afd9f3SGreg Kroah-Hartman return -EIO;
1213a6afd9f3SGreg Kroah-Hartman
1214a6afd9f3SGreg Kroah-Hartman switch (cmd) {
1215a6afd9f3SGreg Kroah-Hartman case TIOCSERGETLSR: /* Get line status register */
1216a6afd9f3SGreg Kroah-Hartman return mxser_get_lsr_info(info, argp);
1217a6afd9f3SGreg Kroah-Hartman /*
1218a6afd9f3SGreg Kroah-Hartman * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1219a6afd9f3SGreg Kroah-Hartman * - mask passed in arg for lines of interest
1220a6afd9f3SGreg Kroah-Hartman * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1221a6afd9f3SGreg Kroah-Hartman * Caller should use TIOCGICOUNT to see which one it was
1222a6afd9f3SGreg Kroah-Hartman */
1223a6afd9f3SGreg Kroah-Hartman case TIOCMIWAIT:
1224a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1225a6afd9f3SGreg Kroah-Hartman cnow = info->icount; /* note the counters on entry */
1226a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1227a6afd9f3SGreg Kroah-Hartman
1228a6afd9f3SGreg Kroah-Hartman return wait_event_interruptible(info->port.delta_msr_wait,
1229a6afd9f3SGreg Kroah-Hartman mxser_cflags_changed(info, arg, &cnow));
1230a6afd9f3SGreg Kroah-Hartman default:
1231a6afd9f3SGreg Kroah-Hartman return -ENOIOCTLCMD;
1232a6afd9f3SGreg Kroah-Hartman }
1233a6afd9f3SGreg Kroah-Hartman return 0;
1234a6afd9f3SGreg Kroah-Hartman }
1235a6afd9f3SGreg Kroah-Hartman
1236a6afd9f3SGreg Kroah-Hartman /*
1237a6afd9f3SGreg Kroah-Hartman * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1238a6afd9f3SGreg Kroah-Hartman * Return: write counters to the user passed counter struct
1239a6afd9f3SGreg Kroah-Hartman * NB: both 1->0 and 0->1 transitions are counted except for
1240a6afd9f3SGreg Kroah-Hartman * RI where only 0->1 is counted.
1241a6afd9f3SGreg Kroah-Hartman */
1242a6afd9f3SGreg Kroah-Hartman
mxser_get_icount(struct tty_struct * tty,struct serial_icounter_struct * icount)1243a6afd9f3SGreg Kroah-Hartman static int mxser_get_icount(struct tty_struct *tty,
1244a6afd9f3SGreg Kroah-Hartman struct serial_icounter_struct *icount)
1245a6afd9f3SGreg Kroah-Hartman
1246a6afd9f3SGreg Kroah-Hartman {
1247a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1248a6afd9f3SGreg Kroah-Hartman struct async_icount cnow;
1249a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1250a6afd9f3SGreg Kroah-Hartman
1251a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1252a6afd9f3SGreg Kroah-Hartman cnow = info->icount;
1253a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1254a6afd9f3SGreg Kroah-Hartman
1255a6afd9f3SGreg Kroah-Hartman icount->frame = cnow.frame;
1256a6afd9f3SGreg Kroah-Hartman icount->brk = cnow.brk;
1257a6afd9f3SGreg Kroah-Hartman icount->overrun = cnow.overrun;
1258a6afd9f3SGreg Kroah-Hartman icount->buf_overrun = cnow.buf_overrun;
1259a6afd9f3SGreg Kroah-Hartman icount->parity = cnow.parity;
1260a6afd9f3SGreg Kroah-Hartman icount->rx = cnow.rx;
1261a6afd9f3SGreg Kroah-Hartman icount->tx = cnow.tx;
1262a6afd9f3SGreg Kroah-Hartman icount->cts = cnow.cts;
1263a6afd9f3SGreg Kroah-Hartman icount->dsr = cnow.dsr;
1264a6afd9f3SGreg Kroah-Hartman icount->rng = cnow.rng;
1265a6afd9f3SGreg Kroah-Hartman icount->dcd = cnow.dcd;
1266a6afd9f3SGreg Kroah-Hartman return 0;
1267a6afd9f3SGreg Kroah-Hartman }
1268a6afd9f3SGreg Kroah-Hartman
1269c6693e6eSJiri Slaby /*
1270c6693e6eSJiri Slaby * This routine is called by the upper-layer tty layer to signal that
1271c6693e6eSJiri Slaby * incoming characters should be throttled.
1272c6693e6eSJiri Slaby */
mxser_throttle(struct tty_struct * tty)1273c6693e6eSJiri Slaby static void mxser_throttle(struct tty_struct *tty)
1274a6afd9f3SGreg Kroah-Hartman {
1275a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1276a6afd9f3SGreg Kroah-Hartman
1277a6afd9f3SGreg Kroah-Hartman if (I_IXOFF(tty)) {
1278292955a7SJiri Slaby if (info->board->must_hwid) {
1279a6afd9f3SGreg Kroah-Hartman info->IER &= ~MOXA_MUST_RECV_ISR;
1280a6afd9f3SGreg Kroah-Hartman outb(info->IER, info->ioaddr + UART_IER);
1281a6afd9f3SGreg Kroah-Hartman } else {
1282a6afd9f3SGreg Kroah-Hartman info->x_char = STOP_CHAR(tty);
1283a6afd9f3SGreg Kroah-Hartman outb(0, info->ioaddr + UART_IER);
1284a6afd9f3SGreg Kroah-Hartman info->IER |= UART_IER_THRI;
1285a6afd9f3SGreg Kroah-Hartman outb(info->IER, info->ioaddr + UART_IER);
1286a6afd9f3SGreg Kroah-Hartman }
1287a6afd9f3SGreg Kroah-Hartman }
1288a6afd9f3SGreg Kroah-Hartman
12899db276f8SPeter Hurley if (C_CRTSCTS(tty)) {
1290a6afd9f3SGreg Kroah-Hartman info->MCR &= ~UART_MCR_RTS;
1291a6afd9f3SGreg Kroah-Hartman outb(info->MCR, info->ioaddr + UART_MCR);
1292a6afd9f3SGreg Kroah-Hartman }
1293a6afd9f3SGreg Kroah-Hartman }
1294a6afd9f3SGreg Kroah-Hartman
mxser_unthrottle(struct tty_struct * tty)1295a6afd9f3SGreg Kroah-Hartman static void mxser_unthrottle(struct tty_struct *tty)
1296a6afd9f3SGreg Kroah-Hartman {
1297a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1298a6afd9f3SGreg Kroah-Hartman
1299a6afd9f3SGreg Kroah-Hartman /* startrx */
1300a6afd9f3SGreg Kroah-Hartman if (I_IXOFF(tty)) {
1301a6afd9f3SGreg Kroah-Hartman if (info->x_char)
1302a6afd9f3SGreg Kroah-Hartman info->x_char = 0;
1303a6afd9f3SGreg Kroah-Hartman else {
1304292955a7SJiri Slaby if (info->board->must_hwid) {
1305a6afd9f3SGreg Kroah-Hartman info->IER |= MOXA_MUST_RECV_ISR;
1306a6afd9f3SGreg Kroah-Hartman outb(info->IER, info->ioaddr + UART_IER);
1307a6afd9f3SGreg Kroah-Hartman } else {
1308a6afd9f3SGreg Kroah-Hartman info->x_char = START_CHAR(tty);
1309a6afd9f3SGreg Kroah-Hartman outb(0, info->ioaddr + UART_IER);
1310a6afd9f3SGreg Kroah-Hartman info->IER |= UART_IER_THRI;
1311a6afd9f3SGreg Kroah-Hartman outb(info->IER, info->ioaddr + UART_IER);
1312a6afd9f3SGreg Kroah-Hartman }
1313a6afd9f3SGreg Kroah-Hartman }
1314a6afd9f3SGreg Kroah-Hartman }
1315a6afd9f3SGreg Kroah-Hartman
13169db276f8SPeter Hurley if (C_CRTSCTS(tty)) {
1317a6afd9f3SGreg Kroah-Hartman info->MCR |= UART_MCR_RTS;
1318a6afd9f3SGreg Kroah-Hartman outb(info->MCR, info->ioaddr + UART_MCR);
1319a6afd9f3SGreg Kroah-Hartman }
1320a6afd9f3SGreg Kroah-Hartman }
1321a6afd9f3SGreg Kroah-Hartman
1322a6afd9f3SGreg Kroah-Hartman /*
1323a6afd9f3SGreg Kroah-Hartman * mxser_stop() and mxser_start()
1324a6afd9f3SGreg Kroah-Hartman *
13256e94dbc7SJiri Slaby * This routines are called before setting or resetting tty->flow.stopped.
1326a6afd9f3SGreg Kroah-Hartman * They enable or disable transmitter interrupts, as necessary.
1327a6afd9f3SGreg Kroah-Hartman */
mxser_stop(struct tty_struct * tty)1328a6afd9f3SGreg Kroah-Hartman static void mxser_stop(struct tty_struct *tty)
1329a6afd9f3SGreg Kroah-Hartman {
1330a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1331a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1332a6afd9f3SGreg Kroah-Hartman
1333a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1334740165f7SJiri Slaby if (info->IER & UART_IER_THRI)
1335740165f7SJiri Slaby __mxser_stop_tx(info);
1336a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1337a6afd9f3SGreg Kroah-Hartman }
1338a6afd9f3SGreg Kroah-Hartman
mxser_start(struct tty_struct * tty)1339a6afd9f3SGreg Kroah-Hartman static void mxser_start(struct tty_struct *tty)
1340a6afd9f3SGreg Kroah-Hartman {
1341a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1342a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1343a6afd9f3SGreg Kroah-Hartman
1344a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
134532330c83SJiri Slaby if (!kfifo_is_empty(&info->port.xmit_fifo))
1346740165f7SJiri Slaby __mxser_start_tx(info);
1347a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1348a6afd9f3SGreg Kroah-Hartman }
1349a6afd9f3SGreg Kroah-Hartman
mxser_set_termios(struct tty_struct * tty,const struct ktermios * old_termios)1350a8c11c15SIlpo Järvinen static void mxser_set_termios(struct tty_struct *tty,
1351a8c11c15SIlpo Järvinen const struct ktermios *old_termios)
1352a6afd9f3SGreg Kroah-Hartman {
1353a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1354a6afd9f3SGreg Kroah-Hartman unsigned long flags;
1355a6afd9f3SGreg Kroah-Hartman
1356a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
13573fdfa165SJiri Slaby mxser_change_speed(tty, old_termios);
1358a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1359a6afd9f3SGreg Kroah-Hartman
13609db276f8SPeter Hurley if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) {
1361035173c9SIlpo Järvinen tty->hw_stopped = false;
1362a6afd9f3SGreg Kroah-Hartman mxser_start(tty);
1363a6afd9f3SGreg Kroah-Hartman }
1364a6afd9f3SGreg Kroah-Hartman
1365a6afd9f3SGreg Kroah-Hartman /* Handle sw stopped */
13669db276f8SPeter Hurley if ((old_termios->c_iflag & IXON) && !I_IXON(tty)) {
13676e94dbc7SJiri Slaby tty->flow.stopped = 0;
1368a6afd9f3SGreg Kroah-Hartman
1369292955a7SJiri Slaby if (info->board->must_hwid) {
1370a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
1371b441eb0fSJiri Slaby mxser_must_set_rx_sw_flow_control(info->ioaddr, false);
1372a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
1373a6afd9f3SGreg Kroah-Hartman }
1374a6afd9f3SGreg Kroah-Hartman
1375a6afd9f3SGreg Kroah-Hartman mxser_start(tty);
1376a6afd9f3SGreg Kroah-Hartman }
1377a6afd9f3SGreg Kroah-Hartman }
1378a6afd9f3SGreg Kroah-Hartman
mxser_tx_empty(struct mxser_port * info)1379239ef19eSJiri Slaby static bool mxser_tx_empty(struct mxser_port *info)
1380239ef19eSJiri Slaby {
1381239ef19eSJiri Slaby unsigned long flags;
1382239ef19eSJiri Slaby u8 lsr;
1383239ef19eSJiri Slaby
1384239ef19eSJiri Slaby spin_lock_irqsave(&info->slock, flags);
1385239ef19eSJiri Slaby lsr = inb(info->ioaddr + UART_LSR);
1386239ef19eSJiri Slaby spin_unlock_irqrestore(&info->slock, flags);
1387239ef19eSJiri Slaby
1388239ef19eSJiri Slaby return !(lsr & UART_LSR_TEMT);
1389239ef19eSJiri Slaby }
1390239ef19eSJiri Slaby
1391a6afd9f3SGreg Kroah-Hartman /*
1392a6afd9f3SGreg Kroah-Hartman * mxser_wait_until_sent() --- wait until the transmitter is empty
1393a6afd9f3SGreg Kroah-Hartman */
mxser_wait_until_sent(struct tty_struct * tty,int timeout)1394a6afd9f3SGreg Kroah-Hartman static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1395a6afd9f3SGreg Kroah-Hartman {
1396a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
139749b798a6SJiri Slaby unsigned long expire, char_time;
1398a6afd9f3SGreg Kroah-Hartman
1399a6afd9f3SGreg Kroah-Hartman if (info->type == PORT_UNKNOWN)
1400a6afd9f3SGreg Kroah-Hartman return;
1401a6afd9f3SGreg Kroah-Hartman
1402a6afd9f3SGreg Kroah-Hartman if (info->xmit_fifo_size == 0)
1403a6afd9f3SGreg Kroah-Hartman return; /* Just in case.... */
1404a6afd9f3SGreg Kroah-Hartman
1405a6afd9f3SGreg Kroah-Hartman /*
1406a6afd9f3SGreg Kroah-Hartman * Set the check interval to be 1/5 of the estimated time to
1407a6afd9f3SGreg Kroah-Hartman * send a single character, and make it at least 1. The check
1408a6afd9f3SGreg Kroah-Hartman * interval should also be less than the timeout.
1409a6afd9f3SGreg Kroah-Hartman *
1410a6afd9f3SGreg Kroah-Hartman * Note: we have to use pretty tight timings here to satisfy
1411a6afd9f3SGreg Kroah-Hartman * the NIST-PCTS.
1412a6afd9f3SGreg Kroah-Hartman */
1413a6afd9f3SGreg Kroah-Hartman char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1414a6afd9f3SGreg Kroah-Hartman char_time = char_time / 5;
1415a6afd9f3SGreg Kroah-Hartman if (char_time == 0)
1416a6afd9f3SGreg Kroah-Hartman char_time = 1;
1417a6afd9f3SGreg Kroah-Hartman if (timeout && timeout < char_time)
1418a6afd9f3SGreg Kroah-Hartman char_time = timeout;
1419fe74bc61SJiri Slaby
1420fe74bc61SJiri Slaby char_time = jiffies_to_msecs(char_time);
1421fe74bc61SJiri Slaby
1422a6afd9f3SGreg Kroah-Hartman /*
1423a6afd9f3SGreg Kroah-Hartman * If the transmitter hasn't cleared in twice the approximate
1424a6afd9f3SGreg Kroah-Hartman * amount of time to send the entire FIFO, it probably won't
1425a6afd9f3SGreg Kroah-Hartman * ever clear. This assumes the UART isn't doing flow
1426a6afd9f3SGreg Kroah-Hartman * control, which is currently the case. Hence, if it ever
1427a6afd9f3SGreg Kroah-Hartman * takes longer than info->timeout, this is probably due to a
1428a6afd9f3SGreg Kroah-Hartman * UART bug of some kind. So, we clamp the timeout parameter at
1429a6afd9f3SGreg Kroah-Hartman * 2*info->timeout.
1430a6afd9f3SGreg Kroah-Hartman */
1431a6afd9f3SGreg Kroah-Hartman if (!timeout || timeout > 2 * info->timeout)
1432a6afd9f3SGreg Kroah-Hartman timeout = 2 * info->timeout;
14338bab534bSJiri Slaby
143449b798a6SJiri Slaby expire = jiffies + timeout;
143549b798a6SJiri Slaby
1436239ef19eSJiri Slaby while (mxser_tx_empty(info)) {
1437fe74bc61SJiri Slaby msleep_interruptible(char_time);
1438a6afd9f3SGreg Kroah-Hartman if (signal_pending(current))
1439a6afd9f3SGreg Kroah-Hartman break;
144049b798a6SJiri Slaby if (time_after(jiffies, expire))
1441a6afd9f3SGreg Kroah-Hartman break;
1442a6afd9f3SGreg Kroah-Hartman }
1443a6afd9f3SGreg Kroah-Hartman }
1444a6afd9f3SGreg Kroah-Hartman
1445a6afd9f3SGreg Kroah-Hartman /*
1446a6afd9f3SGreg Kroah-Hartman * This routine is called by tty_hangup() when a hangup is signaled.
1447a6afd9f3SGreg Kroah-Hartman */
mxser_hangup(struct tty_struct * tty)1448a6afd9f3SGreg Kroah-Hartman static void mxser_hangup(struct tty_struct *tty)
1449a6afd9f3SGreg Kroah-Hartman {
1450a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1451a6afd9f3SGreg Kroah-Hartman
1452a6afd9f3SGreg Kroah-Hartman mxser_flush_buffer(tty);
1453a6afd9f3SGreg Kroah-Hartman tty_port_hangup(&info->port);
1454a6afd9f3SGreg Kroah-Hartman }
1455a6afd9f3SGreg Kroah-Hartman
1456a6afd9f3SGreg Kroah-Hartman /*
1457a6afd9f3SGreg Kroah-Hartman * mxser_rs_break() --- routine which turns the break handling on or off
1458a6afd9f3SGreg Kroah-Hartman */
mxser_rs_break(struct tty_struct * tty,int break_state)1459a6afd9f3SGreg Kroah-Hartman static int mxser_rs_break(struct tty_struct *tty, int break_state)
1460a6afd9f3SGreg Kroah-Hartman {
1461a6afd9f3SGreg Kroah-Hartman struct mxser_port *info = tty->driver_data;
1462a6afd9f3SGreg Kroah-Hartman unsigned long flags;
146359908433SJiri Slaby u8 lcr;
1464a6afd9f3SGreg Kroah-Hartman
1465a6afd9f3SGreg Kroah-Hartman spin_lock_irqsave(&info->slock, flags);
146659908433SJiri Slaby lcr = inb(info->ioaddr + UART_LCR);
1467a6afd9f3SGreg Kroah-Hartman if (break_state == -1)
146859908433SJiri Slaby lcr |= UART_LCR_SBC;
1469a6afd9f3SGreg Kroah-Hartman else
147059908433SJiri Slaby lcr &= ~UART_LCR_SBC;
147159908433SJiri Slaby outb(lcr, info->ioaddr + UART_LCR);
1472a6afd9f3SGreg Kroah-Hartman spin_unlock_irqrestore(&info->slock, flags);
147359908433SJiri Slaby
1474a6afd9f3SGreg Kroah-Hartman return 0;
1475a6afd9f3SGreg Kroah-Hartman }
1476a6afd9f3SGreg Kroah-Hartman
mxser_receive_chars_new(struct mxser_port * port,u8 status)14779dd6f306SJiri Slaby static bool mxser_receive_chars_new(struct mxser_port *port, u8 status)
1478e5ce1bceSJiri Slaby {
1479e5ce1bceSJiri Slaby enum mxser_must_hwid hwid = port->board->must_hwid;
1480e5ce1bceSJiri Slaby u8 gdl;
1481e5ce1bceSJiri Slaby
1482e5ce1bceSJiri Slaby if (hwid == MOXA_OTHER_UART)
1483e5ce1bceSJiri Slaby return false;
14847d5006d5SJiri Slaby if (status & (UART_LSR_BRK_ERROR_BITS | MOXA_MUST_LSR_RERR))
1485e5ce1bceSJiri Slaby return false;
1486e5ce1bceSJiri Slaby
1487e5ce1bceSJiri Slaby gdl = inb(port->ioaddr + MOXA_MUST_GDL_REGISTER);
1488e5ce1bceSJiri Slaby if (hwid == MOXA_MUST_MU150_HWID)
1489e5ce1bceSJiri Slaby gdl &= MOXA_MUST_GDL_MASK;
1490e5ce1bceSJiri Slaby
1491e5ce1bceSJiri Slaby while (gdl--) {
1492e5ce1bceSJiri Slaby u8 ch = inb(port->ioaddr + UART_RX);
1493eb68ac04SJiri Slaby if (!tty_insert_flip_char(&port->port, ch, 0))
1494eb68ac04SJiri Slaby port->icount.buf_overrun++;
1495e5ce1bceSJiri Slaby }
1496e5ce1bceSJiri Slaby
1497e5ce1bceSJiri Slaby return true;
1498e5ce1bceSJiri Slaby }
1499e5ce1bceSJiri Slaby
mxser_receive_chars_old(struct tty_struct * tty,struct mxser_port * port,u8 status)15000c419421SJiri Slaby static u8 mxser_receive_chars_old(struct tty_struct *tty,
150195b3ea4cSJiri Slaby struct mxser_port *port, u8 status)
1502a6afd9f3SGreg Kroah-Hartman {
15030c419421SJiri Slaby enum mxser_must_hwid hwid = port->board->must_hwid;
1504a6afd9f3SGreg Kroah-Hartman int ignored = 0;
1505a6afd9f3SGreg Kroah-Hartman int max = 256;
15060c419421SJiri Slaby u8 ch;
1507a6afd9f3SGreg Kroah-Hartman
1508a6afd9f3SGreg Kroah-Hartman do {
1509a6afd9f3SGreg Kroah-Hartman if (max-- < 0)
1510a6afd9f3SGreg Kroah-Hartman break;
1511a6afd9f3SGreg Kroah-Hartman
1512a6afd9f3SGreg Kroah-Hartman ch = inb(port->ioaddr + UART_RX);
15130c419421SJiri Slaby if (hwid && (status & UART_LSR_OE))
1514d249e662SJiri Slaby outb(port->FCR | UART_FCR_CLEAR_RCVR,
1515aaa28e9fSJiri Slaby port->ioaddr + UART_FCR);
151615517806SJiri Slaby status &= port->read_status_mask;
151715517806SJiri Slaby if (status & port->ignore_status_mask) {
1518a6afd9f3SGreg Kroah-Hartman if (++ignored > 100)
1519a6afd9f3SGreg Kroah-Hartman break;
1520a6afd9f3SGreg Kroah-Hartman } else {
152159b94335SJiri Slaby (SUSE) u8 flag = 0;
152270640052SJiri Slaby if (status & UART_LSR_BRK_ERROR_BITS) {
152315517806SJiri Slaby if (status & UART_LSR_BI) {
1524a6afd9f3SGreg Kroah-Hartman flag = TTY_BREAK;
1525a6afd9f3SGreg Kroah-Hartman port->icount.brk++;
1526a6afd9f3SGreg Kroah-Hartman
1527a6afd9f3SGreg Kroah-Hartman if (port->port.flags & ASYNC_SAK)
1528a6afd9f3SGreg Kroah-Hartman do_SAK(tty);
152915517806SJiri Slaby } else if (status & UART_LSR_PE) {
1530a6afd9f3SGreg Kroah-Hartman flag = TTY_PARITY;
1531a6afd9f3SGreg Kroah-Hartman port->icount.parity++;
153215517806SJiri Slaby } else if (status & UART_LSR_FE) {
1533a6afd9f3SGreg Kroah-Hartman flag = TTY_FRAME;
1534a6afd9f3SGreg Kroah-Hartman port->icount.frame++;
153515517806SJiri Slaby } else if (status & UART_LSR_OE) {
1536a6afd9f3SGreg Kroah-Hartman flag = TTY_OVERRUN;
1537a6afd9f3SGreg Kroah-Hartman port->icount.overrun++;
15386de6e5c4SJiri Slaby }
1539a6afd9f3SGreg Kroah-Hartman }
1540eb68ac04SJiri Slaby if (!tty_insert_flip_char(&port->port, ch, flag)) {
1541eb68ac04SJiri Slaby port->icount.buf_overrun++;
1542a6afd9f3SGreg Kroah-Hartman break;
1543a6afd9f3SGreg Kroah-Hartman }
1544eb68ac04SJiri Slaby }
1545a6afd9f3SGreg Kroah-Hartman
15460c419421SJiri Slaby if (hwid)
1547a6afd9f3SGreg Kroah-Hartman break;
1548a6afd9f3SGreg Kroah-Hartman
154915517806SJiri Slaby status = inb(port->ioaddr + UART_LSR);
155015517806SJiri Slaby } while (status & UART_LSR_DR);
1551a6afd9f3SGreg Kroah-Hartman
15520c419421SJiri Slaby return status;
15530c419421SJiri Slaby }
15540c419421SJiri Slaby
mxser_receive_chars(struct tty_struct * tty,struct mxser_port * port,u8 status)15550c419421SJiri Slaby static u8 mxser_receive_chars(struct tty_struct *tty,
15560c419421SJiri Slaby struct mxser_port *port, u8 status)
15570c419421SJiri Slaby {
15589dd6f306SJiri Slaby if (!mxser_receive_chars_new(port, status))
155995b3ea4cSJiri Slaby status = mxser_receive_chars_old(tty, port, status);
15600c419421SJiri Slaby
15612e124b4aSJiri Slaby tty_flip_buffer_push(&port->port);
156215517806SJiri Slaby
156315517806SJiri Slaby return status;
1564a6afd9f3SGreg Kroah-Hartman }
1565a6afd9f3SGreg Kroah-Hartman
mxser_transmit_chars(struct tty_struct * tty,struct mxser_port * port)1566a6afd9f3SGreg Kroah-Hartman static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port)
1567a6afd9f3SGreg Kroah-Hartman {
15683b88dbffSJiri Slaby int count;
1569a6afd9f3SGreg Kroah-Hartman
1570a6afd9f3SGreg Kroah-Hartman if (port->x_char) {
1571a6afd9f3SGreg Kroah-Hartman outb(port->x_char, port->ioaddr + UART_TX);
1572a6afd9f3SGreg Kroah-Hartman port->x_char = 0;
1573a6afd9f3SGreg Kroah-Hartman port->icount.tx++;
1574a6afd9f3SGreg Kroah-Hartman return;
1575a6afd9f3SGreg Kroah-Hartman }
1576a6afd9f3SGreg Kroah-Hartman
157732330c83SJiri Slaby if (kfifo_is_empty(&port->port.xmit_fifo) || tty->flow.stopped ||
15785d1ea1adSJiri Slaby (tty->hw_stopped && !mxser_16550A_or_MUST(port))) {
1579740165f7SJiri Slaby __mxser_stop_tx(port);
1580a6afd9f3SGreg Kroah-Hartman return;
1581a6afd9f3SGreg Kroah-Hartman }
1582a6afd9f3SGreg Kroah-Hartman
1583a6afd9f3SGreg Kroah-Hartman count = port->xmit_fifo_size;
1584a6afd9f3SGreg Kroah-Hartman do {
158559b94335SJiri Slaby (SUSE) u8 c;
158632330c83SJiri Slaby
158732330c83SJiri Slaby if (!kfifo_get(&port->port.xmit_fifo, &c))
1588a6afd9f3SGreg Kroah-Hartman break;
158932330c83SJiri Slaby
159032330c83SJiri Slaby outb(c, port->ioaddr + UART_TX);
159132330c83SJiri Slaby port->icount.tx++;
1592a6afd9f3SGreg Kroah-Hartman } while (--count > 0);
1593a6afd9f3SGreg Kroah-Hartman
159432330c83SJiri Slaby if (kfifo_len(&port->port.xmit_fifo) < WAKEUP_CHARS)
1595a6afd9f3SGreg Kroah-Hartman tty_wakeup(tty);
1596a6afd9f3SGreg Kroah-Hartman
159732330c83SJiri Slaby if (kfifo_is_empty(&port->port.xmit_fifo))
1598740165f7SJiri Slaby __mxser_stop_tx(port);
1599a6afd9f3SGreg Kroah-Hartman }
1600a6afd9f3SGreg Kroah-Hartman
mxser_port_isr(struct mxser_port * port)16019e40ea1fSJiri Slaby static bool mxser_port_isr(struct mxser_port *port)
16029e40ea1fSJiri Slaby {
16039e40ea1fSJiri Slaby struct tty_struct *tty;
160430f6027fSJiri Slaby u8 iir, status;
16059e40ea1fSJiri Slaby bool error = false;
16069e40ea1fSJiri Slaby
16079e40ea1fSJiri Slaby iir = inb(port->ioaddr + UART_IIR);
16089e40ea1fSJiri Slaby if (iir & UART_IIR_NO_INT)
16099e40ea1fSJiri Slaby return true;
16109e40ea1fSJiri Slaby
16119e40ea1fSJiri Slaby iir &= MOXA_MUST_IIR_MASK;
16129e40ea1fSJiri Slaby tty = tty_port_tty_get(&port->port);
1613274ab58dSJiri Slaby if (!tty) {
16149e40ea1fSJiri Slaby status = inb(port->ioaddr + UART_LSR);
1615d249e662SJiri Slaby outb(port->FCR | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
1616aaa28e9fSJiri Slaby port->ioaddr + UART_FCR);
16179e40ea1fSJiri Slaby inb(port->ioaddr + UART_MSR);
16189e40ea1fSJiri Slaby
16199e40ea1fSJiri Slaby error = true;
16209e40ea1fSJiri Slaby goto put_tty;
16219e40ea1fSJiri Slaby }
16229e40ea1fSJiri Slaby
16239e40ea1fSJiri Slaby status = inb(port->ioaddr + UART_LSR);
16249e40ea1fSJiri Slaby
16259e40ea1fSJiri Slaby if (port->board->must_hwid) {
16269e40ea1fSJiri Slaby if (iir == MOXA_MUST_IIR_GDA ||
16279e40ea1fSJiri Slaby iir == MOXA_MUST_IIR_RDA ||
16289e40ea1fSJiri Slaby iir == MOXA_MUST_IIR_RTO ||
16299e40ea1fSJiri Slaby iir == MOXA_MUST_IIR_LSR)
16309e40ea1fSJiri Slaby status = mxser_receive_chars(tty, port, status);
16319e40ea1fSJiri Slaby } else {
16329e40ea1fSJiri Slaby status &= port->read_status_mask;
16339e40ea1fSJiri Slaby if (status & UART_LSR_DR)
16349e40ea1fSJiri Slaby status = mxser_receive_chars(tty, port, status);
16359e40ea1fSJiri Slaby }
16369e40ea1fSJiri Slaby
163730f6027fSJiri Slaby mxser_check_modem_status(tty, port);
16389e40ea1fSJiri Slaby
16399e40ea1fSJiri Slaby if (port->board->must_hwid) {
16409e40ea1fSJiri Slaby if (iir == 0x02 && (status & UART_LSR_THRE))
16419e40ea1fSJiri Slaby mxser_transmit_chars(tty, port);
16429e40ea1fSJiri Slaby } else {
16439e40ea1fSJiri Slaby if (status & UART_LSR_THRE)
16449e40ea1fSJiri Slaby mxser_transmit_chars(tty, port);
16459e40ea1fSJiri Slaby }
16469e40ea1fSJiri Slaby
16479e40ea1fSJiri Slaby put_tty:
16489e40ea1fSJiri Slaby tty_kref_put(tty);
16499e40ea1fSJiri Slaby
16509e40ea1fSJiri Slaby return error;
16519e40ea1fSJiri Slaby }
16529e40ea1fSJiri Slaby
1653a6afd9f3SGreg Kroah-Hartman /*
1654a6afd9f3SGreg Kroah-Hartman * This is the serial driver's generic interrupt routine
1655a6afd9f3SGreg Kroah-Hartman */
mxser_interrupt(int irq,void * dev_id)1656a6afd9f3SGreg Kroah-Hartman static irqreturn_t mxser_interrupt(int irq, void *dev_id)
1657a6afd9f3SGreg Kroah-Hartman {
1658cef222cbSJiri Slaby struct mxser_board *brd = dev_id;
1659a6afd9f3SGreg Kroah-Hartman struct mxser_port *port;
1660a6afd9f3SGreg Kroah-Hartman unsigned int int_cnt, pass_counter = 0;
1661c24c31ffSJiri Slaby unsigned int i, max = brd->nports;
1662a6afd9f3SGreg Kroah-Hartman int handled = IRQ_NONE;
16639cb5c9c3SJiri Slaby u8 irqbits, bits, mask = BIT(max) - 1;
1664a6afd9f3SGreg Kroah-Hartman
1665a6afd9f3SGreg Kroah-Hartman while (pass_counter++ < MXSER_ISR_PASS_LIMIT) {
16669cb5c9c3SJiri Slaby irqbits = inb(brd->vector) & mask;
16679cb5c9c3SJiri Slaby if (irqbits == mask)
1668a6afd9f3SGreg Kroah-Hartman break;
1669a6afd9f3SGreg Kroah-Hartman
1670a6afd9f3SGreg Kroah-Hartman handled = IRQ_HANDLED;
1671a6afd9f3SGreg Kroah-Hartman for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
16729cb5c9c3SJiri Slaby if (irqbits == mask)
1673a6afd9f3SGreg Kroah-Hartman break;
1674a6afd9f3SGreg Kroah-Hartman if (bits & irqbits)
1675a6afd9f3SGreg Kroah-Hartman continue;
1676a6afd9f3SGreg Kroah-Hartman port = &brd->ports[i];
1677a6afd9f3SGreg Kroah-Hartman
1678a6afd9f3SGreg Kroah-Hartman int_cnt = 0;
1679a6afd9f3SGreg Kroah-Hartman spin_lock(&port->slock);
1680a6afd9f3SGreg Kroah-Hartman do {
16819e40ea1fSJiri Slaby if (mxser_port_isr(port))
1682a6afd9f3SGreg Kroah-Hartman break;
1683a6afd9f3SGreg Kroah-Hartman } while (int_cnt++ < MXSER_ISR_PASS_LIMIT);
1684a6afd9f3SGreg Kroah-Hartman spin_unlock(&port->slock);
1685a6afd9f3SGreg Kroah-Hartman }
1686a6afd9f3SGreg Kroah-Hartman }
1687a6afd9f3SGreg Kroah-Hartman
1688a6afd9f3SGreg Kroah-Hartman return handled;
1689a6afd9f3SGreg Kroah-Hartman }
1690a6afd9f3SGreg Kroah-Hartman
1691a6afd9f3SGreg Kroah-Hartman static const struct tty_operations mxser_ops = {
1692a6afd9f3SGreg Kroah-Hartman .open = mxser_open,
1693a6afd9f3SGreg Kroah-Hartman .close = mxser_close,
1694a6afd9f3SGreg Kroah-Hartman .write = mxser_write,
1695a6afd9f3SGreg Kroah-Hartman .put_char = mxser_put_char,
1696a6afd9f3SGreg Kroah-Hartman .flush_chars = mxser_flush_chars,
1697a6afd9f3SGreg Kroah-Hartman .write_room = mxser_write_room,
1698a6afd9f3SGreg Kroah-Hartman .chars_in_buffer = mxser_chars_in_buffer,
1699a6afd9f3SGreg Kroah-Hartman .flush_buffer = mxser_flush_buffer,
1700a6afd9f3SGreg Kroah-Hartman .ioctl = mxser_ioctl,
1701a6afd9f3SGreg Kroah-Hartman .throttle = mxser_throttle,
1702a6afd9f3SGreg Kroah-Hartman .unthrottle = mxser_unthrottle,
1703a6afd9f3SGreg Kroah-Hartman .set_termios = mxser_set_termios,
1704a6afd9f3SGreg Kroah-Hartman .stop = mxser_stop,
1705a6afd9f3SGreg Kroah-Hartman .start = mxser_start,
1706a6afd9f3SGreg Kroah-Hartman .hangup = mxser_hangup,
1707a6afd9f3SGreg Kroah-Hartman .break_ctl = mxser_rs_break,
1708a6afd9f3SGreg Kroah-Hartman .wait_until_sent = mxser_wait_until_sent,
1709a6afd9f3SGreg Kroah-Hartman .tiocmget = mxser_tiocmget,
1710a6afd9f3SGreg Kroah-Hartman .tiocmset = mxser_tiocmset,
17116da5b587SAl Viro .set_serial = mxser_set_serial_info,
17126da5b587SAl Viro .get_serial = mxser_get_serial_info,
1713a6afd9f3SGreg Kroah-Hartman .get_icount = mxser_get_icount,
1714a6afd9f3SGreg Kroah-Hartman };
1715a6afd9f3SGreg Kroah-Hartman
171604b757dfSAya Mahfouz static const struct tty_port_operations mxser_port_ops = {
1717a6afd9f3SGreg Kroah-Hartman .carrier_raised = mxser_carrier_raised,
1718a6afd9f3SGreg Kroah-Hartman .dtr_rts = mxser_dtr_rts,
1719a6afd9f3SGreg Kroah-Hartman .activate = mxser_activate,
1720a6afd9f3SGreg Kroah-Hartman .shutdown = mxser_shutdown_port,
1721a6afd9f3SGreg Kroah-Hartman };
1722a6afd9f3SGreg Kroah-Hartman
1723a6afd9f3SGreg Kroah-Hartman /*
1724a6afd9f3SGreg Kroah-Hartman * The MOXA Smartio/Industio serial driver boot-time initialization code!
1725a6afd9f3SGreg Kroah-Hartman */
1726a6afd9f3SGreg Kroah-Hartman
mxser_initbrd(struct mxser_board * brd,bool high_baud)1727c24c31ffSJiri Slaby static void mxser_initbrd(struct mxser_board *brd, bool high_baud)
1728a6afd9f3SGreg Kroah-Hartman {
1729a6afd9f3SGreg Kroah-Hartman struct mxser_port *info;
1730a6afd9f3SGreg Kroah-Hartman unsigned int i;
173157faa7d6SJiri Slaby bool is_mu860;
173257faa7d6SJiri Slaby
173357faa7d6SJiri Slaby brd->must_hwid = mxser_must_get_hwid(brd->ports[0].ioaddr);
173457faa7d6SJiri Slaby is_mu860 = brd->must_hwid == MOXA_MUST_MU860_HWID;
173557faa7d6SJiri Slaby
173657faa7d6SJiri Slaby for (i = 0; i < UART_INFO_NUM; i++) {
173757faa7d6SJiri Slaby if (Gpci_uart_info[i].type == brd->must_hwid) {
173857faa7d6SJiri Slaby brd->max_baud = Gpci_uart_info[i].max_baud;
173957faa7d6SJiri Slaby
174057faa7d6SJiri Slaby /* exception....CP-102 */
1741c24c31ffSJiri Slaby if (high_baud)
174257faa7d6SJiri Slaby brd->max_baud = 921600;
174357faa7d6SJiri Slaby break;
174457faa7d6SJiri Slaby }
174557faa7d6SJiri Slaby }
174657faa7d6SJiri Slaby
174757faa7d6SJiri Slaby if (is_mu860) {
174857faa7d6SJiri Slaby /* set to RS232 mode by default */
174957faa7d6SJiri Slaby outb(0, brd->vector + 4);
175057faa7d6SJiri Slaby outb(0, brd->vector + 0x0c);
175157faa7d6SJiri Slaby }
1752a6afd9f3SGreg Kroah-Hartman
1753c24c31ffSJiri Slaby for (i = 0; i < brd->nports; i++) {
1754a6afd9f3SGreg Kroah-Hartman info = &brd->ports[i];
175557faa7d6SJiri Slaby if (is_mu860) {
175657faa7d6SJiri Slaby if (i < 4)
175757faa7d6SJiri Slaby info->opmode_ioaddr = brd->vector + 4;
175857faa7d6SJiri Slaby else
175957faa7d6SJiri Slaby info->opmode_ioaddr = brd->vector + 0x0c;
176057faa7d6SJiri Slaby }
1761a6afd9f3SGreg Kroah-Hartman tty_port_init(&info->port);
1762a6afd9f3SGreg Kroah-Hartman info->port.ops = &mxser_port_ops;
1763a6afd9f3SGreg Kroah-Hartman info->board = brd;
1764a6afd9f3SGreg Kroah-Hartman
1765a6afd9f3SGreg Kroah-Hartman /* Enhance mode enabled here */
1766292955a7SJiri Slaby if (brd->must_hwid != MOXA_OTHER_UART)
1767edb7d27cSJiri Slaby mxser_must_set_enhance_mode(info->ioaddr, true);
1768a6afd9f3SGreg Kroah-Hartman
176958a2ddb3SJiri Slaby info->type = PORT_16550A;
1770a6afd9f3SGreg Kroah-Hartman
1771c3db20c3SJiri Slaby mxser_process_txrx_fifo(info);
1772a6afd9f3SGreg Kroah-Hartman
1773a6afd9f3SGreg Kroah-Hartman spin_lock_init(&info->slock);
1774a6afd9f3SGreg Kroah-Hartman
1775a6afd9f3SGreg Kroah-Hartman /* before set INT ISR, disable all int */
1776a6afd9f3SGreg Kroah-Hartman outb(inb(info->ioaddr + UART_IER) & 0xf0,
1777a6afd9f3SGreg Kroah-Hartman info->ioaddr + UART_IER);
1778a6afd9f3SGreg Kroah-Hartman }
1779a6afd9f3SGreg Kroah-Hartman }
1780a6afd9f3SGreg Kroah-Hartman
mxser_probe(struct pci_dev * pdev,const struct pci_device_id * ent)17819671f099SBill Pemberton static int mxser_probe(struct pci_dev *pdev,
1782a6afd9f3SGreg Kroah-Hartman const struct pci_device_id *ent)
1783a6afd9f3SGreg Kroah-Hartman {
1784a6afd9f3SGreg Kroah-Hartman struct mxser_board *brd;
178513d4aba8SJiri Slaby unsigned int i, base;
1786a6afd9f3SGreg Kroah-Hartman unsigned long ioaddress;
1787c24c31ffSJiri Slaby unsigned short nports = MXSER_NPORTS(ent->driver_data);
17889e17df37SAlexey Khoroshilov struct device *tty_dev;
1789a6afd9f3SGreg Kroah-Hartman int retval = -EINVAL;
1790a6afd9f3SGreg Kroah-Hartman
1791f8b6b327SJiri Slaby i = find_first_zero_bit(mxser_boards, MXSER_BOARDS);
1792a6afd9f3SGreg Kroah-Hartman if (i >= MXSER_BOARDS) {
1793a6afd9f3SGreg Kroah-Hartman dev_err(&pdev->dev, "too many boards found (maximum %d), board "
1794a6afd9f3SGreg Kroah-Hartman "not configured\n", MXSER_BOARDS);
1795a6afd9f3SGreg Kroah-Hartman goto err;
1796a6afd9f3SGreg Kroah-Hartman }
1797a6afd9f3SGreg Kroah-Hartman
1798ad1c92ffSJiri Slaby brd = devm_kzalloc(&pdev->dev, struct_size(brd, ports, nports),
1799ad1c92ffSJiri Slaby GFP_KERNEL);
1800f8b6b327SJiri Slaby if (!brd)
1801f8b6b327SJiri Slaby goto err;
1802f8b6b327SJiri Slaby
180313d4aba8SJiri Slaby brd->idx = i;
1804f8b6b327SJiri Slaby __set_bit(brd->idx, mxser_boards);
180513d4aba8SJiri Slaby base = i * MXSER_PORTS_PER_BOARD;
1806a6afd9f3SGreg Kroah-Hartman
1807dcb04e21SJiri Slaby retval = pcim_enable_device(pdev);
1808a6afd9f3SGreg Kroah-Hartman if (retval) {
1809a6afd9f3SGreg Kroah-Hartman dev_err(&pdev->dev, "PCI enable failed\n");
1810f8b6b327SJiri Slaby goto err_zero;
1811a6afd9f3SGreg Kroah-Hartman }
1812a6afd9f3SGreg Kroah-Hartman
1813a6afd9f3SGreg Kroah-Hartman /* io address */
1814a6afd9f3SGreg Kroah-Hartman ioaddress = pci_resource_start(pdev, 2);
1815a6afd9f3SGreg Kroah-Hartman retval = pci_request_region(pdev, 2, "mxser(IO)");
1816a6afd9f3SGreg Kroah-Hartman if (retval)
1817f8b6b327SJiri Slaby goto err_zero;
1818a6afd9f3SGreg Kroah-Hartman
1819c24c31ffSJiri Slaby brd->nports = nports;
1820c24c31ffSJiri Slaby for (i = 0; i < nports; i++)
1821a6afd9f3SGreg Kroah-Hartman brd->ports[i].ioaddr = ioaddress + 8 * i;
1822a6afd9f3SGreg Kroah-Hartman
1823a6afd9f3SGreg Kroah-Hartman /* vector */
1824a6afd9f3SGreg Kroah-Hartman ioaddress = pci_resource_start(pdev, 3);
1825a6afd9f3SGreg Kroah-Hartman retval = pci_request_region(pdev, 3, "mxser(vector)");
1826a6afd9f3SGreg Kroah-Hartman if (retval)
1827a6afd9f3SGreg Kroah-Hartman goto err_zero;
1828a6afd9f3SGreg Kroah-Hartman brd->vector = ioaddress;
1829a6afd9f3SGreg Kroah-Hartman
1830a6afd9f3SGreg Kroah-Hartman /* irq */
1831a6afd9f3SGreg Kroah-Hartman brd->irq = pdev->irq;
1832a6afd9f3SGreg Kroah-Hartman
1833c24c31ffSJiri Slaby mxser_initbrd(brd, ent->driver_data & MXSER_HIGHBAUD);
18347f0e79dcSJiri Slaby
18357f0e79dcSJiri Slaby retval = devm_request_irq(&pdev->dev, brd->irq, mxser_interrupt,
18367f0e79dcSJiri Slaby IRQF_SHARED, "mxser", brd);
18377f0e79dcSJiri Slaby if (retval) {
18387f0e79dcSJiri Slaby dev_err(&pdev->dev, "request irq failed");
18397f0e79dcSJiri Slaby goto err_relbrd;
18407f0e79dcSJiri Slaby }
1841a6afd9f3SGreg Kroah-Hartman
1842c24c31ffSJiri Slaby for (i = 0; i < nports; i++) {
18439e17df37SAlexey Khoroshilov tty_dev = tty_port_register_device(&brd->ports[i].port,
184413d4aba8SJiri Slaby mxvar_sdriver, base + i, &pdev->dev);
18459e17df37SAlexey Khoroshilov if (IS_ERR(tty_dev)) {
18469e17df37SAlexey Khoroshilov retval = PTR_ERR(tty_dev);
18471b581f17SAlexey Khoroshilov for (; i > 0; i--)
18489e17df37SAlexey Khoroshilov tty_unregister_device(mxvar_sdriver,
184913d4aba8SJiri Slaby base + i - 1);
18509e17df37SAlexey Khoroshilov goto err_relbrd;
18519e17df37SAlexey Khoroshilov }
18529e17df37SAlexey Khoroshilov }
1853a6afd9f3SGreg Kroah-Hartman
1854a6afd9f3SGreg Kroah-Hartman pci_set_drvdata(pdev, brd);
1855a6afd9f3SGreg Kroah-Hartman
1856a6afd9f3SGreg Kroah-Hartman return 0;
18579e17df37SAlexey Khoroshilov err_relbrd:
1858c24c31ffSJiri Slaby for (i = 0; i < nports; i++)
18599e17df37SAlexey Khoroshilov tty_port_destroy(&brd->ports[i].port);
1860a6afd9f3SGreg Kroah-Hartman err_zero:
1861f8b6b327SJiri Slaby __clear_bit(brd->idx, mxser_boards);
1862a6afd9f3SGreg Kroah-Hartman err:
1863a6afd9f3SGreg Kroah-Hartman return retval;
1864a6afd9f3SGreg Kroah-Hartman }
1865a6afd9f3SGreg Kroah-Hartman
mxser_remove(struct pci_dev * pdev)1866ae8d8a14SBill Pemberton static void mxser_remove(struct pci_dev *pdev)
1867a6afd9f3SGreg Kroah-Hartman {
1868a6afd9f3SGreg Kroah-Hartman struct mxser_board *brd = pci_get_drvdata(pdev);
186913d4aba8SJiri Slaby unsigned int i, base = brd->idx * MXSER_PORTS_PER_BOARD;
1870a6afd9f3SGreg Kroah-Hartman
1871c24c31ffSJiri Slaby for (i = 0; i < brd->nports; i++) {
187213d4aba8SJiri Slaby tty_unregister_device(mxvar_sdriver, base + i);
1873d450f085SJiri Slaby tty_port_destroy(&brd->ports[i].port);
1874d450f085SJiri Slaby }
1875d450f085SJiri Slaby
1876f8b6b327SJiri Slaby __clear_bit(brd->idx, mxser_boards);
1877a6afd9f3SGreg Kroah-Hartman }
1878a6afd9f3SGreg Kroah-Hartman
1879a6afd9f3SGreg Kroah-Hartman static struct pci_driver mxser_driver = {
1880a6afd9f3SGreg Kroah-Hartman .name = "mxser",
1881a6afd9f3SGreg Kroah-Hartman .id_table = mxser_pcibrds,
1882a6afd9f3SGreg Kroah-Hartman .probe = mxser_probe,
188391116cbaSBill Pemberton .remove = mxser_remove
1884a6afd9f3SGreg Kroah-Hartman };
1885a6afd9f3SGreg Kroah-Hartman
mxser_module_init(void)1886a6afd9f3SGreg Kroah-Hartman static int __init mxser_module_init(void)
1887a6afd9f3SGreg Kroah-Hartman {
1888a6afd9f3SGreg Kroah-Hartman int retval;
1889a6afd9f3SGreg Kroah-Hartman
189039b7b42bSJiri Slaby mxvar_sdriver = tty_alloc_driver(MXSER_PORTS, TTY_DRIVER_REAL_RAW |
189139b7b42bSJiri Slaby TTY_DRIVER_DYNAMIC_DEV);
189239b7b42bSJiri Slaby if (IS_ERR(mxvar_sdriver))
189339b7b42bSJiri Slaby return PTR_ERR(mxvar_sdriver);
1894a6afd9f3SGreg Kroah-Hartman
1895a6afd9f3SGreg Kroah-Hartman /* Initialize the tty_driver structure */
1896a6afd9f3SGreg Kroah-Hartman mxvar_sdriver->name = "ttyMI";
1897a6afd9f3SGreg Kroah-Hartman mxvar_sdriver->major = ttymajor;
1898a6afd9f3SGreg Kroah-Hartman mxvar_sdriver->minor_start = 0;
1899a6afd9f3SGreg Kroah-Hartman mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
1900a6afd9f3SGreg Kroah-Hartman mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
1901a6afd9f3SGreg Kroah-Hartman mxvar_sdriver->init_termios = tty_std_termios;
1902a6afd9f3SGreg Kroah-Hartman mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
1903a6afd9f3SGreg Kroah-Hartman tty_set_operations(mxvar_sdriver, &mxser_ops);
1904a6afd9f3SGreg Kroah-Hartman
1905a6afd9f3SGreg Kroah-Hartman retval = tty_register_driver(mxvar_sdriver);
1906a6afd9f3SGreg Kroah-Hartman if (retval) {
1907a6afd9f3SGreg Kroah-Hartman printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family "
1908a6afd9f3SGreg Kroah-Hartman "tty driver !\n");
1909a6afd9f3SGreg Kroah-Hartman goto err_put;
1910a6afd9f3SGreg Kroah-Hartman }
1911a6afd9f3SGreg Kroah-Hartman
1912a6afd9f3SGreg Kroah-Hartman retval = pci_register_driver(&mxser_driver);
1913a6afd9f3SGreg Kroah-Hartman if (retval) {
1914a6afd9f3SGreg Kroah-Hartman printk(KERN_ERR "mxser: can't register pci driver\n");
1915a6afd9f3SGreg Kroah-Hartman goto err_unr;
1916a6afd9f3SGreg Kroah-Hartman }
1917a6afd9f3SGreg Kroah-Hartman
1918a6afd9f3SGreg Kroah-Hartman return 0;
1919a6afd9f3SGreg Kroah-Hartman err_unr:
1920a6afd9f3SGreg Kroah-Hartman tty_unregister_driver(mxvar_sdriver);
1921a6afd9f3SGreg Kroah-Hartman err_put:
19229f90a4ddSJiri Slaby tty_driver_kref_put(mxvar_sdriver);
1923a6afd9f3SGreg Kroah-Hartman return retval;
1924a6afd9f3SGreg Kroah-Hartman }
1925a6afd9f3SGreg Kroah-Hartman
mxser_module_exit(void)1926a6afd9f3SGreg Kroah-Hartman static void __exit mxser_module_exit(void)
1927a6afd9f3SGreg Kroah-Hartman {
1928a6afd9f3SGreg Kroah-Hartman pci_unregister_driver(&mxser_driver);
1929a6afd9f3SGreg Kroah-Hartman tty_unregister_driver(mxvar_sdriver);
19309f90a4ddSJiri Slaby tty_driver_kref_put(mxvar_sdriver);
1931a6afd9f3SGreg Kroah-Hartman }
1932a6afd9f3SGreg Kroah-Hartman
1933a6afd9f3SGreg Kroah-Hartman module_init(mxser_module_init);
1934a6afd9f3SGreg Kroah-Hartman module_exit(mxser_module_exit);
1935