summaryrefslogtreecommitdiffstats
path: root/ft2232_spi.c
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-09-26 00:46:02 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-09-26 00:46:02 +0000
commitfbc71ac494a798ed6b19f5895c0f4a5183e9866c (patch)
tree5db8dd8d0a8bbf9798cc0729383ec73a44d1620c /ft2232_spi.c
parentfd0d41353777804d890caf150c749da928da4d79 (diff)
downloadflashrom-fbc71ac494a798ed6b19f5895c0f4a5183e9866c.tar.gz
flashrom-fbc71ac494a798ed6b19f5895c0f4a5183e9866c.tar.bz2
flashrom-fbc71ac494a798ed6b19f5895c0f4a5183e9866c.zip
Add support for all 4 possible channels to the ft2232_spi programmer
Add a check to validate the selected channel/interface, which not even libftdi seems to do yet. This patch changes default behavior: the new default channel/interface is A. Also, this patch uses the word 'channel' in addition or in place of 'interface' where possible without too much hassle because it is the term FTDI uses. Corresponding to flashrom svn r1608. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Diffstat (limited to 'ft2232_spi.c')
-rw-r--r--ft2232_spi.c60
1 files changed, 41 insertions, 19 deletions
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 1b8067454..628823fbd 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -161,7 +161,8 @@ int ft2232_spi_init(void)
unsigned char buf[512];
int ft2232_vid = FTDI_VID;
int ft2232_type = FTDI_FT4232H_PID;
- enum ftdi_interface ft2232_interface = INTERFACE_B;
+ int channel_count = 4; /* Stores the number of channels of the device. */
+ enum ftdi_interface ft2232_interface = INTERFACE_A;
/*
* 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
@@ -183,53 +184,55 @@ int ft2232_spi_init(void)
arg = extract_programmer_param("type");
if (arg) {
- if (!strcasecmp(arg, "2232H"))
+ if (!strcasecmp(arg, "2232H")) {
ft2232_type = FTDI_FT2232H_PID;
- else if (!strcasecmp(arg, "4232H"))
+ channel_count = 2;
+ } else if (!strcasecmp(arg, "4232H")) {
ft2232_type = FTDI_FT4232H_PID;
- else if (!strcasecmp(arg, "jtagkey")) {
+ channel_count = 4;
+ } else if (!strcasecmp(arg, "jtagkey")) {
ft2232_type = AMONTEC_JTAGKEY_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
cs_bits = 0x18;
pindir = 0x1b;
} else if (!strcasecmp(arg, "picotap")) {
ft2232_vid = GOEPEL_VID;
ft2232_type = GOEPEL_PICOTAP_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
} else if (!strcasecmp(arg, "tumpa")) {
/* Interface A is SPI1, B is SPI2. */
ft2232_type = TIAO_TUMPA_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
} else if (!strcasecmp(arg, "busblaster")) {
/* In its default configuration it is a jtagkey clone */
ft2232_type = FTDI_FT2232H_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
cs_bits = 0x18;
pindir = 0x1b;
} else if (!strcasecmp(arg, "openmoko")) {
ft2232_vid = FIC_VID;
ft2232_type = OPENMOKO_DBGBOARD_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
} else if (!strcasecmp(arg, "arm-usb-ocd")) {
ft2232_vid = OLIMEX_VID;
ft2232_type = OLIMEX_ARM_OCD_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
cs_bits = 0x08;
pindir = 0x1b;
} else if (!strcasecmp(arg, "arm-usb-tiny")) {
ft2232_vid = OLIMEX_VID;
ft2232_type = OLIMEX_ARM_TINY_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
} else if (!strcasecmp(arg, "arm-usb-ocd-h")) {
ft2232_vid = OLIMEX_VID;
ft2232_type = OLIMEX_ARM_OCD_H_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
cs_bits = 0x08;
pindir = 0x1b;
} else if (!strcasecmp(arg, "arm-usb-tiny-h")) {
ft2232_vid = OLIMEX_VID;
ft2232_type = OLIMEX_ARM_TINY_H_PID;
- ft2232_interface = INTERFACE_A;
+ channel_count = 2;
} else {
msg_perr("Error: Invalid device type specified.\n");
free(arg);
@@ -245,14 +248,31 @@ int ft2232_spi_init(void)
break;
case 'B':
ft2232_interface = INTERFACE_B;
+ if (channel_count < 2)
+ channel_count = -1;
+ break;
+ case 'C':
+ ft2232_interface = INTERFACE_C;
+ if (channel_count < 3)
+ channel_count = -1;
+ break;
+ case 'D':
+ ft2232_interface = INTERFACE_D;
+ if (channel_count < 4)
+ channel_count = -1;
break;
default:
- msg_perr("Error: Invalid port/interface specified.\n");
- free(arg);
- return -2;
+ channel_count = -1;
+ break;
}
}
+ if (channel_count < 0 || strlen(arg) != 1) {
+ msg_perr("Error: Invalid channel/port/interface specified: \"%s\".\n", arg);
+ free(arg);
+ return -2;
+ }
free(arg);
+
arg = extract_programmer_param("divisor");
if (arg && strlen(arg)) {
unsigned int temp = 0;
@@ -271,8 +291,10 @@ int ft2232_spi_init(void)
msg_pdbg("Using device type %s %s ",
get_ft2232_vendorname(ft2232_vid, ft2232_type),
get_ft2232_devicename(ft2232_vid, ft2232_type));
- msg_pdbg("interface %s\n",
- (ft2232_interface == INTERFACE_A) ? "A" : "B");
+ msg_pdbg("channel %s\n",
+ (ft2232_interface == INTERFACE_A) ? "A" :
+ (ft2232_interface == INTERFACE_B) ? "B" :
+ (ft2232_interface == INTERFACE_C) ? "C" : "D");
if (ftdi_init(ftdic) < 0) {
msg_perr("ftdi_init failed\n");
@@ -280,7 +302,7 @@ int ft2232_spi_init(void)
}
if (ftdi_set_interface(ftdic, ft2232_interface) < 0) {
- msg_perr("Unable to select interface: %s\n", ftdic->error_str);
+ msg_perr("Unable to select channel: %s\n", ftdic->error_str);
}
arg = extract_programmer_param("serial");