dediprog: Add protocol detection for SF700 & SF600Plus-G2

The short-lived SF700 was not tested but is treated the same as an
SF600Plus-G2 by `dpcmd'.  Both programmers have their own firmware
versioning:  For the SF700, only clues about firmware versions 4.x
were found. The SF600Plus-G2 seems to start anew from version 1.x.

Given that the SF700 was introduced in 2019 [1], after support for
the current protocol was added to flashrom in commit f73f8a732f8fd
(dediprog: implement command spec for firmware >= 7.2.30), it most
likely never supported any older protocol version.

Tested with "SF600PG2. V:01.01.012 HW:01.00", "V:01.01.006 HW:01.00".

[1] https://www.dediprog.com/news/show?id=196

Change-Id: I8d2c9612e422cedbf91b42432b1832abaaf95c62
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/94
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/dediprog.c b/dediprog.c
index c7b4ae8..52161f1 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -48,6 +48,8 @@
 	DEV_SF100		= 100,
 	DEV_SF200		= 200,
 	DEV_SF600		= 600,
+	DEV_SF600PG2		= 600+2,
+	DEV_SF700		= 700,
 };
 
 enum dediprog_leds {
@@ -195,6 +197,9 @@
 			return PROTOCOL_V2;
 		else
 			return PROTOCOL_V3;
+	case DEV_SF700:
+	case DEV_SF600PG2:
+		return PROTOCOL_V3;
 	default:
 		return PROTOCOL_UNKNOWN;
 	}
@@ -351,7 +356,7 @@
 
 static int dediprog_set_spi_speed(unsigned int spispeed_idx, const struct dediprog_data *dp_data)
 {
-	if (dp_data->firmwareversion < FIRMWARE_VERSION(5, 0, 0)) {
+	if (dp_data->devicetype < DEV_SF600PG2 && dp_data->firmwareversion < FIRMWARE_VERSION(5, 0, 0)) {
 		msg_pwarn("Skipping to set SPI speed because firmware is too old.\n");
 		return 0;
 	}
@@ -832,23 +837,30 @@
 		dp_data->devicetype = DEV_SF100;
 	else if (memcmp(buf, "SF200", 5) == 0)
 		dp_data->devicetype = DEV_SF200;
+	else if (memcmp(buf, "SF600PG2", 8) == 0) /* match first, before shorter, generic SF600 */
+		dp_data->devicetype = DEV_SF600PG2;
 	else if (memcmp(buf, "SF600", 5) == 0)
 		dp_data->devicetype = DEV_SF600;
+	else if (memcmp(buf, "SF700", 5) == 0)
+		dp_data->devicetype = DEV_SF700;
 	else {
-		msg_perr("Device not a SF100, SF200, or SF600!\n");
+		msg_perr("Device not a SF100, SF200, SF600(Plus(-G2)), or SF700!\n");
 		return 1;
 	}
 
 	unsigned int sfnum;
 	unsigned int fw[3];
 	if (sscanf(buf, "SF%u", &sfnum) != 1 ||
-	    sfnum != dp_data->devicetype ||
+	    sfnum != dp_data->devicetype / 100 * 100 ||
 	    sscanf(buf, "SF%*s V:%u.%u.%u ", &fw[0], &fw[1], &fw[2]) != 3) {
 		msg_perr("Unexpected firmware version string '%s'\n", buf);
 		return 1;
 	}
-	/* Only these major versions were tested. */
-	if (fw[0] < 2 || fw[0] > 7) {
+
+	/* Only allow major versions that were tested. */
+	if ((dp_data->devicetype == DEV_SF600PG2 && fw[0] > 1) ||
+	    (dp_data->devicetype == DEV_SF700    && fw[0] != 4) ||
+	    (dp_data->devicetype <= DEV_SF600    && (fw[0] < 2 || fw[0] > 7))) {
 		msg_perr("Unexpected firmware version %d.%d.%d!\n", fw[0], fw[1], fw[2]);
 		return 1;
 	}