From 3681ade2c7bfb2e4befee1ff6909608752f91d92 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 2 Sep 2018 17:11:52 +0200 Subject: Force flash to exist QPI mode in iceprog Signed-off-by: Clifford Wolf --- iceprog/iceprog.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c index 104159e..6462b3d 100644 --- a/iceprog/iceprog.c +++ b/iceprog/iceprog.c @@ -175,7 +175,6 @@ enum flash_cmd { FC_EPR = 0x7A, /* Erase / Program Resume */ FC_PD = 0xB9, /* Power-down */ FC_QPI = 0x38, /* Enter QPI mode */ - FC_EQPI = 0xFF, /* Exit QPI mode */ FC_ERESET = 0x66, /* Enable Reset */ FC_RESET = 0x99, /* Reset Device */ }; @@ -270,6 +269,19 @@ static void xfer_spi(uint8_t *data, int n) data[i] = recv_byte(); } +static uint8_t xfer_spi_bits(uint8_t data, int n) +{ + if (n < 1) + return 0; + + /* Input and output, update data on negative edge read on positive, bits. */ + send_byte(MC_DATA_IN | MC_DATA_OUT | MC_DATA_OCN | MC_DATA_BITS); + send_byte(n - 1); + send_byte(data); + + return recv_byte(); +} + static void set_gpio(int slavesel_b, int creset_b) { uint8_t gpio = 0; @@ -381,14 +393,12 @@ static void flash_read_id() static void flash_reset() { - uint8_t data_eqpi[1] = { FC_EQPI }; - flash_chip_select(); - xfer_spi(data_eqpi, 1); + xfer_spi_bits(0xFF, 8); flash_chip_deselect(); flash_chip_select(); - xfer_spi(data_eqpi, 1); + xfer_spi_bits(0xFF, 2); flash_chip_deselect(); } -- cgit v1.2.3