Commit 917507ec2ba530e7fa0de0c772e370a9278daf20

Con Kolivas 2014-03-02T13:59:59

Add initial bxm opening sequence for detect one.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index 1d50e42..6b74390 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -436,6 +436,49 @@ out:
 	return ret;
 }
 
+static void bxm_empty_buffer(struct cgpu_info *bitfury)
+{
+	char buf[512];
+	int amount;
+
+	do {
+		usb_read_once(bitfury, buf, 512, &amount, C_BXM_FLUSH);
+	} while (amount);
+}
+
+static bool bxm_open(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	char buf[4];
+	int err;
+
+	bxm_empty_buffer(bitfury);
+	/* Device likes being reset first. */
+	usb_reset(bitfury);
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_RESET_REQUEST, SIO_RESET_SIO, 1, C_BXM_RESET);
+	if (err)
+		return false;
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_SET_LATENCY_TIMER_REQUEST, BXM_LATENCY_MS, 1, C_BXM_SETLATENCY);
+	if (err)
+		return false;
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_SET_EVENT_CHAR_REQUEST, 0x00, 1, C_BXM_SECR);
+	if (err)
+		return false;
+
+	return true;
+}
+
+static bool bxm_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	bool ret;
+
+	ret = bxm_open(bitfury, info);
+	if (ret) {
+		applog(LOG_INFO, "%s %d: Successfully opened at %s", bitfury->drv->name, bitfury->device_id,
+		       bitfury->device_path);
+	}
+	return ret;
+}
+
 static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
 {
 	struct cgpu_info *bitfury;
@@ -465,6 +508,9 @@ static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct us
 		case IDENT_NF1:
 			ret = nf1_detect_one(bitfury, info);
 			break;
+		case IDENT_BXM:
+			ret = bxm_detect_one(bitfury, info);
+			break;
 		default:
 			applog(LOG_INFO, "%s %d: Unrecognised bitfury device",
 			       bitfury->drv->name, bitfury->device_id);
diff --git a/driver-bitfury.h b/driver-bitfury.h
index a9f05a2..f7af174 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -33,6 +33,20 @@ extern int opt_nf1_bits;
 #define SPIBUF_SIZE 16384
 #define BITFURY_REFRESH_DELAY 100
 
+#define SIO_RESET_REQUEST 0
+#define SIO_SET_LATENCY_TIMER_REQUEST 0x09
+#define SIO_SET_EVENT_CHAR_REQUEST    0x06
+#define SIO_SET_ERROR_CHAR_REQUEST    0x07
+#define SIO_SET_BITMODE_REQUEST       0x0B
+#define SIO_RESET_PURGE_RX 1
+#define SIO_RESET_PURGE_TX 2
+
+#define BITMODE_RESET 0x00
+#define BITMODE_MPSSE 0x02
+#define SIO_RESET_SIO 0
+
+#define BXM_LATENCY_MS 2
+
 struct bitfury_payload {
 	unsigned char midstate[32];
 	unsigned int junk[8];
diff --git a/usbutils.h b/usbutils.h
index 9fcd4f2..fa97d90 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -371,6 +371,10 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_BXF_MAXROLL, "BXFMaxRoll") \
 	USB_ADD_COMMAND(C_BXF_FLUSH, "BXFFlush") \
 	USB_ADD_COMMAND(C_BXF_CLOCK, "BXFClock") \
+	USB_ADD_COMMAND(C_BXM_FLUSH, "BXMFlush") \
+	USB_ADD_COMMAND(C_BXM_RESET, "BXMReset") \
+	USB_ADD_COMMAND(C_BXM_SETLATENCY, "BXMSetLatency") \
+	USB_ADD_COMMAND(C_BXM_SECR, "BXMSetEventCharRequest") \
 	USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
 	USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
 	USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \