1 /* Derived from Applicom driver ac.c for SCO Unix */
2 /* Ported by David Woodhouse, Axiom (Cambridge) Ltd. */
3 /* dwmw2@redhat.com 30/8/98 */
4 /* $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $ */
5 /* This module is for Linux 2.1 and 2.2 series kernels. */
6 /*****************************************************************************/
7 /* J PAGET 18/02/94 passage V2.4.2 ioctl avec code 2 reset to les interrupt */
8 /* ceci pour reseter correctement apres une sortie sauvage */
9 /* J PAGET 02/05/94 passage V2.4.3 dans le traitement de d'interruption, */
10 /* LoopCount n'etait pas initialise a 0. */
11 /* F LAFORSE 04/07/95 version V2.6.0 lecture bidon apres acces a une carte */
12 /* pour liberer le bus */
13 /* J.PAGET 19/11/95 version V2.6.1 Nombre, addresse,irq n'est plus configure */
14 /* et passe en argument a acinit, mais est scrute sur le bus pour s'adapter */
15 /* au nombre de cartes presentes sur le bus. IOCL code 6 affichait V2.4.3 */
16 /* F.LAFORSE 28/11/95 creation de fichiers acXX.o avec les differentes */
17 /* adresses de base des cartes, IOCTL 6 plus complet */
18 /* J.PAGET le 19/08/96 copie de la version V2.6 en V2.8.0 sans modification */
19 /* de code autre que le texte V2.6.1 en V2.8.0 */
20 /*****************************************************************************/
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/interrupt.h>
26 #include <linux/slab.h>
27 #include <linux/errno.h>
28 #include <linux/miscdevice.h>
29 #include <linux/pci.h>
30 #include <linux/wait.h>
31 #include <linux/init.h>
32 #include <linux/compatmac.h>
35 #include <asm/uaccess.h>
39 #if LINUX_VERSION_CODE < 0x20300
40 /* These probably want adding to <linux/compatmac.h> */
41 #define init_waitqueue_head(x) do { *(x) = NULL; } while (0)
42 #define PCI_BASE_ADDRESS(dev) (dev->base_address[0])
43 #define DECLARE_WAIT_QUEUE_HEAD(x) struct wait_queue *x
44 #define __setup(x,y) /* */
46 #define PCI_BASE_ADDRESS(dev) (dev->resource[0].start)
49 /* NOTE: We use for loops with {write,read}b() instead of
50 memcpy_{from,to}io throughout this driver. This is because
51 the board doesn't correctly handle word accesses - only
58 #define MAX_BOARD 8 /* maximum of pc board possible */
59 #define MAX_ISA_BOARD 4
60 #define LEN_RAM_IO 0x800
63 #ifndef PCI_VENDOR_ID_APPLICOM
64 #define PCI_VENDOR_ID_APPLICOM 0x1389
65 #define PCI_DEVICE_ID_APPLICOM_PCIGENERIC 0x0001
66 #define PCI_DEVICE_ID_APPLICOM_PCI2000IBS_CAN 0x0002
67 #define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003
69 #define MAX_PCI_DEVICE_NUM 3
71 static char *applicom_pci_devnames
[] = {
73 "PCI2000IBS / PCI2000CAN",
77 static struct pci_device_id applicom_pci_tbl
[] = {
78 { PCI_VENDOR_ID_APPLICOM
, PCI_DEVICE_ID_APPLICOM_PCIGENERIC
,
79 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
80 { PCI_VENDOR_ID_APPLICOM
, PCI_DEVICE_ID_APPLICOM_PCI2000IBS_CAN
,
81 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
82 { PCI_VENDOR_ID_APPLICOM
, PCI_DEVICE_ID_APPLICOM_PCI2000PFB
,
83 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
86 MODULE_DEVICE_TABLE(pci
, applicom_pci_tbl
);
88 MODULE_AUTHOR("David Woodhouse & Applicom International");
89 MODULE_DESCRIPTION("Driver for Applicom Profibus card");
90 MODULE_LICENSE("GPL");
91 MODULE_PARM(irq
, "i");
92 MODULE_PARM_DESC(irq
, "IRQ of the Applicom board");
93 MODULE_PARM(mem
, "i");
94 MODULE_PARM_DESC(mem
, "Shared Memory Address of Applicom board");
96 MODULE_SUPPORTED_DEVICE("ac");
99 static struct applicom_board
{
100 unsigned long PhysIO
;
102 wait_queue_head_t FlagSleepSend
;
107 static unsigned int irq
= 0; /* interrupt number IRQ */
108 static unsigned long mem
= 0; /* physical segment of board */
110 static unsigned int numboards
; /* number of installed boards */
111 static volatile unsigned char Dummy
;
112 static DECLARE_WAIT_QUEUE_HEAD(FlagSleepRec
);
113 static unsigned int WriteErrorCount
; /* number of write error */
114 static unsigned int ReadErrorCount
; /* number of read error */
115 static unsigned int DeviceErrorCount
; /* number of device error */
117 static ssize_t
ac_read (struct file
*, char *, size_t, loff_t
*);
118 static ssize_t
ac_write (struct file
*, const char *, size_t, loff_t
*);
119 static int ac_ioctl(struct inode
*, struct file
*, unsigned int,
121 static void ac_interrupt(int, void *, struct pt_regs
*);
123 static struct file_operations ac_fops
= {
124 .owner
= THIS_MODULE
,
131 static struct miscdevice ac_miscdev
= {
137 static int dummy
; /* dev_id for request_irq() */
139 static int ac_register_board(unsigned long physloc
, unsigned long loc
,
140 unsigned char boardno
)
142 volatile unsigned char byte_reset_it
;
144 if((readb(loc
+ CONF_END_TEST
) != 0x00) ||
145 (readb(loc
+ CONF_END_TEST
+ 1) != 0x55) ||
146 (readb(loc
+ CONF_END_TEST
+ 2) != 0xAA) ||
147 (readb(loc
+ CONF_END_TEST
+ 3) != 0xFF))
151 boardno
= readb(loc
+ NUMCARD_OWNER_TO_PC
);
153 if (!boardno
&& boardno
> MAX_BOARD
) {
154 printk(KERN_WARNING
"Board #%d (at 0x%lx) is out of range (1 <= x <= %d).\n",
155 boardno
, physloc
, MAX_BOARD
);
159 if (apbs
[boardno
- 1].RamIO
) {
160 printk(KERN_WARNING
"Board #%d (at 0x%lx) conflicts with previous board #%d (at 0x%lx)\n",
161 boardno
, physloc
, boardno
, apbs
[boardno
-1].PhysIO
);
167 apbs
[boardno
].PhysIO
= physloc
;
168 apbs
[boardno
].RamIO
= loc
;
169 init_waitqueue_head(&apbs
[boardno
].FlagSleepSend
);
170 spin_lock_init(&apbs
[boardno
].mutex
);
171 byte_reset_it
= readb(loc
+ RAM_IT_TO_PC
);
179 #define applicom_init init_module
181 void cleanup_module(void)
185 misc_deregister(&ac_miscdev
);
187 for (i
= 0; i
< MAX_BOARD
; i
++) {
192 iounmap((void *) apbs
[i
].RamIO
);
195 free_irq(apbs
[i
].irq
, &dummy
);
201 int __init
applicom_init(void)
204 struct pci_dev
*dev
= NULL
;
208 printk(KERN_INFO
"Applicom driver: $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $\n");
210 /* No mem and irq given - check for a PCI card */
212 while ( (dev
= pci_find_class(PCI_CLASS_OTHERS
<< 16, dev
))) {
214 if (dev
->vendor
!= PCI_VENDOR_ID_APPLICOM
)
217 if (dev
->device
> MAX_PCI_DEVICE_NUM
|| dev
->device
== 0)
220 if (pci_enable_device(dev
))
223 RamIO
= ioremap(PCI_BASE_ADDRESS(dev
), LEN_RAM_IO
);
226 printk(KERN_INFO
"ac.o: Failed to ioremap PCI memory space at 0x%lx\n", PCI_BASE_ADDRESS(dev
));
230 printk(KERN_INFO
"Applicom %s found at mem 0x%lx, irq %d\n",
231 applicom_pci_devnames
[dev
->device
-1], PCI_BASE_ADDRESS(dev
),
234 if (!(boardno
= ac_register_board(PCI_BASE_ADDRESS(dev
),
235 (unsigned long)RamIO
,0))) {
236 printk(KERN_INFO
"ac.o: PCI Applicom device doesn't have correct signature.\n");
241 if (request_irq(dev
->irq
, &ac_interrupt
, SA_SHIRQ
, "Applicom PCI", &dummy
)) {
242 printk(KERN_INFO
"Could not allocate IRQ %d for PCI Applicom device.\n", dev
->irq
);
244 apbs
[boardno
- 1].RamIO
= 0;
248 /* Enable interrupts. */
250 writeb(0x40, apbs
[boardno
- 1].RamIO
+ RAM_IT_FROM_PC
);
252 apbs
[boardno
- 1].irq
= dev
->irq
;
255 /* Finished with PCI cards. If none registered,
256 * and there was no mem/irq specified, exit */
262 printk(KERN_INFO
"ac.o: No PCI boards found.\n");
263 printk(KERN_INFO
"ac.o: For an ISA board you must supply memory and irq parameters.\n");
268 /* Now try the specified ISA cards */
271 RamIO
= ioremap(mem
, LEN_RAM_IO
* MAX_ISA_BOARD
);
274 printk(KERN_INFO
"ac.o: Failed to ioremap ISA memory space at 0x%lx\n", mem
);
276 for (i
= 0; i
< MAX_ISA_BOARD
; i
++) {
277 RamIO
= ioremap(mem
+ (LEN_RAM_IO
* i
), LEN_RAM_IO
);
280 printk(KERN_INFO
"ac.o: Failed to ioremap the ISA card's memory space (slot #%d)\n", i
+ 1);
284 if (!(boardno
= ac_register_board((unsigned long)mem
+ (LEN_RAM_IO
*i
),
285 (unsigned long)RamIO
,i
+1))) {
290 printk(KERN_NOTICE
"Applicom ISA card found at mem 0x%lx, irq %d\n", mem
+ (LEN_RAM_IO
*i
), irq
);
293 if (request_irq(irq
, &ac_interrupt
, SA_SHIRQ
, "Applicom ISA", &dummy
)) {
294 printk(KERN_WARNING
"Could not allocate IRQ %d for ISA Applicom device.\n", irq
);
295 iounmap((void *) RamIO
);
296 apbs
[boardno
- 1].RamIO
= 0;
298 apbs
[boardno
- 1].irq
= irq
;
301 apbs
[boardno
- 1].irq
= 0;
307 printk(KERN_WARNING
"ac.o: No valid ISA Applicom boards found at mem 0x%lx\n",mem
);
310 init_waitqueue_head(&FlagSleepRec
);
314 DeviceErrorCount
= 0;
317 misc_register(&ac_miscdev
);
318 for (i
= 0; i
< MAX_BOARD
; i
++) {
320 char boardname
[(SERIAL_NUMBER
- TYPE_CARD
) + 1];
325 for (serial
= 0; serial
< SERIAL_NUMBER
- TYPE_CARD
; serial
++)
326 boardname
[serial
] = readb(apbs
[i
].RamIO
+ TYPE_CARD
+ serial
);
328 boardname
[serial
] = 0;
331 printk(KERN_INFO
"Applicom board %d: %s, PROM V%d.%d",
333 (int)(readb(apbs
[i
].RamIO
+ VERS
) >> 4),
334 (int)(readb(apbs
[i
].RamIO
+ VERS
) & 0xF));
336 serial
= (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
) << 16) +
337 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 1) << 8) +
338 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 2) );
341 printk(" S/N %d\n", serial
);
354 __initcall(applicom_init
);
357 static ssize_t
ac_write(struct file
*file
, const char *buf
, size_t count
, loff_t
* ppos
)
359 unsigned int NumCard
; /* Board number 1 -> 8 */
360 unsigned int IndexCard
; /* Index board number 0 -> 7 */
361 unsigned char TicCard
; /* Board TIC to send */
362 unsigned long flags
; /* Current priority */
363 struct st_ram_io st_loc
;
364 struct mailbox tmpmailbox
;
368 DECLARE_WAITQUEUE(wait
, current
);
370 if (count
!= sizeof(struct st_ram_io
) + sizeof(struct mailbox
)) {
371 static int warncount
= 5;
373 printk(KERN_INFO
"Hmmm. write() of Applicom card, length %d != expected %d\n",
374 count
, sizeof(struct st_ram_io
) + sizeof(struct mailbox
));
380 if(copy_from_user(&st_loc
, buf
, sizeof(struct st_ram_io
)))
383 if(copy_from_user(&tmpmailbox
, &buf
[sizeof(struct st_ram_io
)],
384 sizeof(struct mailbox
)))
387 NumCard
= st_loc
.num_card
; /* board number to send */
388 TicCard
= st_loc
.tic_des_from_pc
; /* tic number to send */
389 IndexCard
= NumCard
- 1;
391 if((NumCard
< 1) || (NumCard
> MAX_BOARD
) || !apbs
[IndexCard
].RamIO
)
395 printk("Write to applicom card #%d. struct st_ram_io follows:",
398 for (c
= 0; c
< sizeof(struct st_ram_io
);) {
400 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &st_loc
)[c
]);
402 for (c
++; c
% 8 && c
< sizeof(struct st_ram_io
); c
++) {
403 printk(" %2.2X", ((unsigned char *) &st_loc
)[c
]);
407 printk("\nstruct mailbox follows:");
409 for (c
= 0; c
< sizeof(struct mailbox
);) {
410 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &tmpmailbox
)[c
]);
412 for (c
++; c
% 8 && c
< sizeof(struct mailbox
); c
++) {
413 printk(" %2.2X", ((unsigned char *) &tmpmailbox
)[c
]);
420 spin_lock_irqsave(&apbs
[IndexCard
].mutex
, flags
);
422 /* Test octet ready correct */
423 if(readb(apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
) > 2) {
424 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
425 spin_unlock_irqrestore(&apbs
[IndexCard
].mutex
, flags
);
426 printk(KERN_WARNING
"APPLICOM driver write error board %d, DataFromPcReady = %d\n",
427 IndexCard
,(int)readb(apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
));
432 /* Place ourselves on the wait queue */
433 set_current_state(TASK_INTERRUPTIBLE
);
434 add_wait_queue(&apbs
[IndexCard
].FlagSleepSend
, &wait
);
436 /* Check whether the card is ready for us */
437 while (readb(apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
) != 0) {
438 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
439 /* It's busy. Sleep. */
441 spin_unlock_irqrestore(&apbs
[IndexCard
].mutex
, flags
);
443 if (signal_pending(current
)) {
444 remove_wait_queue(&apbs
[IndexCard
].FlagSleepSend
,
448 spin_lock_irqsave(&apbs
[IndexCard
].mutex
, flags
);
449 set_current_state(TASK_INTERRUPTIBLE
);
452 /* We may not have actually slept */
453 set_current_state(TASK_RUNNING
);
454 remove_wait_queue(&apbs
[IndexCard
].FlagSleepSend
, &wait
);
456 writeb(1, apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
458 /* Which is best - lock down the pages with rawio and then
459 copy directly, or use bounce buffers? For now we do the latter
460 because it works with 2.2 still */
462 unsigned char *from
= (unsigned char *) &tmpmailbox
;
463 unsigned long to
= (unsigned long) apbs
[IndexCard
].RamIO
+ RAM_FROM_PC
;
466 for (c
= 0; c
< sizeof(struct mailbox
); c
++)
467 writeb(*(from
++), to
++);
470 writeb(0x20, apbs
[IndexCard
].RamIO
+ TIC_OWNER_FROM_PC
);
471 writeb(0xff, apbs
[IndexCard
].RamIO
+ NUMCARD_OWNER_FROM_PC
);
472 writeb(TicCard
, apbs
[IndexCard
].RamIO
+ TIC_DES_FROM_PC
);
473 writeb(NumCard
, apbs
[IndexCard
].RamIO
+ NUMCARD_DES_FROM_PC
);
474 writeb(2, apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
475 writeb(1, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
476 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
477 spin_unlock_irqrestore(&apbs
[IndexCard
].mutex
, flags
);
481 static int do_ac_read(int IndexCard
, char *buf
)
483 struct st_ram_io st_loc
;
484 struct mailbox tmpmailbox
; /* bounce buffer - can't copy to user space with cli() */
485 unsigned long from
= (unsigned long)apbs
[IndexCard
].RamIO
+ RAM_TO_PC
;
486 unsigned char *to
= (unsigned char *)&tmpmailbox
;
491 st_loc
.tic_owner_to_pc
= readb(apbs
[IndexCard
].RamIO
+ TIC_OWNER_TO_PC
);
492 st_loc
.numcard_owner_to_pc
= readb(apbs
[IndexCard
].RamIO
+ NUMCARD_OWNER_TO_PC
);
498 for (c
= 0; c
< sizeof(struct mailbox
); c
++)
499 *(to
++) = readb(from
++);
501 writeb(1, apbs
[IndexCard
].RamIO
+ ACK_FROM_PC_READY
);
502 writeb(1, apbs
[IndexCard
].RamIO
+ TYP_ACK_FROM_PC
);
503 writeb(IndexCard
+1, apbs
[IndexCard
].RamIO
+ NUMCARD_ACK_FROM_PC
);
504 writeb(readb(apbs
[IndexCard
].RamIO
+ TIC_OWNER_TO_PC
),
505 apbs
[IndexCard
].RamIO
+ TIC_ACK_FROM_PC
);
506 writeb(2, apbs
[IndexCard
].RamIO
+ ACK_FROM_PC_READY
);
507 writeb(0, apbs
[IndexCard
].RamIO
+ DATA_TO_PC_READY
);
508 writeb(2, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
509 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
512 printk("Read from applicom card #%d. struct st_ram_io follows:", NumCard
);
514 for (c
= 0; c
< sizeof(struct st_ram_io
);) {
515 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &st_loc
)[c
]);
517 for (c
++; c
% 8 && c
< sizeof(struct st_ram_io
); c
++) {
518 printk(" %2.2X", ((unsigned char *) &st_loc
)[c
]);
522 printk("\nstruct mailbox follows:");
524 for (c
= 0; c
< sizeof(struct mailbox
);) {
525 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &tmpmailbox
)[c
]);
527 for (c
++; c
% 8 && c
< sizeof(struct mailbox
); c
++) {
528 printk(" %2.2X", ((unsigned char *) &tmpmailbox
)[c
]);
534 #warning "Je suis stupide. DW. - copy*user in cli"
536 if (copy_to_user(buf
, &st_loc
, sizeof(struct st_ram_io
)))
538 if (copy_to_user(&buf
[sizeof(struct st_ram_io
)], &tmpmailbox
, sizeof(struct mailbox
)))
541 return (sizeof(struct st_ram_io
) + sizeof(struct mailbox
));
544 static ssize_t
ac_read (struct file
*filp
, char *buf
, size_t count
, loff_t
*ptr
)
550 DECLARE_WAITQUEUE(wait
, current
);
554 /* No need to ratelimit this. Only root can trigger it anyway */
555 if (count
!= sizeof(struct st_ram_io
) + sizeof(struct mailbox
)) {
556 printk( KERN_WARNING
"Hmmm. read() of Applicom card, length %d != expected %d\n",
557 count
,sizeof(struct st_ram_io
) + sizeof(struct mailbox
));
562 /* Stick ourself on the wait queue */
563 set_current_state(TASK_INTERRUPTIBLE
);
564 add_wait_queue(&FlagSleepRec
, &wait
);
566 /* Scan each board, looking for one which has a packet for us */
567 for (i
=0; i
< MAX_BOARD
; i
++) {
570 spin_lock_irqsave(&apbs
[i
].mutex
, flags
);
572 tmp
= readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
);
575 /* Got a packet for us */
576 ret
= do_ac_read(i
, buf
);
577 spin_unlock_irqrestore(&apbs
[i
].mutex
, flags
);
578 set_current_state(TASK_RUNNING
);
579 remove_wait_queue(&FlagSleepRec
, &wait
);
585 Dummy
= readb(apbs
[i
].RamIO
+ VERS
);
587 spin_unlock_irqrestore(&apbs
[i
].mutex
, flags
);
588 set_current_state(TASK_RUNNING
);
589 remove_wait_queue(&FlagSleepRec
, &wait
);
591 printk(KERN_WARNING
"APPLICOM driver read error board %d, DataToPcReady = %d\n",
592 i
,(int)readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
));
597 /* Nothing for us. Try the next board */
598 Dummy
= readb(apbs
[i
].RamIO
+ VERS
);
599 spin_unlock_irqrestore(&apbs
[i
].mutex
, flags
);
603 /* OK - No boards had data for us. Sleep now */
606 remove_wait_queue(&FlagSleepRec
, &wait
);
608 if (signal_pending(current
))
612 if (loopcount
++ > 2) {
613 printk("Looping in ac_read. loopcount %d\n", loopcount
);
619 static void ac_interrupt(int vec
, void *dev_instance
, struct pt_regs
*regs
)
622 unsigned int FlagInt
;
623 unsigned int LoopCount
;
625 // printk("Applicom interrupt on IRQ %d occurred\n", vec);
631 for (i
= 0; i
< MAX_BOARD
; i
++) {
633 /* Skip if this board doesn't exist */
637 spin_lock(&apbs
[i
].mutex
);
639 /* Skip if this board doesn't want attention */
640 if(readb(apbs
[i
].RamIO
+ RAM_IT_TO_PC
) == 0) {
641 spin_unlock(&apbs
[i
].mutex
);
646 writeb(0, apbs
[i
].RamIO
+ RAM_IT_TO_PC
);
648 if (readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
) > 2) {
649 printk(KERN_WARNING
"APPLICOM driver interrupt err board %d, DataToPcReady = %d\n",
650 i
+1,(int)readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
));
654 if((readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
) > 2) &&
655 (readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
) != 6)) {
657 printk(KERN_WARNING
"APPLICOM driver interrupt err board %d, DataFromPcReady = %d\n",
658 i
+1,(int)readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
));
662 if (readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
) == 2) { /* mailbox sent by the card ? */
663 if (waitqueue_active(&FlagSleepRec
)) {
664 wake_up_interruptible(&FlagSleepRec
);
668 if (readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
) == 0) { /* ram i/o free for write by pc ? */
669 if (waitqueue_active(&apbs
[i
].FlagSleepSend
)) { /* process sleep during read ? */
670 wake_up_interruptible(&apbs
[i
].FlagSleepSend
);
673 Dummy
= readb(apbs
[i
].RamIO
+ VERS
);
675 if(readb(apbs
[i
].RamIO
+ RAM_IT_TO_PC
)) {
676 /* There's another int waiting on this card */
677 spin_unlock(&apbs
[i
].mutex
);
680 spin_unlock(&apbs
[i
].mutex
);
687 } while(LoopCount
< 2);
692 static int ac_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
694 { /* @ ADG ou ATO selon le cas */
696 unsigned char IndexCard
;
699 volatile unsigned char byte_reset_it
;
700 struct st_ram_io
*adgl
;
702 /* In general, the device is only openable by root anyway, so we're not
703 particularly concerned that bogus ioctls can flood the console. */
705 adgl
= kmalloc(sizeof(struct st_ram_io
), GFP_KERNEL
);
709 if (copy_from_user(adgl
, (void *)arg
,sizeof(struct st_ram_io
))) {
714 IndexCard
= adgl
->num_card
-1;
716 if(cmd
!= 0 && cmd
!= 6 &&
717 ((IndexCard
>= MAX_BOARD
) || !apbs
[IndexCard
].RamIO
)) {
718 static int warncount
= 10;
720 printk( KERN_WARNING
"APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard
+1);
730 pmem
= apbs
[IndexCard
].RamIO
;
731 for (i
= 0; i
< sizeof(struct st_ram_io
); i
++)
732 ((unsigned char *)adgl
)[i
]=readb(pmem
++);
733 if (copy_to_user((void *)arg
, adgl
, sizeof(struct st_ram_io
)))
737 pmem
= apbs
[IndexCard
].RamIO
+ CONF_END_TEST
;
738 for (i
= 0; i
< 4; i
++)
739 adgl
->conf_end_test
[i
] = readb(pmem
++);
740 for (i
= 0; i
< 2; i
++)
741 adgl
->error_code
[i
] = readb(pmem
++);
742 for (i
= 0; i
< 4; i
++)
743 adgl
->parameter_error
[i
] = readb(pmem
++);
744 pmem
= apbs
[IndexCard
].RamIO
+ VERS
;
745 adgl
->vers
= readb(pmem
);
746 pmem
= apbs
[IndexCard
].RamIO
+ TYPE_CARD
;
747 for (i
= 0; i
< 20; i
++)
748 adgl
->reserv1
[i
] = readb(pmem
++);
749 *(int *)&adgl
->reserv1
[20] =
750 (readb(apbs
[IndexCard
].RamIO
+ SERIAL_NUMBER
) << 16) +
751 (readb(apbs
[IndexCard
].RamIO
+ SERIAL_NUMBER
+ 1) << 8) +
752 (readb(apbs
[IndexCard
].RamIO
+ SERIAL_NUMBER
+ 2) );
754 if (copy_to_user((void *)arg
, adgl
, sizeof(struct st_ram_io
)))
758 pmem
= apbs
[IndexCard
].RamIO
+ CONF_END_TEST
;
759 for (i
= 0; i
< 10; i
++)
760 writeb(0xff, pmem
++);
761 writeb(adgl
->data_from_pc_ready
,
762 apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
764 writeb(1, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
766 for (i
= 0; i
< MAX_BOARD
; i
++) {
768 byte_reset_it
= readb(apbs
[i
].RamIO
+ RAM_IT_TO_PC
);
773 pmem
= apbs
[IndexCard
].RamIO
+ TIC_DES_FROM_PC
;
774 writeb(adgl
->tic_des_from_pc
, pmem
);
777 pmem
= apbs
[IndexCard
].RamIO
+ TIC_OWNER_TO_PC
;
778 adgl
->tic_owner_to_pc
= readb(pmem
++);
779 adgl
->numcard_owner_to_pc
= readb(pmem
);
780 if (copy_to_user((void *)arg
, adgl
,sizeof(struct st_ram_io
)))
784 writeb(adgl
->num_card
, apbs
[IndexCard
].RamIO
+ NUMCARD_OWNER_TO_PC
);
785 writeb(adgl
->num_card
, apbs
[IndexCard
].RamIO
+ NUMCARD_DES_FROM_PC
);
786 writeb(adgl
->num_card
, apbs
[IndexCard
].RamIO
+ NUMCARD_ACK_FROM_PC
);
787 writeb(4, apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
788 writeb(1, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
791 printk(KERN_INFO
"APPLICOM driver release .... V2.8.0 ($Revision: 1.30 $)\n");
792 printk(KERN_INFO
"Number of installed boards . %d\n", (int) numboards
);
793 printk(KERN_INFO
"Segment of board ........... %X\n", (int) mem
);
794 printk(KERN_INFO
"Interrupt IRQ number ....... %d\n", (int) irq
);
795 for (i
= 0; i
< MAX_BOARD
; i
++) {
797 char boardname
[(SERIAL_NUMBER
- TYPE_CARD
) + 1];
802 for (serial
= 0; serial
< SERIAL_NUMBER
- TYPE_CARD
; serial
++)
803 boardname
[serial
] = readb(apbs
[i
].RamIO
+ TYPE_CARD
+ serial
);
804 boardname
[serial
] = 0;
806 printk(KERN_INFO
"Prom version board %d ....... V%d.%d %s",
808 (int)(readb(apbs
[IndexCard
].RamIO
+ VERS
) >> 4),
809 (int)(readb(apbs
[IndexCard
].RamIO
+ VERS
) & 0xF),
813 serial
= (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
) << 16) +
814 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 1) << 8) +
815 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 2) );
818 printk(" S/N %d\n", serial
);
822 if (DeviceErrorCount
!= 0)
823 printk(KERN_INFO
"DeviceErrorCount ........... %d\n", DeviceErrorCount
);
824 if (ReadErrorCount
!= 0)
825 printk(KERN_INFO
"ReadErrorCount ............. %d\n", ReadErrorCount
);
826 if (WriteErrorCount
!= 0)
827 printk(KERN_INFO
"WriteErrorCount ............ %d\n", WriteErrorCount
);
828 if (waitqueue_active(&FlagSleepRec
))
829 printk(KERN_INFO
"Process in read pending\n");
830 for (i
= 0; i
< MAX_BOARD
; i
++) {
831 if (apbs
[i
].RamIO
&& waitqueue_active(&apbs
[i
].FlagSleepSend
))
832 printk(KERN_INFO
"Process in write pending board %d\n",i
+1);
836 printk(KERN_INFO
"APPLICOM driver ioctl, unknown function code %d\n",cmd
) ;
840 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
846 static int __init
applicom_setup(char *str
)
850 (void) get_options(str
, 4, ints
);
853 printk(KERN_WARNING
"Too many arguments to 'applicom=', expected mem,irq only.\n");
857 printk(KERN_INFO
"applicom numargs: %d\n", ints
[0]);
866 __setup("applicom=", applicom_setup
);