aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2021-05-11 17:38:14 +0200
committerNico Huber <nico.h@gmx.de>2021-05-13 14:37:29 +0000
commit7e4968525d37d87e8b6f8b848e4f2f9696926237 (patch)
treecefab4e871fc4e32e15772e131942c8fa5712a13
parentc1173784781d81c5d601a65fbfc61d550d50f377 (diff)
downloadflashrom-7e4968525d37d87e8b6f8b848e4f2f9696926237.tar.gz
flashrom-7e4968525d37d87e8b6f8b848e4f2f9696926237.tar.bz2
flashrom-7e4968525d37d87e8b6f8b848e4f2f9696926237.zip
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>
-rw-r--r--bitbang_spi.c2
-rw-r--r--buspirate_spi.c2
-rw-r--r--ch341a_spi.c2
-rw-r--r--dediprog.c2
-rw-r--r--digilent_spi.c2
-rw-r--r--dummyflasher.c2
-rw-r--r--ene_lpc.c2
-rw-r--r--ft2232_spi.c2
-rw-r--r--ichspi.c6
-rw-r--r--it85spi.c2
-rw-r--r--it87spi.c2
-rw-r--r--jlink_spi.c2
-rw-r--r--linux_spi.c2
-rw-r--r--lspcon_i2c_spi.c2
-rw-r--r--mec1308.c2
-rw-r--r--mstarddc_spi.c2
-rw-r--r--ni845x_spi.c2
-rw-r--r--pickit2_spi.c2
-rw-r--r--programmer.h2
-rw-r--r--raiden_debug_spi.c2
-rw-r--r--realtek_mst_i2c_spi.c2
-rw-r--r--sb600spi.c6
-rw-r--r--serprog.c2
-rw-r--r--spi.c4
-rw-r--r--stlinkv3_spi.c2
-rw-r--r--usbblaster_spi.c2
-rw-r--r--wbsio_spi.c2
27 files changed, 33 insertions, 31 deletions
diff --git a/bitbang_spi.c b/bitbang_spi.c
index b12d81ac..bb89071d 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -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. */
diff --git a/buspirate_spi.c b/buspirate_spi.c
index eee8daa4..96e9673f 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -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;
}
diff --git a/ch341a_spi.c b/ch341a_spi.c
index 84cc3fe7..f84add4e 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -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;
diff --git a/dediprog.c b/dediprog.c
index 4f48f473..a8fe19e3 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -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;
diff --git a/digilent_spi.c b/digilent_spi.c
index 91a28b01..5471724e 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -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;
diff --git a/dummyflasher.c b/dummyflasher.c
index ec5060d1..74075f4e 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -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;
}
diff --git a/ene_lpc.c b/ene_lpc.c
index b66e96e7..46f17832 100644
--- a/ene_lpc.c
+++ b/ene_lpc.c
@@ -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;
diff --git a/ft2232_spi.c b/ft2232_spi.c
index bdc6e373..8d50d204 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -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;
diff --git a/ichspi.c b/ichspi.c
index e45b39a6..613f3fc3 100644
--- a/ichspi.c
+++ b/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));
diff --git a/it85spi.c b/it85spi.c
index 9817c2a9..4d0f9880 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -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;
}
diff --git a/it87spi.c b/it87spi.c
index 868b479a..0760ac86 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -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;
}
diff --git a/jlink_spi.c b/jlink_spi.c
index 8b5cd2cb..9fe44a50 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -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;
diff --git a/linux_spi.c b/linux_spi.c
index 4668e7f2..82741bf6 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -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:
diff --git a/lspcon_i2c_spi.c b/lspcon_i2c_spi.c
index 096fb762..6b8dfe66 100644
--- a/lspcon_i2c_spi.c
+++ b/lspcon_i2c_spi.c
@@ -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;
}
diff --git a/mec1308.c b/mec1308.c
index 1530d9b5..70d2a796 100644
--- a/mec1308.c
+++ b/mec1308.c
@@ -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;
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index c041bd33..32b77cdd 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -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;
diff --git a/ni845x_spi.c b/ni845x_spi.c
index 765da8a6..df8ae0d7 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -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;
}
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 3d0c775c..47316d05 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -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;
diff --git a/programmer.h b/programmer.h
index 675a2594..1b0cdb97 100644
--- a/programmer.h
+++ b/programmer.h
@@ -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 {
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index bd7c054d..c2758515 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -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;
diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c
index 10a1dffd..f0a6dce9 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -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;
}
diff --git a/sb600spi.c b/sb600spi.c
index ef9da4b1..43bf407a 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -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;
}
diff --git a/serprog.c b/serprog.c
index d583a40d..056d8d1a 100644
--- a/serprog.c
+++ b/serprog.c
@@ -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;
diff --git a/spi.c b/spi.c
index aa245d7e..4ac39145 100644
--- a/spi.c
+++ b/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);
}
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index 7e8336e1..7712ec21 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -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;
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index c92efe64..b652a3d5 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -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;
}
diff --git a/wbsio_spi.c b/wbsio_spi.c
index 632ff72a..9eed495c 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -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;
}