summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-10-08 22:30:25 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2022-10-22 00:45:03 +0000
commit759a0566733b3d8d64de3534140ba05a40bc4bd5 (patch)
tree3a476d3e2e8e055b9364ada77e96de2ceacd2ebf
parent1837f0df2798b2fc6f953853976c622c8e26637b (diff)
downloadflashrom-759a0566733b3d8d64de3534140ba05a40bc4bd5.tar.gz
flashrom-759a0566733b3d8d64de3534140ba05a40bc4bd5.tar.bz2
flashrom-759a0566733b3d8d64de3534140ba05a40bc4bd5.zip
rayer_spi.c: Roll up programmer type search logic into func
Roll up the programmer type table search and match logic into it's own function and lexically scope the 'rayer_spi_types' table into the function while we are here. Change-Id: Id226ea61132ecc30fd8696e1d8ea50373e752cac Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/68238 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
-rw-r--r--rayer_spi.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/rayer_spi.c b/rayer_spi.c
index 41c536424..9be41e76c 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -174,16 +174,6 @@ static const struct rayer_pinout spi_tt = {
.miso_bit = 7,
};
-static const struct rayer_programmer rayer_spi_types[] = {
- {"rayer", NT, "RayeR SPIPGM", &rayer_spipgm},
- {"xilinx", NT, "Xilinx Parallel Cable III (DLC 5)", &xilinx_dlc5},
- {"byteblastermv", OK, "Altera ByteBlasterMV", &altera_byteblastermv},
- {"stk200", NT, "Atmel STK200/300 adapter", &atmel_stk200},
- {"wiggler", OK, "Wiggler LPT", &wiggler_lpt},
- {"spi_tt", NT, "SPI Tiny Tools (SPI_TT LPT)", &spi_tt},
- {0},
-};
-
static void rayer_bitbang_set_cs(int val, void *spi_data)
{
struct rayer_spi_data *data = spi_data;
@@ -235,6 +225,35 @@ static const struct bitbang_spi_master bitbang_spi_master_rayer = {
.half_period = 0,
};
+static const struct rayer_programmer *find_progtype(const char *prog_type)
+{
+ static const struct rayer_programmer rayer_spi_types[] = {
+ {"rayer", NT, "RayeR SPIPGM", &rayer_spipgm},
+ {"xilinx", NT, "Xilinx Parallel Cable III (DLC 5)", &xilinx_dlc5},
+ {"byteblastermv", OK, "Altera ByteBlasterMV", &altera_byteblastermv},
+ {"stk200", NT, "Atmel STK200/300 adapter", &atmel_stk200},
+ {"wiggler", OK, "Wiggler LPT", &wiggler_lpt},
+ {"spi_tt", NT, "SPI Tiny Tools (SPI_TT LPT)", &spi_tt},
+ {0},
+ };
+ if (!prog_type)
+ return &rayer_spi_types[0];
+
+ const struct rayer_programmer *prog = rayer_spi_types;
+ for (; prog->type != NULL; prog++) {
+ if (strcasecmp(prog_type, prog->type) == 0) {
+ break;
+ }
+ }
+
+ if (!prog->type) {
+ msg_perr("Error: Invalid device type specified.\n");
+ return NULL;
+ }
+
+ return prog;
+}
+
static int get_params(const struct programmer_cfg *cfg, uint16_t *lpt_iobase, char **prog_type)
{
/* Pick a default value for the I/O base. */
@@ -280,7 +299,6 @@ static int get_params(const struct programmer_cfg *cfg, uint16_t *lpt_iobase, ch
static int rayer_spi_init(const struct programmer_cfg *cfg)
{
- const struct rayer_programmer *prog = rayer_spi_types;
struct rayer_pinout *pinout = NULL;
uint16_t lpt_iobase;
char *prog_type;
@@ -288,19 +306,10 @@ static int rayer_spi_init(const struct programmer_cfg *cfg)
if (get_params(cfg, &lpt_iobase, &prog_type) < 0)
return 1;
- if (prog_type) {
- for (; prog->type != NULL; prog++) {
- if (strcasecmp(prog_type, prog->type) == 0) {
- break;
- }
- }
- free(prog_type);
-
- if (prog->type == NULL) {
- msg_perr("Error: Invalid device type specified.\n");
- return 1;
- }
- }
+ const struct rayer_programmer *prog = find_progtype(prog_type);
+ free(prog_type);
+ if (!prog)
+ return 1;
msg_pdbg("Using address 0x%x as I/O base for parallel port access.\n",
lpt_iobase);