Commit 8f4ec3af7141804a7712c85763770d6d41733a0c

Con Kolivas 2014-01-04T09:25:30

Implement initial part of nanofury init sequence for GPIO pin settings and add output debugging of set values.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index 8504f90..7211019 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -277,6 +277,49 @@ out_close:
 	return false;
 }
 
+static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	bool ret = false;
+	int i;
+
+	/* Set all pins to GPIO mode */
+	for (i = 0; i < 9; i++) {
+		if (!mcp2210_set_gpio_pindes(bitfury, i, MCP2210_PIN_GPIO))
+			return ret;
+	}
+	/* Set all pins to input mode */
+	for (i = 0; i < 9; i++) {
+		if (!mcp2210_set_gpio_pindir(bitfury, i, MCP2210_GPIO_INPUT))
+			return ret;
+	}
+	if (!mcp2210_set_gpio_pindir(bitfury, NF1_PIN_LED, MCP2210_GPIO_OUTPUT))
+		return ret;
+	if (!mcp2210_set_gpio_pindir(bitfury, NF1_PIN_PWR_EN, MCP2210_GPIO_OUTPUT))
+		return ret;
+
+	if (opt_debug) {
+		struct gpio_pin gp;
+
+		mcp2210_get_gpio_pindirs(bitfury, &gp);
+		for (i = 0; i < 9; i++) {
+			applog(LOG_DEBUG, "%s %d: Pin dir %d %d", bitfury->drv->name,
+			       bitfury->device_id, i, gp.pin[i]);
+		}
+		mcp2210_get_gpio_pinvals(bitfury, &gp);
+		for (i = 0; i < 9; i++) {
+			applog(LOG_DEBUG, "%s %d: Pin val %d %d", bitfury->drv->name,
+			       bitfury->device_id, i, gp.pin[i]);
+		}
+		mcp2210_get_gpio_pindes(bitfury, &gp);
+		for (i = 0; i < 9; i++) {
+			applog(LOG_DEBUG, "%s %d: Pin des %d %d", bitfury->drv->name,
+			       bitfury->device_id, i, gp.pin[i]);
+		}
+	}
+out:
+	return ret;
+}
+
 static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
 {
 	struct cgpu_info *bitfury;
@@ -303,6 +346,9 @@ static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct us
 		case IDENT_BXF:
 			ret = bxf_detect_one(bitfury, info);
 			break;
+		case IDENT_NF1:
+			ret = nf1_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 9412076..0a5f99e 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -24,6 +24,10 @@
 
 extern int opt_bxf_temp_target;
 
+#define NF1_PIN_LED 0
+#define NF1_PIN_SCK_OVR 5
+#define NF1_PIN_PWR_EN 6
+
 struct bitfury_info {
 	struct cgpu_info *base_cgpu;
 	struct thr_info *thr;