msm: dcvs: use wait_q.

It is cleaner to use wait_q mechanism instead of waking up the thread
and managing the scheduling flag ourselves.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 33bf417160e9340f2dd5f9f275e7e6021987bfe1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit de943e4aff2a26e0d21b208d85b5876c31bfda85)

Change-Id: I4316ee58633f7353197654074263466cdaa25778
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
diff --git a/arch/arm/mach-msm/msm_dcvs.c b/arch/arm/mach-msm/msm_dcvs.c
index 4ef120c..f761bf9 100644
--- a/arch/arm/mach-msm/msm_dcvs.c
+++ b/arch/arm/mach-msm/msm_dcvs.c
@@ -96,6 +96,7 @@
 	struct msm_dcvs_core_info *info;
 	int sensor;
 	int pending_freq;
+	wait_queue_head_t wait_q;
 };
 
 static int msm_dcvs_debug;
@@ -260,24 +261,21 @@
 	static struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1};
 
 	sched_setscheduler(current, SCHED_FIFO, &param);
-	set_current_state(TASK_UNINTERRUPTIBLE);
 
 	while (!kthread_should_stop()) {
-		mutex_lock(&core->lock);
-		__msm_dcvs_change_freq(core);
-		__msm_dcvs_report_temp(core);
-		mutex_unlock(&core->lock);
-
-		schedule();
+		wait_event(core->wait_q, !(core->pending_freq == 0 ||
+					  core->pending_freq == -1) ||
+					  kthread_should_stop());
 
 		if (kthread_should_stop())
 			break;
 
-		set_current_state(TASK_UNINTERRUPTIBLE);
+		mutex_lock(&core->lock);
+		__msm_dcvs_change_freq(core);
+		__msm_dcvs_report_temp(core);
+		mutex_unlock(&core->lock);
 	}
 
-	__set_current_state(TASK_RUNNING);
-
 	return 0;
 }
 
@@ -306,7 +304,7 @@
 		core->time_start = ktime_to_ns(ktime_get());
 
 		if (core->task)
-			wake_up_process(core->task);
+			wake_up(&core->wait_q);
 	} else {
 		if (freq_changed)
 			*freq_changed = 0;
@@ -628,8 +626,8 @@
 		core_handles[core->handle - CORE_HANDLE_OFFSET] = NULL;
 		goto bail;
 	}
-
-	core->task = kthread_create(msm_dcvs_do_freq, (void *)core,
+	init_waitqueue_head(&core->wait_q);
+	core->task = kthread_run(msm_dcvs_do_freq, (void *)core,
 			"msm_dcvs/%d", core->handle);
 bail:
 	mutex_unlock(&core->lock);