From b81dbc5233c89f35b51dc763d531a337d4237a8f Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Sun, 2 May 2021 19:03:58 +0200 Subject: realtek_mst_i2c_spi: Use `i2c_open_from_programmer_params` This allows using `buspath` to specify which I2C device to use. Change-Id: Ibdf07a9fde0ddfcda1c0bfa35a3e7cde5c22cedb Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/flashrom/+/52831 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan Reviewed-by: Peter Marheine --- realtek_mst_i2c_spi.c | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c index 27bcb4a0..64579e1d 100644 --- a/realtek_mst_i2c_spi.c +++ b/realtek_mst_i2c_spi.c @@ -442,38 +442,11 @@ static int realtek_mst_i2c_spi_shutdown(void *data) return ret; } -static int get_params(int *i2c_bus, int *reset, int *enter_isp) +static int get_params(int *reset, int *enter_isp) { - char *bus_str = NULL, *reset_str = NULL, *isp_str = NULL; + char *reset_str = NULL, *isp_str = NULL; int ret = SPI_GENERIC_ERROR; - bus_str = extract_programmer_param("bus"); - if (bus_str) { - char *bus_suffix; - errno = 0; - int bus = (int)strtol(bus_str, &bus_suffix, 10); - if (errno != 0 || bus_str == bus_suffix) { - msg_perr("%s: Could not convert 'bus'.\n", __func__); - goto _get_params_failed; - } - - if (bus < 0 || bus > 255) { - msg_perr("%s: Value for 'bus' is out of range(0-255).\n", __func__); - goto _get_params_failed; - } - - if (strlen(bus_suffix) > 0) { - msg_perr("%s: Garbage following 'bus' value.\n", __func__); - goto _get_params_failed; - } - - msg_pinfo("Using i2c bus %i.\n", bus); - *i2c_bus = bus; - ret = 0; - } else { - msg_perr("%s: Bus number not specified.\n", __func__); - } - reset_str = extract_programmer_param("reset-mcu"); if (reset_str) { if (reset_str[0] == '1') { @@ -504,22 +477,18 @@ static int get_params(int *i2c_bus, int *reset, int *enter_isp) } free(isp_str); -_get_params_failed: - if (bus_str) - free(bus_str); - return ret; } int realtek_mst_i2c_spi_init(void) { int ret = 0; - int i2c_bus = 0, reset = 0, enter_isp = 0; + int reset = 0, enter_isp = 0; - if (get_params(&i2c_bus, &reset, &enter_isp)) + if (get_params(&reset, &enter_isp)) return SPI_GENERIC_ERROR; - int fd = i2c_open(i2c_bus, REGISTER_ADDRESS, 0); + int fd = i2c_open_from_programmer_params(REGISTER_ADDRESS, 0); if (fd < 0) return fd; -- cgit v1.2.3