aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <dev@zapb.de>2020-02-05 15:50:31 +0100
committerOleksij Rempel <linux@rempel-privat.de>2020-03-03 07:24:33 +0000
commit93c6bf2cce5f23e37d4a1dd5136a40e74c69285c (patch)
treeb8d081f5f51d4b9c10f50f598d0c77e2bfbfa1f3
parent8ce51b6a207e8cefdf5b6cb06d3c57d1cbef5a99 (diff)
drivers: libusb1_common code cleanup
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>
-rw-r--r--src/jtag/aice/aice_usb.c18
-rw-r--r--src/jtag/aice/aice_usb.h2
-rw-r--r--src/jtag/drivers/ft232r.c6
-rw-r--r--src/jtag/drivers/kitprog.c4
-rw-r--r--src/jtag/drivers/libusb1_common.c22
-rw-r--r--src/jtag/drivers/libusb1_common.h39
-rw-r--r--src/jtag/drivers/opendous.c6
-rw-r--r--src/jtag/drivers/openjtag.c2
-rw-r--r--src/jtag/drivers/osbdm.c4
-rw-r--r--src/jtag/drivers/stlink_usb.c12
-rw-r--r--src/jtag/drivers/usb_blaster/ublast2_access_libusb.c6
-rw-r--r--src/jtag/drivers/usb_blaster/ublast_access.h2
12 files changed, 50 insertions, 73 deletions
diff --git a/src/jtag/aice/aice_usb.c b/src/jtag/aice/aice_usb.c
index 9e474134..8c3a629a 100644
--- a/src/jtag/aice/aice_usb.c
+++ b/src/jtag/aice/aice_usb.c
@@ -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;
diff --git a/src/jtag/aice/aice_usb.h b/src/jtag/aice/aice_usb.h
index 15cc1f60..04021de3 100644
--- a/src/jtag/aice/aice_usb.h
+++ b/src/jtag/aice/aice_usb.h
@@ -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 {
diff --git a/src/jtag/drivers/ft232r.c b/src/jtag/drivers/ft232r.c
index c20367fc..8fe63bb3 100644
--- a/src/jtag/drivers/ft232r.c
+++ b/src/jtag/drivers/ft232r.c
@@ -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);
diff --git a/src/jtag/drivers/kitprog.c b/src/jtag/drivers/kitprog.c
index 7b339aa0..e26f5aa9 100644
--- a/src/jtag/drivers/kitprog.c
+++ b/src/jtag/drivers/kitprog.c
@@ -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;
}
diff --git a/src/jtag/drivers/libusb1_common.c b/src/jtag/drivers/libusb1_common.c
index 0d4bcbab..607b6d4a 100644
--- a/src/jtag/drivers/libusb1_common.c
+++ b/src/jtag/drivers/libusb1_common.c
@@ -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;
diff --git a/src/jtag/drivers/libusb1_common.h b/src/jtag/drivers/libusb1_common.h
index 34be691f..b132e26a 100644
--- a/src/jtag/drivers/libusb1_common.h
+++ b/src/jtag/drivers/libusb1_common.h
@@ -22,41 +22,18 @@
#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 */
diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c
index d5c279b0..18d95430 100644
--- a/src/jtag/drivers/opendous.c
+++ b/src/jtag/drivers/opendous.c
@@ -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;
diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c
index c42b620b..3bfcccf6 100644
--- a/src/jtag/drivers/openjtag.c
+++ b/src/jtag/drivers/openjtag.c
@@ -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 */
diff --git a/src/jtag/drivers/osbdm.c b/src/jtag/drivers/osbdm.c
index 3323557b..30c46234 100644
--- a/src/jtag/drivers/osbdm.c
+++ b/src/jtag/drivers/osbdm.c
@@ -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;
diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c
index da1d1b56..a186dfde 100644
--- a/src/jtag/drivers/stlink_usb.c
+++ b/src/jtag/drivers/stlink_usb.c
@@ -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;
diff --git a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
index fb1e4440..34fbb895 100644
--- a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
+++ b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
@@ -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;
diff --git a/src/jtag/drivers/usb_blaster/ublast_access.h b/src/jtag/drivers/usb_blaster/ublast_access.h
index 252f003a..5178ae10 100644
--- a/src/jtag/drivers/usb_blaster/ublast_access.h
+++ b/src/jtag/drivers/usb_blaster/ublast_access.h
@@ -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,