Skip to content

Commit

Permalink
Merge pull request #44 from achpile/odroid-3.8.y
Browse files Browse the repository at this point in the history
Made fan starts smoother when reaches 50 degrees in auto mode
  • Loading branch information
mdrjr committed May 25, 2014
2 parents c264b6f + be290d7 commit 849348d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion arch/arm/mach-exynos/mach-hkdk4412.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ struct odroid_fan_platform_data odroid_fan_pdata = {

.pwm_id = 0,
.pwm_periode_ns = 20972, // Freq 22KHz,
.pwm_duty = 255, // max=255,
.pwm_duty = 255, // max=255,
.pwm_start_temp = 50, // default 50,
};

static struct platform_device odroid_fan = {
Expand Down
39 changes: 37 additions & 2 deletions drivers/hardkernel/odroidu2_fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct odroid_fan {

int period;
int duty;
int start_temp;
int pwm_id;
};

Expand All @@ -62,6 +63,10 @@ static ssize_t set_pwm_duty (struct device *dev, struct device_attribute *attr,
static ssize_t show_pwm_duty (struct device *dev, struct device_attribute *attr, char *buf);
static DEVICE_ATTR(pwm_duty, S_IRWXUGO, show_pwm_duty, set_pwm_duty);

static ssize_t set_start_temp (struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t show_start_temp (struct device *dev, struct device_attribute *attr, char *buf);
static DEVICE_ATTR(start_temp, S_IRWXUGO, show_start_temp, set_start_temp);

static ssize_t set_fan_mode (struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t show_fan_mode (struct device *dev, struct device_attribute *attr, char *buf);
static DEVICE_ATTR(fan_mode, S_IRWXUGO, show_fan_mode, set_fan_mode);
Expand All @@ -70,6 +75,7 @@ static DEVICE_ATTR(fan_mode, S_IRWXUGO, show_fan_mode, set_fan_mode);
static struct attribute *odroid_fan_sysfs_entries[] = {
&dev_attr_pwm_enable.attr,
&dev_attr_pwm_duty.attr,
&dev_attr_start_temp.attr,
&dev_attr_fan_mode.attr,
NULL
};
Expand Down Expand Up @@ -202,6 +208,34 @@ static ssize_t show_pwm_duty (struct device *dev, struct device_attribute *attr,
}


//[*]------------------------------------------------------------------------------------------------------------------
//[*]------------------------------------------------------------------------------------------------------------------
static ssize_t set_start_temp (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct odroid_fan *fan = dev_get_drvdata(dev);
unsigned int val;

if(!(sscanf(buf, "%u\n", &val)))
return -EINVAL;

if((val >= FAN_TEMP_THROTTLE)||(val < 0)){
printk("PWM_0 : Invalid param. Start fan temperature range is 0 to %u \n", FAN_TEMP_THROTTLE - 1);
return count;
}

if(val == 0) val = 1;
fan->start_temp = val;
return count;
}

static ssize_t show_start_temp (struct device *dev, struct device_attribute *attr, char *buf)
{
struct odroid_fan *fan = dev_get_drvdata(dev);

return sprintf(buf, "PWM_0 : Fan starting temperature -> %d \n", fan->start_temp);
}


//[*]--------------------------------------------------------------------------------------------------[*]
//[*]--------------------------------------------------------------------------------------------------[*]
static int odroid_fan_resume(struct platform_device *dev)
Expand Down Expand Up @@ -233,7 +267,7 @@ void odroid_work(struct work_struct *work)

mutex_lock(&fan->mutex);

if(temperature < 50) {
if(temperature < fan->start_temp) {
pwm_disable(fan->pwm);
pwm_config(fan->pwm, 1, fan->period);
pwm_enable(fan->pwm);
Expand All @@ -245,7 +279,7 @@ void odroid_work(struct work_struct *work)
/* 83C is the first throttle..
* Lets not reach it
*/
fan->duty = 255 * temperature / 80;
fan->duty = 255 * (temperature - fan->start_temp) / (FAN_TEMP_THROTTLE - fan->start_temp);


if(fan->pwm_status) {
Expand Down Expand Up @@ -286,6 +320,7 @@ static int odroid_fan_probe (struct platform_device *pdev)

fan->period = fan->pdata->pwm_periode_ns;
fan->duty = fan->pdata->pwm_duty;
fan->start_temp = fan->pdata->pwm_start_temp;
pwm_config(fan->pwm, fan->duty * fan->period / 255, fan->period);
pwm_enable(fan->pwm);

Expand Down
3 changes: 3 additions & 0 deletions include/linux/platform_data/odroidu2_fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
#define ISA1200_PWM_GEN_MODE (2<<3)
#define ISA1200_WAVE_GEN_MODE (3<<3)

#define FAN_TEMP_THROTTLE 80

struct odroid_fan_platform_data {
int pwm_gpio;
int pwm_func;

int pwm_id;
unsigned short pwm_periode_ns;
unsigned short pwm_duty;
unsigned short pwm_start_temp;
};

#endif /* __LINUX_ODROID_FAN_H */

0 comments on commit 849348d

Please sign in to comment.