@@ -47,6 +47,7 @@ struct odroid_fan {
4747 int period ;
4848 int duty ;
4949 int start_temp ;
50+ int start_duty ;
5051 int pwm_id ;
5152};
5253
@@ -67,6 +68,10 @@ static ssize_t set_start_temp (struct device *dev, struct device_attribute *attr
6768static ssize_t show_start_temp (struct device * dev , struct device_attribute * attr , char * buf );
6869static DEVICE_ATTR (start_temp , S_IRWXUGO , show_start_temp , set_start_temp ) ;
6970
71+ static ssize_t set_start_duty (struct device * dev , struct device_attribute * attr , const char * buf , size_t count );
72+ static ssize_t show_start_duty (struct device * dev , struct device_attribute * attr , char * buf );
73+ static DEVICE_ATTR (start_duty , S_IRWXUGO , show_start_duty , set_start_duty ) ;
74+
7075static ssize_t set_fan_mode (struct device * dev , struct device_attribute * attr , const char * buf , size_t count );
7176static ssize_t show_fan_mode (struct device * dev , struct device_attribute * attr , char * buf );
7277static DEVICE_ATTR (fan_mode , S_IRWXUGO , show_fan_mode , set_fan_mode ) ;
@@ -76,6 +81,7 @@ static struct attribute *odroid_fan_sysfs_entries[] = {
7681 & dev_attr_pwm_enable .attr ,
7782 & dev_attr_pwm_duty .attr ,
7883 & dev_attr_start_temp .attr ,
84+ & dev_attr_start_duty .attr ,
7985 & dev_attr_fan_mode .attr ,
8086 NULL
8187};
@@ -236,6 +242,33 @@ static ssize_t show_start_temp (struct device *dev, struct device_attribute *att
236242}
237243
238244
245+ //[*]------------------------------------------------------------------------------------------------------------------
246+ //[*]------------------------------------------------------------------------------------------------------------------
247+ static ssize_t set_start_duty (struct device * dev , struct device_attribute * attr , const char * buf , size_t count )
248+ {
249+ struct odroid_fan * fan = dev_get_drvdata (dev );
250+ unsigned int val ;
251+
252+ if (!(sscanf (buf , "%u\n" , & val )))
253+ return - EINVAL ;
254+
255+ if ((val > 256 )|| (val < 0 )){
256+ printk ("PWM_0 : Invalid param. Starting duty range is 0 to 255 \n" );
257+ return count ;
258+ }
259+
260+ fan -> start_duty = val ;
261+ return count ;
262+ }
263+
264+ static ssize_t show_start_duty (struct device * dev , struct device_attribute * attr , char * buf )
265+ {
266+ struct odroid_fan * fan = dev_get_drvdata (dev );
267+
268+ return sprintf (buf , "PWM_0 : Fan starting duty -> %d \n" , fan -> start_duty );
269+ }
270+
271+
239272//[*]--------------------------------------------------------------------------------------------------[*]
240273//[*]--------------------------------------------------------------------------------------------------[*]
241274static int odroid_fan_resume (struct platform_device * dev )
@@ -271,6 +304,10 @@ void odroid_work(struct work_struct *work)
271304 pwm_disable (fan -> pwm );
272305 pwm_config (fan -> pwm , 1 , fan -> period );
273306 pwm_enable (fan -> pwm );
307+ /* Set duty to zero.
308+ * Otherwise it will stay at the last set entry.
309+ */
310+ fan -> duty = 0 ;
274311 mutex_unlock (& fan -> mutex );
275312 queue_delayed_work_on (0 , fan -> wq , & fan -> work , usecs_to_jiffies (1500 * 1000 ));
276313 return ;
@@ -281,7 +318,14 @@ void odroid_work(struct work_struct *work)
281318 */
282319 fan -> duty = 255 * (temperature - fan -> start_temp ) / (FAN_TEMP_THROTTLE - fan -> start_temp );
283320
284-
321+ /* Check if duty is lower than start_duty.
322+ * If yes, set it to start_duty.
323+ * Lets the user set an at least value for duty.
324+ */
325+ if (fan -> duty < fan -> start_duty ) {
326+ fan -> duty = fan -> start_duty ;
327+ }
328+
285329 if (fan -> pwm_status ) {
286330 pwm_disable (fan -> pwm );
287331 pwm_config (fan -> pwm , fan -> duty * fan -> period / 255 , fan -> period );
0 commit comments