Commit 6b532de05ca55637fb8ed6bf0e76dd036aecd3b8

Con Kolivas 2014-01-04T09:38:05

Cancel any SPI transfers in progress in nanofury after initial setup.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index d5fbf32..765724f 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -277,7 +277,7 @@ out_close:
 	return false;
 }
 
-static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
+static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info __maybe_unused *info)
 {
 	bool ret = false;
 	int i;
@@ -285,21 +285,23 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	/* Set all pins to GPIO mode */
 	for (i = 0; i < 9; i++) {
 		if (!mcp2210_set_gpio_pindes(bitfury, i, MCP2210_PIN_GPIO))
-			return ret;
+			goto out;
 	}
 	/* Set all pins to input mode */
 	for (i = 0; i < 9; i++) {
 		if (!mcp2210_set_gpio_pindir(bitfury, i, MCP2210_GPIO_INPUT))
-			return ret;
+			goto out;
 	}
+
+	/* Set LED and PWR pins to output and high */
 	if (!mcp2210_set_gpio_pindir(bitfury, NF1_PIN_LED, MCP2210_GPIO_OUTPUT))
-		return ret;
+		goto out;
 	if (!mcp2210_set_gpio_pinval(bitfury, NF1_PIN_LED, MCP2210_GPIO_PIN_HIGH))
-		return ret;
+		goto out;
 	if (!mcp2210_set_gpio_pindir(bitfury, NF1_PIN_PWR_EN, MCP2210_GPIO_OUTPUT))
-		return ret;
+		goto out;
 	if (!mcp2210_set_gpio_pinval(bitfury, NF1_PIN_PWR_EN, MCP2210_GPIO_PIN_HIGH))
-		return ret;
+		goto out;
 
 	if (opt_debug) {
 		struct gpio_pin gp;
@@ -320,6 +322,10 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 			       bitfury->device_id, i, gp.pin[i]);
 		}
 	}
+
+	/* Cancel any transfers in progress */
+	if (!mcp2210_spi_cancel(bitfury))
+		goto out;
 out:
 	return ret;
 }
diff --git a/mcp2210.h b/mcp2210.h
index 3c811dd..563fdd3 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -51,5 +51,6 @@ bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val);
 bool mcp2210_set_gpio_pinval(struct cgpu_info *cgpu, int pin, int val);
 bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir);
 bool mcp2210_set_gpio_pindir(struct cgpu_info *cgpu, int pin, int dir);
+bool mcp2210_spi_cancel(struct cgpu_info *cgpu);
 
 #endif /* MCP2210_H */