Commit 5ee279ca0054852aef047ead8f626423d1492283

Con Kolivas 2013-10-21T13:30:17

Add atmel init sequence likely to be required on hashfast for windows to work.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index e5757f5..19bd4f3 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -38,12 +38,12 @@ static int bitfury_open(struct cgpu_info *bitfury)
 	 * harmless on linux. */
 	buf[0] = 0x80250000;
 	buf[1] = 0x00000800;
-	err = usb_transfer(bitfury, 0, 9, 1, 0, C_BF1_RESET);
+	err = usb_transfer(bitfury, 0, 9, 1, 0, C_ATMEL_RESET);
 	if (!err)
-		err = usb_transfer(bitfury, 0x21, 0x22, 0, 0, C_BF1_OPEN);
+		err = usb_transfer(bitfury, 0x21, 0x22, 0, 0, C_ATMEL_OPEN);
 	if (!err) {
 		err = usb_transfer_data(bitfury, 0x21, 0x20, 0x0000, 0, buf,
-					BF1MSGSIZE, C_BF1_INIT);
+					BF1MSGSIZE, C_ATMEL_INIT);
 	}
 
 	if (err < 0) {
diff --git a/driver-hashfast.c b/driver-hashfast.c
index ffc010a..5832102 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -312,7 +312,6 @@ static bool hfa_detect_common(struct cgpu_info *hashfast)
 	if (!info)
 		quit(1, "Failed to calloc hashfast_info in hfa_detect_common");
 	hashfast->device_data = info;
-	hfa_clear_readbuf(hashfast);
 	/* hashfast_reset should fill in details for info */
 	ret = hfa_reset(hashfast, info);
 	if (!ret) {
@@ -340,12 +339,35 @@ static bool hfa_detect_common(struct cgpu_info *hashfast)
 	return true;
 }
 
-static void hfa_initialise(struct cgpu_info *hashfast)
+static bool hfa_initialise(struct cgpu_info *hashfast)
 {
+	int err;
+
 	if (hashfast->usbinfo.nodev)
-		return;
+		return false;
+
 	usb_buffer_enable(hashfast);
-	// FIXME Do necessary initialising here
+	hfa_clear_readbuf(hashfast);
+
+	err = usb_transfer(hashfast, 0, 9, 1, 0, C_ATMEL_RESET);
+	if (!err)
+		err = usb_transfer(hashfast, 0x21, 0x22, 0, 0, C_ATMEL_OPEN);
+	if (!err) {
+		uint32_t buf[2];
+
+		/* Magic sequence to reset device only really needed for windows
+		 * but harmless on linux. */
+		buf[0] = 0x80250000;
+		buf[1] = 0x00000800;
+		err = usb_transfer_data(hashfast, 0x21, 0x20, 0x0000, 0, buf,
+					7, C_ATMEL_INIT);
+	}
+	if (err < 0) {
+		applog(LOG_INFO, "HFA %d: Failed to open with error %s",
+		       hashfast->device_id, libusb_error_name(err));
+	}
+	/* Must have transmitted init sequence sized buffer */
+	return (err == 7);
 }
 
 static bool hfa_detect_one_usb(libusb_device *dev, struct usb_find_devices *found)
@@ -363,7 +385,10 @@ static bool hfa_detect_one_usb(libusb_device *dev, struct usb_find_devices *foun
 
 	hashfast->usbdev->usb_type = USB_TYPE_STD;
 
-	hfa_initialise(hashfast);
+	if (!hfa_initialise(hashfast)) {
+		hashfast = usb_free_cgpu(hashfast);
+		return false;
+	}
 
 	add_cgpu(hashfast);
 
diff --git a/usbutils.h b/usbutils.h
index e383f1a..be4baa4 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -331,10 +331,10 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_ENABLE_UART, "EnableUART") \
 	USB_ADD_COMMAND(C_BB_SET_VOLTAGE, "SetCoreVoltage") \
 	USB_ADD_COMMAND(C_BB_GET_VOLTAGE, "GetCoreVoltage") \
-	USB_ADD_COMMAND(C_BF1_RESET, "BF1Reset") \
-	USB_ADD_COMMAND(C_BF1_OPEN, "BF1Open") \
-	USB_ADD_COMMAND(C_BF1_INIT, "BF1Init") \
-	USB_ADD_COMMAND(C_BF1_CLOSE, "BF1Close") \
+	USB_ADD_COMMAND(C_ATMEL_RESET, "AtmelReset") \
+	USB_ADD_COMMAND(C_ATMEL_OPEN, "AtmelOpen") \
+	USB_ADD_COMMAND(C_ATMEL_INIT, "AtmelInit") \
+	USB_ADD_COMMAND(C_ATMEL_CLOSE, "AtmelClose") \
 	USB_ADD_COMMAND(C_BF1_REQINFO, "BF1RequestInfo") \
 	USB_ADD_COMMAND(C_BF1_GETINFO, "BF1GetInfo") \
 	USB_ADD_COMMAND(C_BF1_REQRESET, "BF1RequestReset") \