Alan Green has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/49632 )
Change subject: ft2232_spi.c: release I/Os on shutdown ......................................................................
ft2232_spi.c: release I/Os on shutdown
Resets FTDI I/O pins to high-Z (input) when shutting down. This allows other devices to use the SPI bus without having to disconnect the programmer.
This change will introduce a backward incompatibility in the case where a user is relying on the state of FTDI outputs post-programming (eg. to disallow another device from driving CS low).
However, there are likely more cases where releasing the SPI bus is likely the correct thing to do.
Signed-off-by: Alan Green avg@google.com Change-Id: I9fae55e532595752983f55fac2298f81699dbe5b --- M ft2232_spi.c 1 file changed, 28 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/32/49632/1
diff --git a/ft2232_spi.c b/ft2232_spi.c index 65ff449..6cf7a3c 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -106,6 +106,7 @@ static uint8_t pindir = 0x0b; static struct ftdi_context ftdic_context;
+ static const char *get_ft2232_devicename(int ft2232_vid, int ft2232_type) { int i; @@ -159,6 +160,32 @@ return 0; }
+static int ft2232_shutdown(void *data) +{ + int ret = 0; + int f; + struct ftdi_context *ftdic = &ftdic_context; + unsigned char buf[3]; + + msg_pdbg("Releasing I/Os\n"); + buf[0] = SET_BITS_LOW; + buf[1] = 0; /* Output byte ignored */ + buf[2] = 0; /* Pin direction: all inputs */ + if (send_buf(ftdic, buf, 3)) { + ret = -8; + goto ftdi_err; + } + +ftdi_err: + if ((f = ftdi_usb_close(ftdic)) < 0) { + msg_perr("Unable to close FTDI device: %d (%s)\n", f, + ftdi_get_error_string(ftdic)); + return f; + } + + return ret; +} + static int ft2232_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, @@ -453,6 +480,7 @@ goto ftdi_err; }
+ register_shutdown(ft2232_shutdown, ftdic); register_spi_master(&spi_master_ft2232);
return 0;