ft2232_spi: prevent use of reserved pins on some programmers

On some programmers an output buffer needs to be enabled by pulling a
gpio high/low. This gpio can not be used for `csgpiol`. Prevent this by
printing an error.

Change-Id: Ied450fa5ef358153adefec3beabc63a62c9f60cd
Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/57809
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/71429
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 0e95590..fadd3a4 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -419,6 +419,9 @@
 	}
 	free(arg);
 
+	/* Remember reserved pins before pindir gets modified. */
+	const uint8_t rsv_bits = pindir & 0xf0;
+
 	arg = extract_programmer_param("port");
 	if (arg) {
 		switch (toupper((unsigned char)*arg)) {
@@ -481,6 +484,15 @@
 			goto init_err;
 		}
 		unsigned int pin = temp + 4;
+
+		if (rsv_bits & 1 << pin) {
+			msg_perr("Error: Invalid GPIOL specified: \"%s\".\n"
+				 "The pin is reserved on this programmer.\n",
+				 arg);
+			free(arg);
+			return -2;
+		}
+
 		cs_bits |= 1 << pin;
 		pindir |= 1 << pin;
 	}