Browse Source

ft232r & libztex: Skip probe of claimed devices

Luke Dashjr 12 years ago
parent
commit
90339fdf90
4 changed files with 24 additions and 6 deletions
  1. 2 6
      driver-x6500.c
  2. 1 0
      fpgautils.h
  3. 10 0
      ft232r.c
  4. 11 0
      libztex.c

+ 2 - 6
driver-x6500.c

@@ -124,12 +124,8 @@ uint32_t x6500_get_register(struct jtag_port *jp, uint8_t addr)
 
 static bool x6500_foundusb(libusb_device *dev, const char *product, const char *serial)
 {
-	{
-		uint8_t usbbus = libusb_get_bus_number(dev);
-		uint8_t usbaddr = libusb_get_device_address(dev);
-		if (bfg_claim_usb(&x6500_api, true, usbbus, usbaddr))
-			return false;
-	}
+	if (bfg_claim_libusb(&x6500_api, true, dev))
+		return false;
 	
 	struct cgpu_info *x6500;
 	x6500 = calloc(1, sizeof(*x6500));

+ 1 - 0
fpgautils.h

@@ -32,6 +32,7 @@ extern struct device_drv *bfg_claim_serial(struct device_drv * const, const bool
 #define serial_claim(devpath, drv)    bfg_claim_serial(drv, false, devpath)
 #define serial_claim_v(devpath, drv)  bfg_claim_serial(drv, true , devpath)
 extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr);
+#define bfg_claim_libusb(api, verbose, dev)  bfg_claim_usb(api, verbose, libusb_get_bus_number(dev), libusb_get_device_address(dev))
 
 extern int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool purge);
 extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);

+ 10 - 0
ft232r.c

@@ -63,6 +63,7 @@ void ft232r_scan()
 	struct ft232r_device_info *info;
 	int err;
 	unsigned char buf[0x100];
+	int skipped = 0;
 
 	ft232r_scan_free();
 
@@ -76,6 +77,12 @@ void ft232r_scan()
 	ft232r_devinfo_list = malloc(sizeof(struct ft232r_device_info *) * (count + 1));
 
 	for (i = 0; i < count; ++i) {
+		if (bfg_claim_libusb(NULL, false, list[i]))
+		{
+			++skipped;
+			continue;
+		}
+		
 		err = libusb_get_device_descriptor(list[i], &desc);
 		if (unlikely(err)) {
 			applog(LOG_ERR, "ft232r_scan: Error getting device descriptor: %s", bfg_strerror(err, BST_LIBUSB));
@@ -118,6 +125,9 @@ void ft232r_scan()
 
 	ft232r_devinfo_list[found] = NULL;
 	libusb_free_device_list(list, 1);
+	
+	if (skipped)
+		applog(LOG_DEBUG, "%s: Skipping probe of %d claimed devices", __func__, skipped);
 }
 
 int ft232r_detect(const char *product_needle, const char *serial, foundusb_func_t cb)

+ 11 - 0
libztex.c

@@ -738,6 +738,7 @@ int libztex_scanDevices(struct libztex_dev_list*** devs_p)
 	int found, max_found = 0, pos = 0, err, rescan, ret = 0;
 	libusb_device **list = NULL;
 	ssize_t cnt, i;
+	int skipped = 0;
 
 	do {
 		cnt = libusb_get_device_list(NULL, &list);
@@ -747,6 +748,12 @@ int libztex_scanDevices(struct libztex_dev_list*** devs_p)
 		}
 
 		for (found = rescan = i = 0; i < cnt; i++) {
+			if (bfg_claim_libusb(NULL, false, list[i]))
+			{
+				++skipped;
+				continue;
+			}
+			
 			err = libztex_checkDevice(list[i]);
 			switch (err) {
 			case CHECK_ERROR:
@@ -828,6 +835,10 @@ done:
 		free(devs);
 	if (list)
 		libusb_free_device_list(list, 1);
+	
+	if (skipped)
+		applog(LOG_DEBUG, "%s: Skipping probe of %d claimed devices", __func__, skipped);
+	
 	return ret;
 }