Created
October 8, 2014 17:02
-
-
Save h-yamamo/37652620ca0fc2b3088e to your computer and use it in GitHub Desktop.
Improve FAN control for ODROID-U3 - linux 3.8.13.28 #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- linux/drivers/hardkernel/odroidu2_fan.c 2014-09-06 15:18:25.000000000 +0900 | |
+++ new/drivers/hardkernel/odroidu2_fan.c 2014-10-08 00:38:06.233601714 +0900 | |
@@ -291,6 +291,8 @@ | |
{ | |
struct odroid_fan *fan = container_of(work, struct odroid_fan, work.work); | |
unsigned long temperature; | |
+ int hysteresis = fan->duty ? 2 : 0; // FAN off under start_temp - 2C | |
+ int duty, spinup = 0; | |
/* check if its in auto-mode */ | |
if(!fan->auto_mode) | |
@@ -300,7 +302,9 @@ | |
mutex_lock(&fan->mutex); | |
- if(temperature < fan->start_temp) { | |
+ if(temperature < 40) | |
+ hysteresis /= 2; // FAN off under start_temp - 1C | |
+ if(temperature + hysteresis < fan->start_temp) { // avoid FAN on/off frequently | |
pwm_disable(fan->pwm); | |
pwm_config(fan->pwm, 1, fan->period); | |
pwm_enable(fan->pwm); | |
@@ -316,19 +320,48 @@ | |
/* 83C is the first throttle.. | |
* Lets not reach it | |
*/ | |
- fan->duty = 255 * (temperature - fan->start_temp) / (FAN_TEMP_THROTTLE - fan->start_temp); | |
+/* | |
+ 42+23=65C +----- 255 (max) | |
+ / | |
+ / | |
+ / | |
+ / | |
+ start_duty +------+ | |
+ | 42C | |
+ 0 ------+ | |
+ start_temp | |
+ # you may customize. */ | |
+#define THRESHOLD_TEMPERATURE 42 | |
+#define VARIABLE_RANGE 23 | |
+ | |
+ if(temperature <= THRESHOLD_TEMPERATURE) | |
+ duty = fan->start_duty; | |
+ else if(temperature >= THRESHOLD_TEMPERATURE + VARIABLE_RANGE) | |
+ duty = 255; | |
+ else { | |
+ duty = (temperature - THRESHOLD_TEMPERATURE) | |
+ * (255 - fan->start_duty) / VARIABLE_RANGE | |
+ + fan->start_duty; | |
+ } | |
/* Check if duty is lower than start_duty. | |
* If yes, set it to start_duty. | |
* Lets the user set an at least value for duty. | |
*/ | |
- if(fan->duty < fan->start_duty) { | |
- fan->duty = fan->start_duty; | |
+ if(duty < fan->start_duty) { | |
+ duty = fan->start_duty; | |
} | |
+ if(duty + 12 < fan->duty) // slowly speed down. | |
+ duty = fan->duty - 12; | |
+ | |
+ if(fan->duty < 1 && duty > 1 && duty < 127) | |
+ spinup = 16; // if FAN doesn't spin up, increase the value. | |
+ | |
+ fan->duty = duty; | |
if(fan->pwm_status) { | |
pwm_disable(fan->pwm); | |
- pwm_config(fan->pwm, fan->duty * fan->period / 255, fan->period); | |
+ pwm_config(fan->pwm, (duty + spinup) * fan->period / 255, fan->period); | |
pwm_enable(fan->pwm); | |
} | |
@@ -375,7 +408,8 @@ | |
fan->pwm_status = 1; | |
fan->auto_mode = true; | |
- fan->start_duty = 127; | |
+ fan->start_duty = 64; // you may customize. | |
+ fan->start_temp = 32; // almost FAN ON. | |
mutex_init(&fan->mutex); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment