Set the mcp2210 transfer setting only when it changes.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
diff --git a/driver-bitfury.c b/driver-bitfury.c
index e5f7a0e..3bad374 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -377,7 +377,7 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
buf[0] = 0;
length = 1;
- if (!mcp2210_spi_transfer(bitfury, buf, &length))
+ if (!mcp2210_spi_transfer(bitfury, mcp, buf, &length))
goto out;
/* after this command SCK_OVRRIDE should read the same as current SCK
* value (which for mode 0 should be 0) */
@@ -392,7 +392,7 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
goto out;
buf[0] = 0;
length = 1;
- if (!mcp2210_spi_transfer(bitfury, buf, &length))
+ if (!mcp2210_spi_transfer(bitfury, mcp, buf, &length))
goto out;
/* after this command SCK_OVRRIDE should read the same as current SCK
* value (which for mode 2 should be 1) */
@@ -407,7 +407,7 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
goto out;
buf[0] = 0;
length = 1;
- if (!mcp2210_spi_transfer(bitfury, buf, &length))
+ if (!mcp2210_spi_transfer(bitfury, mcp, buf, &length))
goto out;
if (!mcp2210_get_gpio_pinval(bitfury, NF1_PIN_SCK_OVR, &val))
goto out;
diff --git a/driver-bitfury.h b/driver-bitfury.h
index cc20591..30d7e4d 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -87,7 +87,6 @@ struct bitfury_info {
unsigned oldbuf[17];
int job_switched;
unsigned int results[16];
- int results_n;
struct work *work;
struct work *owork;
};
diff --git a/libbitfury.c b/libbitfury.c
index e32828b..17f2cc1 100644
--- a/libbitfury.c
+++ b/libbitfury.c
@@ -230,7 +230,7 @@ bool spi_reset(struct cgpu_info *bitfury, struct bitfury_info *info)
char buf[1] = {0x81}; // will send this waveform: - _ _ _ _ _ _ -
unsigned int length = 1;
- if (!mcp2210_spi_transfer(bitfury, buf, &length))
+ if (!mcp2210_spi_transfer(bitfury, &info->mcp, buf, &length))
return false;
}
@@ -252,7 +252,7 @@ bool spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
bitfury->device_id, length);
while (length > MCP2210_TRANSFER_MAX) {
sendrcv = MCP2210_TRANSFER_MAX;
- if (!mcp2210_spi_transfer(bitfury, info->spibuf + offset, &sendrcv))
+ if (!mcp2210_spi_transfer(bitfury, &info->mcp, info->spibuf + offset, &sendrcv))
return false;
if (sendrcv != MCP2210_TRANSFER_MAX) {
applog(LOG_DEBUG, "%s %d: Send/Receive size mismatch sent %d received %d",
@@ -262,7 +262,7 @@ bool spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
offset += MCP2210_TRANSFER_MAX;
}
sendrcv = length;
- if (!mcp2210_spi_transfer(bitfury, info->spibuf + offset, &sendrcv))
+ if (!mcp2210_spi_transfer(bitfury, &info->mcp, info->spibuf + offset, &sendrcv))
return false;
if (sendrcv != length) {
applog(LOG_WARNING, "%s %d: Send/Receive size mismatch sent %d received %d",
diff --git a/mcp2210.c b/mcp2210.c
index 2906651..83ff95f 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -299,10 +299,10 @@ mcp2210_set_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int bitrate,
/* Perform an spi transfer of *length bytes and return the amount of data
* returned in the same buffer in *length */
-bool mcp2210_spi_transfer(struct cgpu_info *cgpu, char *data, unsigned int *length)
+bool mcp2210_spi_transfer(struct cgpu_info *cgpu, struct mcp_settings *mcp,
+ char *data, unsigned int *length)
{
- unsigned int bitrate, icsv, acsv, cstdd, ldbtcsd, sdbd, bpst, spimode;
- uint8_t res, status, orig_len, len, offset = 0;
+ uint8_t res, status, orig_len, offset = 0;
char buf[MCP2210_BUFFER_LENGTH];
if (unlikely(*length > MCP2210_TRANSFER_MAX || !*length)) {
@@ -310,14 +310,14 @@ bool mcp2210_spi_transfer(struct cgpu_info *cgpu, char *data, unsigned int *leng
cgpu->device_id, *length);
return false;
}
- if (!mcp2210_get_spi_transfer_settings(cgpu, &bitrate, &icsv, &acsv, &cstdd,
- &ldbtcsd, &sdbd, &bpst, &spimode))
- return false;
- bpst = *length;
- if (!mcp2210_set_spi_transfer_settings(cgpu, bitrate, icsv, acsv, cstdd,
- ldbtcsd, sdbd, bpst, spimode))
- return false;
- orig_len = len = *length;
+ if (mcp->bpst != *length) {
+ /* Set the transfer setting only when it changes. */
+ mcp->bpst = *length;
+ if (!mcp2210_set_spi_transfer_settings(cgpu, mcp->bitrate, mcp->icsv,
+ mcp->acsv, mcp->cstdd, mcp->ldbtcsd, mcp->sdbd, mcp->bpst, mcp->spimode))
+ return false;
+ }
+ orig_len = *length;
retry:
applog(LOG_DEBUG, "%s %d: SPI sending %u bytes", cgpu->drv->name, cgpu->device_id,
*length);
@@ -333,7 +333,6 @@ retry:
res = (uint8_t)buf[1];
switch(res) {
case MCP2210_SPI_TRANSFER_SUCCESS:
- len -= *length;
*length = buf[2];
status = buf[3];
applog(LOG_DEBUG, "%s %d: SPI transfer success, received %u bytes status 0x%x",
diff --git a/mcp2210.h b/mcp2210.h
index 2b9c3d1..cb75443 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -67,6 +67,7 @@ bool
mcp2210_set_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int bitrate, unsigned int icsv,
unsigned int acsv, unsigned int cstdd, unsigned int ldbtcsd,
unsigned int sdbd, unsigned int bpst, unsigned int spimode);
-bool mcp2210_spi_transfer(struct cgpu_info *cgpu, char *data, unsigned int *length);
+bool mcp2210_spi_transfer(struct cgpu_info *cgpu, struct mcp_settings *mcp,
+ char *data, unsigned int *length);
#endif /* MCP2210_H */