Commit 5107a133b746bd034c0306621def64674296d236

Con Kolivas 2014-03-02T16:04:15

Add a bxm specific txrx function for spi transfers.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index 30028c5..ed694da 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -520,6 +520,36 @@ static uint16_t calc_divisor(uint32_t system_clock, uint32_t freq)
 	return divisor;
 }
 
+static bool bxm_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	int err, amount, len;
+	uint16_t length;
+	char buf[1024];
+
+	len = info->spibufsz;
+	length = info->spibufsz - 1; //FTDI length is shifted by one 0x0000 = one byte
+	buf[0] = READ_WRITE_BYTES_SPI0;
+	buf[1] = length & 0x00FF;
+	buf[2] = (length & 0xFF00) >> 8;
+	memcpy(&buf[3], info->spibuf, info->spibufsz);
+	info->spibufsz += 3;
+	err = usb_write(bitfury, buf, info->spibufsz, &amount, C_BXM_SPITX);
+	if (err || amount != info->spibufsz) {
+		applog(LOG_ERR, "%s %d: SPI TX error %d, sent %d of %d", bitfury->drv->name,
+		       bitfury->device_id, err, amount, info->spibufsz);
+		return false;
+	}
+	info->spibufsz = len;
+	/* We shouldn't even get a timeout error on reads in spi mode */
+	err = usb_read(bitfury, info->spibuf, len, &amount, C_BXM_SPIRX);
+	if (err || amount != len) {
+		applog(LOG_ERR, "%s %d: SPI RX error %d, read %d of %d", bitfury->drv->name,
+		       bitfury->device_id, err, amount, info->spibufsz);
+		return false;
+	}
+	return true;
+}
+
 static void bxm_close(struct cgpu_info *bitfury)
 {
 	unsigned char bitmask = 0;
diff --git a/usbutils.h b/usbutils.h
index e93d1f7..a79e3cb 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -386,6 +386,8 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_BXM_CSLOW, "BXMCSLow") \
 	USB_ADD_COMMAND(C_BXM_CSHIGH, "BXMCSHigh") \
 	USB_ADD_COMMAND(C_BXM_RESET, "BXMReset") \
+	USB_ADD_COMMAND(C_BXM_SPITX, "BXMSPITX") \
+	USB_ADD_COMMAND(C_BXM_SPIRX, "BXMSPIRX") \
 	USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
 	USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
 	USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \