thermal: Add palmas thermal support
[linux-2.6.git] / drivers / thermal / pwm_fan.c
1 /*
2  * pwm_fan.c fan driver that is controlled by pwm
3  *
4  * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * Author: Anshul Jain <anshulj@nvidia.com>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <linux/therm_est.h>
22 #include <linux/slab.h>
23 #include <linux/platform_data/pwm_fan.h>
24 #include <linux/thermal.h>
25 #include <linux/mutex.h>
26 #include <linux/debugfs.h>
27 #include <linux/platform_device.h>
28 #include <linux/delay.h>
29 #include <linux/module.h>
30 #include <linux/debugfs.h>
31 #include <linux/uaccess.h>
32 #include <linux/seq_file.h>
33 #include <linux/pwm.h>
34 #include <linux/device.h>
35 #include <linux/sysfs.h>
36
37 struct fan_dev_data {
38         int next_state;
39         int active_steps;
40         int *fan_rpm;
41         int *fan_pwm;
42         int *fan_rru;
43         int *fan_rrd;
44         struct workqueue_struct *workqueue;
45         int fan_temp_control_flag;
46         struct pwm_device *pwm_dev;
47         int fan_cap_pwm;
48         int fan_cur_pwm;
49         int next_target_pwm;
50         struct thermal_cooling_device *cdev;
51         struct delayed_work fan_ramp_work;
52         int step_time;
53         int precision_multiplier;
54         struct mutex fan_state_lock;
55         int pwm_period;
56         struct device *dev;
57 };
58
59 #ifdef CONFIG_DEBUG_FS
60 static struct dentry *fan_debugfs_root;
61
62 static int fan_target_pwm_show(void *data, u64 *val)
63 {
64         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
65
66         if (!fan_data)
67                 return -EINVAL;
68         mutex_lock(&fan_data->fan_state_lock);
69         *val = ((struct fan_dev_data *)data)->next_target_pwm /
70                                         fan_data->precision_multiplier;
71         mutex_unlock(&fan_data->fan_state_lock);
72         return 0;
73 }
74
75 static int fan_target_pwm_set(void *data, u64 val)
76 {
77         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
78
79         if (!fan_data)
80                 return -EINVAL;
81
82         if (val > fan_data->pwm_period)
83                 val = fan_data->pwm_period;
84
85         mutex_lock(&fan_data->fan_state_lock);
86         fan_data->next_target_pwm =
87                 min((int)(val * fan_data->precision_multiplier),
88                 fan_data->fan_cap_pwm);
89
90         if (fan_data->next_target_pwm != fan_data->fan_cur_pwm)
91                 queue_delayed_work(fan_data->workqueue,
92                                         &fan_data->fan_ramp_work,
93                                         msecs_to_jiffies(fan_data->step_time));
94         mutex_unlock(&fan_data->fan_state_lock);
95         return 0;
96 }
97
98 static int fan_temp_control_show(void *data, u64 *val)
99 {
100         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
101
102         if (!fan_data)
103                 return -EINVAL;
104         mutex_lock(&fan_data->fan_state_lock);
105         *val = fan_data->fan_temp_control_flag;
106         mutex_unlock(&fan_data->fan_state_lock);
107         return 0;
108 }
109
110 static int fan_temp_control_set(void *data, u64 val)
111 {
112         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
113
114         if (!fan_data)
115                 return -EINVAL;
116
117         mutex_lock(&fan_data->fan_state_lock);
118         fan_data->fan_temp_control_flag = val > 0 ? 1 : 0;
119         mutex_unlock(&fan_data->fan_state_lock);
120         return 0;
121 }
122
123 static int fan_cap_pwm_set(void *data, u64 val)
124 {
125         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
126
127         if (!fan_data)
128                 return -EINVAL;
129
130         if (val > fan_data->pwm_period)
131                 val = fan_data->pwm_period;
132         mutex_lock(&fan_data->fan_state_lock);
133         fan_data->fan_cap_pwm = val * fan_data->precision_multiplier;
134         fan_data->next_target_pwm = min(fan_data->fan_cap_pwm,
135                                         fan_data->next_target_pwm);
136         mutex_unlock(&fan_data->fan_state_lock);
137         return 0;
138 }
139
140 static int fan_cap_pwm_show(void *data, u64 *val)
141 {
142         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
143
144         if (!fan_data)
145                 return -EINVAL;
146         mutex_lock(&fan_data->fan_state_lock);
147         *val = fan_data->fan_cap_pwm / fan_data->precision_multiplier;
148         mutex_unlock(&fan_data->fan_state_lock);
149         return 0;
150 }
151
152 static int fan_step_time_set(void *data, u64 val)
153 {
154         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
155
156         if (!fan_data)
157                 return -EINVAL;
158         mutex_lock(&fan_data->fan_state_lock);
159         fan_data->step_time = val;
160         mutex_unlock(&fan_data->fan_state_lock);
161         return 0;
162 }
163
164 static int fan_cur_pwm_show(void *data, u64 *val)
165 {
166         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
167
168         if (!fan_data)
169                 return -EINVAL;
170         mutex_lock(&fan_data->fan_state_lock);
171         *val = (fan_data->fan_cur_pwm / fan_data->precision_multiplier);
172         mutex_unlock(&fan_data->fan_state_lock);
173         return 0;
174 }
175
176 static int fan_step_time_show(void *data, u64 *val)
177 {
178         struct fan_dev_data *fan_data = (struct fan_dev_data *)data;
179
180         if (!fan_data)
181                 return -EINVAL;
182         mutex_lock(&fan_data->fan_state_lock);
183         *val = fan_data->step_time;
184         mutex_unlock(&fan_data->fan_state_lock);
185         return 0;
186 }
187
188 static int fan_debugfs_show(struct seq_file *s, void *data)
189 {
190         int i;
191         struct fan_dev_data *fan_data = s->private;
192
193         if (!fan_data)
194                 return -EINVAL;
195         seq_printf(s, "(Index, RPM, PWM, RRU*1024, RRD*1024)\n");
196         for (i = 0; i < fan_data->active_steps; i++) {
197                 seq_printf(s, "(%d, %d, %d, %d, %d)\n", i, fan_data->fan_rpm[i],
198                         fan_data->fan_pwm[i]/fan_data->precision_multiplier,
199                         fan_data->fan_rru[i],
200                         fan_data->fan_rrd[i]);
201         }
202         return 0;
203 }
204
205 static int fan_debugfs_open(struct inode *inode, struct file *file)
206 {
207         return single_open(file, fan_debugfs_show, inode->i_private);
208 }
209
210 static const struct file_operations fan_rpm_table_fops = {
211         .open           = fan_debugfs_open,
212         .read           = seq_read,
213         .llseek         = seq_lseek,
214         .release        = single_release,
215 };
216
217 DEFINE_SIMPLE_ATTRIBUTE(fan_cap_pwm_fops,
218                         fan_cap_pwm_show,
219                         fan_cap_pwm_set, "%llu\n");
220 DEFINE_SIMPLE_ATTRIBUTE(fan_temp_control_fops,
221                         fan_temp_control_show,
222                         fan_temp_control_set, "%llu\n");
223 DEFINE_SIMPLE_ATTRIBUTE(fan_target_pwm_fops,
224                         fan_target_pwm_show,
225                         fan_target_pwm_set, "%llu\n");
226 DEFINE_SIMPLE_ATTRIBUTE(fan_cur_pwm_fops,
227                         fan_cur_pwm_show,
228                         NULL, "%llu\n");
229 DEFINE_SIMPLE_ATTRIBUTE(fan_step_time_fops,
230                         fan_step_time_show,
231                         fan_step_time_set, "%llu\n");
232
233 static int pwm_fan_debug_init(struct fan_dev_data *fan_data)
234 {
235         fan_debugfs_root = debugfs_create_dir("tegra_fan", 0);
236
237         if (!fan_debugfs_root)
238                 return -ENOMEM;
239
240         if (!debugfs_create_file("target_pwm", 0644, fan_debugfs_root,
241                 (void *)fan_data,
242                 &fan_target_pwm_fops))
243                 goto err_out;
244
245         if (!debugfs_create_file("temp_control", 0644, fan_debugfs_root,
246                 (void *)fan_data,
247                 &fan_temp_control_fops))
248                 goto err_out;
249
250         if (!debugfs_create_file("pwm_cap", 0644, fan_debugfs_root,
251                 (void *)fan_data,
252                 &fan_cap_pwm_fops))
253                 goto err_out;
254
255         if (!debugfs_create_file("pwm_rpm_table", 0444, fan_debugfs_root,
256                 (void *)fan_data,
257                 &fan_rpm_table_fops))
258                 goto err_out;
259
260         if (!debugfs_create_file("step_time", 0644, fan_debugfs_root,
261                 (void *)fan_data,
262                 &fan_step_time_fops))
263                 goto err_out;
264
265         if (!debugfs_create_file("cur_pwm", 0444, fan_debugfs_root,
266                 (void *)fan_data,
267                 &fan_cur_pwm_fops))
268                 goto err_out;
269         return 0;
270
271 err_out:
272         debugfs_remove_recursive(fan_debugfs_root);
273         return -ENOMEM;
274 }
275 #else
276 static inline int pwm_fan_debug_init(struct fan_dev_data *fan_data)
277 {
278         return 0;
279 }
280 #endif /* DEBUG_FS*/
281
282 static int pwm_fan_get_cur_state(struct thermal_cooling_device *cdev,
283                                                 unsigned long *cur_state)
284 {
285         struct fan_dev_data *fan_data = cdev->devdata;
286
287         if (!fan_data)
288                 return -EINVAL;
289
290         mutex_lock(&fan_data->fan_state_lock);
291         *cur_state = fan_data->next_state;
292         mutex_unlock(&fan_data->fan_state_lock);
293         return 0;
294 }
295
296 static int pwm_fan_set_cur_state(struct thermal_cooling_device *cdev,
297                                                 unsigned long cur_state)
298 {
299         struct fan_dev_data *fan_data = cdev->devdata;
300
301         if (!fan_data)
302                 return -EINVAL;
303
304         mutex_lock(&fan_data->fan_state_lock);
305
306         fan_data->next_state = cur_state;
307
308         if (fan_data->next_state <= 0)
309                 fan_data->next_target_pwm = 0;
310         else
311                 fan_data->next_target_pwm = fan_data->fan_pwm[cur_state];
312
313         fan_data->next_target_pwm =
314                 min(fan_data->fan_cap_pwm, fan_data->next_target_pwm);
315         if (fan_data->next_target_pwm != fan_data->fan_cur_pwm &&
316                 (fan_data->fan_temp_control_flag))
317                 queue_delayed_work(fan_data->workqueue,
318                                         &(fan_data->fan_ramp_work),
319                                         msecs_to_jiffies(fan_data->step_time));
320
321         mutex_unlock(&fan_data->fan_state_lock);
322         return 0;
323 }
324
325 static int pwm_fan_get_max_state(struct thermal_cooling_device *cdev,
326                                                 unsigned long *max_state)
327 {
328         struct fan_dev_data *fan_data = cdev->devdata;
329
330         *max_state = fan_data->active_steps;
331         return 0;
332 }
333
334 static struct thermal_cooling_device_ops pwm_fan_cooling_ops = {
335         .get_max_state = pwm_fan_get_max_state,
336         .get_cur_state = pwm_fan_get_cur_state,
337         .set_cur_state = pwm_fan_set_cur_state,
338 };
339
340 static int fan_get_rru(int pwm, struct fan_dev_data *fan_data)
341 {
342         int i;
343
344         for (i = 0; i < fan_data->active_steps - 1 ; i++) {
345                 if ((pwm >= fan_data->fan_pwm[i]) &&
346                                 (pwm < fan_data->fan_pwm[i + 1])) {
347                         return fan_data->fan_rru[i];
348                 }
349         }
350         return fan_data->fan_rru[fan_data->active_steps - 1];
351 }
352
353 static int fan_get_rrd(int pwm, struct fan_dev_data *fan_data)
354 {
355         int i;
356
357         for (i = 0; i < fan_data->active_steps - 1 ; i++) {
358                 if ((pwm >= fan_data->fan_pwm[i]) &&
359                                 (pwm < fan_data->fan_pwm[i + 1])) {
360                         return fan_data->fan_rrd[i];
361                 }
362         }
363         return fan_data->fan_rrd[fan_data->active_steps - 1];
364 }
365
366 static void set_pwm_duty_cycle(int pwm, struct fan_dev_data *fan_data)
367 {
368         if (fan_data != NULL && fan_data->pwm_dev != NULL) {
369                 pwm_config(fan_data->pwm_dev, fan_data->pwm_period - pwm,
370                                                         fan_data->pwm_period);
371                 pwm_enable(fan_data->pwm_dev);
372         } else {
373                 dev_err(fan_data->dev,
374                                 "FAN:PWM device or fan data is null\n");
375         }
376 }
377
378 static int get_next_higher_pwm(int pwm, struct fan_dev_data *fan_data)
379 {
380         int i;
381
382         for (i = 0; i < fan_data->active_steps; i++)
383                 if (pwm < fan_data->fan_pwm[i])
384                         return fan_data->fan_pwm[i];
385
386         return fan_data->fan_pwm[fan_data->active_steps - 1];
387 }
388
389 static int get_next_lower_pwm(int pwm, struct fan_dev_data *fan_data)
390 {
391         int i;
392
393         for (i = fan_data->active_steps - 1; i >= 0; i--)
394                 if (pwm > fan_data->fan_pwm[i])
395                         return fan_data->fan_pwm[i];
396
397         return fan_data->fan_pwm[fan_data->active_steps - 1];
398 }
399
400 static void fan_ramping_work_func(struct work_struct *work)
401 {
402         int rru, rrd;
403         int cur_pwm, next_pwm;
404         struct delayed_work *dwork = container_of(work, struct delayed_work,
405                                                                         work);
406         struct fan_dev_data *fan_data = container_of(dwork, struct
407                                                 fan_dev_data, fan_ramp_work);
408
409         if (!fan_data) {
410                 dev_err(fan_data->dev, "Fan data is null\n");
411                 return;
412         }
413         mutex_lock(&fan_data->fan_state_lock);
414         cur_pwm = fan_data->fan_cur_pwm;
415         rru = fan_get_rru(cur_pwm, fan_data);
416         rrd = fan_get_rrd(cur_pwm, fan_data);
417         next_pwm = cur_pwm;
418
419         if (fan_data->next_target_pwm > fan_data->fan_cur_pwm) {
420                 fan_data->fan_cur_pwm = fan_data->fan_cur_pwm + rru;
421                 next_pwm = min(
422                                 get_next_higher_pwm(cur_pwm, fan_data),
423                                 fan_data->fan_cur_pwm);
424                 next_pwm = min(fan_data->next_target_pwm, next_pwm);
425                 next_pwm = min(fan_data->fan_cap_pwm, next_pwm);
426         } else if (fan_data->next_target_pwm < fan_data->fan_cur_pwm) {
427                 fan_data->fan_cur_pwm = fan_data->fan_cur_pwm - rrd;
428                 next_pwm = max(get_next_lower_pwm(cur_pwm, fan_data),
429                                                         fan_data->fan_cur_pwm);
430                 next_pwm = max(next_pwm, fan_data->next_target_pwm);
431                 next_pwm = max(0, next_pwm);
432         }
433         set_pwm_duty_cycle(next_pwm/fan_data->precision_multiplier, fan_data);
434         fan_data->fan_cur_pwm = next_pwm;
435         if (fan_data->next_target_pwm != next_pwm)
436                 queue_delayed_work(fan_data->workqueue,
437                                 &(fan_data->fan_ramp_work),
438                                 msecs_to_jiffies(fan_data->step_time));
439         mutex_unlock(&fan_data->fan_state_lock);
440 }
441
442
443 static ssize_t show_fan_pwm_cap_sysfs(struct device *dev,
444                                 struct device_attribute *attr, char *buf)
445 {
446         struct fan_dev_data *fan_data = dev_get_drvdata(dev);
447         int ret;
448
449         if (!fan_data)
450                 return -EINVAL;
451         mutex_lock(&fan_data->fan_state_lock);
452         ret = sprintf(buf, "%d\n",
453                 (fan_data->fan_cap_pwm / fan_data->precision_multiplier));
454         mutex_unlock(&fan_data->fan_state_lock);
455         return ret;
456 }
457
458 static ssize_t set_fan_pwm_cap_sysfs(struct device *dev,
459         struct device_attribute *attr, const char *buf, size_t count)
460 {
461         struct fan_dev_data *fan_data = dev_get_drvdata(dev);
462         long val;
463         int ret;
464
465         ret = kstrtol(buf, 10, &val);
466
467         if (ret < 0)
468                 return -EINVAL;
469
470         if (!fan_data)
471                 return -EINVAL;
472
473         if (val < 0)
474                 val = 0;
475         else if (val > fan_data->pwm_period)
476                 val = fan_data->pwm_period;
477         mutex_lock(&fan_data->fan_state_lock);
478         fan_data->fan_cap_pwm = val * fan_data->precision_multiplier;
479         fan_data->next_target_pwm = min(fan_data->fan_cap_pwm,
480                                         fan_data->next_target_pwm);
481         mutex_unlock(&fan_data->fan_state_lock);
482         return count;
483 }
484
485 static DEVICE_ATTR(pwm_cap, S_IWUSR | S_IRUGO, show_fan_pwm_cap_sysfs,
486                                                         set_fan_pwm_cap_sysfs);
487 static struct attribute *pwm_fan_attributes[] = {
488         &dev_attr_pwm_cap.attr,
489         NULL
490 };
491
492 static const struct attribute_group pwm_fan_group = {
493         .attrs = pwm_fan_attributes,
494 };
495
496 static int add_sysfs_entry(struct device *dev)
497 {
498         return sysfs_create_group(&dev->kobj, &pwm_fan_group);
499 }
500
501 static void remove_sysfs_entry(struct device *dev)
502 {
503         sysfs_remove_group(&dev->kobj, &pwm_fan_group);
504 }
505
506 static int __devinit pwm_fan_probe(struct platform_device *pdev)
507 {
508         int i;
509         struct pwm_fan_platform_data *data;
510         struct fan_dev_data *fan_data;
511         int *rpm_data;
512         int err = 0;
513
514         data = dev_get_platdata(&pdev->dev);
515         if (!data) {
516                 dev_err(&pdev->dev, "platform data is null\n");
517                 return -EINVAL;
518         }
519
520         fan_data = devm_kzalloc(&pdev->dev,
521                                 sizeof(struct fan_dev_data), GFP_KERNEL);
522         if (!fan_data)
523                 return -ENOMEM;
524
525         rpm_data = devm_kzalloc(&pdev->dev,
526                         4 * sizeof(int) * data->active_steps, GFP_KERNEL);
527         if (!rpm_data)
528                 return -ENOMEM;
529
530         fan_data->fan_rpm = rpm_data;
531         fan_data->fan_pwm = rpm_data + data->active_steps;
532         fan_data->fan_rru = fan_data->fan_pwm + data->active_steps;
533         fan_data->fan_rrd = fan_data->fan_rru + data->active_steps;
534
535         mutex_init(&fan_data->fan_state_lock);
536
537         fan_data->workqueue = alloc_workqueue(dev_name(&pdev->dev),
538                                 WQ_HIGHPRI | WQ_UNBOUND | WQ_RESCUER, 1);
539         if (!fan_data->workqueue)
540                 return -ENOMEM;
541
542         INIT_DELAYED_WORK(&(fan_data->fan_ramp_work), fan_ramping_work_func);
543
544         fan_data->precision_multiplier = data->precision_multiplier;
545         fan_data->fan_cap_pwm = data->pwm_cap * data->precision_multiplier;
546         fan_data->step_time = data->step_time;
547         fan_data->active_steps = data->active_steps;
548         fan_data->pwm_period = data->pwm_period;
549         fan_data->dev = &pdev->dev;
550
551         for (i = 0; i < fan_data->active_steps; i++) {
552                 fan_data->fan_rpm[i] = data->active_rpm[i];
553                 fan_data->fan_pwm[i] = data->active_pwm[i];
554                 fan_data->fan_rru[i] = data->active_rru[i];
555                 fan_data->fan_rrd[i] = data->active_rrd[i];
556                 dev_info(&pdev->dev, "rpm=%d, pwm=%d, rru=%d, rrd=%d\n",
557                                                 fan_data->fan_rpm[i],
558                                                 fan_data->fan_pwm[i],
559                                                 fan_data->fan_rru[i],
560                                                 fan_data->fan_rrd[i]);
561         }
562
563         fan_data->cdev =
564                 thermal_cooling_device_register((char *)dev_name(&pdev->dev),
565                                         fan_data, &pwm_fan_cooling_ops);
566
567         if (IS_ERR_OR_NULL(fan_data->cdev)) {
568                 dev_err(&pdev->dev, "Failed to register cooling device\n");
569                 return -EINVAL;
570         }
571
572         fan_data->pwm_dev = pwm_request(data->pwm_id, dev_name(&pdev->dev));
573         if (IS_ERR_OR_NULL(fan_data->pwm_dev)) {
574                 dev_err(&pdev->dev, "unable to request PWM for fan\n");
575                 err = -ENODEV;
576                 goto pwm_req_fail;
577         } else {
578                 dev_info(&pdev->dev, "got pwm for fan\n");
579         }
580
581         platform_set_drvdata(pdev, fan_data);
582
583         /*turn temp control on*/
584         fan_data->fan_temp_control_flag = 1;
585         set_pwm_duty_cycle(0, fan_data);
586
587         if (add_sysfs_entry(&pdev->dev) < 0) {
588                 dev_err(&pdev->dev, "FAN:Can't create syfs node");
589                 err = -ENOMEM;
590                 goto sysfs_fail;
591         }
592
593         if (pwm_fan_debug_init(fan_data) < 0) {
594                 dev_err(&pdev->dev, "FAN:Can't create debug fs nodes");
595                 /*Just continue without debug fs*/
596         }
597         return err;
598
599 sysfs_fail:
600         pwm_free(fan_data->pwm_dev);
601 pwm_req_fail:
602         thermal_cooling_device_unregister(fan_data->cdev);
603         return err;
604 }
605
606 static int __devexit pwm_fan_remove(struct platform_device *pdev)
607 {
608         struct fan_dev_data *fan_data = platform_get_drvdata(pdev);
609
610         if (!fan_data)
611                 return -EINVAL;
612         pwm_config(fan_data->pwm_dev, 0, fan_data->pwm_period);
613         pwm_disable(fan_data->pwm_dev);
614         pwm_free(fan_data->pwm_dev);
615         thermal_cooling_device_unregister(fan_data->cdev);
616         remove_sysfs_entry(&pdev->dev);
617         return 0;
618 }
619
620 #if CONFIG_PM
621 static int pwm_fan_suspend(struct platform_device *pdev, pm_message_t state)
622 {
623         struct fan_dev_data *fan_data = platform_get_drvdata(pdev);
624
625         mutex_lock(&fan_data->fan_state_lock);
626         cancel_delayed_work(&fan_data->fan_ramp_work);
627         /*Turn the fan off*/
628         fan_data->fan_cur_pwm = 0;
629         set_pwm_duty_cycle(0, fan_data);
630
631         /*Stop thermal control*/
632         fan_data->fan_temp_control_flag = 0;
633         mutex_unlock(&fan_data->fan_state_lock);
634         return 0;
635 }
636
637 static int pwm_fan_resume(struct platform_device *pdev)
638 {
639         struct fan_dev_data *fan_data = platform_get_drvdata(pdev);
640
641         /*Sanity check, want to make sure fan is off when the driver resumes*/
642         mutex_lock(&fan_data->fan_state_lock);
643         set_pwm_duty_cycle(0, fan_data);
644
645         /*Start thermal control*/
646         fan_data->fan_temp_control_flag = 1;
647         if (fan_data->next_target_pwm != fan_data->fan_cur_pwm)
648                 queue_delayed_work(fan_data->workqueue,
649                                         &fan_data->fan_ramp_work,
650                                         msecs_to_jiffies(fan_data->step_time));
651         mutex_unlock(&fan_data->fan_state_lock);
652         return 0;
653 }
654 #endif
655
656 static struct platform_driver pwm_fan_driver = {
657         .driver = {
658                 .owner = THIS_MODULE,
659                 .name = "pwm-fan",
660         },
661         .probe = pwm_fan_probe,
662         .remove = __devexit_p(pwm_fan_remove),
663 #if CONFIG_PM
664         .suspend = pwm_fan_suspend,
665         .resume = pwm_fan_resume,
666 #endif
667 };
668
669 module_platform_driver(pwm_fan_driver);
670
671 MODULE_DESCRIPTION("pwm fan driver");
672 MODULE_AUTHOR("Anshul Jain <anshulj@nvidia.com>");
673 MODULE_LICENSE("GPL v2");