Commit ea3f7fee authored by Bernhard Nortmann's avatar Bernhard Nortmann
Browse files

fel: Rework some of the USB functions' logic



This moves claiming / releasing the interface into the respective
"open" / "close" functions. The USB code in main() is now trimmed
down to:

feldev_init();
handle = open_fel_device(...);
feldev_done(handle);
Signed-off-by: default avatarBernhard Nortmann <bernhard.nortmann@web.de>
parent edf6d6c5
......@@ -1422,11 +1422,8 @@ static feldev_handle *open_fel_device(int busnum, int devnum,
}
exit(1);
}
return result;
}
} else {
/* look for specific bus and device number */
pr_info("Selecting USB Bus %03d Device %03d\n", busnum, devnum);
bool found = false;
ssize_t rc, i;
libusb_device **list;
......@@ -1461,13 +1458,36 @@ static feldev_handle *open_fel_device(int busnum, int devnum,
busnum, devnum);
exit(1);
}
}
feldev_claim(result); /* claim interface, detect USB endpoints */
return result;
}
void feldev_close(feldev_handle *dev)
{
if (dev) {
if (dev->usb->handle) {
feldev_release(dev);
libusb_close(dev->usb->handle);
free(dev->usb); /* release memory allocated for felusb_handle struct */
}
free(dev->usb); /* release memory allocated for felusb_handle */
}
}
void feldev_init(void)
{
int rc = libusb_init(NULL);
if (rc != 0)
usb_error(rc, "libusb_init()", 1);
}
void feldev_done(feldev_handle *dev)
{
feldev_close(dev);
free(dev);
libusb_exit(NULL);
}
int main(int argc, char **argv)
......@@ -1539,17 +1559,15 @@ int main(int argc, char **argv)
fprintf(stderr, "ERROR: Expected 'bus:devnum', got '%s'.\n", dev_arg);
exit(1);
}
pr_info("Selecting USB Bus %03d Device %03d\n", busnum, devnum);
} else
break; /* no valid (prefix) option detected, exit loop */
argc -= 1;
argv += 1;
}
int rc = libusb_init(NULL);
assert(rc == 0);
feldev_init();
handle = open_fel_device(busnum, devnum, AW_USB_VENDOR_ID, AW_USB_PRODUCT_ID);
assert(handle != NULL);
feldev_claim(handle);
while (argc > 1 ) {
int skip = 1;
......@@ -1645,10 +1663,7 @@ int main(int argc, char **argv)
aw_fel_execute(handle, uboot_entry);
}
feldev_release(handle);
feldev_close(handle);
free(handle);
libusb_exit(NULL);
feldev_done(handle);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment