Anastasia Klimchuk has uploaded this change for review.
Experimenting with register_x_master API change
work in progress
Change-Id: Ia9ab858a8ce2cae78be32cc9a632eedd3b6ad7cd
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
---
M atavia.c
M bitbang_spi.c
M buspirate_spi.c
M ch341a_spi.c
M dediprog.c
M digilent_spi.c
M drkaiser.c
M dummyflasher.c
M ene_lpc.c
M ft2232_spi.c
M gfxnvidia.c
M ichspi.c
M internal.c
M it8212.c
M it85spi.c
M it87spi.c
M linux_mtd.c
M linux_spi.c
M mec1308.c
M nic3com.c
M nicintel.c
M nicintel_eeprom.c
M nicrealtek.c
M opaque.c
M pickit2_spi.c
M programmer.c
M programmer.h
M raiden_debug_spi.c
M satamv.c
M satasii.c
M sb600spi.c
M serprog.c
M spi.c
M stlinkv3_spi.c
M usbblaster_spi.c
M wbsio_spi.c
36 files changed, 143 insertions(+), 115 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/76/51676/1
diff --git a/atavia.c b/atavia.c
index b407a30..6a32b07 100644
--- a/atavia.c
+++ b/atavia.c
@@ -160,7 +160,7 @@
return 1;
}
- register_par_master(&lpc_master_atavia, BUS_LPC);
+ register_par_master(&lpc_master_atavia, BUS_LPC, NULL, NULL);
return 0;
}
diff --git a/bitbang_spi.c b/bitbang_spi.c
index b12d81a..e5f1c63 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -162,8 +162,10 @@
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_shutdown(bitbang_spi_shutdown, data);
+ if (register_spi_master(&mst, bitbang_spi_shutdown, data)) {
+ free(data);
+ return 1;
+ }
/* Only mess with the bus if we're sure nobody else uses it. */
bitbang_spi_request_bus(master);
diff --git a/buspirate_spi.c b/buspirate_spi.c
index eee8daa..d245922 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -385,13 +385,6 @@
return ret;
}
- if (register_shutdown(buspirate_spi_shutdown, NULL) != 0) {
- bp_commbufsize = 0;
- free(bp_commbuf);
- bp_commbuf = NULL;
- return 1;
- }
-
/* This is the brute force version, but it should work.
* It is likely to fail if a previous flashrom run was aborted during a write with the new SPI commands
* in firmware v5.5 because that firmware may wait for up to 4096 bytes of input before responding to
@@ -655,7 +648,12 @@
return 1;
}
- register_spi_master(&spi_master_buspirate);
+ if (register_spi_master(&spi_master_buspirate, buspirate_spi_shutdown, NULL)) {
+ bp_commbufsize = 0;
+ free(bp_commbuf);
+ bp_commbuf = NULL;
+ return 1;
+ }
return 0;
}
diff --git a/ch341a_spi.c b/ch341a_spi.c
index 84cc3fe..31d0ca1 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -505,8 +505,7 @@
if ((config_stream(CH341A_STM_I2C_100K) < 0) || (enable_pins(true) < 0))
goto dealloc_transfers;
- register_shutdown(ch341a_spi_shutdown, NULL);
- register_spi_master(&spi_master_ch341a_spi);
+ register_spi_master(&spi_master_ch341a_spi, ch341a_spi_shutdown, NULL);
return 0;
diff --git a/dediprog.c b/dediprog.c
index c50e374..d74e7ec 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1227,9 +1227,6 @@
msg_pinfo("Using dediprog id SF%06d.\n", found_id);
}
- if (register_shutdown(dediprog_shutdown, NULL))
- return 1;
-
/* Try reading the devicestring. If that fails and the device is old (FW < 6.0.0, which we can not know)
* then we need to try the "set voltage" command and then attempt to read the devicestring again. */
if (dediprog_check_devicestring()) {
@@ -1273,7 +1270,7 @@
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, dediprog_shutdown, NULL) || dediprog_set_leds(LED_NONE))
return 1;
return 0;
diff --git a/digilent_spi.c b/digilent_spi.c
index 0f7a9da..23e96b5 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -444,8 +444,7 @@
if (spi_set_mode(0x00) != 0)
goto close_handle;
- register_shutdown(digilent_spi_shutdown, NULL);
- register_spi_master(&spi_master_digilent_spi);
+ register_spi_master(&spi_master_digilent_spi, digilent_spi_shutdown, NULL);
return 0;
diff --git a/drkaiser.c b/drkaiser.c
index ac49df3..f92dc36 100644
--- a/drkaiser.c
+++ b/drkaiser.c
@@ -77,7 +77,7 @@
return 1;
max_rom_decode.parallel = 128 * 1024;
- register_par_master(&par_master_drkaiser, BUS_PARALLEL);
+ register_par_master(&par_master_drkaiser, BUS_PARALLEL, NULL, NULL);
return 0;
}
diff --git a/dummyflasher.c b/dummyflasher.c
index 5190282..edc0562 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -658,6 +658,7 @@
char *bustext = NULL;
char *tmp = NULL;
unsigned int i;
+ int ret = 0;
#if EMULATE_SPI_CHIP
char *status = NULL;
int size = -1; /* size for VARIABLE_SIZE chip device */
@@ -1020,16 +1021,18 @@
#endif
dummy_init_out:
- if (register_shutdown(dummy_shutdown, data)) {
+ if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
+ ret = register_par_master(&par_master_dummy,
+ dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH),
+ dummy_shutdown, data);
+ if (dummy_buses_supported & BUS_SPI)
+ ret = register_spi_master(&spi_master_dummyflasher, dummy_shutdown, data);
+
+ if (ret) {
free(flashchip_contents);
free(data);
- return 1;
+ return ret;
}
- if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
- 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);
return 0;
}
diff --git a/ene_lpc.c b/ene_lpc.c
index 56d6580..98980fe 100644
--- a/ene_lpc.c
+++ b/ene_lpc.c
@@ -573,17 +573,14 @@
* Compal - ec_command(0x41, 0xa1) returns 43 4f 4d 50 41 4c 9c
*/
-
- if (register_shutdown(ene_leave_flash_mode, ctx_data)) {
- ret = 1;
- goto ene_probe_spi_flash_exit;
- }
-
ene_enter_flash_mode(ctx_data);
internal_buses_supported |= BUS_LPC;
spi_master_ene.data = ctx_data;
- register_spi_master(&spi_master_ene);
+ if (register_spi_master(&spi_master_ene, ene_leave_flash_mode, ctx_data)) {
+ ret = 1;
+ goto ene_probe_spi_flash_exit;
+ }
msg_pdbg("%s: successfully initialized ene\n", __func__);
ene_probe_spi_flash_exit:
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 1fb795b..7910d4e 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -602,8 +602,10 @@
goto ftdi_err;
}
- register_shutdown(ft2232_shutdown, ftdic);
- register_spi_master(&spi_master_ft2232);
+ if (register_spi_master(&spi_master_ft2232, ft2232_shutdown, ftdic)) {
+ ret = 1;
+ goto ftdi_err;
+ }
return 0;
diff --git a/gfxnvidia.c b/gfxnvidia.c
index d8ea4d6..51bbf22 100644
--- a/gfxnvidia.c
+++ b/gfxnvidia.c
@@ -103,7 +103,7 @@
/* Write/erase doesn't work. */
programmer_may_write = 0;
- register_par_master(&par_master_gfxnvidia, BUS_PARALLEL);
+ register_par_master(&par_master_gfxnvidia, BUS_PARALLEL, NULL, NULL);
return 0;
}
diff --git a/ichspi.c b/ichspi.c
index e45b39a..a328106 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -1812,7 +1812,7 @@
}
ich_init_opcodes(ich_gen);
ich_set_bbar(0, ich_gen);
- register_spi_master(&spi_master_ich7);
+ register_spi_master(&spi_master_ich7, NULL, NULL);
break;
case CHIPSET_ICH8:
default: /* Future version might behave the same */
@@ -2039,9 +2039,9 @@
}
hwseq_data.size_comp1 = tmpi;
- register_opaque_master(&opaque_master_ich_hwseq);
+ register_opaque_master(&opaque_master_ich_hwseq, NULL, NULL);
} else {
- register_spi_master(&spi_master_ich9);
+ register_spi_master(&spi_master_ich9, NULL, NULL);
}
break;
}
@@ -2071,7 +2071,7 @@
/* 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, 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/internal.c b/internal.c
index bdbe32d..a76d9c7 100644
--- a/internal.c
+++ b/internal.c
@@ -335,7 +335,10 @@
#endif /* IS_X86 */
if (internal_buses_supported & BUS_NONSPI)
- register_par_master(&par_master_internal, internal_buses_supported);
+ register_par_master(&par_master_internal,
+ internal_buses_supported,
+ NULL,
+ NULL);
/* Report if a non-whitelisted laptop is detected that likely uses a legacy bus. */
if (is_laptop && !laptop_ok) {
diff --git a/it8212.c b/it8212.c
index ac53a6f..ba140e5 100644
--- a/it8212.c
+++ b/it8212.c
@@ -67,7 +67,7 @@
rpci_write_long(dev, PCI_ROM_ADDRESS, io_base_addr | 0x01);
max_rom_decode.parallel = IT8212_MEMMAP_SIZE;
- register_par_master(&par_master_it8212, BUS_PARALLEL);
+ register_par_master(&par_master_it8212, BUS_PARALLEL, NULL, NULL);
return 0;
}
diff --git a/it85spi.c b/it85spi.c
index 9817c2a..2ebdf7a 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -353,11 +353,6 @@
data->ce_high = ((unsigned char *)base) + 0xE00; /* 0xFFFFFE00 */
data->ce_low = ((unsigned char *)base) + 0xD00; /* 0xFFFFFD00 */
- if (register_shutdown(it85xx_shutdown, data)) {
- free(data);
- return 1;
- }
-
spi_master_it85xx.data = data;
/* FIXME: Really leave FWH enabled? We can't use this region
@@ -366,7 +361,11 @@
* a debug message about it.
*/
/* Set this as SPI controller. */
- register_spi_master(&spi_master_it85xx);
+ if (register_spi_master(&spi_master_it85xx, it85xx_shutdown, data)) {
+ /* TODO: decide whether to free data here or inside register */
+ free(data);
+ return 1;
+ }
return 0;
}
diff --git a/it87spi.c b/it87spi.c
index 868b479..af85668 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -421,12 +421,14 @@
data->fast_spi = 1;
spi_master_it87xx.data = data;
- register_shutdown(it8716f_shutdown, data);
-
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);
+ if (register_spi_master(&spi_master_it87xx, it8716f_shutdown, data)) {
+ /* TODO: decide when to free data */
+ free(data);
+ return 1;
+ }
return 0;
}
diff --git a/linux_mtd.c b/linux_mtd.c
index 22702e9..7eb6a77 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -401,11 +401,9 @@
if (linux_mtd_setup(dev_num))
goto linux_mtd_init_exit;
- if (register_shutdown(linux_mtd_shutdown, NULL))
+ if (register_opaque_master(&programmer_linux_mtd, linux_mtd_shutdown, NULL))
goto linux_mtd_init_exit;
- register_opaque_master(&programmer_linux_mtd);
-
ret = 0;
linux_mtd_init_exit:
free(param);
diff --git a/linux_spi.c b/linux_spi.c
index bbd45f3..c9060ca 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -160,10 +160,6 @@
}
free(dev);
- if (register_shutdown(linux_spi_shutdown, NULL))
- return 1;
- /* We rely on the shutdown function for cleanup from here on. */
-
if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) == -1) {
msg_perr("%s: failed to set speed to %"PRIu32"Hz: %s\n",
__func__, speed_hz, strerror(errno));
@@ -220,7 +216,9 @@
}
msg_pdbg("%s: max_kernel_buf_size: %zu\n", __func__, max_kernel_buf_size);
- register_spi_master(&spi_master_linux);
+ if (register_spi_master(&spi_master_linux, linux_spi_shutdown, NULL)) {
+ return 1;
+ }
return 0;
}
diff --git a/mec1308.c b/mec1308.c
index c4b34f5..8f7ca05 100644
--- a/mec1308.c
+++ b/mec1308.c
@@ -492,11 +492,6 @@
goto mec1308_init_exit;
}
- if (register_shutdown(mec1308_shutdown, ctx_data)) {
- ret = 1;
- goto mec1308_init_exit;
- }
-
/*
* Enter SPI Pass-Thru Mode after commands which do not require access
* to SPI ROM are complete. We'll start by doing the exit_passthru_mode
@@ -511,7 +506,12 @@
internal_buses_supported |= BUS_LPC; /* for LPC <--> SPI bridging */
spi_master_mec1308.data = ctx_data;
- register_spi_master(&spi_master_mec1308);
+
+ if (register_spi_master(&spi_master_mec1308, mec1308_shutdown, ctx_data)) {
+ ret = 1;
+ goto mec1308_init_exit;
+ }
+
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);
mec1308_init_exit:
diff --git a/nic3com.c b/nic3com.c
index b7b967a..ff1cbc7 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -116,11 +116,10 @@
*/
OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);
- if (register_shutdown(nic3com_shutdown, NULL))
- return 1;
-
max_rom_decode.parallel = 128 * 1024;
- register_par_master(&par_master_nic3com, BUS_PARALLEL);
+ if (register_par_master(&par_master_nic3com, BUS_PARALLEL, nic3com_shutdown, NULL)) {
+ return 1;
+ }
return 0;
}
diff --git a/nicintel.c b/nicintel.c
index 4672890..85100aa 100644
--- a/nicintel.c
+++ b/nicintel.c
@@ -99,7 +99,7 @@
pci_rmmio_writew(0x0001, nicintel_control_bar + CSR_FCR);
max_rom_decode.parallel = NICINTEL_MEMMAP_SIZE;
- register_par_master(&par_master_nicintel, BUS_PARALLEL);
+ register_par_master(&par_master_nicintel, BUS_PARALLEL, NULL, NULL);
return 0;
}
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index 4d45f79..f75448d 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -482,21 +482,23 @@
return 1;
*eecp = eec;
- if (register_shutdown(nicintel_ee_shutdown_82580, eecp))
+ if (register_opaque_master(&opaque_master_nicintel_ee_82580,
+ nicintel_ee_shutdown_82580,
+ eecp))
return 1;
}
- return register_opaque_master(&opaque_master_nicintel_ee_82580);
+ return register_opaque_master(&opaque_master_nicintel_ee_82580, NULL, NULL);
} else {
nicintel_eebar = rphysmap("Intel i210 NIC w/ emulated EEPROM",
io_base_addr + 0x12000, MEMMAP_SIZE);
if (!nicintel_eebar)
return 1;
- if (register_shutdown(nicintel_ee_shutdown_i210, NULL))
+ if (register_opaque_master(&opaque_master_nicintel_ee_i210,
+ nicintel_ee_shutdown_i210,
+ NULL))
return 1;
-
- return register_opaque_master(&opaque_master_nicintel_ee_i210);
}
return 1;
diff --git a/nicrealtek.c b/nicrealtek.c
index 5454b63..b48cf88 100644
--- a/nicrealtek.c
+++ b/nicrealtek.c
@@ -83,10 +83,7 @@
break;
}
- if (register_shutdown(nicrealtek_shutdown, NULL))
- return 1;
-
- register_par_master(&par_master_nicrealtek, BUS_PARALLEL);
+ register_par_master(&par_master_nicrealtek, BUS_PARALLEL, nicrealtek_shutdown, NULL);
return 0;
}
diff --git a/opaque.c b/opaque.c
index 276934f..f92a11f 100644
--- a/opaque.c
+++ b/opaque.c
@@ -46,7 +46,7 @@
return flash->mst->opaque.erase(flash, blockaddr, blocklen);
}
-int register_opaque_master(const struct opaque_master *mst)
+int register_opaque_master(const struct opaque_master *mst, int (*function) (void *data), void *data)
{
struct registered_master rmst;
@@ -58,5 +58,5 @@
}
rmst.buses_supported = BUS_PROG;
rmst.opaque = *mst;
- return register_master(&rmst);
+ return register_master(&rmst, function, data);
}
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 0bc17af..6e09bcb 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -458,10 +458,6 @@
return 1;
}
- if (register_shutdown(pickit2_shutdown, NULL) != 0) {
- return 1;
- }
-
if (pickit2_get_firmware_version()) {
return 1;
}
@@ -485,7 +481,9 @@
return 1;
}
- register_spi_master(&spi_master_pickit2);
+ if (register_spi_master(&spi_master_pickit2, pickit2_shutdown, NULL)) {
+ return 1;
+ }
return 0;
}
diff --git a/programmer.c b/programmer.c
index bee60e3..ecfe529 100644
--- a/programmer.c
+++ b/programmer.c
@@ -81,7 +81,9 @@
}
int register_par_master(const struct par_master *mst,
- const enum chipbustype buses)
+ const enum chipbustype buses,
+ int (*function) (void *data),
+ void *data)
{
struct registered_master rmst;
if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel ||
@@ -95,7 +97,7 @@
rmst.buses_supported = buses;
rmst.par = *mst;
- return register_master(&rmst);
+ return register_master(&rmst, function, data);
}
/* The limit of 4 is totally arbitrary. */
@@ -103,8 +105,16 @@
struct registered_master registered_masters[MASTERS_MAX];
int registered_master_count = 0;
-/* This function copies the struct registered_master parameter. */
-int register_master(const struct registered_master *mst)
+/* This function copies the struct registered_master parameter and
+ * registers a shutdown function for this master.
+ *
+ * Takes a pointer to shutdown function and a pointer to a data
+ * used by said function. If data is not needed set data=NULL.
+ *
+ * If no shutdown function is needed, set function=NULL, in this case
+ * data is ignored.
+ * */
+int register_master(const struct registered_master *mst, int (*function) (void *data), void *data)
{
if (registered_master_count >= MASTERS_MAX) {
msg_perr("Tried to register more than %i master "
@@ -114,6 +124,11 @@
registered_masters[registered_master_count] = *mst;
registered_master_count++;
+ /* TODO: think about memory management for data! */
+ if (function)
+ if (register_shutdown(function, data))
+ return 1;
+
return 0;
}
diff --git a/programmer.h b/programmer.h
index 29a100b..35ad488 100644
--- a/programmer.h
+++ b/programmer.h
@@ -643,7 +643,7 @@
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, int (*function) (void *data), void *data);
/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
enum ich_chipset {
@@ -724,7 +724,9 @@
int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
void *data;
};
-int register_opaque_master(const struct opaque_master *mst);
+int register_opaque_master(const struct opaque_master *mst,
+ int (*function) (void *data),
+ void *data);
/* programmer.c */
void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
@@ -746,7 +748,10 @@
void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
void *data;
};
-int register_par_master(const struct par_master *mst, const enum chipbustype buses);
+int register_par_master(const struct par_master *mst,
+ const enum chipbustype buses,
+ int (*function) (void *data),
+ void *data);
struct registered_master {
enum chipbustype buses_supported;
union {
@@ -757,7 +762,7 @@
};
extern struct registered_master registered_masters[];
extern int registered_master_count;
-int register_master(const struct registered_master *mst);
+int register_master(const struct registered_master *mst, int (*function) (void *data), void *data);
/* serprog.c */
#if CONFIG_SERPROG == 1
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index bd7c054..bb954ba 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -1614,8 +1614,7 @@
return SPI_GENERIC_ERROR;
}
- register_spi_master(spi_config);
- register_shutdown(raiden_debug_spi_shutdown, spi_config);
+ register_spi_master(spi_config, raiden_debug_spi_shutdown, spi_config);
return 0;
}
diff --git a/satamv.c b/satamv.c
index 31265ea..da0091a 100644
--- a/satamv.c
+++ b/satamv.c
@@ -148,7 +148,7 @@
/* 512 kByte with two 8-bit latches, and
* 4 MByte with additional 3-bit latch. */
max_rom_decode.parallel = 4 * 1024 * 1024;
- register_par_master(&par_master_satamv, BUS_PARALLEL);
+ register_par_master(&par_master_satamv, BUS_PARALLEL, NULL, NULL);
return 0;
}
diff --git a/satasii.c b/satasii.c
index 8a0938d..7560d4c 100644
--- a/satasii.c
+++ b/satasii.c
@@ -100,7 +100,7 @@
if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26))))
msg_pwarn("Warning: Flash seems unconnected.\n");
- register_par_master(&par_master_satasii, BUS_PARALLEL);
+ register_par_master(&par_master_satasii, BUS_PARALLEL, NULL, NULL);
return 0;
}
diff --git a/sb600spi.c b/sb600spi.c
index ef9da4b..c8cfca0 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -610,6 +610,7 @@
struct pci_dev *smbus_dev;
uint32_t tmp;
uint8_t reg;
+ int ret = 0;
/* Read SPI_BaseAddr */
tmp = pci_read_long(dev, 0xa0);
@@ -778,7 +779,6 @@
data->flash = NULL;
- register_shutdown(sb600spi_shutdown, data);
spi_master_sb600.data = data;
spi_master_yangtze.data = data;
spi_master_promontory.data = data;
@@ -786,11 +786,16 @@
/* 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);
+ ret = register_spi_master(&spi_master_sb600, sb600spi_shutdown, data);
else if (amd_gen == CHIPSET_YANGTZE)
- register_spi_master(&spi_master_yangtze);
+ ret = register_spi_master(&spi_master_yangtze, sb600spi_shutdown, data);
else
- register_spi_master(&spi_master_promontory);
+ ret = register_spi_master(&spi_master_promontory, sb600spi_shutdown, data);
+
+ if (ret) {
+ free(data);
+ return ret;
+ }
return 0;
}
diff --git a/serprog.c b/serprog.c
index d583a40..e430a83 100644
--- a/serprog.c
+++ b/serprog.c
@@ -883,9 +883,12 @@
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, NULL);
if (serprog_buses_supported & BUS_NONSPI)
- register_par_master(&par_master_serprog, serprog_buses_supported & BUS_NONSPI);
+ register_par_master(&par_master_serprog,
+ serprog_buses_supported & BUS_NONSPI,
+ NULL,
+ NULL);
return 0;
}
diff --git a/spi.c b/spi.c
index aed2a92..0836094 100644
--- a/spi.c
+++ b/spi.c
@@ -131,7 +131,16 @@
return flash->mst->spi.write_aai(flash, buf, start, len);
}
-int register_spi_master(const struct spi_master *mst)
+/*
+ * Registers spi master and registers a shutdown function for it.
+ *
+ * Takes a pointer to shutdown function and a pointer to a data
+ * used by said function. If data is not needed set data=NULL.
+ *
+ * If no shutdown function is needed, set function=NULL, in this case
+ * data is ignored.
+ * */
+int register_spi_master(const struct spi_master *mst, int (*function) (void *data), void *data)
{
struct registered_master rmst;
@@ -145,8 +154,8 @@
return ERROR_FLASHROM_BUG;
}
-
rmst.buses_supported = BUS_SPI;
rmst.spi = *mst;
- return register_master(&rmst);
+
+ return register_master(&rmst, function, data);
}
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index 7e8336e..999cba6 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -506,10 +506,7 @@
if (stlinkv3_spi_open(sck_freq_kHz))
goto err_exit;
- if (register_shutdown(stlinkv3_spi_shutdown, NULL))
- goto err_exit;
-
- if (register_spi_master(&spi_programmer_stlinkv3))
+ if (register_spi_master(&spi_programmer_stlinkv3, stlinkv3_spi_shutdown, NULL))
goto err_exit;
return 0;
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index 58a8a0e..8699292 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -113,7 +113,7 @@
return -1;
}
- register_spi_master(&spi_master_usbblaster);
+ register_spi_master(&spi_master_usbblaster, NULL, NULL);
return 0;
}
diff --git a/wbsio_spi.c b/wbsio_spi.c
index 632ff72..c97ef95 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -214,9 +214,11 @@
}
data->spibase = wbsio_spibase;
- register_shutdown(wbsio_spi_shutdown, data);
spi_master_wbsio.data = data;
- register_spi_master(&spi_master_wbsio);
+ if (register_spi_master(&spi_master_wbsio, wbsio_spi_shutdown, data)) {
+ free(data);
+ return 1;
+ }
return 0;
}
To view, visit change 51676. To unsubscribe, or for help writing mail filters, visit settings.