Edward O'Callaghan submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Edward O'Callaghan: Looks good to me, approved
spi_master: Make use of new register_spi_master() API

Some more spi masters are now ready to get the advantage of new API
and pass pointers to dynamically allocated data to
register_spi_master(). This way we can avoid some mutable globals.

BUG=b:185191942
TEST=./flashrom --programmer raiden_debug_spi -r $(mktemp)
./flashrom --programmer raiden_debug_spi -v /tmp/tmp.Fch5QLVb4R

Change-Id: If72f54c28a95b402b3565fd14ea481f734e1c970
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/54889
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
---
M ene_lpc.c
M mec1308.c
M raiden_debug_spi.c
M realtek_mst_i2c_spi.c
4 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/ene_lpc.c b/ene_lpc.c
index 46f1783..04c17e3 100644
--- a/ene_lpc.c
+++ b/ene_lpc.c
@@ -504,7 +504,7 @@
return rv;
}

-static struct spi_master spi_master_ene = {
+static const struct spi_master spi_master_ene = {
.max_data_read = 256,
.max_data_write = 256,
.command = ene_spi_send_command,
@@ -568,11 +568,10 @@
ene_enter_flash_mode(ctx_data);

internal_buses_supported |= BUS_LPC;
- spi_master_ene.data = ctx_data;

if (register_shutdown(ene_leave_flash_mode, ctx_data))
goto init_err_cleanup_exit;
- register_spi_master(&spi_master_ene, NULL);
+ register_spi_master(&spi_master_ene, ctx_data);
msg_pdbg("%s: successfully initialized ene\n", __func__);

return 0;
diff --git a/mec1308.c b/mec1308.c
index 70d2a79..3923d5b 100644
--- a/mec1308.c
+++ b/mec1308.c
@@ -397,7 +397,7 @@
return rc;
}

-static struct spi_master spi_master_mec1308 = {
+static const struct spi_master spi_master_mec1308 = {
.max_data_read = 256, /* FIXME: should be MAX_DATA_READ_UNLIMITED? */
.max_data_write = 256, /* FIXME: should be MAX_DATA_WRITE_UNLIMITED? */
.command = mec1308_spi_send_command,
@@ -505,11 +505,10 @@
goto init_err_cleanup_exit;

internal_buses_supported |= BUS_LPC; /* for LPC <--> SPI bridging */
- spi_master_mec1308.data = ctx_data;

if (register_shutdown(mec1308_shutdown, ctx_data))
goto init_err_cleanup_exit;
- register_spi_master(&spi_master_mec1308, NULL);
+ register_spi_master(&spi_master_mec1308, ctx_data);
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);

return 0;
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index c275851..f67bbe5 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -1597,7 +1597,7 @@
data->in_ep = in_endpoint;
data->out_ep = out_endpoint;

- spi_config->data = data;
+ spi_config->data = data; /* data is needed to configure protocol below */
/*
* The SPI master needs to be configured based on the device connected.
* Using the device protocol interrogation, we will set the limits on
@@ -1614,7 +1614,7 @@
return SPI_GENERIC_ERROR;
}

- register_spi_master(spi_config, NULL);
+ register_spi_master(spi_config, data);
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 f0a6dce..95c017f 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -410,7 +410,7 @@
return SPI_GENERIC_ERROR;
}

-static struct spi_master spi_master_i2c_realtek_mst = {
+static const struct spi_master spi_master_i2c_realtek_mst = {
.max_data_read = 16,
.max_data_write = 8,
.command = realtek_mst_i2c_spi_send_command,
@@ -513,9 +513,7 @@
data->fd = fd;
data->reset = reset;
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, NULL);
+ ret |= register_spi_master(&spi_master_i2c_realtek_mst, data);

return ret;
}

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If72f54c28a95b402b3565fd14ea481f734e1c970
Gerrit-Change-Number: 54889
Gerrit-PatchSet: 4
Gerrit-Owner: 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