Browse Source

vcom_lowl_probe_wrapper: Attempt to reattach detached USB devices

Luke Dashjr 12 years ago
parent
commit
df5cdd45a6
8 changed files with 43 additions and 7 deletions
  1. 1 1
      driver-bigpic.c
  2. 1 1
      driver-bitforce.c
  3. 1 1
      driver-cairnsmore.c
  4. 1 1
      driver-erupter.c
  5. 1 1
      driver-littlefury.c
  6. 1 1
      driver-modminer.c
  7. 15 1
      fpgautils.c
  8. 22 0
      lowl-usb.c

+ 1 - 1
driver-bigpic.c

@@ -35,7 +35,7 @@ BFG_REGISTER_DRIVER(bigpic_drv)
 static
 bool bigpic_lowl_match(const struct lowlevel_device_info * const info)
 {
-	return lowlevel_match_lowlproduct(info, &lowl_vcom, "Bitfury", "BF1");
+	return lowlevel_match_product(info, "Bitfury", "BF1");
 }
 
 //------------------------------------------------------------------------------

+ 1 - 1
driver-bitforce.c

@@ -169,7 +169,7 @@ int bitforce_chips_to_plan_for(int parallel, int chipcount) {
 static
 bool bitforce_lowl_match(const struct lowlevel_device_info * const info)
 {
-	return lowlevel_match_lowlproduct(info, &lowl_vcom, "BitFORCE", "SHA256");
+	return lowlevel_match_product(info, "BitFORCE", "SHA256");
 }
 
 static bool bitforce_detect_one(const char *devpath)

+ 1 - 1
driver-cairnsmore.c

@@ -33,7 +33,7 @@ BFG_REGISTER_DRIVER(cairnsmore_drv)
 static
 bool cairnsmore_lowl_match(const struct lowlevel_device_info * const info)
 {
-	return lowlevel_match_lowlproduct(info, &lowl_vcom, "Cairnsmore1");
+	return lowlevel_match_product(info, "Cairnsmore1");
 }
 
 static bool cairnsmore_detect_one(const char *devpath)

+ 1 - 1
driver-erupter.c

@@ -45,7 +45,7 @@ static bool _erupter_detect_one(const char *devpath, struct device_drv *drv)
 static
 bool erupter_emerald_lowl_match(const struct lowlevel_device_info * const info)
 {
-	return lowlevel_match_lowlproduct(info, &lowl_vcom, "Block", "Erupter", "Emerald");
+	return lowlevel_match_product(info, "Block", "Erupter", "Emerald");
 }
 
 static bool erupter_emerald_detect_one(const char *devpath)

+ 1 - 1
driver-littlefury.c

@@ -226,7 +226,7 @@ bool littlefury_txrx(struct spi_port *port)
 static
 bool littlefury_lowl_match(const struct lowlevel_device_info * const info)
 {
-	return lowlevel_match_lowlproduct(info, &lowl_vcom, "LittleFury");
+	return lowlevel_match_product(info, "LittleFury");
 }
 
 static

+ 1 - 1
driver-modminer.c

@@ -104,7 +104,7 @@ static const char NOOP[] = MODMINER_PING "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x
 static
 bool modminer_lowl_match(const struct lowlevel_device_info * const info)
 {
-	return lowlevel_match_lowlproduct(info, &lowl_vcom, "ModMiner");
+	return lowlevel_match_product(info, "ModMiner");
 }
 
 static bool

+ 15 - 1
fpgautils.c

@@ -647,10 +647,19 @@ extern void _vcom_devinfo_scan_querydosdevice(struct lowlevel_device_info **);
 extern void _vcom_devinfo_scan_lsdev(struct lowlevel_device_info **);
 #endif
 
+extern bool lowl_usb_attach_kernel_driver(const struct lowlevel_device_info *);
+
 bool vcom_lowl_probe_wrapper(const struct lowlevel_device_info * const info, detectone_func_t detectone)
 {
 	if (info->lowl != &lowl_vcom)
+	{
+		if (info->lowl == &lowl_usb)
+		{
+			if (lowl_usb_attach_kernel_driver(info))
+				bfg_need_detect_rescan = true;
+		}
 		return false;
+	}
 	detectone_meta_info = (struct detectone_meta_info_t){
 		.manufacturer = info->manufacturer,
 		.product = info->product,
@@ -671,7 +680,12 @@ bool _serial_autodetect_found_cb(struct lowlevel_device_info * const devinfo, vo
 	}
 	if (devinfo->lowl != &lowl_vcom)
 	{
-		if (devinfo->lowl != &lowl_usb)
+		if (devinfo->lowl == &lowl_usb)
+		{
+			if (lowl_usb_attach_kernel_driver(devinfo))
+				bfg_need_detect_rescan = true;
+		}
+		else
 			applog(LOG_WARNING, "Non-VCOM %s (%s) matched", devinfo->path, devinfo->devid);
 		return false;
 	}

+ 22 - 0
lowl-usb.c

@@ -9,6 +9,7 @@
 
 #include "config.h"
 
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -108,6 +109,27 @@ struct lowlevel_device_info *usb_devinfo_scan()
 	return devinfo_list;
 }
 
+bool lowl_usb_attach_kernel_driver(const struct lowlevel_device_info * const info)
+{
+	libusb_device * const dev = info->lowl_data;
+	libusb_device_handle *devh;
+	bool rv = false;
+	
+	if (libusb_open(dev, &devh))
+		return false;
+	
+	if (libusb_kernel_driver_active(devh, 0) == 0)
+		if (!libusb_attach_kernel_driver(devh, 0))
+		{
+			applog(LOG_DEBUG, "Reattaching kernel driver for %s", info->devid);
+			rv = true;
+		}
+	
+	libusb_close(devh);
+	
+	return rv;
+}
+
 struct libusb_device_handle *lowl_usb_open(struct lowlevel_device_info * const info)
 {
 	libusb_device * const dev = info->lowl_data;