[flashrom] [PATCH 2/2] Add support for FT232HM

Ilya A. Volynets-Evenbakh ilya at total-knowledge.com
Thu Jun 14 17:07:59 CEST 2012


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 at 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;
-- 
1.7.3.4





More information about the flashrom mailing list