Call to ftdi_set_interface right after ftdi_init and before call to ftdi_usb_open
Signed-off-by: Ilya A. Volynets-Evenbakh ilya@total-knowledge.com --- ft2232_spi.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/ft2232_spi.c b/ft2232_spi.c index aec2fd5..aaca5f3 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -276,6 +276,11 @@ int ft2232_spi_init(void) return -3; }
+ if (ftdi_set_interface(ftdic, ft2232_interface) < 0) { + msg_perr("Unable to select interface: %s\n", + ftdic->error_str); + } + f = ftdi_usb_open(ftdic, ft2232_vid, ft2232_type);
if (f < 0 && f != -5) { @@ -290,11 +295,6 @@ int ft2232_spi_init(void) clock_5x = 0; }
- if (ftdi_set_interface(ftdic, ft2232_interface) < 0) { - msg_perr("Unable to select interface: %s\n", - ftdic->error_str); - } - if (ftdi_usb_reset(ftdic) < 0) { msg_perr("Unable to reset FTDI device\n"); }
FT232HM is a USB to SPI/I2C/RSR232 converter, with USB on one end, and 10 separate single female pin headers on the other. Basically, it can be hooked up any way you want, and then configured accordingly.
This patch introduced support for following things: - FT232H chip - Support for two slaves on SPI bus (can be extended to 5 - the device has 4 GPIOs in addition to standard CS) - Added option to enable libusb debug output
This patch requires latest libftdi sources from libftdi git tree, and consequently libusb >= 1.0
Signed-off-by: Ilya A. Volynets-Evenbakh ilya@total-knowledge.com --- Makefile | 3 +++ ft2232_spi.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile index 530fb83..3caf3e7 100644 --- a/Makefile +++ b/Makefile @@ -432,6 +432,9 @@ endif
ifeq ($(CONFIG_FT2232_SPI), yes) FTDILIBS := $(shell pkg-config --libs libftdi 2>/dev/null || printf "%s" "-lftdi -lusb") +FTDICFLAGS := $(shell pkg-config --cflags libftdi 2>/dev/null || printf "%s" "-I/usr/include/libftdi") +LIBUSB_INCLUDES?=-I/usr/include/libusb-1.0 +CPPFLAGS += $(LIBUSB_INCLUDES) $(FTDICFLAGS) # This is a totally ugly hack. FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && printf "%s" "-D'CONFIG_FT2232_SPI=1'") FEATURE_LIBS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && printf "%s" "$(FTDILIBS)") diff --git a/ft2232_spi.c b/ft2232_spi.c index aaca5f3..02250a7 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -28,12 +28,14 @@ #include "programmer.h" #include "spi.h" #include <ftdi.h> +#include <libusb.h>
/* Please keep sorted by vendor ID, then device ID. */
#define FTDI_VID 0x0403 #define FTDI_FT2232H_PID 0x6010 #define FTDI_FT4232H_PID 0x6011 +#define FTDI_FT232HM_PID 0x6014 #define TIAO_TUMPA_PID 0x8a98 #define AMONTEC_JTAGKEY_PID 0xCFF8
@@ -52,6 +54,7 @@ const struct usbdev_status devs_ft2232spi[] = { {FTDI_VID, FTDI_FT2232H_PID, OK, "FTDI", "FT2232H"}, {FTDI_VID, FTDI_FT4232H_PID, OK, "FTDI", "FT4232H"}, + {FTDI_VID, FTDI_FT232HM_PID, OK, "FTDI", "FT232HM"}, {FTDI_VID, TIAO_TUMPA_PID, OK, "TIAO", "USB Multi-Protocol Adapter"}, {FTDI_VID, AMONTEC_JTAGKEY_PID, OK, "Amontec", "JTAGkey"}, {GOEPEL_VID, GOEPEL_PICOTAP_PID, OK, "GOEPEL", "PicoTAP"}, @@ -159,6 +162,7 @@ int ft2232_spi_init(void) int ft2232_vid = FTDI_VID; int ft2232_type = FTDI_FT4232H_PID; enum ftdi_interface ft2232_interface = INTERFACE_B; + int libusb_debug = 0; /* * The 'H' chips can run with an internal clock of either 12 MHz or 60 MHz, * but the non-H chips can only run at 12 MHz. We enable the divide-by-5 @@ -174,17 +178,39 @@ int ft2232_spi_init(void) * 92 Hz for 12 MHz inputs. */ uint32_t divisor = DEFAULT_DIVISOR; + /* Chip select on 232HM: when set to 1, selects secondary + SPI slave, by setting GPIO0 (line 6) to 1, and CS to 0 */ + int cs = 0; int f; char *arg; double mpsse_clk;
+ arg = extract_programmer_param("usb_debug"); + if(arg) { + printf("Enabling libusb debugging\n"); + libusb_debug=2; + } + + arg = extract_programmer_param("cs"); + if (arg) { + cs = atoi(arg); + } + arg = extract_programmer_param("type"); if (arg) { if (!strcasecmp(arg, "2232H")) ft2232_type = FTDI_FT2232H_PID; else if (!strcasecmp(arg, "4232H")) ft2232_type = FTDI_FT4232H_PID; - else if (!strcasecmp(arg, "jtagkey")) { + else if (!strcasecmp(arg, "232HM")) { + ft2232_type = FTDI_FT232HM_PID; + ft2232_interface = INTERFACE_A; + if(cs==1) { + printf("Selecting secondary SPI slave\n"); + cs_bits = 0x10; + pindir = 0x1b; + } + } else if (!strcasecmp(arg, "jtagkey")) { ft2232_type = AMONTEC_JTAGKEY_PID; ft2232_interface = INTERFACE_A; cs_bits = 0x18; @@ -281,6 +307,14 @@ int ft2232_spi_init(void) ftdic->error_str); }
+ if(libusb_debug) + libusb_set_debug(ftdic->usb_ctx, 2); + + if (ftdi_set_interface(ftdic, ft2232_interface) < 0) { + msg_perr("Unable to select interface: %s\n", + ftdic->error_str); + } + f = ftdi_usb_open(ftdic, ft2232_vid, ft2232_type);
if (f < 0 && f != -5) { @@ -289,7 +323,7 @@ int ft2232_spi_init(void) return -4; }
- if (ftdic->type != TYPE_2232H && ftdic->type != TYPE_4232H) { + if (ftdic->type != TYPE_2232H && ftdic->type != TYPE_4232H && ftdic->type != TYPE_232H) { msg_pdbg("FTDI chip type %d is not high-speed\n", ftdic->type); clock_5x = 0;
On Thu, 14 Jun 2012 18:07:59 +0300 "Ilya A. Volynets-Evenbakh" ilya@total-knowledge.com wrote:
FT232HM is a USB to SPI/I2C/RSR232 converter, with USB on one end, and 10 separate single female pin headers on the other. Basically, it can be hooked up any way you want, and then configured accordingly.
This patch introduced support for following things:
- FT232H chip
- Support for two slaves on SPI bus (can be extended to 5 - the device has 4 GPIOs in addition to standard CS)
- Added option to enable libusb debug output
hello Ilya and thanks for your patch!
i have not reviewed or tested your patch in detail but i have the following change requests: extract_programmer_param allocates a new string, so you need to clean its return value up with free() (see other usages in the same file)
also, can you please split the patch up in at least two parts: - general FT232H support - support for multiple slaves (i would prefer if you could add the other GPIOs too)
the first one can be merged without much concern (maybe some ifdefs to be backward compatible to older libftdis). the CS/GPIO part needs some internal discussion first, hence the requested split.
i am not sure if we want to merge the libusb debug part at all, but if you want it please provide it as separate patch.
have you done some benchmarks? i'd like to know if this chip behaves significantly different to the older ones.
This patch requires latest libftdi sources from libftdi git tree, and consequently libusb >= 1.0
Signed-off-by: Ilya A. Volynets-Evenbakh ilya@total-knowledge.com
Hi!
Based on Ilya's patch i have prepared the integration of FT232H support. Could somebody please test/review the following patch set[1], especially the secondd one?
[1]: they are currently also available on github: https://github.com/stefanct/flashrom/tree/ft232h
Stefan Tauner (3): Add support for all 4 possible channels to the ft2232_spi programmer. Add support for FT232H. Cleanup ft2322.c
Makefile | 12 ++++++++ flashrom.8 | 12 ++++---- ft2232_spi.c | 86 ++++++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 75 insertions(+), 35 deletions(-)
On Thu, 14 Jun 2012 18:07:58 +0300 "Ilya A. Volynets-Evenbakh" ilya@total-knowledge.com wrote:
Call to ftdi_set_interface right after ftdi_init and before call to ftdi_usb_open
Signed-off-by: Ilya A. Volynets-Evenbakh ilya@total-knowledge.com
right. this has been checked for since libftdi commit 1c5fa36b67bc30742eee94ed3e3648fcd4640f24 (which will probably end up in libftdi 0.21). http://developer.intra2net.com/git/?p=libftdi;a=commit;f=src/ftdi.c;h=1c5fa3...
Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at and committed in r1573 Thanks!