From 62175a094dcb74dc4845cd091be5100b6b4ec5d7 Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Sat, 17 Jul 2010 23:27:47 +0000 Subject: Use struct pointer instead of enum to set bitbang adapter Corresponding to flashrom svn r1091. Signed-off-by: Michael Karcher Acked-by: Carl-Daniel Hailfinger --- bitbang_spi.c | 23 ++++++----------------- flash.h | 11 ++++++----- flashrom.c | 6 ------ 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/bitbang_spi.c b/bitbang_spi.c index b543fd4..9f0e878 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -29,45 +29,34 @@ /* Length of half a clock period in usecs. */ static int bitbang_spi_half_period; -static enum bitbang_spi_master bitbang_spi_master = BITBANG_SPI_INVALID; - -static const struct bitbang_spi_master_entry bitbang_spi_master_table[] = { - {}, /* This entry corresponds to BITBANG_SPI_INVALID. */ -}; - -const int bitbang_spi_master_count = ARRAY_SIZE(bitbang_spi_master_table); +static const struct bitbang_spi_master *bitbang_spi_master = NULL; /* Note that CS# is active low, so val=0 means the chip is active. */ static void bitbang_spi_set_cs(int val) { - bitbang_spi_master_table[bitbang_spi_master].set_cs(val); + bitbang_spi_master->set_cs(val); } static void bitbang_spi_set_sck(int val) { - bitbang_spi_master_table[bitbang_spi_master].set_sck(val); + bitbang_spi_master->set_sck(val); } static void bitbang_spi_set_mosi(int val) { - bitbang_spi_master_table[bitbang_spi_master].set_mosi(val); + bitbang_spi_master->set_mosi(val); } static int bitbang_spi_get_miso(void) { - return bitbang_spi_master_table[bitbang_spi_master].get_miso(); + return bitbang_spi_master->get_miso(); } -int bitbang_spi_init(enum bitbang_spi_master master, int halfperiod) +int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod) { bitbang_spi_master = master; bitbang_spi_half_period = halfperiod; - if (bitbang_spi_master == BITBANG_SPI_INVALID) { - msg_perr("Invalid bitbang SPI master. \n" - "Please report a bug at flashrom@flashrom.org\n"); - return 1; - } bitbang_spi_set_cs(1); bitbang_spi_set_sck(0); bitbang_spi_set_mosi(0); diff --git a/flash.h b/flash.h index c858eba..c3302c4 100644 --- a/flash.h +++ b/flash.h @@ -127,13 +127,14 @@ uint32_t chip_readl(const chipaddr addr); void chip_readn(uint8_t *buf, const chipaddr addr, size_t len); void programmer_delay(int usecs); -enum bitbang_spi_master { - BITBANG_SPI_INVALID /* This must always be the last entry. */ +enum bitbang_spi_master_type { + BITBANG_SPI_DUMMY /* remove as soon as there is a real entry */ }; -extern const int bitbang_spi_master_count; +struct bitbang_spi_master { + enum bitbang_spi_master_type type; -struct bitbang_spi_master_entry { + /* Note that CS# is active low, so val=0 means the chip is active. */ void (*set_cs) (int val); void (*set_sck) (int val); void (*set_mosi) (int val); @@ -531,7 +532,7 @@ int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); /* bitbang_spi.c */ -int bitbang_spi_init(enum bitbang_spi_master master, int halfperiod); +int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod); int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); diff --git a/flashrom.c b/flashrom.c index 2118bec..fe173a7 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1358,12 +1358,6 @@ int selfcheck(void) msg_gerr("SPI programmer table miscompilation!\n"); ret = 1; } -#if CONFIG_BITBANG_SPI == 1 - if (bitbang_spi_master_count - 1 != BITBANG_SPI_INVALID) { - msg_gerr("Bitbanging SPI master table miscompilation!\n"); - ret = 1; - } -#endif for (flash = flashchips; flash && flash->name; flash++) if (selfcheck_eraseblocks(flash)) ret = 1; -- cgit v1.1