sr: zeroplus: Remove unused gl_open()/gl_close().
Merge the missing function calls into zeroplus.c's init functions.
This commit is contained in:
parent
1a081ca67d
commit
185ae2c5c9
|
@ -140,69 +140,3 @@ int gl_reg_read(libusb_device_handle *devh, unsigned int reg)
|
||||||
ret = gl_read_data(devh);
|
ret = gl_read_data(devh);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gl_open(int vid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
struct libusb_device **devs;
|
|
||||||
struct libusb_device *dev;
|
|
||||||
size_t i = 0;
|
|
||||||
struct libusb_device_descriptor desc;
|
|
||||||
|
|
||||||
ret = libusb_init(NULL);
|
|
||||||
if (ret < 0)
|
|
||||||
return GL_ELIBUSB;
|
|
||||||
|
|
||||||
if (libusb_get_device_list(NULL, &devs) < 0) {
|
|
||||||
ret = GL_EOPEN;
|
|
||||||
goto gl_open_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((dev = devs[i++]) != NULL) {
|
|
||||||
if (libusb_get_device_descriptor(dev, &desc) < 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (desc.idVendor == vid) {
|
|
||||||
if (libusb_open(dev, &g_devh) < 0)
|
|
||||||
g_devh = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_free_device_list(devs, 1);
|
|
||||||
|
|
||||||
if (!g_devh) {
|
|
||||||
ret = GL_EOPEN;
|
|
||||||
goto gl_open_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = libusb_set_configuration(g_devh, 1);
|
|
||||||
if (ret < 0) {
|
|
||||||
ret = GL_ESETCONFIG;
|
|
||||||
goto gl_open_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = libusb_claim_interface(g_devh, 0);
|
|
||||||
if (ret < 0) {
|
|
||||||
ret = GL_ECLAIM;
|
|
||||||
goto gl_open_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GL_OK;
|
|
||||||
|
|
||||||
gl_open_error:
|
|
||||||
gl_close();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int gl_close(void)
|
|
||||||
{
|
|
||||||
if (g_devh) {
|
|
||||||
libusb_release_interface(g_devh, 0);
|
|
||||||
libusb_reset_device(g_devh);
|
|
||||||
libusb_close(g_devh);
|
|
||||||
}
|
|
||||||
libusb_exit(NULL);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -47,7 +47,5 @@ int gl_read_bulk(libusb_device_handle *devh, void *buffer, unsigned int size);
|
||||||
int gl_reg_write(libusb_device_handle *devh, unsigned int reg,
|
int gl_reg_write(libusb_device_handle *devh, unsigned int reg,
|
||||||
unsigned int val);
|
unsigned int val);
|
||||||
int gl_reg_read(libusb_device_handle *devh, unsigned int reg);
|
int gl_reg_read(libusb_device_handle *devh, unsigned int reg);
|
||||||
int gl_open(int vid);
|
|
||||||
int gl_close(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -283,8 +283,10 @@ static void close_device(struct sr_device_instance *sdi)
|
||||||
sr_info("closing device %d on %d.%d interface %d", sdi->index,
|
sr_info("closing device %d on %d.%d interface %d", sdi->index,
|
||||||
zp->usb->bus, zp->usb->address, USB_INTERFACE);
|
zp->usb->bus, zp->usb->address, USB_INTERFACE);
|
||||||
libusb_release_interface(zp->usb->devhdl, USB_INTERFACE);
|
libusb_release_interface(zp->usb->devhdl, USB_INTERFACE);
|
||||||
|
libusb_reset_device(zp->usb->devhdl);
|
||||||
libusb_close(zp->usb->devhdl);
|
libusb_close(zp->usb->devhdl);
|
||||||
zp->usb->devhdl = NULL;
|
zp->usb->devhdl = NULL;
|
||||||
|
/* TODO: Call libusb_exit() here or only in hw_cleanup()? */
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +369,7 @@ static int hw_init(const char *deviceinfo)
|
||||||
|
|
||||||
/* Find all ZeroPlus analyzers and add them to device list. */
|
/* Find all ZeroPlus analyzers and add them to device list. */
|
||||||
devcnt = 0;
|
devcnt = 0;
|
||||||
libusb_get_device_list(usb_context, &devlist);
|
libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */
|
||||||
|
|
||||||
for (i = 0; devlist[i]; i++) {
|
for (i = 0; devlist[i]; i++) {
|
||||||
err = libusb_get_device_descriptor(devlist[i], &des);
|
err = libusb_get_device_descriptor(devlist[i], &des);
|
||||||
|
@ -425,11 +427,19 @@ static int hw_opendev(int device_index)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = libusb_set_configuration(zp->usb->devhdl, USB_CONFIGURATION);
|
||||||
|
if (err < 0) {
|
||||||
|
sr_warn("zp: Unable to set USB configuration %d: %d",
|
||||||
|
USB_CONFIGURATION, err);
|
||||||
|
return SR_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
err = libusb_claim_interface(zp->usb->devhdl, USB_INTERFACE);
|
err = libusb_claim_interface(zp->usb->devhdl, USB_INTERFACE);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
sr_warn("Unable to claim interface: %d", err);
|
sr_warn("Unable to claim interface: %d", err);
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
analyzer_reset(zp->usb->devhdl);
|
analyzer_reset(zp->usb->devhdl);
|
||||||
analyzer_initialize(zp->usb->devhdl);
|
analyzer_initialize(zp->usb->devhdl);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue