Move the set gpio output function to a generic mcp2210 version from nanofury which also sets the pin to gpio.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
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);