Revert "Update all programmer init functions to register bus programmers into common list"
This reverts commit 63b92f99a9d43dd637bcce564cd372be3c81c5d8.
BUG=chromium:635405
Change-Id: I94ae18b547d2aedd74fc7103a38dcbfd2f57be66
Reviewed-on: https://chromium-review.googlesource.com/367504
Commit-Ready: David Hendricks <dhendrix@chromium.org>
Tested-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: David Hendricks <dhendrix@chromium.org>
diff --git a/spi.c b/spi.c
index 25b2926..41fbe2a 100644
--- a/spi.c
+++ b/spi.c
@@ -30,16 +30,42 @@
#include "programmer.h"
#include "spi.h"
+const struct spi_programmer spi_programmer_none = {
+ .type = SPI_CONTROLLER_NONE,
+ .max_data_read = MAX_DATA_UNSPECIFIED,
+ .max_data_write = MAX_DATA_UNSPECIFIED,
+ .command = NULL,
+ .multicommand = NULL,
+ .read = NULL,
+ .write_256 = NULL,
+};
+
+const struct spi_programmer *spi_programmer = &spi_programmer_none;
+
int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
- return flash->pgm->spi.command(flash, writecnt, readcnt, writearr,
- readarr);
+ if (!spi_programmer->command) {
+ msg_perr("%s called, but SPI is unsupported on this "
+ "hardware. Please report a bug at "
+ "flashrom@flashrom.org\n", __func__);
+ return 1;
+ }
+
+ return spi_programmer->command(flash, writecnt, readcnt,
+ writearr, readarr);
}
int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds)
{
- return flash->pgm->spi.multicommand(flash, cmds);
+ if (!spi_programmer->multicommand) {
+ msg_perr("%s called, but SPI is unsupported on this "
+ "hardware. Please report a bug at "
+ "flashrom@flashrom.org\n", __func__);
+ return 1;
+ }
+
+ return spi_programmer->multicommand(flash, cmds);
}
int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
@@ -73,7 +99,7 @@
int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
{
- unsigned int max_data = flash->pgm->spi.max_data_read;
+ unsigned int max_data = spi_programmer->max_data_read;
int rc;
if (max_data == MAX_DATA_UNSPECIFIED) {
msg_perr("%s called, but SPI read chunk size not defined "
@@ -93,7 +119,7 @@
int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
{
- unsigned int max_data = flash->pgm->spi.max_data_write;
+ unsigned int max_data = spi_programmer->max_data_write;
int rc;
if (max_data == MAX_DATA_UNSPECIFIED) {
msg_perr("%s called, but SPI write chunk size not defined "
@@ -111,6 +137,13 @@
int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
{
unsigned int addrbase = 0;
+ if (!spi_programmer->read) {
+ msg_perr("%s called, but SPI read is unsupported on this "
+ "hardware. Please report a bug at "
+ "flashrom@flashrom.org\n", __func__);
+ return 1;
+ }
+
/* Check if the chip fits between lowest valid and highest possible
* address. Highest possible address with the current SPI implementation
* means 0xffffff, the highest unsigned 24bit number.
@@ -130,7 +163,7 @@
"access window.\n");
msg_perr("Read will probably return garbage.\n");
}
- return flash->pgm->spi.read(flash, buf, addrbase + start, len);
+ return spi_programmer->read(flash, buf, addrbase + start, len);
}
/*
@@ -142,7 +175,14 @@
/* real chunksize is up to 256, logical chunksize is 256 */
int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
{
- return flash->pgm->spi.write_256(flash, buf, start, len);
+ if (!spi_programmer->write_256) {
+ msg_perr("%s called, but SPI page write is unsupported on this "
+ "hardware. Please report a bug at "
+ "flashrom@flashrom.org\n", __func__);
+ return 1;
+ }
+
+ return spi_programmer->write_256(flash, buf, start, len);
}
/*
@@ -152,7 +192,7 @@
*/
uint32_t spi_get_valid_read_addr(struct flashctx *flash)
{
- switch (flash->pgm->spi.type) {
+ switch (spi_programmer->type) {
#if CONFIG_INTERNAL == 1
#if defined(__i386__) || defined(__x86_64__)
case SPI_CONTROLLER_ICH7:
@@ -165,21 +205,8 @@
}
}
-int register_spi_programmer(const struct spi_programmer *pgm)
+void register_spi_programmer(const struct spi_programmer *pgm)
{
- struct registered_programmer rpgm;
-
- if (!pgm->write_256 || !pgm->read || !pgm->command ||
- !pgm->multicommand ||
- ((pgm->command == default_spi_send_command) &&
- (pgm->multicommand == default_spi_send_multicommand))) {
- msg_perr("%s called with incomplete programmer definition. "
- "Please report a bug at flashrom@flashrom.org\n",
- __func__);
- return ERROR_FLASHROM_BUG;
- }
-
- rpgm.buses_supported = BUS_SPI;
- rpgm.spi = *pgm;
- return register_programmer(&rpgm);
+ spi_programmer = pgm;
+ buses_supported |= BUS_SPI;
}