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