Browse Source

Merge commit 'b4a4049' into bfgminer

Luke Dashjr 12 years ago
parent
commit
5946849a91
3 changed files with 46 additions and 7 deletions
  1. 30 7
      driver-bitfury.c
  2. 15 0
      miner.c
  3. 1 0
      miner.h

+ 30 - 7
driver-bitfury.c

@@ -39,6 +39,8 @@
 
 BFG_REGISTER_DRIVER(bitfury_drv)
 
+static char *bitfury_spi_port_config(struct cgpu_info *, char *, char *, char *);
+
 static
 int bitfury_autodetect()
 {
@@ -55,6 +57,14 @@ int bitfury_autodetect()
 	spi_init();
 	if (!sys_spi)
 		return 0;
+	
+	{
+		struct bitfury_device dummy_bitfury = {
+			.spi = sys_spi,
+		};
+		drv_set_defaults(&bitfury_drv, bitfury_spi_port_config, &dummy_bitfury);
+	}
+	
 	chip_n = libbitfury_detectChips1(sys_spi);
 	if (!chip_n) {
 		applog(LOG_WARNING, "No Bitfury chips detected!");
@@ -681,9 +691,26 @@ bool _bitfury_set_device_parse_setting(uint32_t * const rv, char * const setting
 	return true;
 }
 
+static
+char *bitfury_spi_port_config(struct cgpu_info * const proc, char *option, char *setting, char *replybuf)
+{
+	struct bitfury_device * const bitfury = proc->device_data;
+	
+	if (!strcasecmp(option, "baud"))
+	{
+		if (!_bitfury_set_device_parse_setting(&bitfury->spi->speed, setting, replybuf, INT_MAX))
+			return replybuf;
+		
+		return NULL;
+	}
+	
+	return "";
+}
+
 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;
+	char *rv;
 	uint32_t newval;
 	
 	if (!strcasecmp(option, "help"))
@@ -692,13 +719,9 @@ char *bitfury_set_device(struct cgpu_info * const proc, char * const option, cha
 		return replybuf;
 	}
 	
-	if (!strcasecmp(option, "baud"))
-	{
-		if (!_bitfury_set_device_parse_setting(&bitfury->spi->speed, setting, replybuf, INT_MAX))
-			return replybuf;
-		
-		return NULL;
-	}
+	rv = bitfury_spi_port_config(proc, option, setting, replybuf);
+	if ((!rv) || rv[0])
+		return rv;
 	
 	if (!strcasecmp(option, "osc6_bits"))
 	{

+ 15 - 0
miner.c

@@ -9656,6 +9656,21 @@ void cgpu_set_defaults(struct cgpu_info * const cgpu)
 	cgpu->already_set_defaults = true;
 }
 
+void drv_set_defaults(const struct device_drv * const drv, char *(*set_func)(struct cgpu_info *, char *, char *, char *), void *userp)
+{
+	struct device_drv dummy_drv = *drv;
+	struct cgpu_info dummy_cgpu = {
+		.drv = &dummy_drv,
+		.device = &dummy_cgpu,
+		.device_id = -1,
+		.proc_id = -1,
+		.device_data = userp,
+	};
+	strcpy(dummy_cgpu.proc_repr, drv->name);
+	dummy_drv.set_device = set_func;
+	cgpu_set_defaults(&dummy_cgpu);
+}
+
 /* Makes sure the hashmeter keeps going even if mining threads stall, updates
  * the screen at regular intervals, and restarts threads if they appear to have
  * died. */

+ 1 - 0
miner.h

@@ -1041,6 +1041,7 @@ extern void proc_enable(struct cgpu_info *);
 extern void reinit_device(struct cgpu_info *cgpu);
 
 extern void cgpu_set_defaults(struct cgpu_info *);
+extern void drv_set_defaults(const struct device_drv *, char *(*set_func)(struct cgpu_info *, char *, char *, char *), void *userp);
 
 #ifdef HAVE_ADL
 extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);