mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
programmer: Smoothen register_spi_master() API
It was impossible to register a const struct spi_master that would point to dynamically allocated `data`. Fix that so that we won't have to create more mutable globals. Change-Id: I0c753b3db050fb87d4bbe2301a7ead854f28456f Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/flashrom/+/54066 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
parent
c117378478
commit
7e4968525d
@ -162,7 +162,7 @@ int register_spi_bitbang_master(const struct bitbang_spi_master *master)
|
||||
struct bitbang_spi_master_data *data = calloc(1, sizeof(struct bitbang_spi_master_data));
|
||||
data->mst = master;
|
||||
mst.data = data;
|
||||
register_spi_master(&mst);
|
||||
register_spi_master(&mst, NULL);
|
||||
register_shutdown(bitbang_spi_shutdown, data);
|
||||
|
||||
/* Only mess with the bus if we're sure nobody else uses it. */
|
||||
|
@ -655,7 +655,7 @@ int buspirate_spi_init(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
register_spi_master(&spi_master_buspirate);
|
||||
register_spi_master(&spi_master_buspirate, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ int ch341a_spi_init(void)
|
||||
goto dealloc_transfers;
|
||||
|
||||
register_shutdown(ch341a_spi_shutdown, NULL);
|
||||
register_spi_master(&spi_master_ch341a_spi);
|
||||
register_spi_master(&spi_master_ch341a_spi, NULL);
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -1274,7 +1274,7 @@ int dediprog_init(void)
|
||||
if (protocol() >= PROTOCOL_V2)
|
||||
spi_master_dediprog.features |= SPI_MASTER_4BA;
|
||||
|
||||
if (register_spi_master(&spi_master_dediprog) || dediprog_set_leds(LED_NONE))
|
||||
if (register_spi_master(&spi_master_dediprog, NULL) || dediprog_set_leds(LED_NONE))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -457,7 +457,7 @@ int digilent_spi_init(void)
|
||||
spi_master_digilent_spi.data = digilent_data;
|
||||
|
||||
register_shutdown(digilent_spi_shutdown, digilent_data);
|
||||
register_spi_master(&spi_master_digilent_spi);
|
||||
register_spi_master(&spi_master_digilent_spi, NULL);
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -1030,7 +1030,7 @@ dummy_init_out:
|
||||
register_par_master(&par_master_dummy,
|
||||
dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH));
|
||||
if (dummy_buses_supported & BUS_SPI)
|
||||
register_spi_master(&spi_master_dummyflasher);
|
||||
register_spi_master(&spi_master_dummyflasher, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ int ene_lpc_init()
|
||||
|
||||
if (register_shutdown(ene_leave_flash_mode, ctx_data))
|
||||
goto init_err_cleanup_exit;
|
||||
register_spi_master(&spi_master_ene);
|
||||
register_spi_master(&spi_master_ene, NULL);
|
||||
msg_pdbg("%s: successfully initialized ene\n", __func__);
|
||||
|
||||
return 0;
|
||||
|
@ -626,7 +626,7 @@ int ft2232_spi_init(void)
|
||||
free(spi_data);
|
||||
goto ftdi_err;
|
||||
}
|
||||
register_spi_master(&spi_master_ft2232);
|
||||
register_spi_master(&spi_master_ft2232, NULL);
|
||||
|
||||
return 0;
|
||||
|
||||
|
6
ichspi.c
6
ichspi.c
@ -1812,7 +1812,7 @@ int ich_init_spi(void *spibar, enum ich_chipset ich_gen)
|
||||
}
|
||||
ich_init_opcodes(ich_gen);
|
||||
ich_set_bbar(0, ich_gen);
|
||||
register_spi_master(&spi_master_ich7);
|
||||
register_spi_master(&spi_master_ich7, NULL);
|
||||
break;
|
||||
case CHIPSET_ICH8:
|
||||
default: /* Future version might behave the same */
|
||||
@ -2041,7 +2041,7 @@ int ich_init_spi(void *spibar, enum ich_chipset ich_gen)
|
||||
|
||||
register_opaque_master(&opaque_master_ich_hwseq);
|
||||
} else {
|
||||
register_spi_master(&spi_master_ich9);
|
||||
register_spi_master(&spi_master_ich9, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2071,7 +2071,7 @@ int via_init_spi(uint32_t mmio_base)
|
||||
/* Not sure if it speaks all these bus protocols. */
|
||||
internal_buses_supported &= BUS_LPC | BUS_FWH;
|
||||
ich_generation = CHIPSET_ICH7;
|
||||
register_spi_master(&spi_master_via);
|
||||
register_spi_master(&spi_master_via, NULL);
|
||||
|
||||
msg_pdbg("0x00: 0x%04x (SPIS)\n", mmio_readw(ich_spibar + 0));
|
||||
msg_pdbg("0x02: 0x%04x (SPIC)\n", mmio_readw(ich_spibar + 2));
|
||||
|
@ -366,7 +366,7 @@ int it85xx_spi_init(struct superio s)
|
||||
* a debug message about it.
|
||||
*/
|
||||
/* Set this as SPI controller. */
|
||||
register_spi_master(&spi_master_it85xx);
|
||||
register_spi_master(&spi_master_it85xx, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ static uint16_t it87spi_probe(uint16_t port)
|
||||
if (internal_buses_supported & BUS_SPI)
|
||||
msg_pdbg("Overriding chipset SPI with IT87 SPI.\n");
|
||||
/* FIXME: Add the SPI bus or replace the other buses with it? */
|
||||
register_spi_master(&spi_master_it87xx);
|
||||
register_spi_master(&spi_master_it87xx, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ int jlink_spi_init(void)
|
||||
|
||||
if (register_shutdown(jlink_spi_shutdown, jlink_data))
|
||||
goto init_err;
|
||||
register_spi_master(&spi_master_jlink_spi);
|
||||
register_spi_master(&spi_master_jlink_spi, NULL);
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -244,7 +244,7 @@ int linux_spi_init(void)
|
||||
free(spi_data);
|
||||
goto init_err;
|
||||
}
|
||||
register_spi_master(&spi_master_linux);
|
||||
register_spi_master(&spi_master_linux, NULL);
|
||||
return 0;
|
||||
|
||||
init_err:
|
||||
|
@ -457,7 +457,7 @@ int lspcon_i2c_spi_init(void)
|
||||
spi_master_i2c_lspcon.data = data;
|
||||
|
||||
ret |= register_shutdown(lspcon_i2c_spi_shutdown, data);
|
||||
ret |= register_spi_master(&spi_master_i2c_lspcon);
|
||||
ret |= register_spi_master(&spi_master_i2c_lspcon, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ int mec1308_init(void)
|
||||
|
||||
if (register_shutdown(mec1308_shutdown, ctx_data))
|
||||
goto init_err_cleanup_exit;
|
||||
register_spi_master(&spi_master_mec1308);
|
||||
register_spi_master(&spi_master_mec1308, NULL);
|
||||
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);
|
||||
|
||||
return 0;
|
||||
|
@ -221,7 +221,7 @@ int mstarddc_spi_init(void)
|
||||
register_shutdown(mstarddc_spi_shutdown, NULL);
|
||||
|
||||
// Register programmer
|
||||
register_spi_master(&spi_master_mstarddc);
|
||||
register_spi_master(&spi_master_mstarddc, NULL);
|
||||
out:
|
||||
free(i2c_device);
|
||||
return ret;
|
||||
|
@ -630,7 +630,7 @@ int ni845x_spi_init(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
register_spi_master(&spi_programmer_ni845x);
|
||||
register_spi_master(&spi_programmer_ni845x, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ int pickit2_spi_init(void)
|
||||
|
||||
if (register_shutdown(pickit2_shutdown, pickit2_data))
|
||||
goto init_err_cleanup_exit;
|
||||
register_spi_master(&spi_master_pickit2);
|
||||
register_spi_master(&spi_master_pickit2, NULL);
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -643,7 +643,7 @@ int default_spi_send_multicommand(const struct flashctx *flash, struct spi_comma
|
||||
int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
|
||||
int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
|
||||
int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
|
||||
int register_spi_master(const struct spi_master *mst);
|
||||
int register_spi_master(const struct spi_master *mst, void *data);
|
||||
|
||||
/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
|
||||
enum ich_chipset {
|
||||
|
@ -1614,7 +1614,7 @@ loop_end:
|
||||
return SPI_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
register_spi_master(spi_config);
|
||||
register_spi_master(spi_config, NULL);
|
||||
register_shutdown(raiden_debug_spi_shutdown, spi_config);
|
||||
|
||||
return 0;
|
||||
|
@ -515,7 +515,7 @@ int realtek_mst_i2c_spi_init(void)
|
||||
ret |= register_shutdown(realtek_mst_i2c_spi_shutdown, data);
|
||||
|
||||
spi_master_i2c_realtek_mst.data = data;
|
||||
ret |= register_spi_master(&spi_master_i2c_realtek_mst);
|
||||
ret |= register_spi_master(&spi_master_i2c_realtek_mst, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -786,11 +786,11 @@ int sb600_probe_spi(struct pci_dev *dev)
|
||||
|
||||
/* Starting with Yangtze the SPI controller got a different interface with a much bigger buffer. */
|
||||
if (amd_gen < CHIPSET_YANGTZE)
|
||||
register_spi_master(&spi_master_sb600);
|
||||
register_spi_master(&spi_master_sb600, NULL);
|
||||
else if (amd_gen == CHIPSET_YANGTZE)
|
||||
register_spi_master(&spi_master_yangtze);
|
||||
register_spi_master(&spi_master_yangtze, NULL);
|
||||
else
|
||||
register_spi_master(&spi_master_promontory);
|
||||
register_spi_master(&spi_master_promontory, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -883,7 +883,7 @@ int serprog_init(void)
|
||||
sp_streamed_transmit_bytes = 0;
|
||||
sp_opbuf_usage = 0;
|
||||
if (serprog_buses_supported & BUS_SPI)
|
||||
register_spi_master(&spi_master_serprog);
|
||||
register_spi_master(&spi_master_serprog, NULL);
|
||||
if (serprog_buses_supported & BUS_NONSPI)
|
||||
register_par_master(&par_master_serprog, serprog_buses_supported & BUS_NONSPI);
|
||||
return 0;
|
||||
|
4
spi.c
4
spi.c
@ -131,7 +131,7 @@ int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start
|
||||
return flash->mst->spi.write_aai(flash, buf, start, len);
|
||||
}
|
||||
|
||||
int register_spi_master(const struct spi_master *mst)
|
||||
int register_spi_master(const struct spi_master *mst, void *data)
|
||||
{
|
||||
struct registered_master rmst = {0};
|
||||
|
||||
@ -148,5 +148,7 @@ int register_spi_master(const struct spi_master *mst)
|
||||
|
||||
rmst.buses_supported = BUS_SPI;
|
||||
rmst.spi = *mst;
|
||||
if (data)
|
||||
rmst.spi.data = data;
|
||||
return register_master(&rmst);
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ int stlinkv3_spi_init(void)
|
||||
if (register_shutdown(stlinkv3_spi_shutdown, NULL))
|
||||
goto err_exit;
|
||||
|
||||
if (register_spi_master(&spi_programmer_stlinkv3))
|
||||
if (register_spi_master(&spi_programmer_stlinkv3, NULL))
|
||||
goto err_exit;
|
||||
|
||||
return 0;
|
||||
|
@ -232,7 +232,7 @@ int usbblaster_spi_init(void)
|
||||
free(usbblaster_data);
|
||||
return -1;
|
||||
}
|
||||
register_spi_master(&spi_master_usbblaster);
|
||||
register_spi_master(&spi_master_usbblaster, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ int wbsio_check_for_spi(void)
|
||||
|
||||
register_shutdown(wbsio_spi_shutdown, data);
|
||||
spi_master_wbsio.data = data;
|
||||
register_spi_master(&spi_master_wbsio);
|
||||
register_spi_master(&spi_master_wbsio, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user