Angel Pons has uploaded this change for review.

View Change

ft2232_spi.c: Split out most programmer param parsing

Separate most programmer parameter parsing into a helper function.

Change-Id: I25faac1060fc2bcd6042e34802e5bc493c936377
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
---
M ft2232_spi.c
1 file changed, 52 insertions(+), 29 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/08/67908/1
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 4edbf71..b41ee74 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -326,37 +326,10 @@
uint8_t pindir_high;
};

-/* Returns 0 upon success, a negative number upon errors. */
-static int ft2232_spi_init(const struct programmer_cfg *cfg)
+static int ft2232_get_params(struct ft2232_parameters *const parameters, const struct programmer_cfg *cfg)
{
- int ret = 0;
- unsigned char buf[512];
int channel_count = 4; /* Stores the number of channels of the device. */
- /*
- * The 'H' chips can run with an internal clock of either 12 MHz or 60 MHz,
- * but the non-H chips can only run at 12 MHz. We disable the divide-by-5
- * prescaler on 'H' chips so they run at 60MHz.
- */
- bool clock_5x = true;
- int f;
- char *arg, *arg2;
- double mpsse_clk;
-
- struct ft2232_parameters programmer_parameters = {
- .ft2232_vid = FTDI_VID,
- .ft2232_type = FTDI_FT4232H_PID,
- .ft2232_interface = INTERFACE_A,
- .divisor = DEFAULT_DIVISOR,
- .cs_bits = 0x08,
- .aux_bits = 0x00,
- .pindir = 0x0b,
- .aux_bits_high = 0x00,
- .pindir_high = 0x00,
- };
- struct ft2232_parameters *const parameters = &programmer_parameters;
-
- struct ftdi_context ftdic;
- struct ft2232_data *spi_data;
+ char *arg;

arg = extract_programmer_param_str(cfg, "type");
if (arg) {
@@ -603,6 +576,44 @@
return -2;
}

+ return 0;
+}
+
+/* Returns 0 upon success, a negative number upon errors. */
+static int ft2232_spi_init(const struct programmer_cfg *cfg)
+{
+ int ret;
+ unsigned char buf[512];
+ /*
+ * The 'H' chips can run with an internal clock of either 12 MHz or 60 MHz,
+ * but the non-H chips can only run at 12 MHz. We disable the divide-by-5
+ * prescaler on 'H' chips so they run at 60MHz.
+ */
+ bool clock_5x = true;
+ int f;
+ char *arg, *arg2;
+ double mpsse_clk;
+
+ struct ft2232_parameters programmer_parameters = {
+ .ft2232_vid = FTDI_VID,
+ .ft2232_type = FTDI_FT4232H_PID,
+ .ft2232_interface = INTERFACE_A,
+ .divisor = DEFAULT_DIVISOR,
+ .cs_bits = 0x08,
+ .aux_bits = 0x00,
+ .pindir = 0x0b,
+ .aux_bits_high = 0x00,
+ .pindir_high = 0x00,
+ };
+ struct ft2232_parameters *const parameters = &programmer_parameters;
+
+ struct ftdi_context ftdic;
+ struct ft2232_data *spi_data;
+
+ ret = ft2232_get_params(parameters, cfg);
+ if (ret)
+ return ret;
+
msg_pdbg("Using device type %s %s ",
get_ft2232_vendorname(parameters->ft2232_vid, parameters->ft2232_type),
get_ft2232_devicename(parameters->ft2232_vid, parameters->ft2232_type));

To view, visit change 67908. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I25faac1060fc2bcd6042e34802e5bc493c936377
Gerrit-Change-Number: 67908
Gerrit-PatchSet: 1
Gerrit-Owner: Angel Pons <th3fanbus@gmail.com>
Gerrit-MessageType: newchange