Skip to content

Commit

Permalink
spi25.c: Move spi_get_opcode_from_erasefn() to spi.c
Browse files Browse the repository at this point in the history
Split spi_get_opcode_from_erasefn() out into spi.c to add support for
non spi25 flashes next.

Change-Id: Id654e998d0af2d3f5845336bb98b38d724519038
Signed-off-by: Thomas Heijligen <[email protected]>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/67715
Reviewed-by: Thomas Heijligen <[email protected]>
Reviewed-by: Edward O'Callaghan <[email protected]>
Tested-by: build bot (Jenkins) <[email protected]>
  • Loading branch information
heijligen committed Dec 14, 2022
1 parent 76f28a3 commit cb99e8a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
34 changes: 34 additions & 0 deletions spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,37 @@ int register_spi_master(const struct spi_master *mst, void *data)
rmst.spi.data = data;
return register_master(&rmst);
}

static const struct {
enum block_erase_func func;
uint8_t opcode;
} function_opcode_list[] = {
{SPI_BLOCK_ERASE_20, 0x20},
{SPI_BLOCK_ERASE_21, 0x21},
{SPI_BLOCK_ERASE_50, 0x50},
{SPI_BLOCK_ERASE_52, 0x52},
{SPI_BLOCK_ERASE_53, 0x53},
{SPI_BLOCK_ERASE_5C, 0x5c},
{SPI_BLOCK_ERASE_60, 0x60},
{SPI_BLOCK_ERASE_62, 0x62},
{SPI_BLOCK_ERASE_81, 0x81},
{SPI_BLOCK_ERASE_C4, 0xc4},
{SPI_BLOCK_ERASE_C7, 0xc7},
{SPI_BLOCK_ERASE_D7, 0xd7},
{SPI_BLOCK_ERASE_D8, 0xd8},
{SPI_BLOCK_ERASE_DB, 0xdb},
{SPI_BLOCK_ERASE_DC, 0xdc},
};

uint8_t spi_get_opcode_from_erasefn(enum block_erase_func func)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(function_opcode_list); i++) {
if (function_opcode_list[i].func == func)
return function_opcode_list[i].opcode;
}
msg_cinfo("%s: unknown erase function (0x%d). Please report "
"this at [email protected]\n", __func__, func);
return 0x00; //Assuming 0x00 is not a erase function opcode
}

12 changes: 0 additions & 12 deletions spi25.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,18 +651,6 @@ enum block_erase_func spi_get_erasefn_from_opcode(uint8_t opcode)
return NO_BLOCK_ERASE_FUNC;
}

uint8_t spi_get_opcode_from_erasefn(enum block_erase_func func)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(function_opcode_list); i++) {
if (function_opcode_list[i].func == func)
return function_opcode_list[i].opcode;
}
msg_cinfo("%s: unknown erase function (0x%d). Please report "
"this at [email protected]\n", __func__, func);
return 0x00; //Assuming 0x00 is not a erase function opcode
}

static int spi_nbyte_program(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len)
{
const bool native_4ba = flash->chip->feature_bits & FEATURE_4BA_WRITE && spi_master_4ba(flash);
Expand Down

0 comments on commit cb99e8a

Please sign in to comment.