Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * mxser.c -- MOXA Smartio/Industio family multiport serial driver. |
| 4 | * |
Jiri Slaby | 80ff8a8 | 2008-02-07 00:16:51 -0800 | [diff] [blame] | 5 | * Copyright (C) 1999-2006 Moxa Technologies (support@moxa.com). |
| 6 | * Copyright (C) 2006-2008 Jiri Slaby <jirislaby@gmail.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 8 | * This code is loosely based on the 1.8 moxa driver which is based on |
| 9 | * Linux serial driver, written by Linus Torvalds, Theodore T'so and |
| 10 | * others. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox |
Alan Cox | 8eb04cf | 2008-11-11 14:48:44 +0000 | [diff] [blame] | 13 | * <alan@lxorguk.ukuu.org.uk>. The original 1.8 code is available on |
| 14 | * www.moxa.com. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * - Fixed x86_64 cleanness |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/errno.h> |
| 20 | #include <linux/signal.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/timer.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/tty.h> |
| 25 | #include <linux/tty_flip.h> |
| 26 | #include <linux/serial.h> |
| 27 | #include <linux/serial_reg.h> |
| 28 | #include <linux/major.h> |
| 29 | #include <linux/string.h> |
| 30 | #include <linux/fcntl.h> |
| 31 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/ioport.h> |
| 33 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/delay.h> |
| 35 | #include <linux/pci.h> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 36 | #include <linux/bitops.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Manuel Zerpies | 5a3c6b251 | 2011-06-16 14:07:22 +0200 | [diff] [blame] | 38 | #include <linux/ratelimit.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/io.h> |
| 41 | #include <asm/irq.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 42 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Jiri Slaby | 4463cc5 | 2021-06-18 08:14:10 +0200 | [diff] [blame] | 44 | /* |
| 45 | * Semi-public control interfaces |
| 46 | */ |
| 47 | |
| 48 | /* |
| 49 | * MOXA ioctls |
| 50 | */ |
| 51 | |
| 52 | #define MOXA 0x400 |
| 53 | #define MOXA_GETDATACOUNT (MOXA + 23) |
| 54 | #define MOXA_DIAGNOSE (MOXA + 50) |
| 55 | #define MOXA_CHKPORTENABLE (MOXA + 60) |
| 56 | #define MOXA_HighSpeedOn (MOXA + 61) |
| 57 | #define MOXA_GET_MAJOR (MOXA + 63) |
| 58 | #define MOXA_GETMSTATUS (MOXA + 65) |
| 59 | #define MOXA_SET_OP_MODE (MOXA + 66) |
| 60 | #define MOXA_GET_OP_MODE (MOXA + 67) |
| 61 | |
| 62 | #define RS232_MODE 0 |
| 63 | #define RS485_2WIRE_MODE 1 |
| 64 | #define RS422_MODE 2 |
| 65 | #define RS485_4WIRE_MODE 3 |
| 66 | #define OP_MODE_MASK 3 |
| 67 | |
| 68 | #define MOXA_SDS_RSTICOUNTER (MOXA + 69) |
| 69 | #define MOXA_ASPP_OQUEUE (MOXA + 70) |
| 70 | #define MOXA_ASPP_MON (MOXA + 73) |
| 71 | #define MOXA_ASPP_LSTATUS (MOXA + 74) |
| 72 | #define MOXA_ASPP_MON_EXT (MOXA + 75) |
| 73 | #define MOXA_SET_BAUD_METHOD (MOXA + 76) |
| 74 | |
| 75 | /* --------------------------------------------------- */ |
| 76 | |
| 77 | #define NPPI_NOTIFY_PARITY 0x01 |
| 78 | #define NPPI_NOTIFY_FRAMING 0x02 |
| 79 | #define NPPI_NOTIFY_HW_OVERRUN 0x04 |
| 80 | #define NPPI_NOTIFY_SW_OVERRUN 0x08 |
| 81 | #define NPPI_NOTIFY_BREAK 0x10 |
| 82 | |
| 83 | #define NPPI_NOTIFY_CTSHOLD 0x01 /* Tx hold by CTS low */ |
| 84 | #define NPPI_NOTIFY_DSRHOLD 0x02 /* Tx hold by DSR low */ |
| 85 | #define NPPI_NOTIFY_XOFFHOLD 0x08 /* Tx hold by Xoff received */ |
| 86 | #define NPPI_NOTIFY_XOFFXENT 0x10 /* Xoff Sent */ |
| 87 | |
| 88 | /* |
| 89 | * Follow just what Moxa Must chip defines. |
| 90 | * |
| 91 | * When LCR register (offset 0x03) writes the following value, the Must chip |
| 92 | * will enter enchance mode. And write value on EFR (offset 0x02) bit 6,7 to |
| 93 | * change bank. |
| 94 | */ |
| 95 | #define MOXA_MUST_ENTER_ENCHANCE 0xBF |
| 96 | |
| 97 | /* when enhance mode enabled, access on general bank register */ |
| 98 | #define MOXA_MUST_GDL_REGISTER 0x07 |
| 99 | #define MOXA_MUST_GDL_MASK 0x7F |
| 100 | #define MOXA_MUST_GDL_HAS_BAD_DATA 0x80 |
| 101 | |
| 102 | #define MOXA_MUST_LSR_RERR 0x80 /* error in receive FIFO */ |
| 103 | /* enchance register bank select and enchance mode setting register */ |
| 104 | /* when LCR register equals to 0xBF */ |
| 105 | #define MOXA_MUST_EFR_REGISTER 0x02 |
| 106 | #define MOXA_MUST_EFR_EFRB_ENABLE 0x10 /* enchance mode enable */ |
| 107 | /* enchance register bank set 0, 1, 2 */ |
| 108 | #define MOXA_MUST_EFR_BANK0 0x00 |
| 109 | #define MOXA_MUST_EFR_BANK1 0x40 |
| 110 | #define MOXA_MUST_EFR_BANK2 0x80 |
| 111 | #define MOXA_MUST_EFR_BANK3 0xC0 |
| 112 | #define MOXA_MUST_EFR_BANK_MASK 0xC0 |
| 113 | |
| 114 | /* set XON1 value register, when LCR=0xBF and change to bank0 */ |
| 115 | #define MOXA_MUST_XON1_REGISTER 0x04 |
| 116 | |
| 117 | /* set XON2 value register, when LCR=0xBF and change to bank0 */ |
| 118 | #define MOXA_MUST_XON2_REGISTER 0x05 |
| 119 | |
| 120 | /* set XOFF1 value register, when LCR=0xBF and change to bank0 */ |
| 121 | #define MOXA_MUST_XOFF1_REGISTER 0x06 |
| 122 | |
| 123 | /* set XOFF2 value register, when LCR=0xBF and change to bank0 */ |
| 124 | #define MOXA_MUST_XOFF2_REGISTER 0x07 |
| 125 | |
| 126 | #define MOXA_MUST_RBRTL_REGISTER 0x04 |
| 127 | #define MOXA_MUST_RBRTH_REGISTER 0x05 |
| 128 | #define MOXA_MUST_RBRTI_REGISTER 0x06 |
| 129 | #define MOXA_MUST_THRTL_REGISTER 0x07 |
| 130 | #define MOXA_MUST_ENUM_REGISTER 0x04 |
| 131 | #define MOXA_MUST_HWID_REGISTER 0x05 |
| 132 | #define MOXA_MUST_ECR_REGISTER 0x06 |
| 133 | #define MOXA_MUST_CSR_REGISTER 0x07 |
| 134 | |
| 135 | #define MOXA_MUST_FCR_GDA_MODE_ENABLE 0x20 /* good data mode enable */ |
| 136 | #define MOXA_MUST_FCR_GDA_ONLY_ENABLE 0x10 /* only good data put into RxFIFO */ |
| 137 | |
| 138 | #define MOXA_MUST_IER_ECTSI 0x80 /* enable CTS interrupt */ |
| 139 | #define MOXA_MUST_IER_ERTSI 0x40 /* enable RTS interrupt */ |
| 140 | #define MOXA_MUST_IER_XINT 0x20 /* enable Xon/Xoff interrupt */ |
| 141 | #define MOXA_MUST_IER_EGDAI 0x10 /* enable GDA interrupt */ |
| 142 | |
| 143 | #define MOXA_MUST_RECV_ISR (UART_IER_RDI | MOXA_MUST_IER_EGDAI) |
| 144 | |
| 145 | /* GDA interrupt pending */ |
| 146 | #define MOXA_MUST_IIR_GDA 0x1C |
| 147 | #define MOXA_MUST_IIR_RDA 0x04 |
| 148 | #define MOXA_MUST_IIR_RTO 0x0C |
| 149 | #define MOXA_MUST_IIR_LSR 0x06 |
| 150 | |
| 151 | /* received Xon/Xoff or specical interrupt pending */ |
| 152 | #define MOXA_MUST_IIR_XSC 0x10 |
| 153 | |
| 154 | /* RTS/CTS change state interrupt pending */ |
| 155 | #define MOXA_MUST_IIR_RTSCTS 0x20 |
| 156 | #define MOXA_MUST_IIR_MASK 0x3E |
| 157 | |
| 158 | #define MOXA_MUST_MCR_XON_FLAG 0x40 |
| 159 | #define MOXA_MUST_MCR_XON_ANY 0x80 |
| 160 | #define MOXA_MUST_MCR_TX_XON 0x08 |
| 161 | |
| 162 | #define MOXA_MUST_EFR_SF_MASK 0x0F /* software flow control on chip mask value */ |
| 163 | #define MOXA_MUST_EFR_SF_TX1 0x08 /* send Xon1/Xoff1 */ |
| 164 | #define MOXA_MUST_EFR_SF_TX2 0x04 /* send Xon2/Xoff2 */ |
| 165 | #define MOXA_MUST_EFR_SF_TX12 0x0C /* send Xon1,Xon2/Xoff1,Xoff2 */ |
| 166 | #define MOXA_MUST_EFR_SF_TX_NO 0x00 /* don't send Xon/Xoff */ |
| 167 | #define MOXA_MUST_EFR_SF_TX_MASK 0x0C /* Tx software flow control mask */ |
| 168 | #define MOXA_MUST_EFR_SF_RX_NO 0x00 /* don't receive Xon/Xoff */ |
| 169 | #define MOXA_MUST_EFR_SF_RX1 0x02 /* receive Xon1/Xoff1 */ |
| 170 | #define MOXA_MUST_EFR_SF_RX2 0x01 /* receive Xon2/Xoff2 */ |
| 171 | #define MOXA_MUST_EFR_SF_RX12 0x03 /* receive Xon1,Xon2/Xoff1,Xoff2 */ |
| 172 | #define MOXA_MUST_EFR_SF_RX_MASK 0x03 /* Rx software flow control mask */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | #define MXSERMAJOR 174 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | #define MXSER_BOARDS 4 /* Max. boards */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 178 | #define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD) |
| 179 | #define MXSER_ISR_PASS_LIMIT 100 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | #define WAKEUP_CHARS 256 |
| 182 | |
| 183 | #define UART_MCR_AFE 0x20 |
| 184 | #define UART_LSR_SPECIAL 0x1E |
| 185 | |
Jiri Slaby | e129def | 2008-07-22 11:20:34 +0100 | [diff] [blame] | 186 | #define PCI_DEVICE_ID_POS104UL 0x1044 |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 187 | #define PCI_DEVICE_ID_CB108 0x1080 |
Jiri Slaby | e129def | 2008-07-22 11:20:34 +0100 | [diff] [blame] | 188 | #define PCI_DEVICE_ID_CP102UF 0x1023 |
Jiri Slaby | 502f295 | 2009-09-10 12:20:07 +0200 | [diff] [blame] | 189 | #define PCI_DEVICE_ID_CP112UL 0x1120 |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 190 | #define PCI_DEVICE_ID_CB114 0x1142 |
Jiri Slaby | 80ff8a8 | 2008-02-07 00:16:51 -0800 | [diff] [blame] | 191 | #define PCI_DEVICE_ID_CP114UL 0x1143 |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 192 | #define PCI_DEVICE_ID_CB134I 0x1341 |
| 193 | #define PCI_DEVICE_ID_CP138U 0x1380 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 195 | #define MXSER_HIGHBAUD 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Jiri Slaby | e455836 | 2021-06-18 08:14:14 +0200 | [diff] [blame] | 197 | enum mxser_must_hwid { |
| 198 | MOXA_OTHER_UART = 0x00, |
| 199 | MOXA_MUST_MU150_HWID = 0x01, |
| 200 | MOXA_MUST_MU860_HWID = 0x02, |
| 201 | }; |
| 202 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 203 | static const struct { |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 204 | u8 type; |
| 205 | u8 fifo_size; |
| 206 | u8 rx_high_water; |
| 207 | u8 rx_low_water; |
| 208 | speed_t max_baud; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 209 | } Gpci_uart_info[] = { |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 210 | { MOXA_OTHER_UART, 16, 14, 1, 921600 }, |
| 211 | { MOXA_MUST_MU150_HWID, 64, 48, 16, 230400 }, |
| 212 | { MOXA_MUST_MU860_HWID, 128, 96, 32, 921600 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | }; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 214 | #define UART_INFO_NUM ARRAY_SIZE(Gpci_uart_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 216 | struct mxser_cardinfo { |
| 217 | char *name; |
| 218 | unsigned int nports; |
| 219 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 222 | static const struct mxser_cardinfo mxser_cards[] = { |
Jiri Slaby | 1525490 | 2021-06-18 08:14:08 +0200 | [diff] [blame] | 223 | /* 0*/ { "C168H/PCI series", 8, }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 224 | { "C104H/PCI series", 4, }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 225 | { "CP-132 series", 2, }, |
| 226 | { "CP-114 series", 4, }, |
Jiri Slaby | 1525490 | 2021-06-18 08:14:08 +0200 | [diff] [blame] | 227 | { "CT-114 series", 4, }, |
| 228 | /* 5*/ { "CP-102 series", 2, MXSER_HIGHBAUD }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 229 | { "CP-104U series", 4, }, |
| 230 | { "CP-168U series", 8, }, |
| 231 | { "CP-132U series", 2, }, |
Jiri Slaby | 1525490 | 2021-06-18 08:14:08 +0200 | [diff] [blame] | 232 | { "CP-134U series", 4, }, |
| 233 | /*10*/ { "CP-104JU series", 4, }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 234 | { "Moxa UC7000 Serial", 8, }, /* RC7000 */ |
| 235 | { "CP-118U series", 8, }, |
| 236 | { "CP-102UL series", 2, }, |
Jiri Slaby | 1525490 | 2021-06-18 08:14:08 +0200 | [diff] [blame] | 237 | { "CP-102U series", 2, }, |
| 238 | /*15*/ { "CP-118EL series", 8, }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 239 | { "CP-168EL series", 8, }, |
| 240 | { "CP-104EL series", 4, }, |
| 241 | { "CB-108 series", 8, }, |
Jiri Slaby | 1525490 | 2021-06-18 08:14:08 +0200 | [diff] [blame] | 242 | { "CB-114 series", 4, }, |
| 243 | /*20*/ { "CB-134I series", 4, }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 244 | { "CP-138U series", 8, }, |
Jiri Slaby | 80ff8a8 | 2008-02-07 00:16:51 -0800 | [diff] [blame] | 245 | { "POS-104UL series", 4, }, |
Jiri Slaby | e129def | 2008-07-22 11:20:34 +0100 | [diff] [blame] | 246 | { "CP-114UL series", 4, }, |
Jiri Slaby | 1525490 | 2021-06-18 08:14:08 +0200 | [diff] [blame] | 247 | { "CP-102UF series", 2, }, |
| 248 | /*25*/ { "CP-112UL series", 2, }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | /* driver_data correspond to the lines in the structure above |
| 252 | see also ISA probe function before you change something */ |
Arvind Yadav | 3385ecf | 2017-07-23 15:31:01 +0530 | [diff] [blame] | 253 | static const struct pci_device_id mxser_pcibrds[] = { |
Jiri Slaby | 1525490 | 2021-06-18 08:14:08 +0200 | [diff] [blame] | 254 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168), .driver_data = 0 }, |
| 255 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104), .driver_data = 1 }, |
| 256 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132), .driver_data = 2 }, |
| 257 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114), .driver_data = 3 }, |
| 258 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CT114), .driver_data = 4 }, |
| 259 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102), .driver_data = 5 }, |
| 260 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104U), .driver_data = 6 }, |
| 261 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168U), .driver_data = 7 }, |
| 262 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132U), .driver_data = 8 }, |
| 263 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134U), .driver_data = 9 }, |
| 264 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104JU),.driver_data = 10 }, |
| 265 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_RC7000), .driver_data = 11 }, |
| 266 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118U), .driver_data = 12 }, |
| 267 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102UL),.driver_data = 13 }, |
| 268 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102U), .driver_data = 14 }, |
| 269 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL),.driver_data = 15 }, |
| 270 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL),.driver_data = 16 }, |
| 271 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL),.driver_data = 17 }, |
| 272 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB108), .driver_data = 18 }, |
| 273 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB114), .driver_data = 19 }, |
| 274 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB134I), .driver_data = 20 }, |
| 275 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U), .driver_data = 21 }, |
| 276 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_POS104UL), .driver_data = 22 }, |
| 277 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL), .driver_data = 23 }, |
| 278 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP102UF), .driver_data = 24 }, |
| 279 | { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP112UL), .driver_data = 25 }, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 280 | { } |
| 281 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | MODULE_DEVICE_TABLE(pci, mxser_pcibrds); |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | static int ttymajor = MXSERMAJOR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | /* Variables for insmod */ |
| 287 | |
| 288 | MODULE_AUTHOR("Casper Yang"); |
| 289 | MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 290 | module_param(ttymajor, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | MODULE_LICENSE("GPL"); |
| 292 | |
| 293 | struct mxser_log { |
| 294 | int tick; |
| 295 | unsigned long rxcnt[MXSER_PORTS]; |
| 296 | unsigned long txcnt[MXSER_PORTS]; |
| 297 | }; |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | struct mxser_mon { |
| 300 | unsigned long rxcnt; |
| 301 | unsigned long txcnt; |
| 302 | unsigned long up_rxcnt; |
| 303 | unsigned long up_txcnt; |
| 304 | int modem_status; |
| 305 | unsigned char hold_reason; |
| 306 | }; |
| 307 | |
| 308 | struct mxser_mon_ext { |
| 309 | unsigned long rx_cnt[32]; |
| 310 | unsigned long tx_cnt[32]; |
| 311 | unsigned long up_rxcnt[32]; |
| 312 | unsigned long up_txcnt[32]; |
| 313 | int modem_status[32]; |
| 314 | |
| 315 | long baudrate[32]; |
| 316 | int databits[32]; |
| 317 | int stopbits[32]; |
| 318 | int parity[32]; |
| 319 | int flowctrl[32]; |
| 320 | int fifo[32]; |
| 321 | int iftype[32]; |
| 322 | }; |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 323 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 324 | struct mxser_board; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 326 | struct mxser_port { |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 327 | struct tty_port port; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 328 | struct mxser_board *board; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 329 | |
| 330 | unsigned long ioaddr; |
| 331 | unsigned long opmode_ioaddr; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 332 | |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 333 | u8 rx_high_water; |
| 334 | u8 rx_low_water; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | int baud_base; /* max. speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | int type; /* UART type */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 337 | |
| 338 | int x_char; /* xon/xoff character */ |
| 339 | int IER; /* Interrupt Enable Register */ |
| 340 | int MCR; /* Modem control register */ |
| 341 | |
| 342 | unsigned char stop_rx; |
| 343 | unsigned char ldisc_stop_rx; |
| 344 | |
| 345 | int custom_divisor; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 346 | unsigned char err_shadow; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 347 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 348 | struct async_icount icount; /* kernel counters for 4 input interrupts */ |
Jiri Slaby | 104583b | 2017-09-12 12:39:54 +0200 | [diff] [blame] | 349 | unsigned int timeout; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | int read_status_mask; |
| 352 | int ignore_status_mask; |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 353 | u8 xmit_fifo_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | int xmit_head; |
| 355 | int xmit_tail; |
| 356 | int xmit_cnt; |
Peter Hurley | cd7b4b3 | 2016-01-10 14:51:38 -0800 | [diff] [blame] | 357 | int closing; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 358 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 359 | struct ktermios normal_termios; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | struct mxser_mon mon_data; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | spinlock_t slock; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | struct mxser_board { |
| 367 | unsigned int idx; |
| 368 | int irq; |
| 369 | const struct mxser_cardinfo *info; |
| 370 | unsigned long vector; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 371 | |
Jiri Slaby | e455836 | 2021-06-18 08:14:14 +0200 | [diff] [blame] | 372 | enum mxser_must_hwid must_hwid; |
Jiri Slaby | 928f946 | 2021-06-18 08:14:16 +0200 | [diff] [blame] | 373 | speed_t max_baud; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 374 | |
| 375 | struct mxser_port ports[MXSER_PORTS_PER_BOARD]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | }; |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | struct mxser_mstatus { |
| 379 | tcflag_t cflag; |
| 380 | int cts; |
| 381 | int dsr; |
| 382 | int ri; |
| 383 | int dcd; |
| 384 | }; |
| 385 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 386 | static struct mxser_board mxser_boards[MXSER_BOARDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | static struct tty_driver *mxvar_sdriver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | static struct mxser_log mxvar_log; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | static int mxser_set_baud_method[MXSER_PORTS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 391 | static void mxser_enable_must_enchance_mode(unsigned long baseio) |
| 392 | { |
| 393 | u8 oldlcr; |
| 394 | u8 efr; |
| 395 | |
| 396 | oldlcr = inb(baseio + UART_LCR); |
| 397 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 398 | |
| 399 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 400 | efr |= MOXA_MUST_EFR_EFRB_ENABLE; |
| 401 | |
| 402 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 403 | outb(oldlcr, baseio + UART_LCR); |
| 404 | } |
| 405 | |
| 406 | static void mxser_disable_must_enchance_mode(unsigned long baseio) |
| 407 | { |
| 408 | u8 oldlcr; |
| 409 | u8 efr; |
| 410 | |
| 411 | oldlcr = inb(baseio + UART_LCR); |
| 412 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 413 | |
| 414 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 415 | efr &= ~MOXA_MUST_EFR_EFRB_ENABLE; |
| 416 | |
| 417 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 418 | outb(oldlcr, baseio + UART_LCR); |
| 419 | } |
| 420 | |
| 421 | static void mxser_set_must_xon1_value(unsigned long baseio, u8 value) |
| 422 | { |
| 423 | u8 oldlcr; |
| 424 | u8 efr; |
| 425 | |
| 426 | oldlcr = inb(baseio + UART_LCR); |
| 427 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 428 | |
| 429 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 430 | efr &= ~MOXA_MUST_EFR_BANK_MASK; |
| 431 | efr |= MOXA_MUST_EFR_BANK0; |
| 432 | |
| 433 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 434 | outb(value, baseio + MOXA_MUST_XON1_REGISTER); |
| 435 | outb(oldlcr, baseio + UART_LCR); |
| 436 | } |
| 437 | |
| 438 | static void mxser_set_must_xoff1_value(unsigned long baseio, u8 value) |
| 439 | { |
| 440 | u8 oldlcr; |
| 441 | u8 efr; |
| 442 | |
| 443 | oldlcr = inb(baseio + UART_LCR); |
| 444 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 445 | |
| 446 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 447 | efr &= ~MOXA_MUST_EFR_BANK_MASK; |
| 448 | efr |= MOXA_MUST_EFR_BANK0; |
| 449 | |
| 450 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 451 | outb(value, baseio + MOXA_MUST_XOFF1_REGISTER); |
| 452 | outb(oldlcr, baseio + UART_LCR); |
| 453 | } |
| 454 | |
| 455 | static void mxser_set_must_fifo_value(struct mxser_port *info) |
| 456 | { |
| 457 | u8 oldlcr; |
| 458 | u8 efr; |
| 459 | |
| 460 | oldlcr = inb(info->ioaddr + UART_LCR); |
| 461 | outb(MOXA_MUST_ENTER_ENCHANCE, info->ioaddr + UART_LCR); |
| 462 | |
| 463 | efr = inb(info->ioaddr + MOXA_MUST_EFR_REGISTER); |
| 464 | efr &= ~MOXA_MUST_EFR_BANK_MASK; |
| 465 | efr |= MOXA_MUST_EFR_BANK1; |
| 466 | |
| 467 | outb(efr, info->ioaddr + MOXA_MUST_EFR_REGISTER); |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 468 | outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTH_REGISTER); |
| 469 | outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTI_REGISTER); |
| 470 | outb(info->rx_low_water, info->ioaddr + MOXA_MUST_RBRTL_REGISTER); |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 471 | outb(oldlcr, info->ioaddr + UART_LCR); |
| 472 | } |
| 473 | |
| 474 | static void mxser_set_must_enum_value(unsigned long baseio, u8 value) |
| 475 | { |
| 476 | u8 oldlcr; |
| 477 | u8 efr; |
| 478 | |
| 479 | oldlcr = inb(baseio + UART_LCR); |
| 480 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 481 | |
| 482 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 483 | efr &= ~MOXA_MUST_EFR_BANK_MASK; |
| 484 | efr |= MOXA_MUST_EFR_BANK2; |
| 485 | |
| 486 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 487 | outb(value, baseio + MOXA_MUST_ENUM_REGISTER); |
| 488 | outb(oldlcr, baseio + UART_LCR); |
| 489 | } |
| 490 | |
| 491 | static void mxser_get_must_hardware_id(unsigned long baseio, u8 *pId) |
| 492 | { |
| 493 | u8 oldlcr; |
| 494 | u8 efr; |
| 495 | |
| 496 | oldlcr = inb(baseio + UART_LCR); |
| 497 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 498 | |
| 499 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 500 | efr &= ~MOXA_MUST_EFR_BANK_MASK; |
| 501 | efr |= MOXA_MUST_EFR_BANK2; |
| 502 | |
| 503 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 504 | *pId = inb(baseio + MOXA_MUST_HWID_REGISTER); |
| 505 | outb(oldlcr, baseio + UART_LCR); |
| 506 | } |
| 507 | |
| 508 | static void SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(unsigned long baseio) |
| 509 | { |
| 510 | u8 oldlcr; |
| 511 | u8 efr; |
| 512 | |
| 513 | oldlcr = inb(baseio + UART_LCR); |
| 514 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 515 | |
| 516 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 517 | efr &= ~MOXA_MUST_EFR_SF_MASK; |
| 518 | |
| 519 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 520 | outb(oldlcr, baseio + UART_LCR); |
| 521 | } |
| 522 | |
| 523 | static void mxser_enable_must_tx_software_flow_control(unsigned long baseio) |
| 524 | { |
| 525 | u8 oldlcr; |
| 526 | u8 efr; |
| 527 | |
| 528 | oldlcr = inb(baseio + UART_LCR); |
| 529 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 530 | |
| 531 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 532 | efr &= ~MOXA_MUST_EFR_SF_TX_MASK; |
| 533 | efr |= MOXA_MUST_EFR_SF_TX1; |
| 534 | |
| 535 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 536 | outb(oldlcr, baseio + UART_LCR); |
| 537 | } |
| 538 | |
| 539 | static void mxser_disable_must_tx_software_flow_control(unsigned long baseio) |
| 540 | { |
| 541 | u8 oldlcr; |
| 542 | u8 efr; |
| 543 | |
| 544 | oldlcr = inb(baseio + UART_LCR); |
| 545 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 546 | |
| 547 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 548 | efr &= ~MOXA_MUST_EFR_SF_TX_MASK; |
| 549 | |
| 550 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 551 | outb(oldlcr, baseio + UART_LCR); |
| 552 | } |
| 553 | |
| 554 | static void mxser_enable_must_rx_software_flow_control(unsigned long baseio) |
| 555 | { |
| 556 | u8 oldlcr; |
| 557 | u8 efr; |
| 558 | |
| 559 | oldlcr = inb(baseio + UART_LCR); |
| 560 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 561 | |
| 562 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 563 | efr &= ~MOXA_MUST_EFR_SF_RX_MASK; |
| 564 | efr |= MOXA_MUST_EFR_SF_RX1; |
| 565 | |
| 566 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 567 | outb(oldlcr, baseio + UART_LCR); |
| 568 | } |
| 569 | |
| 570 | static void mxser_disable_must_rx_software_flow_control(unsigned long baseio) |
| 571 | { |
| 572 | u8 oldlcr; |
| 573 | u8 efr; |
| 574 | |
| 575 | oldlcr = inb(baseio + UART_LCR); |
| 576 | outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR); |
| 577 | |
| 578 | efr = inb(baseio + MOXA_MUST_EFR_REGISTER); |
| 579 | efr &= ~MOXA_MUST_EFR_SF_RX_MASK; |
| 580 | |
| 581 | outb(efr, baseio + MOXA_MUST_EFR_REGISTER); |
| 582 | outb(oldlcr, baseio + UART_LCR); |
| 583 | } |
| 584 | |
Jiri Slaby | e455836 | 2021-06-18 08:14:14 +0200 | [diff] [blame] | 585 | static enum mxser_must_hwid mxser_must_get_hwid(unsigned long io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | { |
| 587 | u8 oldmcr, hwid; |
| 588 | int i; |
| 589 | |
| 590 | outb(0, io + UART_LCR); |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 591 | mxser_disable_must_enchance_mode(io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | oldmcr = inb(io + UART_MCR); |
| 593 | outb(0, io + UART_MCR); |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 594 | mxser_set_must_xon1_value(io, 0x11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | if ((hwid = inb(io + UART_MCR)) != 0) { |
| 596 | outb(oldmcr, io + UART_MCR); |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 597 | return MOXA_OTHER_UART; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 600 | mxser_get_must_hardware_id(io, &hwid); |
Jiri Slaby | e455836 | 2021-06-18 08:14:14 +0200 | [diff] [blame] | 601 | for (i = 1; i < UART_INFO_NUM; i++) /* 0 = OTHER_UART */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 602 | if (hwid == Gpci_uart_info[i].type) |
Jiri Slaby | e455836 | 2021-06-18 08:14:14 +0200 | [diff] [blame] | 603 | return hwid; |
| 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | return MOXA_OTHER_UART; |
| 606 | } |
| 607 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 608 | static void process_txrx_fifo(struct mxser_port *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { |
| 610 | int i; |
| 611 | |
| 612 | if ((info->type == PORT_16450) || (info->type == PORT_8250)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | info->rx_high_water = 1; |
| 614 | info->rx_low_water = 1; |
| 615 | info->xmit_fifo_size = 1; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 616 | } else |
| 617 | for (i = 0; i < UART_INFO_NUM; i++) |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 618 | if (info->board->must_hwid == Gpci_uart_info[i].type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | info->rx_low_water = Gpci_uart_info[i].rx_low_water; |
| 620 | info->rx_high_water = Gpci_uart_info[i].rx_high_water; |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 621 | info->xmit_fifo_size = Gpci_uart_info[i].fifo_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | break; |
| 623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 626 | static unsigned char mxser_get_msr(int baseaddr, int mode, int port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 628 | static unsigned char mxser_msr[MXSER_PORTS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | unsigned char status = 0; |
| 630 | |
| 631 | status = inb(baseaddr + UART_MSR); |
| 632 | |
| 633 | mxser_msr[port] &= 0x0F; |
| 634 | mxser_msr[port] |= status; |
| 635 | status = mxser_msr[port]; |
| 636 | if (mode) |
| 637 | mxser_msr[port] = 0; |
| 638 | |
| 639 | return status; |
| 640 | } |
| 641 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 642 | static int mxser_carrier_raised(struct tty_port *port) |
| 643 | { |
| 644 | struct mxser_port *mp = container_of(port, struct mxser_port, port); |
| 645 | return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; |
| 646 | } |
| 647 | |
Alan Cox | fcc8ac1 | 2009-06-11 12:24:17 +0100 | [diff] [blame] | 648 | static void mxser_dtr_rts(struct tty_port *port, int on) |
Alan Cox | 5d951fb | 2009-01-02 13:45:19 +0000 | [diff] [blame] | 649 | { |
| 650 | struct mxser_port *mp = container_of(port, struct mxser_port, port); |
| 651 | unsigned long flags; |
| 652 | |
| 653 | spin_lock_irqsave(&mp->slock, flags); |
Alan Cox | fcc8ac1 | 2009-06-11 12:24:17 +0100 | [diff] [blame] | 654 | if (on) |
| 655 | outb(inb(mp->ioaddr + UART_MCR) | |
| 656 | UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); |
| 657 | else |
| 658 | outb(inb(mp->ioaddr + UART_MCR)&~(UART_MCR_DTR | UART_MCR_RTS), |
| 659 | mp->ioaddr + UART_MCR); |
Alan Cox | 5d951fb | 2009-01-02 13:45:19 +0000 | [diff] [blame] | 660 | spin_unlock_irqrestore(&mp->slock, flags); |
| 661 | } |
| 662 | |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 663 | static int mxser_set_baud(struct tty_struct *tty, speed_t newspd) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 664 | { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 665 | struct mxser_port *info = tty->driver_data; |
Jiri Slaby | 104583b | 2017-09-12 12:39:54 +0200 | [diff] [blame] | 666 | unsigned int quot = 0, baud; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 667 | unsigned char cval; |
Jiri Slaby | 104583b | 2017-09-12 12:39:54 +0200 | [diff] [blame] | 668 | u64 timeout; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 669 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 670 | if (!info->ioaddr) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 671 | return -1; |
| 672 | |
Jiri Slaby | 928f946 | 2021-06-18 08:14:16 +0200 | [diff] [blame] | 673 | if (newspd > info->board->max_baud) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 674 | return -1; |
| 675 | |
| 676 | if (newspd == 134) { |
| 677 | quot = 2 * info->baud_base / 269; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 678 | tty_encode_baud_rate(tty, 134, 134); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 679 | } else if (newspd) { |
| 680 | quot = info->baud_base / newspd; |
| 681 | if (quot == 0) |
| 682 | quot = 1; |
| 683 | baud = info->baud_base/quot; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 684 | tty_encode_baud_rate(tty, baud, baud); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 685 | } else { |
| 686 | quot = 0; |
| 687 | } |
| 688 | |
Jiri Slaby | 104583b | 2017-09-12 12:39:54 +0200 | [diff] [blame] | 689 | /* |
| 690 | * worst case (128 * 1000 * 10 * 18432) needs 35 bits, so divide in the |
| 691 | * u64 domain |
| 692 | */ |
| 693 | timeout = (u64)info->xmit_fifo_size * HZ * 10 * quot; |
| 694 | do_div(timeout, info->baud_base); |
| 695 | info->timeout = timeout + HZ / 50; /* Add .02 seconds of slop */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 696 | |
| 697 | if (quot) { |
| 698 | info->MCR |= UART_MCR_DTR; |
| 699 | outb(info->MCR, info->ioaddr + UART_MCR); |
| 700 | } else { |
| 701 | info->MCR &= ~UART_MCR_DTR; |
| 702 | outb(info->MCR, info->ioaddr + UART_MCR); |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | cval = inb(info->ioaddr + UART_LCR); |
| 707 | |
| 708 | outb(cval | UART_LCR_DLAB, info->ioaddr + UART_LCR); /* set DLAB */ |
| 709 | |
| 710 | outb(quot & 0xff, info->ioaddr + UART_DLL); /* LS of divisor */ |
| 711 | outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */ |
| 712 | outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */ |
| 713 | |
| 714 | #ifdef BOTHER |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 715 | if (C_BAUD(tty) == BOTHER) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 716 | quot = info->baud_base % newspd; |
| 717 | quot *= 8; |
| 718 | if (quot % newspd > newspd / 2) { |
| 719 | quot /= newspd; |
| 720 | quot++; |
| 721 | } else |
| 722 | quot /= newspd; |
| 723 | |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 724 | mxser_set_must_enum_value(info->ioaddr, quot); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 725 | } else |
| 726 | #endif |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 727 | mxser_set_must_enum_value(info->ioaddr, 0); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | /* |
| 733 | * This routine is called to set the UART divisor registers to match |
| 734 | * the specified baud rate for a serial port. |
| 735 | */ |
Jason Yan | beca62c | 2020-05-06 14:17:35 +0800 | [diff] [blame] | 736 | static void mxser_change_speed(struct tty_struct *tty) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 737 | { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 738 | struct mxser_port *info = tty->driver_data; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 739 | unsigned cflag, cval, fcr; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 740 | unsigned char status; |
| 741 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 742 | cflag = tty->termios.c_cflag; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 743 | if (!info->ioaddr) |
Jason Yan | beca62c | 2020-05-06 14:17:35 +0800 | [diff] [blame] | 744 | return; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 745 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 746 | if (mxser_set_baud_method[tty->index] == 0) |
| 747 | mxser_set_baud(tty, tty_get_baud_rate(tty)); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 748 | |
| 749 | /* byte size and parity */ |
| 750 | switch (cflag & CSIZE) { |
| 751 | case CS5: |
| 752 | cval = 0x00; |
| 753 | break; |
| 754 | case CS6: |
| 755 | cval = 0x01; |
| 756 | break; |
| 757 | case CS7: |
| 758 | cval = 0x02; |
| 759 | break; |
| 760 | case CS8: |
| 761 | cval = 0x03; |
| 762 | break; |
| 763 | default: |
| 764 | cval = 0x00; |
| 765 | break; /* too keep GCC shut... */ |
| 766 | } |
| 767 | if (cflag & CSTOPB) |
| 768 | cval |= 0x04; |
| 769 | if (cflag & PARENB) |
| 770 | cval |= UART_LCR_PARITY; |
| 771 | if (!(cflag & PARODD)) |
| 772 | cval |= UART_LCR_EPAR; |
| 773 | if (cflag & CMSPAR) |
| 774 | cval |= UART_LCR_SPAR; |
| 775 | |
| 776 | if ((info->type == PORT_8250) || (info->type == PORT_16450)) { |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 777 | if (info->board->must_hwid) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 778 | fcr = UART_FCR_ENABLE_FIFO; |
| 779 | fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE; |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 780 | mxser_set_must_fifo_value(info); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 781 | } else |
| 782 | fcr = 0; |
| 783 | } else { |
| 784 | fcr = UART_FCR_ENABLE_FIFO; |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 785 | if (info->board->must_hwid) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 786 | fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE; |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 787 | mxser_set_must_fifo_value(info); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 788 | } else { |
Jiri Slaby | dc33f64 | 2021-06-18 08:14:11 +0200 | [diff] [blame] | 789 | switch (info->rx_high_water) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 790 | case 1: |
| 791 | fcr |= UART_FCR_TRIGGER_1; |
| 792 | break; |
| 793 | case 4: |
| 794 | fcr |= UART_FCR_TRIGGER_4; |
| 795 | break; |
| 796 | case 8: |
| 797 | fcr |= UART_FCR_TRIGGER_8; |
| 798 | break; |
| 799 | default: |
| 800 | fcr |= UART_FCR_TRIGGER_14; |
| 801 | break; |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | /* CTS flow control flag and modem status interrupts */ |
| 807 | info->IER &= ~UART_IER_MSI; |
| 808 | info->MCR &= ~UART_MCR_AFE; |
Peter Hurley | 5604a98 | 2016-04-09 17:53:21 -0700 | [diff] [blame] | 809 | tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 810 | if (cflag & CRTSCTS) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 811 | info->IER |= UART_IER_MSI; |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 812 | if ((info->type == PORT_16550A) || (info->board->must_hwid)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 813 | info->MCR |= UART_MCR_AFE; |
| 814 | } else { |
| 815 | status = inb(info->ioaddr + UART_MSR); |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 816 | if (tty->hw_stopped) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 817 | if (status & UART_MSR_CTS) { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 818 | tty->hw_stopped = 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 819 | if (info->type != PORT_16550A && |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 820 | !info->board->must_hwid) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 821 | outb(info->IER & ~UART_IER_THRI, |
| 822 | info->ioaddr + |
| 823 | UART_IER); |
| 824 | info->IER |= UART_IER_THRI; |
| 825 | outb(info->IER, info->ioaddr + |
| 826 | UART_IER); |
| 827 | } |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 828 | tty_wakeup(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 829 | } |
| 830 | } else { |
| 831 | if (!(status & UART_MSR_CTS)) { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 832 | tty->hw_stopped = 1; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 833 | if ((info->type != PORT_16550A) && |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 834 | (!info->board->must_hwid)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 835 | info->IER &= ~UART_IER_THRI; |
| 836 | outb(info->IER, info->ioaddr + |
| 837 | UART_IER); |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 842 | } |
| 843 | outb(info->MCR, info->ioaddr + UART_MCR); |
Peter Hurley | 2d68655 | 2016-04-09 17:53:23 -0700 | [diff] [blame] | 844 | tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); |
| 845 | if (~cflag & CLOCAL) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 846 | info->IER |= UART_IER_MSI; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 847 | outb(info->IER, info->ioaddr + UART_IER); |
| 848 | |
| 849 | /* |
| 850 | * Set up parity check flag |
| 851 | */ |
| 852 | info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 853 | if (I_INPCK(tty)) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 854 | info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 855 | if (I_BRKINT(tty) || I_PARMRK(tty)) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 856 | info->read_status_mask |= UART_LSR_BI; |
| 857 | |
| 858 | info->ignore_status_mask = 0; |
| 859 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 860 | if (I_IGNBRK(tty)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 861 | info->ignore_status_mask |= UART_LSR_BI; |
| 862 | info->read_status_mask |= UART_LSR_BI; |
| 863 | /* |
| 864 | * If we're ignore parity and break indicators, ignore |
| 865 | * overruns too. (For real raw support). |
| 866 | */ |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 867 | if (I_IGNPAR(tty)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 868 | info->ignore_status_mask |= |
| 869 | UART_LSR_OE | |
| 870 | UART_LSR_PE | |
| 871 | UART_LSR_FE; |
| 872 | info->read_status_mask |= |
| 873 | UART_LSR_OE | |
| 874 | UART_LSR_PE | |
| 875 | UART_LSR_FE; |
| 876 | } |
| 877 | } |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 878 | if (info->board->must_hwid) { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 879 | mxser_set_must_xon1_value(info->ioaddr, START_CHAR(tty)); |
| 880 | mxser_set_must_xoff1_value(info->ioaddr, STOP_CHAR(tty)); |
| 881 | if (I_IXON(tty)) { |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 882 | mxser_enable_must_rx_software_flow_control( |
| 883 | info->ioaddr); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 884 | } else { |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 885 | mxser_disable_must_rx_software_flow_control( |
| 886 | info->ioaddr); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 887 | } |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 888 | if (I_IXOFF(tty)) { |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 889 | mxser_enable_must_tx_software_flow_control( |
| 890 | info->ioaddr); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 891 | } else { |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 892 | mxser_disable_must_tx_software_flow_control( |
| 893 | info->ioaddr); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
| 897 | |
| 898 | outb(fcr, info->ioaddr + UART_FCR); /* set fcr */ |
| 899 | outb(cval, info->ioaddr + UART_LCR); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 900 | } |
| 901 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 902 | static void mxser_check_modem_status(struct tty_struct *tty, |
| 903 | struct mxser_port *port, int status) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 904 | { |
| 905 | /* update input line counters */ |
| 906 | if (status & UART_MSR_TERI) |
| 907 | port->icount.rng++; |
| 908 | if (status & UART_MSR_DDSR) |
| 909 | port->icount.dsr++; |
| 910 | if (status & UART_MSR_DDCD) |
| 911 | port->icount.dcd++; |
| 912 | if (status & UART_MSR_DCTS) |
| 913 | port->icount.cts++; |
| 914 | port->mon_data.modem_status = status; |
Alan Cox | bdc04e3 | 2009-09-19 13:13:31 -0700 | [diff] [blame] | 915 | wake_up_interruptible(&port->port.delta_msr_wait); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 916 | |
Peter Hurley | 2d68655 | 2016-04-09 17:53:23 -0700 | [diff] [blame] | 917 | if (tty_port_check_carrier(&port->port) && (status & UART_MSR_DDCD)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 918 | if (status & UART_MSR_DCD) |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 919 | wake_up_interruptible(&port->port.open_wait); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 920 | } |
| 921 | |
Huang Shijie | f21ec3d | 2012-08-22 22:13:36 -0400 | [diff] [blame] | 922 | if (tty_port_cts_enabled(&port->port)) { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 923 | if (tty->hw_stopped) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 924 | if (status & UART_MSR_CTS) { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 925 | tty->hw_stopped = 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 926 | |
| 927 | if ((port->type != PORT_16550A) && |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 928 | (!port->board->must_hwid)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 929 | outb(port->IER & ~UART_IER_THRI, |
| 930 | port->ioaddr + UART_IER); |
| 931 | port->IER |= UART_IER_THRI; |
| 932 | outb(port->IER, port->ioaddr + |
| 933 | UART_IER); |
| 934 | } |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 935 | tty_wakeup(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 936 | } |
| 937 | } else { |
| 938 | if (!(status & UART_MSR_CTS)) { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 939 | tty->hw_stopped = 1; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 940 | if (port->type != PORT_16550A && |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 941 | !port->board->must_hwid) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 942 | port->IER &= ~UART_IER_THRI; |
| 943 | outb(port->IER, port->ioaddr + |
| 944 | UART_IER); |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | } |
| 950 | |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 951 | static int mxser_activate(struct tty_port *port, struct tty_struct *tty) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 952 | { |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 953 | struct mxser_port *info = container_of(port, struct mxser_port, port); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 954 | unsigned long page; |
| 955 | unsigned long flags; |
| 956 | |
| 957 | page = __get_free_page(GFP_KERNEL); |
| 958 | if (!page) |
| 959 | return -ENOMEM; |
| 960 | |
| 961 | spin_lock_irqsave(&info->slock, flags); |
| 962 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 963 | if (!info->ioaddr || !info->type) { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 964 | set_bit(TTY_IO_ERROR, &tty->flags); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 965 | free_page(page); |
| 966 | spin_unlock_irqrestore(&info->slock, flags); |
| 967 | return 0; |
| 968 | } |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 969 | info->port.xmit_buf = (unsigned char *) page; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 970 | |
| 971 | /* |
| 972 | * Clear the FIFO buffers and disable them |
| 973 | * (they will be reenabled in mxser_change_speed()) |
| 974 | */ |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 975 | if (info->board->must_hwid) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 976 | outb((UART_FCR_CLEAR_RCVR | |
| 977 | UART_FCR_CLEAR_XMIT | |
| 978 | MOXA_MUST_FCR_GDA_MODE_ENABLE), info->ioaddr + UART_FCR); |
| 979 | else |
| 980 | outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), |
| 981 | info->ioaddr + UART_FCR); |
| 982 | |
| 983 | /* |
| 984 | * At this point there's no way the LSR could still be 0xFF; |
| 985 | * if it is, then bail out, because there's likely no UART |
| 986 | * here. |
| 987 | */ |
| 988 | if (inb(info->ioaddr + UART_LSR) == 0xff) { |
| 989 | spin_unlock_irqrestore(&info->slock, flags); |
| 990 | if (capable(CAP_SYS_ADMIN)) { |
Jiri Slaby | f43a510d | 2009-12-09 12:34:15 -0800 | [diff] [blame] | 991 | set_bit(TTY_IO_ERROR, &tty->flags); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 992 | return 0; |
| 993 | } else |
| 994 | return -ENODEV; |
| 995 | } |
| 996 | |
| 997 | /* |
| 998 | * Clear the interrupt registers. |
| 999 | */ |
| 1000 | (void) inb(info->ioaddr + UART_LSR); |
| 1001 | (void) inb(info->ioaddr + UART_RX); |
| 1002 | (void) inb(info->ioaddr + UART_IIR); |
| 1003 | (void) inb(info->ioaddr + UART_MSR); |
| 1004 | |
| 1005 | /* |
| 1006 | * Now, initialize the UART |
| 1007 | */ |
| 1008 | outb(UART_LCR_WLEN8, info->ioaddr + UART_LCR); /* reset DLAB */ |
| 1009 | info->MCR = UART_MCR_DTR | UART_MCR_RTS; |
| 1010 | outb(info->MCR, info->ioaddr + UART_MCR); |
| 1011 | |
| 1012 | /* |
| 1013 | * Finally, enable interrupts |
| 1014 | */ |
| 1015 | info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI; |
| 1016 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1017 | if (info->board->must_hwid) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1018 | info->IER |= MOXA_MUST_IER_EGDAI; |
| 1019 | outb(info->IER, info->ioaddr + UART_IER); /* enable interrupts */ |
| 1020 | |
| 1021 | /* |
| 1022 | * And clear the interrupt registers again for luck. |
| 1023 | */ |
| 1024 | (void) inb(info->ioaddr + UART_LSR); |
| 1025 | (void) inb(info->ioaddr + UART_RX); |
| 1026 | (void) inb(info->ioaddr + UART_IIR); |
| 1027 | (void) inb(info->ioaddr + UART_MSR); |
| 1028 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1029 | clear_bit(TTY_IO_ERROR, &tty->flags); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1030 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; |
| 1031 | |
| 1032 | /* |
| 1033 | * and set the speed of the serial port |
| 1034 | */ |
Jiri Slaby | 2799707 | 2017-09-12 12:39:55 +0200 | [diff] [blame] | 1035 | mxser_change_speed(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1036 | spin_unlock_irqrestore(&info->slock, flags); |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | /* |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1042 | * This routine will shutdown a serial port |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1043 | */ |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1044 | static void mxser_shutdown_port(struct tty_port *port) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1045 | { |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1046 | struct mxser_port *info = container_of(port, struct mxser_port, port); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1047 | unsigned long flags; |
| 1048 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1049 | spin_lock_irqsave(&info->slock, flags); |
| 1050 | |
| 1051 | /* |
| 1052 | * clear delta_msr_wait queue to avoid mem leaks: we may free the irq |
| 1053 | * here so the queue might never be waken up |
| 1054 | */ |
Alan Cox | bdc04e3 | 2009-09-19 13:13:31 -0700 | [diff] [blame] | 1055 | wake_up_interruptible(&info->port.delta_msr_wait); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1056 | |
| 1057 | /* |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1058 | * Free the xmit buffer, if necessary |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1059 | */ |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 1060 | if (info->port.xmit_buf) { |
| 1061 | free_page((unsigned long) info->port.xmit_buf); |
| 1062 | info->port.xmit_buf = NULL; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | info->IER = 0; |
| 1066 | outb(0x00, info->ioaddr + UART_IER); |
| 1067 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1068 | /* clear Rx/Tx FIFO's */ |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1069 | if (info->board->must_hwid) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1070 | outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | |
| 1071 | MOXA_MUST_FCR_GDA_MODE_ENABLE, |
| 1072 | info->ioaddr + UART_FCR); |
| 1073 | else |
| 1074 | outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT, |
| 1075 | info->ioaddr + UART_FCR); |
| 1076 | |
| 1077 | /* read data port to reset things */ |
| 1078 | (void) inb(info->ioaddr + UART_RX); |
| 1079 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1080 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1081 | if (info->board->must_hwid) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1082 | SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->ioaddr); |
| 1083 | |
| 1084 | spin_unlock_irqrestore(&info->slock, flags); |
| 1085 | } |
| 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | /* |
| 1088 | * This routine is called whenever a serial port is opened. It |
| 1089 | * enables interrupts for a serial port, linking in its async structure into |
| 1090 | * the IRQ chain. It also performs the serial-specific |
| 1091 | * initialization for the tty structure. |
| 1092 | */ |
| 1093 | static int mxser_open(struct tty_struct *tty, struct file *filp) |
| 1094 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1095 | struct mxser_port *info; |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1096 | int line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
| 1098 | line = tty->index; |
| 1099 | if (line == MXSER_PORTS) |
| 1100 | return 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1101 | info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD]; |
| 1102 | if (!info->ioaddr) |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1103 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Alan Cox | a2d1e35 | 2010-04-23 16:01:18 +0100 | [diff] [blame] | 1105 | tty->driver_data = info; |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1106 | return tty_port_open(&info->port, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 1109 | static void mxser_flush_buffer(struct tty_struct *tty) |
| 1110 | { |
| 1111 | struct mxser_port *info = tty->driver_data; |
| 1112 | char fcr; |
| 1113 | unsigned long flags; |
| 1114 | |
| 1115 | |
| 1116 | spin_lock_irqsave(&info->slock, flags); |
| 1117 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; |
| 1118 | |
| 1119 | fcr = inb(info->ioaddr + UART_FCR); |
| 1120 | outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), |
| 1121 | info->ioaddr + UART_FCR); |
| 1122 | outb(fcr, info->ioaddr + UART_FCR); |
| 1123 | |
| 1124 | spin_unlock_irqrestore(&info->slock, flags); |
| 1125 | |
| 1126 | tty_wakeup(tty); |
| 1127 | } |
| 1128 | |
| 1129 | |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1130 | static void mxser_close_port(struct tty_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | { |
Alan Cox | 1e2b025 | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 1132 | struct mxser_port *info = container_of(port, struct mxser_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | unsigned long timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | * At this point we stop accepting input. To do this, we |
| 1136 | * disable the receive line status interrupts, and tell the |
| 1137 | * interrupt driver to stop checking the data ready bit in the |
| 1138 | * line status register. |
| 1139 | */ |
| 1140 | info->IER &= ~UART_IER_RLSI; |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1141 | if (info->board->must_hwid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | info->IER &= ~MOXA_MUST_RECV_ISR; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1143 | |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1144 | outb(info->IER, info->ioaddr + UART_IER); |
| 1145 | /* |
| 1146 | * Before we drop DTR, make sure the UART transmitter |
| 1147 | * has completely drained; this is especially |
| 1148 | * important if there is a transmit FIFO! |
| 1149 | */ |
| 1150 | timeout = jiffies + HZ; |
| 1151 | while (!(inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) { |
| 1152 | schedule_timeout_interruptible(5); |
| 1153 | if (time_after(jiffies, timeout)) |
| 1154 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } |
Alan Cox | 1e2b025 | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | /* |
| 1159 | * This routine is called when the serial port gets closed. First, we |
| 1160 | * wait for the last remaining data to be sent. Then, we unlink its |
| 1161 | * async structure from the interrupt chain if necessary, and we free |
| 1162 | * that IRQ if nothing is left in the chain. |
| 1163 | */ |
| 1164 | static void mxser_close(struct tty_struct *tty, struct file *filp) |
| 1165 | { |
| 1166 | struct mxser_port *info = tty->driver_data; |
| 1167 | struct tty_port *port = &info->port; |
| 1168 | |
Alan Cox | a2d1e35 | 2010-04-23 16:01:18 +0100 | [diff] [blame] | 1169 | if (tty->index == MXSER_PORTS || info == NULL) |
Alan Cox | 1e2b025 | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 1170 | return; |
| 1171 | if (tty_port_close_start(port, tty, filp) == 0) |
| 1172 | return; |
Peter Hurley | cd7b4b3 | 2016-01-10 14:51:38 -0800 | [diff] [blame] | 1173 | info->closing = 1; |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1174 | mutex_lock(&port->mutex); |
| 1175 | mxser_close_port(port); |
Alan Cox | 1e2b025 | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 1176 | mxser_flush_buffer(tty); |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 1177 | if (tty_port_initialized(port) && C_HUPCL(tty)) |
| 1178 | tty_port_lower_dtr_rts(port); |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1179 | mxser_shutdown_port(port); |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 1180 | tty_port_set_initialized(port, 0); |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1181 | mutex_unlock(&port->mutex); |
Peter Hurley | cd7b4b3 | 2016-01-10 14:51:38 -0800 | [diff] [blame] | 1182 | info->closing = 0; |
Alan Cox | a661499 | 2009-01-02 13:46:50 +0000 | [diff] [blame] | 1183 | /* Right now the tty_port set is done outside of the close_end helper |
| 1184 | as we don't yet have everyone using refcounts */ |
| 1185 | tty_port_close_end(port, tty); |
| 1186 | tty_port_tty_set(port, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count) |
| 1190 | { |
| 1191 | int c, total = 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1192 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | unsigned long flags; |
| 1194 | |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 1195 | if (!info->port.xmit_buf) |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1196 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
| 1198 | while (1) { |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1199 | c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, |
| 1200 | SERIAL_XMIT_SIZE - info->xmit_head)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | if (c <= 0) |
| 1202 | break; |
| 1203 | |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 1204 | memcpy(info->port.xmit_buf + info->xmit_head, buf, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | spin_lock_irqsave(&info->slock, flags); |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1206 | info->xmit_head = (info->xmit_head + c) & |
| 1207 | (SERIAL_XMIT_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | info->xmit_cnt += c; |
| 1209 | spin_unlock_irqrestore(&info->slock, flags); |
| 1210 | |
| 1211 | buf += c; |
| 1212 | count -= c; |
| 1213 | total += c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Jiri Slaby | 6e94dbc | 2021-05-05 11:19:05 +0200 | [diff] [blame] | 1216 | if (info->xmit_cnt && !tty->flow.stopped) { |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1217 | if (!tty->hw_stopped || |
| 1218 | (info->type == PORT_16550A) || |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1219 | (info->board->must_hwid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | spin_lock_irqsave(&info->slock, flags); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1221 | outb(info->IER & ~UART_IER_THRI, info->ioaddr + |
| 1222 | UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | info->IER |= UART_IER_THRI; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1224 | outb(info->IER, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | spin_unlock_irqrestore(&info->slock, flags); |
| 1226 | } |
| 1227 | } |
| 1228 | return total; |
| 1229 | } |
| 1230 | |
Alan Cox | 0be2ead | 2008-04-30 00:54:03 -0700 | [diff] [blame] | 1231 | static int mxser_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1233 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | unsigned long flags; |
| 1235 | |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 1236 | if (!info->port.xmit_buf) |
Alan Cox | 0be2ead | 2008-04-30 00:54:03 -0700 | [diff] [blame] | 1237 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
| 1239 | if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) |
Alan Cox | 0be2ead | 2008-04-30 00:54:03 -0700 | [diff] [blame] | 1240 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
| 1242 | spin_lock_irqsave(&info->slock, flags); |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 1243 | info->port.xmit_buf[info->xmit_head++] = ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | info->xmit_head &= SERIAL_XMIT_SIZE - 1; |
| 1245 | info->xmit_cnt++; |
| 1246 | spin_unlock_irqrestore(&info->slock, flags); |
Jiri Slaby | 6e94dbc | 2021-05-05 11:19:05 +0200 | [diff] [blame] | 1247 | if (!tty->flow.stopped) { |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1248 | if (!tty->hw_stopped || |
| 1249 | (info->type == PORT_16550A) || |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1250 | info->board->must_hwid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | spin_lock_irqsave(&info->slock, flags); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1252 | outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | info->IER |= UART_IER_THRI; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1254 | outb(info->IER, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | spin_unlock_irqrestore(&info->slock, flags); |
| 1256 | } |
| 1257 | } |
Alan Cox | 0be2ead | 2008-04-30 00:54:03 -0700 | [diff] [blame] | 1258 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | static void mxser_flush_chars(struct tty_struct *tty) |
| 1263 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1264 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | unsigned long flags; |
| 1266 | |
Jiri Slaby | 6e94dbc | 2021-05-05 11:19:05 +0200 | [diff] [blame] | 1267 | if (info->xmit_cnt <= 0 || tty->flow.stopped || !info->port.xmit_buf || |
Jiri Slaby | ace7dd9 | 2008-07-25 01:48:22 -0700 | [diff] [blame] | 1268 | (tty->hw_stopped && info->type != PORT_16550A && |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1269 | !info->board->must_hwid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | return; |
| 1271 | |
| 1272 | spin_lock_irqsave(&info->slock, flags); |
| 1273 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1274 | outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | info->IER |= UART_IER_THRI; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1276 | outb(info->IER, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
| 1278 | spin_unlock_irqrestore(&info->slock, flags); |
| 1279 | } |
| 1280 | |
Jiri Slaby | 03b3b1a | 2021-05-05 11:19:15 +0200 | [diff] [blame] | 1281 | static unsigned int mxser_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1283 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | int ret; |
| 1285 | |
| 1286 | ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1; |
Jiri Slaby | ace7dd9 | 2008-07-25 01:48:22 -0700 | [diff] [blame] | 1287 | return ret < 0 ? 0 : ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Jiri Slaby | fff4ef1 | 2021-05-05 11:19:19 +0200 | [diff] [blame] | 1290 | static unsigned int mxser_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1292 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | return info->xmit_cnt; |
| 1294 | } |
| 1295 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1296 | /* |
| 1297 | * ------------------------------------------------------------ |
| 1298 | * friends of mxser_ioctl() |
| 1299 | * ------------------------------------------------------------ |
| 1300 | */ |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1301 | static int mxser_get_serial_info(struct tty_struct *tty, |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1302 | struct serial_struct *ss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1304 | struct mxser_port *info = tty->driver_data; |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1305 | struct tty_port *port = &info->port; |
Johan Hovold | be6cf58 | 2021-04-07 12:23:31 +0200 | [diff] [blame] | 1306 | unsigned int closing_wait, close_delay; |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1307 | |
| 1308 | if (tty->index == MXSER_PORTS) |
| 1309 | return -ENOTTY; |
| 1310 | |
| 1311 | mutex_lock(&port->mutex); |
Johan Hovold | be6cf58 | 2021-04-07 12:23:31 +0200 | [diff] [blame] | 1312 | |
| 1313 | close_delay = jiffies_to_msecs(info->port.close_delay) / 10; |
| 1314 | closing_wait = info->port.closing_wait; |
| 1315 | if (closing_wait != ASYNC_CLOSING_WAIT_NONE) |
| 1316 | closing_wait = jiffies_to_msecs(closing_wait) / 10; |
| 1317 | |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1318 | ss->type = info->type, |
| 1319 | ss->line = tty->index, |
| 1320 | ss->port = info->ioaddr, |
| 1321 | ss->irq = info->board->irq, |
| 1322 | ss->flags = info->port.flags, |
| 1323 | ss->baud_base = info->baud_base, |
Johan Hovold | be6cf58 | 2021-04-07 12:23:31 +0200 | [diff] [blame] | 1324 | ss->close_delay = close_delay; |
| 1325 | ss->closing_wait = closing_wait; |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1326 | ss->custom_divisor = info->custom_divisor, |
| 1327 | mutex_unlock(&port->mutex); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1331 | static int mxser_set_serial_info(struct tty_struct *tty, |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1332 | struct serial_struct *ss) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1333 | { |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1334 | struct mxser_port *info = tty->driver_data; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1335 | struct tty_port *port = &info->port; |
Jiri Slaby | 80ff8a8 | 2008-02-07 00:16:51 -0800 | [diff] [blame] | 1336 | speed_t baud; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1337 | unsigned long sl_flags; |
Johan Hovold | be6cf58 | 2021-04-07 12:23:31 +0200 | [diff] [blame] | 1338 | unsigned int flags, close_delay, closing_wait; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1339 | int retval = 0; |
| 1340 | |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1341 | if (tty->index == MXSER_PORTS) |
| 1342 | return -ENOTTY; |
| 1343 | if (tty_io_error(tty)) |
| 1344 | return -EIO; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1345 | |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1346 | mutex_lock(&port->mutex); |
| 1347 | if (!info->ioaddr) { |
| 1348 | mutex_unlock(&port->mutex); |
| 1349 | return -ENODEV; |
| 1350 | } |
| 1351 | |
| 1352 | if (ss->irq != info->board->irq || |
| 1353 | ss->port != info->ioaddr) { |
| 1354 | mutex_unlock(&port->mutex); |
Jiri Slaby | 80ff8a8 | 2008-02-07 00:16:51 -0800 | [diff] [blame] | 1355 | return -EINVAL; |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1356 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1357 | |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1358 | flags = port->flags & ASYNC_SPD_MASK; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1359 | |
Johan Hovold | be6cf58 | 2021-04-07 12:23:31 +0200 | [diff] [blame] | 1360 | close_delay = msecs_to_jiffies(ss->close_delay * 10); |
| 1361 | closing_wait = ss->closing_wait; |
| 1362 | if (closing_wait != ASYNC_CLOSING_WAIT_NONE) |
| 1363 | closing_wait = msecs_to_jiffies(closing_wait * 10); |
| 1364 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1365 | if (!capable(CAP_SYS_ADMIN)) { |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1366 | if ((ss->baud_base != info->baud_base) || |
Johan Hovold | be6cf58 | 2021-04-07 12:23:31 +0200 | [diff] [blame] | 1367 | (close_delay != info->port.close_delay) || |
Johan Hovold | b91cfb2 | 2021-04-07 12:23:32 +0200 | [diff] [blame] | 1368 | (closing_wait != info->port.closing_wait) || |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1369 | ((ss->flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) { |
| 1370 | mutex_unlock(&port->mutex); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1371 | return -EPERM; |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1372 | } |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 1373 | info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) | |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1374 | (ss->flags & ASYNC_USR_MASK)); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1375 | } else { |
| 1376 | /* |
| 1377 | * OK, past this point, all the error checking has been done. |
| 1378 | * At this point, we start making changes..... |
| 1379 | */ |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1380 | port->flags = ((port->flags & ~ASYNC_FLAGS) | |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1381 | (ss->flags & ASYNC_FLAGS)); |
Johan Hovold | be6cf58 | 2021-04-07 12:23:31 +0200 | [diff] [blame] | 1382 | port->close_delay = close_delay; |
| 1383 | port->closing_wait = closing_wait; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1384 | if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST && |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1385 | (ss->baud_base != info->baud_base || |
| 1386 | ss->custom_divisor != |
Jiri Slaby | 80ff8a8 | 2008-02-07 00:16:51 -0800 | [diff] [blame] | 1387 | info->custom_divisor)) { |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1388 | if (ss->custom_divisor == 0) { |
| 1389 | mutex_unlock(&port->mutex); |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1390 | return -EINVAL; |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1391 | } |
| 1392 | baud = ss->baud_base / ss->custom_divisor; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1393 | tty_encode_baud_rate(tty, baud, baud); |
Jiri Slaby | 80ff8a8 | 2008-02-07 00:16:51 -0800 | [diff] [blame] | 1394 | } |
Johan Hovold | b91cfb2 | 2021-04-07 12:23:32 +0200 | [diff] [blame] | 1395 | |
| 1396 | info->type = ss->type; |
| 1397 | |
| 1398 | process_txrx_fifo(info); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 1401 | if (tty_port_initialized(port)) { |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1402 | if (flags != (port->flags & ASYNC_SPD_MASK)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1403 | spin_lock_irqsave(&info->slock, sl_flags); |
Jiri Slaby | 2799707 | 2017-09-12 12:39:55 +0200 | [diff] [blame] | 1404 | mxser_change_speed(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1405 | spin_unlock_irqrestore(&info->slock, sl_flags); |
| 1406 | } |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1407 | } else { |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1408 | retval = mxser_activate(port, tty); |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1409 | if (retval == 0) |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 1410 | tty_port_set_initialized(port, 1); |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 1411 | } |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1412 | mutex_unlock(&port->mutex); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1413 | return retval; |
| 1414 | } |
| 1415 | |
| 1416 | /* |
| 1417 | * mxser_get_lsr_info - get line status register info |
| 1418 | * |
| 1419 | * Purpose: Let user call ioctl() to get info when the UART physically |
| 1420 | * is emptied. On bus types like RS485, the transmitter must |
| 1421 | * release the bus after transmitting. This must be done when |
| 1422 | * the transmit shift register is empty, not be done when the |
| 1423 | * transmit holding register is empty. This functionality |
| 1424 | * allows an RS485 driver to be written in user space. |
| 1425 | */ |
| 1426 | static int mxser_get_lsr_info(struct mxser_port *info, |
| 1427 | unsigned int __user *value) |
| 1428 | { |
| 1429 | unsigned char status; |
| 1430 | unsigned int result; |
| 1431 | unsigned long flags; |
| 1432 | |
| 1433 | spin_lock_irqsave(&info->slock, flags); |
| 1434 | status = inb(info->ioaddr + UART_LSR); |
| 1435 | spin_unlock_irqrestore(&info->slock, flags); |
| 1436 | result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0); |
| 1437 | return put_user(result, value); |
| 1438 | } |
| 1439 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 1440 | static int mxser_tiocmget(struct tty_struct *tty) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1441 | { |
| 1442 | struct mxser_port *info = tty->driver_data; |
| 1443 | unsigned char control, status; |
| 1444 | unsigned long flags; |
| 1445 | |
| 1446 | |
| 1447 | if (tty->index == MXSER_PORTS) |
| 1448 | return -ENOIOCTLCMD; |
Peter Hurley | 18900ca | 2016-04-09 17:06:48 -0700 | [diff] [blame] | 1449 | if (tty_io_error(tty)) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1450 | return -EIO; |
| 1451 | |
| 1452 | control = info->MCR; |
| 1453 | |
| 1454 | spin_lock_irqsave(&info->slock, flags); |
| 1455 | status = inb(info->ioaddr + UART_MSR); |
| 1456 | if (status & UART_MSR_ANY_DELTA) |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1457 | mxser_check_modem_status(tty, info, status); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1458 | spin_unlock_irqrestore(&info->slock, flags); |
| 1459 | return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) | |
| 1460 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) | |
| 1461 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) | |
| 1462 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0) | |
| 1463 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) | |
| 1464 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0); |
| 1465 | } |
| 1466 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 1467 | static int mxser_tiocmset(struct tty_struct *tty, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1468 | unsigned int set, unsigned int clear) |
| 1469 | { |
| 1470 | struct mxser_port *info = tty->driver_data; |
| 1471 | unsigned long flags; |
| 1472 | |
| 1473 | |
| 1474 | if (tty->index == MXSER_PORTS) |
| 1475 | return -ENOIOCTLCMD; |
Peter Hurley | 18900ca | 2016-04-09 17:06:48 -0700 | [diff] [blame] | 1476 | if (tty_io_error(tty)) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1477 | return -EIO; |
| 1478 | |
| 1479 | spin_lock_irqsave(&info->slock, flags); |
| 1480 | |
| 1481 | if (set & TIOCM_RTS) |
| 1482 | info->MCR |= UART_MCR_RTS; |
| 1483 | if (set & TIOCM_DTR) |
| 1484 | info->MCR |= UART_MCR_DTR; |
| 1485 | |
| 1486 | if (clear & TIOCM_RTS) |
| 1487 | info->MCR &= ~UART_MCR_RTS; |
| 1488 | if (clear & TIOCM_DTR) |
| 1489 | info->MCR &= ~UART_MCR_DTR; |
| 1490 | |
| 1491 | outb(info->MCR, info->ioaddr + UART_MCR); |
| 1492 | spin_unlock_irqrestore(&info->slock, flags); |
| 1493 | return 0; |
| 1494 | } |
| 1495 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1496 | static int mxser_ioctl_special(unsigned int cmd, void __user *argp) |
| 1497 | { |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1498 | struct mxser_port *ip; |
| 1499 | struct tty_port *port; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1500 | struct tty_struct *tty; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1501 | int result, status; |
| 1502 | unsigned int i, j; |
Alan Cox | 9d6d162 | 2008-04-30 00:53:20 -0700 | [diff] [blame] | 1503 | int ret = 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1504 | |
| 1505 | switch (cmd) { |
| 1506 | case MOXA_GET_MAJOR: |
Manuel Zerpies | 5a3c6b251 | 2011-06-16 14:07:22 +0200 | [diff] [blame] | 1507 | printk_ratelimited(KERN_WARNING "mxser: '%s' uses deprecated ioctl " |
Jiri Slaby | 8f3d137 | 2008-07-29 22:33:38 -0700 | [diff] [blame] | 1508 | "%x (GET_MAJOR), fix your userspace\n", |
| 1509 | current->comm, cmd); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1510 | return put_user(ttymajor, (int __user *)argp); |
| 1511 | |
| 1512 | case MOXA_CHKPORTENABLE: |
| 1513 | result = 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1514 | for (i = 0; i < MXSER_BOARDS; i++) |
| 1515 | for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) |
| 1516 | if (mxser_boards[i].ports[j].ioaddr) |
| 1517 | result |= (1 << i); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1518 | return put_user(result, (unsigned long __user *)argp); |
| 1519 | case MOXA_GETDATACOUNT: |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1520 | /* The receive side is locked by port->slock but it isn't |
| 1521 | clear that an exact snapshot is worth copying here */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1522 | if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log))) |
Alan Cox | 9d6d162 | 2008-04-30 00:53:20 -0700 | [diff] [blame] | 1523 | ret = -EFAULT; |
Alan Cox | 9d6d162 | 2008-04-30 00:53:20 -0700 | [diff] [blame] | 1524 | return ret; |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1525 | case MOXA_GETMSTATUS: { |
| 1526 | struct mxser_mstatus ms, __user *msu = argp; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1527 | for (i = 0; i < MXSER_BOARDS; i++) |
| 1528 | for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1529 | ip = &mxser_boards[i].ports[j]; |
| 1530 | port = &ip->port; |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1531 | memset(&ms, 0, sizeof(ms)); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1532 | |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1533 | mutex_lock(&port->mutex); |
| 1534 | if (!ip->ioaddr) |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1535 | goto copy; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1536 | |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1537 | tty = tty_port_tty_get(port); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1538 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1539 | if (!tty) |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1540 | ms.cflag = ip->normal_termios.c_cflag; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1541 | else |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1542 | ms.cflag = tty->termios.c_cflag; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1543 | tty_kref_put(tty); |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1544 | spin_lock_irq(&ip->slock); |
| 1545 | status = inb(ip->ioaddr + UART_MSR); |
| 1546 | spin_unlock_irq(&ip->slock); |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1547 | if (status & UART_MSR_DCD) |
| 1548 | ms.dcd = 1; |
| 1549 | if (status & UART_MSR_DSR) |
| 1550 | ms.dsr = 1; |
| 1551 | if (status & UART_MSR_CTS) |
| 1552 | ms.cts = 1; |
| 1553 | copy: |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1554 | mutex_unlock(&port->mutex); |
| 1555 | if (copy_to_user(msu, &ms, sizeof(ms))) |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1556 | return -EFAULT; |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1557 | msu++; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1558 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1559 | return 0; |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1560 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1561 | case MOXA_ASPP_MON_EXT: { |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1562 | struct mxser_mon_ext *me; /* it's 2k, stack unfriendly */ |
| 1563 | unsigned int cflag, iflag, p; |
| 1564 | u8 opmode; |
| 1565 | |
| 1566 | me = kzalloc(sizeof(*me), GFP_KERNEL); |
| 1567 | if (!me) |
| 1568 | return -ENOMEM; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1569 | |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1570 | for (i = 0, p = 0; i < MXSER_BOARDS; i++) { |
| 1571 | for (j = 0; j < MXSER_PORTS_PER_BOARD; j++, p++) { |
| 1572 | if (p >= ARRAY_SIZE(me->rx_cnt)) { |
| 1573 | i = MXSER_BOARDS; |
| 1574 | break; |
| 1575 | } |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1576 | ip = &mxser_boards[i].ports[j]; |
| 1577 | port = &ip->port; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1578 | |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1579 | mutex_lock(&port->mutex); |
| 1580 | if (!ip->ioaddr) { |
| 1581 | mutex_unlock(&port->mutex); |
| 1582 | continue; |
| 1583 | } |
| 1584 | |
| 1585 | spin_lock_irq(&ip->slock); |
| 1586 | status = mxser_get_msr(ip->ioaddr, 0, p); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1587 | |
| 1588 | if (status & UART_MSR_TERI) |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1589 | ip->icount.rng++; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1590 | if (status & UART_MSR_DDSR) |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1591 | ip->icount.dsr++; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1592 | if (status & UART_MSR_DDCD) |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1593 | ip->icount.dcd++; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1594 | if (status & UART_MSR_DCTS) |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1595 | ip->icount.cts++; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1596 | |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1597 | ip->mon_data.modem_status = status; |
| 1598 | me->rx_cnt[p] = ip->mon_data.rxcnt; |
| 1599 | me->tx_cnt[p] = ip->mon_data.txcnt; |
| 1600 | me->up_rxcnt[p] = ip->mon_data.up_rxcnt; |
| 1601 | me->up_txcnt[p] = ip->mon_data.up_txcnt; |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1602 | me->modem_status[p] = |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1603 | ip->mon_data.modem_status; |
| 1604 | spin_unlock_irq(&ip->slock); |
| 1605 | |
| 1606 | tty = tty_port_tty_get(&ip->port); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1607 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1608 | if (!tty) { |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1609 | cflag = ip->normal_termios.c_cflag; |
| 1610 | iflag = ip->normal_termios.c_iflag; |
| 1611 | me->baudrate[p] = tty_termios_baud_rate(&ip->normal_termios); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1612 | } else { |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1613 | cflag = tty->termios.c_cflag; |
| 1614 | iflag = tty->termios.c_iflag; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1615 | me->baudrate[p] = tty_get_baud_rate(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1616 | } |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1617 | tty_kref_put(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1618 | |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1619 | me->databits[p] = cflag & CSIZE; |
| 1620 | me->stopbits[p] = cflag & CSTOPB; |
| 1621 | me->parity[p] = cflag & (PARENB | PARODD | |
| 1622 | CMSPAR); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1623 | |
| 1624 | if (cflag & CRTSCTS) |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1625 | me->flowctrl[p] |= 0x03; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1626 | |
| 1627 | if (iflag & (IXON | IXOFF)) |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1628 | me->flowctrl[p] |= 0x0C; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1629 | |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1630 | if (ip->type == PORT_16550A) |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1631 | me->fifo[p] = 1; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1632 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1633 | if (ip->board->must_hwid == MOXA_MUST_MU860_HWID) { |
Matwey V. Kornilov | dfc7b83 | 2013-05-21 13:57:37 +0400 | [diff] [blame] | 1634 | opmode = inb(ip->opmode_ioaddr)>>((p % 4) * 2); |
| 1635 | opmode &= OP_MODE_MASK; |
| 1636 | } else { |
| 1637 | opmode = RS232_MODE; |
| 1638 | } |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1639 | me->iftype[p] = opmode; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1640 | mutex_unlock(&port->mutex); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1641 | } |
Alan Cox | 9d6d162 | 2008-04-30 00:53:20 -0700 | [diff] [blame] | 1642 | } |
Jiri Slaby | 72800df | 2008-07-25 01:48:20 -0700 | [diff] [blame] | 1643 | if (copy_to_user(argp, me, sizeof(*me))) |
| 1644 | ret = -EFAULT; |
| 1645 | kfree(me); |
| 1646 | return ret; |
Alan Cox | 9d6d162 | 2008-04-30 00:53:20 -0700 | [diff] [blame] | 1647 | } |
| 1648 | default: |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1649 | return -ENOIOCTLCMD; |
| 1650 | } |
| 1651 | return 0; |
| 1652 | } |
| 1653 | |
| 1654 | static int mxser_cflags_changed(struct mxser_port *info, unsigned long arg, |
| 1655 | struct async_icount *cprev) |
| 1656 | { |
| 1657 | struct async_icount cnow; |
| 1658 | unsigned long flags; |
| 1659 | int ret; |
| 1660 | |
| 1661 | spin_lock_irqsave(&info->slock, flags); |
| 1662 | cnow = info->icount; /* atomic copy */ |
| 1663 | spin_unlock_irqrestore(&info->slock, flags); |
| 1664 | |
| 1665 | ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) || |
| 1666 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) || |
| 1667 | ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) || |
| 1668 | ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts)); |
| 1669 | |
| 1670 | *cprev = cnow; |
| 1671 | |
| 1672 | return ret; |
| 1673 | } |
| 1674 | |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 1675 | static int mxser_ioctl(struct tty_struct *tty, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1676 | unsigned int cmd, unsigned long arg) |
| 1677 | { |
| 1678 | struct mxser_port *info = tty->driver_data; |
| 1679 | struct async_icount cnow; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | unsigned long flags; |
| 1681 | void __user *argp = (void __user *)arg; |
| 1682 | |
| 1683 | if (tty->index == MXSER_PORTS) |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1684 | return mxser_ioctl_special(cmd, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1687 | int p; |
| 1688 | unsigned long opmode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f }; |
| 1690 | int shiftbit; |
| 1691 | unsigned char val, mask; |
| 1692 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1693 | if (info->board->must_hwid != MOXA_MUST_MU860_HWID) |
Matwey V. Kornilov | e037f95 | 2013-05-22 11:13:38 +0400 | [diff] [blame] | 1694 | return -EFAULT; |
| 1695 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1696 | p = tty->index % 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | if (cmd == MOXA_SET_OP_MODE) { |
| 1698 | if (get_user(opmode, (int __user *) argp)) |
| 1699 | return -EFAULT; |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1700 | if (opmode != RS232_MODE && |
| 1701 | opmode != RS485_2WIRE_MODE && |
| 1702 | opmode != RS422_MODE && |
| 1703 | opmode != RS485_4WIRE_MODE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | return -EFAULT; |
| 1705 | mask = ModeMask[p]; |
| 1706 | shiftbit = p * 2; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1707 | spin_lock_irq(&info->slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | val = inb(info->opmode_ioaddr); |
| 1709 | val &= mask; |
| 1710 | val |= (opmode << shiftbit); |
| 1711 | outb(val, info->opmode_ioaddr); |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1712 | spin_unlock_irq(&info->slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | } else { |
| 1714 | shiftbit = p * 2; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1715 | spin_lock_irq(&info->slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | opmode = inb(info->opmode_ioaddr) >> shiftbit; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1717 | spin_unlock_irq(&info->slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | opmode &= OP_MODE_MASK; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1719 | if (put_user(opmode, (int __user *)argp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | return -EFAULT; |
| 1721 | } |
| 1722 | return 0; |
| 1723 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 1725 | if (cmd != TIOCMIWAIT && tty_io_error(tty)) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1726 | return -EIO; |
| 1727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | case TIOCSERGETLSR: /* Get line status register */ |
Alan Cox | 9d6d162 | 2008-04-30 00:53:20 -0700 | [diff] [blame] | 1730 | return mxser_get_lsr_info(info, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | /* |
| 1732 | * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change |
| 1733 | * - mask passed in arg for lines of interest |
| 1734 | * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) |
| 1735 | * Caller should use TIOCGICOUNT to see which one it was |
| 1736 | */ |
Jiri Slaby | fc83815 | 2007-04-23 14:41:04 -0700 | [diff] [blame] | 1737 | case TIOCMIWAIT: |
| 1738 | spin_lock_irqsave(&info->slock, flags); |
| 1739 | cnow = info->icount; /* note the counters on entry */ |
| 1740 | spin_unlock_irqrestore(&info->slock, flags); |
| 1741 | |
Alan Cox | bdc04e3 | 2009-09-19 13:13:31 -0700 | [diff] [blame] | 1742 | return wait_event_interruptible(info->port.delta_msr_wait, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1743 | mxser_cflags_changed(info, arg, &cnow)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | case MOXA_HighSpeedOn: |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1745 | return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1746 | case MOXA_SDS_RSTICOUNTER: |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1747 | spin_lock_irq(&info->slock); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1748 | info->mon_data.rxcnt = 0; |
| 1749 | info->mon_data.txcnt = 0; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1750 | spin_unlock_irq(&info->slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | return 0; |
| 1752 | |
| 1753 | case MOXA_ASPP_OQUEUE:{ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1754 | int len, lsr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1756 | len = mxser_chars_in_buffer(tty); |
Dan Carpenter | c6eb69a | 2010-04-06 14:34:50 -0700 | [diff] [blame] | 1757 | spin_lock_irq(&info->slock); |
Jiri Slaby | a75b7b6 | 2009-09-10 12:20:08 +0200 | [diff] [blame] | 1758 | lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_THRE; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1759 | spin_unlock_irq(&info->slock); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1760 | len += (lsr ? 0 : 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1762 | return put_user(len, (int __user *)argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1764 | case MOXA_ASPP_MON: { |
| 1765 | int mcr, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
Dan Carpenter | c6eb69a | 2010-04-06 14:34:50 -0700 | [diff] [blame] | 1767 | spin_lock_irq(&info->slock); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1768 | status = mxser_get_msr(info->ioaddr, 1, tty->index); |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1769 | mxser_check_modem_status(tty, info, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1771 | mcr = inb(info->ioaddr + UART_MCR); |
Dan Carpenter | c6eb69a | 2010-04-06 14:34:50 -0700 | [diff] [blame] | 1772 | spin_unlock_irq(&info->slock); |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1773 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1774 | if (mcr & MOXA_MUST_MCR_XON_FLAG) |
| 1775 | info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD; |
| 1776 | else |
| 1777 | info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1779 | if (mcr & MOXA_MUST_MCR_TX_XON) |
| 1780 | info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT; |
| 1781 | else |
| 1782 | info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT; |
| 1783 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 1784 | if (tty->hw_stopped) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1785 | info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD; |
| 1786 | else |
| 1787 | info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1788 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1789 | if (copy_to_user(argp, &info->mon_data, |
| 1790 | sizeof(struct mxser_mon))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | return -EFAULT; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | return 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1794 | } |
| 1795 | case MOXA_ASPP_LSTATUS: { |
| 1796 | if (put_user(info->err_shadow, (unsigned char __user *)argp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1799 | info->err_shadow = 0; |
| 1800 | return 0; |
| 1801 | } |
| 1802 | case MOXA_SET_BAUD_METHOD: { |
| 1803 | int method; |
| 1804 | |
| 1805 | if (get_user(method, (int __user *)argp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | return -EFAULT; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1807 | mxser_set_baud_method[tty->index] = method; |
| 1808 | return put_user(method, (int __user *)argp); |
| 1809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | default: |
| 1811 | return -ENOIOCTLCMD; |
| 1812 | } |
| 1813 | return 0; |
| 1814 | } |
| 1815 | |
Alan Cox | 0587102 | 2010-09-16 18:21:52 +0100 | [diff] [blame] | 1816 | /* |
| 1817 | * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) |
| 1818 | * Return: write counters to the user passed counter struct |
| 1819 | * NB: both 1->0 and 0->1 transitions are counted except for |
| 1820 | * RI where only 0->1 is counted. |
| 1821 | */ |
| 1822 | |
| 1823 | static int mxser_get_icount(struct tty_struct *tty, |
| 1824 | struct serial_icounter_struct *icount) |
| 1825 | |
| 1826 | { |
| 1827 | struct mxser_port *info = tty->driver_data; |
| 1828 | struct async_icount cnow; |
| 1829 | unsigned long flags; |
| 1830 | |
| 1831 | spin_lock_irqsave(&info->slock, flags); |
| 1832 | cnow = info->icount; |
| 1833 | spin_unlock_irqrestore(&info->slock, flags); |
| 1834 | |
| 1835 | icount->frame = cnow.frame; |
| 1836 | icount->brk = cnow.brk; |
| 1837 | icount->overrun = cnow.overrun; |
| 1838 | icount->buf_overrun = cnow.buf_overrun; |
| 1839 | icount->parity = cnow.parity; |
| 1840 | icount->rx = cnow.rx; |
| 1841 | icount->tx = cnow.tx; |
| 1842 | icount->cts = cnow.cts; |
| 1843 | icount->dsr = cnow.dsr; |
| 1844 | icount->rng = cnow.rng; |
| 1845 | icount->dcd = cnow.dcd; |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | static void mxser_stoprx(struct tty_struct *tty) |
| 1850 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1851 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
| 1853 | info->ldisc_stop_rx = 1; |
| 1854 | if (I_IXOFF(tty)) { |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1855 | if (info->board->must_hwid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | info->IER &= ~MOXA_MUST_RECV_ISR; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1857 | outb(info->IER, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | info->x_char = STOP_CHAR(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1860 | outb(0, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | info->IER |= UART_IER_THRI; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1862 | outb(info->IER, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | |
Peter Hurley | 9db276f | 2016-01-10 20:36:15 -0800 | [diff] [blame] | 1866 | if (C_CRTSCTS(tty)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1867 | info->MCR &= ~UART_MCR_RTS; |
| 1868 | outb(info->MCR, info->ioaddr + UART_MCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | /* |
| 1873 | * This routine is called by the upper-layer tty layer to signal that |
| 1874 | * incoming characters should be throttled. |
| 1875 | */ |
| 1876 | static void mxser_throttle(struct tty_struct *tty) |
| 1877 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | mxser_stoprx(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | static void mxser_unthrottle(struct tty_struct *tty) |
| 1882 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1883 | struct mxser_port *info = tty->driver_data; |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 1884 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1885 | /* startrx */ |
| 1886 | info->ldisc_stop_rx = 0; |
| 1887 | if (I_IXOFF(tty)) { |
| 1888 | if (info->x_char) |
| 1889 | info->x_char = 0; |
| 1890 | else { |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1891 | if (info->board->must_hwid) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1892 | info->IER |= MOXA_MUST_RECV_ISR; |
| 1893 | outb(info->IER, info->ioaddr + UART_IER); |
| 1894 | } else { |
| 1895 | info->x_char = START_CHAR(tty); |
| 1896 | outb(0, info->ioaddr + UART_IER); |
| 1897 | info->IER |= UART_IER_THRI; |
| 1898 | outb(info->IER, info->ioaddr + UART_IER); |
| 1899 | } |
| 1900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Peter Hurley | 9db276f | 2016-01-10 20:36:15 -0800 | [diff] [blame] | 1903 | if (C_CRTSCTS(tty)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1904 | info->MCR |= UART_MCR_RTS; |
| 1905 | outb(info->MCR, info->ioaddr + UART_MCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | /* |
| 1910 | * mxser_stop() and mxser_start() |
| 1911 | * |
Jiri Slaby | 6e94dbc | 2021-05-05 11:19:05 +0200 | [diff] [blame] | 1912 | * This routines are called before setting or resetting tty->flow.stopped. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | * They enable or disable transmitter interrupts, as necessary. |
| 1914 | */ |
| 1915 | static void mxser_stop(struct tty_struct *tty) |
| 1916 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1917 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | unsigned long flags; |
| 1919 | |
| 1920 | spin_lock_irqsave(&info->slock, flags); |
| 1921 | if (info->IER & UART_IER_THRI) { |
| 1922 | info->IER &= ~UART_IER_THRI; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1923 | outb(info->IER, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | } |
| 1925 | spin_unlock_irqrestore(&info->slock, flags); |
| 1926 | } |
| 1927 | |
| 1928 | static void mxser_start(struct tty_struct *tty) |
| 1929 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1930 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | unsigned long flags; |
| 1932 | |
| 1933 | spin_lock_irqsave(&info->slock, flags); |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 1934 | if (info->xmit_cnt && info->port.xmit_buf) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1935 | outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | info->IER |= UART_IER_THRI; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1937 | outb(info->IER, info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | } |
| 1939 | spin_unlock_irqrestore(&info->slock, flags); |
| 1940 | } |
| 1941 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1942 | static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios) |
| 1943 | { |
| 1944 | struct mxser_port *info = tty->driver_data; |
| 1945 | unsigned long flags; |
| 1946 | |
| 1947 | spin_lock_irqsave(&info->slock, flags); |
Jiri Slaby | 2799707 | 2017-09-12 12:39:55 +0200 | [diff] [blame] | 1948 | mxser_change_speed(tty); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1949 | spin_unlock_irqrestore(&info->slock, flags); |
| 1950 | |
Peter Hurley | 9db276f | 2016-01-10 20:36:15 -0800 | [diff] [blame] | 1951 | if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1952 | tty->hw_stopped = 0; |
| 1953 | mxser_start(tty); |
| 1954 | } |
| 1955 | |
| 1956 | /* Handle sw stopped */ |
Peter Hurley | 9db276f | 2016-01-10 20:36:15 -0800 | [diff] [blame] | 1957 | if ((old_termios->c_iflag & IXON) && !I_IXON(tty)) { |
Jiri Slaby | 6e94dbc | 2021-05-05 11:19:05 +0200 | [diff] [blame] | 1958 | tty->flow.stopped = 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1959 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 1960 | if (info->board->must_hwid) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1961 | spin_lock_irqsave(&info->slock, flags); |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 1962 | mxser_disable_must_rx_software_flow_control( |
| 1963 | info->ioaddr); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1964 | spin_unlock_irqrestore(&info->slock, flags); |
| 1965 | } |
| 1966 | |
| 1967 | mxser_start(tty); |
| 1968 | } |
| 1969 | } |
| 1970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | /* |
| 1972 | * mxser_wait_until_sent() --- wait until the transmitter is empty |
| 1973 | */ |
| 1974 | static void mxser_wait_until_sent(struct tty_struct *tty, int timeout) |
| 1975 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 1976 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | unsigned long orig_jiffies, char_time; |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 1978 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | int lsr; |
| 1980 | |
| 1981 | if (info->type == PORT_UNKNOWN) |
| 1982 | return; |
| 1983 | |
| 1984 | if (info->xmit_fifo_size == 0) |
| 1985 | return; /* Just in case.... */ |
| 1986 | |
| 1987 | orig_jiffies = jiffies; |
| 1988 | /* |
| 1989 | * Set the check interval to be 1/5 of the estimated time to |
| 1990 | * send a single character, and make it at least 1. The check |
| 1991 | * interval should also be less than the timeout. |
| 1992 | * |
| 1993 | * Note: we have to use pretty tight timings here to satisfy |
| 1994 | * the NIST-PCTS. |
| 1995 | */ |
| 1996 | char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size; |
| 1997 | char_time = char_time / 5; |
| 1998 | if (char_time == 0) |
| 1999 | char_time = 1; |
| 2000 | if (timeout && timeout < char_time) |
| 2001 | char_time = timeout; |
| 2002 | /* |
| 2003 | * If the transmitter hasn't cleared in twice the approximate |
| 2004 | * amount of time to send the entire FIFO, it probably won't |
| 2005 | * ever clear. This assumes the UART isn't doing flow |
| 2006 | * control, which is currently the case. Hence, if it ever |
| 2007 | * takes longer than info->timeout, this is probably due to a |
| 2008 | * UART bug of some kind. So, we clamp the timeout parameter at |
| 2009 | * 2*info->timeout. |
| 2010 | */ |
| 2011 | if (!timeout || timeout > 2 * info->timeout) |
| 2012 | timeout = 2 * info->timeout; |
Jiri Slaby | 8bab534 | 2011-07-14 14:35:15 +0200 | [diff] [blame] | 2013 | |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 2014 | spin_lock_irqsave(&info->slock, flags); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2015 | while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) { |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 2016 | spin_unlock_irqrestore(&info->slock, flags); |
Nishanth Aravamudan | da4cd8d | 2005-09-10 00:27:30 -0700 | [diff] [blame] | 2017 | schedule_timeout_interruptible(char_time); |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 2018 | spin_lock_irqsave(&info->slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | if (signal_pending(current)) |
| 2020 | break; |
| 2021 | if (timeout && time_after(jiffies, orig_jiffies + timeout)) |
| 2022 | break; |
| 2023 | } |
Alan Cox | 07f86c0 | 2009-11-30 13:17:41 +0000 | [diff] [blame] | 2024 | spin_unlock_irqrestore(&info->slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | /* |
| 2029 | * This routine is called by tty_hangup() when a hangup is signaled. |
| 2030 | */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2031 | static void mxser_hangup(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2033 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
| 2035 | mxser_flush_buffer(tty); |
Alan Cox | 3b6826b | 2009-01-02 13:45:58 +0000 | [diff] [blame] | 2036 | tty_port_hangup(&info->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | /* |
| 2040 | * mxser_rs_break() --- routine which turns the break handling on or off |
| 2041 | */ |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 2042 | static int mxser_rs_break(struct tty_struct *tty, int break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2044 | struct mxser_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | unsigned long flags; |
| 2046 | |
| 2047 | spin_lock_irqsave(&info->slock, flags); |
| 2048 | if (break_state == -1) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2049 | outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC, |
| 2050 | info->ioaddr + UART_LCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | else |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2052 | outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC, |
| 2053 | info->ioaddr + UART_LCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | spin_unlock_irqrestore(&info->slock, flags); |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 2055 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
Jiri Slaby | e5ce1bc | 2021-06-18 08:14:21 +0200 | [diff] [blame^] | 2058 | static bool mxser_receive_chars_new(struct tty_struct *tty, |
| 2059 | struct mxser_port *port, u8 status, int *cnt) |
| 2060 | { |
| 2061 | enum mxser_must_hwid hwid = port->board->must_hwid; |
| 2062 | u8 gdl; |
| 2063 | |
| 2064 | if (hwid == MOXA_OTHER_UART) |
| 2065 | return false; |
| 2066 | if (status & UART_LSR_SPECIAL) |
| 2067 | return false; |
| 2068 | if (hwid == MOXA_MUST_MU860_HWID && (status & MOXA_MUST_LSR_RERR)) |
| 2069 | return false; |
| 2070 | if (status & MOXA_MUST_LSR_RERR) |
| 2071 | return false; |
| 2072 | |
| 2073 | gdl = inb(port->ioaddr + MOXA_MUST_GDL_REGISTER); |
| 2074 | if (hwid == MOXA_MUST_MU150_HWID) |
| 2075 | gdl &= MOXA_MUST_GDL_MASK; |
| 2076 | |
| 2077 | if (gdl >= tty->receive_room && !port->ldisc_stop_rx) |
| 2078 | mxser_stoprx(tty); |
| 2079 | |
| 2080 | while (gdl--) { |
| 2081 | u8 ch = inb(port->ioaddr + UART_RX); |
| 2082 | tty_insert_flip_char(&port->port, ch, 0); |
| 2083 | (*cnt)++; |
| 2084 | } |
| 2085 | |
| 2086 | return true; |
| 2087 | } |
| 2088 | |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2089 | static u8 mxser_receive_chars(struct tty_struct *tty, |
| 2090 | struct mxser_port *port, u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | { |
Jiri Slaby | e5ce1bc | 2021-06-18 08:14:21 +0200 | [diff] [blame^] | 2092 | unsigned char ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | int ignored = 0; |
| 2094 | int cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | int recv_room; |
| 2096 | int max = 256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2098 | recv_room = tty->receive_room; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 2099 | if (recv_room == 0 && !port->ldisc_stop_rx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | mxser_stoprx(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | |
Jiri Slaby | e5ce1bc | 2021-06-18 08:14:21 +0200 | [diff] [blame^] | 2102 | if (mxser_receive_chars_new(tty, port, status, &cnt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | goto end_intr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
| 2105 | do { |
| 2106 | if (max-- < 0) |
| 2107 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2109 | ch = inb(port->ioaddr + UART_RX); |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2110 | if (port->board->must_hwid && (status & UART_LSR_OE)) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2111 | outb(0x23, port->ioaddr + UART_FCR); |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2112 | status &= port->read_status_mask; |
| 2113 | if (status & port->ignore_status_mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | if (++ignored > 100) |
| 2115 | break; |
| 2116 | } else { |
Denis Vlasenko | 3399ba5 | 2005-06-06 13:35:55 -0700 | [diff] [blame] | 2117 | char flag = 0; |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2118 | if (status & UART_LSR_SPECIAL) { |
| 2119 | if (status & UART_LSR_BI) { |
Denis Vlasenko | 3399ba5 | 2005-06-06 13:35:55 -0700 | [diff] [blame] | 2120 | flag = TTY_BREAK; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2121 | port->icount.brk++; |
| 2122 | |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 2123 | if (port->port.flags & ASYNC_SAK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | do_SAK(tty); |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2125 | } else if (status & UART_LSR_PE) { |
Denis Vlasenko | 3399ba5 | 2005-06-06 13:35:55 -0700 | [diff] [blame] | 2126 | flag = TTY_PARITY; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2127 | port->icount.parity++; |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2128 | } else if (status & UART_LSR_FE) { |
Denis Vlasenko | 3399ba5 | 2005-06-06 13:35:55 -0700 | [diff] [blame] | 2129 | flag = TTY_FRAME; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2130 | port->icount.frame++; |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2131 | } else if (status & UART_LSR_OE) { |
Denis Vlasenko | 3399ba5 | 2005-06-06 13:35:55 -0700 | [diff] [blame] | 2132 | flag = TTY_OVERRUN; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2133 | port->icount.overrun++; |
| 2134 | } else |
| 2135 | flag = TTY_BREAK; |
Denis Vlasenko | 3399ba5 | 2005-06-06 13:35:55 -0700 | [diff] [blame] | 2136 | } |
Jiri Slaby | 92a19f9 | 2013-01-03 15:53:03 +0100 | [diff] [blame] | 2137 | tty_insert_flip_char(&port->port, ch, flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | cnt++; |
| 2139 | if (cnt >= recv_room) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2140 | if (!port->ldisc_stop_rx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | mxser_stoprx(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | break; |
| 2143 | } |
| 2144 | |
| 2145 | } |
| 2146 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 2147 | if (port->board->must_hwid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2150 | status = inb(port->ioaddr + UART_LSR); |
| 2151 | } while (status & UART_LSR_DR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2153 | end_intr: |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 2154 | mxvar_log.rxcnt[tty->index] += cnt; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2155 | port->mon_data.rxcnt += cnt; |
| 2156 | port->mon_data.up_rxcnt += cnt; |
Denis Vlasenko | 3399ba5 | 2005-06-06 13:35:55 -0700 | [diff] [blame] | 2157 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 2158 | tty_flip_buffer_push(&port->port); |
Jiri Slaby | 1551780 | 2021-06-18 08:14:18 +0200 | [diff] [blame] | 2159 | |
| 2160 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 2163 | static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | { |
| 2165 | int count, cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2167 | if (port->x_char) { |
| 2168 | outb(port->x_char, port->ioaddr + UART_TX); |
| 2169 | port->x_char = 0; |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 2170 | mxvar_log.txcnt[tty->index]++; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2171 | port->mon_data.txcnt++; |
| 2172 | port->mon_data.up_txcnt++; |
| 2173 | port->icount.tx++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | return; |
| 2175 | } |
| 2176 | |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 2177 | if (port->port.xmit_buf == NULL) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2178 | return; |
| 2179 | |
Jiri Slaby | 6e94dbc | 2021-05-05 11:19:05 +0200 | [diff] [blame] | 2180 | if (port->xmit_cnt <= 0 || tty->flow.stopped || |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 2181 | (tty->hw_stopped && |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2182 | (port->type != PORT_16550A) && |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 2183 | (!port->board->must_hwid))) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2184 | port->IER &= ~UART_IER_THRI; |
| 2185 | outb(port->IER, port->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | return; |
| 2187 | } |
| 2188 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2189 | cnt = port->xmit_cnt; |
| 2190 | count = port->xmit_fifo_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | do { |
Alan Cox | 0ad9e7d | 2008-07-16 21:56:10 +0100 | [diff] [blame] | 2192 | outb(port->port.xmit_buf[port->xmit_tail++], |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2193 | port->ioaddr + UART_TX); |
| 2194 | port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE - 1); |
| 2195 | if (--port->xmit_cnt <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | break; |
| 2197 | } while (--count > 0); |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 2198 | mxvar_log.txcnt[tty->index] += (cnt - port->xmit_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2200 | port->mon_data.txcnt += (cnt - port->xmit_cnt); |
| 2201 | port->mon_data.up_txcnt += (cnt - port->xmit_cnt); |
| 2202 | port->icount.tx += (cnt - port->xmit_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | |
Kulikov Vasiliy | 464eb8f | 2010-07-23 20:34:53 +0400 | [diff] [blame] | 2204 | if (port->xmit_cnt < WAKEUP_CHARS) |
Alan Cox | 216ba02 | 2008-10-13 10:40:19 +0100 | [diff] [blame] | 2205 | tty_wakeup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2207 | if (port->xmit_cnt <= 0) { |
| 2208 | port->IER &= ~UART_IER_THRI; |
| 2209 | outb(port->IER, port->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
Jiri Slaby | 9e40ea1 | 2021-06-18 08:14:19 +0200 | [diff] [blame] | 2213 | static bool mxser_port_isr(struct mxser_port *port) |
| 2214 | { |
| 2215 | struct tty_struct *tty; |
| 2216 | u8 iir, msr, status; |
| 2217 | bool error = false; |
| 2218 | |
| 2219 | iir = inb(port->ioaddr + UART_IIR); |
| 2220 | if (iir & UART_IIR_NO_INT) |
| 2221 | return true; |
| 2222 | |
| 2223 | iir &= MOXA_MUST_IIR_MASK; |
| 2224 | tty = tty_port_tty_get(&port->port); |
| 2225 | if (!tty || port->closing || !tty_port_initialized(&port->port)) { |
| 2226 | status = inb(port->ioaddr + UART_LSR); |
| 2227 | outb(0x27, port->ioaddr + UART_FCR); |
| 2228 | inb(port->ioaddr + UART_MSR); |
| 2229 | |
| 2230 | error = true; |
| 2231 | goto put_tty; |
| 2232 | } |
| 2233 | |
| 2234 | status = inb(port->ioaddr + UART_LSR); |
| 2235 | |
| 2236 | if (status & UART_LSR_PE) |
| 2237 | port->err_shadow |= NPPI_NOTIFY_PARITY; |
| 2238 | if (status & UART_LSR_FE) |
| 2239 | port->err_shadow |= NPPI_NOTIFY_FRAMING; |
| 2240 | if (status & UART_LSR_OE) |
| 2241 | port->err_shadow |= NPPI_NOTIFY_HW_OVERRUN; |
| 2242 | if (status & UART_LSR_BI) |
| 2243 | port->err_shadow |= NPPI_NOTIFY_BREAK; |
| 2244 | |
| 2245 | if (port->board->must_hwid) { |
| 2246 | if (iir == MOXA_MUST_IIR_GDA || |
| 2247 | iir == MOXA_MUST_IIR_RDA || |
| 2248 | iir == MOXA_MUST_IIR_RTO || |
| 2249 | iir == MOXA_MUST_IIR_LSR) |
| 2250 | status = mxser_receive_chars(tty, port, status); |
| 2251 | } else { |
| 2252 | status &= port->read_status_mask; |
| 2253 | if (status & UART_LSR_DR) |
| 2254 | status = mxser_receive_chars(tty, port, status); |
| 2255 | } |
| 2256 | |
| 2257 | msr = inb(port->ioaddr + UART_MSR); |
| 2258 | if (msr & UART_MSR_ANY_DELTA) |
| 2259 | mxser_check_modem_status(tty, port, msr); |
| 2260 | |
| 2261 | if (port->board->must_hwid) { |
| 2262 | if (iir == 0x02 && (status & UART_LSR_THRE)) |
| 2263 | mxser_transmit_chars(tty, port); |
| 2264 | } else { |
| 2265 | if (status & UART_LSR_THRE) |
| 2266 | mxser_transmit_chars(tty, port); |
| 2267 | } |
| 2268 | |
| 2269 | put_tty: |
| 2270 | tty_kref_put(tty); |
| 2271 | |
| 2272 | return error; |
| 2273 | } |
| 2274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | /* |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2276 | * This is the serial driver's generic interrupt routine |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2278 | static irqreturn_t mxser_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | { |
Jiri Slaby | cef222c | 2021-06-18 08:14:17 +0200 | [diff] [blame] | 2280 | struct mxser_board *brd = dev_id; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2281 | struct mxser_port *port; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2282 | unsigned int int_cnt, pass_counter = 0; |
Jiri Slaby | 9cb5c9c | 2021-06-18 08:14:20 +0200 | [diff] [blame] | 2283 | unsigned int i, max = brd->info->nports; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2284 | int handled = IRQ_NONE; |
Jiri Slaby | 9cb5c9c | 2021-06-18 08:14:20 +0200 | [diff] [blame] | 2285 | u8 irqbits, bits, mask = BIT(max) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2287 | while (pass_counter++ < MXSER_ISR_PASS_LIMIT) { |
Jiri Slaby | 9cb5c9c | 2021-06-18 08:14:20 +0200 | [diff] [blame] | 2288 | irqbits = inb(brd->vector) & mask; |
| 2289 | if (irqbits == mask) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2290 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2292 | handled = IRQ_HANDLED; |
| 2293 | for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) { |
Jiri Slaby | 9cb5c9c | 2021-06-18 08:14:20 +0200 | [diff] [blame] | 2294 | if (irqbits == mask) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2295 | break; |
| 2296 | if (bits & irqbits) |
| 2297 | continue; |
| 2298 | port = &brd->ports[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2300 | int_cnt = 0; |
| 2301 | spin_lock(&port->slock); |
| 2302 | do { |
Jiri Slaby | 9e40ea1 | 2021-06-18 08:14:19 +0200 | [diff] [blame] | 2303 | if (mxser_port_isr(port)) |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2304 | break; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2305 | } while (int_cnt++ < MXSER_ISR_PASS_LIMIT); |
| 2306 | spin_unlock(&port->slock); |
| 2307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2310 | return handled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2313 | static const struct tty_operations mxser_ops = { |
| 2314 | .open = mxser_open, |
| 2315 | .close = mxser_close, |
| 2316 | .write = mxser_write, |
| 2317 | .put_char = mxser_put_char, |
| 2318 | .flush_chars = mxser_flush_chars, |
| 2319 | .write_room = mxser_write_room, |
| 2320 | .chars_in_buffer = mxser_chars_in_buffer, |
| 2321 | .flush_buffer = mxser_flush_buffer, |
| 2322 | .ioctl = mxser_ioctl, |
| 2323 | .throttle = mxser_throttle, |
| 2324 | .unthrottle = mxser_unthrottle, |
| 2325 | .set_termios = mxser_set_termios, |
| 2326 | .stop = mxser_stop, |
| 2327 | .start = mxser_start, |
| 2328 | .hangup = mxser_hangup, |
| 2329 | .break_ctl = mxser_rs_break, |
| 2330 | .wait_until_sent = mxser_wait_until_sent, |
| 2331 | .tiocmget = mxser_tiocmget, |
| 2332 | .tiocmset = mxser_tiocmset, |
Al Viro | 6da5b58 | 2018-09-11 22:22:06 -0400 | [diff] [blame] | 2333 | .set_serial = mxser_set_serial_info, |
| 2334 | .get_serial = mxser_get_serial_info, |
Alan Cox | 0587102 | 2010-09-16 18:21:52 +0100 | [diff] [blame] | 2335 | .get_icount = mxser_get_icount, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2336 | }; |
| 2337 | |
Aya Mahfouz | 04b757d | 2015-12-15 01:53:36 +0200 | [diff] [blame] | 2338 | static const struct tty_port_operations mxser_port_ops = { |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 2339 | .carrier_raised = mxser_carrier_raised, |
Alan Cox | fcc8ac1 | 2009-06-11 12:24:17 +0100 | [diff] [blame] | 2340 | .dtr_rts = mxser_dtr_rts, |
Alan Cox | 6769140 | 2009-11-30 13:17:35 +0000 | [diff] [blame] | 2341 | .activate = mxser_activate, |
| 2342 | .shutdown = mxser_shutdown_port, |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 2343 | }; |
| 2344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | /* |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2346 | * The MOXA Smartio/Industio serial driver boot-time initialization code! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2348 | |
Jiri Slaby | 2799707 | 2017-09-12 12:39:55 +0200 | [diff] [blame] | 2349 | static int mxser_initbrd(struct mxser_board *brd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2351 | struct mxser_port *info; |
| 2352 | unsigned int i; |
| 2353 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2355 | for (i = 0; i < brd->info->nports; i++) { |
| 2356 | info = &brd->ports[i]; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2357 | tty_port_init(&info->port); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 2358 | info->port.ops = &mxser_port_ops; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2359 | info->board = brd; |
| 2360 | info->stop_rx = 0; |
| 2361 | info->ldisc_stop_rx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2363 | /* Enhance mode enabled here */ |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 2364 | if (brd->must_hwid != MOXA_OTHER_UART) |
Christoph Hellwig | 148ff86 | 2008-04-30 00:54:29 -0700 | [diff] [blame] | 2365 | mxser_enable_must_enchance_mode(info->ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
Jiri Slaby | 58a2ddb | 2021-06-18 08:14:15 +0200 | [diff] [blame] | 2367 | info->type = PORT_16550A; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2368 | |
| 2369 | process_txrx_fifo(info); |
| 2370 | |
| 2371 | info->custom_divisor = info->baud_base * 16; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2372 | info->port.close_delay = 5 * HZ / 10; |
| 2373 | info->port.closing_wait = 30 * HZ; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2374 | info->normal_termios = mxvar_sdriver->init_termios; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2375 | memset(&info->mon_data, 0, sizeof(struct mxser_mon)); |
| 2376 | info->err_shadow = 0; |
| 2377 | spin_lock_init(&info->slock); |
| 2378 | |
| 2379 | /* before set INT ISR, disable all int */ |
| 2380 | outb(inb(info->ioaddr + UART_IER) & 0xf0, |
| 2381 | info->ioaddr + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2384 | retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser", |
| 2385 | brd); |
Jiri Slaby | 191c5f1 | 2012-11-15 09:49:56 +0100 | [diff] [blame] | 2386 | if (retval) { |
| 2387 | for (i = 0; i < brd->info->nports; i++) |
| 2388 | tty_port_destroy(&brd->ports[i].port); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2389 | printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may " |
| 2390 | "conflict with another device.\n", |
| 2391 | brd->info->name, brd->irq); |
Jiri Slaby | 191c5f1 | 2012-11-15 09:49:56 +0100 | [diff] [blame] | 2392 | } |
Jiri Slaby | df48051 | 2010-09-03 10:31:37 +0200 | [diff] [blame] | 2393 | |
Jesper Juhl | 8ea2c2e | 2006-06-25 05:47:54 -0700 | [diff] [blame] | 2394 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Jiri Slaby | 191c5f1 | 2012-11-15 09:49:56 +0100 | [diff] [blame] | 2397 | static void mxser_board_remove(struct mxser_board *brd) |
| 2398 | { |
| 2399 | unsigned int i; |
| 2400 | |
| 2401 | for (i = 0; i < brd->info->nports; i++) { |
| 2402 | tty_unregister_device(mxvar_sdriver, brd->idx + i); |
| 2403 | tty_port_destroy(&brd->ports[i].port); |
| 2404 | } |
Alexey Khoroshilov | 9e17df3 | 2013-02-17 02:24:37 +0400 | [diff] [blame] | 2405 | free_irq(brd->irq, brd); |
Jiri Slaby | 191c5f1 | 2012-11-15 09:49:56 +0100 | [diff] [blame] | 2406 | } |
| 2407 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 2408 | static int mxser_probe(struct pci_dev *pdev, |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2409 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2411 | struct mxser_board *brd; |
| 2412 | unsigned int i, j; |
| 2413 | unsigned long ioaddress; |
Alexey Khoroshilov | 9e17df3 | 2013-02-17 02:24:37 +0400 | [diff] [blame] | 2414 | struct device *tty_dev; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2415 | int retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2417 | for (i = 0; i < MXSER_BOARDS; i++) |
| 2418 | if (mxser_boards[i].info == NULL) |
| 2419 | break; |
| 2420 | |
| 2421 | if (i >= MXSER_BOARDS) { |
Jiri Slaby | 83766bc | 2008-07-25 01:48:21 -0700 | [diff] [blame] | 2422 | dev_err(&pdev->dev, "too many boards found (maximum %d), board " |
| 2423 | "not configured\n", MXSER_BOARDS); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2424 | goto err; |
| 2425 | } |
| 2426 | |
| 2427 | brd = &mxser_boards[i]; |
| 2428 | brd->idx = i * MXSER_PORTS_PER_BOARD; |
Jiri Slaby | 83766bc | 2008-07-25 01:48:21 -0700 | [diff] [blame] | 2429 | dev_info(&pdev->dev, "found MOXA %s board (BusNo=%d, DevNo=%d)\n", |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2430 | mxser_cards[ent->driver_data].name, |
| 2431 | pdev->bus->number, PCI_SLOT(pdev->devfn)); |
| 2432 | |
| 2433 | retval = pci_enable_device(pdev); |
| 2434 | if (retval) { |
Jiri Slaby | 83766bc | 2008-07-25 01:48:21 -0700 | [diff] [blame] | 2435 | dev_err(&pdev->dev, "PCI enable failed\n"); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2436 | goto err; |
| 2437 | } |
| 2438 | |
| 2439 | /* io address */ |
| 2440 | ioaddress = pci_resource_start(pdev, 2); |
| 2441 | retval = pci_request_region(pdev, 2, "mxser(IO)"); |
| 2442 | if (retval) |
Jiri Slaby | df48051 | 2010-09-03 10:31:37 +0200 | [diff] [blame] | 2443 | goto err_dis; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2444 | |
| 2445 | brd->info = &mxser_cards[ent->driver_data]; |
| 2446 | for (i = 0; i < brd->info->nports; i++) |
| 2447 | brd->ports[i].ioaddr = ioaddress + 8 * i; |
| 2448 | |
| 2449 | /* vector */ |
| 2450 | ioaddress = pci_resource_start(pdev, 3); |
| 2451 | retval = pci_request_region(pdev, 3, "mxser(vector)"); |
| 2452 | if (retval) |
Jiri Slaby | df48051 | 2010-09-03 10:31:37 +0200 | [diff] [blame] | 2453 | goto err_zero; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2454 | brd->vector = ioaddress; |
| 2455 | |
| 2456 | /* irq */ |
| 2457 | brd->irq = pdev->irq; |
| 2458 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 2459 | brd->must_hwid = mxser_must_get_hwid(brd->ports[0].ioaddr); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2460 | |
Jiri Slaby | 928f946 | 2021-06-18 08:14:16 +0200 | [diff] [blame] | 2461 | for (j = 0; j < UART_INFO_NUM; j++) { |
| 2462 | if (Gpci_uart_info[j].type == brd->must_hwid) { |
| 2463 | brd->max_baud = Gpci_uart_info[j].max_baud; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2464 | |
Jiri Slaby | 928f946 | 2021-06-18 08:14:16 +0200 | [diff] [blame] | 2465 | /* exception....CP-102 */ |
| 2466 | if (brd->info->flags & MXSER_HIGHBAUD) |
| 2467 | brd->max_baud = 921600; |
| 2468 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2470 | } |
| 2471 | |
Jiri Slaby | 292955a | 2021-06-18 08:14:13 +0200 | [diff] [blame] | 2472 | if (brd->must_hwid == MOXA_MUST_MU860_HWID) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2473 | for (i = 0; i < brd->info->nports; i++) { |
| 2474 | if (i < 4) |
| 2475 | brd->ports[i].opmode_ioaddr = ioaddress + 4; |
| 2476 | else |
| 2477 | brd->ports[i].opmode_ioaddr = ioaddress + 0x0c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2479 | outb(0, ioaddress + 4); /* default set to RS232 mode */ |
| 2480 | outb(0, ioaddress + 0x0c); /* default set to RS232 mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2482 | |
| 2483 | for (i = 0; i < brd->info->nports; i++) { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2484 | brd->ports[i].baud_base = 921600; |
| 2485 | } |
| 2486 | |
| 2487 | /* mxser_initbrd will hook ISR. */ |
Jiri Slaby | 2799707 | 2017-09-12 12:39:55 +0200 | [diff] [blame] | 2488 | retval = mxser_initbrd(brd); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2489 | if (retval) |
Jiri Slaby | df48051 | 2010-09-03 10:31:37 +0200 | [diff] [blame] | 2490 | goto err_rel3; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2491 | |
Alexey Khoroshilov | 9e17df3 | 2013-02-17 02:24:37 +0400 | [diff] [blame] | 2492 | for (i = 0; i < brd->info->nports; i++) { |
| 2493 | tty_dev = tty_port_register_device(&brd->ports[i].port, |
| 2494 | mxvar_sdriver, brd->idx + i, &pdev->dev); |
| 2495 | if (IS_ERR(tty_dev)) { |
| 2496 | retval = PTR_ERR(tty_dev); |
Alexey Khoroshilov | 1b581f1 | 2013-04-07 23:46:47 +0400 | [diff] [blame] | 2497 | for (; i > 0; i--) |
Alexey Khoroshilov | 9e17df3 | 2013-02-17 02:24:37 +0400 | [diff] [blame] | 2498 | tty_unregister_device(mxvar_sdriver, |
Alexey Khoroshilov | 1b581f1 | 2013-04-07 23:46:47 +0400 | [diff] [blame] | 2499 | brd->idx + i - 1); |
Alexey Khoroshilov | 9e17df3 | 2013-02-17 02:24:37 +0400 | [diff] [blame] | 2500 | goto err_relbrd; |
| 2501 | } |
| 2502 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2503 | |
| 2504 | pci_set_drvdata(pdev, brd); |
| 2505 | |
| 2506 | return 0; |
Alexey Khoroshilov | 9e17df3 | 2013-02-17 02:24:37 +0400 | [diff] [blame] | 2507 | err_relbrd: |
| 2508 | for (i = 0; i < brd->info->nports; i++) |
| 2509 | tty_port_destroy(&brd->ports[i].port); |
| 2510 | free_irq(brd->irq, brd); |
Jiri Slaby | df48051 | 2010-09-03 10:31:37 +0200 | [diff] [blame] | 2511 | err_rel3: |
| 2512 | pci_release_region(pdev, 3); |
| 2513 | err_zero: |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2514 | brd->info = NULL; |
Jiri Slaby | df48051 | 2010-09-03 10:31:37 +0200 | [diff] [blame] | 2515 | pci_release_region(pdev, 2); |
| 2516 | err_dis: |
| 2517 | pci_disable_device(pdev); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2518 | err: |
| 2519 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 2522 | static void mxser_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2524 | struct mxser_board *brd = pci_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | |
Jiri Slaby | 191c5f1 | 2012-11-15 09:49:56 +0100 | [diff] [blame] | 2526 | mxser_board_remove(brd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | |
Jiri Slaby | df48051 | 2010-09-03 10:31:37 +0200 | [diff] [blame] | 2528 | pci_release_region(pdev, 2); |
| 2529 | pci_release_region(pdev, 3); |
| 2530 | pci_disable_device(pdev); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2531 | brd->info = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2534 | static struct pci_driver mxser_driver = { |
| 2535 | .name = "mxser", |
| 2536 | .id_table = mxser_pcibrds, |
| 2537 | .probe = mxser_probe, |
Bill Pemberton | 91116cb | 2012-11-19 13:21:06 -0500 | [diff] [blame] | 2538 | .remove = mxser_remove |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2539 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2541 | static int __init mxser_module_init(void) |
| 2542 | { |
Jiri Slaby | 1df0092 | 2008-07-25 01:48:22 -0700 | [diff] [blame] | 2543 | int retval; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2544 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2545 | mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1); |
| 2546 | if (!mxvar_sdriver) |
| 2547 | return -ENOMEM; |
| 2548 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2549 | /* Initialize the tty_driver structure */ |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2550 | mxvar_sdriver->name = "ttyMI"; |
| 2551 | mxvar_sdriver->major = ttymajor; |
| 2552 | mxvar_sdriver->minor_start = 0; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2553 | mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL; |
| 2554 | mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL; |
| 2555 | mxvar_sdriver->init_termios = tty_std_termios; |
| 2556 | mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL; |
| 2557 | mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV; |
| 2558 | tty_set_operations(mxvar_sdriver, &mxser_ops); |
| 2559 | |
| 2560 | retval = tty_register_driver(mxvar_sdriver); |
| 2561 | if (retval) { |
| 2562 | printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family " |
| 2563 | "tty driver !\n"); |
| 2564 | goto err_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | } |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2566 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2567 | retval = pci_register_driver(&mxser_driver); |
| 2568 | if (retval) { |
Jiri Slaby | 83766bc | 2008-07-25 01:48:21 -0700 | [diff] [blame] | 2569 | printk(KERN_ERR "mxser: can't register pci driver\n"); |
Jiri Slaby | 2913436 | 2021-06-18 08:14:07 +0200 | [diff] [blame] | 2570 | goto err_unr; |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2571 | } |
| 2572 | |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2573 | return 0; |
| 2574 | err_unr: |
| 2575 | tty_unregister_driver(mxvar_sdriver); |
| 2576 | err_put: |
| 2577 | put_tty_driver(mxvar_sdriver); |
| 2578 | return retval; |
| 2579 | } |
| 2580 | |
| 2581 | static void __exit mxser_module_exit(void) |
| 2582 | { |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2583 | pci_unregister_driver(&mxser_driver); |
Jiri Slaby | 1c45607 | 2008-02-07 00:16:46 -0800 | [diff] [blame] | 2584 | tty_unregister_driver(mxvar_sdriver); |
| 2585 | put_tty_driver(mxvar_sdriver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | module_init(mxser_module_init); |
| 2589 | module_exit(mxser_module_exit); |