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
))) {
587 if (schedule_task(&port
->hangup_tq
) == 0)
593 if (header
& ISI_DCD
) {
594 /* Carrier has been detected */
596 printk(KERN_DEBUG
"ISICOM: interrupt: DCD->high.\n");
598 port
->status
|= ISI_DCD
;
599 wake_up_interruptible(&port
->open_wait
);
604 if (header
& ISI_DCD
)
605 port
->status
|= ISI_DCD
;
607 port
->status
&= ~ISI_DCD
;
610 if (port
->flags
& ASYNC_CTS_FLOW
) {
611 if (port
->tty
->hw_stopped
) {
612 if (header
& ISI_CTS
) {
613 port
->tty
->hw_stopped
= 0;
615 port
->status
|= (ISI_TXOK
| ISI_CTS
);
620 if (!(header
& ISI_CTS
)) {
621 port
->tty
->hw_stopped
= 1;
623 port
->status
&= ~(ISI_TXOK
| ISI_CTS
);
628 if (header
& ISI_CTS
)
629 port
->status
|= ISI_CTS
;
631 port
->status
&= ~ISI_CTS
;
634 if (header
& ISI_DSR
)
635 port
->status
|= ISI_DSR
;
637 port
->status
&= ~ISI_DSR
;
640 port
->status
|= ISI_RI
;
642 port
->status
&= ~ISI_RI
;
646 case 1: /* Received Break !!! */
647 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
649 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
650 /* dunno if this is right */
651 *tty
->flip
.char_buf_ptr
++ = 0;
653 if (port
->flags
& ASYNC_SAK
)
655 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
658 case 2: /* Statistics */
659 printk(KERN_DEBUG
"ISICOM: isicom_interrupt: stats!!!.\n");
663 printk(KERN_WARNING
"ISICOM: Intr: Unknown code in status packet.\n");
667 else { /* Data Packet */
668 count
= MIN(byte_count
, (TTY_FLIPBUF_SIZE
- tty
->flip
.count
));
670 printk(KERN_DEBUG
"ISICOM: Intr: Can rx %d of %d bytes.\n",
673 word_count
= count
>> 1;
674 insw(base
, tty
->flip
.char_buf_ptr
, word_count
);
675 tty
->flip
.char_buf_ptr
+= (word_count
<< 1);
676 byte_count
-= (word_count
<< 1);
677 if (count
& 0x0001) {
678 *tty
->flip
.char_buf_ptr
++ = (char)(inw(base
) & 0xff);
681 memset(tty
->flip
.flag_buf_ptr
, 0, count
);
682 tty
->flip
.flag_buf_ptr
+= count
;
683 tty
->flip
.count
+= count
;
685 if (byte_count
> 0) {
686 printk(KERN_DEBUG
"ISICOM: Intr(0x%x:%d): Flip buffer overflow! dropping bytes...\n",
688 while(byte_count
> 0) { /* drain out unread xtra data */
693 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
695 if (card
->isa
== YES
)
696 ClearInterrupt(base
);
698 outw(0x0000, base
+0x04); /* enable interrupts */
702 /* called with interrupts disabled */
703 static void isicom_config_port(struct isi_port
* port
)
705 struct isi_board
* card
= port
->card
;
706 struct tty_struct
* tty
;
708 unsigned short channel_setup
, wait
, base
= card
->base
;
709 unsigned short channel
= port
->channel
, shift_count
= card
->shift_count
;
710 unsigned char flow_ctrl
;
712 if (!(tty
= port
->tty
) || !tty
->termios
)
715 if (baud
& CBAUDEX
) {
718 /* if CBAUDEX bit is on and the baud is set to either 50 or 75
719 * then the card is programmed for 57.6Kbps or 115Kbps
723 if (baud
< 1 || baud
> 2)
724 port
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
730 /* the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set
731 * by the set_serial_info ioctl ... this is done by
732 * the 'setserial' utility.
735 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
736 baud
++; /* 57.6 Kbps */
737 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
738 baud
+=2; /* 115 Kbps */
740 if (linuxb_to_isib
[baud
] == -1) {
749 while (((inw(base
+ 0x0e) & 0x0001) == 0) && (wait
-- > 0));
751 printk(KERN_WARNING
"ISICOM: Card found busy in isicom_config_port at channel setup.\n");
754 outw(0x8000 | (channel
<< shift_count
) |0x03, base
);
755 outw(linuxb_to_isib
[baud
] << 8 | 0x03, base
);
757 switch(C_CSIZE(tty
)) {
759 channel_setup
|= ISICOM_CS5
;
762 channel_setup
|= ISICOM_CS6
;
765 channel_setup
|= ISICOM_CS7
;
768 channel_setup
|= ISICOM_CS8
;
773 channel_setup
|= ISICOM_2SB
;
776 channel_setup
|= ISICOM_EVPAR
;
778 channel_setup
|= ISICOM_ODPAR
;
779 outw(channel_setup
, base
);
780 InterruptTheCard(base
);
783 port
->flags
&= ~ASYNC_CHECK_CD
;
785 port
->flags
|= ASYNC_CHECK_CD
;
787 /* flow control settings ...*/
789 port
->flags
&= ~ASYNC_CTS_FLOW
;
790 if (C_CRTSCTS(tty
)) {
791 port
->flags
|= ASYNC_CTS_FLOW
;
792 flow_ctrl
|= ISICOM_CTSRTS
;
795 flow_ctrl
|= ISICOM_RESPOND_XONXOFF
;
797 flow_ctrl
|= ISICOM_INITIATE_XONXOFF
;
800 while (((inw(base
+ 0x0e) & 0x0001) == 0) && (wait
-- > 0));
802 printk(KERN_WARNING
"ISICOM: Card found busy in isicom_config_port at flow setup.\n");
805 outw(0x8000 | (channel
<< shift_count
) |0x04, base
);
806 outw(flow_ctrl
<< 8 | 0x05, base
);
807 outw((STOP_CHAR(tty
)) << 8 | (START_CHAR(tty
)), base
);
808 InterruptTheCard(base
);
810 /* rx enabled -> enable port for rx on the card */
812 card
->port_status
|= (1 << channel
);
813 outw(card
->port_status
, base
+ 0x02);
820 extern inline void isicom_setup_board(struct isi_board
* bp
)
823 struct isi_port
* port
;
826 if (bp
->status
& BOARD_ACTIVE
)
830 printk(KERN_DEBUG
"ISICOM: setup_board: drop_dtr_rts start, port_count %d...\n", bp
->port_count
);
832 for(channel
= 0; channel
< bp
->port_count
; channel
++, port
++) {
833 save_flags(flags
); cli();
835 restore_flags(flags
);
838 printk(KERN_DEBUG
"ISICOM: setup_board: drop_dtr_rts stop...\n");
841 bp
->status
|= BOARD_ACTIVE
;
846 static int isicom_setup_port(struct isi_port
* port
)
848 struct isi_board
* card
= port
->card
;
851 if (port
->flags
& ASYNC_INITIALIZED
)
853 if (!port
->xmit_buf
) {
856 if (!(page
= get_free_page(GFP_KERNEL
)))
859 if (port
->xmit_buf
) {
863 port
->xmit_buf
= (unsigned char *) page
;
865 save_flags(flags
); cli();
867 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
868 if (port
->count
== 1)
871 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
873 /* discard any residual data */
874 kill_queue(port
, ISICOM_KILLTX
| ISICOM_KILLRX
);
876 isicom_config_port(port
);
877 port
->flags
|= ASYNC_INITIALIZED
;
879 restore_flags(flags
);
884 static int block_til_ready(struct tty_struct
* tty
, struct file
* filp
, struct isi_port
* port
)
886 int do_clocal
= 0, retval
;
887 DECLARE_WAITQUEUE(wait
, current
);
889 /* block if port is in the process of being closed */
891 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
893 printk(KERN_DEBUG
"ISICOM: block_til_ready: close in progress.\n");
895 interruptible_sleep_on(&port
->close_wait
);
896 if (port
->flags
& ASYNC_HUP_NOTIFY
)
902 /* trying to open a callout device... check for constraints */
904 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
906 printk(KERN_DEBUG
"ISICOM: bl_ti_rdy: callout open.\n");
908 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
910 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
911 (port
->flags
& ASYNC_SESSION_LOCKOUT
) &&
912 (port
->session
!= current
->session
))
915 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
916 (port
->flags
& ASYNC_PGRP_LOCKOUT
) &&
917 (port
->pgrp
!= current
->pgrp
))
919 port
->flags
|= ASYNC_CALLOUT_ACTIVE
;
926 /* if non-blocking mode is set ... */
928 if ((filp
->f_flags
& O_NONBLOCK
) || (tty
->flags
& (1 << TTY_IO_ERROR
))) {
930 printk(KERN_DEBUG
"ISICOM: block_til_ready: non-block mode.\n");
932 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
934 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
938 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
) {
939 if (port
->normal_termios
.c_cflag
& CLOCAL
)
947 printk(KERN_DEBUG
"ISICOM: block_til_ready: CLOCAL set.\n");
950 /* block waiting for DCD to be asserted, and while
951 callout dev is busy */
953 add_wait_queue(&port
->open_wait
, &wait
);
955 if (!tty_hung_up_p(filp
))
958 port
->blocked_open
++;
960 printk(KERN_DEBUG
"ISICOM: block_til_ready: waiting for DCD...\n");
964 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
))
968 set_current_state(TASK_INTERRUPTIBLE
);
969 if (tty_hung_up_p(filp
) || !(port
->flags
& ASYNC_INITIALIZED
)) {
970 if (port
->flags
& ASYNC_HUP_NOTIFY
)
973 retval
= -ERESTARTSYS
;
975 printk(KERN_DEBUG
"ISICOM: block_til_ready: tty_hung_up_p || not init.\n");
979 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
980 !(port
->flags
& ASYNC_CLOSING
) &&
981 (do_clocal
|| (port
->status
& ISI_DCD
))) {
983 printk(KERN_DEBUG
"ISICOM: block_til_ready: do_clocal || DCD.\n");
987 if (signal_pending(current
)) {
989 printk(KERN_DEBUG
"ISICOM: block_til_ready: sig blocked.\n");
991 retval
= -ERESTARTSYS
;
996 current
->state
= TASK_RUNNING
;
997 remove_wait_queue(&port
->open_wait
, &wait
);
998 if (!tty_hung_up_p(filp
))
1000 port
->blocked_open
--;
1003 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1007 static int isicom_open(struct tty_struct
* tty
, struct file
* filp
)
1009 struct isi_port
* port
;
1010 struct isi_board
* card
;
1011 unsigned int line
, board
;
1012 unsigned long flags
;
1016 printk(KERN_DEBUG
"ISICOM: open start!!!.\n");
1018 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1021 printk(KERN_DEBUG
"line = %d.\n", line
);
1024 if ((line
< 0) || (line
> (PORT_COUNT
-1)))
1026 board
= BOARD(line
);
1029 printk(KERN_DEBUG
"board = %d.\n", board
);
1032 card
= &isi_card
[board
];
1033 if (!(card
->status
& FIRMWARE_LOADED
)) {
1035 printk(KERN_DEBUG
"ISICOM: Firmware not loaded to card%d.\n", board
);
1040 /* open on a port greater than the port count for the card !!! */
1041 if (line
> ((board
* 16) + card
->port_count
- 1)) {
1042 printk(KERN_ERR
"ISICOM: Open on a port which exceeds the port_count of the card!\n");
1045 port
= &isi_ports
[line
];
1046 if (isicom_paranoia_check(port
, tty
->device
, "isicom_open"))
1050 printk(KERN_DEBUG
"ISICOM: isicom_setup_board ...\n");
1052 isicom_setup_board(card
);
1055 tty
->driver_data
= port
;
1058 printk(KERN_DEBUG
"ISICOM: isicom_setup_port ...\n");
1060 if ((error
= isicom_setup_port(port
))!=0)
1063 printk(KERN_DEBUG
"ISICOM: block_til_ready ...\n");
1065 if ((error
= block_til_ready(tty
, filp
, port
))!=0)
1068 if ((port
->count
== 1) && (port
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1069 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1070 *tty
->termios
= port
->normal_termios
;
1072 *tty
->termios
= port
->callout_termios
;
1073 save_flags(flags
); cli();
1074 isicom_config_port(port
);
1075 restore_flags(flags
);
1078 port
->session
= current
->session
;
1079 port
->pgrp
= current
->pgrp
;
1081 printk(KERN_DEBUG
"ISICOM: open end!!!.\n");
1088 extern inline void isicom_shutdown_board(struct isi_board
* bp
)
1091 struct isi_port
* port
;
1093 if (!(bp
->status
& BOARD_ACTIVE
))
1095 bp
->status
&= ~BOARD_ACTIVE
;
1097 for(channel
= 0; channel
< bp
->port_count
; channel
++, port
++) {
1103 static void isicom_shutdown_port(struct isi_port
* port
)
1105 struct isi_board
* card
= port
->card
;
1106 struct tty_struct
* tty
;
1108 if (!(port
->flags
& ASYNC_INITIALIZED
))
1110 if (port
->xmit_buf
) {
1111 free_page((unsigned long) port
->xmit_buf
);
1112 port
->xmit_buf
= NULL
;
1114 if (!(tty
= port
->tty
) || C_HUPCL(tty
))
1115 /* drop dtr on this port */
1118 /* any other port uninits */
1121 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1122 port
->flags
&= ~ASYNC_INITIALIZED
;
1124 if (--card
->count
< 0) {
1125 printk(KERN_DEBUG
"ISICOM: isicom_shutdown_port: bad board(0x%x) count %d.\n",
1126 card
->base
, card
->count
);
1130 /* last port was closed , shutdown that boad too */
1132 isicom_shutdown_board(card
);
1135 static void isicom_close(struct tty_struct
* tty
, struct file
* filp
)
1137 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1138 struct isi_board
* card
= port
->card
;
1139 unsigned long flags
;
1143 if (isicom_paranoia_check(port
, tty
->device
, "isicom_close"))
1147 printk(KERN_DEBUG
"ISICOM: Close start!!!.\n");
1150 save_flags(flags
); cli();
1151 if (tty_hung_up_p(filp
)) {
1152 restore_flags(flags
);
1156 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1157 printk(KERN_WARNING
"ISICOM:(0x%x) isicom_close: bad port count"
1158 "tty->count = 1 port count = %d.\n",
1159 card
->base
, port
->count
);
1162 if (--port
->count
< 0) {
1163 printk(KERN_WARNING
"ISICOM:(0x%x) isicom_close: bad port count for"
1164 "channel%d = %d", card
->base
, port
->channel
,
1170 restore_flags(flags
);
1173 port
->flags
|= ASYNC_CLOSING
;
1175 * save termios struct since callout and dialin termios may be
1178 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
1179 port
->normal_termios
= *tty
->termios
;
1180 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
1181 port
->callout_termios
= *tty
->termios
;
1184 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1185 tty_wait_until_sent(tty
, port
->closing_wait
);
1186 /* indicate to the card that no more data can be received
1188 if (port
->flags
& ASYNC_INITIALIZED
) {
1189 card
->port_status
&= ~(1 << port
->channel
);
1190 outw(card
->port_status
, card
->base
+ 0x02);
1192 isicom_shutdown_port(port
);
1193 if (tty
->driver
.flush_buffer
)
1194 tty
->driver
.flush_buffer(tty
);
1195 if (tty
->ldisc
.flush_buffer
)
1196 tty
->ldisc
.flush_buffer(tty
);
1199 if (port
->blocked_open
) {
1200 if (port
->close_delay
) {
1201 current
->state
= TASK_INTERRUPTIBLE
;
1203 printk(KERN_DEBUG
"ISICOM: scheduling until time out.\n");
1205 schedule_timeout(port
->close_delay
);
1207 wake_up_interruptible(&port
->open_wait
);
1209 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
|
1211 wake_up_interruptible(&port
->close_wait
);
1212 restore_flags(flags
);
1214 printk(KERN_DEBUG
"ISICOM: Close end!!!.\n");
1219 static int isicom_write(struct tty_struct
* tty
, int from_user
,
1220 const unsigned char * buf
, int count
)
1222 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1223 unsigned long flags
;
1226 printk(KERN_DEBUG
"ISICOM: isicom_write for port%d: %d bytes.\n",
1227 port
->channel
+1, count
);
1229 if (isicom_paranoia_check(port
, tty
->device
, "isicom_write"))
1232 if (!tty
|| !port
->xmit_buf
|| !tmp_buf
)
1235 down(&tmp_buf_sem
); /* acquire xclusive access to tmp_buf */
1240 cnt
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1241 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1246 /* the following may block for paging... hence
1247 enabling interrupts but tx routine may have
1248 created more space in xmit_buf when the ctrl
1251 copy_from_user(tmp_buf
, buf
, cnt
);
1253 cnt
= MIN(cnt
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1254 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1255 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, cnt
);
1258 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, cnt
);
1259 port
->xmit_head
= (port
->xmit_head
+ cnt
) & (SERIAL_XMIT_SIZE
- 1);
1260 port
->xmit_cnt
+= cnt
;
1261 restore_flags(flags
);
1268 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
)
1269 port
->status
|= ISI_TXOK
;
1270 restore_flags(flags
);
1272 printk(KERN_DEBUG
"ISICOM: isicom_write %d bytes written.\n", total
);
1277 /* put_char et all */
1278 static void isicom_put_char(struct tty_struct
* tty
, unsigned char ch
)
1280 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1281 unsigned long flags
;
1283 if (isicom_paranoia_check(port
, tty
->device
, "isicom_put_char"))
1286 if (!tty
|| !port
->xmit_buf
)
1289 printk(KERN_DEBUG
"ISICOM: put_char, port %d, char %c.\n", port
->channel
+1, ch
);
1292 save_flags(flags
); cli();
1294 if (port
->xmit_cnt
>= (SERIAL_XMIT_SIZE
- 1)) {
1295 restore_flags(flags
);
1299 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1300 port
->xmit_head
&= (SERIAL_XMIT_SIZE
- 1);
1302 restore_flags(flags
);
1305 /* flush_chars et all */
1306 static void isicom_flush_chars(struct tty_struct
* tty
)
1308 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1310 if (isicom_paranoia_check(port
, tty
->device
, "isicom_flush_chars"))
1313 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1317 /* this tells the transmitter to consider this port for
1318 data output to the card ... that's the best we can do. */
1319 port
->status
|= ISI_TXOK
;
1322 /* write_room et all */
1323 static int isicom_write_room(struct tty_struct
* tty
)
1325 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1327 if (isicom_paranoia_check(port
, tty
->device
, "isicom_write_room"))
1330 free
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1336 /* chars_in_buffer et all */
1337 static int isicom_chars_in_buffer(struct tty_struct
* tty
)
1339 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1340 if (isicom_paranoia_check(port
, tty
->device
, "isicom_chars_in_buffer"))
1342 return port
->xmit_cnt
;
1346 extern inline void isicom_send_break(struct isi_port
* port
, unsigned long length
)
1348 struct isi_board
* card
= port
->card
;
1350 unsigned short base
= card
->base
;
1351 unsigned long flags
;
1353 save_flags(flags
); cli();
1354 while (((inw(base
+ 0x0e) & 0x0001) == 0) && (wait
-- > 0));
1356 printk(KERN_DEBUG
"ISICOM: Card found busy in isicom_send_break.\n");
1359 outw(0x8000 | ((port
->channel
) << (card
->shift_count
)) | 0x3, base
);
1360 outw((length
& 0xff) << 8 | 0x00, base
);
1361 outw((length
& 0xff00), base
);
1362 InterruptTheCard(base
);
1363 restore_flags(flags
);
1366 static int isicom_get_modem_info(struct isi_port
* port
, unsigned int * value
)
1368 /* just send the port status */
1370 unsigned short status
= port
->status
;
1372 info
= ((status
& ISI_RTS
) ? TIOCM_RTS
: 0) |
1373 ((status
& ISI_DTR
) ? TIOCM_DTR
: 0) |
1374 ((status
& ISI_DCD
) ? TIOCM_CAR
: 0) |
1375 ((status
& ISI_DSR
) ? TIOCM_DSR
: 0) |
1376 ((status
& ISI_CTS
) ? TIOCM_CTS
: 0) |
1377 ((status
& ISI_RI
) ? TIOCM_RI
: 0);
1378 put_user(info
, (unsigned int *) value
);
1382 static int isicom_set_modem_info(struct isi_port
* port
, unsigned int cmd
,
1383 unsigned int * value
)
1386 unsigned long flags
;
1388 if(get_user(arg
, value
))
1391 save_flags(flags
); cli();
1395 if (arg
& TIOCM_RTS
)
1397 if (arg
& TIOCM_DTR
)
1402 if (arg
& TIOCM_RTS
)
1404 if (arg
& TIOCM_DTR
)
1409 if (arg
& TIOCM_RTS
)
1414 if (arg
& TIOCM_DTR
)
1421 restore_flags(flags
);
1424 restore_flags(flags
);
1428 static int isicom_set_serial_info(struct isi_port
* port
,
1429 struct serial_struct
* info
)
1431 struct serial_struct newinfo
;
1432 unsigned long flags
;
1435 if(copy_from_user(&newinfo
, info
, sizeof(newinfo
)))
1438 reconfig_port
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1439 (newinfo
.flags
& ASYNC_SPD_MASK
));
1442 if ((newinfo
.close_delay
!= port
->close_delay
) ||
1443 (newinfo
.closing_wait
!= port
->closing_wait
) ||
1444 ((newinfo
.flags
& ~ASYNC_USR_MASK
) !=
1445 (port
->flags
& ~ASYNC_USR_MASK
)))
1447 port
->flags
= ((port
->flags
& ~ ASYNC_USR_MASK
) |
1448 (newinfo
.flags
& ASYNC_USR_MASK
));
1451 port
->close_delay
= newinfo
.close_delay
;
1452 port
->closing_wait
= newinfo
.closing_wait
;
1453 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1454 (newinfo
.flags
& ASYNC_FLAGS
));
1456 if (reconfig_port
) {
1457 save_flags(flags
); cli();
1458 isicom_config_port(port
);
1459 restore_flags(flags
);
1464 static int isicom_get_serial_info(struct isi_port
* port
,
1465 struct serial_struct
* info
)
1467 struct serial_struct out_info
;
1469 memset(&out_info
, 0, sizeof(out_info
));
1470 /* out_info.type = ? */
1471 out_info
.line
= port
- isi_ports
;
1472 out_info
.port
= port
->card
->base
;
1473 out_info
.irq
= port
->card
->irq
;
1474 out_info
.flags
= port
->flags
;
1475 /* out_info.baud_base = ? */
1476 out_info
.close_delay
= port
->close_delay
;
1477 out_info
.closing_wait
= port
->closing_wait
;
1478 if(copy_to_user(info
, &out_info
, sizeof(out_info
)))
1483 static int isicom_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1484 unsigned int cmd
, unsigned long arg
)
1486 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1489 if (isicom_paranoia_check(port
, tty
->device
, "isicom_ioctl"))
1494 retval
= tty_check_change(tty
);
1497 tty_wait_until_sent(tty
, 0);
1499 isicom_send_break(port
, HZ
/4);
1503 retval
= tty_check_change(tty
);
1506 tty_wait_until_sent(tty
, 0);
1507 isicom_send_break(port
, arg
? arg
* (HZ
/10) : HZ
/4);
1511 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
1514 if(get_user(arg
, (unsigned long *) arg
))
1516 tty
->termios
->c_cflag
=
1517 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1518 (arg
? CLOCAL
: 0));
1522 return isicom_get_modem_info(port
, (unsigned int*) arg
);
1527 return isicom_set_modem_info(port
, cmd
,
1528 (unsigned int *) arg
);
1531 return isicom_get_serial_info(port
,
1532 (struct serial_struct
*) arg
);
1535 return isicom_set_serial_info(port
,
1536 (struct serial_struct
*) arg
);
1539 return -ENOIOCTLCMD
;
1544 /* set_termios et all */
1545 static void isicom_set_termios(struct tty_struct
* tty
, struct termios
* old_termios
)
1547 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1548 unsigned long flags
;
1550 if (isicom_paranoia_check(port
, tty
->device
, "isicom_set_termios"))
1553 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1554 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1557 save_flags(flags
); cli();
1558 isicom_config_port(port
);
1559 restore_flags(flags
);
1561 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1562 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1563 tty
->hw_stopped
= 0;
1568 /* throttle et all */
1569 static void isicom_throttle(struct tty_struct
* tty
)
1571 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1572 struct isi_board
* card
= port
->card
;
1573 unsigned long flags
;
1575 if (isicom_paranoia_check(port
, tty
->device
, "isicom_throttle"))
1578 /* tell the card that this port cannot handle any more data for now */
1579 save_flags(flags
); cli();
1580 card
->port_status
&= ~(1 << port
->channel
);
1581 outw(card
->port_status
, card
->base
+ 0x02);
1582 restore_flags(flags
);
1585 /* unthrottle et all */
1586 static void isicom_unthrottle(struct tty_struct
* tty
)
1588 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1589 struct isi_board
* card
= port
->card
;
1590 unsigned long flags
;
1592 if (isicom_paranoia_check(port
, tty
->device
, "isicom_unthrottle"))
1595 /* tell the card that this port is ready to accept more data */
1596 save_flags(flags
); cli();
1597 card
->port_status
|= (1 << port
->channel
);
1598 outw(card
->port_status
, card
->base
+ 0x02);
1599 restore_flags(flags
);
1603 static void isicom_stop(struct tty_struct
* tty
)
1605 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1607 if (isicom_paranoia_check(port
, tty
->device
, "isicom_stop"))
1610 /* this tells the transmitter not to consider this port for
1611 data output to the card. */
1612 port
->status
&= ~ISI_TXOK
;
1616 static void isicom_start(struct tty_struct
* tty
)
1618 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1620 if (isicom_paranoia_check(port
, tty
->device
, "isicom_start"))
1623 /* this tells the transmitter to consider this port for
1624 data output to the card. */
1625 port
->status
|= ISI_TXOK
;
1629 static void do_isicom_hangup(void * data
)
1631 struct isi_port
* port
= (struct isi_port
*) data
;
1632 struct tty_struct
* tty
;
1636 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
1640 static void isicom_hangup(struct tty_struct
* tty
)
1642 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1644 if (isicom_paranoia_check(port
, tty
->device
, "isicom_hangup"))
1647 isicom_shutdown_port(port
);
1649 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
1651 wake_up_interruptible(&port
->open_wait
);
1654 /* flush_buffer et all */
1655 static void isicom_flush_buffer(struct tty_struct
* tty
)
1657 struct isi_port
* port
= (struct isi_port
*) tty
->driver_data
;
1658 unsigned long flags
;
1660 if (isicom_paranoia_check(port
, tty
->device
, "isicom_flush_buffer"))
1663 save_flags(flags
); cli();
1664 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1665 restore_flags(flags
);
1667 wake_up_interruptible(&tty
->write_wait
);
1668 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1669 tty
->ldisc
.write_wakeup
)
1670 (tty
->ldisc
.write_wakeup
)(tty
);
1674 static int register_ioregion(void)
1677 for (count
=0; count
< BOARD_COUNT
; count
++ ) {
1678 if (isi_card
[count
].base
) {
1679 if (check_region(isi_card
[count
].base
,16)) {
1680 printk(KERN_DEBUG
"ISICOM: I/O Region 0x%x-0x%x is busy. Card%d will be disabled.\n",
1681 isi_card
[count
].base
,isi_card
[count
].base
+15,count
+1);
1682 isi_card
[count
].base
=0;
1685 request_region(isi_card
[count
].base
,16,ISICOM_NAME
);
1687 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);
1696 static void unregister_ioregion(void)
1699 for (count
=0; count
< BOARD_COUNT
; count
++ )
1700 if (isi_card
[count
].base
) {
1701 release_region(isi_card
[count
].base
,16);
1703 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);
1708 static int register_drivers(void)
1712 /* tty driver structure initialization */
1713 memset(&isicom_normal
, 0, sizeof(struct tty_driver
));
1714 isicom_normal
.magic
= TTY_DRIVER_MAGIC
;
1715 isicom_normal
.name
= "ttyM";
1716 isicom_normal
.major
= ISICOM_NMAJOR
;
1717 isicom_normal
.minor_start
= 0;
1718 isicom_normal
.num
= PORT_COUNT
;
1719 isicom_normal
.type
= TTY_DRIVER_TYPE_SERIAL
;
1720 isicom_normal
.subtype
= SERIAL_TYPE_NORMAL
;
1721 isicom_normal
.init_termios
= tty_std_termios
;
1722 isicom_normal
.init_termios
.c_cflag
=
1723 B9600
| CS8
| CREAD
| HUPCL
|CLOCAL
;
1724 isicom_normal
.flags
= TTY_DRIVER_REAL_RAW
;
1725 isicom_normal
.refcount
= &isicom_refcount
;
1727 isicom_normal
.table
= isicom_table
;
1728 isicom_normal
.termios
= isicom_termios
;
1729 isicom_normal
.termios_locked
= isicom_termios_locked
;
1731 isicom_normal
.open
= isicom_open
;
1732 isicom_normal
.close
= isicom_close
;
1733 isicom_normal
.write
= isicom_write
;
1734 isicom_normal
.put_char
= isicom_put_char
;
1735 isicom_normal
.flush_chars
= isicom_flush_chars
;
1736 isicom_normal
.write_room
= isicom_write_room
;
1737 isicom_normal
.chars_in_buffer
= isicom_chars_in_buffer
;
1738 isicom_normal
.ioctl
= isicom_ioctl
;
1739 isicom_normal
.set_termios
= isicom_set_termios
;
1740 isicom_normal
.throttle
= isicom_throttle
;
1741 isicom_normal
.unthrottle
= isicom_unthrottle
;
1742 isicom_normal
.stop
= isicom_stop
;
1743 isicom_normal
.start
= isicom_start
;
1744 isicom_normal
.hangup
= isicom_hangup
;
1745 isicom_normal
.flush_buffer
= isicom_flush_buffer
;
1747 /* callout device */
1749 isicom_callout
= isicom_normal
;
1750 isicom_callout
.name
= "cum";
1751 isicom_callout
.major
= ISICOM_CMAJOR
;
1752 isicom_callout
.subtype
= SERIAL_TYPE_CALLOUT
;
1754 if ((error
=tty_register_driver(&isicom_normal
))!=0) {
1755 printk(KERN_DEBUG
"ISICOM: Couldn't register the dialin driver, error=%d\n",
1759 if ((error
=tty_register_driver(&isicom_callout
))!=0) {
1760 tty_unregister_driver(&isicom_normal
);
1761 printk(KERN_DEBUG
"ISICOM: Couldn't register the callout driver, error=%d\n",
1768 static void unregister_drivers(void)
1771 if ((error
=tty_unregister_driver(&isicom_callout
))!=0)
1772 printk(KERN_DEBUG
"ISICOM: couldn't unregister callout driver error=%d.\n",error
);
1773 if (tty_unregister_driver(&isicom_normal
))
1774 printk(KERN_DEBUG
"ISICOM: couldn't unregister normal driver error=%d.\n",error
);
1777 static int register_isr(void)
1779 int count
, done
=0, card
;
1781 unsigned char request
;
1782 for (count
=0; count
< BOARD_COUNT
; count
++ ) {
1783 if (isi_card
[count
].base
) {
1785 * verify if the required irq has already been requested for
1786 * another ISI Card, if so we already have it, else request it
1789 for(card
= 0; card
< count
; card
++)
1790 if ((isi_card
[card
].base
) && (isi_card
[card
].irq
== isi_card
[count
].irq
)) {
1792 if ((isi_card
[count
].isa
== NO
) && (isi_card
[card
].isa
== NO
))
1795 * ISA cards cannot share interrupts with other
1796 * PCI or ISA devices hence disable this card.
1798 release_region(isi_card
[count
].base
,16);
1799 isi_card
[count
].base
= 0;
1803 if(isi_card
[count
].isa
== NO
)
1806 if (request
== YES
) {
1807 if (request_irq(isi_card
[count
].irq
, isicom_interrupt
, SA_INTERRUPT
|flag
, ISICOM_NAME
, NULL
)) {
1808 printk(KERN_WARNING
"ISICOM: Could not install handler at Irq %d. Card%d will be disabled.\n",
1809 isi_card
[count
].irq
, count
+1);
1810 release_region(isi_card
[count
].base
,16);
1811 isi_card
[count
].base
=0;
1814 printk(KERN_INFO
"ISICOM: Card%d at 0x%x using irq %d.\n",
1815 count
+1, isi_card
[count
].base
, isi_card
[count
].irq
);
1817 irq_to_board
[isi_card
[count
].irq
]=&isi_card
[count
];
1826 static void unregister_isr(void)
1829 unsigned char freeirq
;
1830 for (count
=0; count
< BOARD_COUNT
; count
++ ) {
1831 if (isi_card
[count
].base
) {
1833 for(card
= 0; card
< count
; card
++)
1834 if ((isi_card
[card
].base
) && (isi_card
[card
].irq
== isi_card
[count
].irq
)) {
1838 if (freeirq
== YES
) {
1839 free_irq(isi_card
[count
].irq
, NULL
);
1841 printk(KERN_DEBUG
"ISICOM: Irq %d released for Card%d.\n",isi_card
[count
].irq
, count
+1);
1848 static int isicom_init(void)
1850 int card
, channel
, base
;
1851 struct isi_port
* port
;
1855 page
= get_free_page(GFP_KERNEL
);
1858 printk(KERN_DEBUG
"ISICOM: Couldn't allocate page for tmp_buf.\n");
1860 printk(KERN_ERR
"ISICOM: Not enough memory...\n");
1864 tmp_buf
= (unsigned char *) page
;
1867 if (!register_ioregion())
1869 printk(KERN_ERR
"ISICOM: All required I/O space found busy.\n");
1870 free_page((unsigned long)tmp_buf
);
1873 if (register_drivers())
1875 unregister_ioregion();
1876 free_page((unsigned long)tmp_buf
);
1879 if (!register_isr())
1881 unregister_drivers();
1882 /* ioports already uregistered in register_isr */
1883 free_page((unsigned long)tmp_buf
);
1887 /* initialize bottom half */
1888 init_bh(ISICOM_BH
, do_isicom_bh
);
1891 memset(isi_ports
, 0, sizeof(isi_ports
));
1892 for (card
= 0; card
< BOARD_COUNT
; card
++) {
1893 port
= &isi_ports
[card
* 16];
1894 isi_card
[card
].ports
= port
;
1895 base
= isi_card
[card
].base
;
1896 for (channel
= 0; channel
< 16; channel
++, port
++) {
1897 port
->magic
= ISICOM_MAGIC
;
1898 port
->card
= &isi_card
[card
];
1899 port
->channel
= channel
;
1900 port
->normal_termios
= isicom_normal
.init_termios
;
1901 port
->callout_termios
= isicom_callout
.init_termios
;
1902 port
->close_delay
= 50 * HZ
/100;
1903 port
->closing_wait
= 3000 * HZ
/100;
1904 port
->hangup_tq
.routine
= do_isicom_hangup
;
1905 port
->hangup_tq
.data
= port
;
1906 port
->bh_tqueue
.routine
= isicom_bottomhalf
;
1907 port
->bh_tqueue
.data
= port
;
1909 init_waitqueue_head(&port
->open_wait
);
1910 init_waitqueue_head(&port
->close_wait
);
1919 * Insmod can set static symbols so keep these static
1925 MODULE_AUTHOR("MultiTech");
1926 MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
1927 MODULE_PARM(io
, "1-4i");
1928 MODULE_PARM_DESC(io
, "I/O ports for the cards");
1929 MODULE_PARM(irq
, "1-4i");
1930 MODULE_PARM_DESC(irq
, "Interrupts for the cards");
1932 int init_module(void)
1934 struct pci_dev
*dev
= NULL
;
1935 int retval
, card
, idx
, count
;
1936 unsigned char pciirq
;
1937 unsigned int ioaddr
;
1940 for(idx
=0; idx
< BOARD_COUNT
; idx
++) {
1942 isi_card
[idx
].base
=io
[idx
];
1943 isi_card
[idx
].irq
=irq
[idx
];
1944 isi_card
[idx
].isa
=YES
;
1948 isi_card
[idx
].base
= 0;
1949 isi_card
[idx
].irq
= 0;
1953 for (idx
=0 ;idx
< card
; idx
++) {
1954 if (!((isi_card
[idx
].irq
==2)||(isi_card
[idx
].irq
==3)||
1955 (isi_card
[idx
].irq
==4)||(isi_card
[idx
].irq
==5)||
1956 (isi_card
[idx
].irq
==7)||(isi_card
[idx
].irq
==10)||
1957 (isi_card
[idx
].irq
==11)||(isi_card
[idx
].irq
==12)||
1958 (isi_card
[idx
].irq
==15))) {
1960 if (isi_card
[idx
].base
) {
1961 printk(KERN_ERR
"ISICOM: Irq %d unsupported. Disabling Card%d...\n",
1962 isi_card
[idx
].irq
, idx
+1);
1963 isi_card
[idx
].base
=0;
1969 if (pci_present() && (card
< BOARD_COUNT
)) {
1970 for (idx
=0; idx
< DEVID_COUNT
; idx
++) {
1973 if (!(dev
= pci_find_device(VENDOR_ID
, device_id
[idx
], dev
)))
1975 if (card
>= BOARD_COUNT
)
1978 if (pci_enable_device(dev
))
1981 /* found a PCI ISI card! */
1982 ioaddr
= pci_resource_start (dev
, 3); /* i.e at offset 0x1c in the
1983 * PCI configuration register
1987 printk(KERN_INFO
"ISI PCI Card(Device ID 0x%x)\n", device_id
[idx
]);
1989 * allot the first empty slot in the array
1991 for (count
=0; count
< BOARD_COUNT
; count
++) {
1992 if (isi_card
[count
].base
== 0) {
1993 isi_card
[count
].base
= ioaddr
;
1994 isi_card
[count
].irq
= pciirq
;
1995 isi_card
[count
].isa
= NO
;
2001 if (card
>= BOARD_COUNT
) break;
2005 if (!(isi_card
[0].base
|| isi_card
[1].base
|| isi_card
[2].base
|| isi_card
[3].base
)) {
2006 printk(KERN_ERR
"ISICOM: No valid card configuration. Driver cannot be initialized...\n");
2009 retval
=misc_register(&isiloader_device
);
2011 printk(KERN_ERR
"ISICOM: Unable to register firmware loader driver.\n");
2015 if (!isicom_init()) {
2016 if (misc_deregister(&isiloader_device
))
2017 printk(KERN_ERR
"ISICOM: Unable to unregister Firmware Loader driver\n");
2022 tx
.expires
= jiffies
+ 1;
2024 tx
.function
= isicom_tx
;
2031 void cleanup_module(void)
2034 current
->state
= TASK_INTERRUPTIBLE
;
2035 schedule_timeout(HZ
);
2037 remove_bh(ISICOM_BH
);
2040 printk("ISICOM: isicom_tx tx_count = %ld.\n", tx_count
);
2044 printk("ISICOM: uregistering isr ...\n");
2049 printk("ISICOM: unregistering drivers ...\n");
2051 unregister_drivers();
2054 printk("ISICOM: unregistering ioregion ...\n");
2056 unregister_ioregion();
2059 printk("ISICOM: freeing tmp_buf ...\n");
2061 free_page((unsigned long)tmp_buf
);
2064 printk("ISICOM: unregistering firmware loader ...\n");
2066 if (misc_deregister(&isiloader_device
))
2067 printk(KERN_ERR
"ISICOM: Unable to unregister Firmware Loader driver\n");