tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / power / load_analyzer_exynos3250.c
1 /* drivers/power/load_analyzer_exynos3250.c */
2
3 #include <linux/trm.h>
4
5 unsigned int get_bimc_clk(void);
6 unsigned int get_snoc_clk(void);
7 extern int mali_gpu_clk;
8 extern int mali_dvfs_utilization;
9
10 void store_cpu_load(unsigned int cpufreq[], unsigned int cpu_load[])
11 {
12         unsigned int j = 0, cnt = 0;
13         unsigned long long t, t_interval;
14         unsigned int  t_interval_us;
15         static unsigned long long before_t;
16         unsigned long  nanosec_rem;
17         int cpu_max = 0, cpu_min = 0;
18         struct cpufreq_policy *policy;
19         static int cpu_busy_level_before = 0;
20
21         if (cpu_task_history_onoff == 0)
22                 return;
23
24         if (++cpu_load_freq_history_cnt >= cpu_load_history_num)
25                 cpu_load_freq_history_cnt = 0;
26
27         cnt = cpu_load_freq_history_cnt;
28
29         policy = cpufreq_cpu_get(0);
30
31         if (policy !=NULL) {
32                 cpu_min = pm_qos_request(PM_QOS_CPU_FREQ_MIN);
33                 if (cpu_min < policy->min)
34                         cpu_min = policy->min;
35
36                 cpu_max = pm_qos_request(PM_QOS_CPU_FREQ_MAX);
37                 if (cpu_max > policy->max)
38                         cpu_max = policy->max;
39
40                 cpufreq_cpu_put(policy);
41         }
42
43         cpu_load_freq_history[cnt].cpu_min_locked_freq = cpu_min;
44         cpu_load_freq_history[cnt].cpu_max_locked_freq = cpu_max;
45
46         cpu_load_freq_history[cnt].cpu_min_locked_online = pm_qos_request(PM_QOS_CPU_ONLINE_MIN);
47         cpu_load_freq_history[cnt].cpu_max_locked_online = pm_qos_request(PM_QOS_CPU_ONLINE_MAX);
48
49         t = cpu_clock(UINT_MAX);
50
51         if (before_t == 0)
52                 before_t = t;
53
54         for (j = 0; j < CPU_NUM; j++) {
55                 cpu_load_freq_history[cnt].task_history_cnt[j]
56                         = cpu_task_history_cnt[j];
57         }
58
59 #if defined (CONFIG_CHECK_WORK_HISTORY)
60         for (j = 0; j < CPU_NUM; j++) {
61                 cpu_load_freq_history[cnt].work_history_cnt[j]
62                         = cpu_work_history_cnt[j];
63         }
64 #endif
65
66 #if defined (CONFIG_SLP_INPUT_REC)
67         cpu_load_freq_history[cnt].input_rec_history_cnt
68                 = input_rec_history_cnt;
69 #endif
70
71         t_interval = t -before_t;
72         do_div(t_interval, 1000);
73         t_interval_us = t_interval;
74         before_t = t;
75
76         if (t_interval != 0) {
77                 cpu_load_freq_history[cnt].cpu_idle_time[0]
78                         = (cpuidle_get_idle_residency_time(0) * 1000 + 5) / t_interval_us;
79                 cpu_load_freq_history[cnt].cpu_idle_time[1]
80                         = (cpuidle_get_idle_residency_time(1) * 1000 +5) / t_interval_us;
81                 cpu_load_freq_history[cnt].cpu_idle_time[2]
82                         = (cpuidle_get_idle_residency_time(2) * 1000 +5) / t_interval_us;
83         }
84
85         if (saved_load_factor.suspend_state == 1)
86                 cpu_load_freq_history[cnt].status = 'S';
87         else if (saved_load_factor.suspend_state == 0)
88                 cpu_load_freq_history[cnt].status = 'N';
89         else if (saved_load_factor.suspend_state == -1)
90                 cpu_load_freq_history[cnt].status = 'F';
91
92         cpu_load_freq_history[cnt].time_stamp = t;
93         nanosec_rem = do_div(t, 1000000000);
94         snprintf(cpu_load_freq_history[cnt].time, sizeof(cpu_load_freq_history[cnt].time),
95                 "%2lu.%02lu", (unsigned long) t,(unsigned long)nanosec_rem / 10000000);
96
97         for (j = 0; j < CPU_NUM; j++) {
98                 cpu_load_freq_history[cnt].cpufreq[j] = cpufreq[j];
99                 cpu_load_freq_history[cnt].cpu_load[j] = cpu_load[j];
100         }
101         cpu_load_freq_history[cnt].touch_event = 0;
102         cpu_load_freq_history[cnt].nr_onlinecpu = num_online_cpus();
103         cpu_load_freq_history[cnt].nr_run_avg
104                 = saved_load_factor.nr_running_task;
105
106         cpu_load_freq_history[cnt].lcd_brightness = saved_load_factor.lcd_brightness;
107
108         cpu_load_freq_history[cnt].suspend_count = saved_load_factor.suspend_count;
109
110 #if defined(CONFIG_SLP_CHECK_BUS_LOAD)
111         cpu_load_freq_history[cnt].nr_run_avg
112                                         = saved_load_factor.nr_running_task;
113
114         cpu_load_freq_history[cnt].mif_bus_freq
115                                         = saved_load_factor.mif_bus_freq;
116         cpu_load_freq_history[cnt].int_bus_freq
117                                         = saved_load_factor.int_bus_freq;
118         cpu_load_freq_history[cnt].mif_bus_load
119                                         = saved_load_factor.mif_bus_load;
120         cpu_load_freq_history[cnt].mif_bus_load
121                                         = saved_load_factor.mif_bus_load;
122
123         cpu_load_freq_history[cnt].gpu_freq
124                                         = mali_gpu_clk;
125         cpu_load_freq_history[cnt].gpu_utilization
126                                         = mali_dvfs_utilization;
127 #endif
128
129 #if defined(CONFIG_SLP_CHECK_RESOURCE)
130         cpu_load_freq_history[cnt].bt_tx_bytes
131                 = saved_load_factor.bt_tx_bytes;
132         saved_load_factor.bt_tx_bytes = 0;
133
134         cpu_load_freq_history[cnt].bt_rx_bytes
135                 = saved_load_factor.bt_rx_bytes;
136         saved_load_factor.bt_rx_bytes = 0;
137
138         cpu_load_freq_history[cnt].bt_enabled
139                 = saved_load_factor.bt_enabled;
140
141         cpu_load_freq_history[cnt].wifi_tx_bytes
142                 = saved_load_factor.wifi_tx_bytes;
143         saved_load_factor.wifi_tx_bytes = 0;
144
145         cpu_load_freq_history[cnt].wifi_rx_bytes
146                 = saved_load_factor.wifi_rx_bytes;
147         saved_load_factor.wifi_rx_bytes = 0;
148
149         cpu_load_freq_history[cnt].wifi_enabled
150                 = saved_load_factor.wifi_enabled;
151
152 #endif
153
154         cpu_load_freq_history[cnt].pid = saved_load_factor.active_app_pid;
155         cpu_load_freq_history[cnt].battery_soc = saved_load_factor.battery_soc;
156
157
158         cpu_busy_level = check_load_level(cnt);
159         if (cpu_busy_level != cpu_busy_level_before) {
160                 pr_info("cpu_busy_level=%d->%d", cpu_busy_level_before, cpu_busy_level);
161                 cpu_busy_level_before = cpu_busy_level;
162                 update_cpu_busy_level();
163         }
164
165 #if defined(CONFIG_SLP_BUS_CLK_CHECK_LOAD)
166 {
167         unsigned int pm_domains;
168         unsigned int clk_gates[CLK_GATES_NUM];
169         clk_mon_power_domain(&pm_domains);
170         clk_mon_clock_gate(clk_gates);
171
172         cpu_load_freq_history[cnt].power_domains[0] = pm_domains;
173         memcpy(cpu_load_freq_history[cnt].clk_gates
174                                         , clk_gates, CLK_GATES_NUM*sizeof(unsigned int));
175 }
176 #endif
177
178 #if defined(CONFIG_SLP_CURRENT_MONITOR)
179         if (current_monitor_en == 1)
180                 current_monitor_manager(cnt);
181 #endif
182
183 }
184
185 char cpu_load_freq_menu[] ="=======================================" \
186                         "===============================================\n" \
187                         "     TIME    CPU_FREQ  F_LOCK   O_LOCK  [INDEX]    " \
188                         "CPU0   CPU1   ONLINE   NR_RUN\n";
189
190 unsigned int show_cpu_load_freq_sub(int cnt, int show_cnt, char *buf, unsigned int buf_size, int ret)
191 {
192         int j, delta = 0;
193
194         if ((cnt - show_cnt) < 0) {
195                 delta = cnt - show_cnt;
196                 cnt = cpu_load_history_num + delta;
197         } else
198                 cnt -= show_cnt;
199
200         if ((cnt+1 >= cpu_load_history_num)
201                         || (cpu_load_freq_history_view[cnt+1].time == 0))
202                 cnt = 0;
203         else
204                 cnt++;
205
206         for (j = 0; j < show_cnt; j++) {
207                 if (cnt > cpu_load_history_num-1)
208                         cnt = 0;
209                 ret +=  snprintf(buf + ret, PAGE_SIZE - ret
210                         , "%10s\t%d.%d    %d.%d/%d.%d   %d/%d    [%5d]    %3d    %3d     "
211                                 "%3d    %3d.%02d\n"
212                         , cpu_load_freq_history_view[cnt].time
213                         , cpu_load_freq_history_view[cnt].cpufreq[0]/1000000
214                         , (cpu_load_freq_history_view[cnt].cpufreq[0]/100000) % 10
215                         , cpu_load_freq_history_view[cnt].cpu_min_locked_freq/1000000
216                         , (cpu_load_freq_history_view[cnt].cpu_min_locked_freq/100000) % 10
217                         , cpu_load_freq_history_view[cnt].cpu_max_locked_freq/1000000
218                         , (cpu_load_freq_history_view[cnt].cpu_max_locked_freq/100000) %10
219                         , cpu_load_freq_history_view[cnt].cpu_min_locked_online
220                         , cpu_load_freq_history_view[cnt].cpu_max_locked_online
221                         , cnt
222                         , cpu_load_freq_history_view[cnt].cpu_load[0]
223                         , cpu_load_freq_history_view[cnt].cpu_load[1]
224                         , cpu_load_freq_history_view[cnt].nr_onlinecpu
225                         , cpu_load_freq_history_view[cnt].nr_run_avg/100
226                         , cpu_load_freq_history_view[cnt].nr_run_avg%100);
227
228                 ++cnt;
229         }
230         return ret;
231
232 }
233
234 #if defined(CONFIG_SLP_CHECK_BUS_LOAD)
235
236 char cpu_bus_load_freq_menu[] ="==============================" \
237                         "===========================================" \
238                         "============================================" \
239                         "===========================================\n" \
240                         "   TIME    STA  CPU_F   F_LOCK   O_LOCK  [INDEX]    " \
241                         "CPU0 ( C1/ C2/ C3)    CPU1   ONLINE    NR_RUN    MIF_F    MIF_L    INT_F   INT_L" \
242                         "    GPU_F  GPU_UTIL   INPUT\n";
243
244
245 unsigned int show_cpu_bus_load_freq_sub(int cnt, int show_cnt
246                                         , char *buf, unsigned int buf_size, int ret)
247 {
248         int j, delta = 0;
249
250         if ((cnt - show_cnt) < 0) {
251                 delta = cnt - show_cnt;
252                 cnt = cpu_load_history_num + delta;
253         } else
254                 cnt -= show_cnt;
255
256         if ((cnt+1 >= cpu_load_history_num)
257                         || (cpu_load_freq_history_view[cnt+1].time == 0))
258                 cnt = 0;
259         else
260                 cnt++;
261
262         for (j = 0; j < show_cnt; j++) {
263                 if (cnt > cpu_load_history_num-1)
264                         cnt = 0;
265
266                 ret +=  snprintf(buf + ret, buf_size - ret
267                         , "%8s    %c    %d.%d    %d.%d/%d.%d   %d/%d    [%5d]     %3d (%3d/%3d/%3d)    %3d     "
268                                 "%3d     %3d.%02d      %3d      %3d      %3d     %3d      %3d     %3d"
269                                 "     %5d\n"
270                         , cpu_load_freq_history_view[cnt].time
271                         , cpu_load_freq_history_view[cnt].status
272                         , cpu_load_freq_history_view[cnt].cpufreq[0]/1000000
273                         , (cpu_load_freq_history_view[cnt].cpufreq[0]/100000) % 10
274                         , cpu_load_freq_history_view[cnt].cpu_min_locked_freq/1000000
275                         , (cpu_load_freq_history_view[cnt].cpu_min_locked_freq/100000) % 10
276                         , cpu_load_freq_history_view[cnt].cpu_max_locked_freq/1000000
277                         , (cpu_load_freq_history_view[cnt].cpu_max_locked_freq/100000) %10
278                         , cpu_load_freq_history_view[cnt].cpu_min_locked_online
279                         , cpu_load_freq_history_view[cnt].cpu_max_locked_online
280                         , cnt
281                         , cpu_load_freq_history_view[cnt].cpu_load[0]
282                         , cpu_load_freq_history_view[cnt].cpu_idle_time[0]/10
283                         , cpu_load_freq_history_view[cnt].cpu_idle_time[1]/10
284                         , cpu_load_freq_history_view[cnt].cpu_idle_time[2]/10
285                         , cpu_load_freq_history_view[cnt].cpu_load[1]
286                         , cpu_load_freq_history_view[cnt].nr_onlinecpu
287                         , cpu_load_freq_history_view[cnt].nr_run_avg/100
288                         , cpu_load_freq_history_view[cnt].nr_run_avg%100
289                         , cpu_load_freq_history_view[cnt].mif_bus_freq/1000
290                         , cpu_load_freq_history_view[cnt].mif_bus_load
291                         , cpu_load_freq_history_view[cnt].int_bus_freq/1000
292                         , cpu_load_freq_history_view[cnt].int_bus_load
293                         , cpu_load_freq_history_view[cnt].gpu_freq
294                         , cpu_load_freq_history_view[cnt].gpu_utilization
295                         , cpu_load_freq_history_view[cnt].input_rec_history_cnt);
296
297                 ++cnt;
298         }
299         return ret;
300
301 }
302 #endif
303
304 #if defined(CONFIG_SLP_BUS_CLK_CHECK_LOAD)
305 char cpu_bus_clk_load_freq_menu[] ="============================" \
306                         "============================================" \
307                         "============================================" \
308                         "============================================" \
309                         "============================================\n" \
310                         "   TIME    STA  CPU_F   F_LOCK   O_LOCK  [INDEX]    " \
311                         "CPU0 ( C1/ C2/ C3)    CPU1   ONLINE    NR_RUN    MIF_F    MIF_L    INT_F   INT_L" \
312                         "    GPU_F  GPU_UTIL   INPUT" \
313                         "    PD    CLK1      CLK2      CLK3      CLK4\n";
314
315
316 unsigned int show_cpu_bus_clk_load_freq_sub(int cnt
317                                         , int show_cnt, char *buf, int ret)
318 {
319         int j, delta = 0;
320
321         if ((cnt - show_cnt) < 0) {
322                 delta = cnt - show_cnt;
323                 cnt = cpu_load_history_num + delta;
324         } else
325                 cnt -= show_cnt;
326
327         if ((cnt+1 >= cpu_load_history_num)
328                         || (cpu_load_freq_history_view[cnt+1].time == 0))
329                 cnt = 0;
330         else
331                 cnt++;
332
333         for (j = 0; j < show_cnt; j++) {
334
335                 if (cnt > cpu_load_history_num-1)
336                         cnt = 0;
337
338                 if (ret < PAGE_SIZE - 1) {
339                 ret +=  snprintf(buf + ret, PAGE_SIZE - ret
340                         , "%8s    %c    %d.%d    %d.%d/%d.%d   %d/%d    [%5d]     %3d (%3d/%3d/%3d)    %3d     "
341                                 "%3d     %3d.%02d      %3d      %3d      %3d     %3d      %3d     %3d"
342                                 "     %5d   %4X  %8X  %8X  %8X  %8X\n"
343                         , cpu_load_freq_history_view[cnt].time
344                         , cpu_load_freq_history_view[cnt].status
345                         , cpu_load_freq_history_view[cnt].cpufreq[0]/1000000
346                         , (cpu_load_freq_history_view[cnt].cpufreq[0]/100000) % 10
347                         , cpu_load_freq_history_view[cnt].cpu_min_locked_freq/1000000
348                         , (cpu_load_freq_history_view[cnt].cpu_min_locked_freq/100000) % 10
349                         , cpu_load_freq_history_view[cnt].cpu_max_locked_freq/1000000
350                         , (cpu_load_freq_history_view[cnt].cpu_max_locked_freq/100000) %10
351                         , cpu_load_freq_history_view[cnt].cpu_min_locked_online
352                         , cpu_load_freq_history_view[cnt].cpu_max_locked_online
353                         , cnt
354                         , cpu_load_freq_history_view[cnt].cpu_load[0]
355                         , cpu_load_freq_history_view[cnt].cpu_idle_time[0]/10
356                         , cpu_load_freq_history_view[cnt].cpu_idle_time[1]/10
357                         , cpu_load_freq_history_view[cnt].cpu_idle_time[2]/10
358                         , cpu_load_freq_history_view[cnt].cpu_load[1]
359                         , cpu_load_freq_history_view[cnt].nr_onlinecpu
360                         , cpu_load_freq_history_view[cnt].nr_run_avg/100
361                         , cpu_load_freq_history_view[cnt].nr_run_avg%100
362                         , cpu_load_freq_history_view[cnt].mif_bus_freq/1000
363                         , cpu_load_freq_history_view[cnt].mif_bus_load
364                         , cpu_load_freq_history_view[cnt].int_bus_freq/1000
365                         , cpu_load_freq_history_view[cnt].int_bus_load
366                         , cpu_load_freq_history_view[cnt].gpu_freq
367                         , cpu_load_freq_history_view[cnt].gpu_utilization
368                         , cpu_load_freq_history_view[cnt].input_rec_history_cnt
369                         , cpu_load_freq_history_view[cnt].power_domains[0]
370                         , cpu_load_freq_history_view[cnt].clk_gates[0]
371                         , cpu_load_freq_history_view[cnt].clk_gates[1]
372                         , cpu_load_freq_history_view[cnt].clk_gates[2]
373                         , cpu_load_freq_history_view[cnt].clk_gates[3]
374                         );
375                 } else
376                         break;
377                 ++cnt;
378         }
379
380         return ret;
381
382 }
383 #endif
384
385 #if defined(CONFIG_CHECK_NOT_CPUIDLE_CAUSE)
386 static int not_lpa_cause_check_sub(char *buf, int buf_size)
387 {
388         int ret = 0;
389
390         ret += snprintf(buf + ret, buf_size - ret, "%s\n",  get_not_w_aftr_cause());
391
392         return ret;
393 }
394 #endif
395
396 #if defined(CONFIG_SLP_CURRENT_MONITOR)
397 unsigned int show_current_monitor_read_sub(int cnt, int show_cnt
398                                         , char *buf, unsigned int buf_size, int ret)
399 {
400         int j, delta = 0;
401
402         if ((cnt - show_cnt) < 0) {
403                 delta = cnt - show_cnt;
404                 cnt = cpu_load_history_num + delta;
405         } else
406                 cnt -= show_cnt;
407
408         if ((cnt+1 >= cpu_load_history_num)
409                         || (cpu_load_freq_history[cnt+1].time[0] == '\0'))
410                 cnt = 0;
411         else
412                 cnt++;
413
414         for (j = 0; j < show_cnt; j++) {
415                 char task_name[TASK_COMM_LEN]={0,};
416
417                 if (cnt > cpu_load_history_num-1)
418                         cnt = 0;
419
420                 get_name_from_pid(task_name, cpu_load_freq_history[cnt].pid);
421
422                 ret +=  snprintf(buf + ret, PAGE_SIZE - ret
423                         , "%10s %16s %5d %1c %3d  %d.%d  %d.%d %d.%d    %d  %3d  %3d %3d %3d   %3d"
424                                 "  %3d.%02d   %3d %3d  %3d %3d  %3d %3d  %3d"
425                                 "      %d %5d %5d  %d %5d %5d\n"
426                         , cpu_load_freq_history[cnt].time
427                         , task_name
428                         , cpu_load_freq_history[cnt].suspend_count
429                         , cpu_load_freq_history[cnt].status
430                         , cpu_load_freq_history[cnt].battery_soc
431                         , cpu_load_freq_history[cnt].cpufreq[0]/1000000
432                         , (cpu_load_freq_history[cnt].cpufreq[0]/100000) % 10
433                         , cpu_load_freq_history[cnt].cpu_min_locked_freq/1000000
434                         , (cpu_load_freq_history[cnt].cpu_min_locked_freq/100000) % 10
435                         , cpu_load_freq_history[cnt].cpu_max_locked_freq/1000000
436                         , (cpu_load_freq_history[cnt].cpu_max_locked_freq/100000) %10
437                         , cpu_load_freq_history[cnt].nr_onlinecpu
438                         , cpu_load_freq_history[cnt].cpu_load[0]
439                         , cpu_load_freq_history[cnt].cpu_idle_time[0]/10
440                         , cpu_load_freq_history[cnt].cpu_idle_time[1]/10
441                         , cpu_load_freq_history[cnt].cpu_idle_time[2]/10
442                         , cpu_load_freq_history[cnt].cpu_load[1]
443                         , cpu_load_freq_history[cnt].nr_run_avg/100
444                         , cpu_load_freq_history[cnt].nr_run_avg%100
445                         , cpu_load_freq_history[cnt].mif_bus_freq/1000
446                         , cpu_load_freq_history[cnt].mif_bus_load
447                         , cpu_load_freq_history[cnt].int_bus_freq/1000
448                         , cpu_load_freq_history[cnt].int_bus_load
449                         , cpu_load_freq_history[cnt].gpu_freq
450                         , cpu_load_freq_history[cnt].gpu_utilization
451                         , cpu_load_freq_history[cnt].lcd_brightness
452                         , cpu_load_freq_history[cnt].bt_enabled
453                         , cpu_load_freq_history[cnt].bt_tx_bytes
454                         , cpu_load_freq_history[cnt].bt_rx_bytes
455                         , cpu_load_freq_history[cnt].wifi_enabled
456                         , cpu_load_freq_history[cnt].wifi_tx_bytes
457                         , cpu_load_freq_history[cnt].wifi_rx_bytes);
458
459
460                 ++cnt;
461         }
462         return ret;
463
464 }
465 #endif
466
467
468 #if defined (CONFIG_SLP_CPU_TESTER)
469
470 enum {
471         CPUIDLE_C1,
472         CPUIDLE_C2,
473         CPUIDLE_C3,
474         CPUIDLE_RANDOM,
475 };
476
477 enum {
478         CPUFREQ_1200M,
479         CPUFREQ_1100M,
480         CPUFREQ_1000M,
481         CPUFREQ_800M,
482         CPUFREQ_533M,
483         CPUFREQ_400M,
484         CPUFREQ_200M,
485         CPUFREQ_RANDOM,
486 };
487
488
489
490 struct cpu_test_list_tag cpu_idletest_list[] = {
491         {CPU_IDLE_TEST, CPUIDLE_C1, 1000},
492
493         {END_OF_LIST, 0, 0},
494 };
495
496 struct cpu_test_list_tag cpu_freqtest_list[] = {
497         {CPU_FREQ_TEST, CPUFREQ_1200M, 1000},
498         {CPU_FREQ_TEST, CPUFREQ_1100M, 1000},
499         {CPU_FREQ_TEST, CPUFREQ_1000M, 1000},
500         {CPU_FREQ_TEST, CPUFREQ_800M, 1000},
501         {CPU_FREQ_TEST, CPUFREQ_533M, 1000},
502         {CPU_FREQ_TEST, CPUFREQ_400M, 1000},
503         {CPU_FREQ_TEST, CPUFREQ_200M, 1000},
504
505         {END_OF_LIST, 0, 0},
506 };
507
508 struct cpu_test_freq_table_tag cpu_test_freq_table[] = {
509         {CPUFREQ_1200M},
510         {CPUFREQ_1100M},
511         {CPUFREQ_1000M},
512         {CPUFREQ_800M},
513         {CPUFREQ_533M},
514         {CPUFREQ_400M},
515         {CPUFREQ_200M},
516 };
517
518 struct cpu_test_idle_table_tag cpu_test_idle_table[] ={
519         {CPUIDLE_C1},
520         {CPUIDLE_C2},
521         {CPUIDLE_C3},
522 };
523
524 void set_cpufreq_force_state(int cpufreq_enum)
525 {
526         switch(cpufreq_enum) {
527         case CPUFREQ_1200M :
528                 cpufreq_force_state = 1190400;
529                 break;
530         case CPUFREQ_1100M :
531                 cpufreq_force_state = 1094400;
532                 break;
533         case CPUFREQ_1000M :
534                 cpufreq_force_state = 998400;
535                 break;
536         case CPUFREQ_800M :
537                 cpufreq_force_state = 800000;
538                 break;
539         case CPUFREQ_533M :
540                 cpufreq_force_state = 533333;
541                 break;
542         case CPUFREQ_400M :
543                 cpufreq_force_state = 400000;
544                 break;
545         case CPUFREQ_200M :
546                 cpufreq_force_state = 200000;
547                 break;
548         }
549 }
550
551
552
553
554 int cpu_freq_to_enum(int cpufreq)
555 {
556         int cpufreq_enum = -1;
557
558         switch (cpufreq) {
559         case 1190400 :
560                 cpufreq_enum = CPUFREQ_1200M;
561                 break;
562         case 1094400 :
563                 cpufreq_enum = CPUFREQ_1100M;
564                 break;
565         case 998400 :
566                 cpufreq_enum = CPUFREQ_1000M;
567                 break;
568         case 800000 :
569                 cpufreq_enum = CPUFREQ_800M;
570                 break;
571         case 533333 :
572                 cpufreq_enum = CPUFREQ_533M;
573                 break;
574         case 400000 :
575                 cpufreq_enum = CPUFREQ_400M;
576                 break;
577         case 200000 :
578                 cpufreq_enum = CPUFREQ_200M;
579                 break;
580         }
581
582         return cpufreq_enum;
583
584 }
585
586
587 void cpu_tester_enum_to_str(char *str, int type, int enum_value)
588 {
589         if (type == CPU_FREQ_TEST) {
590                 switch (enum_value) {
591                         case CPUFREQ_1200M :
592                                 strcpy(str, "1.2Ghz");
593                                 break;
594                         case CPUFREQ_1100M :
595                                 strcpy(str, "1.1Ghz");
596                                 break;
597                         case CPUFREQ_1000M :
598                                 strcpy(str, "1.0Ghz");
599                                 break;
600                         case CPUFREQ_800M :
601                                 strcpy(str, "800Mhz");
602                                 break;
603                         case CPUFREQ_533M :
604                                 strcpy(str, "533Mhz");
605                                 break;
606                         case CPUFREQ_400M :
607                                 strcpy(str, "400Mhz");
608                                 break;
609                         case CPUFREQ_200M :
610                                 strcpy(str, "200Mhz");
611                                 break;
612                         case CPUFREQ_RANDOM:
613                                 strcpy(str, "RANDOM");
614                                 break;
615                 }
616         }else if (type == CPU_IDLE_TEST) {
617                 switch (enum_value) {
618                         case CPUIDLE_C1 :
619                                 strcpy(str, "C1");
620                                 break;
621                         case CPUIDLE_C2 :
622                                 strcpy(str, "C2");
623                                 break;
624                         case CPUIDLE_C3 :
625                                 strcpy(str, "C3");
626                                 break;
627                         case CPUIDLE_RANDOM:
628                                 strcpy(str, "RANDOM");
629                                 break;
630                 }
631         }
632
633 }
634
635 #endif
636
637
638 static int cpu_busy_gpu_usage = 200;
639 int gpu_load_checking(unsigned int cnt)
640 {
641         int ret = BUSY_LOAD;
642
643         if ((cpu_load_freq_history[cnt].gpu_freq >= (133 * 1000000))
644                 && (cpu_load_freq_history[cnt].gpu_utilization >= cpu_busy_gpu_usage)) {
645                 ret = BUSY_LOAD;
646         }
647
648         return ret;
649 }
650
651 int cpu_load_checking(unsigned int cnt)
652 {
653         int ret = NOT_BUSY_LOAD;
654         unsigned int high_cpufreq, high_usage;
655
656         high_cpufreq = cpu_load_freq_history[cnt].cpufreq[0];
657         high_usage = max(cpu_load_freq_history[cnt].cpu_load[0], cpu_load_freq_history[cnt].cpu_load[1]);
658
659         if ((high_cpufreq >= 1000000)
660                 && (high_usage >= 90)) {
661                 ret = BUSY_LOAD;
662         } else if (high_usage >= 99) {
663                 ret = BUSY_LOAD;
664         }
665
666         return ret;
667 }
668
669