summaryrefslogtreecommitdiffstats
path: root/ft2232_spi.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-07-01 00:02:23 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-07-01 00:02:23 +0000
commitfeea27222877521548b369e3eb49197f804f7f9c (patch)
tree7976f18e7aa76f8a7e2f04e09e8a989bec3a1d9b /ft2232_spi.c
parent9cb867b57162d028e5819f72e9e504af242d19b4 (diff)
downloadast2050-flashrom-feea27222877521548b369e3eb49197f804f7f9c.zip
ast2050-flashrom-feea27222877521548b369e3eb49197f804f7f9c.tar.gz
ft2232_spi: Allow runtime selection of FT2232H vs. FT4232H and interface A vs
B. Corresponding to flashrom svn r638. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Tested-by: Jakob Bornecrantz <wallbraker@gmail.com> Acked-by: Jakob Bornecrantz <wallbraker@gmail.com>
Diffstat (limited to 'ft2232_spi.c')
-rw-r--r--ft2232_spi.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 36b8969..d8ca743 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -22,9 +22,12 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
+#include <ctype.h>
#include "flash.h"
#include "spi.h"
+char *ft2232spi_param = NULL;
+
#if FT2232_SPI_SUPPORT == 1
#include <ftdi.h>
@@ -71,15 +74,47 @@ int ft2232_spi_init(void)
struct ftdi_context *ftdic = &ftdic_context;
unsigned char buf[512];
unsigned char port_val = 0;
-
+ char *portpos = NULL;
+ int ft2232_type = FTDI_FT4232H;
+ enum ftdi_interface ft2232_interface = INTERFACE_B;
if (ftdi_init(ftdic) < 0) {
fprintf(stderr, "ftdi_init failed\n");
return EXIT_FAILURE;
}
- // f = ftdi_usb_open(ftdic, 0x0403, 0x6010); // FT2232
- f = ftdi_usb_open(ftdic, 0x0403, 0x6011); // FT4232
+ if (ft2232spi_param && !strlen(ft2232spi_param)) {
+ free(ft2232spi_param);
+ ft2232spi_param = NULL;
+ }
+ if (ft2232spi_param) {
+ if (strstr(ft2232spi_param, "2232"))
+ ft2232_type = FTDI_FT2232H;
+ if (strstr(ft2232spi_param, "4232"))
+ ft2232_type = FTDI_FT4232H;
+ portpos = strstr(ft2232spi_param, "port=");
+ if (portpos) {
+ portpos += 5;
+ switch (toupper(*portpos)) {
+ case 'A':
+ ft2232_interface = INTERFACE_A;
+ break;
+ case 'B':
+ ft2232_interface = INTERFACE_B;
+ break;
+ default:
+ fprintf(stderr, "Invalid interface specified, "
+ "using default.\n");
+ }
+ }
+ free(ft2232spi_param);
+ }
+ printf_debug("Using device type %s ",
+ (ft2232_type == FTDI_FT2232H) ? "2232H" : "4232H");
+ printf_debug("interface %s\n",
+ (ft2232_interface == INTERFACE_A) ? "A" : "B");
+
+ f = ftdi_usb_open(ftdic, 0x0403, ft2232_type);
if (f < 0 && f != -5) {
fprintf(stderr, "Unable to open ftdi device: %d (%s)\n", f,
@@ -87,8 +122,8 @@ int ft2232_spi_init(void)
exit(-1);
}
- if (ftdi_set_interface(ftdic, INTERFACE_B) < 0) {
- fprintf(stderr, "Unable to select FT2232 channel B: %s\n",
+ if (ftdi_set_interface(ftdic, ft2232_interface) < 0) {
+ fprintf(stderr, "Unable to select interface: %s\n",
ftdic->error_str);
}
OpenPOWER on IntegriCloud