Commit 2a68889c552691edc4f3e99a6a03592a5d16d994

Con Kolivas 2014-01-04T21:51:00

Check that mcp2210 spi settings have taken and check the value of the pin during nanofury setup.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index da303b6..346e4c0 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -479,7 +479,7 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	unsigned int bitrate, icsv, acsv, cstdd, ldbtcsd, sdbd, bpst, spimode, length;
 	char buf[MCP2210_BUFFER_LENGTH];
 	bool ret = false;
-	int i;
+	int i, val;
 
 	/* Set all pins to GPIO mode */
 	for (i = 0; i < 9; i++) {
@@ -536,7 +536,14 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	length = 1;
 	if (!mcp2210_spi_transfer(bitfury, buf, &length))
 		goto out;
+	/* after this command SCK_OVRRIDE should read the same as current SCK
+	 * value (which for mode 0 should be 0) */
+	if (!mcp2210_get_gpio_pinval(bitfury, NF1_PIN_SCK_OVR, &val))
+		goto out;
+	if (val != MCP2210_GPIO_PIN_LOW)
+		goto out;
 
+	/* switch SCK to polarity (default SCK=1 in mode 2) */
 	spimode = 2;
 	if (!mcp2210_set_spi_transfer_settings(bitfury, bitrate, icsv, acsv, cstdd,
 	    ldbtcsd, sdbd, bpst, spimode))
@@ -545,7 +552,14 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	length = 1;
 	if (!mcp2210_spi_transfer(bitfury, buf, &length))
 		goto out;
+	/* after this command SCK_OVRRIDE should read the same as current SCK
+	 * value (which for mode 2 should be 1) */
+	if (!mcp2210_get_gpio_pinval(bitfury, NF1_PIN_SCK_OVR, &val))
+		goto out;
+	if (val != MCP2210_GPIO_PIN_HIGH)
+		goto out;
 
+	/* switch SCK to polarity (default SCK=0 in mode 0) */
 	spimode = 0;
 	if (!mcp2210_set_spi_transfer_settings(bitfury, bitrate, icsv, acsv, cstdd,
 	    ldbtcsd, sdbd, bpst, spimode))
@@ -554,6 +568,10 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	length = 1;
 	if (!mcp2210_spi_transfer(bitfury, buf, &length))
 		goto out;
+	if (!mcp2210_get_gpio_pinval(bitfury, NF1_PIN_SCK_OVR, &val))
+		goto out;
+	if (val != MCP2210_GPIO_PIN_LOW)
+		goto out;
 
 	info->osc6_bits = 50;
 	nf1_reinit(bitfury, info);
diff --git a/mcp2210.c b/mcp2210.c
index ede8546..efba6cc 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -279,6 +279,7 @@ mcp2210_set_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int bitrate, 
 				  unsigned int sdbd, unsigned int bpst, unsigned int spimode)
 {
 	char buf[MCP2210_BUFFER_LENGTH];
+	bool ret;
 
 	memset(buf, 0, MCP2210_BUFFER_LENGTH);
 	buf[0] = MCP2210_SET_SPI_SETTING;
@@ -307,7 +308,14 @@ mcp2210_set_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int bitrate, 
 	buf[19] = (bpst & 0xff00) >> 8;
 
 	buf[20] = spimode;
-	return mcp2210_send_recv(cgpu, buf, C_MCP_SETSPISETTING);
+	ret = mcp2210_send_recv(cgpu, buf, C_MCP_SETSPISETTING);
+	if (!ret)
+		return ret;
+	if (buf[1] != 0) {
+		applog(LOG_DEBUG, "Failed to set spi settings");
+		return false;
+	}
+	return true;
 }
 
 /* Perform an spi transfer of *length bytes and return the amount of data