Commit a01fbc302f97e429bc48368aabd05da90c887d19

Con Kolivas 2014-01-04T20:35:59

Move the set gpio output function to a generic mcp2210 version from nanofury which also sets the pin to gpio.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index e1a5338..5f59402 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -408,15 +408,6 @@ static void nf1_send_init(struct bitfury_info *info)
 	spi_add_data(info, 0x3000, atrvec, 19 * 4);
 }
 
-static bool nf1_set_gpio_output(struct cgpu_info *bitfury, int pin, int val)
-{
-	if (!mcp2210_set_gpio_pindir(bitfury, pin, MCP2210_GPIO_OUTPUT))
-		return false;
-	if (!mcp2210_set_gpio_pinval(bitfury, pin, val))
-		return false;
-	return true;
-}
-
 // Bit-banging reset... Each 3 reset cycles reset first chip in chain
 static bool nf1_spi_reset(struct cgpu_info *bitfury)
 {
@@ -424,7 +415,7 @@ static bool nf1_spi_reset(struct cgpu_info *bitfury)
 	int r;
 
 	// SCK_OVRRIDE
-	if (!nf1_set_gpio_output(bitfury, NF1_PIN_SCK_OVR, MCP2210_GPIO_PIN_HIGH))
+	if (!mcp2210_set_gpio_output(bitfury, NF1_PIN_SCK_OVR, MCP2210_GPIO_PIN_HIGH))
 		return false;
 
 	for (r = 0; r < 16; ++r) {
@@ -502,9 +493,9 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	}
 
 	/* Set LED and PWR pins to output and high */
-	if (!nf1_set_gpio_output(bitfury, NF1_PIN_LED, MCP2210_GPIO_PIN_HIGH))
+	if (!mcp2210_set_gpio_output(bitfury, NF1_PIN_LED, MCP2210_GPIO_PIN_HIGH))
 		goto out;
-	if (!nf1_set_gpio_output(bitfury, NF1_PIN_PWR_EN, MCP2210_GPIO_PIN_HIGH))
+	if (!mcp2210_set_gpio_output(bitfury, NF1_PIN_PWR_EN, MCP2210_GPIO_PIN_HIGH))
 		goto out;
 
 	if (opt_debug) {
diff --git a/mcp2210.c b/mcp2210.c
index 6cc0806..e505c18 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -172,6 +172,18 @@ bool mcp2210_set_gpio_pinval(struct cgpu_info *cgpu, int pin, int val)
 	return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOPINVAL);
 }
 
+/* Set one pin to gpio output and set the value */
+bool mcp2210_set_gpio_output(struct cgpu_info *cgpu, int pin, int val)
+{
+	if (!mcp2210_set_gpio_pindes(cgpu, pin, MCP2210_PIN_GPIO))
+		return false;
+	if (!mcp2210_set_gpio_pindir(cgpu, pin, MCP2210_GPIO_OUTPUT))
+		return false;
+	if (!mcp2210_set_gpio_pinval(cgpu, pin, val))
+		return false;
+	return true;
+}
+
 /* Get one pindir */
 bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir)
 {
diff --git a/mcp2210.h b/mcp2210.h
index 62019c9..a0ad2f0 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -50,6 +50,7 @@ bool mcp2210_get_gpio_pin(struct cgpu_info *cgpu, int pin, int *des);
 bool mcp2210_set_gpio_pindes(struct cgpu_info *cgpu, int pin, int des);
 bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val);
 bool mcp2210_set_gpio_pinval(struct cgpu_info *cgpu, int pin, int val);
+bool mcp2210_set_gpio_output(struct cgpu_info *cgpu, int pin, int val);
 bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir);
 bool mcp2210_set_gpio_pindir(struct cgpu_info *cgpu, int pin, int dir);
 bool mcp2210_spi_cancel(struct cgpu_info *cgpu);