Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Original driver code supplied by Multi-Tech |
| 4 | * |
| 5 | * Changes |
Alan Cox | 8eb04cf | 2008-11-11 14:48:44 +0000 | [diff] [blame] | 6 | * 1/9/98 alan@lxorguk.ukuu.org.uk |
| 7 | * Merge to 2.0.x kernel tree |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Obtain and use official major/minors |
| 9 | * Loader switched to a misc device |
| 10 | * (fixed range check bug as a side effect) |
| 11 | * Printk clean up |
Alan Cox | 8eb04cf | 2008-11-11 14:48:44 +0000 | [diff] [blame] | 12 | * 9/12/98 alan@lxorguk.ukuu.org.uk |
| 13 | * Rough port to 2.1.x |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
| 15 | * 10/6/99 sameer Merged the ISA and PCI drivers to |
| 16 | * a new unified driver. |
| 17 | * |
| 18 | * 3/9/99 sameer Added support for ISI4616 cards. |
| 19 | * |
| 20 | * 16/9/99 sameer We do not force RTS low anymore. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 21 | * This is to prevent the firmware |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * from getting confused. |
| 23 | * |
| 24 | * 26/10/99 sameer Cosmetic changes:The driver now |
| 25 | * dumps the Port Count information |
| 26 | * along with I/O address and IRQ. |
| 27 | * |
| 28 | * 13/12/99 sameer Fixed the problem with IRQ sharing. |
| 29 | * |
| 30 | * 10/5/00 sameer Fixed isicom_shutdown_board() |
| 31 | * to not lower DTR on all the ports |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 32 | * when the last port on the card is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * closed. |
| 34 | * |
| 35 | * 10/5/00 sameer Signal mask setup command added |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 36 | * to isicom_setup_port and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * isicom_shutdown_port. |
| 38 | * |
| 39 | * 24/5/00 sameer The driver is now SMP aware. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 40 | * |
| 41 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * 27/11/00 Vinayak P Risbud Fixed the Driver Crash Problem |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 43 | * |
| 44 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | * 03/01/01 anil .s Added support for resetting the |
| 46 | * internal modems on ISI cards. |
| 47 | * |
| 48 | * 08/02/01 anil .s Upgraded the driver for kernel |
| 49 | * 2.4.x |
| 50 | * |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 51 | * 11/04/01 Kevin Fixed firmware load problem with |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * ISIHP-4X card |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 53 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * 30/04/01 anil .s Fixed the remote login through |
| 55 | * ISI port problem. Now the link |
| 56 | * does not go down before password |
| 57 | * prompt. |
| 58 | * |
| 59 | * 03/05/01 anil .s Fixed the problem with IRQ sharing |
| 60 | * among ISI-PCI cards. |
| 61 | * |
| 62 | * 03/05/01 anil .s Added support to display the version |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 63 | * info during insmod as well as module |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * listing by lsmod. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 65 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * 10/05/01 anil .s Done the modifications to the source |
| 67 | * file and Install script so that the |
| 68 | * same installation can be used for |
| 69 | * 2.2.x and 2.4.x kernel. |
| 70 | * |
| 71 | * 06/06/01 anil .s Now we drop both dtr and rts during |
| 72 | * shutdown_port as well as raise them |
| 73 | * during isicom_config_port. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 74 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * 09/06/01 acme@conectiva.com.br use capable, not suser, do |
| 76 | * restore_flags on failure in |
| 77 | * isicom_send_break, verify put_user |
| 78 | * result |
| 79 | * |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 80 | * 11/02/03 ranjeeth Added support for 230 Kbps and 460 Kbps |
| 81 | * Baud index extended to 21 |
| 82 | * |
| 83 | * 20/03/03 ranjeeth Made to work for Linux Advanced server. |
| 84 | * Taken care of license warning. |
| 85 | * |
| 86 | * 10/12/03 Ravindra Made to work for Fedora Core 1 of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | * Red Hat Distribution |
| 88 | * |
| 89 | * 06/01/05 Alan Cox Merged the ISI and base kernel strands |
| 90 | * into a single 2.6 driver |
| 91 | * |
| 92 | * *********************************************************** |
| 93 | * |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 94 | * To use this driver you also need the support package. You |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | * can find this in RPM format on |
| 96 | * ftp://ftp.linux.org.uk/pub/linux/alan |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 97 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * You can find the original tools for this direct from Multitech |
| 99 | * ftp://ftp.multitech.com/ISI-Cards/ |
| 100 | * |
Lucas De Marchi | 970e248 | 2012-03-30 13:37:16 -0700 | [diff] [blame] | 101 | * Having installed the cards the module options (/etc/modprobe.d/) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | * |
| 103 | * options isicom io=card1,card2,card3,card4 irq=card1,card2,card3,card4 |
| 104 | * |
| 105 | * Omit those entries for boards you don't have installed. |
| 106 | * |
| 107 | * TODO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * Merge testing |
| 109 | * 64-bit verification |
| 110 | */ |
| 111 | |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 112 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #include <linux/module.h> |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 115 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #include <linux/kernel.h> |
| 117 | #include <linux/tty.h> |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 118 | #include <linux/tty_flip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | #include <linux/termios.h> |
| 120 | #include <linux/fs.h> |
| 121 | #include <linux/sched.h> |
| 122 | #include <linux/serial.h> |
| 123 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #include <linux/interrupt.h> |
| 125 | #include <linux/timer.h> |
| 126 | #include <linux/delay.h> |
| 127 | #include <linux/ioport.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 128 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 130 | #include <linux/uaccess.h> |
| 131 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | #include <linux/pci.h> |
| 134 | |
| 135 | #include <linux/isicom.h> |
| 136 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 137 | #define InterruptTheCard(base) outw(0, (base) + 0xc) |
| 138 | #define ClearInterrupt(base) inw((base) + 0x0a) |
| 139 | |
| 140 | #ifdef DEBUG |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 141 | #define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c)) |
| 142 | #else |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 143 | #define isicom_paranoia_check(a, b, c) 0 |
| 144 | #endif |
| 145 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 146 | static int isicom_probe(struct pci_dev *, const struct pci_device_id *); |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 147 | static void isicom_remove(struct pci_dev *); |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 148 | |
Arvind Yadav | 763653d | 2017-07-23 15:31:02 +0530 | [diff] [blame] | 149 | static const struct pci_device_id isicom_pci_tbl[] = { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 150 | { PCI_DEVICE(VENDOR_ID, 0x2028) }, |
| 151 | { PCI_DEVICE(VENDOR_ID, 0x2051) }, |
| 152 | { PCI_DEVICE(VENDOR_ID, 0x2052) }, |
| 153 | { PCI_DEVICE(VENDOR_ID, 0x2053) }, |
| 154 | { PCI_DEVICE(VENDOR_ID, 0x2054) }, |
| 155 | { PCI_DEVICE(VENDOR_ID, 0x2055) }, |
| 156 | { PCI_DEVICE(VENDOR_ID, 0x2056) }, |
| 157 | { PCI_DEVICE(VENDOR_ID, 0x2057) }, |
| 158 | { PCI_DEVICE(VENDOR_ID, 0x2058) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { 0 } |
| 160 | }; |
| 161 | MODULE_DEVICE_TABLE(pci, isicom_pci_tbl); |
| 162 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 163 | static struct pci_driver isicom_driver = { |
| 164 | .name = "isicom", |
| 165 | .id_table = isicom_pci_tbl, |
| 166 | .probe = isicom_probe, |
Bill Pemberton | 91116cb | 2012-11-19 13:21:06 -0500 | [diff] [blame] | 167 | .remove = isicom_remove |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 168 | }; |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | static int prev_card = 3; /* start servicing isi_card[0] */ |
| 171 | static struct tty_driver *isicom_normal; |
| 172 | |
Kees Cook | 24ed960 | 2017-08-28 11:28:21 -0700 | [diff] [blame] | 173 | static void isicom_tx(struct timer_list *unused); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 174 | static void isicom_start(struct tty_struct *tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Kees Cook | 1d27e3e | 2017-10-04 16:27:04 -0700 | [diff] [blame] | 176 | static DEFINE_TIMER(tx, isicom_tx); |
Jiri Slaby | 34b55b8 | 2006-12-08 02:38:55 -0800 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* baud index mappings from linux defns to isi */ |
| 179 | |
| 180 | static signed char linuxb_to_isib[] = { |
Jiri Slaby | 7edc136 | 2007-02-10 01:44:54 -0800 | [diff] [blame] | 181 | -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19, 20, 21 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | struct isi_board { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 185 | unsigned long base; |
Jiri Slaby | 4969b3a | 2007-07-17 04:05:18 -0700 | [diff] [blame] | 186 | int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | unsigned char port_count; |
| 188 | unsigned short status; |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 189 | unsigned short port_status; /* each bit for each port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | unsigned short shift_count; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 191 | struct isi_port *ports; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | signed char count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */ |
| 194 | unsigned long flags; |
Jiri Slaby | 938a702 | 2006-12-08 02:38:52 -0800 | [diff] [blame] | 195 | unsigned int index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | struct isi_port { |
| 199 | unsigned short magic; |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 200 | struct tty_port port; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 201 | u16 channel; |
| 202 | u16 status; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 203 | struct isi_board *card; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 204 | unsigned char *xmit_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | int xmit_head; |
| 206 | int xmit_tail; |
| 207 | int xmit_cnt; |
| 208 | }; |
| 209 | |
| 210 | static struct isi_board isi_card[BOARD_COUNT]; |
| 211 | static struct isi_port isi_ports[PORT_COUNT]; |
| 212 | |
| 213 | /* |
| 214 | * Locking functions for card level locking. We need to own both |
| 215 | * the kernel lock for the card and have the card in a position that |
| 216 | * it wants to talk. |
| 217 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 218 | |
Denys Vlasenko | 810e20e | 2015-10-27 17:39:58 +0100 | [diff] [blame] | 219 | static int WaitTillCardIsFree(unsigned long base) |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 220 | { |
| 221 | unsigned int count = 0; |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 222 | |
| 223 | while (!(inw(base + 0xe) & 0x1) && count++ < 100) |
Jia-Ju Bai | fe8e7ac | 2017-12-12 21:24:56 +0800 | [diff] [blame] | 224 | mdelay(1); |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 225 | |
| 226 | return !(inw(base + 0xe) & 0x1); |
| 227 | } |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | static int lock_card(struct isi_board *card) |
| 230 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 231 | unsigned long base = card->base; |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 232 | unsigned int retries, a; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 234 | for (retries = 0; retries < 10; retries++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | spin_lock_irqsave(&card->card_lock, card->flags); |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 236 | for (a = 0; a < 10; a++) { |
| 237 | if (inw(base + 0xe) & 0x1) |
| 238 | return 1; |
| 239 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 241 | spin_unlock_irqrestore(&card->card_lock, card->flags); |
| 242 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
Joe Perches | e620e54 | 2014-11-09 22:46:35 -0800 | [diff] [blame] | 244 | pr_warn("Failed to lock Card (0x%lx)\n", card->base); |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 245 | |
Adrian Bunk | 0418726 | 2006-06-30 18:23:04 +0200 | [diff] [blame] | 246 | return 0; /* Failed to acquire the card! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | static void unlock_card(struct isi_board *card) |
| 250 | { |
| 251 | spin_unlock_irqrestore(&card->card_lock, card->flags); |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * ISI Card specific ops ... |
| 256 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 257 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 258 | /* card->lock HAS to be held */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 259 | static void raise_dtr(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 261 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 262 | unsigned long base = card->base; |
| 263 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 265 | if (WaitTillCardIsFree(base)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | return; |
| 267 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 268 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | outw(0x0504, base); |
| 270 | InterruptTheCard(base); |
| 271 | port->status |= ISI_DTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 274 | /* card->lock HAS to be held */ |
Denys Vlasenko | 9428d71 | 2015-10-27 18:46:34 +0100 | [diff] [blame] | 275 | static void drop_dtr(struct isi_port *port) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 276 | { |
| 277 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 278 | unsigned long base = card->base; |
| 279 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 281 | if (WaitTillCardIsFree(base)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | return; |
| 283 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 284 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | outw(0x0404, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 286 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | port->status &= ~ISI_DTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 290 | /* card->lock HAS to be held */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 291 | static inline void raise_rts(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 293 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 294 | unsigned long base = card->base; |
| 295 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 297 | if (WaitTillCardIsFree(base)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return; |
| 299 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 300 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | outw(0x0a04, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 302 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | port->status |= ISI_RTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 305 | |
| 306 | /* card->lock HAS to be held */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 307 | static inline void drop_rts(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 309 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 310 | unsigned long base = card->base; |
| 311 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 313 | if (WaitTillCardIsFree(base)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | return; |
| 315 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 316 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | outw(0x0804, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 318 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | port->status &= ~ISI_RTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 322 | /* card->lock MUST NOT be held */ |
Alan Cox | 5d951fb | 2009-01-02 13:45:19 +0000 | [diff] [blame] | 323 | |
Alan Cox | fcc8ac1 | 2009-06-11 12:24:17 +0100 | [diff] [blame] | 324 | static void isicom_dtr_rts(struct tty_port *port, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
Alan Cox | 5d951fb | 2009-01-02 13:45:19 +0000 | [diff] [blame] | 326 | struct isi_port *ip = container_of(port, struct isi_port, port); |
| 327 | struct isi_board *card = ip->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 328 | unsigned long base = card->base; |
Alan Cox | 5d951fb | 2009-01-02 13:45:19 +0000 | [diff] [blame] | 329 | u16 channel = ip->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | if (!lock_card(card)) |
| 332 | return; |
| 333 | |
Alan Cox | fcc8ac1 | 2009-06-11 12:24:17 +0100 | [diff] [blame] | 334 | if (on) { |
| 335 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
| 336 | outw(0x0f04, base); |
| 337 | InterruptTheCard(base); |
| 338 | ip->status |= (ISI_DTR | ISI_RTS); |
| 339 | } else { |
| 340 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
| 341 | outw(0x0C04, base); |
| 342 | InterruptTheCard(base); |
| 343 | ip->status &= ~(ISI_DTR | ISI_RTS); |
| 344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | unlock_card(card); |
| 346 | } |
| 347 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 348 | /* card->lock HAS to be held */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 349 | static void drop_dtr_rts(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 351 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 352 | unsigned long base = card->base; |
| 353 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 355 | if (WaitTillCardIsFree(base)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return; |
| 357 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 358 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | outw(0x0c04, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 360 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | port->status &= ~(ISI_RTS | ISI_DTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | /* |
| 365 | * ISICOM Driver specific routines ... |
| 366 | * |
| 367 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 368 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 369 | static inline int __isicom_paranoia_check(struct isi_port const *port, |
| 370 | char *name, const char *routine) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | if (!port) { |
Joe Perches | e620e54 | 2014-11-09 22:46:35 -0800 | [diff] [blame] | 373 | pr_warn("Warning: bad isicom magic for dev %s in %s\n", |
| 374 | name, routine); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return 1; |
| 376 | } |
| 377 | if (port->magic != ISICOM_MAGIC) { |
Joe Perches | e620e54 | 2014-11-09 22:46:35 -0800 | [diff] [blame] | 378 | pr_warn("Warning: NULL isicom port for dev %s in %s\n", |
| 379 | name, routine); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | return 1; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 381 | } |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return 0; |
| 384 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /* |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 387 | * Transmitter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | * |
| 389 | * We shovel data into the card buffers on a regular basis. The card |
| 390 | * will do the rest of the work for us. |
| 391 | */ |
| 392 | |
Kees Cook | 24ed960 | 2017-08-28 11:28:21 -0700 | [diff] [blame] | 393 | static void isicom_tx(struct timer_list *unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
Jiri Slaby | 4969b3a | 2007-07-17 04:05:18 -0700 | [diff] [blame] | 395 | unsigned long flags, base; |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 396 | unsigned int retries; |
Jiri Slaby | 4969b3a | 2007-07-17 04:05:18 -0700 | [diff] [blame] | 397 | short count = (BOARD_COUNT-1), card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | short txcount, wrd, residue, word_count, cnt; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 399 | struct isi_port *port; |
| 400 | struct tty_struct *tty; |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | /* find next active board */ |
| 403 | card = (prev_card + 1) & 0x0003; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 404 | while (count-- > 0) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 405 | if (isi_card[card].status & BOARD_ACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | break; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 407 | card = (card + 1) & 0x0003; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | if (!(isi_card[card].status & BOARD_ACTIVE)) |
| 410 | goto sched_again; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | prev_card = card; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | count = isi_card[card].port_count; |
| 415 | port = isi_card[card].ports; |
| 416 | base = isi_card[card].base; |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 417 | |
| 418 | spin_lock_irqsave(&isi_card[card].card_lock, flags); |
| 419 | for (retries = 0; retries < 100; retries++) { |
| 420 | if (inw(base + 0xe) & 0x1) |
| 421 | break; |
| 422 | udelay(2); |
| 423 | } |
| 424 | if (retries >= 100) |
| 425 | goto unlock; |
| 426 | |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 427 | tty = tty_port_tty_get(&port->port); |
| 428 | if (tty == NULL) |
| 429 | goto put_unlock; |
| 430 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 431 | for (; count > 0; count--, port++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* port not active or tx disabled to force flow control */ |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 433 | if (!tty_port_initialized(&port->port) || |
| 434 | !(port->status & ISI_TXOK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | continue; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | txcount = min_t(short, TX_SIZE, port->xmit_cnt); |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 438 | if (txcount <= 0 || tty->stopped || tty->hw_stopped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | continue; |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 440 | |
| 441 | if (!(inw(base + 0x02) & (1 << port->channel))) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 442 | continue; |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 443 | |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 444 | pr_debug("txing %d bytes, port%d.\n", |
| 445 | txcount, port->channel + 1); |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 446 | outw((port->channel << isi_card[card].shift_count) | txcount, |
| 447 | base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | residue = NO; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 449 | wrd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | while (1) { |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 451 | cnt = min_t(int, txcount, (SERIAL_XMIT_SIZE |
| 452 | - port->xmit_tail)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (residue == YES) { |
| 454 | residue = NO; |
| 455 | if (cnt > 0) { |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 456 | wrd |= (port->port.xmit_buf[port->xmit_tail] |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 457 | << 8); |
| 458 | port->xmit_tail = (port->xmit_tail + 1) |
| 459 | & (SERIAL_XMIT_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | port->xmit_cnt--; |
| 461 | txcount--; |
| 462 | cnt--; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 463 | outw(wrd, base); |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 464 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | outw(wrd, base); |
| 466 | break; |
| 467 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 468 | } |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 469 | if (cnt <= 0) |
| 470 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | word_count = cnt >> 1; |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 472 | outsw(base, port->port.xmit_buf+port->xmit_tail, word_count); |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 473 | port->xmit_tail = (port->xmit_tail |
| 474 | + (word_count << 1)) & (SERIAL_XMIT_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | txcount -= (word_count << 1); |
| 476 | port->xmit_cnt -= (word_count << 1); |
| 477 | if (cnt & 0x0001) { |
| 478 | residue = YES; |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 479 | wrd = port->port.xmit_buf[port->xmit_tail]; |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 480 | port->xmit_tail = (port->xmit_tail + 1) |
| 481 | & (SERIAL_XMIT_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | port->xmit_cnt--; |
| 483 | txcount--; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | InterruptTheCard(base); |
| 488 | if (port->xmit_cnt <= 0) |
| 489 | port->status &= ~ISI_TXOK; |
| 490 | if (port->xmit_cnt <= WAKEUP_CHARS) |
Jiri Slaby | 0aa5de8 | 2007-02-10 01:44:47 -0800 | [diff] [blame] | 491 | tty_wakeup(tty); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 494 | put_unlock: |
| 495 | tty_kref_put(tty); |
Jiri Slaby | 5b21f9d | 2007-07-17 04:05:17 -0700 | [diff] [blame] | 496 | unlock: |
| 497 | spin_unlock_irqrestore(&isi_card[card].card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 498 | /* schedule another tx for hopefully in about 10ms */ |
| 499 | sched_again: |
Jiri Slaby | 34b55b8 | 2006-12-08 02:38:55 -0800 | [diff] [blame] | 500 | mod_timer(&tx, jiffies + msecs_to_jiffies(10)); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | /* |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 504 | * Main interrupt handler routine |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 506 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 507 | static irqreturn_t isicom_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 509 | struct isi_board *card = dev_id; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 510 | struct isi_port *port; |
| 511 | struct tty_struct *tty; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 512 | unsigned long base; |
| 513 | u16 header, word_count, count, channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | short byte_count; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 515 | unsigned char *rp; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (!card || !(card->status & FIRMWARE_LOADED)) |
| 518 | return IRQ_NONE; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | base = card->base; |
Jiri Slaby | cb4a10c | 2007-02-10 01:44:53 -0800 | [diff] [blame] | 521 | |
| 522 | /* did the card interrupt us? */ |
| 523 | if (!(inw(base + 0x0e) & 0x02)) |
| 524 | return IRQ_NONE; |
| 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | spin_lock(&card->card_lock); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 527 | |
Jiri Slaby | 18234f8 | 2006-12-08 02:38:51 -0800 | [diff] [blame] | 528 | /* |
| 529 | * disable any interrupts from the PCI card and lower the |
| 530 | * interrupt line |
| 531 | */ |
| 532 | outw(0x8000, base+0x04); |
| 533 | ClearInterrupt(base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | inw(base); /* get the dummy word out */ |
| 536 | header = inw(base); |
| 537 | channel = (header & 0x7800) >> card->shift_count; |
| 538 | byte_count = header & 0xff; |
| 539 | |
| 540 | if (channel + 1 > card->port_count) { |
Joe Perches | e620e54 | 2014-11-09 22:46:35 -0800 | [diff] [blame] | 541 | pr_warn("%s(0x%lx): %d(channel) > port_count\n", |
| 542 | __func__, base, channel + 1); |
Jiri Slaby | 18234f8 | 2006-12-08 02:38:51 -0800 | [diff] [blame] | 543 | outw(0x0000, base+0x04); /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | spin_unlock(&card->card_lock); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 545 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | port = card->ports + channel; |
Peter Hurley | d41861c | 2016-04-09 17:53:25 -0700 | [diff] [blame] | 548 | if (!tty_port_initialized(&port->port)) { |
Jiri Slaby | 18234f8 | 2006-12-08 02:38:51 -0800 | [diff] [blame] | 549 | outw(0x0000, base+0x04); /* enable interrupts */ |
Jiri Slaby | 174f130 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 550 | spin_unlock(&card->card_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | return IRQ_HANDLED; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 554 | tty = tty_port_tty_get(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | if (tty == NULL) { |
| 556 | word_count = byte_count >> 1; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 557 | while (byte_count > 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | inw(base); |
| 559 | byte_count -= 2; |
| 560 | } |
| 561 | if (byte_count & 0x01) |
| 562 | inw(base); |
Jiri Slaby | 18234f8 | 2006-12-08 02:38:51 -0800 | [diff] [blame] | 563 | outw(0x0000, base+0x04); /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | spin_unlock(&card->card_lock); |
| 565 | return IRQ_HANDLED; |
| 566 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | if (header & 0x8000) { /* Status Packet */ |
| 569 | header = inw(base); |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 570 | switch (header & 0xff) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 571 | case 0: /* Change in EIA signals */ |
Peter Hurley | 2d68655 | 2016-04-09 17:53:23 -0700 | [diff] [blame] | 572 | if (tty_port_check_carrier(&port->port)) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 573 | if (port->status & ISI_DCD) { |
| 574 | if (!(header & ISI_DCD)) { |
| 575 | /* Carrier has been lost */ |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 576 | pr_debug("%s: DCD->low.\n", |
| 577 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | port->status &= ~ISI_DCD; |
Jiri Slaby | 0aa5de8 | 2007-02-10 01:44:47 -0800 | [diff] [blame] | 579 | tty_hangup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 581 | } else if (header & ISI_DCD) { |
| 582 | /* Carrier has been detected */ |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 583 | pr_debug("%s: DCD->high.\n", |
| 584 | __func__); |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 585 | port->status |= ISI_DCD; |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 586 | wake_up_interruptible(&port->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 588 | } else { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 589 | if (header & ISI_DCD) |
| 590 | port->status |= ISI_DCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | else |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 592 | port->status &= ~ISI_DCD; |
| 593 | } |
| 594 | |
Huang Shijie | f21ec3d | 2012-08-22 22:13:36 -0400 | [diff] [blame] | 595 | if (tty_port_cts_enabled(&port->port)) { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 596 | if (tty->hw_stopped) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 597 | if (header & ISI_CTS) { |
Jiri Slaby | 7342c59 | 2012-11-15 09:49:48 +0100 | [diff] [blame] | 598 | tty->hw_stopped = 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 599 | /* start tx ing */ |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 600 | port->status |= (ISI_TXOK |
| 601 | | ISI_CTS); |
Jiri Slaby | 0aa5de8 | 2007-02-10 01:44:47 -0800 | [diff] [blame] | 602 | tty_wakeup(tty); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 603 | } |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 604 | } else if (!(header & ISI_CTS)) { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 605 | tty->hw_stopped = 1; |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 606 | /* stop tx ing */ |
| 607 | port->status &= ~(ISI_TXOK | ISI_CTS); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 608 | } |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 609 | } else { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 610 | if (header & ISI_CTS) |
| 611 | port->status |= ISI_CTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | else |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 613 | port->status &= ~ISI_CTS; |
| 614 | } |
| 615 | |
| 616 | if (header & ISI_DSR) |
| 617 | port->status |= ISI_DSR; |
| 618 | else |
| 619 | port->status &= ~ISI_DSR; |
| 620 | |
| 621 | if (header & ISI_RI) |
| 622 | port->status |= ISI_RI; |
| 623 | else |
| 624 | port->status &= ~ISI_RI; |
| 625 | |
| 626 | break; |
| 627 | |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 628 | case 1: /* Received Break !!! */ |
Jiri Slaby | 92a19f9 | 2013-01-03 15:53:03 +0100 | [diff] [blame] | 629 | tty_insert_flip_char(&port->port, 0, TTY_BREAK); |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 630 | if (port->port.flags & ASYNC_SAK) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 631 | do_SAK(tty); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 632 | tty_flip_buffer_push(&port->port); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | case 2: /* Statistics */ |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 636 | pr_debug("%s: stats!!!\n", __func__); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 637 | break; |
| 638 | |
| 639 | default: |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 640 | pr_debug("%s: Unknown code in status packet.\n", |
| 641 | __func__); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 642 | break; |
| 643 | } |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 644 | } else { /* Data Packet */ |
Jiri Slaby | 2f69335 | 2013-01-03 15:53:02 +0100 | [diff] [blame] | 645 | count = tty_prepare_flip_string(&port->port, &rp, |
| 646 | byte_count & ~1); |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 647 | pr_debug("%s: Can rx %d of %d bytes.\n", |
| 648 | __func__, count, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | word_count = count >> 1; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 650 | insw(base, rp, word_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | byte_count -= (word_count << 1); |
| 652 | if (count & 0x0001) { |
Jiri Slaby | 92a19f9 | 2013-01-03 15:53:03 +0100 | [diff] [blame] | 653 | tty_insert_flip_char(&port->port, inw(base) & 0xff, |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 654 | TTY_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | byte_count -= 2; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | if (byte_count > 0) { |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 658 | pr_debug("%s(0x%lx:%d): Flip buffer overflow! dropping bytes...\n", |
| 659 | __func__, base, channel + 1); |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 660 | /* drain out unread xtra data */ |
| 661 | while (byte_count > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | inw(base); |
| 663 | byte_count -= 2; |
| 664 | } |
| 665 | } |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 666 | tty_flip_buffer_push(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } |
Jiri Slaby | 18234f8 | 2006-12-08 02:38:51 -0800 | [diff] [blame] | 668 | outw(0x0000, base+0x04); /* enable interrupts */ |
Jiri Slaby | 174f130 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 669 | spin_unlock(&card->card_lock); |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 670 | tty_kref_put(tty); |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return IRQ_HANDLED; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 673 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 675 | static void isicom_config_port(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 677 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 678 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | unsigned long baud; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 680 | unsigned long base = card->base; |
| 681 | u16 channel_setup, channel = port->channel, |
| 682 | shift_count = card->shift_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | unsigned char flow_ctrl; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 684 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 685 | /* FIXME: Switch to new tty baud API */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | baud = C_BAUD(tty); |
| 687 | if (baud & CBAUDEX) { |
| 688 | baud &= ~CBAUDEX; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | /* if CBAUDEX bit is on and the baud is set to either 50 or 75 |
| 691 | * then the card is programmed for 57.6Kbps or 115Kbps |
| 692 | * respectively. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 693 | */ |
| 694 | |
Jiri Slaby | 7edc136 | 2007-02-10 01:44:54 -0800 | [diff] [blame] | 695 | /* 1,2,3,4 => 57.6, 115.2, 230, 460 kbps resp. */ |
| 696 | if (baud < 1 || baud > 4) |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 697 | tty->termios.c_cflag &= ~CBAUDEX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | else |
| 699 | baud += 15; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 700 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | if (baud == 15) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 702 | |
| 703 | /* the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | * by the set_serial_info ioctl ... this is done by |
| 705 | * the 'setserial' utility. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 706 | */ |
| 707 | |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 708 | if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 709 | baud++; /* 57.6 Kbps */ |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 710 | if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 711 | baud += 2; /* 115 Kbps */ |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 712 | if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) |
Jiri Slaby | 7edc136 | 2007-02-10 01:44:54 -0800 | [diff] [blame] | 713 | baud += 3; /* 230 kbps*/ |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 714 | if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) |
Jiri Slaby | 7edc136 | 2007-02-10 01:44:54 -0800 | [diff] [blame] | 715 | baud += 4; /* 460 kbps*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | if (linuxb_to_isib[baud] == -1) { |
| 718 | /* hang up */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 719 | drop_dtr(port); |
| 720 | return; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 721 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | raise_dtr(port); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 723 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 724 | if (WaitTillCardIsFree(base) == 0) { |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 725 | outw(0x8000 | (channel << shift_count) | 0x03, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | outw(linuxb_to_isib[baud] << 8 | 0x03, base); |
| 727 | channel_setup = 0; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 728 | switch (C_CSIZE(tty)) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 729 | case CS5: |
| 730 | channel_setup |= ISICOM_CS5; |
| 731 | break; |
| 732 | case CS6: |
| 733 | channel_setup |= ISICOM_CS6; |
| 734 | break; |
| 735 | case CS7: |
| 736 | channel_setup |= ISICOM_CS7; |
| 737 | break; |
| 738 | case CS8: |
| 739 | channel_setup |= ISICOM_CS8; |
| 740 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | if (C_CSTOPB(tty)) |
| 744 | channel_setup |= ISICOM_2SB; |
| 745 | if (C_PARENB(tty)) { |
| 746 | channel_setup |= ISICOM_EVPAR; |
| 747 | if (C_PARODD(tty)) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 748 | channel_setup |= ISICOM_ODPAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 750 | outw(channel_setup, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | InterruptTheCard(base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 752 | } |
Peter Hurley | 2d68655 | 2016-04-09 17:53:23 -0700 | [diff] [blame] | 753 | tty_port_set_check_carrier(&port->port, !C_CLOCAL(tty)); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | /* flow control settings ...*/ |
| 756 | flow_ctrl = 0; |
Peter Hurley | 5604a98 | 2016-04-09 17:53:21 -0700 | [diff] [blame] | 757 | tty_port_set_cts_flow(&port->port, C_CRTSCTS(tty)); |
| 758 | if (C_CRTSCTS(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | flow_ctrl |= ISICOM_CTSRTS; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 760 | if (I_IXON(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | flow_ctrl |= ISICOM_RESPOND_XONXOFF; |
| 762 | if (I_IXOFF(tty)) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 763 | flow_ctrl |= ISICOM_INITIATE_XONXOFF; |
| 764 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 765 | if (WaitTillCardIsFree(base) == 0) { |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 766 | outw(0x8000 | (channel << shift_count) | 0x04, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | outw(flow_ctrl << 8 | 0x05, base); |
| 768 | outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base); |
| 769 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | /* rx enabled -> enable port for rx on the card */ |
| 773 | if (C_CREAD(tty)) { |
| 774 | card->port_status |= (1 << channel); |
| 775 | outw(card->port_status, base + 0x02); |
| 776 | } |
| 777 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 779 | /* open et all */ |
| 780 | |
| 781 | static inline void isicom_setup_board(struct isi_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
| 783 | int channel; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 784 | struct isi_port *port; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 785 | |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 786 | bp->count++; |
Alan Cox | 6ed847d | 2009-11-30 13:17:30 +0000 | [diff] [blame] | 787 | if (!(bp->status & BOARD_INIT)) { |
| 788 | port = bp->ports; |
| 789 | for (channel = 0; channel < bp->port_count; channel++, port++) |
| 790 | drop_dtr_rts(port); |
| 791 | } |
| 792 | bp->status |= BOARD_ACTIVE | BOARD_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 794 | |
Alan Cox | 6ed847d | 2009-11-30 13:17:30 +0000 | [diff] [blame] | 795 | /* Activate and thus setup board are protected from races against shutdown |
| 796 | by the tty_port mutex */ |
| 797 | |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 798 | static int isicom_activate(struct tty_port *tport, struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 800 | struct isi_port *port = container_of(tport, struct isi_port, port); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 801 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 803 | |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 804 | if (tty_port_alloc_xmit_buf(tport) < 0) |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 805 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | spin_lock_irqsave(&card->card_lock, flags); |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 808 | isicom_setup_board(card); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | /* discard any residual data */ |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 813 | if (WaitTillCardIsFree(card->base) == 0) { |
| 814 | outw(0x8000 | (port->channel << card->shift_count) | 0x02, |
| 815 | card->base); |
| 816 | outw(((ISICOM_KILLTX | ISICOM_KILLRX) << 8) | 0x06, card->base); |
| 817 | InterruptTheCard(card->base); |
| 818 | } |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 819 | isicom_config_port(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 825 | static int isicom_carrier_raised(struct tty_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | { |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 827 | struct isi_port *ip = container_of(port, struct isi_port, port); |
| 828 | return (ip->status & ISI_DCD)?1 : 0; |
| 829 | } |
| 830 | |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 831 | static struct tty_port *isicom_find_port(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 833 | struct isi_port *port; |
| 834 | struct isi_board *card; |
Jiri Slaby | 17c4edf | 2006-12-08 02:38:57 -0800 | [diff] [blame] | 835 | unsigned int board; |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 836 | int line = tty->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | board = BOARD(line); |
| 839 | card = &isi_card[board]; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | if (!(card->status & FIRMWARE_LOADED)) |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 842 | return NULL; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | /* open on a port greater than the port count for the card !!! */ |
| 845 | if (line > ((board * 16) + card->port_count - 1)) |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 846 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 848 | port = &isi_ports[line]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | if (isicom_paranoia_check(port, tty->name, "isicom_open")) |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 850 | return NULL; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 851 | |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 852 | return &port->port; |
| 853 | } |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 854 | |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 855 | static int isicom_open(struct tty_struct *tty, struct file *filp) |
| 856 | { |
| 857 | struct isi_port *port; |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 858 | struct tty_port *tport; |
Alan Cox | 11d85d7 | 2009-09-19 13:13:27 -0700 | [diff] [blame] | 859 | |
| 860 | tport = isicom_find_port(tty); |
| 861 | if (tport == NULL) |
| 862 | return -ENODEV; |
| 863 | port = container_of(tport, struct isi_port, port); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 864 | |
Alan Cox | a2d1e35 | 2010-04-23 16:01:18 +0100 | [diff] [blame] | 865 | tty->driver_data = port; |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 866 | return tty_port_open(tport, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | /* close et all */ |
| 870 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 871 | /* card->lock HAS to be held */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 872 | static void isicom_shutdown_port(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 874 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | if (--card->count < 0) { |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 877 | pr_debug("%s: bad board(0x%lx) count %d.\n", |
| 878 | __func__, card->base, card->count); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 879 | card->count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | } |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 881 | /* last port was closed, shutdown that board too */ |
Alan Cox | 6ed847d | 2009-11-30 13:17:30 +0000 | [diff] [blame] | 882 | if (!card->count) |
| 883 | card->status &= BOARD_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 886 | static void isicom_flush_buffer(struct tty_struct *tty) |
| 887 | { |
| 888 | struct isi_port *port = tty->driver_data; |
| 889 | struct isi_board *card = port->card; |
| 890 | unsigned long flags; |
| 891 | |
| 892 | if (isicom_paranoia_check(port, tty->name, "isicom_flush_buffer")) |
| 893 | return; |
| 894 | |
| 895 | spin_lock_irqsave(&card->card_lock, flags); |
| 896 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
| 897 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 898 | |
| 899 | tty_wakeup(tty); |
| 900 | } |
| 901 | |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 902 | static void isicom_shutdown(struct tty_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
Alan Cox | 6f6412b | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 904 | struct isi_port *ip = container_of(port, struct isi_port, port); |
| 905 | struct isi_board *card = ip->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 907 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 908 | /* indicate to the card that no more data can be received |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | on this port */ |
| 910 | spin_lock_irqsave(&card->card_lock, flags); |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 911 | card->port_status &= ~(1 << ip->channel); |
| 912 | outw(card->port_status, card->base + 0x02); |
Alan Cox | a661499 | 2009-01-02 13:46:50 +0000 | [diff] [blame] | 913 | isicom_shutdown_port(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | spin_unlock_irqrestore(&card->card_lock, flags); |
Alan Cox | 2493c0c | 2009-11-30 13:17:46 +0000 | [diff] [blame] | 915 | tty_port_free_xmit_buf(port); |
Alan Cox | 6f6412b | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 916 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 917 | |
Alan Cox | 6f6412b | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 918 | static void isicom_close(struct tty_struct *tty, struct file *filp) |
| 919 | { |
| 920 | struct isi_port *ip = tty->driver_data; |
Alan Cox | a2d1e35 | 2010-04-23 16:01:18 +0100 | [diff] [blame] | 921 | struct tty_port *port; |
| 922 | |
| 923 | if (ip == NULL) |
| 924 | return; |
| 925 | |
| 926 | port = &ip->port; |
Alan Cox | 6f6412b | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 927 | if (isicom_paranoia_check(ip, tty->name, "isicom_close")) |
| 928 | return; |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 929 | tty_port_close(port, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /* write et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 933 | static int isicom_write(struct tty_struct *tty, const unsigned char *buf, |
| 934 | int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 936 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 937 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | unsigned long flags; |
| 939 | int cnt, total = 0; |
| 940 | |
| 941 | if (isicom_paranoia_check(port, tty->name, "isicom_write")) |
| 942 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | spin_lock_irqsave(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 945 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 946 | while (1) { |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 947 | cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt |
| 948 | - 1, SERIAL_XMIT_SIZE - port->xmit_head)); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 949 | if (cnt <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | break; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 951 | |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 952 | memcpy(port->port.xmit_buf + port->xmit_head, buf, cnt); |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 953 | port->xmit_head = (port->xmit_head + cnt) & (SERIAL_XMIT_SIZE |
| 954 | - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | port->xmit_cnt += cnt; |
| 956 | buf += cnt; |
| 957 | count -= cnt; |
| 958 | total += cnt; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 959 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped) |
| 961 | port->status |= ISI_TXOK; |
| 962 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 963 | return total; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | /* put_char et all */ |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 967 | static int isicom_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 969 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 970 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | if (isicom_paranoia_check(port, tty->name, "isicom_put_char")) |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 974 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | spin_lock_irqsave(&card->card_lock, flags); |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 977 | if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { |
| 978 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 979 | return 0; |
| 980 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 981 | |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 982 | port->port.xmit_buf[port->xmit_head++] = ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | port->xmit_head &= (SERIAL_XMIT_SIZE - 1); |
| 984 | port->xmit_cnt++; |
| 985 | spin_unlock_irqrestore(&card->card_lock, flags); |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 986 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | /* flush_chars et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 990 | static void isicom_flush_chars(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 992 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | if (isicom_paranoia_check(port, tty->name, "isicom_flush_chars")) |
| 995 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 996 | |
Jiri Slaby | a547dfe | 2006-01-09 20:54:26 -0800 | [diff] [blame] | 997 | if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 998 | !port->port.xmit_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | /* this tells the transmitter to consider this port for |
| 1002 | data output to the card ... that's the best we can do. */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1003 | port->status |= ISI_TXOK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | /* write_room et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1007 | static int isicom_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1009 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | int free; |
| 1011 | |
| 1012 | if (isicom_paranoia_check(port, tty->name, "isicom_write_room")) |
| 1013 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | free = SERIAL_XMIT_SIZE - port->xmit_cnt - 1; |
| 1016 | if (free < 0) |
| 1017 | free = 0; |
| 1018 | return free; |
| 1019 | } |
| 1020 | |
| 1021 | /* chars_in_buffer et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1022 | static int isicom_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1024 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | if (isicom_paranoia_check(port, tty->name, "isicom_chars_in_buffer")) |
| 1026 | return 0; |
| 1027 | return port->xmit_cnt; |
| 1028 | } |
| 1029 | |
| 1030 | /* ioctl et all */ |
Alan Cox | 6d88972 | 2008-07-22 11:18:21 +0100 | [diff] [blame] | 1031 | static int isicom_send_break(struct tty_struct *tty, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | { |
Alan Cox | 6d88972 | 2008-07-22 11:18:21 +0100 | [diff] [blame] | 1033 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1034 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1035 | unsigned long base = card->base; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1036 | |
Alan Cox | 6d88972 | 2008-07-22 11:18:21 +0100 | [diff] [blame] | 1037 | if (length == -1) |
| 1038 | return -EOPNOTSUPP; |
| 1039 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1040 | if (!lock_card(card)) |
Alan Cox | 6d88972 | 2008-07-22 11:18:21 +0100 | [diff] [blame] | 1041 | return -EINVAL; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base); |
| 1044 | outw((length & 0xff) << 8 | 0x00, base); |
Arnd Bergmann | f3e2d56 | 2015-01-13 22:59:47 +0100 | [diff] [blame] | 1045 | outw((length & 0xff00u), base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | InterruptTheCard(base); |
| 1047 | |
| 1048 | unlock_card(card); |
Alan Cox | 6d88972 | 2008-07-22 11:18:21 +0100 | [diff] [blame] | 1049 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 1052 | static int isicom_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1054 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | /* just send the port status */ |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1056 | u16 status = port->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | |
| 1058 | if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) |
| 1059 | return -ENODEV; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | return ((status & ISI_RTS) ? TIOCM_RTS : 0) | |
| 1062 | ((status & ISI_DTR) ? TIOCM_DTR : 0) | |
| 1063 | ((status & ISI_DCD) ? TIOCM_CAR : 0) | |
| 1064 | ((status & ISI_DSR) ? TIOCM_DSR : 0) | |
| 1065 | ((status & ISI_CTS) ? TIOCM_CTS : 0) | |
| 1066 | ((status & ISI_RI ) ? TIOCM_RI : 0); |
| 1067 | } |
| 1068 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 1069 | static int isicom_tiocmset(struct tty_struct *tty, |
| 1070 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1072 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1073 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1074 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) |
| 1076 | return -ENODEV; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1077 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1078 | spin_lock_irqsave(&port->card->card_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | if (set & TIOCM_RTS) |
| 1080 | raise_rts(port); |
| 1081 | if (set & TIOCM_DTR) |
| 1082 | raise_dtr(port); |
| 1083 | |
| 1084 | if (clear & TIOCM_RTS) |
| 1085 | drop_rts(port); |
| 1086 | if (clear & TIOCM_DTR) |
| 1087 | drop_dtr(port); |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1088 | spin_unlock_irqrestore(&port->card->card_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
| 1090 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1093 | static int isicom_set_serial_info(struct tty_struct *tty, |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1094 | struct serial_struct *ss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1096 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | int reconfig_port; |
| 1098 | |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1099 | if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) |
| 1100 | return -ENODEV; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1101 | |
Alan Cox | ec82db1 | 2010-06-01 22:52:44 +0200 | [diff] [blame] | 1102 | mutex_lock(&port->port.mutex); |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 1103 | reconfig_port = ((port->port.flags & ASYNC_SPD_MASK) != |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1104 | (ss->flags & ASYNC_SPD_MASK)); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | if (!capable(CAP_SYS_ADMIN)) { |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1107 | if ((ss->close_delay != port->port.close_delay) || |
| 1108 | (ss->closing_wait != port->port.closing_wait) || |
| 1109 | ((ss->flags & ~ASYNC_USR_MASK) != |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 1110 | (port->port.flags & ~ASYNC_USR_MASK))) { |
Alan Cox | ec82db1 | 2010-06-01 22:52:44 +0200 | [diff] [blame] | 1111 | mutex_unlock(&port->port.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | return -EPERM; |
Alan Cox | 1eac494 | 2008-04-30 00:53:19 -0700 | [diff] [blame] | 1113 | } |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 1114 | port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1115 | (ss->flags & ASYNC_USR_MASK)); |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1116 | } else { |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1117 | port->port.close_delay = ss->close_delay; |
| 1118 | port->port.closing_wait = ss->closing_wait; |
Alan Cox | f1d0322 | 2008-07-16 21:55:45 +0100 | [diff] [blame] | 1119 | port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) | |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1120 | (ss->flags & ASYNC_FLAGS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } |
| 1122 | if (reconfig_port) { |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1123 | unsigned long flags; |
| 1124 | spin_lock_irqsave(&port->card->card_lock, flags); |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1125 | isicom_config_port(tty); |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1126 | spin_unlock_irqrestore(&port->card->card_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | } |
Alan Cox | ec82db1 | 2010-06-01 22:52:44 +0200 | [diff] [blame] | 1128 | mutex_unlock(&port->port.mutex); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1129 | return 0; |
| 1130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1132 | static int isicom_get_serial_info(struct tty_struct *tty, |
| 1133 | struct serial_struct *ss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1135 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | |
| 1137 | if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) |
| 1138 | return -ENODEV; |
| 1139 | |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1140 | mutex_lock(&port->port.mutex); |
| 1141 | /* ss->type = ? */ |
| 1142 | ss->line = port - isi_ports; |
| 1143 | ss->port = port->card->base; |
| 1144 | ss->irq = port->card->irq; |
| 1145 | ss->flags = port->port.flags; |
| 1146 | /* ss->baud_base = ? */ |
| 1147 | ss->close_delay = port->port.close_delay; |
| 1148 | ss->closing_wait = port->port.closing_wait; |
| 1149 | mutex_unlock(&port->port.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | return 0; |
| 1151 | } |
| 1152 | |
| 1153 | /* set_termios et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1154 | static void isicom_set_termios(struct tty_struct *tty, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1155 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1157 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1158 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | if (isicom_paranoia_check(port, tty->name, "isicom_set_termios")) |
| 1161 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1162 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1163 | if (tty->termios.c_cflag == old_termios->c_cflag && |
| 1164 | tty->termios.c_iflag == old_termios->c_iflag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1166 | |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1167 | spin_lock_irqsave(&port->card->card_lock, flags); |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1168 | isicom_config_port(tty); |
Jiri Slaby | cfe7c09a | 2006-12-29 16:48:00 -0800 | [diff] [blame] | 1169 | spin_unlock_irqrestore(&port->card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1170 | |
Peter Hurley | 9db276f | 2016-01-10 20:36:15 -0800 | [diff] [blame] | 1171 | if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | tty->hw_stopped = 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1173 | isicom_start(tty); |
| 1174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | /* throttle et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1178 | static void isicom_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1180 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1181 | struct isi_board *card = port->card; |
| 1182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | if (isicom_paranoia_check(port, tty->name, "isicom_throttle")) |
| 1184 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | /* tell the card that this port cannot handle any more data for now */ |
| 1187 | card->port_status &= ~(1 << port->channel); |
| 1188 | outw(card->port_status, card->base + 0x02); |
| 1189 | } |
| 1190 | |
| 1191 | /* unthrottle et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1192 | static void isicom_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1194 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1195 | struct isi_board *card = port->card; |
| 1196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | if (isicom_paranoia_check(port, tty->name, "isicom_unthrottle")) |
| 1198 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | /* tell the card that this port is ready to accept more data */ |
| 1201 | card->port_status |= (1 << port->channel); |
| 1202 | outw(card->port_status, card->base + 0x02); |
| 1203 | } |
| 1204 | |
| 1205 | /* stop et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1206 | static void isicom_stop(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1208 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
| 1210 | if (isicom_paranoia_check(port, tty->name, "isicom_stop")) |
| 1211 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | /* this tells the transmitter not to consider this port for |
| 1214 | data output to the card. */ |
| 1215 | port->status &= ~ISI_TXOK; |
| 1216 | } |
| 1217 | |
| 1218 | /* start et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1219 | static void isicom_start(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1221 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | if (isicom_paranoia_check(port, tty->name, "isicom_start")) |
| 1224 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | /* this tells the transmitter to consider this port for |
| 1227 | data output to the card. */ |
| 1228 | port->status |= ISI_TXOK; |
| 1229 | } |
| 1230 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1231 | static void isicom_hangup(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1233 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | if (isicom_paranoia_check(port, tty->name, "isicom_hangup")) |
| 1236 | return; |
Alan Cox | 3e61696 | 2009-01-02 13:45:26 +0000 | [diff] [blame] | 1237 | tty_port_hangup(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1241 | /* |
| 1242 | * Driver init and deinit functions |
| 1243 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 1245 | static const struct tty_operations isicom_ops = { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1246 | .open = isicom_open, |
| 1247 | .close = isicom_close, |
| 1248 | .write = isicom_write, |
| 1249 | .put_char = isicom_put_char, |
| 1250 | .flush_chars = isicom_flush_chars, |
| 1251 | .write_room = isicom_write_room, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | .chars_in_buffer = isicom_chars_in_buffer, |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1253 | .set_termios = isicom_set_termios, |
| 1254 | .throttle = isicom_throttle, |
| 1255 | .unthrottle = isicom_unthrottle, |
| 1256 | .stop = isicom_stop, |
| 1257 | .start = isicom_start, |
| 1258 | .hangup = isicom_hangup, |
| 1259 | .flush_buffer = isicom_flush_buffer, |
| 1260 | .tiocmget = isicom_tiocmget, |
| 1261 | .tiocmset = isicom_tiocmset, |
Alan Cox | 6d88972 | 2008-07-22 11:18:21 +0100 | [diff] [blame] | 1262 | .break_ctl = isicom_send_break, |
Al Viro | b60f38c | 2018-09-11 22:00:37 -0400 | [diff] [blame] | 1263 | .get_serial = isicom_get_serial_info, |
| 1264 | .set_serial = isicom_set_serial_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | }; |
| 1266 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1267 | static const struct tty_port_operations isicom_port_ops = { |
| 1268 | .carrier_raised = isicom_carrier_raised, |
Alan Cox | fcc8ac1 | 2009-06-11 12:24:17 +0100 | [diff] [blame] | 1269 | .dtr_rts = isicom_dtr_rts, |
Alan Cox | baaa08a | 2009-11-30 13:17:24 +0000 | [diff] [blame] | 1270 | .activate = isicom_activate, |
| 1271 | .shutdown = isicom_shutdown, |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1272 | }; |
| 1273 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 1274 | static int reset_card(struct pci_dev *pdev, |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1275 | const unsigned int card, unsigned int *signature) |
| 1276 | { |
| 1277 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1278 | unsigned long base = board->base; |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1279 | unsigned int sig, portcount = 0; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1280 | int retval = 0; |
| 1281 | |
| 1282 | dev_dbg(&pdev->dev, "ISILoad:Resetting Card%d at 0x%lx\n", card + 1, |
| 1283 | base); |
| 1284 | |
| 1285 | inw(base + 0x8); |
| 1286 | |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1287 | msleep(10); |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1288 | |
| 1289 | outw(0, base + 0x8); /* Reset */ |
| 1290 | |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1291 | msleep(1000); |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1292 | |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1293 | sig = inw(base + 0x4) & 0xff; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1294 | |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1295 | if (sig != 0xa5 && sig != 0xbb && sig != 0xcc && sig != 0xdd && |
| 1296 | sig != 0xee) { |
| 1297 | dev_warn(&pdev->dev, "ISILoad:Card%u reset failure (Possible " |
| 1298 | "bad I/O Port Address 0x%lx).\n", card + 1, base); |
| 1299 | dev_dbg(&pdev->dev, "Sig=0x%x\n", sig); |
Jiri Slaby | 18234f8 | 2006-12-08 02:38:51 -0800 | [diff] [blame] | 1300 | retval = -EIO; |
| 1301 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1304 | msleep(10); |
| 1305 | |
| 1306 | portcount = inw(base + 0x2); |
Julia Lawall | 07fb6f2 | 2008-03-04 14:29:17 -0800 | [diff] [blame] | 1307 | if (!(inw(base + 0xe) & 0x1) || (portcount != 0 && portcount != 4 && |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1308 | portcount != 8 && portcount != 16)) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1309 | dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure.\n", |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1310 | card + 1); |
| 1311 | retval = -EIO; |
| 1312 | goto end; |
| 1313 | } |
| 1314 | |
| 1315 | switch (sig) { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1316 | case 0xa5: |
| 1317 | case 0xbb: |
| 1318 | case 0xdd: |
Jiri Slaby | 18234f8 | 2006-12-08 02:38:51 -0800 | [diff] [blame] | 1319 | board->port_count = (portcount == 4) ? 4 : 8; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1320 | board->shift_count = 12; |
| 1321 | break; |
| 1322 | case 0xcc: |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1323 | case 0xee: |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1324 | board->port_count = 16; |
| 1325 | board->shift_count = 11; |
| 1326 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1328 | dev_info(&pdev->dev, "-Done\n"); |
Jiri Slaby | f0a0ba6 | 2007-02-10 01:44:52 -0800 | [diff] [blame] | 1329 | *signature = sig; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1330 | |
| 1331 | end: |
| 1332 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 1335 | static int load_firmware(struct pci_dev *pdev, |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1336 | const unsigned int index, const unsigned int signature) |
| 1337 | { |
| 1338 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1339 | const struct firmware *fw; |
| 1340 | unsigned long base = board->base; |
| 1341 | unsigned int a; |
| 1342 | u16 word_count, status; |
| 1343 | int retval = -EIO; |
| 1344 | char *name; |
| 1345 | u8 *data; |
| 1346 | |
| 1347 | struct stframe { |
| 1348 | u16 addr; |
| 1349 | u16 count; |
| 1350 | u8 data[0]; |
| 1351 | } *frame; |
| 1352 | |
| 1353 | switch (signature) { |
| 1354 | case 0xa5: |
| 1355 | name = "isi608.bin"; |
| 1356 | break; |
| 1357 | case 0xbb: |
| 1358 | name = "isi608em.bin"; |
| 1359 | break; |
| 1360 | case 0xcc: |
| 1361 | name = "isi616em.bin"; |
| 1362 | break; |
| 1363 | case 0xdd: |
| 1364 | name = "isi4608.bin"; |
| 1365 | break; |
| 1366 | case 0xee: |
| 1367 | name = "isi4616.bin"; |
| 1368 | break; |
| 1369 | default: |
| 1370 | dev_err(&pdev->dev, "Unknown signature.\n"); |
| 1371 | goto end; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1372 | } |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1373 | |
| 1374 | retval = request_firmware(&fw, name, &pdev->dev); |
| 1375 | if (retval) |
| 1376 | goto end; |
| 1377 | |
Jiri Slaby | e4e0408 | 2006-09-30 23:27:50 -0700 | [diff] [blame] | 1378 | retval = -EIO; |
| 1379 | |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1380 | for (frame = (struct stframe *)fw->data; |
| 1381 | frame < (struct stframe *)(fw->data + fw->size); |
Jiri Slaby | e4e0408 | 2006-09-30 23:27:50 -0700 | [diff] [blame] | 1382 | frame = (struct stframe *)((u8 *)(frame + 1) + |
| 1383 | frame->count)) { |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1384 | if (WaitTillCardIsFree(base)) |
| 1385 | goto errrelfw; |
| 1386 | |
| 1387 | outw(0xf0, base); /* start upload sequence */ |
| 1388 | outw(0x00, base); |
| 1389 | outw(frame->addr, base); /* lsb of address */ |
| 1390 | |
| 1391 | word_count = frame->count / 2 + frame->count % 2; |
| 1392 | outw(word_count, base); |
| 1393 | InterruptTheCard(base); |
| 1394 | |
| 1395 | udelay(100); /* 0x2f */ |
| 1396 | |
| 1397 | if (WaitTillCardIsFree(base)) |
| 1398 | goto errrelfw; |
| 1399 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1400 | status = inw(base + 0x4); |
| 1401 | if (status != 0) { |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1402 | dev_warn(&pdev->dev, "Card%d rejected load header:\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1403 | "Address:0x%x\n" |
| 1404 | "Count:0x%x\n" |
| 1405 | "Status:0x%x\n", |
| 1406 | index + 1, frame->addr, frame->count, status); |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1407 | goto errrelfw; |
| 1408 | } |
| 1409 | outsw(base, frame->data, word_count); |
| 1410 | |
| 1411 | InterruptTheCard(base); |
| 1412 | |
| 1413 | udelay(50); /* 0x0f */ |
| 1414 | |
| 1415 | if (WaitTillCardIsFree(base)) |
| 1416 | goto errrelfw; |
| 1417 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1418 | status = inw(base + 0x4); |
| 1419 | if (status != 0) { |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1420 | dev_err(&pdev->dev, "Card%d got out of sync.Card " |
| 1421 | "Status:0x%x\n", index + 1, status); |
| 1422 | goto errrelfw; |
| 1423 | } |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1424 | } |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1425 | |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1426 | /* XXX: should we test it by reading it back and comparing with original like |
| 1427 | * in load firmware package? */ |
Jiri Slaby | e4e0408 | 2006-09-30 23:27:50 -0700 | [diff] [blame] | 1428 | for (frame = (struct stframe *)fw->data; |
| 1429 | frame < (struct stframe *)(fw->data + fw->size); |
| 1430 | frame = (struct stframe *)((u8 *)(frame + 1) + |
| 1431 | frame->count)) { |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1432 | if (WaitTillCardIsFree(base)) |
| 1433 | goto errrelfw; |
| 1434 | |
| 1435 | outw(0xf1, base); /* start download sequence */ |
| 1436 | outw(0x00, base); |
| 1437 | outw(frame->addr, base); /* lsb of address */ |
| 1438 | |
| 1439 | word_count = (frame->count >> 1) + frame->count % 2; |
| 1440 | outw(word_count + 1, base); |
| 1441 | InterruptTheCard(base); |
| 1442 | |
| 1443 | udelay(50); /* 0xf */ |
| 1444 | |
| 1445 | if (WaitTillCardIsFree(base)) |
| 1446 | goto errrelfw; |
| 1447 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1448 | status = inw(base + 0x4); |
| 1449 | if (status != 0) { |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1450 | dev_warn(&pdev->dev, "Card%d rejected verify header:\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 1451 | "Address:0x%x\n" |
| 1452 | "Count:0x%x\n" |
| 1453 | "Status: 0x%x\n", |
| 1454 | index + 1, frame->addr, frame->count, status); |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1455 | goto errrelfw; |
| 1456 | } |
| 1457 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 1458 | data = kmalloc_array(word_count, 2, GFP_KERNEL); |
Jiri Slaby | f067137 | 2006-12-08 02:38:54 -0800 | [diff] [blame] | 1459 | if (data == NULL) { |
| 1460 | dev_err(&pdev->dev, "Card%d, firmware upload " |
| 1461 | "failed, not enough memory\n", index + 1); |
| 1462 | goto errrelfw; |
| 1463 | } |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1464 | inw(base); |
| 1465 | insw(base, data, word_count); |
| 1466 | InterruptTheCard(base); |
| 1467 | |
| 1468 | for (a = 0; a < frame->count; a++) |
| 1469 | if (data[a] != frame->data[a]) { |
| 1470 | kfree(data); |
| 1471 | dev_err(&pdev->dev, "Card%d, firmware upload " |
| 1472 | "failed\n", index + 1); |
| 1473 | goto errrelfw; |
| 1474 | } |
| 1475 | kfree(data); |
| 1476 | |
| 1477 | udelay(50); /* 0xf */ |
| 1478 | |
| 1479 | if (WaitTillCardIsFree(base)) |
| 1480 | goto errrelfw; |
| 1481 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1482 | status = inw(base + 0x4); |
| 1483 | if (status != 0) { |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1484 | dev_err(&pdev->dev, "Card%d verify got out of sync. " |
| 1485 | "Card Status:0x%x\n", index + 1, status); |
| 1486 | goto errrelfw; |
| 1487 | } |
| 1488 | } |
| 1489 | |
Jiri Slaby | e4e0408 | 2006-09-30 23:27:50 -0700 | [diff] [blame] | 1490 | /* xfer ctrl */ |
| 1491 | if (WaitTillCardIsFree(base)) |
| 1492 | goto errrelfw; |
| 1493 | |
| 1494 | outw(0xf2, base); |
| 1495 | outw(0x800, base); |
| 1496 | outw(0x0, base); |
| 1497 | outw(0x0, base); |
| 1498 | InterruptTheCard(base); |
| 1499 | outw(0x0, base + 0x4); /* for ISI4608 cards */ |
| 1500 | |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1501 | board->status |= FIRMWARE_LOADED; |
| 1502 | retval = 0; |
| 1503 | |
| 1504 | errrelfw: |
| 1505 | release_firmware(fw); |
| 1506 | end: |
| 1507 | return retval; |
| 1508 | } |
| 1509 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1510 | /* |
| 1511 | * Insmod can set static symbols so keep these static |
| 1512 | */ |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1513 | static unsigned int card_count; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1514 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 1515 | static int isicom_probe(struct pci_dev *pdev, |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1516 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | { |
Jiri Slaby | 9653a69 | 2009-06-17 16:27:48 -0700 | [diff] [blame] | 1518 | unsigned int uninitialized_var(signature), index; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1519 | int retval = -EPERM; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1520 | struct isi_board *board = NULL; |
| 1521 | |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1522 | if (card_count >= BOARD_COUNT) |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1523 | goto err; |
| 1524 | |
Jiri Slaby | e1e5770 | 2008-07-16 21:52:56 +0100 | [diff] [blame] | 1525 | retval = pci_enable_device(pdev); |
| 1526 | if (retval) { |
| 1527 | dev_err(&pdev->dev, "failed to enable\n"); |
| 1528 | goto err; |
| 1529 | } |
| 1530 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1531 | dev_info(&pdev->dev, "ISI PCI Card(Device ID 0x%x)\n", ent->device); |
| 1532 | |
| 1533 | /* allot the first empty slot in the array */ |
Dan Carpenter | 26e1e8d | 2010-05-07 10:30:41 +0200 | [diff] [blame] | 1534 | for (index = 0; index < BOARD_COUNT; index++) { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1535 | if (isi_card[index].base == 0) { |
| 1536 | board = &isi_card[index]; |
| 1537 | break; |
| 1538 | } |
Dan Carpenter | 26e1e8d | 2010-05-07 10:30:41 +0200 | [diff] [blame] | 1539 | } |
| 1540 | if (index == BOARD_COUNT) { |
| 1541 | retval = -ENODEV; |
| 1542 | goto err_disable; |
| 1543 | } |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1544 | |
Jiri Slaby | 938a702 | 2006-12-08 02:38:52 -0800 | [diff] [blame] | 1545 | board->index = index; |
Jiri Slaby | 4969b3a | 2007-07-17 04:05:18 -0700 | [diff] [blame] | 1546 | board->base = pci_resource_start(pdev, 3); |
| 1547 | board->irq = pdev->irq; |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1548 | card_count++; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1549 | |
| 1550 | pci_set_drvdata(pdev, board); |
| 1551 | |
Jiri Slaby | 78028da | 2006-12-08 02:38:53 -0800 | [diff] [blame] | 1552 | retval = pci_request_region(pdev, 3, ISICOM_NAME); |
| 1553 | if (retval) { |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1554 | dev_err(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d " |
| 1555 | "will be disabled.\n", board->base, board->base + 15, |
| 1556 | index + 1); |
| 1557 | retval = -EBUSY; |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1558 | goto errdec; |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1559 | } |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1560 | |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1561 | retval = request_irq(board->irq, isicom_interrupt, |
Yong Zhang | 9cfb5c0 | 2011-09-22 16:59:15 +0800 | [diff] [blame] | 1562 | IRQF_SHARED, ISICOM_NAME, board); |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1563 | if (retval < 0) { |
| 1564 | dev_err(&pdev->dev, "Could not install handler at Irq %d. " |
| 1565 | "Card%d will be disabled.\n", board->irq, index + 1); |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1566 | goto errunrr; |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1567 | } |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1568 | |
| 1569 | retval = reset_card(pdev, index, &signature); |
| 1570 | if (retval < 0) |
| 1571 | goto errunri; |
| 1572 | |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame] | 1573 | retval = load_firmware(pdev, index, signature); |
| 1574 | if (retval < 0) |
| 1575 | goto errunri; |
| 1576 | |
Jiri Slaby | d0f5914 | 2012-11-15 09:49:55 +0100 | [diff] [blame] | 1577 | for (index = 0; index < board->port_count; index++) { |
| 1578 | struct tty_port *tport = &board->ports[index].port; |
| 1579 | tty_port_init(tport); |
| 1580 | tport->ops = &isicom_port_ops; |
| 1581 | tport->close_delay = 50 * HZ/100; |
| 1582 | tport->closing_wait = 3000 * HZ/100; |
| 1583 | tty_port_register_device(tport, isicom_normal, |
| 1584 | board->index * 16 + index, &pdev->dev); |
| 1585 | } |
Jiri Slaby | 938a702 | 2006-12-08 02:38:52 -0800 | [diff] [blame] | 1586 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1587 | return 0; |
| 1588 | |
| 1589 | errunri: |
| 1590 | free_irq(board->irq, board); |
| 1591 | errunrr: |
Jiri Slaby | 78028da | 2006-12-08 02:38:53 -0800 | [diff] [blame] | 1592 | pci_release_region(pdev, 3); |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1593 | errdec: |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1594 | board->base = 0; |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1595 | card_count--; |
Dan Carpenter | 26e1e8d | 2010-05-07 10:30:41 +0200 | [diff] [blame] | 1596 | err_disable: |
Jiri Slaby | e1e5770 | 2008-07-16 21:52:56 +0100 | [diff] [blame] | 1597 | pci_disable_device(pdev); |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1598 | err: |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1599 | return retval; |
| 1600 | } |
| 1601 | |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 1602 | static void isicom_remove(struct pci_dev *pdev) |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1603 | { |
| 1604 | struct isi_board *board = pci_get_drvdata(pdev); |
Jiri Slaby | 938a702 | 2006-12-08 02:38:52 -0800 | [diff] [blame] | 1605 | unsigned int i; |
| 1606 | |
Jiri Slaby | d0f5914 | 2012-11-15 09:49:55 +0100 | [diff] [blame] | 1607 | for (i = 0; i < board->port_count; i++) { |
Jiri Slaby | 938a702 | 2006-12-08 02:38:52 -0800 | [diff] [blame] | 1608 | tty_unregister_device(isicom_normal, board->index * 16 + i); |
Jiri Slaby | d0f5914 | 2012-11-15 09:49:55 +0100 | [diff] [blame] | 1609 | tty_port_destroy(&board->ports[i].port); |
| 1610 | } |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1611 | |
| 1612 | free_irq(board->irq, board); |
Jiri Slaby | 78028da | 2006-12-08 02:38:53 -0800 | [diff] [blame] | 1613 | pci_release_region(pdev, 3); |
Jiri Slaby | 1ed0c0b | 2007-02-10 01:44:55 -0800 | [diff] [blame] | 1614 | board->base = 0; |
| 1615 | card_count--; |
Jiri Slaby | e1e5770 | 2008-07-16 21:52:56 +0100 | [diff] [blame] | 1616 | pci_disable_device(pdev); |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1617 | } |
| 1618 | |
Jiri Slaby | ca26200 | 2006-12-08 02:38:50 -0800 | [diff] [blame] | 1619 | static int __init isicom_init(void) |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1620 | { |
| 1621 | int retval, idx, channel; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1622 | struct isi_port *port; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1623 | |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1624 | for (idx = 0; idx < BOARD_COUNT; idx++) { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1625 | port = &isi_ports[idx * 16]; |
| 1626 | isi_card[idx].ports = port; |
| 1627 | spin_lock_init(&isi_card[idx].card_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | for (channel = 0; channel < 16; channel++, port++) { |
| 1629 | port->magic = ISICOM_MAGIC; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1630 | port->card = &isi_card[idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | port->channel = channel; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1632 | port->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | /* . . . */ |
Alan Cox | 251b8dd | 2008-04-30 00:54:12 -0700 | [diff] [blame] | 1634 | } |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1635 | isi_card[idx].base = 0; |
| 1636 | isi_card[idx].irq = 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1637 | } |
| 1638 | |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1639 | /* tty driver structure initialization */ |
| 1640 | isicom_normal = alloc_tty_driver(PORT_COUNT); |
| 1641 | if (!isicom_normal) { |
| 1642 | retval = -ENOMEM; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1643 | goto error; |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1644 | } |
| 1645 | |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1646 | isicom_normal->name = "ttyM"; |
| 1647 | isicom_normal->major = ISICOM_NMAJOR; |
| 1648 | isicom_normal->minor_start = 0; |
| 1649 | isicom_normal->type = TTY_DRIVER_TYPE_SERIAL; |
| 1650 | isicom_normal->subtype = SERIAL_TYPE_NORMAL; |
| 1651 | isicom_normal->init_termios = tty_std_termios; |
| 1652 | isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | |
| 1653 | CLOCAL; |
Jiri Slaby | 938a702 | 2006-12-08 02:38:52 -0800 | [diff] [blame] | 1654 | isicom_normal->flags = TTY_DRIVER_REAL_RAW | |
Alan Cox | 6d88972 | 2008-07-22 11:18:21 +0100 | [diff] [blame] | 1655 | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK; |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1656 | tty_set_operations(isicom_normal, &isicom_ops); |
| 1657 | |
| 1658 | retval = tty_register_driver(isicom_normal); |
| 1659 | if (retval) { |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 1660 | pr_debug("Couldn't register the dialin driver\n"); |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1661 | goto err_puttty; |
| 1662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1664 | retval = pci_register_driver(&isicom_driver); |
| 1665 | if (retval < 0) { |
Joe Perches | db91340b | 2009-12-09 12:34:16 -0800 | [diff] [blame] | 1666 | pr_err("Unable to register pci driver.\n"); |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1667 | goto err_unrtty; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
Jiri Slaby | 34b55b8 | 2006-12-08 02:38:55 -0800 | [diff] [blame] | 1670 | mod_timer(&tx, jiffies + 1); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | return 0; |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1673 | err_unrtty: |
| 1674 | tty_unregister_driver(isicom_normal); |
| 1675 | err_puttty: |
| 1676 | put_tty_driver(isicom_normal); |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1677 | error: |
| 1678 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | static void __exit isicom_exit(void) |
| 1682 | { |
Jiri Slaby | e327325 | 2007-07-17 04:05:18 -0700 | [diff] [blame] | 1683 | del_timer_sync(&tx); |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1684 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1685 | pci_unregister_driver(&isicom_driver); |
Jiri Slaby | 09a4a11 | 2006-12-08 02:38:49 -0800 | [diff] [blame] | 1686 | tty_unregister_driver(isicom_normal); |
| 1687 | put_tty_driver(isicom_normal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
Jiri Slaby | ca26200 | 2006-12-08 02:38:50 -0800 | [diff] [blame] | 1690 | module_init(isicom_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | module_exit(isicom_exit); |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1692 | |
| 1693 | MODULE_AUTHOR("MultiTech"); |
| 1694 | MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); |
| 1695 | MODULE_LICENSE("GPL"); |
Ben Hutchings | e6c4ef9 | 2010-01-13 23:34:18 +0000 | [diff] [blame] | 1696 | MODULE_FIRMWARE("isi608.bin"); |
| 1697 | MODULE_FIRMWARE("isi608em.bin"); |
| 1698 | MODULE_FIRMWARE("isi616em.bin"); |
| 1699 | MODULE_FIRMWARE("isi4608.bin"); |
| 1700 | MODULE_FIRMWARE("isi4616.bin"); |