diff options
author | Anastasia Klimchuk <aklm@chromium.org> | 2021-10-29 15:01:05 +1100 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2022-02-02 21:51:34 +0000 |
commit | 629379029310a3f76decdeeb2199a267bfffac34 (patch) | |
tree | af3b63fb3177b183d8e210b8d5ed2e0562d88787 | |
parent | 0d7767ecdba86fc580503000d8915c052da16e62 (diff) | |
download | flashrom-629379029310a3f76decdeeb2199a267bfffac34.tar.gz flashrom-629379029310a3f76decdeeb2199a267bfffac34.tar.bz2 flashrom-629379029310a3f76decdeeb2199a267bfffac34.zip |
ichspi: Extract handling programmer param into a function
Extract processing of ich_spi_mode into a separate function which
is called from init_ich_default. This makes init_ich_default more
readable and avoids one local variable.
BUG=b:204488958
TEST=Check that the following scenarios still behave properly:
1) probe-read-verify-erase section-write-reboot
on Intel octopus board with GD25LQ128C/GD25LQ128D/GD25LQ128E
2) probe and read on Panther Point (7 series PCH)
Change-Id: I20e2379a6fd58c9346f0a2d6daf2b8decf1f6976
Tested-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: Nico Huber <nico.h@gmx.de>
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58736
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r-- | ichspi.c | 64 |
1 files changed, 37 insertions, 27 deletions
@@ -1752,20 +1752,48 @@ static int init_ich7_spi(void *spibar, enum ich_chipset ich_gen) return 0; } +enum ich_spi_mode { + ich_auto, + ich_hwseq, + ich_swseq +}; + +static int get_ich_spi_mode_param(enum ich_spi_mode *ich_spi_mode) +{ + char *const arg = extract_programmer_param("ich_spi_mode"); + if (arg && !strcmp(arg, "hwseq")) { + *ich_spi_mode = ich_hwseq; + msg_pspew("user selected hwseq\n"); + } else if (arg && !strcmp(arg, "swseq")) { + *ich_spi_mode = ich_swseq; + msg_pspew("user selected swseq\n"); + } else if (arg && !strcmp(arg, "auto")) { + msg_pspew("user selected auto\n"); + *ich_spi_mode = ich_auto; + } else if (arg && !strlen(arg)) { + msg_perr("Missing argument for ich_spi_mode.\n"); + free(arg); + return ERROR_FATAL; + } else if (arg) { + msg_perr("Unknown argument for ich_spi_mode: %s\n", arg); + free(arg); + return ERROR_FATAL; + } + free(arg); + + return 0; +} + + static int init_ich_default(void *spibar, enum ich_chipset ich_gen) { unsigned int i; uint16_t tmp2; uint32_t tmp; - char *arg; int ich_spi_rw_restricted = 0; int desc_valid = 0; struct ich_descriptors desc = { 0 }; - enum ich_spi_mode { - ich_auto, - ich_hwseq, - ich_swseq - } ich_spi_mode = ich_auto; + enum ich_spi_mode ich_spi_mode = ich_auto; size_t num_freg, num_pr, reg_pr0; /* Moving registers / bits */ @@ -1818,27 +1846,9 @@ static int init_ich_default(void *spibar, enum ich_chipset ich_gen) break; } - arg = extract_programmer_param("ich_spi_mode"); - if (arg && !strcmp(arg, "hwseq")) { - ich_spi_mode = ich_hwseq; - msg_pspew("user selected hwseq\n"); - } else if (arg && !strcmp(arg, "swseq")) { - ich_spi_mode = ich_swseq; - msg_pspew("user selected swseq\n"); - } else if (arg && !strcmp(arg, "auto")) { - msg_pspew("user selected auto\n"); - ich_spi_mode = ich_auto; - } else if (arg && !strlen(arg)) { - msg_perr("Missing argument for ich_spi_mode.\n"); - free(arg); - return ERROR_FATAL; - } else if (arg) { - msg_perr("Unknown argument for ich_spi_mode: %s\n", - arg); - free(arg); - return ERROR_FATAL; - } - free(arg); + int ret = get_ich_spi_mode_param(&ich_spi_mode); + if (ret) + return ret; tmp2 = mmio_readw(spibar + ICH9_REG_HSFS); msg_pdbg("0x04: 0x%04x (HSFS)\n", tmp2); |