Browse Source

Merge branch 'bitforce_voltclock' into bfgminer

Luke Dashjr 10 years ago
parent
commit
a9d0c6e742
4 changed files with 64 additions and 18 deletions
  1. 25 0
      deviceapi.c
  2. 3 0
      deviceapi.h
  3. 2 18
      driver-avalonmm.c
  4. 34 0
      driver-bitforce.c

+ 25 - 0
deviceapi.c

@@ -997,6 +997,31 @@ const char *proc_set_device(struct cgpu_info * const proc, char * const optname,
 	return rv;
 }
 
+#ifdef HAVE_CURSES
+const char *proc_set_device_tui_wrapper(struct cgpu_info * const proc, char * const optname, const bfg_set_device_func_t func, const char * const prompt, const char * const success_msg)
+{
+	static char replybuf[0x2001];
+	char * const cvar = curses_input(prompt);
+	if (!cvar)
+		return "Cancelled\n";
+	
+	enum bfg_set_device_replytype success;
+	const char * const reply = func(proc, optname, cvar, replybuf, &success);
+	free(cvar);
+	
+	if (reply)
+	{
+		if (reply != replybuf)
+			snprintf(replybuf, sizeof(replybuf), "%s\n", reply);
+		else
+			tailsprintf(replybuf, sizeof(replybuf), "\n");
+		return replybuf;
+	}
+	
+	return success_msg ?: "Successful\n";
+}
+#endif
+
 #ifdef NEED_BFG_LOWL_VCOM
 bool _serial_detect_all(struct lowlevel_device_info * const info, void * const userp)
 {

+ 3 - 0
deviceapi.h

@@ -95,6 +95,9 @@ struct bfg_set_device_definition {
 	const char *description;
 };
 extern const char *proc_set_device(struct cgpu_info *proc, char *optname, char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
+#ifdef HAVE_CURSES
+extern const char *proc_set_device_tui_wrapper(struct cgpu_info *proc, char *optname, bfg_set_device_func_t, const char *prompt, const char *success_msg);
+#endif
 
 typedef bool(*detectone_func_t)(const char*);
 typedef int(*autoscan_func_t)();

+ 2 - 18
driver-avalonmm.c

@@ -895,24 +895,8 @@ void avalonmm_tui_wlogprint_choices(struct cgpu_info * const proc)
 	wlogprint("[V]oltage ");
 }
 
-static
-const char *avalonmm_tui_wrapper(struct cgpu_info * const proc, bfg_set_device_func_t func, const char * const prompt)
-{
-	static char replybuf[0x20];
-	char * const cvar = curses_input(prompt);
-	if (!cvar)
-		return "Cancelled\n";
-	
-	const char *reply = func(proc, NULL, cvar, NULL, NULL);
-	free(cvar);
-	if (reply)
-	{
-		snprintf(replybuf, sizeof(replybuf), "%s\n", reply);
-		return replybuf;
-	}
-	
-	return "Successful\n";
-}
+#define avalonmm_tui_wrapper(proc, func, prompt) \
+	proc_set_device_tui_wrapper(proc, NULL, func, prompt, NULL)
 
 static
 const char *avalonmm_tui_handle_choice(struct cgpu_info * const proc, const int input)

+ 34 - 0
driver-bitforce.c

@@ -12,6 +12,7 @@
 
 #include <ctype.h>
 #include <limits.h>
+#include <math.h>
 #include <pthread.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -1810,6 +1811,35 @@ static bool bitforce_thread_init(struct thr_info *thr)
 	return true;
 }
 
+static
+const char *bitforce_set_voltage(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success)
+{
+	pthread_mutex_t *mutexp = &proc->device->device_mutex;
+	char cmd[3] = "VFX";
+	
+	const unsigned mV = round(atof(newvalue) * 1000);
+	static const unsigned n[] = {750, 730, 720, 700, 680, 670, 662, 650, 643, 630, 620, 600, 580, 560, 550, 540};
+	for (int i = 0; ; ++i)
+	{
+		if (i >= 0x10)
+			return "Voltage must be from 0.54 to 0.75";
+		if (mV >= n[i])
+		{
+			cmd[1] -= i;
+			break;
+		}
+	}
+	
+	mutex_lock(mutexp);
+	bitforce_cmd1b(proc, replybuf, 8000, cmd, 3);
+	mutex_unlock(mutexp);
+	
+	if (!strncasecmp(replybuf, "OK", 2))
+		return NULL;
+	
+	return replybuf;
+}
+
 #ifdef HAVE_CURSES
 static
 void bitforce_tui_wlogprint_choices(struct cgpu_info *cgpu)
@@ -1817,6 +1847,7 @@ void bitforce_tui_wlogprint_choices(struct cgpu_info *cgpu)
 	struct bitforce_data *data = cgpu->device_data;
 	if (data->supports_fanspeed)
 		wlogprint("[F]an control ");
+	wlogprint("[V]oltage ");
 }
 
 static
@@ -1851,6 +1882,8 @@ const char *bitforce_tui_handle_choice(struct cgpu_info *cgpu, int input)
 			mutex_unlock(mutexp);
 			return replybuf;
 		}
+		case 'v': case 'V':
+			return proc_set_device_tui_wrapper(cgpu, NULL, bitforce_set_voltage, "Set voltage (0.54-0.75 V)", "Requested voltage change");
 	}
 	return NULL;
 }
@@ -1978,6 +2011,7 @@ const char *bitforce_rpc_send_cmd1(struct cgpu_info * const proc, const char * c
 
 static const struct bfg_set_device_definition bitforce_set_device_funcs[] = {
 	{"fanmode", bitforce_set_fanmode, "range 0-5 (low to fast) or 9 (auto)"},
+	{"voltage", bitforce_set_voltage, "range 0.54-0.75 V"},
 	{"_cmd1", bitforce_rpc_send_cmd1, NULL},
 	{NULL},
 };