From 119d0e5236df69702c5ac5be593c4aa683e2b35d Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Fri, 9 Sep 2022 23:14:06 +1000 Subject: spi: Make 'default_spi_send_multicommand' the default unless defined A NULL func pointer is necessary and sufficient for the condition `NULL func pointer => default_spi_send_multicommand' as to not need this explicit specification of 'default'. Therefore drop the explicit need to specify the 'default_spi_send_multicommand' callback function pointer in the spi_master struct. This is a reasonable default for every other driver in the tree with only a few exceptions. This simplifies the code and driver development. Change-Id: I6cc24bf982da3d5251d391eb397db43dd10280e8 Signed-off-by: Edward O'Callaghan Reviewed-on: https://review.coreboot.org/c/flashrom/+/67481 Tested-by: build bot (Jenkins) Reviewed-by: Thomas Heijligen --- asm106x.c | 1 - bitbang_spi.c | 1 - buspirate_spi.c | 1 - ch341a_spi.c | 1 - ch347_spi.c | 1 - dediprog.c | 1 - digilent_spi.c | 1 - dirtyjtag_spi.c | 1 - dummyflasher.c | 1 - it87spi.c | 1 - jlink_spi.c | 1 - linux_spi.c | 1 - mediatek_i2c_spi.c | 1 - mstarddc_spi.c | 1 - ni845x_spi.c | 1 - parade_lspcon.c | 1 - pickit2_spi.c | 1 - raiden_debug_spi.c | 1 - realtek_mst_i2c_spi.c | 1 - sb600spi.c | 3 --- serprog.c | 1 - spi.c | 9 +++++---- stlinkv3_spi.c | 1 - usbblaster_spi.c | 1 - wbsio_spi.c | 1 - 25 files changed, 5 insertions(+), 30 deletions(-) diff --git a/asm106x.c b/asm106x.c index fe35f94d..78c0b74c 100644 --- a/asm106x.c +++ b/asm106x.c @@ -123,7 +123,6 @@ static const struct spi_master asm106x_spi_master = { .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = asm106x_command, .shutdown = asm106x_shutdown, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .probe_opcode = default_spi_probe_opcode, diff --git a/bitbang_spi.c b/bitbang_spi.c index 7919e45d..6488650c 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -143,7 +143,6 @@ static const struct spi_master spi_master_bitbang = { .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = bitbang_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = bitbang_spi_shutdown, diff --git a/buspirate_spi.c b/buspirate_spi.c index a40fb708..192d2743 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -178,7 +178,6 @@ static struct spi_master spi_master_buspirate = { .max_data_read = MAX_DATA_UNSPECIFIED, .max_data_write = MAX_DATA_UNSPECIFIED, .command = NULL, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = buspirate_spi_shutdown, diff --git a/ch341a_spi.c b/ch341a_spi.c index 75eaf869..b9be18e5 100644 --- a/ch341a_spi.c +++ b/ch341a_spi.c @@ -413,7 +413,6 @@ static const struct spi_master spi_master_ch341a_spi = { .max_data_read = 4 * 1024, .max_data_write = 4 * 1024, .command = ch341a_spi_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = ch341a_spi_shutdown, diff --git a/ch347_spi.c b/ch347_spi.c index c3326b0c..e828f008 100644 --- a/ch347_spi.c +++ b/ch347_spi.c @@ -253,7 +253,6 @@ static const struct spi_master spi_master_ch347_spi = { .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = ch347_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .write_aai = default_spi_write_aai, diff --git a/dediprog.c b/dediprog.c index 723f4a80..60ce6e6e 100644 --- a/dediprog.c +++ b/dediprog.c @@ -1034,7 +1034,6 @@ static struct spi_master spi_master_dediprog = { .max_data_read = 16, /* 18 seems to work fine as well, but 19 times out sometimes with FW 5.15. */ .max_data_write = 16, .command = dediprog_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = dediprog_spi_read, .write_256 = dediprog_spi_write_256, .write_aai = dediprog_spi_write_aai, diff --git a/digilent_spi.c b/digilent_spi.c index 55cb6ecd..5fa60b92 100644 --- a/digilent_spi.c +++ b/digilent_spi.c @@ -333,7 +333,6 @@ static const struct spi_master spi_master_digilent_spi = { .max_data_read = 252, .max_data_write = 252, .command = digilent_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = digilent_spi_shutdown, diff --git a/dirtyjtag_spi.c b/dirtyjtag_spi.c index 42169ed2..9f0e43bf 100644 --- a/dirtyjtag_spi.c +++ b/dirtyjtag_spi.c @@ -193,7 +193,6 @@ static const struct spi_master spi_master_dirtyjtag_spi = { .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = dirtyjtag_spi_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .write_aai = default_spi_write_aai, diff --git a/dummyflasher.c b/dummyflasher.c index 08973327..a68889b2 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -939,7 +939,6 @@ static const struct spi_master spi_master_dummyflasher = { .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = MAX_DATA_UNSPECIFIED, .command = dummy_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = dummy_spi_write_256, .shutdown = dummy_shutdown, diff --git a/it87spi.c b/it87spi.c index 34dbea08..b2da8751 100644 --- a/it87spi.c +++ b/it87spi.c @@ -314,7 +314,6 @@ static const struct spi_master spi_master_it87xx = { .max_data_read = 3, .max_data_write = MAX_DATA_UNSPECIFIED, .command = it8716f_spi_send_command, - .multicommand = default_spi_send_multicommand, .map_flash_region = physmap, .unmap_flash_region = physunmap, .read = it8716f_spi_chip_read, diff --git a/jlink_spi.c b/jlink_spi.c index ad2ca789..7743c40b 100644 --- a/jlink_spi.c +++ b/jlink_spi.c @@ -184,7 +184,6 @@ static const struct spi_master spi_master_jlink_spi = { /* Maximum data write size in one go (excluding opcode+address). */ .max_data_write = JTAG_MAX_TRANSFER_SIZE - 5, .command = jlink_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .features = SPI_MASTER_4BA, diff --git a/linux_spi.c b/linux_spi.c index d65b3e89..d849fe4b 100644 --- a/linux_spi.c +++ b/linux_spi.c @@ -116,7 +116,6 @@ static const struct spi_master spi_master_linux = { .max_data_read = MAX_DATA_UNSPECIFIED, /* TODO? */ .max_data_write = MAX_DATA_UNSPECIFIED, /* TODO? */ .command = linux_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = linux_spi_read, .write_256 = linux_spi_write_256, .shutdown = linux_spi_shutdown, diff --git a/mediatek_i2c_spi.c b/mediatek_i2c_spi.c index c15df056..e9c3c8c8 100644 --- a/mediatek_i2c_spi.c +++ b/mediatek_i2c_spi.c @@ -456,7 +456,6 @@ static const struct spi_master spi_master_i2c_mediatek = { // Leave room for 1-byte command and up to a 4-byte address. .max_data_write = I2C_SMBUS_BLOCK_MAX - 5, .command = mediatek_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = mediatek_shutdown, diff --git a/mstarddc_spi.c b/mstarddc_spi.c index bd652814..1172cb20 100644 --- a/mstarddc_spi.c +++ b/mstarddc_spi.c @@ -142,7 +142,6 @@ static const struct spi_master spi_master_mstarddc = { .max_data_read = 256, .max_data_write = 256, .command = mstarddc_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = mstarddc_spi_shutdown, diff --git a/ni845x_spi.c b/ni845x_spi.c index fd5057dd..dec6f6f3 100644 --- a/ni845x_spi.c +++ b/ni845x_spi.c @@ -532,7 +532,6 @@ static const struct spi_master spi_programmer_ni845x = { .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = ni845x_spi_transmit, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = ni845x_spi_shutdown, diff --git a/parade_lspcon.c b/parade_lspcon.c index a50346e7..8b927893 100644 --- a/parade_lspcon.c +++ b/parade_lspcon.c @@ -432,7 +432,6 @@ static const struct spi_master spi_master_parade_lspcon = { .max_data_read = 16, .max_data_write = 12, .command = parade_lspcon_send_command, - .multicommand = default_spi_send_multicommand, .read = parade_lspcon_read, .write_256 = parade_lspcon_write_256, .write_aai = parade_lspcon_write_aai, diff --git a/pickit2_spi.c b/pickit2_spi.c index 86c54036..56894d9a 100644 --- a/pickit2_spi.c +++ b/pickit2_spi.c @@ -380,7 +380,6 @@ static const struct spi_master spi_master_pickit2 = { .max_data_read = 40, .max_data_write = 40, .command = pickit2_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = pickit2_shutdown, diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c index d1a09d7a..5111ae98 100644 --- a/raiden_debug_spi.c +++ b/raiden_debug_spi.c @@ -1320,7 +1320,6 @@ static const struct spi_master spi_master_raiden_debug = { .max_data_read = 0, .max_data_write = 0, .command = NULL, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = raiden_debug_spi_shutdown, diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c index 2a5d5ed6..ee6390c4 100644 --- a/realtek_mst_i2c_spi.c +++ b/realtek_mst_i2c_spi.c @@ -436,7 +436,6 @@ static const struct spi_master spi_master_i2c_realtek_mst = { .max_data_read = 16, .max_data_write = 8, .command = realtek_mst_i2c_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = realtek_mst_i2c_spi_read, .write_256 = realtek_mst_i2c_spi_write_256, .write_aai = realtek_mst_i2c_spi_write_aai, diff --git a/sb600spi.c b/sb600spi.c index 5b9ac45c..2e6c2eca 100644 --- a/sb600spi.c +++ b/sb600spi.c @@ -599,7 +599,6 @@ static const struct spi_master spi_master_sb600 = { .max_data_read = FIFO_SIZE_OLD, .max_data_write = FIFO_SIZE_OLD - 3, .command = sb600_spi_send_command, - .multicommand = default_spi_send_multicommand, .map_flash_region = physmap, .unmap_flash_region = physunmap, .read = default_spi_read, @@ -612,7 +611,6 @@ static const struct spi_master spi_master_yangtze = { .max_data_read = FIFO_SIZE_YANGTZE - 3, /* Apparently the big SPI 100 buffer is not a ring buffer. */ .max_data_write = FIFO_SIZE_YANGTZE - 3, .command = spi100_spi_send_command, - .multicommand = default_spi_send_multicommand, .map_flash_region = physmap, .unmap_flash_region = physunmap, .read = default_spi_read, @@ -625,7 +623,6 @@ static const struct spi_master spi_master_promontory = { .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = FIFO_SIZE_YANGTZE - 3, .command = spi100_spi_send_command, - .multicommand = default_spi_send_multicommand, .map_flash_region = physmap, .unmap_flash_region = physunmap, .read = promontory_read_memmapped, diff --git a/serprog.c b/serprog.c index 5ddbe3d6..4d93e075 100644 --- a/serprog.c +++ b/serprog.c @@ -461,7 +461,6 @@ static struct spi_master spi_master_serprog = { .max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = serprog_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .probe_opcode = default_spi_probe_opcode, diff --git a/spi.c b/spi.c index ca27cbb1..4fe0fa5c 100644 --- a/spi.c +++ b/spi.c @@ -37,7 +37,9 @@ int spi_send_command(const struct flashctx *flash, unsigned int writecnt, int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds) { - return flash->mst->spi.multicommand(flash, cmds); + if (flash->mst->spi.multicommand) + return flash->mst->spi.multicommand(flash, cmds); + return default_spi_send_multicommand(flash, cmds); } int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, @@ -153,10 +155,9 @@ int register_spi_master(const struct spi_master *mst, void *data) } } - if (!mst->write_256 || !mst->read || - !mst->multicommand || !mst->probe_opcode || + if (!mst->write_256 || !mst->read || !mst->probe_opcode || ((mst->command == default_spi_send_command || !mst->command) && - (mst->multicommand == default_spi_send_multicommand))) { + (mst->multicommand == default_spi_send_multicommand || !mst->multicommand))) { msg_perr("%s called with incomplete master definition. " "Please report a bug at flashrom@flashrom.org\n", __func__); diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c index 16a66b47..726cdcfd 100644 --- a/stlinkv3_spi.c +++ b/stlinkv3_spi.c @@ -466,7 +466,6 @@ static const struct spi_master spi_programmer_stlinkv3 = { .max_data_read = UINT16_MAX, .max_data_write = UINT16_MAX, .command = stlinkv3_spi_transmit, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = stlinkv3_spi_shutdown, diff --git a/usbblaster_spi.c b/usbblaster_spi.c index 75d5be73..958d4ea5 100644 --- a/usbblaster_spi.c +++ b/usbblaster_spi.c @@ -168,7 +168,6 @@ static const struct spi_master spi_master_usbblaster = { .max_data_read = 256, .max_data_write = 256, .command = usbblaster_spi_send_command, - .multicommand = default_spi_send_multicommand, .read = default_spi_read, .write_256 = default_spi_write_256, .shutdown = usbblaster_shutdown, diff --git a/wbsio_spi.c b/wbsio_spi.c index d635a09e..ee79ef2a 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -186,7 +186,6 @@ static const struct spi_master spi_master_wbsio = { .max_data_read = MAX_DATA_UNSPECIFIED, .max_data_write = MAX_DATA_UNSPECIFIED, .command = wbsio_spi_send_command, - .multicommand = default_spi_send_multicommand, .map_flash_region = physmap, .unmap_flash_region = physunmap, .read = wbsio_spi_read, -- cgit v1.2.3