drivers: libusb1_common code cleanup 33/5433/3
authorMarc Schink <dev@zapb.de>
Wed, 5 Feb 2020 14:50:31 +0000 (15:50 +0100)
committerOleksij Rempel <linux@rempel-privat.de>
Tue, 3 Mar 2020 07:24:33 +0000 (07:24 +0000)
Remove unncessary wrapper functions and 'jtag_' prefixes.

Change-Id: I0fd866ff1e1cf7386c4d58a808dfda2c1c0a1518
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5433
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
12 files changed:
src/jtag/aice/aice_usb.c
src/jtag/aice/aice_usb.h
src/jtag/drivers/ft232r.c
src/jtag/drivers/kitprog.c
src/jtag/drivers/libusb1_common.c
src/jtag/drivers/libusb1_common.h
src/jtag/drivers/opendous.c
src/jtag/drivers/openjtag.c
src/jtag/drivers/osbdm.c
src/jtag/drivers/stlink_usb.c
src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
src/jtag/drivers/usb_blaster/ublast_access.h

index 9e47413..8c3a629 100644 (file)
@@ -349,8 +349,8 @@ static void aice_unpack_dthmb(uint8_t *cmd_ack_code, uint8_t *target_id,
 /* calls the given usb_bulk_* function, allowing for the data to
  * trickle in with some timeouts  */
 static int usb_bulk_with_retries(
-                       int (*f)(jtag_libusb_device_handle *, int, char *, int, int, int *),
-                       jtag_libusb_device_handle *dev, int ep,
+                       int (*f)(libusb_device_handle *, int, char *, int, int, int *),
+                       libusb_device_handle *dev, int ep,
                        char *bytes, int size, int timeout, int *transferred)
 {
        int tries = 3, count = 0;
@@ -369,7 +369,7 @@ static int usb_bulk_with_retries(
        return ERROR_OK;
 }
 
-static int wrap_usb_bulk_write(jtag_libusb_device_handle *dev, int ep,
+static int wrap_usb_bulk_write(libusb_device_handle *dev, int ep,
                char *buff, int size, int timeout, int *transferred)
 {
 
@@ -379,7 +379,7 @@ static int wrap_usb_bulk_write(jtag_libusb_device_handle *dev, int ep,
        return 0;
 }
 
-static inline int usb_bulk_write_ex(jtag_libusb_device_handle *dev, int ep,
+static inline int usb_bulk_write_ex(libusb_device_handle *dev, int ep,
                char *bytes, int size, int timeout)
 {
        int tr = 0;
@@ -389,7 +389,7 @@ static inline int usb_bulk_write_ex(jtag_libusb_device_handle *dev, int ep,
        return tr;
 }
 
-static inline int usb_bulk_read_ex(jtag_libusb_device_handle *dev, int ep,
+static inline int usb_bulk_read_ex(struct libusb_device_handle *dev, int ep,
                char *bytes, int size, int timeout)
 {
        int tr = 0;
@@ -2107,7 +2107,7 @@ static int aice_usb_open(struct aice_port_param_s *param)
 {
        const uint16_t vids[] = { param->vid, 0 };
        const uint16_t pids[] = { param->pid, 0 };
-       struct jtag_libusb_device_handle *devh;
+       struct libusb_device_handle *devh;
 
        if (jtag_libusb_open(vids, pids, NULL, &devh) != ERROR_OK)
                return ERROR_FAIL;
@@ -2125,7 +2125,7 @@ static int aice_usb_open(struct aice_port_param_s *param)
 
 #if IS_WIN32 == 0
 
-       jtag_libusb_reset_device(devh);
+       libusb_reset_device(devh);
 
 #if IS_DARWIN == 0
 
@@ -2146,8 +2146,8 @@ static int aice_usb_open(struct aice_port_param_s *param)
 #endif
 
        /* usb_set_configuration required under win32 */
-       jtag_libusb_set_configuration(devh, 0);
-       jtag_libusb_claim_interface(devh, 0);
+       libusb_set_configuration(devh, 0);
+       libusb_claim_interface(devh, 0);
 
        unsigned int aice_read_ep;
        unsigned int aice_write_ep;
index 15cc1f6..04021de 100644 (file)
@@ -93,7 +93,7 @@
 struct aice_usb_handler_s {
        unsigned int usb_read_ep;
        unsigned int usb_write_ep;
-       struct jtag_libusb_device_handle *usb_handle;
+       struct libusb_device_handle *usb_handle;
 };
 
 struct cache_info {
index c20367f..8fe63bb 100644 (file)
@@ -71,7 +71,7 @@
 static char *ft232r_serial_desc;
 static uint16_t ft232r_vid = 0x0403; /* FTDI */
 static uint16_t ft232r_pid = 0x6001; /* FT232R */
-static jtag_libusb_device_handle *adapter;
+static struct libusb_device_handle *adapter;
 
 static uint8_t *ft232r_output;
 static size_t ft232r_output_len;
@@ -268,7 +268,7 @@ static int ft232r_init(void)
        else /* serial port will be restored after jtag: */
                libusb_set_auto_detach_kernel_driver(adapter, 1); /* 1: DONT_DETACH_SIO_MODULE */
 
-       if (jtag_libusb_claim_interface(adapter, 0)) {
+       if (libusb_claim_interface(adapter, 0)) {
                LOG_ERROR("unable to claim interface");
                return ERROR_JTAG_INIT_FAILED;
        }
@@ -330,7 +330,7 @@ static int ft232r_quit(void)
                }
        }
 
-       if (jtag_libusb_release_interface(adapter, 0) != 0)
+       if (libusb_release_interface(adapter, 0) != 0)
                LOG_ERROR("usb release interface failed");
 
        jtag_libusb_close(adapter);
index 7b339aa..e26f5aa 100644 (file)
@@ -95,7 +95,7 @@
 
 struct kitprog {
        hid_device *hid_handle;
-       struct jtag_libusb_device_handle *usb_handle;
+       struct libusb_device_handle *usb_handle;
        uint16_t packet_size;
        uint16_t packet_index;
        uint8_t *packet_buffer;
@@ -311,7 +311,7 @@ static int kitprog_usb_open(void)
        }
 
        /* Claim the KitProg Programmer (bulk transfer) interface */
-       if (jtag_libusb_claim_interface(kitprog_handle->usb_handle, 1) != ERROR_OK) {
+       if (libusb_claim_interface(kitprog_handle->usb_handle, 1) != ERROR_OK) {
                LOG_ERROR("Failed to claim KitProg Programmer (bulk transfer) interface");
                return ERROR_FAIL;
        }
index 0d4bcba..607b6d4 100644 (file)
@@ -125,12 +125,12 @@ static bool string_descriptor_equal(libusb_device_handle *device, uint8_t str_in
 
 int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
                const char *serial,
-               struct jtag_libusb_device_handle **out)
+               struct libusb_device_handle **out)
 {
        int cnt, idx, errCode;
        int retval = ERROR_FAIL;
        bool serial_mismatch = false;
-       struct jtag_libusb_device_handle *libusb_handle = NULL;
+       struct libusb_device_handle *libusb_handle = NULL;
 
        if (libusb_init(&jtag_libusb_context) < 0)
                return ERROR_FAIL;
@@ -180,7 +180,7 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
        return retval;
 }
 
-void jtag_libusb_close(jtag_libusb_device_handle *dev)
+void jtag_libusb_close(struct libusb_device_handle *dev)
 {
        /* Close device */
        libusb_close(dev);
@@ -188,7 +188,7 @@ void jtag_libusb_close(jtag_libusb_device_handle *dev)
        libusb_exit(jtag_libusb_context);
 }
 
-int jtag_libusb_control_transfer(jtag_libusb_device_handle *dev, uint8_t requestType,
+int jtag_libusb_control_transfer(struct libusb_device_handle *dev, uint8_t requestType,
                uint8_t request, uint16_t wValue, uint16_t wIndex, char *bytes,
                uint16_t size, unsigned int timeout)
 {
@@ -203,7 +203,7 @@ int jtag_libusb_control_transfer(jtag_libusb_device_handle *dev, uint8_t request
        return transferred;
 }
 
-int jtag_libusb_bulk_write(jtag_libusb_device_handle *dev, int ep, char *bytes,
+int jtag_libusb_bulk_write(struct libusb_device_handle *dev, int ep, char *bytes,
                           int size, int timeout, int *transferred)
 {
        int ret;
@@ -220,7 +220,7 @@ int jtag_libusb_bulk_write(jtag_libusb_device_handle *dev, int ep, char *bytes,
        return ERROR_OK;
 }
 
-int jtag_libusb_bulk_read(jtag_libusb_device_handle *dev, int ep, char *bytes,
+int jtag_libusb_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes,
                          int size, int timeout, int *transferred)
 {
        int ret;
@@ -237,10 +237,10 @@ int jtag_libusb_bulk_read(jtag_libusb_device_handle *dev, int ep, char *bytes,
        return ERROR_OK;
 }
 
-int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
+int jtag_libusb_set_configuration(struct libusb_device_handle *devh,
                int configuration)
 {
-       struct jtag_libusb_device *udev = jtag_libusb_get_device(devh);
+       struct libusb_device *udev = libusb_get_device(devh);
        int retCode = -99;
 
        struct libusb_config_descriptor *config = NULL;
@@ -265,12 +265,12 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
        return retCode;
 }
 
-int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
+int jtag_libusb_choose_interface(struct libusb_device_handle *devh,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep,
                int bclass, int subclass, int protocol, int trans_type)
 {
-       struct jtag_libusb_device *udev = jtag_libusb_get_device(devh);
+       struct libusb_device *udev = libusb_get_device(devh);
        const struct libusb_interface *inter;
        const struct libusb_interface_descriptor *interdesc;
        const struct libusb_endpoint_descriptor *epdesc;
@@ -317,7 +317,7 @@ int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
        return ERROR_FAIL;
 }
 
-int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid)
+int jtag_libusb_get_pid(struct libusb_device *dev, uint16_t *pid)
 {
        struct libusb_device_descriptor dev_desc;
 
index 34be691..b132e26 100644 (file)
 
 #include <libusb.h>
 
-#define jtag_libusb_device                     libusb_device
-#define jtag_libusb_device_handle              libusb_device_handle
-#define jtag_libusb_device_descriptor          libusb_device_descriptor
-#define jtag_libusb_interface                  libusb_interface
-#define jtag_libusb_interface_descriptor       libusb_interface_descriptor
-#define jtag_libusb_endpoint_descriptor                libusb_endpoint_descriptor
-#define jtag_libusb_config_descriptor          libusb_config_descriptor
-
-#define jtag_libusb_reset_device(dev)          libusb_reset_device(dev)
-#define jtag_libusb_get_device(devh)           libusb_get_device(devh)
-
-static inline int jtag_libusb_claim_interface(jtag_libusb_device_handle *devh,
-               int iface)
-{
-       return libusb_claim_interface(devh, iface);
-};
-
-static inline int jtag_libusb_release_interface(jtag_libusb_device_handle *devh,
-               int iface)
-{
-       return libusb_release_interface(devh, iface);
-}
-
 int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
                const char *serial,
-               struct jtag_libusb_device_handle **out);
-void jtag_libusb_close(jtag_libusb_device_handle *dev);
-int jtag_libusb_control_transfer(jtag_libusb_device_handle *dev,
+               struct libusb_device_handle **out);
+void jtag_libusb_close(struct libusb_device_handle *dev);
+int jtag_libusb_control_transfer(struct libusb_device_handle *dev,
                uint8_t requestType, uint8_t request, uint16_t wValue,
                uint16_t wIndex, char *bytes,   uint16_t size, unsigned int timeout);
-int jtag_libusb_bulk_write(struct jtag_libusb_device_handle *dev, int ep,
+int jtag_libusb_bulk_write(struct libusb_device_handle *dev, int ep,
                char *bytes, int size, int timeout, int *transferred);
-int jtag_libusb_bulk_read(struct jtag_libusb_device_handle *dev, int ep,
+int jtag_libusb_bulk_read(struct libusb_device_handle *dev, int ep,
                char *bytes, int size, int timeout, int *transferred);
-int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
+int jtag_libusb_set_configuration(struct libusb_device_handle *devh,
                int configuration);
 /**
  * Find the first interface optionally matching class, subclass and
@@ -72,10 +49,10 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
  * @param trans_type `bmAttributes Bits 0..1 Transfer type` to match, or -1 to ignore this field.
  * @returns Returns ERROR_OK on success, ERROR_FAIL otherwise.
  */
-int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
+int jtag_libusb_choose_interface(struct libusb_device_handle *devh,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep,
                int bclass, int subclass, int protocol, int trans_type);
-int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid);
+int jtag_libusb_get_pid(struct libusb_device *dev, uint16_t *pid);
 
 #endif /* OPENOCD_JTAG_DRIVERS_LIBUSB1_COMMON_H */
index d5c279b..18d9543 100644 (file)
@@ -134,7 +134,7 @@ static void opendous_tap_append_scan(int length, uint8_t *buffer, struct scan_co
 
 /* opendous lowlevel functions */
 struct opendous_jtag {
-       struct jtag_libusb_device_handle *usb_handle;
+       struct libusb_device_handle *usb_handle;
 };
 
 static struct opendous_jtag *opendous_usb_open(void);
@@ -714,12 +714,12 @@ struct opendous_jtag *opendous_usb_open(void)
 {
        struct opendous_jtag *result;
 
-       struct jtag_libusb_device_handle *devh;
+       struct libusb_device_handle *devh;
        if (jtag_libusb_open(opendous_probe->VID, opendous_probe->PID, NULL, &devh) != ERROR_OK)
                return NULL;
 
        jtag_libusb_set_configuration(devh, 0);
-       jtag_libusb_claim_interface(devh, 0);
+       libusb_claim_interface(devh, 0);
 
        result = malloc(sizeof(*result));
        result->usb_handle = devh;
index c42b620..3bfcccf 100644 (file)
@@ -111,7 +111,7 @@ static uint8_t usb_rx_buf[OPENJTAG_BUFFER_SIZE];
 static struct openjtag_scan_result openjtag_scan_result_buffer[OPENJTAG_MAX_PENDING_RESULTS];
 static int openjtag_scan_result_count;
 
-static jtag_libusb_device_handle *usbh;
+static struct libusb_device_handle *usbh;
 
 /* CY7C65215 model only */
 #define CY7C65215_JTAG_REQUEST  0x40  /* bmRequestType: vendor host-to-device */
index 3323557..30c4623 100644 (file)
@@ -132,7 +132,7 @@ static const uint16_t osbdm_vid[] = { 0x15a2, 0x15a2, 0x15a2, 0 };
 static const uint16_t osbdm_pid[] = { 0x0042, 0x0058, 0x005e, 0 };
 
 struct osbdm {
-       struct jtag_libusb_device_handle *devh; /* USB handle */
+       struct libusb_device_handle *devh; /* USB handle */
        uint8_t buffer[OSBDM_USB_BUFSIZE]; /* Data to send and receive */
        int count; /* Count data to send and to read */
 };
@@ -377,7 +377,7 @@ static int osbdm_open(struct osbdm *osbdm)
        if (jtag_libusb_open(osbdm_vid, osbdm_pid, NULL, &osbdm->devh) != ERROR_OK)
                return ERROR_FAIL;
 
-       if (jtag_libusb_claim_interface(osbdm->devh, 0) != ERROR_OK)
+       if (libusb_claim_interface(osbdm->devh, 0) != ERROR_OK)
                return ERROR_FAIL;
 
        return ERROR_OK;
index da1d1b5..a186dfd 100644 (file)
@@ -111,7 +111,7 @@ struct stlink_usb_version {
 /** */
 struct stlink_usb_handle_s {
        /** */
-       struct jtag_libusb_device_handle *fd;
+       struct libusb_device_handle *fd;
        /** */
        struct libusb_transfer *trans;
        /** */
@@ -451,7 +451,7 @@ struct jtag_xfer {
 };
 
 static int jtag_libusb_bulk_transfer_n(
-               jtag_libusb_device_handle * dev_handle,
+               struct libusb_device_handle *dev_handle,
                struct jtag_xfer *transfers,
                size_t n_transfers,
                int timeout)
@@ -2785,7 +2785,7 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
 
                jtag_libusb_set_configuration(h->fd, 0);
 
-               if (jtag_libusb_claim_interface(h->fd, 0) != ERROR_OK) {
+               if (libusb_claim_interface(h->fd, 0) != ERROR_OK) {
                        LOG_DEBUG("claim interface failed");
                        goto error_open;
                }
@@ -2794,7 +2794,7 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
                h->rx_ep = STLINK_RX_EP;
 
                uint16_t pid;
-               if (jtag_libusb_get_pid(jtag_libusb_get_device(h->fd), &pid) != ERROR_OK) {
+               if (jtag_libusb_get_pid(libusb_get_device(h->fd), &pid) != ERROR_OK) {
                        LOG_DEBUG("libusb_get_pid failed");
                        goto error_open;
                }
@@ -2838,13 +2838,13 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
                        LOG_ERROR("read version failed");
                        goto error_open;
                } else {
-                       err = jtag_libusb_release_interface(h->fd, 0);
+                       err = libusb_release_interface(h->fd, 0);
                        if (err != ERROR_OK) {
                                LOG_ERROR("release interface failed");
                                goto error_open;
                        }
 
-                       err = jtag_libusb_reset_device(h->fd);
+                       err = libusb_reset_device(h->fd);
                        if (err != ERROR_OK) {
                                LOG_ERROR("reset device failed");
                                goto error_open;
index fb1e444..34fbb89 100644 (file)
@@ -72,7 +72,7 @@ static int ublast2_libusb_write(struct ublast_lowlevel *low, uint8_t *buf,
 
 }
 
-static int ublast2_write_firmware_section(struct jtag_libusb_device_handle *libusb_dev,
+static int ublast2_write_firmware_section(struct libusb_device_handle *libusb_dev,
                                   struct image *firmware_image, int section_index)
 {
        uint16_t chunk_size;
@@ -123,7 +123,7 @@ static int ublast2_write_firmware_section(struct jtag_libusb_device_handle *libu
        return ERROR_OK;
 }
 
-static int load_usb_blaster_firmware(struct jtag_libusb_device_handle *libusb_dev,
+static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev,
                                     struct ublast_lowlevel *low)
 {
        struct image ublast2_firmware_image;
@@ -191,7 +191,7 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
 {
        const uint16_t vids[] = { low->ublast_vid_uninit, 0 };
        const uint16_t pids[] = { low->ublast_pid_uninit, 0 };
-       struct jtag_libusb_device_handle *temp;
+       struct libusb_device_handle *temp;
        bool renumeration = false;
        int ret;
 
index 252f003..5178ae1 100644 (file)
@@ -39,7 +39,7 @@ struct ublast_lowlevel {
        uint16_t ublast_vid_uninit;
        uint16_t ublast_pid_uninit;
        char *ublast_device_desc;
-       struct jtag_libusb_device_handle *libusb_dev;
+       struct libusb_device_handle *libusb_dev;
        char *firmware_path;
 
        int (*write)(struct ublast_lowlevel *low, uint8_t *buf, int size,