Attention is currently required from: Edward O'Callaghan, Angel Pons, Anastasia Klimchuk.

Nico Huber would like Edward O'Callaghan, Angel Pons and Anastasia Klimchuk to review this change.

View Change

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>
---
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 wbsio_spi.c
8 files changed, 16 insertions(+), 26 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/67/54067/1
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/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: 1
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-Attention: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus@gmail.com>
Gerrit-Attention: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-MessageType: newchange