1 /* Derived from Applicom driver ac.c for SCO Unix */
2 /* Ported by David Woodhouse, Axiom (Cambridge) Ltd. */
3 /* Dave@mvhi.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/malloc.h>
26 #include <asm/errno.h>
28 #include <asm/uaccess.h>
29 #include <linux/miscdevice.h>
30 #include <linux/pci.h>
31 #include <linux/wait.h>
32 #include <linux/init.h>
33 #include <linux/compatmac.h>
37 #if LINUX_VERSION_CODE < 0x20300
38 /* These probably want adding to <linux/compatmac.h> */
39 #define init_waitqueue_head(x) do { *(x) = NULL; } while (0);
40 #define PCI_BASE_ADDRESS(dev) (dev->base_address[0])
41 #define DECLARE_WAIT_QUEUE_HEAD(x) struct wait_queue *x
42 #define __setup(x,y) /* */
44 #define PCI_BASE_ADDRESS(dev) (dev->resource[0].start)
47 /* NOTE: We use for loops with {write,read}b() instead of
48 memcpy_{from,to}io throughout this driver. This is because
49 the board doesn't correctly handle word accesses - only
56 #define MAX_BOARD 8 /* maximum of pc board possible */
57 #define MAX_ISA_BOARD 4
58 #define LEN_RAM_IO 0x800
61 #ifndef PCI_VENDOR_ID_APPLICOM
62 #define PCI_VENDOR_ID_APPLICOM 0x1389
63 #define PCI_DEVICE_ID_APPLICOM_PCIGENERIC 0x0001
64 #define PCI_DEVICE_ID_APPLICOM_PCI2000IBS_CAN 0x0002
65 #define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003
67 #define MAX_PCI_DEVICE_NUM 3
69 static char *applicom_pci_devnames
[] = {
71 "PCI2000IBS / PCI2000CAN",
75 MODULE_AUTHOR("David Woodhouse & Applicom International");
76 MODULE_DESCRIPTION("Driver for Applicom Profibus card");
77 MODULE_PARM(irq
, "i");
78 MODULE_PARM_DESC(irq
, "IRQ of the Applicom board");
79 MODULE_PARM(mem
, "i");
80 MODULE_PARM_DESC(mem
, "Shared Memory Address of Applicom board");
82 MODULE_SUPPORTED_DEVICE("ac");
85 struct applicom_board
{
88 wait_queue_head_t FlagSleepSend
;
93 static unsigned int irq
= 0; /* interrupt number IRQ */
94 static unsigned long mem
= 0; /* physical segment of board */
96 static unsigned int numboards
; /* number of installed boards */
97 static volatile unsigned char Dummy
;
98 static DECLARE_WAIT_QUEUE_HEAD(FlagSleepRec
);
99 static unsigned int WriteErrorCount
; /* number of write error */
100 static unsigned int ReadErrorCount
; /* number of read error */
101 static unsigned int DeviceErrorCount
; /* number of device error */
103 static loff_t
ac_llseek(struct file
*, loff_t
, int);
104 static ssize_t
ac_read (struct file
*, char *, size_t, loff_t
*);
105 static ssize_t
ac_write (struct file
*, const char *, size_t, loff_t
*);
106 static int ac_ioctl(struct inode
*, struct file
*, unsigned int,
108 static void ac_interrupt(int, void *, struct pt_regs
*);
110 struct file_operations ac_fops
= {
118 struct miscdevice ac_miscdev
= {
124 static int dummy
; /* dev_id for request_irq() */
126 int ac_register_board(unsigned long physloc
, unsigned long loc
,
127 unsigned char boardno
)
129 volatile unsigned char byte_reset_it
;
131 if((readb(loc
+ CONF_END_TEST
) != 0x00) ||
132 (readb(loc
+ CONF_END_TEST
+ 1) != 0x55) ||
133 (readb(loc
+ CONF_END_TEST
+ 2) != 0xAA) ||
134 (readb(loc
+ CONF_END_TEST
+ 3) != 0xFF))
138 boardno
= readb(loc
+ NUMCARD_OWNER_TO_PC
);
140 if (!boardno
&& boardno
> MAX_BOARD
) {
141 printk(KERN_WARNING
"Board #%d (at 0x%lx) is out of range (1 <= x <= %d).\n",
142 boardno
, physloc
, MAX_BOARD
);
146 if (apbs
[boardno
- 1].RamIO
) {
147 printk(KERN_WARNING
"Board #%d (at 0x%lx) conflicts with previous board #%d (at 0x%lx)\n",
148 boardno
, physloc
, boardno
, apbs
[boardno
-1].PhysIO
);
154 apbs
[boardno
].PhysIO
= physloc
;
155 apbs
[boardno
].RamIO
= loc
;
156 init_waitqueue_head(&apbs
[boardno
].FlagSleepSend
);
157 spin_lock_init(&apbs
[boardno
].mutex
);
158 byte_reset_it
= readb(loc
+ RAM_IT_TO_PC
);
166 #define applicom_init init_module
168 void cleanup_module(void)
172 misc_deregister(&ac_miscdev
);
174 for (i
= 0; i
< MAX_BOARD
; i
++) {
179 iounmap((void *) apbs
[i
].RamIO
);
182 free_irq(apbs
[i
].irq
, &dummy
);
188 int __init
applicom_init(void)
191 struct pci_dev
*dev
= NULL
;
195 printk(KERN_INFO
"Applicom driver: $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $\n");
197 /* No mem and irq given - check for a PCI card */
199 while ( (dev
= pci_find_class(PCI_CLASS_OTHERS
<< 16, dev
))) {
201 if (dev
->vendor
!= PCI_VENDOR_ID_APPLICOM
)
204 if (dev
->device
> MAX_PCI_DEVICE_NUM
|| dev
->device
== 0)
207 if (pci_enable_device(dev
))
210 RamIO
= ioremap(PCI_BASE_ADDRESS(dev
), LEN_RAM_IO
);
213 printk(KERN_INFO
"ac.o: Failed to ioremap PCI memory space at 0x%lx\n", PCI_BASE_ADDRESS(dev
));
217 printk(KERN_INFO
"Applicom %s found at mem 0x%lx, irq %d\n",
218 applicom_pci_devnames
[dev
->device
-1], PCI_BASE_ADDRESS(dev
),
221 if (!(boardno
= ac_register_board(PCI_BASE_ADDRESS(dev
),
222 (unsigned long)RamIO
,0))) {
223 printk(KERN_INFO
"ac.o: PCI Applicom device doesn't have correct signature.\n");
228 if (request_irq(dev
->irq
, &ac_interrupt
, SA_SHIRQ
, "Applicom PCI", &dummy
)) {
229 printk(KERN_INFO
"Could not allocate IRQ %d for PCI Applicom device.\n", dev
->irq
);
231 apbs
[boardno
- 1].RamIO
= 0;
235 /* Enable interrupts. */
237 writeb(0x40, apbs
[boardno
- 1].RamIO
+ RAM_IT_FROM_PC
);
239 apbs
[boardno
- 1].irq
= dev
->irq
;
242 /* Finished with PCI cards. If none registered,
243 * and there was no mem/irq specified, exit */
249 printk(KERN_INFO
"ac.o: No PCI boards found.\n");
250 printk(KERN_INFO
"ac.o: For an ISA board you must supply memory and irq parameters.\n");
255 /* Now try the specified ISA cards */
257 RamIO
= ioremap(mem
, LEN_RAM_IO
* MAX_ISA_BOARD
);
260 printk(KERN_INFO
"ac.o: Failed to ioremap ISA memory space at 0x%lx\n", mem
);
262 for (i
= 0; i
< MAX_ISA_BOARD
; i
++) {
263 RamIO
= ioremap(mem
+ (LEN_RAM_IO
* i
), LEN_RAM_IO
);
266 printk(KERN_INFO
"ac.o: Failed to ioremap the ISA card's memory space (slot #%d)\n", i
+ 1);
270 if (!(boardno
= ac_register_board((unsigned long)mem
+ (LEN_RAM_IO
*i
),
271 (unsigned long)RamIO
,i
+1))) {
276 printk(KERN_NOTICE
"Applicom ISA card found at mem 0x%lx, irq %d\n", mem
+ (LEN_RAM_IO
*i
), irq
);
279 if (request_irq(irq
, &ac_interrupt
, SA_SHIRQ
, "Applicom ISA", &dummy
)) {
280 printk(KERN_WARNING
"Could not allocate IRQ %d for ISA Applicom device.\n", irq
);
281 iounmap((void *) RamIO
);
282 apbs
[boardno
- 1].RamIO
= 0;
284 apbs
[boardno
- 1].irq
= irq
;
287 apbs
[boardno
- 1].irq
= 0;
293 printk(KERN_WARNING
"ac.o: No valid ISA Applicom boards found at mem 0x%lx\n",mem
);
296 init_waitqueue_head(&FlagSleepRec
);
300 DeviceErrorCount
= 0;
303 misc_register(&ac_miscdev
);
304 for (i
= 0; i
< MAX_BOARD
; i
++) {
306 char boardname
[(SERIAL_NUMBER
- TYPE_CARD
) + 1];
311 for (serial
= 0; serial
< SERIAL_NUMBER
- TYPE_CARD
; serial
++)
312 boardname
[serial
] = readb(apbs
[i
].RamIO
+ TYPE_CARD
+ serial
);
314 boardname
[serial
] = 0;
317 printk(KERN_INFO
"Applicom board %d: %s, PROM V%d.%d",
319 (int)(readb(apbs
[i
].RamIO
+ VERS
) >> 4),
320 (int)(readb(apbs
[i
].RamIO
+ VERS
) & 0xF));
322 serial
= (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
) << 16) +
323 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 1) << 8) +
324 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 2) );
327 printk(" S/N %d\n", serial
);
340 __initcall(applicom_init
);
343 static loff_t
ac_llseek(struct file
*file
, loff_t offset
, int origin
)
348 static ssize_t
ac_write(struct file
*file
, const char *buf
, size_t count
, loff_t
* ppos
)
350 unsigned int NumCard
; /* Board number 1 -> 8 */
351 unsigned int IndexCard
; /* Index board number 0 -> 7 */
352 unsigned char TicCard
; /* Board TIC to send */
353 unsigned long flags
; /* Current priority */
354 struct st_ram_io st_loc
;
355 struct mailbox tmpmailbox
;
359 DECLARE_WAITQUEUE(wait
, current
);
361 if (count
!= sizeof(struct st_ram_io
) + sizeof(struct mailbox
)) {
362 static int warncount
= 5;
364 printk(KERN_INFO
"Hmmm. write() of Applicom card, length %d != expected %d\n",
365 count
, sizeof(struct st_ram_io
) + sizeof(struct mailbox
));
371 if(copy_from_user(&st_loc
, buf
, sizeof(struct st_ram_io
)))
374 if(copy_from_user(&tmpmailbox
, &buf
[sizeof(struct st_ram_io
)],
375 sizeof(struct mailbox
)))
378 NumCard
= st_loc
.num_card
; /* board number to send */
379 TicCard
= st_loc
.tic_des_from_pc
; /* tic number to send */
380 IndexCard
= NumCard
- 1;
382 if((NumCard
< 1) || (NumCard
> MAX_BOARD
) || !apbs
[IndexCard
].RamIO
)
386 printk("Write to applicom card #%d. struct st_ram_io follows:",
389 for (c
= 0; c
< sizeof(struct st_ram_io
);) {
391 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &st_loc
)[c
]);
393 for (c
++; c
% 8 && c
< sizeof(struct st_ram_io
); c
++) {
394 printk(" %2.2X", ((unsigned char *) &st_loc
)[c
]);
398 printk("\nstruct mailbox follows:");
400 for (c
= 0; c
< sizeof(struct mailbox
);) {
401 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &tmpmailbox
)[c
]);
403 for (c
++; c
% 8 && c
< sizeof(struct mailbox
); c
++) {
404 printk(" %2.2X", ((unsigned char *) &tmpmailbox
)[c
]);
411 spin_lock_irqsave(&apbs
[IndexCard
].mutex
, flags
);
413 /* Test octet ready correct */
414 if(readb(apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
) > 2) {
415 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
416 spin_unlock_irqrestore(&apbs
[IndexCard
].mutex
, flags
);
417 printk(KERN_WARNING
"APPLICOM driver write error board %d, DataFromPcReady = %d\n",
418 IndexCard
,(int)readb(apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
));
423 /* Place ourselves on the wait queue */
424 current
->state
= TASK_INTERRUPTIBLE
;
425 add_wait_queue(&apbs
[IndexCard
].FlagSleepSend
, &wait
);
427 /* Check whether the card is ready for us */
428 while (readb(apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
) != 0) {
429 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
430 /* It's busy. Sleep. */
432 spin_unlock_irqrestore(&apbs
[IndexCard
].mutex
, flags
);
434 if (signal_pending(current
)) {
435 remove_wait_queue(&apbs
[IndexCard
].FlagSleepSend
,
439 spin_lock_irqsave(&apbs
[IndexCard
].mutex
, flags
);
442 /* We may not have actually slept */
443 current
->state
= TASK_RUNNING
;
444 remove_wait_queue(&apbs
[IndexCard
].FlagSleepSend
, &wait
);
446 writeb(1, apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
448 /* Which is best - lock down the pages with rawio and then
449 copy directly, or use bounce buffers? For now we do the latter
450 because it works with 2.2 still */
452 unsigned char *from
= (unsigned char *) &tmpmailbox
;
453 unsigned long to
= (unsigned long) apbs
[IndexCard
].RamIO
+ RAM_FROM_PC
;
456 for (c
= 0; c
< sizeof(struct mailbox
); c
++)
457 writeb(*(from
++), to
++);
460 writeb(0x20, apbs
[IndexCard
].RamIO
+ TIC_OWNER_FROM_PC
);
461 writeb(0xff, apbs
[IndexCard
].RamIO
+ NUMCARD_OWNER_FROM_PC
);
462 writeb(TicCard
, apbs
[IndexCard
].RamIO
+ TIC_DES_FROM_PC
);
463 writeb(NumCard
, apbs
[IndexCard
].RamIO
+ NUMCARD_DES_FROM_PC
);
464 writeb(2, apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
465 writeb(1, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
466 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
467 spin_unlock_irqrestore(&apbs
[IndexCard
].mutex
, flags
);
471 static int do_ac_read(int IndexCard
, char *buf
)
473 struct st_ram_io st_loc
;
474 struct mailbox tmpmailbox
; /* bounce buffer - can't copy to user space with cli() */
475 unsigned long from
= (unsigned long)apbs
[IndexCard
].RamIO
+ RAM_TO_PC
;
476 unsigned char *to
= (unsigned char *)&tmpmailbox
;
481 st_loc
.tic_owner_to_pc
= readb(apbs
[IndexCard
].RamIO
+ TIC_OWNER_TO_PC
);
482 st_loc
.numcard_owner_to_pc
= readb(apbs
[IndexCard
].RamIO
+ NUMCARD_OWNER_TO_PC
);
488 for (c
= 0; c
< sizeof(struct mailbox
); c
++)
489 *(to
++) = readb(from
++);
491 writeb(1, apbs
[IndexCard
].RamIO
+ ACK_FROM_PC_READY
);
492 writeb(1, apbs
[IndexCard
].RamIO
+ TYP_ACK_FROM_PC
);
493 writeb(IndexCard
+1, apbs
[IndexCard
].RamIO
+ NUMCARD_ACK_FROM_PC
);
494 writeb(readb(apbs
[IndexCard
].RamIO
+ TIC_OWNER_TO_PC
),
495 apbs
[IndexCard
].RamIO
+ TIC_ACK_FROM_PC
);
496 writeb(2, apbs
[IndexCard
].RamIO
+ ACK_FROM_PC_READY
);
497 writeb(0, apbs
[IndexCard
].RamIO
+ DATA_TO_PC_READY
);
498 writeb(2, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
499 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
502 printk("Read from applicom card #%d. struct st_ram_io follows:", NumCard
);
504 for (c
= 0; c
< sizeof(struct st_ram_io
);) {
505 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &st_loc
)[c
]);
507 for (c
++; c
% 8 && c
< sizeof(struct st_ram_io
); c
++) {
508 printk(" %2.2X", ((unsigned char *) &st_loc
)[c
]);
512 printk("\nstruct mailbox follows:");
514 for (c
= 0; c
< sizeof(struct mailbox
);) {
515 printk("\n%5.5X: %2.2X", c
, ((unsigned char *) &tmpmailbox
)[c
]);
517 for (c
++; c
% 8 && c
< sizeof(struct mailbox
); c
++) {
518 printk(" %2.2X", ((unsigned char *) &tmpmailbox
)[c
]);
524 /* Je suis stupide. DW. */
526 if (copy_to_user(buf
, &st_loc
, sizeof(struct st_ram_io
)))
528 if (copy_to_user(&buf
[sizeof(struct st_ram_io
)], &tmpmailbox
, sizeof(struct mailbox
)))
531 return (sizeof(struct st_ram_io
) + sizeof(struct mailbox
));
534 static ssize_t
ac_read (struct file
*filp
, char *buf
, size_t count
, loff_t
*ptr
)
540 DECLARE_WAITQUEUE(wait
, current
);
544 /* No need to ratelimit this. Only root can trigger it anyway */
545 if (count
!= sizeof(struct st_ram_io
) + sizeof(struct mailbox
)) {
546 printk( KERN_WARNING
"Hmmm. read() of Applicom card, length %d != expected %d\n",
547 count
,sizeof(struct st_ram_io
) + sizeof(struct mailbox
));
552 /* Stick ourself on the wait queue */
553 current
->state
= TASK_INTERRUPTIBLE
;
554 add_wait_queue(&FlagSleepRec
, &wait
);
556 /* Scan each board, looking for one which has a packet for us */
557 for (i
=0; i
< MAX_BOARD
; i
++) {
560 spin_lock_irqsave(&apbs
[i
].mutex
, flags
);
562 tmp
= readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
);
565 /* Got a packet for us */
566 ret
= do_ac_read(i
, buf
);
567 spin_unlock_irqrestore(&apbs
[i
].mutex
, flags
);
568 current
->state
= TASK_RUNNING
;
569 remove_wait_queue(&FlagSleepRec
, &wait
);
575 Dummy
= readb(apbs
[i
].RamIO
+ VERS
);
577 spin_unlock_irqrestore(&apbs
[i
].mutex
, flags
);
578 current
->state
= TASK_RUNNING
;
579 remove_wait_queue(&FlagSleepRec
, &wait
);
581 printk(KERN_WARNING
"APPLICOM driver read error board %d, DataToPcReady = %d\n",
582 i
,(int)readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
));
587 /* Nothing for us. Try the next board */
588 Dummy
= readb(apbs
[i
].RamIO
+ VERS
);
589 spin_unlock_irqrestore(&apbs
[i
].mutex
, flags
);
593 /* OK - No boards had data for us. Sleep now */
596 remove_wait_queue(&FlagSleepRec
, &wait
);
598 if (signal_pending(current
))
602 if (loopcount
++ > 2) {
603 printk("Looping in ac_read. loopcount %d\n", loopcount
);
609 static void ac_interrupt(int vec
, void *dev_instance
, struct pt_regs
*regs
)
612 unsigned int FlagInt
;
613 unsigned int LoopCount
;
615 // printk("Applicom interrupt on IRQ %d occurred\n", vec);
621 for (i
= 0; i
< MAX_BOARD
; i
++) {
623 /* Skip if this board doesn't exist */
627 spin_lock(&apbs
[i
].mutex
);
629 /* Skip if this board doesn't want attention */
630 if(readb(apbs
[i
].RamIO
+ RAM_IT_TO_PC
) == 0) {
631 spin_unlock(&apbs
[i
].mutex
);
636 writeb(0, apbs
[i
].RamIO
+ RAM_IT_TO_PC
);
638 if (readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
) > 2) {
639 printk(KERN_WARNING
"APPLICOM driver interrupt err board %d, DataToPcReady = %d\n",
640 i
+1,(int)readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
));
644 if((readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
) > 2) &&
645 (readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
) != 6)) {
647 printk(KERN_WARNING
"APPLICOM driver interrupt err board %d, DataFromPcReady = %d\n",
648 i
+1,(int)readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
));
652 if (readb(apbs
[i
].RamIO
+ DATA_TO_PC_READY
) == 2) { /* mailbox sent by the card ? */
653 if (waitqueue_active(&FlagSleepRec
)) {
654 wake_up_interruptible(&FlagSleepRec
);
658 if (readb(apbs
[i
].RamIO
+ DATA_FROM_PC_READY
) == 0) { /* ram i/o free for write by pc ? */
659 if (waitqueue_active(&apbs
[i
].FlagSleepSend
)) { /* process sleep during read ? */
660 wake_up_interruptible(&apbs
[i
].FlagSleepSend
);
663 Dummy
= readb(apbs
[i
].RamIO
+ VERS
);
665 if(readb(apbs
[i
].RamIO
+ RAM_IT_TO_PC
)) {
666 /* There's another int waiting on this card */
667 spin_unlock(&apbs
[i
].mutex
);
670 spin_unlock(&apbs
[i
].mutex
);
677 } while(LoopCount
< 2);
682 static int ac_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
684 { /* @ ADG ou ATO selon le cas */
686 unsigned char IndexCard
;
689 volatile unsigned char byte_reset_it
;
690 struct st_ram_io
*adgl
;
692 /* In general, the device is only openable by root anyway, so we're not
693 particularly concerned that bogus ioctls can flood the console. */
695 adgl
= kmalloc(sizeof(struct st_ram_io
), GFP_KERNEL
);
699 if (copy_from_user(adgl
, (void *)arg
,sizeof(struct st_ram_io
))) {
704 IndexCard
= adgl
->num_card
-1;
706 if(cmd
!= 0 && cmd
!= 6 &&
707 ((IndexCard
>= MAX_BOARD
) || !apbs
[IndexCard
].RamIO
)) {
708 static int warncount
= 10;
710 printk( KERN_WARNING
"APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard
+1);
720 pmem
= apbs
[IndexCard
].RamIO
;
721 for (i
= 0; i
< sizeof(struct st_ram_io
); i
++)
722 ((unsigned char *)adgl
)[i
]=readb(pmem
++);
723 if (copy_to_user((void *)arg
, adgl
, sizeof(struct st_ram_io
)))
727 pmem
= apbs
[IndexCard
].RamIO
+ CONF_END_TEST
;
728 for (i
= 0; i
< 4; i
++)
729 adgl
->conf_end_test
[i
] = readb(pmem
++);
730 for (i
= 0; i
< 2; i
++)
731 adgl
->error_code
[i
] = readb(pmem
++);
732 for (i
= 0; i
< 4; i
++)
733 adgl
->parameter_error
[i
] = readb(pmem
++);
734 pmem
= apbs
[IndexCard
].RamIO
+ VERS
;
735 adgl
->vers
= readb(pmem
);
736 pmem
= apbs
[IndexCard
].RamIO
+ TYPE_CARD
;
737 for (i
= 0; i
< 20; i
++)
738 adgl
->reserv1
[i
] = readb(pmem
++);
739 *(int *)&adgl
->reserv1
[20] =
740 (readb(apbs
[IndexCard
].RamIO
+ SERIAL_NUMBER
) << 16) +
741 (readb(apbs
[IndexCard
].RamIO
+ SERIAL_NUMBER
+ 1) << 8) +
742 (readb(apbs
[IndexCard
].RamIO
+ SERIAL_NUMBER
+ 2) );
744 if (copy_to_user((void *)arg
, adgl
, sizeof(struct st_ram_io
)))
748 pmem
= apbs
[IndexCard
].RamIO
+ CONF_END_TEST
;
749 for (i
= 0; i
< 10; i
++)
750 writeb(0xff, pmem
++);
751 writeb(adgl
->data_from_pc_ready
,
752 apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
754 writeb(1, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
756 for (i
= 0; i
< MAX_BOARD
; i
++) {
758 byte_reset_it
= readb(apbs
[i
].RamIO
+ RAM_IT_TO_PC
);
763 pmem
= apbs
[IndexCard
].RamIO
+ TIC_DES_FROM_PC
;
764 writeb(adgl
->tic_des_from_pc
, pmem
);
767 pmem
= apbs
[IndexCard
].RamIO
+ TIC_OWNER_TO_PC
;
768 adgl
->tic_owner_to_pc
= readb(pmem
++);
769 adgl
->numcard_owner_to_pc
= readb(pmem
);
770 if (copy_to_user((void *)arg
, adgl
,sizeof(struct st_ram_io
)))
774 writeb(adgl
->num_card
, apbs
[IndexCard
].RamIO
+ NUMCARD_OWNER_TO_PC
);
775 writeb(adgl
->num_card
, apbs
[IndexCard
].RamIO
+ NUMCARD_DES_FROM_PC
);
776 writeb(adgl
->num_card
, apbs
[IndexCard
].RamIO
+ NUMCARD_ACK_FROM_PC
);
777 writeb(4, apbs
[IndexCard
].RamIO
+ DATA_FROM_PC_READY
);
778 writeb(1, apbs
[IndexCard
].RamIO
+ RAM_IT_FROM_PC
);
781 printk(KERN_INFO
"APPLICOM driver release .... V2.8.0 ($Revision: 1.30 $)\n");
782 printk(KERN_INFO
"Number of installed boards . %d\n", (int) numboards
);
783 printk(KERN_INFO
"Segment of board ........... %X\n", (int) mem
);
784 printk(KERN_INFO
"Interrupt IRQ number ....... %d\n", (int) irq
);
785 for (i
= 0; i
< MAX_BOARD
; i
++) {
787 char boardname
[(SERIAL_NUMBER
- TYPE_CARD
) + 1];
792 for (serial
= 0; serial
< SERIAL_NUMBER
- TYPE_CARD
; serial
++)
793 boardname
[serial
] = readb(apbs
[i
].RamIO
+ TYPE_CARD
+ serial
);
794 boardname
[serial
] = 0;
796 printk(KERN_INFO
"Prom version board %d ....... V%d.%d %s",
798 (int)(readb(apbs
[IndexCard
].RamIO
+ VERS
) >> 4),
799 (int)(readb(apbs
[IndexCard
].RamIO
+ VERS
) & 0xF),
803 serial
= (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
) << 16) +
804 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 1) << 8) +
805 (readb(apbs
[i
].RamIO
+ SERIAL_NUMBER
+ 2) );
808 printk(" S/N %d\n", serial
);
812 if (DeviceErrorCount
!= 0)
813 printk(KERN_INFO
"DeviceErrorCount ........... %d\n", DeviceErrorCount
);
814 if (ReadErrorCount
!= 0)
815 printk(KERN_INFO
"ReadErrorCount ............. %d\n", ReadErrorCount
);
816 if (WriteErrorCount
!= 0)
817 printk(KERN_INFO
"WriteErrorCount ............ %d\n", WriteErrorCount
);
818 if (waitqueue_active(&FlagSleepRec
))
819 printk(KERN_INFO
"Process in read pending\n");
820 for (i
= 0; i
< MAX_BOARD
; i
++) {
821 if (apbs
[i
].RamIO
&& waitqueue_active(&apbs
[i
].FlagSleepSend
))
822 printk(KERN_INFO
"Process in write pending board %d\n",i
+1);
826 printk(KERN_INFO
"APPLICOM driver ioctl, unknown function code %d\n",cmd
) ;
830 Dummy
= readb(apbs
[IndexCard
].RamIO
+ VERS
);
836 static int __init
applicom_setup(char *str
)
840 (void) get_options(str
, 4, ints
);
843 printk(KERN_WARNING
"Too many arguments to 'applicom=', expected mem,irq only.\n");
847 printk(KERN_INFO
"applicom numargs: %d\n", ints
[0]);
856 __setup("applicom=", applicom_setup
);