From e704583ad53b24e1b39aa7a2e5077fa95d5f9244 Mon Sep 17 00:00:00 2001 From: Anastasia Klimchuk Date: Tue, 23 Mar 2021 16:34:07 +1100 Subject: tree: Remove forward-declarations of structs for spi masters Reorder functions to avoid forward-declarations of structs. Similar thing was done earlier for functions declarations, this patch takes care of structs declarations. BUG=b:140394053 TEST=builds objdump -d is identical objdump -s only difference is version number Change-Id: I256bd7c763efc010fc1f29f7c5853f150ac10739 Signed-off-by: Anastasia Klimchuk Reviewed-on: https://review.coreboot.org/c/flashrom/+/51731 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber Reviewed-by: Edward O'Callaghan --- usbblaster_spi.c | 91 +++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 47 deletions(-) (limited to 'usbblaster_spi.c') diff --git a/usbblaster_spi.c b/usbblaster_spi.c index 58a8a0e3d..020c3bf50 100644 --- a/usbblaster_spi.c +++ b/usbblaster_spi.c @@ -51,8 +51,6 @@ const struct dev_entry devs_usbblasterspi[] = { {0} }; -static const struct spi_master spi_master_usbblaster; - static struct ftdi_context ftdic; // command bytes @@ -72,51 +70,6 @@ static uint8_t reverse(uint8_t b) return ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16; } - -/* Returns 0 upon success, a negative number upon errors. */ -int usbblaster_spi_init(void) -{ - uint8_t buf[BUF_SIZE + 1]; - - if (ftdi_init(&ftdic) < 0) - return -1; - - if (ftdi_usb_open(&ftdic, ALTERA_VID, ALTERA_USBBLASTER_PID) < 0) { - msg_perr("Failed to open USB-Blaster: %s\n", ftdic.error_str); - return -1; - } - - if (ftdi_usb_reset(&ftdic) < 0) { - msg_perr("USB-Blaster reset failed\n"); - return -1; - } - - if (ftdi_set_latency_timer(&ftdic, 2) < 0) { - msg_perr("USB-Blaster set latency timer failed\n"); - return -1; - } - - if (ftdi_write_data_set_chunksize(&ftdic, 4096) < 0 || - ftdi_read_data_set_chunksize(&ftdic, BUF_SIZE) < 0) { - msg_perr("USB-Blaster set chunk size failed\n"); - return -1; - } - - memset(buf, 0, sizeof(buf)); - buf[sizeof(buf)-1] = BIT_LED | BIT_CS; - if (ftdi_write_data(&ftdic, buf, sizeof(buf)) < 0) { - msg_perr("USB-Blaster reset write failed\n"); - return -1; - } - if (ftdi_read_data(&ftdic, buf, sizeof(buf)) < 0) { - msg_perr("USB-Blaster reset read failed\n"); - return -1; - } - - register_spi_master(&spi_master_usbblaster); - return 0; -} - static int send_write(unsigned int writecnt, const unsigned char *writearr) { uint8_t buf[BUF_SIZE]; @@ -217,4 +170,48 @@ static const struct spi_master spi_master_usbblaster = { .write_aai = default_spi_write_aai, }; +/* Returns 0 upon success, a negative number upon errors. */ +int usbblaster_spi_init(void) +{ + uint8_t buf[BUF_SIZE + 1]; + + if (ftdi_init(&ftdic) < 0) + return -1; + + if (ftdi_usb_open(&ftdic, ALTERA_VID, ALTERA_USBBLASTER_PID) < 0) { + msg_perr("Failed to open USB-Blaster: %s\n", ftdic.error_str); + return -1; + } + + if (ftdi_usb_reset(&ftdic) < 0) { + msg_perr("USB-Blaster reset failed\n"); + return -1; + } + + if (ftdi_set_latency_timer(&ftdic, 2) < 0) { + msg_perr("USB-Blaster set latency timer failed\n"); + return -1; + } + + if (ftdi_write_data_set_chunksize(&ftdic, 4096) < 0 || + ftdi_read_data_set_chunksize(&ftdic, BUF_SIZE) < 0) { + msg_perr("USB-Blaster set chunk size failed\n"); + return -1; + } + + memset(buf, 0, sizeof(buf)); + buf[sizeof(buf)-1] = BIT_LED | BIT_CS; + if (ftdi_write_data(&ftdic, buf, sizeof(buf)) < 0) { + msg_perr("USB-Blaster reset write failed\n"); + return -1; + } + if (ftdi_read_data(&ftdic, buf, sizeof(buf)) < 0) { + msg_perr("USB-Blaster reset read failed\n"); + return -1; + } + + register_spi_master(&spi_master_usbblaster); + return 0; +} + #endif -- cgit v1.2.3