X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/blobdiff_plain/ac9e3f59d8073109e43c84738e2776b95d90a403..3cc5a0bc5aff472da5f6ad0df3eb108eae229dae:/usb-driver.c diff --git a/usb-driver.c b/usb-driver.c index 825c35c..f2f8477 100644 --- a/usb-driver.c +++ b/usb-driver.c @@ -1,4 +1,4 @@ -/* libusb connector for XILINX impact +/* libusb/ppdev connector for XILINX impact * * Copyright (c) 2007 Michael Gernoth * @@ -38,11 +38,21 @@ #include #include #include +#include #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; FILE *modulesfp = NULL; +FILE *baseaddrfp = NULL; +int baseaddrnum = 0; static int modules_read = 0; static struct usb_bus *busses = NULL; static struct usb_device *usbdevice; @@ -53,10 +63,7 @@ static int ints_enabled = 0; static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER; #define NO_WINDRVR 1 -#undef PARPORT -#ifdef DEBUG -#define DPRINTF(format, args...) fprintf(stderr, format, ##args) void hexdump(unsigned char *buf, int len) { int i; @@ -67,9 +74,6 @@ void hexdump(unsigned char *buf, int len) { } fprintf(stderr,"\n"); } -#else -#define DPRINTF(format, args...) -#endif int usb_deviceinfo(unsigned char *buf) { int i,j,k,l; @@ -231,33 +235,6 @@ int usb_deviceinfo(unsigned char *buf) { return len; } -int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wdioctl) { - int ret = 0; - - DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n", - (unsigned long)tr->dwPort, tr->cmdTrans, tr->dwBytes, - tr->fAutoinc, tr->dwOptions); - -#ifdef DEBUG - if (tr->cmdTrans == 13) - DPRINTF("write byte: %d\n", tr->Data.Byte); -#endif - -#ifndef NO_WINDRVR - ret = (*ioctl_func) (fd, request, wdioctl); -#endif - - DPRINTF("dwPortReturn: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n", - (unsigned long)tr->dwPort, tr->cmdTrans, tr->dwBytes, - tr->fAutoinc, tr->dwOptions); -#ifdef DEBUG - if (tr->cmdTrans == 10) - DPRINTF("read byte: %d\n", tr->Data.Byte); -#endif - - return ret; -} - int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { struct header_struct* wdheader = (struct header_struct*)wdioctl; struct version_struct *version; @@ -271,7 +248,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, "WinDriver no more"); + strcpy(version->version, "libusb-driver.so $Revision: 1.67 $"); version->versionul = 802; DPRINTF("VERSION\n"); break; @@ -282,20 +259,45 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { case CARD_REGISTER_OLD: case CARD_REGISTER: - /* TODO: Implement for LPT-support */ -#ifdef PARPORT + DPRINTF("CARD_REGISTER\n"); { struct card_register* cr = (struct card_register*)(wdheader->data); + + DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n", + cr->Card.dwItems, + (unsigned long)cr->Card.Item[0].I.IO.dwAddr, + cr->Card.Item[0].I.IO.dwBytes, + cr->Card.Item[0].I.IO.dwBar); + + DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n", + cr->Card.dwItems, + (unsigned long)cr->Card.Item[1].I.IO.dwAddr, + cr->Card.Item[1].I.IO.dwBytes, + cr->Card.Item[1].I.IO.dwBar); #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - /* TODO: Open /dev/parport, check, ... */ - cr->hCard = 1; + +#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); + + ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr; + + if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr) + ecpbase = (unsigned long)cr->Card.Item[1].I.IO.dwAddr; + + if (ret >= 0) { + cr->hCard = ret; + } else { + cr->hCard = 0; + } #endif DPRINTF("hCard: %lu\n", cr->hCard); } -#endif - DPRINTF("CARD_REGISTER\n"); break; case USB_TRANSFER: @@ -561,33 +563,38 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { { WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data); - ret = pp_transfer(tr, fd, request, 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); +#endif } break; + case MULTI_TRANSFER_OLD: case MULTI_TRANSFER: DPRINTF("MULTI_TRANSFER\n"); { WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data); unsigned long num = wdheader->size/sizeof(WD_TRANSFER); - int i; - - - for (i = 0; i < num; i++) { - DPRINTF("Transfer %d:\n", i+1); #ifndef NO_WINDRVR - wdheader->size = sizeof(WD_TRANSFER); - request = TRANSFER; - wdheader->data = tr + i; -#endif - ret = pp_transfer(tr + i, fd, request, wdioctl); - } + ret = (*ioctl_func) (fd, request, wdioctl); +#else -#ifndef NO_WINDRVR - wdheader->data = tr; +#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); #endif - - return ret; } break; @@ -633,9 +640,27 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { case CARD_UNREGISTER: DPRINTF("CARD_UNREGISTER\n"); + { + struct card_register* cr = (struct card_register*)(wdheader->data); + + DPRINTF("Addr: 0x%lx, bytes: %lu, bar: %lu\n", + (unsigned long)cr->Card.Item[0].I.IO.dwAddr, + cr->Card.Item[0].I.IO.dwBytes, + cr->Card.Item[0].I.IO.dwBar); + + DPRINTF("hCard: %lu\n", cr->hCard); + #ifndef NO_WINDRVR - ret = (*ioctl_func) (fd, request, wdioctl); + ret = (*ioctl_func) (fd, request, wdioctl); +#else +#ifdef JTAGKEY + if (cr->hCard == 0xff) + jtagkey_close(cr->hCard); + else #endif + parport_close(cr->hCard); +#endif + } break; case EVENT_PULL: @@ -718,7 +743,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { return ret; } -int ioctl(int fd, int request, ...) { +int ioctl(int fd, unsigned long int request, ...) { va_list args; void *argp; int ret; @@ -799,13 +824,34 @@ int close(int fd) { FILE *fopen(const char *path, const char *mode) { FILE *ret; static FILE* (*func) (const char*, const char*) = NULL; + char buf[256]; + int i; if (!func) func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen"); + for (i = 0; i < 4; i++) { + snprintf(buf, sizeof(buf), "/proc/sys/dev/parport/parport%d/base-addr", i); + if (!strcmp(path, buf)) { + DPRINTF("open base-addr of parport%d\n", i); + if (config_is_real_pport(i)) { + ret = (*func) (path, mode); + } else { + ret = (*func) ("/dev/null", mode); + } + + if (ret) { + baseaddrfp = ret; + baseaddrnum = i; + } + + return ret; + } + } + ret = (*func) (path, mode); - if (!strcmp (path, "/proc/modules")) { + if (!strcmp(path, "/proc/modules")) { DPRINTF("opening /proc/modules\n"); #ifdef NO_WINDRVR modulesfp = ret; @@ -819,6 +865,7 @@ FILE *fopen(const char *path, const char *mode) { char *fgets(char *s, int size, FILE *stream) { static char* (*func) (char*, int, FILE*) = NULL; const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"}; + char buf[256]; char *ret = NULL; @@ -826,11 +873,16 @@ char *fgets(char *s, int size, FILE *stream) { func = (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT, "fgets"); if (modulesfp == stream) { - if (modules_read < sizeof(modules)) { + if (modules_read < sizeof(modules) / sizeof(modules[0])) { strcpy(s, modules[modules_read]); ret = s; modules_read++; } + } else if (baseaddrfp == stream) { + snprintf(s, sizeof(buf), "%d\t%d\n", + (baseaddrnum) * 0x10, + ((baseaddrnum) * 0x10) + 0x400); + ret = s; } else { ret = (*func)(s,size,stream); } @@ -847,6 +899,10 @@ int fclose(FILE *fp) { if (fp == modulesfp) { modulesfp = NULL; } + + if (fp == baseaddrfp) { + baseaddrfp = NULL; + } return (*func)(fp); }