Xiang Wang has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/49264 )
Change subject: bitbang_spi.c: fix spi sequence in time ......................................................................
bitbang_spi.c: fix spi sequence in time
SPI write operation requires the change of mosi before the change of sck. For this reason, the interface set_sck_set_mosi was rename to set_mosi_set_sck. And the sequence in time bug was corrected.
Change-Id: I107803afef044996c94ebfaf0b0e0040cea9f8c1 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M bitbang_spi.c M developerbox_spi.c M programmer.h 3 files changed, 9 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/64/49264/1
diff --git a/bitbang_spi.c b/bitbang_spi.c index 7b69946..c5b2cd0 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -65,15 +65,15 @@ master->release_bus(); }
-static void bitbang_spi_set_sck_set_mosi(const struct bitbang_spi_master * const master, int sck, int mosi) +static void bitbang_spi_set_mosi_set_sck(const struct bitbang_spi_master * const master, int mosi, int sck) { - if (master->set_sck_set_mosi) { - master->set_sck_set_mosi(sck, mosi); + if (master->set_mosi_set_sck) { + master->set_mosi_set_sck(mosi, sck); return; }
- master->set_sck(sck); master->set_mosi(mosi); + master->set_sck(sck); }
static int bitbang_spi_set_sck_get_miso(const struct bitbang_spi_master * const master, int sck) @@ -115,11 +115,11 @@ if (cpha) { bitbang_spi_set_sck(master, !cpol); programmer_delay(master->half_period); - bitbang_spi_set_sck_set_mosi(master, cpol, (val >> i) & 1); + bitbang_spi_set_mosi_set_sck(master, (val >> i) & 1, cpol); programmer_delay(master->half_period); } else { programmer_delay(master->half_period); - bitbang_spi_set_sck_set_mosi(master, !cpol, (val >> i) & 1); + bitbang_spi_set_mosi_set_sck(master, (val >> i) & 1, !cpol); programmer_delay(master->half_period); bitbang_spi_set_sck(master, cpol); } diff --git a/developerbox_spi.c b/developerbox_spi.c index 4ff2fb6..03baba9 100644 --- a/developerbox_spi.c +++ b/developerbox_spi.c @@ -114,7 +114,7 @@ return !!(cp210x_gpio_get() & (1 << DEVELOPERBOX_SPI_MISO)); }
-static void cp210x_bitbang_set_sck_set_mosi(int sck, int mosi) +static void cp210x_bitbang_set_mosi_set_sck(int mosi, int sck) { cp210x_gpio_set(sck << DEVELOPERBOX_SPI_SCK | mosi << DEVELOPERBOX_SPI_MOSI, 1 << DEVELOPERBOX_SPI_SCK | 1 << DEVELOPERBOX_SPI_MOSI); @@ -125,7 +125,7 @@ .set_sck = cp210x_bitbang_set_sck, .set_mosi = cp210x_bitbang_set_mosi, .get_miso = cp210x_bitbang_get_miso, - .set_sck_set_mosi = cp210x_bitbang_set_sck_set_mosi, + .set_mosi_set_sck = cp210x_bitbang_set_mosi_set_sck, };
static int developerbox_spi_shutdown(void *data) diff --git a/programmer.h b/programmer.h index 5dbbaf9..aea1419 100644 --- a/programmer.h +++ b/programmer.h @@ -192,7 +192,7 @@ void (*request_bus) (void); void (*release_bus) (void); /* optional functions to optimize xfers */ - void (*set_sck_set_mosi) (int sck, int mosi); + void (*set_mosi_set_sck) (int mosi, int sck); int (*set_sck_get_miso) (int sck); /* Length of half a clock period in usecs. */ unsigned int half_period;