summaryrefslogtreecommitdiffstats
path: root/usbblaster_spi.c
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2021-03-23 16:34:07 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2021-04-01 01:17:48 +0000
commite704583ad53b24e1b39aa7a2e5077fa95d5f9244 (patch)
treed30504f5ac4310850372b124c33447b8f8ce3176 /usbblaster_spi.c
parent6d79a6ab808463f6895a9665858ff8b220d5118b (diff)
downloadflashrom-e704583ad53b24e1b39aa7a2e5077fa95d5f9244.tar.gz
flashrom-e704583ad53b24e1b39aa7a2e5077fa95d5f9244.tar.bz2
flashrom-e704583ad53b24e1b39aa7a2e5077fa95d5f9244.zip
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 <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/51731 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'usbblaster_spi.c')
-rw-r--r--usbblaster_spi.c91
1 files changed, 44 insertions, 47 deletions
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