Store the spi settings in a struct for nanofury devices.
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
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 346e4c0..2dbc3ad 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -474,10 +474,18 @@ static void nf1_reinit(struct cgpu_info *bitfury, struct bitfury_info *info)
nf1_spi_txrx(bitfury, info);
}
+static bool nf1_set_spi_settings(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ struct mcp_settings *mcp = &info->mcp;
+
+ return mcp2210_set_spi_transfer_settings(bitfury, mcp->bitrate, mcp->icsv,
+ mcp->acsv, mcp->cstdd, mcp->ldbtcsd, mcp->sdbd, mcp->bpst, mcp->spimode);
+}
+
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];
+ unsigned int length;
bool ret = false;
int i, val;
@@ -521,15 +529,16 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
/* Cancel any transfers in progress */
if (!mcp2210_spi_cancel(bitfury))
goto out;
- if (!mcp2210_get_spi_transfer_settings(bitfury, &bitrate, &icsv, &acsv, &cstdd,
- &ldbtcsd, &sdbd, &bpst, &spimode))
+ if (!mcp2210_get_spi_transfer_settings(bitfury, &info->mcp.bitrate, &info->mcp.icsv,
+ &info->mcp.acsv, &info->mcp.cstdd, &info->mcp.ldbtcsd, &info->mcp.sdbd,
+ &info->mcp.bpst, &info->mcp.spimode))
goto out;
- bitrate = 200000;
- icsv = 0xffff;
- acsv = 0xffef;
- cstdd = ldbtcsd = sdbd = spimode = 0;
- if (!mcp2210_set_spi_transfer_settings(bitfury, bitrate, icsv, acsv, cstdd,
- ldbtcsd, sdbd, bpst, spimode))
+ info->mcp.bitrate = 12000000;
+ info->mcp.icsv = 0xffff;
+ info->mcp.acsv = 0xffef;
+ info->mcp.cstdd = info->mcp.ldbtcsd = info->mcp.sdbd = info->mcp.spimode = 0;
+ info->mcp.sdbd = 1;
+ if (!nf1_set_spi_settings(bitfury, info))
goto out;
buf[0] = 0;
@@ -544,9 +553,8 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
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))
+ info->mcp.spimode = 2;
+ if (!nf1_set_spi_settings(bitfury, info))
goto out;
buf[0] = 0;
length = 1;
@@ -560,9 +568,8 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
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))
+ info->mcp.spimode = 0;
+ if (!nf1_set_spi_settings(bitfury, info))
goto out;
buf[0] = 0;
length = 1;
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 6a80e07..c5cb9ba 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -31,6 +31,10 @@ extern int opt_bxf_temp_target;
#define NF1_SPIBUF_SIZE 16384
+struct mcp_settings {
+ unsigned int bitrate, icsv, acsv, cstdd, ldbtcsd, sdbd, bpst, spimode;
+};
+
struct bitfury_info {
struct cgpu_info *base_cgpu;
struct thr_info *thr;
@@ -67,6 +71,7 @@ struct bitfury_info {
int submits[2]; // Submitted responses
/* NF1 specific data */
+ struct mcp_settings mcp;
char spibuf[NF1_SPIBUF_SIZE];
unsigned int spibufsz;
int osc6_bits;