Browse Source

bitfury: Split driver into bitfury_gpio (bare GPIO) and metabank (i2c banked GPIO)

Luke Dashjr 12 years ago
parent
commit
462bda82cb
4 changed files with 203 additions and 99 deletions
  1. 1 1
      Makefile.am
  2. 20 98
      driver-bitfury.c
  3. 178 0
      driver-metabank.c
  4. 4 0
      miner.c

+ 1 - 1
Makefile.am

@@ -211,7 +211,7 @@ bfgminer_SOURCES += driver-ztex.c libztex.c libztex.h
 endif
 endif
 
 
 if HAS_BITFURY
 if HAS_BITFURY
-bfgminer_SOURCES += driver-bitfury.c libbitfury.c libbitfury.h spidevc.h spidevc.c tm_i2c.h tm_i2c.c
+bfgminer_SOURCES += driver-bitfury.c libbitfury.c libbitfury.h spidevc.h spidevc.c driver-metabank.c tm_i2c.h tm_i2c.c
 
 
 if HAS_LITTLEFURY
 if HAS_LITTLEFURY
 bfgminer_SOURCES += driver-littlefury.c
 bfgminer_SOURCES += driver-littlefury.c

+ 20 - 98
driver-bitfury.c

@@ -31,99 +31,11 @@
 #include "libbitfury.h"
 #include "libbitfury.h"
 #include "util.h"
 #include "util.h"
 #include "spidevc.h"
 #include "spidevc.h"
-#include "tm_i2c.h"
 
 
 #define GOLDEN_BACKLOG 5
 #define GOLDEN_BACKLOG 5
 
 
 struct device_drv bitfury_drv;
 struct device_drv bitfury_drv;
 
 
-static
-bool metabank_spi_txrx(struct spi_port *port)
-{
-	struct cgpu_info * const proc = port->cgpu;
-	struct bitfury_device * const bitfury = proc->device_data;
-	tm_i2c_set_oe(bitfury->slot);
-	const bool rv = sys_spi_txrx(port);
-	tm_i2c_clear_oe(bitfury->slot);
-	return rv;
-}
-
-static
-struct bitfury_device **metabank_detect_chips(int *out_count) {
-	struct bitfury_device **devicelist, *bitfury;
-	struct spi_port *port;
-	int n = 0;
-	int i, j;
-	bool slot_on[32];
-	struct timespec t1, t2;
-	struct bitfury_device dummy_bitfury;
-	struct cgpu_info dummy_cgpu;
-
-	if (tm_i2c_init() < 0) {
-		printf("I2C init error\n");
-		*out_count = 0;
-		return NULL;
-	}
-
-
-	devicelist = malloc(100 * sizeof(*devicelist));
-	dummy_cgpu.device_data = &dummy_bitfury;
-	
-	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
-	for (i = 0; i < 32; i++) {
-		int slot_detected = tm_i2c_detect(i) != -1;
-		slot_on[i] = slot_detected;
-		tm_i2c_clear_oe(i);
-		cgsleep_ms(1);
-	}
-
-	for (i = 0; i < 32; i++) {
-		if (slot_on[i]) {
-			int chip_n;
-			
-			port = malloc(sizeof(*port));
-			*port = *sys_spi;
-			port->cgpu = &dummy_cgpu;
-			port->txrx = metabank_spi_txrx;
-			dummy_bitfury.slot = i;
-			
-			chip_n = libbitfury_detectChips1(port);
-			if (chip_n)
-			{
-				applog(LOG_WARNING, "BITFURY slot %d: %d chips detected", i, chip_n);
-				for (j = 0; j < chip_n; ++j)
-				{
-					devicelist[n] = bitfury = malloc(sizeof(*bitfury));
-					bitfury->spi = port;
-					bitfury->slot = i;
-					bitfury->fasync = j;
-					n++;
-				}
-			}
-			else
-				free(port);
-		}
-	}
-
-	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t2);
-
-	*out_count = n;
-	return devicelist;
-}
-
-void libbitfury_shutdownChips(struct cgpu_info *proc) {
-	struct bitfury_device *bitfury;
-	for ( ; proc; proc = proc->next_proc)
-	{
-		bitfury = proc->device_data;
-		send_shutdown(bitfury->spi, bitfury->slot, bitfury->fasync);
-	}
-	tm_i2c_close();
-}
-
-
-// Forward declarations
-static bool bitfury_prepare(struct thr_info *thr);
 int calc_stat(time_t * stat_ts, time_t stat, struct timeval now);
 int calc_stat(time_t * stat_ts, time_t stat, struct timeval now);
 double shares_to_ghashes(int shares, int seconds);
 double shares_to_ghashes(int shares, int seconds);
 
 
@@ -143,7 +55,7 @@ int bitfury_autodetect()
 	spi_init();
 	spi_init();
 	if (!sys_spi)
 	if (!sys_spi)
 		return 0;
 		return 0;
-	bitfury_info->device_data = metabank_detect_chips(&chip_n);
+	chip_n = libbitfury_detectChips1(sys_spi);
 	if (!chip_n) {
 	if (!chip_n) {
 		applog(LOG_WARNING, "No Bitfury chips detected!");
 		applog(LOG_WARNING, "No Bitfury chips detected!");
 		return 0;
 		return 0;
@@ -166,13 +78,17 @@ static void bitfury_detect(void)
 static
 static
 bool bitfury_init(struct thr_info *thr)
 bool bitfury_init(struct thr_info *thr)
 {
 {
-	struct bitfury_device **devicelist = thr->cgpu->device_data;
 	struct cgpu_info *proc;
 	struct cgpu_info *proc;
+	struct bitfury_device *bitfury;
 	
 	
 	for (proc = thr->cgpu; proc; proc = proc->next_proc)
 	for (proc = thr->cgpu; proc; proc = proc->next_proc)
-		proc->device_data = devicelist[proc->proc_id];
-	
-	free(devicelist);
+	{
+		bitfury = proc->device_data = malloc(sizeof(struct bitfury_device));
+		*bitfury = (struct bitfury_device){
+			.spi = sys_spi,
+			.fasync = proc->proc_id,
+		};
+	}
 	
 	
 	return true;
 	return true;
 }
 }
@@ -377,7 +293,7 @@ int calc_stat(time_t * stat_ts, time_t stat, struct timeval now) {
 	return shares_found;
 	return shares_found;
 }
 }
 
 
-static bool bitfury_prepare(struct thr_info *thr)
+bool bitfury_prepare(struct thr_info *thr)
 {
 {
 	struct cgpu_info *cgpu = thr->cgpu;
 	struct cgpu_info *cgpu = thr->cgpu;
 
 
@@ -387,14 +303,20 @@ static bool bitfury_prepare(struct thr_info *thr)
 	return true;
 	return true;
 }
 }
 
 
-static void bitfury_shutdown(struct thr_info *thr)
-{
+void bitfury_shutdown(struct thr_info *thr) {
+	struct cgpu_info *cgpu = thr->cgpu, *proc;
+	struct bitfury_device *bitfury;
+	
 	applog(LOG_INFO, "INFO bitfury_shutdown");
 	applog(LOG_INFO, "INFO bitfury_shutdown");
-	libbitfury_shutdownChips(thr->cgpu);
+	for (proc = cgpu; proc; proc = proc->next_proc)
+	{
+		bitfury = proc->device_data;
+		send_shutdown(bitfury->spi, bitfury->slot, bitfury->fasync);
+	}
 }
 }
 
 
 struct device_drv bitfury_drv = {
 struct device_drv bitfury_drv = {
-	.dname = "bitfury",
+	.dname = "bitfury_gpio",
 	.name = "BFY",
 	.name = "BFY",
 	.drv_detect = bitfury_detect,
 	.drv_detect = bitfury_detect,
 	.thread_prepare = bitfury_prepare,
 	.thread_prepare = bitfury_prepare,

+ 178 - 0
driver-metabank.c

@@ -0,0 +1,178 @@
+/*
+ * Copyright 2013 bitfury
+ * Copyright 2013 legkodymov
+ * Copyright 2013 Luke Dashjr
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "deviceapi.h"
+#include "libbitfury.h"
+#include "spidevc.h"
+#include "tm_i2c.h"
+
+struct device_drv metabank_drv;
+
+static
+bool metabank_spi_txrx(struct spi_port *port)
+{
+	struct cgpu_info * const proc = port->cgpu;
+	struct bitfury_device * const bitfury = proc->device_data;
+	tm_i2c_set_oe(bitfury->slot);
+	const bool rv = sys_spi_txrx(port);
+	tm_i2c_clear_oe(bitfury->slot);
+	return rv;
+}
+
+static
+struct bitfury_device **metabank_detect_chips(int *out_count) {
+	struct bitfury_device **devicelist, *bitfury;
+	struct spi_port *port;
+	int n = 0;
+	int i, j;
+	bool slot_on[32];
+	struct timespec t1, t2;
+	struct bitfury_device dummy_bitfury;
+	struct cgpu_info dummy_cgpu;
+
+	if (tm_i2c_init() < 0) {
+		printf("I2C init error\n");
+		*out_count = 0;
+		return NULL;
+	}
+
+
+	devicelist = malloc(100 * sizeof(*devicelist));
+	dummy_cgpu.device_data = &dummy_bitfury;
+	
+	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
+	for (i = 0; i < 32; i++) {
+		int slot_detected = tm_i2c_detect(i) != -1;
+		slot_on[i] = slot_detected;
+		tm_i2c_clear_oe(i);
+		cgsleep_ms(1);
+	}
+
+	for (i = 0; i < 32; i++) {
+		if (slot_on[i]) {
+			int chip_n;
+			
+			port = malloc(sizeof(*port));
+			*port = *sys_spi;
+			port->cgpu = &dummy_cgpu;
+			port->txrx = metabank_spi_txrx;
+			dummy_bitfury.slot = i;
+			
+			chip_n = libbitfury_detectChips1(port);
+			if (chip_n)
+			{
+				applog(LOG_WARNING, "BITFURY slot %d: %d chips detected", i, chip_n);
+				for (j = 0; j < chip_n; ++j)
+				{
+					devicelist[n] = bitfury = malloc(sizeof(*bitfury));
+					bitfury->spi = port;
+					bitfury->slot = i;
+					bitfury->fasync = j;
+					n++;
+				}
+			}
+			else
+				free(port);
+		}
+	}
+
+	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t2);
+
+	*out_count = n;
+	return devicelist;
+}
+
+static
+int metabank_autodetect()
+{
+	RUNONCE(0);
+	
+	int chip_n;
+	struct cgpu_info *bitfury_info;
+
+	bitfury_info = calloc(1, sizeof(struct cgpu_info));
+	bitfury_info->drv = &metabank_drv;
+	bitfury_info->threads = 1;
+
+	applog(LOG_INFO, "INFO: bitfury_detect");
+	spi_init();
+	if (!sys_spi)
+		return 0;
+	bitfury_info->device_data = metabank_detect_chips(&chip_n);
+	if (!chip_n) {
+		applog(LOG_WARNING, "No Bitfury chips detected!");
+		return 0;
+	} else {
+		applog(LOG_WARNING, "BITFURY: %d chips detected!", chip_n);
+	}
+
+	bitfury_info->procs = chip_n;
+	add_cgpu(bitfury_info);
+	
+	return 1;
+}
+
+static void metabank_detect(void)
+{
+	noserial_detect_manual(&metabank_drv, metabank_autodetect);
+}
+
+extern bool bitfury_prepare(struct thr_info *);
+
+static
+bool metabank_init(struct thr_info *thr)
+{
+	struct bitfury_device **devicelist = thr->cgpu->device_data;
+	struct cgpu_info *proc;
+	
+	for (proc = thr->cgpu; proc; proc = proc->next_proc)
+		proc->device_data = devicelist[proc->proc_id];
+	
+	free(devicelist);
+	
+	return true;
+}
+
+extern int64_t bitfury_scanHash(struct thr_info *);
+extern void bitfury_shutdown(struct thr_info *);
+
+static void metabank_shutdown(struct thr_info *thr)
+{
+	bitfury_shutdown(thr);
+	tm_i2c_close();
+}
+
+struct device_drv metabank_drv = {
+	.dname = "metabank",
+	.name = "MBF",
+	.drv_detect = metabank_detect,
+	
+	.minerloop = hash_queued_work,
+	.thread_prepare = bitfury_prepare,
+	.thread_init = metabank_init,
+	.scanwork = bitfury_scanHash,
+	.thread_shutdown = metabank_shutdown,
+};

+ 4 - 0
miner.c

@@ -9389,6 +9389,7 @@ extern struct device_drv ztex_drv;
 
 
 #ifdef USE_BITFURY
 #ifdef USE_BITFURY
 extern struct device_drv bitfury_drv;
 extern struct device_drv bitfury_drv;
+extern struct device_drv metabank_drv;
 #endif
 #endif
 
 
 static int cgminer_id_count = 0;
 static int cgminer_id_count = 0;
@@ -9496,7 +9497,10 @@ void drv_detect_all()
 
 
 #ifdef USE_BITFURY
 #ifdef USE_BITFURY
 	if (!opt_scrypt)
 	if (!opt_scrypt)
+	{
 		bitfury_drv.drv_detect();
 		bitfury_drv.drv_detect();
+		metabank_drv.drv_detect();
+	}
 #endif
 #endif
 
 
 #ifdef USE_LITTLEFURY
 #ifdef USE_LITTLEFURY