+
+ return ERROR_OK;
+}
+
+static int ft2232_purge_libftdi(void)
+{
+ if (ftdi_usb_purge_buffers(&ftdic) < 0)
+ {
+ ERROR("ftdi_purge_buffers: %s", ftdic.error_str);
+ return ERROR_JTAG_INIT_FAILED;
+ }
+
+ return ERROR_OK;
+}
+#endif /* BUILD_FT2232_LIBFTDI == 1 */
+
+int ft2232_init(void)
+{
+ u8 buf[1];
+ int retval;
+ u32 bytes_written;
+ ft2232_layout_t *cur_layout = ft2232_layouts;
+ int i;
+
+ if ((ft2232_layout == NULL) || (ft2232_layout[0] == 0))
+ {
+ ft2232_layout = "usbjtag";
+ WARNING("No ft2232 layout specified, using default 'usbjtag'");
+ }
+
+ while (cur_layout->name)
+ {
+ if (strcmp(cur_layout->name, ft2232_layout) == 0)
+ {
+ layout = cur_layout;
+ break;
+ }
+ cur_layout++;
+ }
+
+ if (!layout)
+ {
+ ERROR("No matching layout found for %s", ft2232_layout);
+ return ERROR_JTAG_INIT_FAILED;
+ }
+
+ for (i = 0; 1; i++) {
+ /*
+ * "more indicates that there are more IDs to try, so we should
+ * not print an error for an ID mismatch (but for anything
+ * else, we should).
+ *
+ * try_more indicates that the error code returned indicates an
+ * ID mismatch (and nothing else) and that we should proceeed
+ * with the next ID pair.
+ */
+ int more = ft2232_vid[i+1] || ft2232_pid[i+1];
+ int try_more = 0;
+
+#if BUILD_FT2232_FTD2XX == 1
+ retval = ft2232_init_ftd2xx(ft2232_vid[i], ft2232_pid[i],
+ more, &try_more);
+#elif BUILD_FT2232_LIBFTDI == 1
+ retval = ft2232_init_libftdi(ft2232_vid[i], ft2232_pid[i],
+ more, &try_more);