]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/fx2lafw/api.c
drivers: Load firmware via new resource API
[libsigrok.git] / src / hardware / fx2lafw / api.c
index 724e2dd4e2ee0eb63b9ca3d723759c04eaf634f0..fc6081b45fb697d1dd83792c8f03137da4040511 100644 (file)
@@ -18,6 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include "protocol.h"
 #include "dslogic.h"
 
@@ -28,48 +29,48 @@ static const struct fx2lafw_profile supported_fx2[] = {
         * ARMFLY AX-Pro
         */
        { 0x08a9, 0x0014, "CWAV", "USBee AX", NULL,
-               FIRMWARE_DIR "/fx2lafw-cwav-usbeeax.fw",
+               "fx2lafw-cwav-usbeeax.fw",
                0, NULL, NULL},
        /*
         * CWAV USBee DX
         * XZL-Studio DX
         */
        { 0x08a9, 0x0015, "CWAV", "USBee DX", NULL,
-               FIRMWARE_DIR "/fx2lafw-cwav-usbeedx.fw",
+               "fx2lafw-cwav-usbeedx.fw",
                DEV_CAPS_16BIT, NULL, NULL },
 
        /*
         * CWAV USBee SX
         */
        { 0x08a9, 0x0009, "CWAV", "USBee SX", NULL,
-               FIRMWARE_DIR "/fx2lafw-cwav-usbeesx.fw",
+               "fx2lafw-cwav-usbeesx.fw",
                0, NULL, NULL},
 
        /* DreamSourceLab DSLogic (before FW upload) */
        { 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL,
-               FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw",
+               "dreamsourcelab-dslogic-fx2.fw",
                DEV_CAPS_16BIT, NULL, NULL},
        /* DreamSourceLab DSLogic (after FW upload) */
        { 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL,
-               FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw",
+               "dreamsourcelab-dslogic-fx2.fw",
                DEV_CAPS_16BIT, "DreamSourceLab", "DSLogic"},
 
        /* DreamSourceLab DSCope (before FW upload) */
        { 0x2a0e, 0x0002, "DreamSourceLab", "DSCope", NULL,
-               FIRMWARE_DIR "/dreamsourcelab-dscope-fx2.fw",
+               "dreamsourcelab-dscope-fx2.fw",
                DEV_CAPS_16BIT, NULL, NULL},
        /* DreamSourceLab DSCope (after FW upload) */
        { 0x2a0e, 0x0002, "DreamSourceLab", "DSCope", NULL,
-               FIRMWARE_DIR "/dreamsourcelab-dscope-fx2.fw",
+               "dreamsourcelab-dscope-fx2.fw",
                DEV_CAPS_16BIT, "DreamSourceLab", "DSCope"},
 
        /* DreamSourceLab DSLogic Pro (before FW upload) */
        { 0x2a0e, 0x0003, "DreamSourceLab", "DSLogic Pro", NULL,
-               FIRMWARE_DIR "/dreamsourcelab-dslogic-pro-fx2.fw",
+               "dreamsourcelab-dslogic-pro-fx2.fw",
                DEV_CAPS_16BIT, NULL, NULL},
        /* DreamSourceLab DSLogic Pro (after FW upload) */
        { 0x2a0e, 0x0003, "DreamSourceLab", "DSLogic Pro", NULL,
-               FIRMWARE_DIR "/dreamsourcelab-dslogic-pro-fx2.fw",
+               "dreamsourcelab-dslogic-pro-fx2.fw",
                DEV_CAPS_16BIT, "DreamSourceLab", "DSLogic"},
 
        /*
@@ -79,7 +80,7 @@ static const struct fx2lafw_profile supported_fx2[] = {
         * Robomotic BugLogic 3
         */
        { 0x0925, 0x3881, "Saleae", "Logic", NULL,
-               FIRMWARE_DIR "/fx2lafw-saleae-logic.fw",
+               "fx2lafw-saleae-logic.fw",
                0, NULL, NULL},
 
        /*
@@ -88,14 +89,14 @@ static const struct fx2lafw_profile supported_fx2[] = {
         * Braintechnology USB Interface V2.x
         */
        { 0x04B4, 0x8613, "Cypress", "FX2", NULL,
-               FIRMWARE_DIR "/fx2lafw-cypress-fx2.fw",
+               "fx2lafw-cypress-fx2.fw",
                DEV_CAPS_16BIT, NULL, NULL },
 
        /*
         * Braintechnology USB-LPS
         */
        { 0x16d0, 0x0498, "Braintechnology", "USB-LPS", NULL,
-               FIRMWARE_DIR "/fx2lafw-braintechnology-usb-lps.fw",
+               "fx2lafw-braintechnology-usb-lps.fw",
                DEV_CAPS_16BIT, NULL, NULL },
 
        { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
@@ -193,7 +194,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        const char *conn;
        char manufacturer[64], product[64], serial_num[64], connection_id[64];
 
-       drvc = di->priv;
+       drvc = di->context;
 
        conn = NULL;
        for (l = options; l; l = l->next) {
@@ -227,11 +228,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                continue;
                }
 
-               if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) {
-                       sr_warn("Failed to get device descriptor: %s.",
-                               libusb_error_name(ret));
-                       continue;
-               }
+               libusb_get_device_descriptor( devlist[i], &des);
 
                if ((ret = libusb_open(devlist[i], &hdl)) < 0)
                        continue;
@@ -333,8 +330,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                        sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
                                        libusb_get_device_address(devlist[i]), NULL);
                } else {
-                       if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
-                               prof->firmware) == SR_OK)
+                       if (ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
+                                       USB_CONFIGURATION, prof->firmware) == SR_OK)
                                /* Store when this device's FW was updated. */
                                devc->fw_updated = g_get_monotonic_time();
                        else
@@ -355,7 +352,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
 static GSList *dev_list(const struct sr_dev_driver *di)
 {
-       return ((struct drv_context *)(di->priv))->instances;
+       return ((struct drv_context *)(di->context))->instances;
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
@@ -370,16 +367,6 @@ static int dev_open(struct sr_dev_inst *sdi)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (libusb_has_capability(LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER)) {
-               if (libusb_kernel_driver_active(usb->devhdl, 0) == 1) {
-                       if ((ret = libusb_detach_kernel_driver(usb->devhdl, 0)) < 0) {
-                               sr_err("Failed to detach kernel driver: %s.",
-                                       libusb_error_name(ret));
-                               return SR_ERR;
-                       }
-               }
-       }
-
        /*
         * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
         * milliseconds for the FX2 to renumerate.
@@ -478,7 +465,7 @@ static int cleanup(const struct sr_dev_driver *di)
        int ret;
        struct drv_context *drvc;
 
-       if (!(drvc = di->priv))
+       if (!(drvc = di->context))
                return SR_OK;
 
        ret = std_dev_clear(di, NULL);
@@ -668,8 +655,6 @@ static int start_transfers(const struct sr_dev_inst *sdi)
        } else
                devc->trigger_fired = TRUE;
 
-       timeout = fx2lafw_get_timeout(devc);
-
        num_transfers = fx2lafw_get_number_of_transfers(devc);
        size = fx2lafw_get_buffer_size(devc);
        devc->submitted_transfers = 0;
@@ -774,7 +759,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                return SR_ERR_DEV_CLOSED;
 
        di = sdi->driver;
-       drvc = di->priv;
+       drvc = di->context;
        devc = sdi->priv;
 
        devc->ctx = drvc->sr_ctx;
@@ -788,8 +773,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        if (devc->dslogic) {
                dslogic_trigger_request(sdi);
-       }
-       else {
+       } else {
                start_transfers(sdi);
                if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK) {
                        fx2lafw_abort_acquisition(devc);
@@ -825,5 +809,5 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = {
        .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };