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