1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

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>
This commit is contained in:
Nico Huber 2021-05-11 17:53:34 +02:00
parent 7e4968525d
commit 90739d147f
11 changed files with 22 additions and 35 deletions

View File

@ -315,7 +315,7 @@ static int digilent_spi_send_command(const struct flashctx *flash, unsigned int
return 0; return 0;
} }
static struct spi_master spi_master_digilent_spi = { static const struct spi_master spi_master_digilent_spi = {
.features = SPI_MASTER_4BA, .features = SPI_MASTER_4BA,
.max_data_read = 252, .max_data_read = 252,
.max_data_write = 252, .max_data_write = 252,
@ -454,10 +454,9 @@ int digilent_spi_init(void)
} }
digilent_data->reset_board = reset_board; digilent_data->reset_board = reset_board;
digilent_data->handle = handle; digilent_data->handle = handle;
spi_master_digilent_spi.data = digilent_data;
register_shutdown(digilent_spi_shutdown, 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; return 0;

View File

@ -611,7 +611,7 @@ static int dummy_spi_send_command(const struct flashctx *flash, unsigned int wri
static struct spi_master spi_master_dummyflasher = { static const struct spi_master spi_master_dummyflasher = {
.features = SPI_MASTER_4BA, .features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED, .max_data_read = MAX_DATA_READ_UNLIMITED,
.max_data_write = MAX_DATA_UNSPECIFIED, .max_data_write = MAX_DATA_UNSPECIFIED,
@ -674,7 +674,6 @@ int dummy_init(void)
} }
data->emu_chip = EMULATE_NONE; data->emu_chip = EMULATE_NONE;
data->delay_us = 0; data->delay_us = 0;
spi_master_dummyflasher.data = data;
par_master_dummy.data = data; par_master_dummy.data = data;
msg_pspew("%s\n", __func__); msg_pspew("%s\n", __func__);
@ -1030,7 +1029,7 @@ dummy_init_out:
register_par_master(&par_master_dummy, register_par_master(&par_master_dummy,
dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH)); dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH));
if (dummy_buses_supported & BUS_SPI) if (dummy_buses_supported & BUS_SPI)
register_spi_master(&spi_master_dummyflasher, NULL); register_spi_master(&spi_master_dummyflasher, data);
return 0; return 0;
} }

View File

@ -276,7 +276,7 @@ static int ft2232_spi_send_command(const struct flashctx *flash,
return failed ? -1 : 0; return failed ? -1 : 0;
} }
static struct spi_master spi_master_ft2232 = { static const struct spi_master spi_master_ft2232 = {
.features = SPI_MASTER_4BA, .features = SPI_MASTER_4BA,
.max_data_read = 64 * 1024, .max_data_read = 64 * 1024,
.max_data_write = 256, .max_data_write = 256,
@ -620,13 +620,11 @@ int ft2232_spi_init(void)
spi_data->pindir = pindir; spi_data->pindir = pindir;
spi_data->ftdic_context = ftdic; spi_data->ftdic_context = ftdic;
spi_master_ft2232.data = spi_data;
if (register_shutdown(ft2232_shutdown, spi_data)) { if (register_shutdown(ft2232_shutdown, spi_data)) {
free(spi_data); free(spi_data);
goto ftdi_err; goto ftdi_err;
} }
register_spi_master(&spi_master_ft2232, NULL); register_spi_master(&spi_master_ft2232, spi_data);
return 0; return 0;

View File

@ -281,7 +281,7 @@ static int it85xx_spi_send_command(const struct flashctx *flash,
return 0; return 0;
} }
static struct spi_master spi_master_it85xx = { static const struct spi_master spi_master_it85xx = {
.max_data_read = 64, .max_data_read = 64,
.max_data_write = 64, .max_data_write = 64,
.command = it85xx_spi_send_command, .command = it85xx_spi_send_command,
@ -358,15 +358,13 @@ int it85xx_spi_init(struct superio s)
return 1; return 1;
} }
spi_master_it85xx.data = data;
/* FIXME: Really leave FWH enabled? We can't use this region /* FIXME: Really leave FWH enabled? We can't use this region
* anymore since accessing it would mess up IT85 communication. * anymore since accessing it would mess up IT85 communication.
* If we decide to disable FWH for this region, we should print * If we decide to disable FWH for this region, we should print
* a debug message about it. * a debug message about it.
*/ */
/* Set this as SPI controller. */ /* Set this as SPI controller. */
register_spi_master(&spi_master_it85xx, NULL); register_spi_master(&spi_master_it85xx, data);
return 0; return 0;
} }

View File

@ -290,7 +290,7 @@ static int it8716f_spi_chip_write_256(struct flashctx *flash, const uint8_t *buf
return 0; return 0;
} }
static struct spi_master spi_master_it87xx = { static const struct spi_master spi_master_it87xx = {
.max_data_read = 3, .max_data_read = 3,
.max_data_write = MAX_DATA_UNSPECIFIED, .max_data_write = MAX_DATA_UNSPECIFIED,
.command = it8716f_spi_send_command, .command = it8716f_spi_send_command,
@ -419,14 +419,13 @@ static uint16_t it87spi_probe(uint16_t port)
data->flashport = flashport; data->flashport = flashport;
data->fast_spi = 1; data->fast_spi = 1;
spi_master_it87xx.data = data;
register_shutdown(it8716f_shutdown, data); register_shutdown(it8716f_shutdown, data);
if (internal_buses_supported & BUS_SPI) if (internal_buses_supported & BUS_SPI)
msg_pdbg("Overriding chipset SPI with IT87 SPI.\n"); msg_pdbg("Overriding chipset SPI with IT87 SPI.\n");
/* FIXME: Add the SPI bus or replace the other buses with it? */ /* 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; return 0;
} }

View File

@ -155,7 +155,7 @@ static int jlink_spi_send_command(const struct flashctx *flash, unsigned int wri
return 0; 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). */ /* Maximum data read size in one go (excluding opcode+address). */
.max_data_read = JTAG_MAX_TRANSFER_SIZE - 5, .max_data_read = JTAG_MAX_TRANSFER_SIZE - 5,
/* Maximum data write size in one go (excluding opcode+address). */ /* Maximum data write size in one go (excluding opcode+address). */
@ -464,7 +464,6 @@ int jlink_spi_init(void)
jlink_data->ctx = jaylink_ctx; jlink_data->ctx = jaylink_ctx;
jlink_data->devh = jaylink_devh; jlink_data->devh = jaylink_devh;
jlink_data->reset_cs = reset_cs; jlink_data->reset_cs = reset_cs;
spi_master_jlink_spi.data = jlink_data;
/* Ensure that the CS signal is not active initially. */ /* Ensure that the CS signal is not active initially. */
if (!deassert_cs(jlink_data)) if (!deassert_cs(jlink_data))
@ -472,7 +471,7 @@ int jlink_spi_init(void)
if (register_shutdown(jlink_spi_shutdown, jlink_data)) if (register_shutdown(jlink_spi_shutdown, jlink_data))
goto init_err; goto init_err;
register_spi_master(&spi_master_jlink_spi, NULL); register_spi_master(&spi_master_jlink_spi, jlink_data);
return 0; return 0;

View File

@ -113,7 +113,7 @@ static int linux_spi_send_command(const struct flashctx *flash, unsigned int wri
return 0; return 0;
} }
static struct spi_master spi_master_linux = { static const struct spi_master spi_master_linux = {
.features = SPI_MASTER_4BA, .features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_UNSPECIFIED, /* TODO? */ .max_data_read = MAX_DATA_UNSPECIFIED, /* TODO? */
.max_data_write = MAX_DATA_UNSPECIFIED, /* TODO? */ .max_data_write = MAX_DATA_UNSPECIFIED, /* TODO? */
@ -238,13 +238,12 @@ int linux_spi_init(void)
} }
spi_data->fd = fd; spi_data->fd = fd;
spi_data->max_kernel_buf_size = max_kernel_buf_size; spi_data->max_kernel_buf_size = max_kernel_buf_size;
spi_master_linux.data = spi_data;
if (register_shutdown(linux_spi_shutdown, spi_data)) { if (register_shutdown(linux_spi_shutdown, spi_data)) {
free(spi_data); free(spi_data);
goto init_err; goto init_err;
} }
register_spi_master(&spi_master_linux, NULL); register_spi_master(&spi_master_linux, spi_data);
return 0; return 0;
init_err: init_err:

View File

@ -408,7 +408,7 @@ static int lspcon_i2c_spi_write_aai(struct flashctx *flash, const uint8_t *buf,
return SPI_GENERIC_ERROR; 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_read = 16,
.max_data_write = 12, .max_data_write = 12,
.command = lspcon_i2c_spi_send_command, .command = lspcon_i2c_spi_send_command,
@ -454,10 +454,9 @@ int lspcon_i2c_spi_init(void)
} }
data->fd = fd; data->fd = fd;
spi_master_i2c_lspcon.data = data;
ret |= register_shutdown(lspcon_i2c_spi_shutdown, 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; return ret;
} }

View File

@ -340,7 +340,7 @@ static int parse_voltage(char *voltage)
return millivolt; return millivolt;
} }
static struct spi_master spi_master_pickit2 = { static const struct spi_master spi_master_pickit2 = {
.max_data_read = 40, .max_data_read = 40,
.max_data_write = 40, .max_data_write = 40,
.command = pickit2_spi_send_command, .command = pickit2_spi_send_command,
@ -477,7 +477,6 @@ int pickit2_spi_init(void)
return 1; return 1;
} }
pickit2_data->pickit2_handle = pickit2_handle; pickit2_data->pickit2_handle = pickit2_handle;
spi_master_pickit2.data = pickit2_data;
if (pickit2_get_firmware_version(pickit2_handle)) if (pickit2_get_firmware_version(pickit2_handle))
goto init_err_cleanup_exit; goto init_err_cleanup_exit;
@ -501,7 +500,7 @@ int pickit2_spi_init(void)
if (register_shutdown(pickit2_shutdown, pickit2_data)) if (register_shutdown(pickit2_shutdown, pickit2_data))
goto init_err_cleanup_exit; goto init_err_cleanup_exit;
register_spi_master(&spi_master_pickit2, NULL); register_spi_master(&spi_master_pickit2, pickit2_data);
return 0; return 0;

View File

@ -168,7 +168,7 @@ static int usbblaster_shutdown(void *data)
return 0; return 0;
} }
static struct spi_master spi_master_usbblaster = { static const struct spi_master spi_master_usbblaster = {
.max_data_read = 256, .max_data_read = 256,
.max_data_write = 256, .max_data_write = 256,
.command = usbblaster_spi_send_command, .command = usbblaster_spi_send_command,
@ -226,13 +226,12 @@ int usbblaster_spi_init(void)
return -1; return -1;
} }
usbblaster_data->ftdic = ftdic; usbblaster_data->ftdic = ftdic;
spi_master_usbblaster.data = usbblaster_data;
if (register_shutdown(usbblaster_shutdown, usbblaster_data)) { if (register_shutdown(usbblaster_shutdown, usbblaster_data)) {
free(usbblaster_data); free(usbblaster_data);
return -1; return -1;
} }
register_spi_master(&spi_master_usbblaster, NULL); register_spi_master(&spi_master_usbblaster, usbblaster_data);
return 0; return 0;
} }

View File

@ -177,7 +177,7 @@ static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf,
return 0; 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_read = MAX_DATA_UNSPECIFIED,
.max_data_write = MAX_DATA_UNSPECIFIED, .max_data_write = MAX_DATA_UNSPECIFIED,
.command = wbsio_spi_send_command, .command = wbsio_spi_send_command,
@ -215,8 +215,7 @@ int wbsio_check_for_spi(void)
data->spibase = wbsio_spibase; data->spibase = wbsio_spibase;
register_shutdown(wbsio_spi_shutdown, data); register_shutdown(wbsio_spi_shutdown, data);
spi_master_wbsio.data = data; register_spi_master(&spi_master_wbsio, data);
register_spi_master(&spi_master_wbsio, NULL);
return 0; return 0;
} }