|
@@ -24,58 +24,40 @@
|
|
|
#include "fpgautils.h"
|
|
#include "fpgautils.h"
|
|
|
#include "ft232r.h"
|
|
#include "ft232r.h"
|
|
|
#include "logging.h"
|
|
#include "logging.h"
|
|
|
|
|
+#include "lowlevel.h"
|
|
|
#include "miner.h"
|
|
#include "miner.h"
|
|
|
|
|
|
|
|
#define FT232R_IDVENDOR 0x0403
|
|
#define FT232R_IDVENDOR 0x0403
|
|
|
#define FT232R_IDPRODUCT 0x6001
|
|
#define FT232R_IDPRODUCT 0x6001
|
|
|
|
|
|
|
|
-struct ft232r_device_info {
|
|
|
|
|
- libusb_device *libusb_dev;
|
|
|
|
|
- char *product;
|
|
|
|
|
- char *serial;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-static struct ft232r_device_info **ft232r_devinfo_list;
|
|
|
|
|
-
|
|
|
|
|
-void ft232r_scan_free()
|
|
|
|
|
|
|
+static
|
|
|
|
|
+void ft232r_devinfo_free(struct lowlevel_device_info * const info)
|
|
|
{
|
|
{
|
|
|
- if (!ft232r_devinfo_list)
|
|
|
|
|
- return;
|
|
|
|
|
-
|
|
|
|
|
- struct ft232r_device_info *info;
|
|
|
|
|
-
|
|
|
|
|
- for (struct ft232r_device_info **infop = ft232r_devinfo_list; (info = *infop); ++infop) {
|
|
|
|
|
- libusb_unref_device(info->libusb_dev);
|
|
|
|
|
- free(info->product);
|
|
|
|
|
- free(info->serial);
|
|
|
|
|
- free(info);
|
|
|
|
|
- }
|
|
|
|
|
- free(ft232r_devinfo_list);
|
|
|
|
|
- ft232r_devinfo_list = NULL;
|
|
|
|
|
|
|
+ libusb_unref_device(info->lowl_data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void ft232r_scan()
|
|
|
|
|
|
|
+static
|
|
|
|
|
+struct lowlevel_device_info *ft232r_devinfo_scan()
|
|
|
{
|
|
{
|
|
|
- ssize_t count, n, i, found = 0;
|
|
|
|
|
|
|
+ struct lowlevel_device_info *devinfo_list = NULL;
|
|
|
|
|
+ ssize_t count, n, i;
|
|
|
libusb_device **list;
|
|
libusb_device **list;
|
|
|
struct libusb_device_descriptor desc;
|
|
struct libusb_device_descriptor desc;
|
|
|
libusb_device_handle *handle;
|
|
libusb_device_handle *handle;
|
|
|
- struct ft232r_device_info *info;
|
|
|
|
|
|
|
+ struct lowlevel_device_info *info;
|
|
|
int err;
|
|
int err;
|
|
|
unsigned char buf[0x100];
|
|
unsigned char buf[0x100];
|
|
|
int skipped = 0;
|
|
int skipped = 0;
|
|
|
|
|
|
|
|
- ft232r_scan_free();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (unlikely(!have_libusb))
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+
|
|
|
count = libusb_get_device_list(NULL, &list);
|
|
count = libusb_get_device_list(NULL, &list);
|
|
|
if (unlikely(count < 0)) {
|
|
if (unlikely(count < 0)) {
|
|
|
applog(LOG_ERR, "ft232r_scan: Error getting USB device list: %s", bfg_strerror(count, BST_LIBUSB));
|
|
applog(LOG_ERR, "ft232r_scan: Error getting USB device list: %s", bfg_strerror(count, BST_LIBUSB));
|
|
|
- ft232r_devinfo_list = calloc(1, sizeof(struct ft232r_device_info *));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ft232r_devinfo_list = malloc(sizeof(struct ft232r_device_info *) * (count + 1));
|
|
|
|
|
-
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
for (i = 0; i < count; ++i) {
|
|
|
if (bfg_claim_libusb(NULL, false, list[i]))
|
|
if (bfg_claim_libusb(NULL, false, list[i]))
|
|
|
{
|
|
{
|
|
@@ -106,7 +88,10 @@ void ft232r_scan()
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
buf[n] = '\0';
|
|
buf[n] = '\0';
|
|
|
- info = malloc(sizeof(struct ft232r_device_info));
|
|
|
|
|
|
|
+ info = malloc(sizeof(struct lowlevel_device_info));
|
|
|
|
|
+ *info = (struct lowlevel_device_info){
|
|
|
|
|
+ .lowl = &lowl_ft232r,
|
|
|
|
|
+ };
|
|
|
info->product = strdup((char*)buf);
|
|
info->product = strdup((char*)buf);
|
|
|
|
|
|
|
|
n = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, buf, sizeof(buf)-1);
|
|
n = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, buf, sizeof(buf)-1);
|
|
@@ -117,42 +102,37 @@ void ft232r_scan()
|
|
|
}
|
|
}
|
|
|
buf[n] = '\0';
|
|
buf[n] = '\0';
|
|
|
info->serial = strdup((char*)buf);
|
|
info->serial = strdup((char*)buf);
|
|
|
- info->libusb_dev = libusb_ref_device(list[i]);
|
|
|
|
|
- ft232r_devinfo_list[found++] = info;
|
|
|
|
|
|
|
+ info->lowl_data = libusb_ref_device(list[i]);
|
|
|
|
|
+
|
|
|
|
|
+ LL_PREPEND(devinfo_list, info);
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "ft232r_scan: Found \"%s\" serial \"%s\"", info->product, info->serial);
|
|
applog(LOG_DEBUG, "ft232r_scan: Found \"%s\" serial \"%s\"", info->product, info->serial);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ft232r_devinfo_list[found] = NULL;
|
|
|
|
|
libusb_free_device_list(list, 1);
|
|
libusb_free_device_list(list, 1);
|
|
|
|
|
|
|
|
if (skipped)
|
|
if (skipped)
|
|
|
applog(LOG_DEBUG, "%s: Skipping probe of %d claimed devices", __func__, skipped);
|
|
applog(LOG_DEBUG, "%s: Skipping probe of %d claimed devices", __func__, skipped);
|
|
|
|
|
+
|
|
|
|
|
+ return devinfo_list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int ft232r_detect(const char *product_needle, const char *serial, foundusb_func_t cb)
|
|
|
|
|
|
|
+static foundusb_func_t _wrapper_cb;
|
|
|
|
|
+static
|
|
|
|
|
+bool _wrapper(struct lowlevel_device_info *info)
|
|
|
{
|
|
{
|
|
|
- struct ft232r_device_info *info;
|
|
|
|
|
- int found = 0;
|
|
|
|
|
-
|
|
|
|
|
- for (struct ft232r_device_info **infop = ft232r_devinfo_list; (info = *infop); ++infop) {
|
|
|
|
|
- if (serial) {
|
|
|
|
|
- // If we are searching for a specific serial, pay no attention to the product id
|
|
|
|
|
- if (strcmp(serial, info->serial))
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- if (!strstr(info->product, product_needle))
|
|
|
|
|
- continue;
|
|
|
|
|
- if (!info->libusb_dev)
|
|
|
|
|
- continue;
|
|
|
|
|
- if (!cb(info->libusb_dev, info->product, info->serial))
|
|
|
|
|
- continue;
|
|
|
|
|
- info->libusb_dev = NULL;
|
|
|
|
|
- ++found;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (info->lowl != &lowl_ft232r)
|
|
|
|
|
+ return false;
|
|
|
|
|
+ return _wrapper_cb(info->lowl_data, info->product, info->serial);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- return found;
|
|
|
|
|
|
|
+int ft232r_detect(const char *product_needle, const char *serial, foundusb_func_t cb)
|
|
|
|
|
+{
|
|
|
|
|
+ _wrapper_cb = cb;
|
|
|
|
|
+ if (serial)
|
|
|
|
|
+ return lowlevel_detect_serial(_wrapper, serial);
|
|
|
|
|
+ else
|
|
|
|
|
+ return lowlevel_detect(_wrapper, product_needle);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#define FTDI_REQTYPE (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE)
|
|
#define FTDI_REQTYPE (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE)
|
|
@@ -408,6 +388,11 @@ bool ft232r_get_cbus_bits(struct ft232r_device_handle *dev, bool *out_sio0, bool
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+struct lowlevel_driver lowl_ft232r = {
|
|
|
|
|
+ .devinfo_scan = ft232r_devinfo_scan,
|
|
|
|
|
+ .devinfo_free = ft232r_devinfo_free,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
#if 0
|
|
#if 0
|
|
|
int main() {
|
|
int main() {
|
|
|
libusb_init(NULL);
|
|
libusb_init(NULL);
|