]> cvs.zerfleddert.de Git - usb-driver/blobdiff - usb-driver.c
ignore bus-id on XILINX_USB_DEV setting missing a device-id
[usb-driver] / usb-driver.c
index f2f8477a5c430cde97ebb2423c5c1257f2684302..929c1019484581a25a1ae33986583585f936ff39 100644 (file)
 #include <sys/ioctl.h>
 #include "usb-driver.h"
 #include "config.h"
-#include "parport.h"
-#ifdef JTAGKEY
-#include "jtagkey.h"
-#endif
 
 static int (*ioctl_func) (int, int, void *) = NULL;
 static int windrvrfd = -1;
 static unsigned long ppbase = 0;
 static unsigned long ecpbase = 0;
+static struct parport_config *pport = NULL;
 FILE *modulesfp = NULL;
 FILE *baseaddrfp = NULL;
 int baseaddrnum = 0;
@@ -248,7 +245,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
        switch(request & ~(0xc0000000)) {
                case VERSION:
                        version = (struct version_struct*)(wdheader->data);
-                       strcpy(version->version, "libusb-driver.so $Revision: 1.67 $");
+                       strcpy(version->version, "libusb-driver.so version: " USB_DRIVER_VERSION);
                        version->versionul = 802;
                        DPRINTF("VERSION\n");
                        break;
@@ -278,12 +275,11 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
 
-#ifdef JTAGKEY
-                               if (!config_is_real_pport((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10))
-                                       ret = jtagkey_open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
-                               else
-#endif
-                                       ret = parport_open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
+                               pport = config_get((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
+                               if (!pport)
+                                       break;
+
+                               ret = pport->open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
 
                                ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
 
@@ -470,6 +466,8 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        {
                                struct event *e = (struct event*)(wdheader->data);
                                struct usb_bus *bus;
+                               char* devpos;
+                               int busnum = -1, devnum = -1;
                                int i;
 
                                DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
@@ -481,6 +479,37 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                e->u.Usb.dwUniqueID, e->dwEventVer,
                                e->dwNumMatchTables);
 
+                               devpos = getenv("XILINX_USB_DEV");
+                               if (devpos != NULL) {
+                                       int j;
+                                       char *devstr = NULL, *remainder;
+
+                                       DPRINTF("XILINX_USB_DEV=%s\n", devpos);
+
+                                       for (j = 0; j < strlen(devpos) && devpos[j] != 0; j++) {
+                                               if (devpos[j] == ':') {
+                                                       devpos[j] = 0;
+                                                       devstr = &(devpos[j+1]);
+                                               }
+                                       }
+
+                                       if (devstr && strlen(devstr) > 0) {
+                                               busnum = strtol(devpos, &remainder, 10);
+                                               if (devpos == remainder) {
+                                                       busnum = -1;
+                                               } else {
+                                                       devnum = strtol(devstr, &remainder, 10);
+                                                       if (devstr == remainder) {
+                                                               busnum = -1;
+                                                               devnum = -1;
+                                                       } else {
+                                                               fprintf(stderr,"Using XILINX platform cable USB at %03d:%03d\n",
+                                                               busnum, devnum);
+                                                       }
+                                               }
+                                       }
+                               }
+
                                for (i = 0; i < e->dwNumMatchTables; i++) {
 
                                        DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
@@ -495,13 +524,17 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        for (bus = busses; bus; bus = bus->next) {
                                                struct usb_device *dev;
 
+                                               if ((devnum != -1) && (strtol(bus->dirname, NULL, 10) != busnum))
+                                                       continue;
+
                                                for (dev = bus->devices; dev; dev = dev->next) {
                                                        struct usb_device_descriptor *desc = &(dev->descriptor);
 
                                                        if((desc->idVendor == e->matchTables[i].VendorId) &&
                                                           (desc->idProduct == e->matchTables[i].ProductId) &&
                                                           (desc->bDeviceClass == e->matchTables[i].bDeviceClass) &&
-                                                          (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) {
+                                                          (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass) &&
+                                                          ((devnum == -1) || (dev->devnum == devnum)) ) {
                                                                   int ac;
                                                                   for (ac = 0; ac < desc->bNumConfigurations; ac++) {
                                                                           struct usb_interface *interface = dev->config[ac].interface;
@@ -566,14 +599,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
-
-#ifdef JTAGKEY
-                               if (!config_is_real_pport(ppbase / 0x10)) {
-                                       ret = jtagkey_transfer(tr, fd, request, ppbase, ecpbase, 1);
-                                       break;
-                               }
-#endif /* JTAGKEY */
-                               ret = pp_transfer(tr, fd, request, ppbase, ecpbase, 1);
+                               ret = pport->transfer(tr, fd, request, ppbase, ecpbase, 1);
 #endif
                        }
                        break;
@@ -587,13 +613,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
-
-#ifdef JTAGKEY
-                               if (!config_is_real_pport(ppbase / 0x10)) {
-                                       ret = jtagkey_transfer(tr, fd, request, ppbase, ecpbase, num);
-                               } else
-#endif /* JTAGKEY */
-                                       ret = pp_transfer(tr, fd, request, ppbase, ecpbase, num);
+                               ret = pport->transfer(tr, fd, request, ppbase, ecpbase, num);
 #endif
                        }
                        break;
@@ -653,12 +673,10 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
-#ifdef JTAGKEY
-                               if (cr->hCard == 0xff)
-                                       jtagkey_close(cr->hCard);
-                               else
-#endif
-                                       parport_close(cr->hCard);
+                               if (pport)
+                                       pport->close(cr->hCard);
+
+                               pport = NULL;
 #endif
                        }
                        break;
@@ -912,8 +930,8 @@ int access(const char *pathname, int mode) {
 
        if (!func)
                func = (int (*) (const char*, int)) dlsym(RTLD_NEXT, "access");
-       
-       if (!strcmp(pathname, "/dev/windrvr6")) {
+
+       if (pathname && !strcmp(pathname, "/dev/windrvr6")) {
                return 0;
        } else {
                return (*func)(pathname, mode);
Impressum, Datenschutz