2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version
5 * 2 of the License, or (at your option) any later version.
7 * Original driver code supplied by Multi-Tech
10 * 1/9/98 alan@redhat.com Merge to 2.0.x kernel tree
11 * Obtain and use official major/minors
12 * Loader switched to a misc device
13 * (fixed range check bug as a side effect)
15 * 9/12/98 alan@redhat.com Rough port to 2.1.x
17 * 10/6/99 sameer Merged the ISA and PCI drivers to
18 * a new unified driver.
20 * 3/9/99 sameer Added support for ISI4616 cards.
22 * 16/9/99 sameer We do not force RTS low anymore.
23 * This is to prevent the firmware
24 * from getting confused.
26 * 26/10/99 sameer Cosmetic changes:The driver now
27 * dumps the Port Count information
28 * along with I/O address and IRQ.
30 * 13/12/99 sameer Fixed the problem with IRQ sharing.
32 * 10/5/00 sameer Fixed isicom_shutdown_board()
33 * to not lower DTR on all the ports
34 * when the last port on the card is
37 * 10/5/00 sameer Signal mask setup command added
38 * to isicom_setup_port and
39 * isicom_shutdown_port.
41 * 24/5/00 sameer The driver is now SMP aware.
44 * 27/11/00 Vinayak P Risbud Fixed the Driver Crash Problem
47 * 03/01/01 anil .s Added support for resetting the
48 * internal modems on ISI cards.
50 * 08/02/01 anil .s Upgraded the driver for kernel
53 * 11/04/01 Kevin Fixed firmware load problem with
56 * 30/04/01 anil .s Fixed the remote login through
57 * ISI port problem. Now the link
58 * does not go down before password
61 * 03/05/01 anil .s Fixed the problem with IRQ sharing
62 * among ISI-PCI cards.
64 * 03/05/01 anil .s Added support to display the version
65 * info during insmod as well as module
68 * 10/05/01 anil .s Done the modifications to the source
69 * file and Install script so that the
70 * same installation can be used for
71 * 2.2.x and 2.4.x kernel.
73 * 06/06/01 anil .s Now we drop both dtr and rts during
74 * shutdown_port as well as raise them
75 * during isicom_config_port.
77 * 09/06/01 acme@conectiva.com.br use capable, not suser, do
78 * restore_flags on failure in
79 * isicom_send_break, verify put_user
82 * 11/02/03 ranjeeth Added support for 230 Kbps and 460 Kbps
83 * Baud index extended to 21
85 * 20/03/03 ranjeeth Made to work for Linux Advanced server.
86 * Taken care of license warning.
88 * 10/12/03 Ravindra Made to work for Fedora Core 1 of
89 * Red Hat Distribution
91 * 06/01/05 Alan Cox Merged the ISI and base kernel strands
92 * into a single 2.6 driver
94 * ***********************************************************
96 * To use this driver you also need the support package. You
97 * can find this in RPM format on
98 * ftp://ftp.linux.org.uk/pub/linux/alan
100 * You can find the original tools for this direct from Multitech
101 * ftp://ftp.multitech.com/ISI-Cards/
103 * Having installed the cards the module options (/etc/modprobe.conf)
105 * options isicom io=card1,card2,card3,card4 irq=card1,card2,card3,card4
107 * Omit those entries for boards you don't have installed.
111 * 64-bit verification
114 #include <linux/module.h>
115 #include <linux/firmware.h>
116 #include <linux/kernel.h>
117 #include <linux/tty.h>
118 #include <linux/tty_flip.h>
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>
124 #include <linux/interrupt.h>
125 #include <linux/timer.h>
126 #include <linux/delay.h>
127 #include <linux/ioport.h>
129 #include <asm/uaccess.h>
131 #include <asm/system.h>
133 #include <linux/pci.h>
135 #include <linux/isicom.h>
137 #define InterruptTheCard(base) outw(0, (base) + 0xc)
138 #define ClearInterrupt(base) inw((base) + 0x0a)
141 #define pr_dbg(str...) printk(KERN_DEBUG "ISICOM: " str)
142 #define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c))
144 #define pr_dbg(str...) do { } while (0)
145 #define isicom_paranoia_check(a, b, c) 0
148 static int isicom_probe(struct pci_dev *, const struct pci_device_id *);
149 static void __devexit isicom_remove(struct pci_dev *);
151 static struct pci_device_id isicom_pci_tbl[] = {
152 { PCI_DEVICE(VENDOR_ID, 0x2028) },
153 { PCI_DEVICE(VENDOR_ID, 0x2051) },
154 { PCI_DEVICE(VENDOR_ID, 0x2052) },
155 { PCI_DEVICE(VENDOR_ID, 0x2053) },
156 { PCI_DEVICE(VENDOR_ID, 0x2054) },
157 { PCI_DEVICE(VENDOR_ID, 0x2055) },
158 { PCI_DEVICE(VENDOR_ID, 0x2056) },
159 { PCI_DEVICE(VENDOR_ID, 0x2057) },
160 { PCI_DEVICE(VENDOR_ID, 0x2058) },
163 MODULE_DEVICE_TABLE(pci, isicom_pci_tbl);
165 static struct pci_driver isicom_driver = {
167 .id_table = isicom_pci_tbl,
168 .probe = isicom_probe,
169 .remove = __devexit_p(isicom_remove)
172 static int prev_card = 3; /* start servicing isi_card[0] */
173 static struct tty_driver *isicom_normal;
175 static struct timer_list tx;
176 static char re_schedule = 1;
178 static void isicom_tx(unsigned long _data);
179 static void isicom_start(struct tty_struct *tty);
181 /* baud index mappings from linux defns to isi */
183 static signed char linuxb_to_isib[] = {
184 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19
190 unsigned char port_count;
191 unsigned short status;
192 unsigned short port_status; /* each bit represents a single port */
193 unsigned short shift_count;
194 struct isi_port * ports;
197 spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */
202 unsigned short magic;
210 struct isi_board * card;
211 struct tty_struct * tty;
212 wait_queue_head_t close_wait;
213 wait_queue_head_t open_wait;
214 struct work_struct hangup_tq;
215 struct work_struct bh_tqueue;
216 unsigned char * xmit_buf;
222 static struct isi_board isi_card[BOARD_COUNT];
223 static struct isi_port isi_ports[PORT_COUNT];
226 * Locking functions for card level locking. We need to own both
227 * the kernel lock for the card and have the card in a position that
231 static int lock_card(struct isi_board *card)
234 unsigned long base = card->base;
236 for (retries = 0; retries < 100; retries++) {
237 spin_lock_irqsave(&card->card_lock, card->flags);
238 if (inw(base + 0xe) & 0x1) {
241 spin_unlock_irqrestore(&card->card_lock, card->flags);
242 udelay(1000); /* 1ms */
245 printk(KERN_WARNING "ISICOM: Failed to lock Card (0x%lx)\n", card->base);
246 return 0; /* Failed to aquire the card! */
249 static int lock_card_at_interrupt(struct isi_board *card)
251 unsigned char retries;
252 unsigned long base = card->base;
254 for (retries = 0; retries < 200; retries++) {
255 spin_lock_irqsave(&card->card_lock, card->flags);
257 if (inw(base + 0xe) & 0x1)
260 spin_unlock_irqrestore(&card->card_lock, card->flags);
262 /* Failing in interrupt is an acceptable event */
263 return 0; /* Failed to aquire the card! */
266 static void unlock_card(struct isi_board *card)
268 spin_unlock_irqrestore(&card->card_lock, card->flags);
272 * ISI Card specific ops ...
275 static void raise_dtr(struct isi_port *port)
277 struct isi_board *card = port->card;
278 unsigned long base = card->base;
279 u16 channel = port->channel;
281 if (!lock_card(card))
284 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
286 InterruptTheCard(base);
287 port->status |= ISI_DTR;
291 static inline void drop_dtr(struct isi_port *port)
293 struct isi_board *card = port->card;
294 unsigned long base = card->base;
295 u16 channel = port->channel;
297 if (!lock_card(card))
300 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
302 InterruptTheCard(base);
303 port->status &= ~ISI_DTR;
307 static inline void raise_rts(struct isi_port *port)
309 struct isi_board *card = port->card;
310 unsigned long base = card->base;
311 u16 channel = port->channel;
313 if (!lock_card(card))
316 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
318 InterruptTheCard(base);
319 port->status |= ISI_RTS;
322 static inline void drop_rts(struct isi_port *port)
324 struct isi_board *card = port->card;
325 unsigned long base = card->base;
326 u16 channel = port->channel;
328 if (!lock_card(card))
331 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
333 InterruptTheCard(base);
334 port->status &= ~ISI_RTS;
338 static inline void raise_dtr_rts(struct isi_port *port)
340 struct isi_board *card = port->card;
341 unsigned long base = card->base;
342 u16 channel = port->channel;
344 if (!lock_card(card))
347 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
349 InterruptTheCard(base);
350 port->status |= (ISI_DTR | ISI_RTS);
354 static void drop_dtr_rts(struct isi_port *port)
356 struct isi_board *card = port->card;
357 unsigned long base = card->base;
358 u16 channel = port->channel;
360 if (!lock_card(card))
363 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
365 InterruptTheCard(base);
366 port->status &= ~(ISI_RTS | ISI_DTR);
370 static inline void kill_queue(struct isi_port *port, short queue)
372 struct isi_board *card = port->card;
373 unsigned long base = card->base;
374 u16 channel = port->channel;
376 if (!lock_card(card))
379 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
380 outw((queue << 8) | 0x06, base);
381 InterruptTheCard(base);
386 * ISICOM Driver specific routines ...
390 static inline int __isicom_paranoia_check(struct isi_port const *port,
391 char *name, const char *routine)
394 printk(KERN_WARNING "ISICOM: Warning: bad isicom magic for "
395 "dev %s in %s.\n", name, routine);
398 if (port->magic != ISICOM_MAGIC) {
399 printk(KERN_WARNING "ISICOM: Warning: NULL isicom port for "
400 "dev %s in %s.\n", name, routine);
410 * We shovel data into the card buffers on a regular basis. The card
411 * will do the rest of the work for us.
414 static void isicom_tx(unsigned long _data)
416 short count = (BOARD_COUNT-1), card, base;
417 short txcount, wrd, residue, word_count, cnt;
418 struct isi_port *port;
419 struct tty_struct *tty;
421 /* find next active board */
422 card = (prev_card + 1) & 0x0003;
424 if (isi_card[card].status & BOARD_ACTIVE)
426 card = (card + 1) & 0x0003;
428 if (!(isi_card[card].status & BOARD_ACTIVE))
433 count = isi_card[card].port_count;
434 port = isi_card[card].ports;
435 base = isi_card[card].base;
436 for (;count > 0;count--, port++) {
437 if (!lock_card_at_interrupt(&isi_card[card]))
439 /* port not active or tx disabled to force flow control */
440 if (!(port->flags & ASYNC_INITIALIZED) ||
441 !(port->status & ISI_TXOK))
442 unlock_card(&isi_card[card]);
449 unlock_card(&isi_card[card]);
453 txcount = min_t(short, TX_SIZE, port->xmit_cnt);
454 if (txcount <= 0 || tty->stopped || tty->hw_stopped) {
455 unlock_card(&isi_card[card]);
458 if (!(inw(base + 0x02) & (1 << port->channel))) {
459 unlock_card(&isi_card[card]);
462 pr_dbg("txing %d bytes, port%d.\n", txcount,
464 outw((port->channel << isi_card[card].shift_count) | txcount,
469 cnt = min_t(int, txcount, (SERIAL_XMIT_SIZE - port->xmit_tail));
470 if (residue == YES) {
473 wrd |= (port->xmit_buf[port->xmit_tail] << 8);
474 port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
486 word_count = cnt >> 1;
487 outsw(base, port->xmit_buf+port->xmit_tail, word_count);
488 port->xmit_tail = (port->xmit_tail + (word_count << 1)) &
489 (SERIAL_XMIT_SIZE - 1);
490 txcount -= (word_count << 1);
491 port->xmit_cnt -= (word_count << 1);
494 wrd = port->xmit_buf[port->xmit_tail];
495 port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
501 InterruptTheCard(base);
502 if (port->xmit_cnt <= 0)
503 port->status &= ~ISI_TXOK;
504 if (port->xmit_cnt <= WAKEUP_CHARS)
505 schedule_work(&port->bh_tqueue);
506 unlock_card(&isi_card[card]);
509 /* schedule another tx for hopefully in about 10ms */
517 tx.expires = jiffies + HZ/100;
519 tx.function = isicom_tx;
525 /* Interrupt handlers */
528 static void isicom_bottomhalf(void *data)
530 struct isi_port *port = (struct isi_port *) data;
531 struct tty_struct *tty = port->tty;
537 wake_up_interruptible(&tty->write_wait);
541 * Main interrupt handler routine
544 static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs)
546 struct isi_board *card = dev_id;
547 struct isi_port *port;
548 struct tty_struct *tty;
550 u16 header, word_count, count, channel;
554 if (!card || !(card->status & FIRMWARE_LOADED))
558 spin_lock(&card->card_lock);
560 if (card->isa == NO) {
562 * disable any interrupts from the PCI card and lower the
565 outw(0x8000, base+0x04);
566 ClearInterrupt(base);
569 inw(base); /* get the dummy word out */
571 channel = (header & 0x7800) >> card->shift_count;
572 byte_count = header & 0xff;
574 if (channel + 1 > card->port_count) {
575 printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): %d(channel) > port_count.\n",
578 ClearInterrupt(base);
580 outw(0x0000, base+0x04); /* enable interrupts */
581 spin_unlock(&card->card_lock);
584 port = card->ports + channel;
585 if (!(port->flags & ASYNC_INITIALIZED)) {
587 ClearInterrupt(base);
589 outw(0x0000, base+0x04); /* enable interrupts */
595 word_count = byte_count >> 1;
596 while(byte_count > 1) {
600 if (byte_count & 0x01)
602 if (card->isa == YES)
603 ClearInterrupt(base);
605 outw(0x0000, base+0x04); /* enable interrupts */
606 spin_unlock(&card->card_lock);
610 if (header & 0x8000) { /* Status Packet */
612 switch(header & 0xff) {
613 case 0: /* Change in EIA signals */
615 if (port->flags & ASYNC_CHECK_CD) {
616 if (port->status & ISI_DCD) {
617 if (!(header & ISI_DCD)) {
618 /* Carrier has been lost */
619 pr_dbg("interrupt: DCD->low.\n");
620 port->status &= ~ISI_DCD;
621 schedule_work(&port->hangup_tq);
625 if (header & ISI_DCD) {
626 /* Carrier has been detected */
627 pr_dbg("interrupt: DCD->high.\n");
628 port->status |= ISI_DCD;
629 wake_up_interruptible(&port->open_wait);
634 if (header & ISI_DCD)
635 port->status |= ISI_DCD;
637 port->status &= ~ISI_DCD;
640 if (port->flags & ASYNC_CTS_FLOW) {
641 if (port->tty->hw_stopped) {
642 if (header & ISI_CTS) {
643 port->tty->hw_stopped = 0;
645 port->status |= (ISI_TXOK | ISI_CTS);
646 schedule_work(&port->bh_tqueue);
650 if (!(header & ISI_CTS)) {
651 port->tty->hw_stopped = 1;
653 port->status &= ~(ISI_TXOK | ISI_CTS);
658 if (header & ISI_CTS)
659 port->status |= ISI_CTS;
661 port->status &= ~ISI_CTS;
664 if (header & ISI_DSR)
665 port->status |= ISI_DSR;
667 port->status &= ~ISI_DSR;
670 port->status |= ISI_RI;
672 port->status &= ~ISI_RI;
676 case 1: /* Received Break !!! */
677 tty_insert_flip_char(tty, 0, TTY_BREAK);
678 if (port->flags & ASYNC_SAK)
680 tty_flip_buffer_push(tty);
683 case 2: /* Statistics */
684 pr_dbg("isicom_interrupt: stats!!!.\n");
688 pr_dbg("Intr: Unknown code in status packet.\n");
692 else { /* Data Packet */
694 count = tty_prepare_flip_string(tty, &rp, byte_count & ~1);
695 pr_dbg("Intr: Can rx %d of %d bytes.\n", count, byte_count);
696 word_count = count >> 1;
697 insw(base, rp, word_count);
698 byte_count -= (word_count << 1);
699 if (count & 0x0001) {
700 tty_insert_flip_char(tty, inw(base) & 0xff, TTY_NORMAL);
703 if (byte_count > 0) {
704 pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping "
705 "bytes...\n", base, channel + 1);
706 while(byte_count > 0) { /* drain out unread xtra data */
711 tty_flip_buffer_push(tty);
713 if (card->isa == YES)
714 ClearInterrupt(base);
716 outw(0x0000, base+0x04); /* enable interrupts */
720 static void isicom_config_port(struct isi_port *port)
722 struct isi_board *card = port->card;
723 struct tty_struct *tty;
725 unsigned long base = card->base;
726 u16 channel_setup, channel = port->channel,
727 shift_count = card->shift_count;
728 unsigned char flow_ctrl;
730 if (!(tty = port->tty) || !tty->termios)
733 if (baud & CBAUDEX) {
736 /* if CBAUDEX bit is on and the baud is set to either 50 or 75
737 * then the card is programmed for 57.6Kbps or 115Kbps
741 if (baud < 1 || baud > 2)
742 port->tty->termios->c_cflag &= ~CBAUDEX;
748 /* the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set
749 * by the set_serial_info ioctl ... this is done by
750 * the 'setserial' utility.
753 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
754 baud++; /* 57.6 Kbps */
755 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
756 baud +=2; /* 115 Kbps */
758 if (linuxb_to_isib[baud] == -1) {
766 if (lock_card(card)) {
767 outw(0x8000 | (channel << shift_count) |0x03, base);
768 outw(linuxb_to_isib[baud] << 8 | 0x03, base);
770 switch(C_CSIZE(tty)) {
772 channel_setup |= ISICOM_CS5;
775 channel_setup |= ISICOM_CS6;
778 channel_setup |= ISICOM_CS7;
781 channel_setup |= ISICOM_CS8;
786 channel_setup |= ISICOM_2SB;
788 channel_setup |= ISICOM_EVPAR;
790 channel_setup |= ISICOM_ODPAR;
792 outw(channel_setup, base);
793 InterruptTheCard(base);
797 port->flags &= ~ASYNC_CHECK_CD;
799 port->flags |= ASYNC_CHECK_CD;
801 /* flow control settings ...*/
803 port->flags &= ~ASYNC_CTS_FLOW;
804 if (C_CRTSCTS(tty)) {
805 port->flags |= ASYNC_CTS_FLOW;
806 flow_ctrl |= ISICOM_CTSRTS;
809 flow_ctrl |= ISICOM_RESPOND_XONXOFF;
811 flow_ctrl |= ISICOM_INITIATE_XONXOFF;
813 if (lock_card(card)) {
814 outw(0x8000 | (channel << shift_count) |0x04, base);
815 outw(flow_ctrl << 8 | 0x05, base);
816 outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base);
817 InterruptTheCard(base);
821 /* rx enabled -> enable port for rx on the card */
823 card->port_status |= (1 << channel);
824 outw(card->port_status, base + 0x02);
830 static inline void isicom_setup_board(struct isi_board *bp)
833 struct isi_port *port;
836 spin_lock_irqsave(&bp->card_lock, flags);
837 if (bp->status & BOARD_ACTIVE) {
838 spin_unlock_irqrestore(&bp->card_lock, flags);
842 bp->status |= BOARD_ACTIVE;
843 spin_unlock_irqrestore(&bp->card_lock, flags);
844 for (channel = 0; channel < bp->port_count; channel++, port++)
849 static int isicom_setup_port(struct isi_port *port)
851 struct isi_board *card = port->card;
854 if (port->flags & ASYNC_INITIALIZED) {
857 if (!port->xmit_buf) {
860 if (!(page = get_zeroed_page(GFP_KERNEL)))
863 if (port->xmit_buf) {
867 port->xmit_buf = (unsigned char *) page;
870 spin_lock_irqsave(&card->card_lock, flags);
872 clear_bit(TTY_IO_ERROR, &port->tty->flags);
873 if (port->count == 1)
876 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
878 /* discard any residual data */
879 kill_queue(port, ISICOM_KILLTX | ISICOM_KILLRX);
881 isicom_config_port(port);
882 port->flags |= ASYNC_INITIALIZED;
883 spin_unlock_irqrestore(&card->card_lock, flags);
888 static int block_til_ready(struct tty_struct *tty, struct file *filp, struct isi_port *port)
890 struct isi_board *card = port->card;
891 int do_clocal = 0, retval;
893 DECLARE_WAITQUEUE(wait, current);
895 /* block if port is in the process of being closed */
897 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
898 pr_dbg("block_til_ready: close in progress.\n");
899 interruptible_sleep_on(&port->close_wait);
900 if (port->flags & ASYNC_HUP_NOTIFY)
906 /* if non-blocking mode is set ... */
908 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
909 pr_dbg("block_til_ready: non-block mode.\n");
910 port->flags |= ASYNC_NORMAL_ACTIVE;
917 /* block waiting for DCD to be asserted, and while
918 callout dev is busy */
920 add_wait_queue(&port->open_wait, &wait);
922 spin_lock_irqsave(&card->card_lock, flags);
923 if (!tty_hung_up_p(filp))
925 port->blocked_open++;
926 spin_unlock_irqrestore(&card->card_lock, flags);
931 set_current_state(TASK_INTERRUPTIBLE);
932 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
933 if (port->flags & ASYNC_HUP_NOTIFY)
936 retval = -ERESTARTSYS;
939 if (!(port->flags & ASYNC_CLOSING) &&
940 (do_clocal || (port->status & ISI_DCD))) {
943 if (signal_pending(current)) {
944 retval = -ERESTARTSYS;
949 set_current_state(TASK_RUNNING);
950 remove_wait_queue(&port->open_wait, &wait);
951 spin_lock_irqsave(&card->card_lock, flags);
952 if (!tty_hung_up_p(filp))
954 port->blocked_open--;
955 spin_unlock_irqrestore(&card->card_lock, flags);
958 port->flags |= ASYNC_NORMAL_ACTIVE;
962 static int isicom_open(struct tty_struct *tty, struct file *filp)
964 struct isi_port *port;
965 struct isi_board *card;
966 unsigned int line, board;
970 if (line < 0 || line > PORT_COUNT-1)
973 card = &isi_card[board];
975 if (!(card->status & FIRMWARE_LOADED))
978 /* open on a port greater than the port count for the card !!! */
979 if (line > ((board * 16) + card->port_count - 1))
982 port = &isi_ports[line];
983 if (isicom_paranoia_check(port, tty->name, "isicom_open"))
986 isicom_setup_board(card);
989 tty->driver_data = port;
991 if ((error = isicom_setup_port(port))!=0)
993 if ((error = block_til_ready(tty, filp, port))!=0)
1001 static inline void isicom_shutdown_board(struct isi_board *bp)
1003 unsigned long flags;
1005 spin_lock_irqsave(&bp->card_lock, flags);
1006 if (bp->status & BOARD_ACTIVE) {
1007 bp->status &= ~BOARD_ACTIVE;
1009 spin_unlock_irqrestore(&bp->card_lock, flags);
1012 static void isicom_shutdown_port(struct isi_port *port)
1014 struct isi_board *card = port->card;
1015 struct tty_struct *tty;
1016 unsigned long flags;
1020 spin_lock_irqsave(&card->card_lock, flags);
1021 if (!(port->flags & ASYNC_INITIALIZED)) {
1022 spin_unlock_irqrestore(&card->card_lock, flags);
1025 if (port->xmit_buf) {
1026 free_page((unsigned long) port->xmit_buf);
1027 port->xmit_buf = NULL;
1029 port->flags &= ~ASYNC_INITIALIZED;
1030 /* 3rd October 2000 : Vinayak P Risbud */
1032 spin_unlock_irqrestore(&card->card_lock, flags);
1034 /*Fix done by Anil .S on 30-04-2001
1035 remote login through isi port has dtr toggle problem
1036 due to which the carrier drops before the password prompt
1037 appears on the remote end. Now we drop the dtr only if the
1038 HUPCL(Hangup on close) flag is set for the tty*/
1041 /* drop dtr on this port */
1044 /* any other port uninits */
1046 set_bit(TTY_IO_ERROR, &tty->flags);
1048 if (--card->count < 0) {
1049 pr_dbg("isicom_shutdown_port: bad board(0x%lx) count %d.\n",
1050 card->base, card->count);
1054 /* last port was closed , shutdown that boad too */
1057 isicom_shutdown_board(card);
1061 static void isicom_close(struct tty_struct *tty, struct file *filp)
1063 struct isi_port *port = tty->driver_data;
1064 struct isi_board *card = port->card;
1065 unsigned long flags;
1069 if (isicom_paranoia_check(port, tty->name, "isicom_close"))
1072 pr_dbg("Close start!!!.\n");
1074 spin_lock_irqsave(&card->card_lock, flags);
1075 if (tty_hung_up_p(filp)) {
1076 spin_unlock_irqrestore(&card->card_lock, flags);
1080 if (tty->count == 1 && port->count != 1) {
1081 printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port count"
1082 "tty->count = 1 port count = %d.\n",
1083 card->base, port->count);
1086 if (--port->count < 0) {
1087 printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port count for"
1088 "channel%d = %d", card->base, port->channel,
1094 spin_unlock_irqrestore(&card->card_lock, flags);
1097 port->flags |= ASYNC_CLOSING;
1099 spin_unlock_irqrestore(&card->card_lock, flags);
1101 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1102 tty_wait_until_sent(tty, port->closing_wait);
1103 /* indicate to the card that no more data can be received
1105 spin_lock_irqsave(&card->card_lock, flags);
1106 if (port->flags & ASYNC_INITIALIZED) {
1107 card->port_status &= ~(1 << port->channel);
1108 outw(card->port_status, card->base + 0x02);
1110 isicom_shutdown_port(port);
1111 spin_unlock_irqrestore(&card->card_lock, flags);
1113 if (tty->driver->flush_buffer)
1114 tty->driver->flush_buffer(tty);
1115 tty_ldisc_flush(tty);
1117 spin_lock_irqsave(&card->card_lock, flags);
1120 if (port->blocked_open) {
1121 spin_unlock_irqrestore(&card->card_lock, flags);
1122 if (port->close_delay) {
1123 pr_dbg("scheduling until time out.\n");
1124 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1126 spin_lock_irqsave(&card->card_lock, flags);
1127 wake_up_interruptible(&port->open_wait);
1129 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1130 wake_up_interruptible(&port->close_wait);
1131 spin_unlock_irqrestore(&card->card_lock, flags);
1135 static int isicom_write(struct tty_struct *tty, const unsigned char *buf,
1138 struct isi_port *port = tty->driver_data;
1139 struct isi_board *card = port->card;
1140 unsigned long flags;
1143 if (isicom_paranoia_check(port, tty->name, "isicom_write"))
1146 if (!tty || !port->xmit_buf)
1149 spin_lock_irqsave(&card->card_lock, flags);
1152 cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1153 SERIAL_XMIT_SIZE - port->xmit_head));
1157 memcpy(port->xmit_buf + port->xmit_head, buf, cnt);
1158 port->xmit_head = (port->xmit_head + cnt) & (SERIAL_XMIT_SIZE - 1);
1159 port->xmit_cnt += cnt;
1164 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped)
1165 port->status |= ISI_TXOK;
1166 spin_unlock_irqrestore(&card->card_lock, flags);
1170 /* put_char et all */
1171 static void isicom_put_char(struct tty_struct *tty, unsigned char ch)
1173 struct isi_port *port = tty->driver_data;
1174 struct isi_board *card = port->card;
1175 unsigned long flags;
1177 if (isicom_paranoia_check(port, tty->name, "isicom_put_char"))
1180 if (!tty || !port->xmit_buf)
1183 spin_lock_irqsave(&card->card_lock, flags);
1184 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1185 spin_unlock_irqrestore(&card->card_lock, flags);
1189 port->xmit_buf[port->xmit_head++] = ch;
1190 port->xmit_head &= (SERIAL_XMIT_SIZE - 1);
1192 spin_unlock_irqrestore(&card->card_lock, flags);
1195 /* flush_chars et all */
1196 static void isicom_flush_chars(struct tty_struct *tty)
1198 struct isi_port *port = tty->driver_data;
1200 if (isicom_paranoia_check(port, tty->name, "isicom_flush_chars"))
1203 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || !port->xmit_buf)
1206 /* this tells the transmitter to consider this port for
1207 data output to the card ... that's the best we can do. */
1208 port->status |= ISI_TXOK;
1211 /* write_room et all */
1212 static int isicom_write_room(struct tty_struct *tty)
1214 struct isi_port *port = tty->driver_data;
1217 if (isicom_paranoia_check(port, tty->name, "isicom_write_room"))
1220 free = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1226 /* chars_in_buffer et all */
1227 static int isicom_chars_in_buffer(struct tty_struct *tty)
1229 struct isi_port *port = tty->driver_data;
1230 if (isicom_paranoia_check(port, tty->name, "isicom_chars_in_buffer"))
1232 return port->xmit_cnt;
1236 static inline void isicom_send_break(struct isi_port *port, unsigned long length)
1238 struct isi_board *card = port->card;
1239 unsigned long base = card->base;
1241 if (!lock_card(card))
1244 outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base);
1245 outw((length & 0xff) << 8 | 0x00, base);
1246 outw((length & 0xff00), base);
1247 InterruptTheCard(base);
1252 static int isicom_tiocmget(struct tty_struct *tty, struct file *file)
1254 struct isi_port *port = tty->driver_data;
1255 /* just send the port status */
1256 u16 status = port->status;
1258 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1261 return ((status & ISI_RTS) ? TIOCM_RTS : 0) |
1262 ((status & ISI_DTR) ? TIOCM_DTR : 0) |
1263 ((status & ISI_DCD) ? TIOCM_CAR : 0) |
1264 ((status & ISI_DSR) ? TIOCM_DSR : 0) |
1265 ((status & ISI_CTS) ? TIOCM_CTS : 0) |
1266 ((status & ISI_RI ) ? TIOCM_RI : 0);
1269 static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
1270 unsigned int set, unsigned int clear)
1272 struct isi_port *port = tty->driver_data;
1274 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1277 if (set & TIOCM_RTS)
1279 if (set & TIOCM_DTR)
1282 if (clear & TIOCM_RTS)
1284 if (clear & TIOCM_DTR)
1290 static int isicom_set_serial_info(struct isi_port *port,
1291 struct serial_struct __user *info)
1293 struct serial_struct newinfo;
1296 if (copy_from_user(&newinfo, info, sizeof(newinfo)))
1299 reconfig_port = ((port->flags & ASYNC_SPD_MASK) !=
1300 (newinfo.flags & ASYNC_SPD_MASK));
1302 if (!capable(CAP_SYS_ADMIN)) {
1303 if ((newinfo.close_delay != port->close_delay) ||
1304 (newinfo.closing_wait != port->closing_wait) ||
1305 ((newinfo.flags & ~ASYNC_USR_MASK) !=
1306 (port->flags & ~ASYNC_USR_MASK)))
1308 port->flags = ((port->flags & ~ ASYNC_USR_MASK) |
1309 (newinfo.flags & ASYNC_USR_MASK));
1312 port->close_delay = newinfo.close_delay;
1313 port->closing_wait = newinfo.closing_wait;
1314 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1315 (newinfo.flags & ASYNC_FLAGS));
1317 if (reconfig_port) {
1318 isicom_config_port(port);
1323 static int isicom_get_serial_info(struct isi_port *port,
1324 struct serial_struct __user *info)
1326 struct serial_struct out_info;
1328 memset(&out_info, 0, sizeof(out_info));
1329 /* out_info.type = ? */
1330 out_info.line = port - isi_ports;
1331 out_info.port = port->card->base;
1332 out_info.irq = port->card->irq;
1333 out_info.flags = port->flags;
1334 /* out_info.baud_base = ? */
1335 out_info.close_delay = port->close_delay;
1336 out_info.closing_wait = port->closing_wait;
1337 if (copy_to_user(info, &out_info, sizeof(out_info)))
1342 static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1343 unsigned int cmd, unsigned long arg)
1345 struct isi_port *port = tty->driver_data;
1346 void __user *argp = (void __user *)arg;
1349 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1354 retval = tty_check_change(tty);
1357 tty_wait_until_sent(tty, 0);
1359 isicom_send_break(port, HZ/4);
1363 retval = tty_check_change(tty);
1366 tty_wait_until_sent(tty, 0);
1367 isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4);
1371 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1374 if (get_user(arg, (unsigned long __user *) argp))
1376 tty->termios->c_cflag =
1377 ((tty->termios->c_cflag & ~CLOCAL) |
1378 (arg ? CLOCAL : 0));
1382 return isicom_get_serial_info(port, argp);
1385 return isicom_set_serial_info(port, argp);
1388 return -ENOIOCTLCMD;
1393 /* set_termios et all */
1394 static void isicom_set_termios(struct tty_struct *tty,
1395 struct termios *old_termios)
1397 struct isi_port *port = tty->driver_data;
1399 if (isicom_paranoia_check(port, tty->name, "isicom_set_termios"))
1402 if (tty->termios->c_cflag == old_termios->c_cflag &&
1403 tty->termios->c_iflag == old_termios->c_iflag)
1406 isicom_config_port(port);
1408 if ((old_termios->c_cflag & CRTSCTS) &&
1409 !(tty->termios->c_cflag & CRTSCTS)) {
1410 tty->hw_stopped = 0;
1415 /* throttle et all */
1416 static void isicom_throttle(struct tty_struct *tty)
1418 struct isi_port *port = tty->driver_data;
1419 struct isi_board *card = port->card;
1421 if (isicom_paranoia_check(port, tty->name, "isicom_throttle"))
1424 /* tell the card that this port cannot handle any more data for now */
1425 card->port_status &= ~(1 << port->channel);
1426 outw(card->port_status, card->base + 0x02);
1429 /* unthrottle et all */
1430 static void isicom_unthrottle(struct tty_struct *tty)
1432 struct isi_port *port = tty->driver_data;
1433 struct isi_board *card = port->card;
1435 if (isicom_paranoia_check(port, tty->name, "isicom_unthrottle"))
1438 /* tell the card that this port is ready to accept more data */
1439 card->port_status |= (1 << port->channel);
1440 outw(card->port_status, card->base + 0x02);
1444 static void isicom_stop(struct tty_struct *tty)
1446 struct isi_port *port = tty->driver_data;
1448 if (isicom_paranoia_check(port, tty->name, "isicom_stop"))
1451 /* this tells the transmitter not to consider this port for
1452 data output to the card. */
1453 port->status &= ~ISI_TXOK;
1457 static void isicom_start(struct tty_struct *tty)
1459 struct isi_port *port = tty->driver_data;
1461 if (isicom_paranoia_check(port, tty->name, "isicom_start"))
1464 /* this tells the transmitter to consider this port for
1465 data output to the card. */
1466 port->status |= ISI_TXOK;
1470 static void do_isicom_hangup(void *data)
1472 struct isi_port *port = data;
1473 struct tty_struct *tty;
1480 static void isicom_hangup(struct tty_struct *tty)
1482 struct isi_port *port = tty->driver_data;
1484 if (isicom_paranoia_check(port, tty->name, "isicom_hangup"))
1487 isicom_shutdown_port(port);
1489 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1491 wake_up_interruptible(&port->open_wait);
1494 /* flush_buffer et all */
1495 static void isicom_flush_buffer(struct tty_struct *tty)
1497 struct isi_port *port = tty->driver_data;
1498 struct isi_board *card = port->card;
1499 unsigned long flags;
1501 if (isicom_paranoia_check(port, tty->name, "isicom_flush_buffer"))
1504 spin_lock_irqsave(&card->card_lock, flags);
1505 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1506 spin_unlock_irqrestore(&card->card_lock, flags);
1508 wake_up_interruptible(&tty->write_wait);
1513 * Driver init and deinit functions
1516 static int __devinit isicom_register_ioregion(struct pci_dev *pdev,
1517 const unsigned int index)
1519 struct isi_board *board = pci_get_drvdata(pdev);
1524 if (!request_region(board->base, 16, ISICOM_NAME)) {
1525 dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d "
1526 "will be disabled.\n", board->base, board->base + 15,
1534 static void isicom_unregister_ioregion(struct pci_dev *pdev)
1536 struct isi_board *board = pci_get_drvdata(pdev);
1541 release_region(board->base, 16);
1542 dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx released.\n",
1543 board->base, board->base + 15);
1547 static struct tty_operations isicom_ops = {
1548 .open = isicom_open,
1549 .close = isicom_close,
1550 .write = isicom_write,
1551 .put_char = isicom_put_char,
1552 .flush_chars = isicom_flush_chars,
1553 .write_room = isicom_write_room,
1554 .chars_in_buffer = isicom_chars_in_buffer,
1555 .ioctl = isicom_ioctl,
1556 .set_termios = isicom_set_termios,
1557 .throttle = isicom_throttle,
1558 .unthrottle = isicom_unthrottle,
1559 .stop = isicom_stop,
1560 .start = isicom_start,
1561 .hangup = isicom_hangup,
1562 .flush_buffer = isicom_flush_buffer,
1563 .tiocmget = isicom_tiocmget,
1564 .tiocmset = isicom_tiocmset,
1567 static int __devinit isicom_register_tty_driver(void)
1569 int error = -ENOMEM;
1571 /* tty driver structure initialization */
1572 isicom_normal = alloc_tty_driver(PORT_COUNT);
1576 isicom_normal->owner = THIS_MODULE;
1577 isicom_normal->name = "ttyM";
1578 isicom_normal->devfs_name = "isicom/";
1579 isicom_normal->major = ISICOM_NMAJOR;
1580 isicom_normal->minor_start = 0;
1581 isicom_normal->type = TTY_DRIVER_TYPE_SERIAL;
1582 isicom_normal->subtype = SERIAL_TYPE_NORMAL;
1583 isicom_normal->init_termios = tty_std_termios;
1584 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
1586 isicom_normal->flags = TTY_DRIVER_REAL_RAW;
1587 tty_set_operations(isicom_normal, &isicom_ops);
1589 if ((error = tty_register_driver(isicom_normal))) {
1590 pr_dbg("Couldn't register the dialin driver, error=%d\n",
1592 put_tty_driver(isicom_normal);
1598 static void isicom_unregister_tty_driver(void)
1602 if ((error = tty_unregister_driver(isicom_normal)))
1603 pr_dbg("couldn't unregister normal driver, error=%d.\n", error);
1605 put_tty_driver(isicom_normal);
1608 static int __devinit isicom_register_isr(struct pci_dev *pdev,
1609 const unsigned int index)
1611 struct isi_board *board = pci_get_drvdata(pdev);
1612 unsigned long irqflags = SA_INTERRUPT;
1613 int retval = -EINVAL;
1618 if (board->isa == NO)
1619 irqflags |= SA_SHIRQ;
1621 retval = request_irq(board->irq, isicom_interrupt, irqflags,
1622 ISICOM_NAME, board);
1624 dev_warn(&pdev->dev, "Could not install handler at Irq %d. "
1625 "Card%d will be disabled.\n", board->irq, index + 1);
1632 static int __devinit reset_card(struct pci_dev *pdev,
1633 const unsigned int card, unsigned int *signature)
1635 struct isi_board *board = pci_get_drvdata(pdev);
1636 unsigned long base = board->base;
1637 unsigned int portcount = 0;
1640 dev_dbg(&pdev->dev, "ISILoad:Resetting Card%d at 0x%lx\n", card + 1,
1647 outw(0, base + 0x8); /* Reset */
1651 *signature = inw(base + 0x4) & 0xff;
1653 if (board->isa == YES) {
1654 if (!(inw(base + 0xe) & 0x1) || (inw(base + 0x2))) {
1655 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
1656 inw(base + 0x2), inw(base + 0xe));
1657 dev_err(&pdev->dev, "ISILoad:ISA Card%d reset failure "
1658 "(Possible bad I/O Port Address 0x%lx).\n",
1664 portcount = inw(base + 0x2);
1665 if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) &&
1666 (portcount != 4) && (portcount != 8))) {
1667 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
1668 inw(base + 0x2), inw(base + 0xe));
1669 dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure "
1670 "(Possible bad I/O Port Address 0x%lx).\n",
1677 switch (*signature) {
1681 board->port_count = (board->isa == NO && portcount == 4) ? 4 :
1683 board->shift_count = 12;
1686 board->port_count = 16;
1687 board->shift_count = 11;
1690 dev_warn(&pdev->dev, "ISILoad:Card%d reset failure (Possible "
1691 "bad I/O Port Address 0x%lx).\n", card + 1, base);
1692 dev_dbg(&pdev->dev, "Sig=0x%lx\n", signature);
1695 dev_info(&pdev->dev, "-Done\n");
1701 static inline int WaitTillCardIsFree(u16 base)
1703 unsigned long count = 0;
1705 while (!(inw(base + 0xe) & 0x1) && count++ < 100)
1708 return !(inw(base + 0xe) & 0x1);
1711 static int __devinit load_firmware(struct pci_dev *pdev,
1712 const unsigned int index, const unsigned int signature)
1714 struct isi_board *board = pci_get_drvdata(pdev);
1715 const struct firmware *fw;
1716 unsigned long base = board->base;
1718 u16 word_count, status;
1729 switch (signature) {
1731 name = "isi608.bin";
1734 name = "isi608em.bin";
1737 name = "isi616em.bin";
1740 name = "isi4608.bin";
1743 name = "isi4616.bin";
1746 dev_err(&pdev->dev, "Unknown signature.\n");
1750 retval = request_firmware(&fw, name, &pdev->dev);
1754 for (frame = (struct stframe *)fw->data;
1755 frame < (struct stframe *)(fw->data + fw->size);
1757 if (WaitTillCardIsFree(base))
1760 outw(0xf0, base); /* start upload sequence */
1762 outw(frame->addr, base); /* lsb of address */
1764 word_count = frame->count / 2 + frame->count % 2;
1765 outw(word_count, base);
1766 InterruptTheCard(base);
1768 udelay(100); /* 0x2f */
1770 if (WaitTillCardIsFree(base))
1773 if ((status = inw(base + 0x4)) != 0) {
1774 dev_warn(&pdev->dev, "Card%d rejected load header:\n"
1775 "Address:0x%x\nCount:0x%x\nStatus:0x%x\n",
1776 index + 1, frame->addr, frame->count, status);
1779 outsw(base, frame->data, word_count);
1781 InterruptTheCard(base);
1783 udelay(50); /* 0x0f */
1785 if (WaitTillCardIsFree(base))
1788 if ((status = inw(base + 0x4)) != 0) {
1789 dev_err(&pdev->dev, "Card%d got out of sync.Card "
1790 "Status:0x%x\n", index + 1, status);
1797 if (WaitTillCardIsFree(base))
1804 InterruptTheCard(base);
1805 outw(0x0, base + 0x4); /* for ISI4608 cards */
1807 /* XXX: should we test it by reading it back and comparing with original like
1808 * in load firmware package? */
1809 for (frame = (struct stframe*)fw->data;
1810 frame < (struct stframe*)(fw->data + fw->size);
1812 if (WaitTillCardIsFree(base))
1815 outw(0xf1, base); /* start download sequence */
1817 outw(frame->addr, base); /* lsb of address */
1819 word_count = (frame->count >> 1) + frame->count % 2;
1820 outw(word_count + 1, base);
1821 InterruptTheCard(base);
1823 udelay(50); /* 0xf */
1825 if (WaitTillCardIsFree(base))
1828 if ((status = inw(base + 0x4)) != 0) {
1829 dev_warn(&pdev->dev, "Card%d rejected verify header:\n"
1830 "Address:0x%x\nCount:0x%x\nStatus: 0x%x\n",
1831 index + 1, frame->addr, frame->count, status);
1835 data = kmalloc(word_count * 2, GFP_KERNEL);
1837 insw(base, data, word_count);
1838 InterruptTheCard(base);
1840 for (a = 0; a < frame->count; a++)
1841 if (data[a] != frame->data[a]) {
1843 dev_err(&pdev->dev, "Card%d, firmware upload "
1844 "failed\n", index + 1);
1849 udelay(50); /* 0xf */
1851 if (WaitTillCardIsFree(base))
1854 if ((status = inw(base + 0x4)) != 0) {
1855 dev_err(&pdev->dev, "Card%d verify got out of sync. "
1856 "Card Status:0x%x\n", index + 1, status);
1861 board->status |= FIRMWARE_LOADED;
1865 release_firmware(fw);
1871 * Insmod can set static symbols so keep these static
1877 static int __devinit isicom_probe(struct pci_dev *pdev,
1878 const struct pci_device_id *ent)
1880 unsigned int ioaddr, signature, index;
1881 int retval = -EPERM;
1883 struct isi_board *board = NULL;
1885 if (card >= BOARD_COUNT)
1888 ioaddr = pci_resource_start(pdev, 3);
1889 /* i.e at offset 0x1c in the PCI configuration register space. */
1891 dev_info(&pdev->dev, "ISI PCI Card(Device ID 0x%x)\n", ent->device);
1893 /* allot the first empty slot in the array */
1894 for (index = 0; index < BOARD_COUNT; index++)
1895 if (isi_card[index].base == 0) {
1896 board = &isi_card[index];
1900 board->base = ioaddr;
1901 board->irq = pciirq;
1905 pci_set_drvdata(pdev, board);
1907 retval = isicom_register_ioregion(pdev, index);
1911 retval = isicom_register_isr(pdev, index);
1915 retval = reset_card(pdev, index, &signature);
1919 retval = load_firmware(pdev, index, signature);
1926 free_irq(board->irq, board);
1928 isicom_unregister_ioregion(pdev);
1934 static void __devexit isicom_remove(struct pci_dev *pdev)
1936 struct isi_board *board = pci_get_drvdata(pdev);
1938 free_irq(board->irq, board);
1939 isicom_unregister_ioregion(pdev);
1942 static int __devinit isicom_setup(void)
1944 int retval, idx, channel;
1945 struct isi_port *port;
1948 memset(isi_ports, 0, sizeof(isi_ports));
1950 for(idx = 0; idx < BOARD_COUNT; idx++) {
1951 port = &isi_ports[idx * 16];
1952 isi_card[idx].ports = port;
1953 spin_lock_init(&isi_card[idx].card_lock);
1954 for (channel = 0; channel < 16; channel++, port++) {
1955 port->magic = ISICOM_MAGIC;
1956 port->card = &isi_card[idx];
1957 port->channel = channel;
1958 port->close_delay = 50 * HZ/100;
1959 port->closing_wait = 3000 * HZ/100;
1960 INIT_WORK(&port->hangup_tq, do_isicom_hangup, port);
1961 INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port);
1963 init_waitqueue_head(&port->open_wait);
1964 init_waitqueue_head(&port->close_wait);
1967 isi_card[idx].base = 0;
1968 isi_card[idx].irq = 0;
1973 if (irq[idx] == 2 || irq[idx] == 3 || irq[idx] == 4 ||
1974 irq[idx] == 5 || irq[idx] == 7 ||
1975 irq[idx] == 10 || irq[idx] == 11 ||
1976 irq[idx] == 12 || irq[idx] == 15) {
1977 printk(KERN_ERR "ISICOM: ISA not supported yet.\n");
1981 printk(KERN_ERR "ISICOM: Irq %d unsupported. "
1982 "Disabling Card%d...\n", irq[idx], idx + 1);
1985 retval = isicom_register_tty_driver();
1989 retval = pci_register_driver(&isicom_driver);
1991 printk(KERN_ERR "ISICOM: Unable to register pci driver.\n");
1996 tx.expires = jiffies + 1;
1998 tx.function = isicom_tx;
2004 isicom_unregister_tty_driver();
2009 static void __exit isicom_exit(void)
2011 unsigned int index = 0;
2015 while (re_schedule != 2 && index++ < 100)
2018 pci_unregister_driver(&isicom_driver);
2019 isicom_unregister_tty_driver();
2022 module_init(isicom_setup);
2023 module_exit(isicom_exit);
2025 MODULE_AUTHOR("MultiTech");
2026 MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
2027 MODULE_LICENSE("GPL");
2028 module_param_array(io, int, NULL, 0);
2029 MODULE_PARM_DESC(io, "I/O ports for the cards");
2030 module_param_array(irq, int, NULL, 0);
2031 MODULE_PARM_DESC(irq, "Interrupts for the cards");