X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/blobdiff_plain/1f62c14e4f95d8a27377b558676d78ccb9d522c3..41d0a9f776f45fe753d3f5cb71228ca9e289b94b:/usb-driver.c?ds=sidebyside diff --git a/usb-driver.c b/usb-driver.c index a7d14bf..a34e5e4 100644 --- a/usb-driver.c +++ b/usb-driver.c @@ -46,9 +46,9 @@ static int (*ioctl_func) (int, int, void *) = NULL; static int windrvrfd = -1; static int parportfd = -1; -static int parportnum = 0; static unsigned long ppbase = 0; static unsigned long ecpbase = 0; +static struct pports *pplist = NULL; FILE *modulesfp = NULL; static int modules_read = 0; static struct usb_bus *busses = NULL; @@ -241,6 +241,7 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd int ret = 0; unsigned long port = (unsigned long)tr->dwPort; unsigned char val; + static int last_pp_write = 0; DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n", (unsigned long)tr->dwPort, tr->cmdTrans, tr->dwBytes, @@ -268,6 +269,7 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd case PP_WRITE: ret = ioctl(parportfd, PPWDATA, &val); + last_pp_write = val; break; default: @@ -276,10 +278,17 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd break; } } else if (port == ppbase + PP_STATUS) { - DPRINTF("status port\n"); + DPRINTF("status port (last write: %d)\n", last_pp_write); switch(tr->cmdTrans) { case PP_READ: ret = ioctl(parportfd, PPRSTATUS, &val); +#ifdef FORCE_PC3_IDENT + val &= 95; + if (last_pp_write & 64) + val |= 32; + else + val |= 128; +#endif break; case PP_WRITE: @@ -376,10 +385,36 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { ret = (*ioctl_func) (fd, request, wdioctl); #else if (parportfd < 0) { - if (ppbase && ((unsigned long)cr->Card.Item[0].I.IO.dwAddr != ppbase)) - parportnum++; + int max = -1; + struct pports **port = &pplist; + + while (*port) { + DPRINTF("Looking up parallel port in linked list, entry: %d\n", (*port)->num); + if (max < (*port)->num) + max = (*port)->num; + + if ((*port)->base == (unsigned long)cr->Card.Item[0].I.IO.dwAddr) { + break; + } + + port = &((*port)->next); + } + + if (!(*port)) { /* not found */ + (*port) = malloc(sizeof(struct pports)); + if (!(*port)) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + (*port)->base = (unsigned long)cr->Card.Item[0].I.IO.dwAddr; + (*port)->num = max+1; + (*port)->next = NULL; + + DPRINTF("parallel port not in linked list, new entry: %d\n", (*port)->num); + } - snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", parportnum); + snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", (*port)->num); DPRINTF("opening %s\n", ppdev); parportfd = open(ppdev, O_RDWR|O_EXCL);