Remove all standalone gpio setting change functions in mcp2210 and just use the one global setting function.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
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,