1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

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 <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/67481
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
This commit is contained in:
Edward O'Callaghan 2022-09-09 23:14:06 +10:00 committed by Thomas Heijligen
parent 263d50c7d1
commit 119d0e5236
25 changed files with 5 additions and 30 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

9
spi.c
View File

@ -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__);

View File

@ -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,

View File

@ -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,

View File

@ -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,