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