Check that mcp2210 spi settings have taken and check the value of the pin during nanofury setup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
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