Add kernel driver auto attach/detach
authorRobby McKilliam <robby.mckilliam@myriota.com>
Wed, 13 Dec 2017 22:54:35 +0000 (08:54 +1030)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 6 Feb 2018 20:17:21 +0000 (21:17 +0100)
Introduce new detach mode:
AUTO_DETACH_REATACH_SIO_MODULE

Tested on linux (Ubuntu 16.04 and Raspbian Stretch) with an FT230.

src/ftdi.c
src/ftdi.h

index e7904b3..52266d0 100644 (file)
@@ -614,6 +614,11 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi, libusb_device *dev)
         if (libusb_detach_kernel_driver(ftdi->usb_dev, ftdi->interface) !=0)
             detach_errno = errno;
     }
+    else if (ftdi->module_detach_mode == AUTO_DETACH_REATACH_SIO_MODULE)
+    {
+        if (libusb_set_auto_detach_kernel_driver(ftdi->usb_dev, 1) != LIBUSB_SUCCESS)
+            detach_errno = errno;
+    }
 
     if (libusb_get_configuration (ftdi->usb_dev, &cfg) < 0)
         ftdi_error_return(-12, "libusb_get_configuration () failed");
index b3e596e..f170881 100644 (file)
@@ -84,7 +84,8 @@ enum ftdi_interface
 enum ftdi_module_detach_mode
 {
     AUTO_DETACH_SIO_MODULE = 0,
-    DONT_DETACH_SIO_MODULE = 1
+    DONT_DETACH_SIO_MODULE = 1,
+    AUTO_DETACH_REATACH_SIO_MODULE = 2
 };
 
 /* Shifting commands IN MPSSE Mode*/