23 #include <linux/kernel.h>
24 #include <linux/module.h>
26 #include <linux/sched.h>
27 #include <linux/slab.h>
28 #include <linux/errno.h>
31 #include <linux/pci.h>
32 #include <linux/wait.h>
37 #include <asm/uaccess.h>
52 #define MAX_ISA_BOARD 4
53 #define LEN_RAM_IO 0x800
56 #ifndef PCI_VENDOR_ID_APPLICOM
57 #define PCI_VENDOR_ID_APPLICOM 0x1389
58 #define PCI_DEVICE_ID_APPLICOM_PCIGENERIC 0x0001
59 #define PCI_DEVICE_ID_APPLICOM_PCI2000IBS_CAN 0x0002
60 #define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003
64 static char *applicom_pci_devnames[] = {
66 "PCI2000IBS / PCI2000CAN",
86 static struct applicom_board {
94 static unsigned int irq = 0;
95 static unsigned long mem = 0;
102 static unsigned int numboards;
103 static volatile unsigned char Dummy;
105 static unsigned int WriteErrorCount;
106 static unsigned int ReadErrorCount;
107 static unsigned int DeviceErrorCount;
109 static ssize_t ac_read (
struct file *,
char __user *,
size_t, loff_t *);
110 static ssize_t ac_write (
struct file *,
const char __user *,
size_t, loff_t *);
111 static long ac_ioctl(
struct file *,
unsigned int,
unsigned long);
119 .unlocked_ioctl = ac_ioctl,
130 static int ac_register_board(
unsigned long physloc,
void __iomem *
loc,
131 unsigned char boardno)
133 volatile unsigned char byte_reset_it;
150 if (apbs[boardno - 1].RamIO) {
151 printk(
KERN_WARNING "Board #%d (at 0x%lx) conflicts with previous board #%d (at 0x%lx)\n",
152 boardno, physloc, boardno, apbs[boardno-1].PhysIO);
158 apbs[boardno].PhysIO = physloc;
159 apbs[boardno].RamIO =
loc;
168 static void __exit applicom_exit(
void)
186 static int __init applicom_init(
void)
193 printk(
KERN_INFO "Applicom driver: $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $\n");
216 applicom_pci_devnames[dev->
device-1],
223 printk(
KERN_INFO "ac.o: PCI Applicom device doesn't have correct signature.\n");
233 apbs[boardno - 1].RamIO =
NULL;
241 apbs[boardno - 1].irq = dev->
irq;
252 printk(
KERN_INFO "ac.o: For an ISA board you must supply memory and irq parameters.\n");
263 printk(
KERN_INFO "ac.o: Failed to ioremap the ISA card's memory space (slot #%d)\n", i + 1);
267 if (!(boardno = ac_register_board((
unsigned long)
mem+ (
LEN_RAM_IO*i),
279 apbs[boardno - 1].RamIO =
NULL;
282 apbs[boardno - 1].irq =
irq;
285 apbs[boardno - 1].irq = 0;
292 "at mem 0x%lx\n",
mem);
299 DeviceErrorCount = 0;
315 boardname[serial] =
readb(apbs[i].RamIO + TYPE_CARD + serial);
323 (
int)(
readb(apbs[i].RamIO +
VERS) & 0xF));
330 printk(
" S/N %d\n", serial);
358 unsigned int NumCard;
359 unsigned int IndexCard;
360 unsigned char TicCard;
370 static int warncount = 5;
372 printk(
KERN_INFO "Hmmm. write() of Applicom card, length %zd != expected %zd\n",
386 NumCard = st_loc.num_card;
387 TicCard = st_loc.tic_des_from_pc;
388 IndexCard = NumCard - 1;
390 if((NumCard < 1) || (NumCard > MAX_BOARD) || !apbs[IndexCard].RamIO)
394 printk(
"Write to applicom card #%d. struct st_ram_io follows:",
397 for (c = 0; c <
sizeof(
struct st_ram_io);) {
399 printk(
"\n%5.5X: %2.2X", c, ((
unsigned char *) &st_loc)[c]);
401 for (c++; c % 8 && c <
sizeof(
struct st_ram_io); c++) {
402 printk(
" %2.2X", ((
unsigned char *) &st_loc)[c]);
406 printk(
"\nstruct mailbox follows:");
408 for (c = 0; c <
sizeof(
struct mailbox);) {
409 printk(
"\n%5.5X: %2.2X", c, ((
unsigned char *) &tmpmailbox)[c]);
411 for (c++; c % 8 && c <
sizeof(
struct mailbox); c++) {
412 printk(
" %2.2X", ((
unsigned char *) &tmpmailbox)[c]);
424 spin_unlock_irqrestore(&apbs[IndexCard].
mutex, flags);
440 spin_unlock_irqrestore(&apbs[IndexCard].
mutex, flags);
461 unsigned char *
from = (
unsigned char *) &tmpmailbox;
465 for (c = 0; c <
sizeof(
struct mailbox); c++)
476 spin_unlock_irqrestore(&apbs[IndexCard].
mutex, flags);
480 static int do_ac_read(
int IndexCard,
char __user *buf,
484 unsigned char *to = (
unsigned char *)mailbox;
496 for (c = 0; c <
sizeof(
struct mailbox); c++)
497 *(to++) =
readb(from++);
510 printk(
"Read from applicom card #%d. struct st_ram_io follows:", NumCard);
512 for (c = 0; c <
sizeof(
struct st_ram_io);) {
513 printk(
"\n%5.5X: %2.2X", c, ((
unsigned char *)st_loc)[c]);
515 for (c++; c % 8 && c <
sizeof(
struct st_ram_io); c++) {
516 printk(
" %2.2X", ((
unsigned char *)st_loc)[c]);
520 printk(
"\nstruct mailbox follows:");
522 for (c = 0; c <
sizeof(
struct mailbox);) {
523 printk(
"\n%5.5X: %2.2X", c, ((
unsigned char *)mailbox)[c]);
525 for (c++; c % 8 && c <
sizeof(
struct mailbox); c++) {
526 printk(
" %2.2X", ((
unsigned char *)mailbox)[c]);
531 return (
sizeof(
struct st_ram_io) +
sizeof(
struct mailbox));
534 static ssize_t ac_read (
struct file *filp,
char __user *buf,
size_t count, loff_t *
ptr)
545 if (count !=
sizeof(
struct st_ram_io) +
sizeof(
struct mailbox)) {
547 count,
sizeof(
struct st_ram_io) +
sizeof(
struct mailbox));
566 struct mailbox mailbox;
569 memset(&st_loc, 0,
sizeof(st_loc));
570 ret = do_ac_read(i, buf, &st_loc, &mailbox);
571 spin_unlock_irqrestore(&apbs[i].
mutex, flags);
577 if (
copy_to_user(buf +
sizeof(st_loc), &mailbox,
sizeof(mailbox)))
586 spin_unlock_irqrestore(&apbs[i].
mutex, flags);
598 spin_unlock_irqrestore(&apbs[i].
mutex, flags);
611 if (loopcount++ > 2) {
618 static irqreturn_t ac_interrupt(
int vec,
void *dev_instance)
621 unsigned int FlagInt;
622 unsigned int LoopCount;
637 spin_lock(&apbs[i].
mutex);
641 spin_unlock(&apbs[i].
mutex);
664 if (waitqueue_active(&FlagSleepRec)) {
670 if (waitqueue_active(&apbs[i].FlagSleepSend)) {
678 spin_unlock(&apbs[i].
mutex);
681 spin_unlock(&apbs[i].
mutex);
688 }
while(LoopCount < 2);
694 static long ac_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
698 unsigned char IndexCard;
701 volatile unsigned char byte_reset_it;
710 return PTR_ERR(adgl);
715 if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
716 static int warncount = 10;
718 printk(
KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(
int)IndexCard+1);
729 pmem = apbs[IndexCard].RamIO;
730 for (i = 0; i <
sizeof(
struct st_ram_io); i++)
731 ((
unsigned char *)adgl)[
i]=
readb(pmem++);
737 for (i = 0; i < 4; i++)
739 for (i = 0; i < 2; i++)
741 for (i = 0; i < 4; i++)
743 pmem = apbs[IndexCard].RamIO +
VERS;
745 pmem = apbs[IndexCard].RamIO +
TYPE_CARD;
746 for (i = 0; i < 20; i++)
758 for (i = 0; i < 10; i++)
790 printk(
KERN_INFO "APPLICOM driver release .... V2.8.0 ($Revision: 1.30 $)\n");
791 printk(
KERN_INFO "Number of installed boards . %d\n", (
int) numboards);
802 boardname[serial] =
readb(apbs[i].RamIO + TYPE_CARD + serial);
807 (
int)(
readb(apbs[IndexCard].RamIO +
VERS) >> 4),
808 (
int)(
readb(apbs[IndexCard].RamIO +
VERS) & 0xF),
817 printk(
" S/N %d\n", serial);
821 if (DeviceErrorCount != 0)
822 printk(
KERN_INFO "DeviceErrorCount ........... %d\n", DeviceErrorCount);
823 if (ReadErrorCount != 0)
825 if (WriteErrorCount != 0)
826 printk(
KERN_INFO "WriteErrorCount ............ %d\n", WriteErrorCount);
827 if (waitqueue_active(&FlagSleepRec))
830 if (apbs[i].RamIO && waitqueue_active(&apbs[i].FlagSleepSend))