Skip to content

Instantly share code, notes, and snippets.

@h-yamamo
Created October 3, 2014 09:42
Show Gist options
  • Save h-yamamo/4a9cb6c3d4a5d7907403 to your computer and use it in GitHub Desktop.
Save h-yamamo/4a9cb6c3d4a5d7907403 to your computer and use it in GitHub Desktop.
Improve FAN control for ODROID-U3 - linux 3.8.13
--- linux/drivers/hardkernel/odroidu2_fan.c 2014-09-06 15:18:25.000000000 +0900
+++ new/drivers/hardkernel/odroidu2_fan.c 2014-10-02 22:51:30.977219061 +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 < 41)
+ 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,45 @@
/* 83C is the first throttle..
* Lets not reach it
*/
- fan->duty = 255 * (temperature - fan->start_temp) / (FAN_TEMP_THROTTLE - fan->start_temp);
+/*
+ 42+20=62C +----- 255 (max)
+ /
+ /
+ /
+ /
+ start_duty +------+
+ | 42C
+ 0 ------+
+ start_temp
+*/
+#define THRESHOLD_TEMPERATURE 42
+#define VARIABLE_RANGE 20
+
+ 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(fan->duty < 1 && duty > 1 && duty < 112)
+ 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 +405,8 @@
fan->pwm_status = 1;
fan->auto_mode = true;
- fan->start_duty = 127;
+ fan->start_duty = 64; // adjust you like
+ 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