Browse Source

bfsb/metabank: Allow pgaset to change osc6_bits and SPI baud rate

Luke Dashjr 12 years ago
parent
commit
b13ba205a1
5 changed files with 70 additions and 1 deletions
  1. 1 0
      driver-bfsb.c
  2. 66 1
      driver-bitfury.c
  3. 1 0
      driver-bitfury.h
  4. 1 0
      driver-metabank.c
  5. 1 0
      libbitfury.h

+ 1 - 0
driver-bfsb.c

@@ -213,6 +213,7 @@ struct device_drv bfsb_drv = {
 	.job_start = bitfury_noop_job_start,
 	.job_process_results = bitfury_job_process_results,
 	.get_api_extra_device_status = bfsb_api_device_status,
+	.set_device = bitfury_set_device,
 	.thread_disable = bfsb_disable,
 	.thread_enable = bfsb_enable,
 	.thread_shutdown = bfsb_shutdown,

+ 66 - 1
driver-bitfury.c

@@ -23,6 +23,7 @@
 
 #include "config.h"
 
+#include <limits.h>
 #include "miner.h"
 #include <unistd.h>
 #include <sha2.h>
@@ -632,7 +633,13 @@ void bitfury_do_io(struct thr_info * const master_thr)
 		bitfury->oldjob = newjob;
 		
 out:
-		continue;
+		if (unlikely(bitfury->force_reinit))
+		{
+			applog(LOG_DEBUG, "%"PRIpreprv": Forcing reinitialisation",
+			       proc->proc_repr);
+			send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
+			bitfury->desync_counter = 99;
+		}
 	}
 	
 	timer_set_delay_from_now(&master_thr->tv_poll, 10000);
@@ -655,6 +662,64 @@ struct api_data *bitfury_api_device_status(const struct cgpu_info * const cgpu)
 	return root;
 }
 
+static
+bool _bitfury_set_device_parse_setting(int * const rv, char * const setting, char * const replybuf, const int maxval)
+{
+	char *p;
+	long int nv;
+	
+	if (!setting || !*setting)
+	{
+		sprintf(replybuf, "missing setting");
+		return false;
+	}
+	nv = strtol(setting, &p, 0);
+	if ((p && p[0]) || nv > maxval || nv < 1)
+	{
+		sprintf(replybuf, "invalid setting");
+		return false;
+	}
+	*rv = nv;
+	return true;
+}
+
+char *bitfury_set_device(struct cgpu_info * const proc, char * const option, char * const setting, char * const replybuf)
+{
+	struct bitfury_device * const bitfury = proc->device_data;
+	int newval;
+	
+	if (!strcasecmp(option, "help"))
+	{
+		sprintf(replybuf, "baud: SPI baud rate");
+		sprintf(replybuf, "osc6_bits: range 1-55 (slow to fast)");
+		return replybuf;
+	}
+	
+	if (!strcasecmp(option, "baud"))
+	{
+		if (!_bitfury_set_device_parse_setting(&bitfury->spi->speed, setting, replybuf, INT_MAX))
+			return replybuf;
+		
+		sprintf(replybuf, "baud changed");
+		return replybuf;
+	}
+	
+	if (!strcasecmp(option, "osc6_bits"))
+	{
+		newval = bitfury->osc6_bits;
+		if (!_bitfury_set_device_parse_setting(&newval, setting, replybuf, 55))
+			return replybuf;
+		
+		bitfury->osc6_bits = newval;
+		bitfury->force_reinit = true;
+		
+		return replybuf;
+	}
+	
+	sprintf(replybuf, "Unknown option: %s", option);
+	return replybuf;
+}
+
 struct device_drv bitfury_drv = {
 	.dname = "bitfury_gpio",
 	.name = "BFY",

+ 1 - 0
driver-bitfury.h

@@ -16,6 +16,7 @@ extern void bitfury_noop_job_start(struct thr_info *);
 extern void bitfury_do_io(struct thr_info *);
 extern int64_t bitfury_job_process_results(struct thr_info *, struct work *, bool stopping);
 extern struct api_data *bitfury_api_device_status(const struct cgpu_info *);
+extern char *bitfury_set_device(struct cgpu_info *, char *, char *, char *);
 
 extern void bitfury_shutdown(struct thr_info *);
 

+ 1 - 0
driver-metabank.c

@@ -228,4 +228,5 @@ struct device_drv metabank_drv = {
 	.thread_shutdown = metabank_shutdown,
 	.get_api_extra_device_status = metabank_api_extra_device_status,
 	.get_stats = metabank_get_stats,
+	.set_device = bitfury_set_device,
 };

+ 1 - 0
libbitfury.h

@@ -54,6 +54,7 @@ struct bitfury_device {
 	unsigned fasync;
 	unsigned strange_counter;
 	bool second_run;
+	bool force_reinit;
 	int desync_counter;
 	int sample_hwe;
 	int sample_tot;