libftdi: (tomj) ftdi_usb_reset is now aware of the kernel version
authorThomas Jarosch <opensource@intra2net.com>
Fri, 12 Nov 2004 10:01:34 +0000 (10:01 +0000)
committerThomas Jarosch <opensource@intra2net.com>
Fri, 12 Nov 2004 10:01:34 +0000 (10:01 +0000)
src/ftdi.c

index 3aaf1bc..0e48b28 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <usb.h>
 #include <string.h>
+#include <sys/utsname.h>
 
 #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;