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.
19 * ***********************************************************
21 * To use this driver you also need the support package. You
22 * can find this in RPM format on
23 * ftp://ftp.linux.org.uk/pub/linux/alan
25 * You can find the original tools for this direct from Multitech
26 * ftp://ftp.multitech.com/ISI-Cards/
28 * Having installed the cards the module options (/etc/modules.conf)
30 * options isicom io=card1,card2,card3,card4 irq=card1,card2,card3,card4
32 * Omit those entries for boards you don't have installed.
36 #include <linux/module.h>
37 #include <linux/version.h>
38 #include <linux/kernel.h>
39 #include <linux/tty.h>
40 #include <linux/termios.h>
42 #include <linux/sched.h>
43 #include <linux/serial.h>
45 #include <linux/miscdevice.h>
46 #include <linux/interrupt.h>
47 #include <linux/timer.h>
48 #include <linux/ioport.h>
50 #include <asm/segment.h>
51 #include <asm/uaccess.h>
53 #include <asm/system.h>
55 #include <linux/pci.h>
57 #include <linux/isicom.h>
59 static int device_id
[] = { 0x2028,
70 static int isicom_refcount
= 0;
71 static int prev_card
= 3; /* start servicing isi_card[0] */
72 static struct isi_board
* irq_to_board
[16] = { NULL
, };
73 static struct tty_driver isicom_normal
, isicom_callout
;
74 static struct tty_struct
* isicom_table
[PORT_COUNT
] = { NULL
, };
75 static struct termios
* isicom_termios
[PORT_COUNT
] = { NULL
, };
76 static struct termios
* isicom_termios_locked
[PORT_COUNT
] = { NULL
, };
78 static struct isi_board isi_card
[BOARD_COUNT
];
79 static struct isi_port isi_ports
[PORT_COUNT
];
81 DECLARE_TASK_QUEUE(tq_isicom
);
83 static struct timer_list tx
;
84 static char re_schedule
= 1;
86 static unsigned long tx_count
= 0;
89 static int ISILoad_ioctl(struct inode
*inode
, struct file
*filp
, unsigned int cmd
, unsigned long arg
);
91 static void isicom_tx(unsigned long _data
);
92 static void isicom_start(struct tty_struct
* tty
);
94 static unsigned char * tmp_buf
= 0;
95 static DECLARE_MUTEX(tmp_buf_sem
);
97 /* baud index mappings from linux defns to isi */
99 static signed char linuxb_to_isib
[] = {
100 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17,
105 * Firmware loader driver specific routines
109 static struct file_operations ISILoad_fops
= {
111 ioctl
: ISILoad_ioctl
,
114 struct miscdevice isiloader_device
= {
115 ISILOAD_MISC_MINOR
, "isictl", &ISILoad_fops
119 extern inline int WaitTillCardIsFree(unsigned short base
)
121 unsigned long count
=0;
122 while( (!(inw(base
+0xe) & 0x1)) && (count
++ < 6000000));
123 if (inw(base
+0xe)&0x1)
129 static int ISILoad_ioctl(struct inode
*inode
, struct file
*filp
,
130 unsigned int cmd
, unsigned long arg
)
132 unsigned int card
, i
, j
, signature
, status
, portcount
= 0;
133 unsigned short word_count
, base
;
135 /* exec_record exec_rec; */
137 if(get_user(card
, (int *)arg
))
140 if(card
< 0 || card
>= BOARD_COUNT
)
143 base
=isi_card
[card
].base
;
146 return -ENXIO
; /* disabled or not used */
149 case MIOCTL_RESET_CARD
:
150 if (!capable(CAP_SYS_ADMIN
))
152 printk(KERN_DEBUG
"ISILoad:Resetting Card%d at 0x%x ",card
+1,base
);
156 for(i
=jiffies
+HZ
/100;time_before(jiffies
, i
););
158 outw(0,base
+0x8); /* Reset */
161 for(i
=jiffies
+HZ
;time_before(jiffies
, i
););
164 signature
=(inw(base
+0x4)) & 0xff;
165 if (isi_card
[card
].isa
) {
167 if (!(inw(base
+0xe) & 0x1) || (inw(base
+0x2))) {
169 printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base
+0x2),inw(base
+0xe));
171 printk("\nISILoad:ISA Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card
+1,base
);
176 portcount
= inw(base
+0x2);
177 if (!(inw(base
+0xe) & 0x1) || ((portcount
!=0) && (portcount
!=4) && (portcount
!=8))) {
179 printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base
+0x2),inw(base
+0xe));
181 printk("\nISILoad:PCI Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card
+1,base
);
189 if (isi_card
[card
].isa
)
190 isi_card
[card
].port_count
= 8;
193 isi_card
[card
].port_count
= 4;
195 isi_card
[card
].port_count
= 8;
197 isi_card
[card
].shift_count
= 12;
200 case 0xcc: isi_card
[card
].port_count
= 16;
201 isi_card
[card
].shift_count
= 11;
204 default: printk("ISILoad:Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card
+1,base
);
206 printk("Sig=0x%x\n",signature
);
211 return put_user(signature
,(unsigned int*)arg
);
213 case MIOCTL_LOAD_FIRMWARE
:
214 if (!capable(CAP_SYS_ADMIN
))
217 if(copy_from_user(&frame
, (void *) arg
, sizeof(bin_frame
)))
220 if (WaitTillCardIsFree(base
))
223 outw(0xf0,base
); /* start upload sequence */
225 outw((frame
.addr
), base
);/* lsb of adderess */
227 word_count
=(frame
.count
>> 1) + frame
.count
% 2;
228 outw(word_count
, base
);
229 InterruptTheCard(base
);
231 for(i
=0;i
<=0x2f;i
++); /* a wee bit of delay */
233 if (WaitTillCardIsFree(base
))
236 if ((status
=inw(base
+0x4))!=0) {
237 printk(KERN_WARNING
"ISILoad:Card%d rejected load header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n",
238 card
+1, frame
.addr
, frame
.count
, status
);
241 outsw(base
, (void *) frame
.bin_data
, word_count
);
243 InterruptTheCard(base
);
245 for(i
=0;i
<=0x0f;i
++); /* another wee bit of delay */
247 if (WaitTillCardIsFree(base
))
250 if ((status
=inw(base
+0x4))!=0) {
251 printk(KERN_ERR
"ISILoad:Card%d got out of sync.Card Status:0x%x\n",card
+1, status
);
256 case MIOCTL_READ_FIRMWARE
:
257 if (!capable(CAP_SYS_ADMIN
))
260 if(copy_from_user(&frame
, (void *) arg
, sizeof(bin_header
)))
263 if (WaitTillCardIsFree(base
))
266 outw(0xf1,base
); /* start download sequence */
268 outw((frame
.addr
), base
);/* lsb of adderess */
270 word_count
=(frame
.count
>> 1) + frame
.count
% 2;
271 outw(word_count
+1, base
);
272 InterruptTheCard(base
);
274 for(i
=0;i
<=0xf;i
++); /* a wee bit of delay */
276 if (WaitTillCardIsFree(base
))
279 if ((status
=inw(base
+0x4))!=0) {
280 printk(KERN_WARNING
"ISILoad:Card%d rejected verify header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n",
281 card
+1, frame
.addr
, frame
.count
, status
);
286 insw(base
, frame
.bin_data
, word_count
);
287 InterruptTheCard(base
);
289 for(i
=0;i
<=0x0f;i
++); /* another wee bit of delay */
291 if (WaitTillCardIsFree(base
))
294 if ((status
=inw(base
+0x4))!=0) {
295 printk(KERN_ERR
"ISILoad:Card%d verify got out of sync.Card Status:0x%x\n",card
+1, status
);
299 if(copy_to_user((void *) arg
, &frame
, sizeof(bin_frame
)))
303 case MIOCTL_XFER_CTRL
:
304 if (!capable(CAP_SYS_ADMIN
))
306 if (WaitTillCardIsFree(base
))
313 InterruptTheCard(base
);
314 outw(0x0, base
+0x4); /* for ISI4608 cards */
316 isi_card
[card
].status
|= FIRMWARE_LOADED
;
321 printk(KERN_DEBUG
"ISILoad: Received Ioctl cmd 0x%x.\n", cmd
);
331 * ISICOM Driver specific routines ...
335 static inline int isicom_paranoia_check(struct isi_port
const * port
, kdev_t dev
,
336 const char * routine
)
339 static const char * badmagic
=
340 KERN_WARNING
"ISICOM: Warning: bad isicom magic for dev %s in %s.\n";
341 static const char * badport
=
342 KERN_WARNING
"ISICOM: Warning: NULL isicom port for dev %s in %s.\n";
344 printk(badport
, kdevname(dev
), routine
);
347 if (port
->magic
!= ISICOM_MAGIC
) {
348 printk(badmagic
, kdevname(dev
), routine
);
355 extern inline void schedule_bh(struct isi_port
* port
)
357 queue_task(&port
->bh_tqueue
, &tq_isicom
);
363 static void isicom_tx(unsigned long _data
)
365 short count
= (BOARD_COUNT
-1), card
, base
;
366 short txcount
, wait
, wrd
, residue
, word_count
, cnt
;
367 struct isi_port
* port
;
368 struct tty_struct
* tty
;
375 /* find next active board */
376 card
= (prev_card
+ 1) & 0x0003;
378 if (isi_card
[card
].status
& BOARD_ACTIVE
)
380 card
= (card
+ 1) & 0x0003;
382 if (!(isi_card
[card
].status
& BOARD_ACTIVE
))
387 count
= isi_card
[card
].port_count
;
388 port
= isi_card
[card
].ports
;
389 base
= isi_card
[card
].base
;
390 for (;count
> 0;count
--, port
++) {
391 /* port not active or tx disabled to force flow control */
392 if (!(port
->status
& ISI_TXOK
))
396 save_flags(flags
); cli();
397 txcount
= MIN(TX_SIZE
, port
->xmit_cnt
);
398 if ((txcount
<= 0) || tty
->stopped
|| tty
->hw_stopped
) {
399 restore_flags(flags
);
403 while(((inw(base
+0x0e) & 0x01) == 0) && (wait
-- > 0));
405 restore_flags(flags
);
407 printk(KERN_DEBUG
"ISICOM: isicom_tx:Card(0x%x) found busy.\n",
412 if (!(inw(base
+ 0x02) & (1 << port
->channel
))) {
413 restore_flags(flags
);
415 printk(KERN_DEBUG
"ISICOM: isicom_tx: cannot tx to 0x%x:%d.\n",
416 base
, port
->channel
+ 1);
421 printk(KERN_DEBUG
"ISICOM: txing %d bytes, port%d.\n",
422 txcount
, port
->channel
+1);
424 outw((port
->channel
<< isi_card
[card
].shift_count
) | txcount
429 cnt
= MIN(txcount
, (SERIAL_XMIT_SIZE
- port
->xmit_tail
));
430 if (residue
== YES
) {
433 wrd
|= (port
->xmit_buf
[port
->xmit_tail
] << 8);
434 port
->xmit_tail
= (port
->xmit_tail
+ 1) & (SERIAL_XMIT_SIZE
- 1);
446 word_count
= cnt
>> 1;
447 outsw(base
, port
->xmit_buf
+port
->xmit_tail
, word_count
);
448 port
->xmit_tail
= (port
->xmit_tail
+ (word_count
<< 1)) &
449 (SERIAL_XMIT_SIZE
- 1);
450 txcount
-= (word_count
<< 1);
451 port
->xmit_cnt
-= (word_count
<< 1);
454 wrd
= port
->xmit_buf
[port
->xmit_tail
];
455 port
->xmit_tail
= (port
->xmit_tail
+ 1) & (SERIAL_XMIT_SIZE
- 1);
461 InterruptTheCard(base
);
462 if (port
->xmit_cnt
<= 0)
463 port
->status
&= ~ISI_TXOK
;
464 if (port
->xmit_cnt
<= WAKEUP_CHARS
)
466 restore_flags(flags
);
469 /* schedule another tx for hopefully in about 10ms */
474 tx
.expires
= jiffies
+ HZ
/100;
476 tx
.function
= isicom_tx
;
482 /* Interrupt handlers */
484 static void do_isicom_bh(void)
486 run_task_queue(&tq_isicom
);
491 static void isicom_bottomhalf(void * data
)
493 struct isi_port
* port
= (struct isi_port
*) data
;
494 struct tty_struct
* tty
= port
->tty
;
499 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
500 tty
->ldisc
.write_wakeup
)
501 (tty
->ldisc
.write_wakeup
)(tty
);
502 wake_up_interruptible(&tty
->write_wait
);
505 /* main interrupt handler routine */
506 static void isicom_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
508 struct isi_board
* card
;
509 struct isi_port
* port
;
510 struct tty_struct
* tty
;
511 unsigned short base
, header
, word_count
, count
;
512 unsigned char channel
;
516 * find the source of interrupt
519 for(count
= 0; count
< BOARD_COUNT
; count
++) {
520 card
= &isi_card
[count
];
521 if (card
->base
!= 0) {
522 if (((card
->isa
== YES
) && (card
->irq
== irq
)) ||
523 ((card
->isa
== NO
) && (card
->irq
== irq
) && (inw(card
->base
+0x0e) & 0x02)))
529 if (!card
|| !(card
->status
& FIRMWARE_LOADED
)) {
530 /* printk(KERN_DEBUG "ISICOM: interrupt: not handling irq%d!.\n", irq);*/
535 if (card
->isa
== NO
) {
537 * disable any interrupts from the PCI card and lower the
540 outw(0x8000, base
+0x04);
541 ClearInterrupt(base
);
544 inw(base
); /* get the dummy word out */
546 channel
= (header
& 0x7800) >> card
->shift_count
;
547 byte_count
= header
& 0xff;
549 printk(KERN_DEBUG
"ISICOM:Intr:(0x%x:%d).\n", base
, channel
+1);
551 if ((channel
+1) > card
->port_count
) {
552 printk(KERN_WARNING
"ISICOM: isicom_interrupt(0x%x): %d(channel) > port_count.\n",
555 ClearInterrupt(base
);
557 outw(0x0000, base
+0x04); /* enable interrupts */
560 port
= card
->ports
+ channel
;
561 if (!(port
->flags
& ASYNC_INITIALIZED
)) {
563 ClearInterrupt(base
);
565 outw(0x0000, base
+0x04); /* enable interrupts */
571 if (header
& 0x8000) { /* Status Packet */
573 switch(header
& 0xff) {
574 case 0: /* Change in EIA signals */
576 if (port
->flags
& ASYNC_CHECK_CD
) {
577 if (port
->status
& ISI_DCD
) {
578 if (!(header
& ISI_DCD
)) {
579 /* Carrier has been lost */
581 printk(KERN_DEBUG
"ISICOM: interrupt: DCD->low.\n");
583 port
->status
&= ~ISI_DCD
;
584 if (!((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
585 (port
->flags
& ASYNC_CALLOUT_NOHUP
)))
586 queue_task(&port
->hangup_tq
,
591 if (header
& ISI_DCD
) {
592 /* Carrier has been detected */
594 printk(KERN_DEBUG
"ISICOM: interrupt: DCD->high.\n");
596 port
->status
|= ISI_DCD
;
597 wake_up_interruptible(&port
->open_wait
);
602 if (header
& ISI_DCD
)
603 port
->status
|= ISI_DCD
;
605 port
->status
&= ~ISI_DCD
;
608 if (port
->flags
& ASYNC_CTS_FLOW
) {
609 if (port
->tty
->hw_stopped
) {
610 if (header
& ISI_CTS
) {
611 port
->tty
->hw_stopped
= 0;
613 port
->status
|= (ISI_TXOK
| ISI_CTS
);
618 if (!(header
& ISI_CTS
)) {
619 port
->tty
->hw_stopped
= 1;
621 port
->status
&= ~(ISI_TXOK
| ISI_CTS
);
626 if (header
& ISI_CTS
)
627 port
->status
|= ISI_CTS
;
629 port
->status
&= ~ISI_CTS
;
632 if (header
& ISI_DSR
)
633 port
->status
|= ISI_DSR
;
635 port
->status
&= ~ISI_DSR
;
638 port
->status
|= ISI_RI
;
640 port
->status
&= ~ISI_RI
;
644 case 1: /* Received Break !!! */
645 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
647 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
648 /* dunno if this is right */
649 *tty
->flip
.char_buf_ptr
++ = 0;
651 if (port
->flags
& ASYNC_SAK
)
653 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
656 case 2: /* Statistics */
657 printk(KERN_DEBUG
"ISICOM: isicom_interrupt: stats!!!.\n");
661 printk(KERN_WARNING
"ISICOM: Intr: Unknown code in status packet.\n");
665 else { /* Data Packet */
666 count
= MIN(byte_count
, (TTY_FLIPBUF_SIZE
- tty
->flip
.count
));
668 printk(KERN_DEBUG
"ISICOM: Intr: Can rx %d of %d bytes.\n",
671 word_count
= count
>> 1;
672 insw(base
, tty
->flip
.char_buf_ptr
, word_count
);
673 tty
->flip
.char_buf_ptr
+= (word_count
<< 1);
674 byte_count
-= (word_count
<< 1);
675 if (count
& 0x0001) {
676 *tty
->flip
.char_buf_ptr
++ = (char)(inw(base
) & 0xff);
679 memset(tty
->flip
.flag_buf_ptr
, 0, count
);
680 tty
->flip
.flag_buf_ptr
+= count
;
681 tty
->flip
.count
+= count
;
683 if (byte_count
> 0) {
684 printk(KERN_DEBUG
"ISICOM: Intr(0x%x:%d): Flip buffer overflow! dropping bytes...\n",
686 while(byte_count
> 0) { /* drain out unread xtra data */
691 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
693 if (card
->isa
== YES
)
694 ClearInterrupt(base
);
696 outw(0x0000, base
+0x04); /* enable interrupts */
700 /* called with interrupts disabled */
701 static void isicom_config_port(struct isi_port
* port
)
703 struct isi_board
* card
= port
->card
;
704 struct tty_struct
* tty
;
706 unsigned short channel_setup
, wait
, base
= card
->base
;
707 unsigned short channel
= port
->channel
, shift_count
= card
->shift_count
;
708 unsigned char flow_ctrl
;
710 if (!(tty
= port
->tty
) || !tty
->termios
)
713 if (baud
& CBAUDEX
) {
716 /* if CBAUDEX bit is on and the baud is set to either 50 or 75
717 * then the card is programmed for 57.6Kbps or 115Kbps
721 if (baud
< 1 || baud
> 2)
722 port
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
728 /* the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set
729 * by the set_serial_info ioctl ... this is done by
730 * the 'setserial' utility.
733 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
734 baud
++; /* 57.6 Kbps */
735 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
736 baud
+=2; /* 115 Kbps */
738 if (linuxb_to_isib
[baud
] == -1) {
747 while (((inw(base
+ 0x0e) & 0x0001) == 0) && (wait
-- > 0));
749 printk(KERN_WARNING
"ISICOM: Card found busy in isicom_config_port at channel setup.\n");
752 outw(0x8000 | (channel
<< shift_count
) |0x03, base
);
753 outw(linuxb_to_isib
[baud
] << 8 | 0x03, base
);
755 switch(C_CSIZE(tty
)) {
757 channel_setup
|= ISICOM_CS5
;
760 channel_setup
|= ISICOM_CS6
;
763 channel_setup
|= ISICOM_CS7
;
766 channel_setup
|= ISICOM_CS8
;
771 channel_setup
|= ISICOM_2SB
;
774 channel_setup
|= ISICOM_EVPAR
;
776 channel_setup
|= ISICOM_ODPAR
;
777 outw(channel_setup
, base
);
778 InterruptTheCard(base
);
781 port
->flags
&= ~ASYNC_CHECK_CD
;
783 port
->flags
|= ASYNC_CHECK_CD
;
785 /* flow control settings ...*/
787 port
->flags
&= ~ASYNC_CTS_FLOW
;
788 if (C_CRTSCTS(tty
)) {
789 port
->flags
|= ASYNC_CTS_FLOW
;
790 flow_ctrl
|= ISICOM_CTSRTS
;
793 flow_ctrl
|= ISICOM_RESPOND_XONXOFF
;
795 flow_ctrl
|= ISICOM_INITIATE_XONXOFF
;
798 while (((inw(base
+ 0x0e) & 0x0001) == 0) && (wait
-- > 0));
800 printk(KERN_WARNING
"ISICOM: Card found busy in isicom_config_port at flow setup.\n");
803 outw(0x8000 | (channel
<< shift_count
) |0x04, base
);
804 outw(flow_ctrl
<< 8 | 0x05, base
);
805 outw((STOP_CHAR(tty
)) << 8 | (START_CHAR(tty
)), base
);
806 InterruptTheCard(base
);
808 /* rx enabled -> enable port for rx on the card */
810 card
->port_status
|= (1 << channel
);
811 outw(card
->port_status
, base
+ 0x02);
818 extern inline void isicom_setup_board(struct isi_board
* bp
)
821 struct isi_port
* port
;
824 if (bp
->status
& BOARD_ACTIVE
)
828 printk(KERN_DEBUG
"ISICOM: setup_board: drop_dtr_rts start, port_count %d...\n", bp
->port_count
);
830 for(channel
= 0; channel
< bp
->port_count
; channel
++, port
++) {
831 save_flags(flags
); cli();
833 restore_flags(flags
);
836 printk(KERN_DEBUG
"ISICOM: setup_board: drop_dtr_rts stop...\n");
839 bp
->status
|= BOARD_ACTIVE
;
844 static int isicom_setup_port(struct isi_port
* port
)
846 struct isi_board
* card
= port
->card
;
849 if (port
->flags
& ASYNC_INITIALIZED
)
851 if (!port
->xmit_buf
) {
854 if (!(page
= get_free_page(GFP_KERNEL
)))
857 if (port
->xmit_buf
) {
861 port
->xmit_buf
= (unsigned char *) page
;
863 save_flags(flags
); cli();
865 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
866 if (port
->count
== 1)
869 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
871 /* discard any residual data */
872 kill_queue(port
, ISICOM_KILLTX
| ISICOM_KILLRX
);
874 isicom_config_port(port
);
875 port
->flags
|= ASYNC_INITIALIZED
;
877 restore_flags(flags
);
882 static int block_til_ready(struct tty_struct
* tty
, struct file
* filp
, struct isi_port
* port
)
884 int do_clocal
= 0, retval
;
885 DECLARE_WAITQUEUE(wait
, current
);
887 /* block if port is in the process of being closed */
889 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
891 printk(KERN_DEBUG
"ISICOM: block_til_ready: close in progress.\n");
893 interruptible_sleep_on(&port
->close_wait
);
894 if (port
->flags
& ASYNC_HUP_NOTIFY
)
900 /* trying to open a callout device... check for constraints */
902 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
904 printk(KERN_DEBUG
"ISICOM: bl_ti_rdy: callout open.\n");
906 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
908 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
909 (port
->flags
& ASYNC_SESSION_LOCKOUT
) &&
910 (port
->session
!= current
->session
))
913 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
914 (port
->flags
& ASYNC_PGRP_LOCKOUT
) &&
915 (port
->pgrp
!= current
->pgrp
))
917 port
->flags
|= ASYNC_CALLOUT_ACTIVE
;
924 /* if non-blocking mode is set ... */
926 if ((filp
->f_flags
& O_NONBLOCK
) || (tty
->flags
& (1 << TTY_IO_ERROR
))) {
928 printk(KERN_DEBUG
"ISICOM: block_til_ready: non-block mode.\n");
930 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
932 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
936 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
) {
937 if (port
->normal_termios
.c_cflag
& CLOCAL
)
945 printk(KERN_DEBUG
"ISICOM: block_til_ready: CLOCAL set.\n");
948 /* block waiting for DCD to be asserted, and while
949 callout dev is busy */
951 add_wait_queue(&port
->open_wait
, &wait
);
953 if (!tty_hung_up_p(filp
))
956 port
->blocked_open
++;
958 printk(KERN_DEBUG
"ISICOM: block_til_ready: waiting for DCD...\n");
962 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
))
966 set_current_state(TASK_INTERRUPTIBLE
);
967 if (tty_hung_up_p(filp
) || !(port
->flags
& ASYNC_INITIALIZED
)) {
968 if (port
->flags
& ASYNC_HUP_NOTIFY
)
971 retval
= -ERESTARTSYS
;
973 printk(KERN_DEBUG
"ISICOM: block_til_ready: tty_hung_up_p || not init.\n");
977 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
978 !(port
->flags
& ASYNC_CLOSING
) &&
979 (do_clocal
|| (port
->status
& ISI_DCD
))) {
981 printk(KERN_DEBUG
"ISICOM: block_til_ready: do_clocal || DCD.\n");
985 if (signal_pending(current
)) {
987 printk(KERN_DEBUG
"ISICOM: block_til_ready: sig blocked.\n");
989 retval
= -ERESTARTSYS
;
994 current
->state
= TASK_RUNNING
;
995 remove_wait_queue(&port
->open_wait
, &wait
);
996 if (!tty_hung_up_p(filp
))
998 port
->blocked_open
--;
1001 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1005 static int isicom_open(struct tty_struct
* tty
, struct file
* filp
)
1007 struct isi_port
* port
;
1008 struct isi_board
* card
;
1009 unsigned int line
, board
;
1010 unsigned long flags
;
1014 printk(KERN_DEBUG
"ISICOM: open start!!!.\n");
1016 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1019 printk(KERN_DEBUG
"line = %d.\n", line
);
1022 if ((line
< 0) || (line
> (PORT_COUNT
-1)))
1024 board
= BOARD(line
);
1027 printk(KERN_DEBUG
"board = %d.\n", board
);
1030 card
= &isi_card
[board
];
1031 if (!(card
->status
& FIRMWARE_LOADED
)) {
1033 printk(KERN_DEBUG
"ISICOM: Firmware not loaded to card%d.\n", board
);
1038 /* open on a port greater than the port count for the card !!! */
1039 if (line
> ((board
* 16) + card
->port_count
- 1)) {
1040 printk(KERN_ERR
"ISICOM: Open on a port which exceeds the port_count of the card!\n");
1043 port
= &isi_ports
[line
];
1044 if (isicom_paranoia_check(port
, tty
->device
, "isicom_open"))
1048 printk(KERN_DEBUG
"ISICOM: isicom_setup_board ...\n");
1050 isicom_setup_board(card
);
1053 tty
->driver_data
= port
;
1056 printk(KERN_DEBUG
"ISICOM: isicom_setup_port ...\n");
1058 if ((error
= isicom_setup_port(port
))!=0)
1061 printk(KERN_DEBUG
"ISICOM: block_til_ready ...\n");
1063 if ((error
= block_til_ready(tty
, filp
, port
))!=0)
1066 if ((port
->count
== 1) && (port
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1067 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1068 *tty
->termios
= port
->normal_termios
;
1070 *tty
->termios
= port
->callout_termios
;
1071 save_flags(flags
); cli();
1072 isicom_config_port(port
);
1073 restore_flags(flags
);
1076 port
->session
= current
->session
;
1077 port
->pgrp
= current
->pgrp
;
1079 printk(KERN_DEBUG
"ISICOM: open end!!!.\n");
1086 extern inline void isicom_shutdown_board(struct isi_board
* bp
)
1089 struct isi_port
* port
;
1091 if (!(bp
->status
& BOARD_ACTIVE
))
1093 bp
->status
&= ~BOARD_ACTIVE
;
1095 for(channel
= 0; channel
< bp
->port_count
; channel
++, port
++) {
1101 static void isicom_shutdown_port(struct isi_port
* port
)
1103 struct isi_board
* card
= port
->card
;
1104 struct tty_struct
* tty
;
1106 if (!(port
->flags
& ASYNC_INITIALIZED
))
1108 if (port
->xmit_buf
) {
1109 free_page((unsigned long) port
->xmit_buf
);
1110 port
->xmit_buf
= NULL
;
1112 if (!(tty
= port
->tty
) || C_HUPCL(tty
))
1113 /* drop dtr on this port */
1116 /* any other port uninits */
1119 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1120 port
->flags
&= ~ASYNC_INITIALIZED
;
1122 if (--card
->count
< 0) {
1123 printk(KERN_DEBUG
"ISICOM: isicom_shutdown_port: bad board(0x%x) count %d.\n",
1124 card
->base
, card
->count
);
1128 /* last port was closed , shutdown that boad too */
1130 isicom_shutdown_board(card
);
1133 static void isicom_close(struct tty_struct
* tty
, struct file
* filp
)
1135 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1136 struct isi_board
* card
= port
->card
;
1137 unsigned long flags
;
1141 if (isicom_paranoia_check(port
, tty
->device
, "isicom_close"))
1145 printk(KERN_DEBUG
"ISICOM: Close start!!!.\n");
1148 save_flags(flags
); cli();
1149 if (tty_hung_up_p(filp
)) {
1150 restore_flags(flags
);
1154 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1155 printk(KERN_WARNING
"ISICOM:(0x%x) isicom_close: bad port count"
1156 "tty->count = 1 port count = %d.\n",
1157 card
->base
, port
->count
);
1160 if (--port
->count
< 0) {
1161 printk(KERN_WARNING
"ISICOM:(0x%x) isicom_close: bad port count for"
1162 "channel%d = %d", card
->base
, port
->channel
,
1168 restore_flags(flags
);
1171 port
->flags
|= ASYNC_CLOSING
;
1173 * save termios struct since callout and dialin termios may be
1176 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
1177 port
->normal_termios
= *tty
->termios
;
1178 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
1179 port
->callout_termios
= *tty
->termios
;
1182 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1183 tty_wait_until_sent(tty
, port
->closing_wait
);
1184 /* indicate to the card that no more data can be received
1186 if (port
->flags
& ASYNC_INITIALIZED
) {
1187 card
->port_status
&= ~(1 << port
->channel
);
1188 outw(card
->port_status
, card
->base
+ 0x02);
1190 isicom_shutdown_port(port
);
1191 if (tty
->driver
.flush_buffer
)
1192 tty
->driver
.flush_buffer(tty
);
1193 if (tty
->ldisc
.flush_buffer
)
1194 tty
->ldisc
.flush_buffer(tty
);
1197 if (port
->blocked_open
) {
1198 if (port
->close_delay
) {
1199 current
->state
= TASK_INTERRUPTIBLE
;
1201 printk(KERN_DEBUG
"ISICOM: scheduling until time out.\n");
1203 schedule_timeout(port
->close_delay
);
1205 wake_up_interruptible(&port
->open_wait
);
1207 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
|
1209 wake_up_interruptible(&port
->close_wait
);
1210 restore_flags(flags
);
1212 printk(KERN_DEBUG
"ISICOM: Close end!!!.\n");
1217 static int isicom_write(struct tty_struct
* tty
, int from_user
,
1218 const unsigned char * buf
, int count
)
1220 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1221 unsigned long flags
;
1224 printk(KERN_DEBUG
"ISICOM: isicom_write for port%d: %d bytes.\n",
1225 port
->channel
+1, count
);
1227 if (isicom_paranoia_check(port
, tty
->device
, "isicom_write"))
1230 if (!tty
|| !port
->xmit_buf
|| !tmp_buf
)
1233 down(&tmp_buf_sem
); /* acquire xclusive access to tmp_buf */
1238 cnt
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1239 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1244 /* the following may block for paging... hence
1245 enabling interrupts but tx routine may have
1246 created more space in xmit_buf when the ctrl
1249 copy_from_user(tmp_buf
, buf
, cnt
);
1251 cnt
= MIN(cnt
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1252 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1253 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, cnt
);
1256 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, cnt
);
1257 port
->xmit_head
= (port
->xmit_head
+ cnt
) & (SERIAL_XMIT_SIZE
- 1);
1258 port
->xmit_cnt
+= cnt
;
1259 restore_flags(flags
);
1266 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
)
1267 port
->status
|= ISI_TXOK
;
1268 restore_flags(flags
);
1270 printk(KERN_DEBUG
"ISICOM: isicom_write %d bytes written.\n", total
);
1275 /* put_char et all */
1276 static void isicom_put_char(struct tty_struct
* tty
, unsigned char ch
)
1278 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1279 unsigned long flags
;
1281 if (isicom_paranoia_check(port
, tty
->device
, "isicom_put_char"))
1284 if (!tty
|| !port
->xmit_buf
)
1287 printk(KERN_DEBUG
"ISICOM: put_char, port %d, char %c.\n", port
->channel
+1, ch
);
1290 save_flags(flags
); cli();
1292 if (port
->xmit_cnt
>= (SERIAL_XMIT_SIZE
- 1)) {
1293 restore_flags(flags
);
1297 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1298 port
->xmit_head
&= (SERIAL_XMIT_SIZE
- 1);
1300 restore_flags(flags
);
1303 /* flush_chars et all */
1304 static void isicom_flush_chars(struct tty_struct
* tty
)
1306 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1308 if (isicom_paranoia_check(port
, tty
->device
, "isicom_flush_chars"))
1311 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1315 /* this tells the transmitter to consider this port for
1316 data output to the card ... that's the best we can do. */
1317 port
->status
|= ISI_TXOK
;
1320 /* write_room et all */
1321 static int isicom_write_room(struct tty_struct
* tty
)
1323 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1325 if (isicom_paranoia_check(port
, tty
->device
, "isicom_write_room"))
1328 free
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1334 /* chars_in_buffer et all */
1335 static int isicom_chars_in_buffer(struct tty_struct
* tty
)
1337 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1338 if (isicom_paranoia_check(port
, tty
->device
, "isicom_chars_in_buffer"))
1340 return port
->xmit_cnt
;
1344 extern inline void isicom_send_break(struct isi_port
* port
, unsigned long length
)
1346 struct isi_board
* card
= port
->card
;
1348 unsigned short base
= card
->base
;
1349 unsigned long flags
;
1351 save_flags(flags
); cli();
1352 while (((inw(base
+ 0x0e) & 0x0001) == 0) && (wait
-- > 0));
1354 printk(KERN_DEBUG
"ISICOM: Card found busy in isicom_send_break.\n");
1357 outw(0x8000 | ((port
->channel
) << (card
->shift_count
)) | 0x3, base
);
1358 outw((length
& 0xff) << 8 | 0x00, base
);
1359 outw((length
& 0xff00), base
);
1360 InterruptTheCard(base
);
1361 restore_flags(flags
);
1364 static int isicom_get_modem_info(struct isi_port
* port
, unsigned int * value
)
1366 /* just send the port status */
1368 unsigned short status
= port
->status
;
1370 info
= ((status
& ISI_RTS
) ? TIOCM_RTS
: 0) |
1371 ((status
& ISI_DTR
) ? TIOCM_DTR
: 0) |
1372 ((status
& ISI_DCD
) ? TIOCM_CAR
: 0) |
1373 ((status
& ISI_DSR
) ? TIOCM_DSR
: 0) |
1374 ((status
& ISI_CTS
) ? TIOCM_CTS
: 0) |
1375 ((status
& ISI_RI
) ? TIOCM_RI
: 0);
1376 put_user(info
, (unsigned int *) value
);
1380 static int isicom_set_modem_info(struct isi_port
* port
, unsigned int cmd
,
1381 unsigned int * value
)
1384 unsigned long flags
;
1386 if(get_user(arg
, value
))
1389 save_flags(flags
); cli();
1393 if (arg
& TIOCM_RTS
)
1395 if (arg
& TIOCM_DTR
)
1400 if (arg
& TIOCM_RTS
)
1402 if (arg
& TIOCM_DTR
)
1407 if (arg
& TIOCM_RTS
)
1412 if (arg
& TIOCM_DTR
)
1419 restore_flags(flags
);
1422 restore_flags(flags
);
1426 static int isicom_set_serial_info(struct isi_port
* port
,
1427 struct serial_struct
* info
)
1429 struct serial_struct newinfo
;
1430 unsigned long flags
;
1433 if(copy_from_user(&newinfo
, info
, sizeof(newinfo
)))
1436 reconfig_port
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1437 (newinfo
.flags
& ASYNC_SPD_MASK
));
1440 if ((newinfo
.close_delay
!= port
->close_delay
) ||
1441 (newinfo
.closing_wait
!= port
->closing_wait
) ||
1442 ((newinfo
.flags
& ~ASYNC_USR_MASK
) !=
1443 (port
->flags
& ~ASYNC_USR_MASK
)))
1445 port
->flags
= ((port
->flags
& ~ ASYNC_USR_MASK
) |
1446 (newinfo
.flags
& ASYNC_USR_MASK
));
1449 port
->close_delay
= newinfo
.close_delay
;
1450 port
->closing_wait
= newinfo
.closing_wait
;
1451 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1452 (newinfo
.flags
& ASYNC_FLAGS
));
1454 if (reconfig_port
) {
1455 save_flags(flags
); cli();
1456 isicom_config_port(port
);
1457 restore_flags(flags
);
1462 static int isicom_get_serial_info(struct isi_port
* port
,
1463 struct serial_struct
* info
)
1465 struct serial_struct out_info
;
1467 memset(&out_info
, 0, sizeof(out_info
));
1468 /* out_info.type = ? */
1469 out_info
.line
= port
- isi_ports
;
1470 out_info
.port
= port
->card
->base
;
1471 out_info
.irq
= port
->card
->irq
;
1472 out_info
.flags
= port
->flags
;
1473 /* out_info.baud_base = ? */
1474 out_info
.close_delay
= port
->close_delay
;
1475 out_info
.closing_wait
= port
->closing_wait
;
1476 if(copy_to_user(info
, &out_info
, sizeof(out_info
)))
1481 static int isicom_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1482 unsigned int cmd
, unsigned long arg
)
1484 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1487 if (isicom_paranoia_check(port
, tty
->device
, "isicom_ioctl"))
1492 retval
= tty_check_change(tty
);
1495 tty_wait_until_sent(tty
, 0);
1497 isicom_send_break(port
, HZ
/4);
1501 retval
= tty_check_change(tty
);
1504 tty_wait_until_sent(tty
, 0);
1505 isicom_send_break(port
, arg
? arg
* (HZ
/10) : HZ
/4);
1509 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
1512 if(get_user(arg
, (unsigned long *) arg
))
1514 tty
->termios
->c_cflag
=
1515 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1516 (arg
? CLOCAL
: 0));
1520 return isicom_get_modem_info(port
, (unsigned int*) arg
);
1525 return isicom_set_modem_info(port
, cmd
,
1526 (unsigned int *) arg
);
1529 return isicom_get_serial_info(port
,
1530 (struct serial_struct
*) arg
);
1533 return isicom_set_serial_info(port
,
1534 (struct serial_struct
*) arg
);
1537 return -ENOIOCTLCMD
;
1542 /* set_termios et all */
1543 static void isicom_set_termios(struct tty_struct
* tty
, struct termios
* old_termios
)
1545 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1546 unsigned long flags
;
1548 if (isicom_paranoia_check(port
, tty
->device
, "isicom_set_termios"))
1551 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1552 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1555 save_flags(flags
); cli();
1556 isicom_config_port(port
);
1557 restore_flags(flags
);
1559 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1560 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1561 tty
->hw_stopped
= 0;
1566 /* throttle et all */
1567 static void isicom_throttle(struct tty_struct
* tty
)
1569 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1570 struct isi_board
* card
= port
->card
;
1571 unsigned long flags
;
1573 if (isicom_paranoia_check(port
, tty
->device
, "isicom_throttle"))
1576 /* tell the card that this port cannot handle any more data for now */
1577 save_flags(flags
); cli();
1578 card
->port_status
&= ~(1 << port
->channel
);
1579 outw(card
->port_status
, card
->base
+ 0x02);
1580 restore_flags(flags
);
1583 /* unthrottle et all */
1584 static void isicom_unthrottle(struct tty_struct
* tty
)
1586 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1587 struct isi_board
* card
= port
->card
;
1588 unsigned long flags
;
1590 if (isicom_paranoia_check(port
, tty
->device
, "isicom_unthrottle"))
1593 /* tell the card that this port is ready to accept more data */
1594 save_flags(flags
); cli();
1595 card
->port_status
|= (1 << port
->channel
);
1596 outw(card
->port_status
, card
->base
+ 0x02);
1597 restore_flags(flags
);
1601 static void isicom_stop(struct tty_struct
* tty
)
1603 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1605 if (isicom_paranoia_check(port
, tty
->device
, "isicom_stop"))
1608 /* this tells the transmitter not to consider this port for
1609 data output to the card. */
1610 port
->status
&= ~ISI_TXOK
;
1614 static void isicom_start(struct tty_struct
* tty
)
1616 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1618 if (isicom_paranoia_check(port
, tty
->device
, "isicom_start"))
1621 /* this tells the transmitter to consider this port for
1622 data output to the card. */
1623 port
->status
|= ISI_TXOK
;
1627 static void do_isicom_hangup(void * data
)
1629 struct isi_port
* port
= (struct isi_port
*) data
;
1630 struct tty_struct
* tty
;
1639 static void isicom_hangup(struct tty_struct
* tty
)
1641 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1643 if (isicom_paranoia_check(port
, tty
->device
, "isicom_hangup"))
1646 isicom_shutdown_port(port
);
1648 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
1650 wake_up_interruptible(&port
->open_wait
);
1653 /* flush_buffer et all */
1654 static void isicom_flush_buffer(struct tty_struct
* tty
)
1656 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1657 unsigned long flags
;
1659 if (isicom_paranoia_check(port
, tty
->device
, "isicom_flush_buffer"))
1662 save_flags(flags
); cli();
1663 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1664 restore_flags(flags
);
1666 wake_up_interruptible(&tty
->write_wait
);
1667 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1668 tty
->ldisc
.write_wakeup
)
1669 (tty
->ldisc
.write_wakeup
)(tty
);
1673 static int register_ioregion(void)
1676 for (count
=0; count
< BOARD_COUNT
; count
++ ) {
1677 if (isi_card
[count
].base
) {
1678 if (check_region(isi_card
[count
].base
,16)) {
1679 printk(KERN_DEBUG
"ISICOM: I/O Region 0x%x-0x%x is busy. Card%d will be disabled.\n",
1680 isi_card
[count
].base
,isi_card
[count
].base
+15,count
+1);
1681 isi_card
[count
].base
=0;
1684 request_region(isi_card
[count
].base
,16,ISICOM_NAME
);
1686 printk(KERN_DEBUG
"ISICOM: I/O Region 0x%x-0x%x requested for Card%d.\n",isi_card
[count
].base
,isi_card
[count
].base
+15,count
+1);
1695 static void unregister_ioregion(void)
1698 for (count
=0; count
< BOARD_COUNT
; count
++ )
1699 if (isi_card
[count
].base
) {
1700 release_region(isi_card
[count
].base
,16);
1702 printk(KERN_DEBUG
"ISICOM: I/O Region 0x%x-0x%x released for Card%d.\n",isi_card
[count
].base
,isi_card
[count
].base
+15,count
+1);
1707 static int register_drivers(void)
1711 /* tty driver structure initialization */
1712 memset(&isicom_normal
, 0, sizeof(struct tty_driver
));
1713 isicom_normal
.magic
= TTY_DRIVER_MAGIC
;
1714 isicom_normal
.name
= "ttyM";
1715 isicom_normal
.major
= ISICOM_NMAJOR
;
1716 isicom_normal
.minor_start
= 0;
1717 isicom_normal
.num
= PORT_COUNT
;
1718 isicom_normal
.type
= TTY_DRIVER_TYPE_SERIAL
;
1719 isicom_normal
.subtype
= SERIAL_TYPE_NORMAL
;
1720 isicom_normal
.init_termios
= tty_std_termios
;
1721 isicom_normal
.init_termios
.c_cflag
=
1722 B9600
| CS8
| CREAD
| HUPCL
|CLOCAL
;
1723 isicom_normal
.flags
= TTY_DRIVER_REAL_RAW
;
1724 isicom_normal
.refcount
= &isicom_refcount
;
1726 isicom_normal
.table
= isicom_table
;
1727 isicom_normal
.termios
= isicom_termios
;
1728 isicom_normal
.termios_locked
= isicom_termios_locked
;
1730 isicom_normal
.open
= isicom_open
;
1731 isicom_normal
.close
= isicom_close
;
1732 isicom_normal
.write
= isicom_write
;
1733 isicom_normal
.put_char
= isicom_put_char
;
1734 isicom_normal
.flush_chars
= isicom_flush_chars
;
1735 isicom_normal
.write_room
= isicom_write_room
;
1736 isicom_normal
.chars_in_buffer
= isicom_chars_in_buffer
;
1737 isicom_normal
.ioctl
= isicom_ioctl
;
1738 isicom_normal
.set_termios
= isicom_set_termios
;
1739 isicom_normal
.throttle
= isicom_throttle
;
1740 isicom_normal
.unthrottle
= isicom_unthrottle
;
1741 isicom_normal
.stop
= isicom_stop
;
1742 isicom_normal
.start
= isicom_start
;
1743 isicom_normal
.hangup
= isicom_hangup
;
1744 isicom_normal
.flush_buffer
= isicom_flush_buffer
;
1746 /* callout device */
1748 isicom_callout
= isicom_normal
;
1749 isicom_callout
.name
= "cum";
1750 isicom_callout
.major
= ISICOM_CMAJOR
;
1751 isicom_callout
.subtype
= SERIAL_TYPE_CALLOUT
;
1753 if ((error
=tty_register_driver(&isicom_normal
))!=0) {
1754 printk(KERN_DEBUG
"ISICOM: Couldn't register the dialin driver, error=%d\n",
1758 if ((error
=tty_register_driver(&isicom_callout
))!=0) {
1759 tty_unregister_driver(&isicom_normal
);
1760 printk(KERN_DEBUG
"ISICOM: Couldn't register the callout driver, error=%d\n",
1767 static void unregister_drivers(void)
1770 if ((error
=tty_unregister_driver(&isicom_callout
))!=0)
1771 printk(KERN_DEBUG
"ISICOM: couldn't unregister callout driver error=%d.\n",error
);
1772 if (tty_unregister_driver(&isicom_normal
))
1773 printk(KERN_DEBUG
"ISICOM: couldn't unregister normal driver error=%d.\n",error
);
1776 static int register_isr(void)
1778 int count
, done
=0, card
;
1780 unsigned char request
;
1781 for (count
=0; count
< BOARD_COUNT
; count
++ ) {
1782 if (isi_card
[count
].base
) {
1784 * verify if the required irq has already been requested for
1785 * another ISI Card, if so we already have it, else request it
1788 for(card
= 0; card
< count
; card
++)
1789 if ((isi_card
[card
].base
) && (isi_card
[card
].irq
== isi_card
[count
].irq
)) {
1791 if ((isi_card
[count
].isa
== NO
) && (isi_card
[card
].isa
== NO
))
1794 * ISA cards cannot share interrupts with other
1795 * PCI or ISA devices hence disable this card.
1797 release_region(isi_card
[count
].base
,16);
1798 isi_card
[count
].base
= 0;
1802 if(isi_card
[count
].isa
== NO
)
1805 if (request
== YES
) {
1806 if (request_irq(isi_card
[count
].irq
, isicom_interrupt
, SA_INTERRUPT
|flag
, ISICOM_NAME
, NULL
)) {
1807 printk(KERN_WARNING
"ISICOM: Could not install handler at Irq %d. Card%d will be disabled.\n",
1808 isi_card
[count
].irq
, count
+1);
1809 release_region(isi_card
[count
].base
,16);
1810 isi_card
[count
].base
=0;
1813 printk(KERN_INFO
"ISICOM: Card%d at 0x%x using irq %d.\n",
1814 count
+1, isi_card
[count
].base
, isi_card
[count
].irq
);
1816 irq_to_board
[isi_card
[count
].irq
]=&isi_card
[count
];
1825 static void unregister_isr(void)
1828 unsigned char freeirq
;
1829 for (count
=0; count
< BOARD_COUNT
; count
++ ) {
1830 if (isi_card
[count
].base
) {
1832 for(card
= 0; card
< count
; card
++)
1833 if ((isi_card
[card
].base
) && (isi_card
[card
].irq
== isi_card
[count
].irq
)) {
1837 if (freeirq
== YES
) {
1838 free_irq(isi_card
[count
].irq
, NULL
);
1840 printk(KERN_DEBUG
"ISICOM: Irq %d released for Card%d.\n",isi_card
[count
].irq
, count
+1);
1847 static int isicom_init(void)
1849 int card
, channel
, base
;
1850 struct isi_port
* port
;
1854 page
= get_free_page(GFP_KERNEL
);
1857 printk(KERN_DEBUG
"ISICOM: Couldn't allocate page for tmp_buf.\n");
1859 printk(KERN_ERR
"ISICOM: Not enough memory...\n");
1863 tmp_buf
= (unsigned char *) page
;
1866 if (!register_ioregion())
1868 printk(KERN_ERR
"ISICOM: All required I/O space found busy.\n");
1869 free_page((unsigned long)tmp_buf
);
1872 if (register_drivers())
1874 unregister_ioregion();
1875 free_page((unsigned long)tmp_buf
);
1878 if (!register_isr())
1880 unregister_drivers();
1881 /* ioports already uregistered in register_isr */
1882 free_page((unsigned long)tmp_buf
);
1886 /* initialize bottom half */
1887 init_bh(ISICOM_BH
, do_isicom_bh
);
1890 memset(isi_ports
, 0, sizeof(isi_ports
));
1891 for (card
= 0; card
< BOARD_COUNT
; card
++) {
1892 port
= &isi_ports
[card
* 16];
1893 isi_card
[card
].ports
= port
;
1894 base
= isi_card
[card
].base
;
1895 for (channel
= 0; channel
< 16; channel
++, port
++) {
1896 port
->magic
= ISICOM_MAGIC
;
1897 port
->card
= &isi_card
[card
];
1898 port
->channel
= channel
;
1899 port
->normal_termios
= isicom_normal
.init_termios
;
1900 port
->callout_termios
= isicom_callout
.init_termios
;
1901 port
->close_delay
= 50 * HZ
/100;
1902 port
->closing_wait
= 3000 * HZ
/100;
1903 port
->hangup_tq
.routine
= do_isicom_hangup
;
1904 port
->hangup_tq
.data
= port
;
1905 port
->bh_tqueue
.routine
= isicom_bottomhalf
;
1906 port
->bh_tqueue
.data
= port
;
1908 init_waitqueue_head(&port
->open_wait
);
1909 init_waitqueue_head(&port
->close_wait
);
1918 * Insmod can set static symbols so keep these static
1924 MODULE_AUTHOR("MultiTech");
1925 MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
1926 MODULE_PARM(io
, "1-4i");
1927 MODULE_PARM_DESC(io
, "I/O ports for the cards");
1928 MODULE_PARM(irq
, "1-4i");
1929 MODULE_PARM_DESC(irq
, "Interrupts for the cards");
1931 int init_module(void)
1933 struct pci_dev
*dev
= NULL
;
1934 int retval
, card
, idx
, count
;
1935 unsigned char pciirq
;
1936 unsigned int ioaddr
;
1939 for(idx
=0; idx
< BOARD_COUNT
; idx
++) {
1941 isi_card
[idx
].base
=io
[idx
];
1942 isi_card
[idx
].irq
=irq
[idx
];
1943 isi_card
[idx
].isa
=YES
;
1947 isi_card
[idx
].base
= 0;
1948 isi_card
[idx
].irq
= 0;
1952 for (idx
=0 ;idx
< card
; idx
++) {
1953 if (!((isi_card
[idx
].irq
==2)||(isi_card
[idx
].irq
==3)||
1954 (isi_card
[idx
].irq
==4)||(isi_card
[idx
].irq
==5)||
1955 (isi_card
[idx
].irq
==7)||(isi_card
[idx
].irq
==10)||
1956 (isi_card
[idx
].irq
==11)||(isi_card
[idx
].irq
==12)||
1957 (isi_card
[idx
].irq
==15))) {
1959 if (isi_card
[idx
].base
) {
1960 printk(KERN_ERR
"ISICOM: Irq %d unsupported. Disabling Card%d...\n",
1961 isi_card
[idx
].irq
, idx
+1);
1962 isi_card
[idx
].base
=0;
1968 if (pci_present() && (card
< BOARD_COUNT
)) {
1969 for (idx
=0; idx
< DEVID_COUNT
; idx
++) {
1972 if (!(dev
= pci_find_device(VENDOR_ID
, device_id
[idx
], dev
)))
1974 if (card
>= BOARD_COUNT
)
1977 if (pci_enable_device(dev
))
1980 /* found a PCI ISI card! */
1981 ioaddr
= pci_resource_start (dev
, 3); /* i.e at offset 0x1c in the
1982 * PCI configuration register
1986 printk(KERN_INFO
"ISI PCI Card(Device ID 0x%x)\n", device_id
[idx
]);
1988 * allot the first empty slot in the array
1990 for (count
=0; count
< BOARD_COUNT
; count
++) {
1991 if (isi_card
[count
].base
== 0) {
1992 isi_card
[count
].base
= ioaddr
;
1993 isi_card
[count
].irq
= pciirq
;
1994 isi_card
[count
].isa
= NO
;
2000 if (card
>= BOARD_COUNT
) break;
2004 if (!(isi_card
[0].base
|| isi_card
[1].base
|| isi_card
[2].base
|| isi_card
[3].base
)) {
2005 printk(KERN_ERR
"ISICOM: No valid card configuration. Driver cannot be initialized...\n");
2008 retval
=misc_register(&isiloader_device
);
2010 printk(KERN_ERR
"ISICOM: Unable to register firmware loader driver.\n");
2014 if (!isicom_init()) {
2015 if (misc_deregister(&isiloader_device
))
2016 printk(KERN_ERR
"ISICOM: Unable to unregister Firmware Loader driver\n");
2021 tx
.expires
= jiffies
+ 1;
2023 tx
.function
= isicom_tx
;
2030 void cleanup_module(void)
2033 current
->state
= TASK_INTERRUPTIBLE
;
2034 schedule_timeout(HZ
);
2036 remove_bh(ISICOM_BH
);
2039 printk("ISICOM: isicom_tx tx_count = %ld.\n", tx_count
);
2043 printk("ISICOM: uregistering isr ...\n");
2048 printk("ISICOM: unregistering drivers ...\n");
2050 unregister_drivers();
2053 printk("ISICOM: unregistering ioregion ...\n");
2055 unregister_ioregion();
2058 printk("ISICOM: freeing tmp_buf ...\n");
2060 free_page((unsigned long)tmp_buf
);
2063 printk("ISICOM: unregistering firmware loader ...\n");
2065 if (misc_deregister(&isiloader_device
))
2066 printk(KERN_ERR
"ISICOM: Unable to unregister Firmware Loader driver\n");