From: Thomas Jarosch Date: Fri, 12 Nov 2004 10:01:34 +0000 (+0000) Subject: libftdi: (tomj) ftdi_usb_reset is now aware of the kernel version X-Git-Tag: v0.6~11 X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=commitdiff_plain;h=792418f119810bc9ac88c270d42c2de1b41d6424 libftdi: (tomj) ftdi_usb_reset is now aware of the kernel version --- diff --git a/src/ftdi.c b/src/ftdi.c index 3aaf1bc..0e48b28 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -16,6 +16,7 @@ #include #include +#include #include "ftdi.h" @@ -182,16 +183,28 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product, int ftdi_usb_reset(struct ftdi_context *ftdi) { +#if defined(__linux__) + struct utsname kernelver; + int k_major, k_minor, k_myver; +#endif + if (usb_control_msg(ftdi->usb_dev, 0x40, 0, 0, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0) { ftdi->error_str = "FTDI reset failed"; return -1; } -/* - if (usb_reset(ftdi->usb_dev) != 0) { - ftdi->error_str = "USB reset failed"; - return -2; + +#if defined(__linux__) + /* Kernel 2.6 (maybe higher versions, too) need an additional usb_reset */ + if (uname(&kernelver) == 0 && sscanf(kernelver.release, "%d.%d", &k_major, &k_minor) == 2) { + k_myver = k_major*10 + k_minor; + + if (k_myver >= 26 && usb_reset(ftdi->usb_dev) != 0) { + ftdi->error_str = "USB reset failed"; + return -2; + } } -*/ +#endif + // Invalidate data in the readbuffer ftdi->readbuffer_offset = 0; ftdi->readbuffer_remaining = 0;