Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Angel Pons: Looks good to me, approved
programmer: Make use of new register_spi_master() API

Pass pointers to dynamically allocated data to register_spi_master().
This way we can avoid some mutable globals.

Change-Id: Id7821f1db3284b7b5b3d0abfd878b979c53870a1
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/54067
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
---
M digilent_spi.c
M dummyflasher.c
M ft2232_spi.c
M it85spi.c
M it87spi.c
M jlink_spi.c
M linux_spi.c
M lspcon_i2c_spi.c
M pickit2_spi.c
M usbblaster_spi.c
M wbsio_spi.c
11 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/digilent_spi.c b/digilent_spi.c
index 5471724..ee78890 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -315,7 +315,7 @@
return 0;
}

-static struct spi_master spi_master_digilent_spi = {
+static const struct spi_master spi_master_digilent_spi = {
.features = SPI_MASTER_4BA,
.max_data_read = 252,
.max_data_write = 252,
@@ -454,10 +454,9 @@
}
digilent_data->reset_board = reset_board;
digilent_data->handle = handle;
- spi_master_digilent_spi.data = digilent_data;

register_shutdown(digilent_spi_shutdown, digilent_data);
- register_spi_master(&spi_master_digilent_spi, NULL);
+ register_spi_master(&spi_master_digilent_spi, digilent_data);

return 0;

diff --git a/dummyflasher.c b/dummyflasher.c
index 74075f4..d434eec 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -611,7 +611,7 @@



-static struct spi_master spi_master_dummyflasher = {
+static const struct spi_master spi_master_dummyflasher = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED,
.max_data_write = MAX_DATA_UNSPECIFIED,
@@ -674,7 +674,6 @@
}
data->emu_chip = EMULATE_NONE;
data->delay_us = 0;
- spi_master_dummyflasher.data = data;
par_master_dummy.data = data;

msg_pspew("%s\n", __func__);
@@ -1030,7 +1029,7 @@
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, NULL);
+ register_spi_master(&spi_master_dummyflasher, data);

return 0;
}
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 8d50d20..6072cd2 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -276,7 +276,7 @@
return failed ? -1 : 0;
}

-static struct spi_master spi_master_ft2232 = {
+static const struct spi_master spi_master_ft2232 = {
.features = SPI_MASTER_4BA,
.max_data_read = 64 * 1024,
.max_data_write = 256,
@@ -620,13 +620,11 @@
spi_data->pindir = pindir;
spi_data->ftdic_context = ftdic;

- spi_master_ft2232.data = spi_data;
-
if (register_shutdown(ft2232_shutdown, spi_data)) {
free(spi_data);
goto ftdi_err;
}
- register_spi_master(&spi_master_ft2232, NULL);
+ register_spi_master(&spi_master_ft2232, spi_data);

return 0;

diff --git a/it85spi.c b/it85spi.c
index 4d0f988..810f062 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -281,7 +281,7 @@
return 0;
}

-static struct spi_master spi_master_it85xx = {
+static const struct spi_master spi_master_it85xx = {
.max_data_read = 64,
.max_data_write = 64,
.command = it85xx_spi_send_command,
@@ -358,15 +358,13 @@
return 1;
}

- spi_master_it85xx.data = data;
-
/* FIXME: Really leave FWH enabled? We can't use this region
* anymore since accessing it would mess up IT85 communication.
* If we decide to disable FWH for this region, we should print
* a debug message about it.
*/
/* Set this as SPI controller. */
- register_spi_master(&spi_master_it85xx, NULL);
+ register_spi_master(&spi_master_it85xx, data);

return 0;
}
diff --git a/it87spi.c b/it87spi.c
index 0760ac8..92c95fa 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -290,7 +290,7 @@
return 0;
}

-static struct spi_master spi_master_it87xx = {
+static const struct spi_master spi_master_it87xx = {
.max_data_read = 3,
.max_data_write = MAX_DATA_UNSPECIFIED,
.command = it8716f_spi_send_command,
@@ -419,14 +419,13 @@

data->flashport = flashport;
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, NULL);
+ register_spi_master(&spi_master_it87xx, data);
return 0;
}

diff --git a/jlink_spi.c b/jlink_spi.c
index 9fe44a5..6342e7f 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -155,7 +155,7 @@
return 0;
}

-static struct spi_master spi_master_jlink_spi = {
+static const struct spi_master spi_master_jlink_spi = {
/* Maximum data read size in one go (excluding opcode+address). */
.max_data_read = JTAG_MAX_TRANSFER_SIZE - 5,
/* Maximum data write size in one go (excluding opcode+address). */
@@ -464,7 +464,6 @@
jlink_data->ctx = jaylink_ctx;
jlink_data->devh = jaylink_devh;
jlink_data->reset_cs = reset_cs;
- spi_master_jlink_spi.data = jlink_data;

/* Ensure that the CS signal is not active initially. */
if (!deassert_cs(jlink_data))
@@ -472,7 +471,7 @@

if (register_shutdown(jlink_spi_shutdown, jlink_data))
goto init_err;
- register_spi_master(&spi_master_jlink_spi, NULL);
+ register_spi_master(&spi_master_jlink_spi, jlink_data);

return 0;

diff --git a/linux_spi.c b/linux_spi.c
index 82741bf..7d866f4 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -113,7 +113,7 @@
return 0;
}

-static struct spi_master spi_master_linux = {
+static const struct spi_master spi_master_linux = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_UNSPECIFIED, /* TODO? */
.max_data_write = MAX_DATA_UNSPECIFIED, /* TODO? */
@@ -238,13 +238,12 @@
}
spi_data->fd = fd;
spi_data->max_kernel_buf_size = max_kernel_buf_size;
- spi_master_linux.data = spi_data;

if (register_shutdown(linux_spi_shutdown, spi_data)) {
free(spi_data);
goto init_err;
}
- register_spi_master(&spi_master_linux, NULL);
+ register_spi_master(&spi_master_linux, spi_data);
return 0;

init_err:
diff --git a/lspcon_i2c_spi.c b/lspcon_i2c_spi.c
index 6b8dfe6..7f5e3ef 100644
--- a/lspcon_i2c_spi.c
+++ b/lspcon_i2c_spi.c
@@ -408,7 +408,7 @@
return SPI_GENERIC_ERROR;
}

-static struct spi_master spi_master_i2c_lspcon = {
+static const struct spi_master spi_master_i2c_lspcon = {
.max_data_read = 16,
.max_data_write = 12,
.command = lspcon_i2c_spi_send_command,
@@ -454,10 +454,9 @@
}

data->fd = fd;
- spi_master_i2c_lspcon.data = data;

ret |= register_shutdown(lspcon_i2c_spi_shutdown, data);
- ret |= register_spi_master(&spi_master_i2c_lspcon, NULL);
+ ret |= register_spi_master(&spi_master_i2c_lspcon, data);

return ret;
}
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 47316d0..9c423b9 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -340,7 +340,7 @@
return millivolt;
}

-static struct spi_master spi_master_pickit2 = {
+static const struct spi_master spi_master_pickit2 = {
.max_data_read = 40,
.max_data_write = 40,
.command = pickit2_spi_send_command,
@@ -477,7 +477,6 @@
return 1;
}
pickit2_data->pickit2_handle = pickit2_handle;
- spi_master_pickit2.data = pickit2_data;

if (pickit2_get_firmware_version(pickit2_handle))
goto init_err_cleanup_exit;
@@ -501,7 +500,7 @@

if (register_shutdown(pickit2_shutdown, pickit2_data))
goto init_err_cleanup_exit;
- register_spi_master(&spi_master_pickit2, NULL);
+ register_spi_master(&spi_master_pickit2, pickit2_data);

return 0;

diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index b652a3d..115876e 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -168,7 +168,7 @@
return 0;
}

-static struct spi_master spi_master_usbblaster = {
+static const struct spi_master spi_master_usbblaster = {
.max_data_read = 256,
.max_data_write = 256,
.command = usbblaster_spi_send_command,
@@ -226,13 +226,12 @@
return -1;
}
usbblaster_data->ftdic = ftdic;
- spi_master_usbblaster.data = usbblaster_data;

if (register_shutdown(usbblaster_shutdown, usbblaster_data)) {
free(usbblaster_data);
return -1;
}
- register_spi_master(&spi_master_usbblaster, NULL);
+ register_spi_master(&spi_master_usbblaster, usbblaster_data);
return 0;
}

diff --git a/wbsio_spi.c b/wbsio_spi.c
index 9eed495..d17d49d 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -177,7 +177,7 @@
return 0;
}

-static struct spi_master spi_master_wbsio = {
+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,
@@ -215,8 +215,7 @@
data->spibase = wbsio_spibase;

register_shutdown(wbsio_spi_shutdown, data);
- spi_master_wbsio.data = data;
- register_spi_master(&spi_master_wbsio, NULL);
+ register_spi_master(&spi_master_wbsio, data);

return 0;
}

To view, visit change 54067. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id7821f1db3284b7b5b3d0abfd878b979c53870a1
Gerrit-Change-Number: 54067
Gerrit-PatchSet: 4
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged