Commit 7e4f6866b950af124ad95f9c66c90526165ec8a9

Con Kolivas 2014-01-05T17:05:11

Remove all standalone gpio setting change functions in mcp2210 and just use the one global setting function.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index a38e666..e3aa71e 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -280,13 +280,14 @@ out_close:
 
 static void nf1_close(struct cgpu_info *bitfury)
 {
-	struct gpio_pin gp;
+	struct bitfury_info *info = bitfury->device_data;
+	struct mcp_settings *mcp = &info->mcp;
 	int i;
 
 	/* Set all pins to input mode, ignoring return code */
 	for (i = 0; i < 9; i++)
-		gp.pin[i] = MCP2210_GPIO_INPUT;
-	mcp2210_set_gpio_pindirs(bitfury, &gp);
+		mcp->direction.pin[i] = MCP2210_GPIO_INPUT;
+	mcp2210_set_gpio_settings(bitfury, mcp);
 }
 
 static void spi_clear_buf(struct bitfury_info *info)
@@ -411,13 +412,16 @@ static void nf1_send_init(struct bitfury_info *info)
 }
 
 // Bit-banging reset... Each 3 reset cycles reset first chip in chain
-static bool nf1_spi_reset(struct cgpu_info *bitfury)
+static bool nf1_spi_reset(struct cgpu_info *bitfury, struct bitfury_info *info)
 {
 	char buf[1] = {0x81}; // will send this waveform: - _ _ _ _ _ _ -
+	struct mcp_settings *mcp = &info->mcp;
 	int r;
 
 	// SCK_OVRRIDE
-	if (!mcp2210_set_gpio_output(bitfury, NF1_PIN_SCK_OVR, MCP2210_GPIO_PIN_HIGH))
+	mcp->value.pin[NF1_PIN_SCK_OVR] = MCP2210_GPIO_PIN_HIGH;
+	mcp->direction.pin[NF1_PIN_SCK_OVR] = MCP2210_GPIO_OUTPUT;
+	if (!mcp2210_set_gpio_settings(bitfury, mcp))
 		return false;
 
 	for (r = 0; r < 16; ++r) {
@@ -426,7 +430,8 @@ static bool nf1_spi_reset(struct cgpu_info *bitfury)
 			return false;
 	}
 
-	if (!mcp2210_set_gpio_input(bitfury, NF1_PIN_SCK_OVR))
+	mcp->direction.pin[NF1_PIN_SCK_OVR] = MCP2210_GPIO_INPUT;
+	if (!mcp2210_set_gpio_settings(bitfury, mcp))
 		return false;
 
 	return true;
@@ -437,7 +442,7 @@ static bool nf1_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
 	unsigned int length, sendrcv;
 	int offset = 0, roffset = 0;
 
-	if (!nf1_spi_reset(bitfury))
+	if (!nf1_spi_reset(bitfury, info))
 		return false;
 	length = info->spibufsz;
 	applog(LOG_DEBUG, "%s %d: SPI sending %u bytes", bitfury->drv->name, bitfury->device_id,
diff --git a/mcp2210.c b/mcp2210.c
index e08ba28..4ba35b3 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -176,42 +176,6 @@ bool mcp2210_get_gpio_pin(struct cgpu_info *cgpu, int pin, int *des)
 	return true;
 }
 
-/* Set the designation of all pins. This will reset direction and values. */
-bool mcp2210_set_gpio_pin_designations(struct cgpu_info *cgpu, struct gpio_pin *gp)
-{
-	char buf[MCP2210_BUFFER_LENGTH];
-	int i;
-
-	/* Copy the current values */
-	memset(buf, 0, MCP2210_BUFFER_LENGTH);
-	buf[0] = MCP2210_GET_GPIO_SETTING;
-	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOSETTING))
-		return false;
-
-	for (i = 0; i < 9; i++)
-		buf[4 + i] = gp->pin[i];
-	memset(buf + 18, 0, 45);
-	buf[0] = MCP2210_SET_GPIO_SETTING;
-	return (mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOSETTING));
-}
-
-/* Set the designation of one pin. This will reset direction and values. */
-bool mcp2210_set_gpio_pindes(struct cgpu_info *cgpu, int pin, int des)
-{
-	char buf[MCP2210_BUFFER_LENGTH];
-
-	/* Copy the current values */
-	memset(buf, 0, MCP2210_BUFFER_LENGTH);
-	buf[0] = MCP2210_GET_GPIO_SETTING;
-	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOSETTING))
-		return false;
-
-	buf[4 + pin] = des;
-	memset(buf + 18, 0, 45);
-	buf[0] = MCP2210_SET_GPIO_SETTING;
-	return (mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOSETTING));
-}
-
 /* Get one pinval */
 bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val)
 {
@@ -232,73 +196,6 @@ bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val)
 	return true;
 }
 
-/* Set all pinvals */
-bool mcp2210_set_gpio_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp)
-{
-	char buf[MCP2210_BUFFER_LENGTH];
-	int pin;
-
-	memset(buf, 0, MCP2210_BUFFER_LENGTH);
-	buf[0] = MCP2210_SET_GPIO_PIN_VAL;
-
-	for (pin = 0; pin < 8; pin++) {
-		if (gp->pin[pin])
-			buf[4] |= (0x01u << pin);
-		else
-			buf[4] &= ~(0x01u << pin);
-	}
-	if (gp->pin[pin])
-		buf[5] |= 0x01u;
-	else
-		buf[5] &= ~0x01u;
-	return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOPINVAL);
-}
-
-/* Set one pinval */
-bool mcp2210_set_gpio_pinval(struct cgpu_info *cgpu, int pin, int val)
-{
-	char buf[MCP2210_BUFFER_LENGTH];
-
-	/* Get the current pin vals first since we're only changing one. */
-	memset(buf, 0, MCP2210_BUFFER_LENGTH);
-	buf[0] = MCP2210_GET_GPIO_PIN_VAL;
-	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOPINVAL))
-		return false;
-
-	buf[0] = MCP2210_SET_GPIO_PIN_VAL;
-
-	if (pin < 8) {
-		if (val)
-			buf[4] |= (0x01u << pin);
-		else
-			buf[4] &= ~(0x01u << pin);
-	} else {
-		if (val)
-			buf[5] |= 0x01u;
-		else
-			buf[5] &= ~0x01u;
-	}
-	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_pindir(cgpu, pin, MCP2210_GPIO_OUTPUT))
-		return false;
-	if (!mcp2210_set_gpio_pinval(cgpu, pin, val))
-		return false;
-	return true;
-}
-
-/* Set one pin to gpio input */
-bool mcp2210_set_gpio_input(struct cgpu_info *cgpu, int pin)
-{
-	if (!mcp2210_set_gpio_pindir(cgpu, pin, MCP2210_GPIO_INPUT))
-		return false;
-	return true;
-}
-
 /* Get one pindir */
 bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir)
 {
@@ -319,55 +216,6 @@ bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir)
 	return true;
 }
 
-/* Set all pindirs */
-bool mcp2210_set_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp)
-{
-	char buf[MCP2210_BUFFER_LENGTH];
-	int pin;
-
-	memset(buf, 0, MCP2210_BUFFER_LENGTH);
-	buf[0] = MCP2210_SET_GPIO_PIN_DIR;
-
-	for (pin = 0; pin < 8; pin++) {
-		if (gp->pin[pin])
-			buf[4] |= (0x01u << pin);
-		else
-			buf[4] &= ~(0x01u << pin);
-	}
-	if (gp->pin[pin])
-		buf[5] |= 0x01u;
-	else
-		buf[5] &= ~0x01u;
-	return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOPINDIR);
-}
-
-/* Set one pindir */
-bool mcp2210_set_gpio_pindir(struct cgpu_info *cgpu, int pin, int dir)
-{
-	char buf[MCP2210_BUFFER_LENGTH];
-
-	/* Get the current pin dirs first since we're only changing one. */
-	memset(buf, 0, MCP2210_BUFFER_LENGTH);
-	buf[0] = MCP2210_GET_GPIO_PIN_DIR;
-	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOPINDIR))
-		return false;
-
-	buf[0] = MCP2210_SET_GPIO_PIN_DIR;
-
-	if (pin < 8) {
-		if (dir)
-			buf[4] |= (0x01u << pin);
-		else
-			buf[4] &= ~(0x01u << pin);
-	} else {
-		if (dir)
-			buf[5] |= 0x01u;
-		else
-			buf[5] &= ~0x01u;
-	}
-	return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOPINDIR);
-}
-
 bool mcp2210_spi_cancel(struct cgpu_info *cgpu)
 {
 	char buf[MCP2210_BUFFER_LENGTH];
diff --git a/mcp2210.h b/mcp2210.h
index d6c4553..2b9c3d1 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -56,16 +56,8 @@ bool mcp2210_get_gpio_pindes(struct cgpu_info *cgpu, struct gpio_pin *gp);
 bool mcp2210_get_gpio_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp);
 bool mcp2210_get_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp);
 bool mcp2210_get_gpio_pin(struct cgpu_info *cgpu, int pin, int *des);
-bool mcp2210_set_gpio_pin_designations(struct cgpu_info *cgpu, struct gpio_pin *gp);
-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_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp);
-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_set_gpio_input(struct cgpu_info *cgpu, int pin);
 bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir);
-bool mcp2210_set_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp);
-bool mcp2210_set_gpio_pindir(struct cgpu_info *cgpu, int pin, int dir);
 bool mcp2210_spi_cancel(struct cgpu_info *cgpu);
 bool
 mcp2210_get_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int *bitrate, unsigned int *icsv,