Commit 630e7d7658958728e50b006e2e41e2eb4450b316

Con Kolivas 2013-06-09T21:33:20

Set BFLSC fan speed coarsely to keep it under 60 or auto as per specs saying it tries to stay below 60.

diff --git a/driver-bflsc.c b/driver-bflsc.c
index d74085f..9cef357 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -116,6 +116,7 @@ struct bflsc_info {
 	bool shutdown;
 	bool flash_led;
 	bool not_first_work; // allow ignoring the first nonce error
+	bool fanauto;
 };
 
 #define BFLSC_XLINKHDR '@'
@@ -1799,6 +1800,29 @@ static int64_t bflsc_scanwork(struct thr_info *thr)
 	return ret;
 }
 
+static void bflsc_set_fanspeed(struct cgpu_info *bflsc)
+{
+	struct bflsc_info *sc_info = (struct bflsc_info *)bflsc->device_data;
+	int amount, err;
+
+	if ((bflsc->temp <= 60 && sc_info->fanauto) ||
+	    (bflsc->temp > 60 && !sc_info->fanauto))
+		return;
+
+	mutex_lock(&bflsc->device_mutex);
+	if (bflsc->temp > 60) {
+		write_to_dev(bflsc, 0, BFLSC_FAN4, BFLSC_FAN4_LEN, &amount,
+			     C_SETFAN);
+		sc_info->fanauto = false;
+	} else {
+		write_to_dev(bflsc, 0, BFLSC_FANAUTO, BFLSC_FANOUT_LEN,
+			     &amount, C_SETFAN);
+		sc_info->fanauto = true;
+	}
+	getok(bflsc, C_FANREPLY, &err, &amount);
+	mutex_unlock(&bflsc->device_mutex);
+}
+
 static bool bflsc_get_stats(struct cgpu_info *bflsc)
 {
 	struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_data);
@@ -1821,6 +1845,8 @@ static bool bflsc_get_stats(struct cgpu_info *bflsc)
 			nmsleep(BFLSC_TEMP_SLEEPMS);
 	}
 
+	bflsc_set_fanspeed(bflsc);
+
 	return allok;
 }
 
diff --git a/usbutils.c b/usbutils.c
index e1ff875..53430fa 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -517,6 +517,8 @@ static const char *C_SENDTESTWORK_S = "SendTestWork";
 static const char *C_LATENCY_S = "SetLatency";
 static const char *C_SETLINE_S = "SetLine";
 static const char *C_VENDOR_S = "Vendor";
+static const char *C_SETFAN_S = "SetFan";
+static const char *C_FANREPLY_S = "GetFan";
 static const char *C_AVALON_TASK_S = "AvalonTask";
 static const char *C_AVALON_READ_S = "AvalonRead";
 static const char *C_GET_AVALON_READY_S = "AvalonReady";
@@ -1002,6 +1004,8 @@ static void cgusb_check_init()
 		usb_commands[C_LATENCY] = C_LATENCY_S;
 		usb_commands[C_SETLINE] = C_SETLINE_S;
 		usb_commands[C_VENDOR] = C_VENDOR_S;
+		usb_commands[C_SETFAN] = C_SETFAN_S;
+		usb_commands[C_FANREPLY] = C_FANREPLY_S;
 		usb_commands[C_AVALON_TASK] = C_AVALON_TASK_S;
 		usb_commands[C_AVALON_READ] = C_AVALON_READ_S;
 		usb_commands[C_GET_AVALON_READY] = C_GET_AVALON_READY_S;
diff --git a/usbutils.h b/usbutils.h
index 2579dcd..199cbb1 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -240,6 +240,8 @@ enum usb_cmds {
 	C_LATENCY,
 	C_SETLINE,
 	C_VENDOR,
+	C_SETFAN,
+	C_FANREPLY,
 	C_AVALON_TASK,
 	C_AVALON_READ,
 	C_GET_AVALON_READY,