ff3bd6bd3e2b762a9fecbb562c1b1c4640f152a7
[linux-3.10.git] / arch / arm / mach-tegra / cpuidle-t11x.c
1 /*
2  * arch/arm/mach-tegra/cpuidle-t11x.c
3  *
4  * CPU idle driver for Tegra11x CPUs
5  *
6  * Copyright (c) 2012, NVIDIA Corporation.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22
23 #include <linux/kernel.h>
24 #include <linux/cpu.h>
25 #include <linux/cpuidle.h>
26 #include <linux/debugfs.h>
27 #include <linux/delay.h>
28 #include <linux/hrtimer.h>
29 #include <linux/init.h>
30 #include <linux/interrupt.h>
31 #include <linux/irq.h>
32 #include <linux/io.h>
33 #include <linux/ratelimit.h>
34 #include <linux/sched.h>
35 #include <linux/seq_file.h>
36 #include <linux/slab.h>
37 #include <linux/smp.h>
38 #include <linux/suspend.h>
39 #include <linux/tick.h>
40 #include <linux/clk.h>
41 #include <linux/cpu_pm.h>
42 #include <linux/module.h>
43
44 #include <asm/cacheflush.h>
45 #include <asm/hardware/gic.h>
46 #include <asm/localtimer.h>
47 #include <asm/suspend.h>
48 #include <asm/cputype.h>
49
50 #include <mach/iomap.h>
51 #include <mach/irqs.h>
52 #include <mach/hardware.h>
53
54 #include <trace/events/power.h>
55
56 #include "clock.h"
57 #include "cpuidle.h"
58 #include "dvfs.h"
59 #include "fuse.h"
60 #include "gic.h"
61 #include "pm.h"
62 #include "reset.h"
63 #include "sleep.h"
64 #include "timer.h"
65 #include "fuse.h"
66
67 #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS \
68         (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x470)
69 #define PMC_POWERGATE_STATUS \
70         (IO_ADDRESS(TEGRA_PMC_BASE) + 0x038)
71
72 #define ARCH_TIMER_CTRL_ENABLE          (1 << 0)
73 #define ARCH_TIMER_CTRL_IT_MASK         (1 << 1)
74
75 #ifdef CONFIG_SMP
76 static s64 tegra_cpu_wake_by_time[4] = {
77         LLONG_MAX, LLONG_MAX, LLONG_MAX, LLONG_MAX };
78 #endif
79
80 static ulong cpu_power_gating_in_idle __read_mostly = 0x1f;
81 module_param(cpu_power_gating_in_idle, ulong, 0644);
82
83 static bool slow_cluster_power_gating_noncpu __read_mostly;
84 module_param(slow_cluster_power_gating_noncpu, bool, 0644);
85
86 static uint fast_cluster_power_down_mode __read_mostly;
87 module_param(fast_cluster_power_down_mode, uint, 0644);
88
89 static struct clk *cpu_clk_for_dvfs;
90
91 static int pd_exit_latencies[5];
92
93 static struct {
94         unsigned int cpu_ready_count[5];
95         unsigned int tear_down_count[5];
96         unsigned long long cpu_wants_pd_time[5];
97         unsigned long long cpu_pg_time[5];
98         unsigned long long rail_pd_time;
99         unsigned long long c0nc_pg_time;
100         unsigned long long c1nc_pg_time;
101         unsigned int rail_gating_count;
102         unsigned int rail_gating_bin[32];
103         unsigned int rail_gating_done_count;
104         unsigned int rail_gating_done_count_bin[32];
105         unsigned int c0nc_gating_count;
106         unsigned int c0nc_gating_bin[32];
107         unsigned int c0nc_gating_done_count;
108         unsigned int c0nc_gating_done_count_bin[32];
109         unsigned int c1nc_gating_count;
110         unsigned int c1nc_gating_bin[32];
111         unsigned int c1nc_gating_done_count;
112         unsigned int c1nc_gating_done_count_bin[32];
113         unsigned int pd_int_count[NR_IRQS];
114         unsigned int last_pd_int_count[NR_IRQS];
115 } idle_stats;
116
117 static inline unsigned int time_to_bin(unsigned int time)
118 {
119         return fls(time);
120 }
121
122 static inline void tegra_irq_unmask(int irq)
123 {
124         struct irq_data *data = irq_get_irq_data(irq);
125         data->chip->irq_unmask(data);
126 }
127
128 static inline unsigned int cpu_number(unsigned int n)
129 {
130         return is_lp_cluster() ? 4 : n;
131 }
132
133 void tegra11x_cpu_idle_stats_pd_ready(unsigned int cpu)
134 {
135         idle_stats.cpu_ready_count[cpu_number(cpu)]++;
136 }
137
138 void tegra11x_cpu_idle_stats_pd_time(unsigned int cpu, s64 us)
139 {
140         idle_stats.cpu_wants_pd_time[cpu_number(cpu)] += us;
141 }
142
143 /* Allow rail off only if all secondary CPUs are power gated, and no
144    rail update is in progress */
145 static bool tegra_rail_off_is_allowed(void)
146 {
147         u32 rst = readl(CLK_RST_CONTROLLER_CPU_CMPLX_STATUS);
148         u32 pg = readl(PMC_POWERGATE_STATUS) >> 8;
149
150         if (((rst & 0xE) != 0xE) || ((pg & 0xE) != 0))
151                 return false;
152
153         if (tegra_dvfs_rail_updating(cpu_clk_for_dvfs))
154                 return false;
155
156         return true;
157 }
158
159 bool tegra11x_pd_is_allowed(struct cpuidle_device *dev,
160         struct cpuidle_state *state)
161 {
162         s64 request;
163
164         if (!cpumask_test_cpu(cpu_number(dev->cpu),
165                                 to_cpumask(&cpu_power_gating_in_idle)))
166                 return false;
167
168         request = ktime_to_us(tick_nohz_get_sleep_length());
169         if (state->exit_latency != pd_exit_latencies[cpu_number(dev->cpu)]) {
170                 /* possible on the 1st entry after cluster switch*/
171                 state->exit_latency = pd_exit_latencies[cpu_number(dev->cpu)];
172                 tegra_pd_update_target_residency(state);
173         }
174         if (request < state->target_residency) {
175                 /* Not enough time left to enter LP2 */
176                 return false;
177         }
178
179         return true;
180 }
181
182 static inline void tegra11_irq_restore_affinity(void)
183 {
184 #ifdef CONFIG_SMP
185         /* Disable the distributor. */
186         tegra_gic_dist_disable();
187
188         /* Restore the other CPU's interrupt affinity. */
189         tegra_gic_restore_affinity();
190
191         /* Re-enable the distributor. */
192         tegra_gic_dist_enable();
193 #endif
194 }
195
196 static bool tegra_cpu_cluster_power_down(struct cpuidle_device *dev,
197                            struct cpuidle_state *state, s64 request)
198 {
199         ktime_t entry_time;
200         ktime_t exit_time;
201         bool sleep_completed = false;
202         bool multi_cpu_entry = false;
203         int bin;
204         unsigned int flag = 0;
205         s64 sleep_time;
206
207         /* LP2 entry time */
208         entry_time = ktime_get();
209
210         if (request < state->target_residency) {
211                 /* Not enough time left to enter LP2 */
212                 cpu_do_idle();
213                 return false;
214         }
215
216 #ifdef CONFIG_SMP
217         multi_cpu_entry = !is_lp_cluster() && (num_online_cpus() > 1);
218         if (multi_cpu_entry) {
219                 s64 wake_time;
220                 unsigned int i;
221
222                 /* Disable the distributor -- this is the only way to
223                    prevent the other CPUs from responding to interrupts
224                    and potentially fiddling with the distributor
225                    registers while we're fiddling with them. */
226                 tegra_gic_dist_disable();
227
228                 /* Did an interrupt come in for another CPU before we
229                    could disable the distributor? */
230                 if (!tegra_rail_off_is_allowed()) {
231                         /* Yes, re-enable the distributor and clock gating. */
232                         tegra_gic_dist_enable();
233                         cpu_do_idle();
234                         return false;
235                 }
236
237                 /* LP2 initial targeted wake time */
238                 wake_time = ktime_to_us(entry_time) + request;
239
240                 /* CPU0 must wake up before any of the other CPUs. */
241                 smp_rmb();
242                 for (i = 1; i < CONFIG_NR_CPUS; i++)
243                         wake_time = min_t(s64, wake_time,
244                                 tegra_cpu_wake_by_time[i]);
245
246                 /* LP2 actual targeted wake time */
247                 request = wake_time - ktime_to_us(entry_time);
248                 BUG_ON(wake_time < 0LL);
249
250                 if (request < state->target_residency) {
251                         /* Not enough time left to enter LP2 */
252                         tegra_gic_dist_enable();
253                         cpu_do_idle();
254                         return false;
255                 }
256
257                 /* Cancel power gating wake timers for all secondary CPUs */
258                 tegra_pd_timer_cancel_secondary();
259
260                 /* Save and disable the affinity setting for the other
261                    CPUs and route all interrupts to CPU0. */
262                 tegra_gic_disable_affinity();
263
264                 /* Re-enable the distributor. */
265                 tegra_gic_dist_enable();
266         }
267 #endif
268         cpu_pm_enter();
269
270         sleep_time = request -
271                 pd_exit_latencies[cpu_number(dev->cpu)];
272
273         bin = time_to_bin((u32)request / 1000);
274         idle_stats.tear_down_count[cpu_number(dev->cpu)]++;
275
276         clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
277         if (is_lp_cluster()) {
278                 /* here we are not supporting emulation mode, for now */
279                 flag = TEGRA_POWER_CLUSTER_PART_NONCPU;
280                 idle_stats.c1nc_gating_count++;
281                 idle_stats.c1nc_gating_bin[bin]++;
282         } else {
283                 tegra_dvfs_rail_off(tegra_cpu_rail, entry_time);
284                 flag = (fast_cluster_power_down_mode
285                         << TEGRA_POWER_CLUSTER_PART_SHIFT)
286                         & TEGRA_POWER_CLUSTER_PART_MASK;
287
288                 if (((request < tegra_min_residency_crail()) &&
289                         (flag != TEGRA_POWER_CLUSTER_PART_MASK)) &&
290                         ((fast_cluster_power_down_mode &
291                         TEGRA_POWER_CLUSTER_FORCE_MASK) == 0))
292                         flag = TEGRA_POWER_CLUSTER_PART_NONCPU;
293
294                 if (flag == TEGRA_POWER_CLUSTER_PART_CRAIL) {
295                         idle_stats.rail_gating_count++;
296                         idle_stats.rail_gating_bin[bin]++;
297                 } else if (flag == TEGRA_POWER_CLUSTER_PART_NONCPU) {
298                         idle_stats.c0nc_gating_count++;
299                         idle_stats.c0nc_gating_bin[bin]++;
300                 }
301         }
302
303         if (tegra_idle_power_down_last(sleep_time, flag) == 0)
304                 sleep_completed = true;
305         else {
306                 int irq = tegra_gic_pending_interrupt();
307                 idle_stats.pd_int_count[irq]++;
308         }
309
310         clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
311         exit_time = ktime_get();
312         if (!is_lp_cluster())
313                 tegra_dvfs_rail_on(tegra_cpu_rail, exit_time);
314
315         if (flag == TEGRA_POWER_CLUSTER_PART_CRAIL)
316                 idle_stats.rail_pd_time +=
317                         ktime_to_us(ktime_sub(exit_time, entry_time));
318         else if (flag == TEGRA_POWER_CLUSTER_PART_NONCPU) {
319                 if (is_lp_cluster())
320                         idle_stats.c1nc_pg_time +=
321                                 ktime_to_us(ktime_sub(exit_time, entry_time));
322                 else
323                         idle_stats.c0nc_pg_time +=
324                                 ktime_to_us(ktime_sub(exit_time, entry_time));
325         }
326
327         if (multi_cpu_entry)
328                 tegra11_irq_restore_affinity();
329
330         if (sleep_completed) {
331                 /*
332                  * Stayed in LP2 for the full time until the next tick,
333                  * adjust the exit latency based on measurement
334                  */
335                 int offset = ktime_to_us(ktime_sub(exit_time, entry_time))
336                         - request;
337                 int latency = pd_exit_latencies[cpu_number(dev->cpu)] +
338                         offset / 16;
339                 latency = clamp(latency, 0, 10000);
340                 pd_exit_latencies[cpu_number(dev->cpu)] = latency;
341                 state->exit_latency = latency;          /* for idle governor */
342                 smp_wmb();
343
344                 if (flag == TEGRA_POWER_CLUSTER_PART_CRAIL) {
345                         idle_stats.rail_gating_done_count++;
346                         idle_stats.rail_gating_done_count_bin[bin]++;
347                 } else if (flag == TEGRA_POWER_CLUSTER_PART_NONCPU) {
348                         if (is_lp_cluster()) {
349                                 idle_stats.c1nc_gating_done_count++;
350                                 idle_stats.c1nc_gating_done_count_bin[bin]++;
351                         } else {
352                                 idle_stats.c0nc_gating_done_count++;
353                                 idle_stats.c0nc_gating_done_count_bin[bin]++;
354                         }
355                 }
356
357                 pr_debug("%lld %lld %d %d\n", request,
358                         ktime_to_us(ktime_sub(exit_time, entry_time)),
359                         offset, bin);
360         }
361
362         cpu_pm_exit();
363
364         return true;
365 }
366
367 static bool tegra_cpu_core_power_down(struct cpuidle_device *dev,
368                            struct cpuidle_state *state, s64 request)
369 {
370 #ifdef CONFIG_SMP
371         s64 sleep_time;
372         ktime_t entry_time;
373         struct arch_timer_context timer_context;
374         bool sleep_completed = false;
375         struct tick_sched *ts = tick_get_tick_sched(dev->cpu);
376
377         if (!arch_timer_get_state(&timer_context)) {
378                 if ((timer_context.cntp_ctl & ARCH_TIMER_CTRL_ENABLE) &&
379                     ~(timer_context.cntp_ctl & ARCH_TIMER_CTRL_IT_MASK)) {
380                         if (timer_context.cntp_tval <= 0) {
381                                 cpu_do_idle();
382                                 return false;
383                         }
384                         request = div_u64((u64)timer_context.cntp_tval *
385                                         1000000, timer_context.cntfrq);
386 #ifdef CONFIG_TEGRA_LP2_CPU_TIMER
387                         if (request >= state->target_residency) {
388                                 timer_context.cntp_tval -= state->exit_latency *
389                                         (timer_context.cntfrq / 1000000);
390                                 __asm__("mcr p15, 0, %0, c14, c2, 0\n"
391                                         :
392                                         :
393                                         "r"(timer_context.cntp_tval));
394                         }
395 #endif
396                 }
397         }
398
399         if (!tegra_is_cpu_wake_timer_ready(dev->cpu) ||
400             (request < state->target_residency) ||
401             (!ts) || (ts->nohz_mode == NOHZ_MODE_INACTIVE)) {
402                 /*
403                  * Not enough time left to enter LP2, or wake timer not ready
404                  */
405                 cpu_do_idle();
406                 return false;
407         }
408
409         cpu_pm_enter();
410
411 #if !defined(CONFIG_TEGRA_LP2_CPU_TIMER)
412         sleep_time = request - state->exit_latency;
413         clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
414         arch_timer_suspend(&timer_context);
415         tegra_pd_set_trigger(sleep_time);
416 #endif
417         idle_stats.tear_down_count[cpu_number(dev->cpu)]++;
418
419         entry_time = ktime_get();
420
421         /* Save time this CPU must be awakened by. */
422         tegra_cpu_wake_by_time[dev->cpu] = ktime_to_us(entry_time) + request;
423         smp_wmb();
424
425 #ifdef CONFIG_TRUSTED_FOUNDATIONS
426         tegra_generic_smc(0xFFFFFFFC, 0xFFFFFFE4,
427                                    (TEGRA_RESET_HANDLER_BASE +
428                                     tegra_cpu_reset_handler_offset));
429 #endif
430         cpu_suspend(0, tegra3_sleep_cpu_secondary_finish);
431
432         tegra_cpu_wake_by_time[dev->cpu] = LLONG_MAX;
433
434 #ifdef CONFIG_TEGRA_LP2_CPU_TIMER
435         if (!arch_timer_get_state(&timer_context))
436                 sleep_completed = (timer_context.cntp_tval <= 0);
437 #else
438         sleep_completed = !tegra_pd_timer_remain();
439         tegra_pd_set_trigger(0);
440         arch_timer_resume(&timer_context);
441         clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
442 #endif
443         sleep_time = ktime_to_us(ktime_sub(ktime_get(), entry_time));
444         idle_stats.cpu_pg_time[cpu_number(dev->cpu)] += sleep_time;
445         if (sleep_completed) {
446                 /*
447                  * Stayed in LP2 for the full time until timer expires,
448                  * adjust the exit latency based on measurement
449                  */
450                 int offset = sleep_time - request;
451                 int latency = pd_exit_latencies[cpu_number(dev->cpu)] +
452                         offset / 16;
453                 latency = clamp(latency, 0, 10000);
454                 pd_exit_latencies[cpu_number(dev->cpu)] = latency;
455                 state->exit_latency = latency;          /* for idle governor */
456                 smp_wmb();
457         }
458 #endif
459         cpu_pm_exit();
460
461         return true;
462 }
463
464 bool tegra11x_idle_power_down(struct cpuidle_device *dev,
465                            struct cpuidle_state *state)
466 {
467         bool power_down;
468         bool cpu_gating_only = false;
469         bool power_gating_cpu_only = true;
470         s64 request = ktime_to_us(tick_nohz_get_sleep_length());
471
472         tegra_set_cpu_in_pd(dev->cpu);
473         cpu_gating_only = (((fast_cluster_power_down_mode
474                         << TEGRA_POWER_CLUSTER_PART_SHIFT)
475                         & TEGRA_POWER_CLUSTER_PART_MASK) == 0);
476
477         if (is_lp_cluster()) {
478                 if (slow_cluster_power_gating_noncpu &&
479                         (request > tegra_min_residency_noncpu()))
480                                 power_gating_cpu_only = false;
481                 else
482                         power_gating_cpu_only = true;
483         } else if (!cpu_gating_only &&
484                 (num_online_cpus() == 1) &&
485                 tegra_rail_off_is_allowed()) {
486                 if (fast_cluster_power_down_mode &&
487                         TEGRA_POWER_CLUSTER_FORCE_MASK)
488                         power_gating_cpu_only = cpu_gating_only;
489                 else if (request > tegra_min_residency_noncpu())
490                         power_gating_cpu_only = false;
491                 else
492                         power_gating_cpu_only = true;
493         } else
494                 power_gating_cpu_only = true;
495
496         if (power_gating_cpu_only)
497                 power_down = tegra_cpu_core_power_down(dev, state, request);
498         else
499                 power_down = tegra_cpu_cluster_power_down(dev, state, request);
500
501         tegra_clear_cpu_in_pd(dev->cpu);
502
503         return power_down;
504 }
505
506 #ifdef CONFIG_DEBUG_FS
507 int tegra11x_pd_debug_show(struct seq_file *s, void *data)
508 {
509         int bin;
510         int i;
511         seq_printf(s, "                                    cpu0     cpu1     cpu2     cpu3     cpulp\n");
512         seq_printf(s, "-----------------------------------------------------------------------------\n");
513         seq_printf(s, "cpu ready:                      %8u %8u %8u %8u %8u\n",
514                 idle_stats.cpu_ready_count[0],
515                 idle_stats.cpu_ready_count[1],
516                 idle_stats.cpu_ready_count[2],
517                 idle_stats.cpu_ready_count[3],
518                 idle_stats.cpu_ready_count[4]);
519         seq_printf(s, "tear down:                      %8u %8u %8u %8u %8u\n",
520                 idle_stats.tear_down_count[0],
521                 idle_stats.tear_down_count[1],
522                 idle_stats.tear_down_count[2],
523                 idle_stats.tear_down_count[3],
524                 idle_stats.tear_down_count[4]);
525         seq_printf(s, "rail gating count:      %8u\n",
526                 idle_stats.rail_gating_count);
527         seq_printf(s, "rail gating completed:  %8u %7u%%\n",
528                 idle_stats.rail_gating_done_count,
529                 idle_stats.rail_gating_done_count * 100 /
530                         (idle_stats.rail_gating_count ?: 1));
531
532         seq_printf(s, "c0nc gating count:      %8u\n",
533                 idle_stats.c0nc_gating_count);
534         seq_printf(s, "c0nc gating completed:  %8u %7u%%\n",
535                 idle_stats.c0nc_gating_done_count,
536                 idle_stats.c0nc_gating_done_count * 100 /
537                         (idle_stats.c0nc_gating_count ?: 1));
538
539         seq_printf(s, "c1nc gating count:      %8u\n",
540                 idle_stats.c1nc_gating_count);
541         seq_printf(s, "c1nc gating completed:  %8u %7u%%\n",
542                 idle_stats.c1nc_gating_done_count,
543                 idle_stats.c1nc_gating_done_count * 100 /
544                         (idle_stats.c1nc_gating_count ?: 1));
545
546         seq_printf(s, "\n");
547         seq_printf(s, "cpu ready time:                 " \
548                         "%8llu %8llu %8llu %8llu %8llu ms\n",
549                 div64_u64(idle_stats.cpu_wants_pd_time[0], 1000),
550                 div64_u64(idle_stats.cpu_wants_pd_time[1], 1000),
551                 div64_u64(idle_stats.cpu_wants_pd_time[2], 1000),
552                 div64_u64(idle_stats.cpu_wants_pd_time[3], 1000),
553                 div64_u64(idle_stats.cpu_wants_pd_time[4], 1000));
554
555         seq_printf(s, "cpu power gating time:          " \
556                         "%8llu %8llu %8llu %8llu %8llu ms\n",
557                 div64_u64(idle_stats.cpu_pg_time[0], 1000),
558                 div64_u64(idle_stats.cpu_pg_time[1], 1000),
559                 div64_u64(idle_stats.cpu_pg_time[2], 1000),
560                 div64_u64(idle_stats.cpu_pg_time[3], 1000),
561                 div64_u64(idle_stats.cpu_pg_time[4], 1000));
562
563         seq_printf(s, "power gated %%:                 " \
564                         "%7d%% %7d%% %7d%% %7d%% %7d%%\n",
565                 (int)(idle_stats.cpu_wants_pd_time[0] ?
566                         div64_u64(idle_stats.cpu_pg_time[0] * 100,
567                         idle_stats.cpu_wants_pd_time[0]) : 0),
568                 (int)(idle_stats.cpu_wants_pd_time[1] ?
569                         div64_u64(idle_stats.cpu_pg_time[1] * 100,
570                         idle_stats.cpu_wants_pd_time[1]) : 0),
571                 (int)(idle_stats.cpu_wants_pd_time[2] ?
572                         div64_u64(idle_stats.cpu_pg_time[2] * 100,
573                         idle_stats.cpu_wants_pd_time[2]) : 0),
574                 (int)(idle_stats.cpu_wants_pd_time[3] ?
575                         div64_u64(idle_stats.cpu_pg_time[3] * 100,
576                         idle_stats.cpu_wants_pd_time[3]) : 0),
577                 (int)(idle_stats.cpu_wants_pd_time[4] ?
578                         div64_u64(idle_stats.cpu_pg_time[4] * 100,
579                         idle_stats.cpu_wants_pd_time[4]) : 0));
580
581         seq_printf(s, "\n");
582         seq_printf(s, "rail gating time  c0nc gating time  c1nc gating time\n");
583         seq_printf(s, "%8llu ms          %8llu ms          %8llu ms\n",
584                 div64_u64(idle_stats.rail_pd_time, 1000),
585                 div64_u64(idle_stats.c0nc_pg_time, 1000),
586                 div64_u64(idle_stats.c1nc_pg_time, 1000));
587         seq_printf(s, "%8d%%             %8d%%             %8d%%\n",
588                 (int)(idle_stats.cpu_wants_pd_time[0] ?
589                         div64_u64(idle_stats.rail_pd_time * 100,
590                         idle_stats.cpu_wants_pd_time[0]) : 0),
591                 (int)(idle_stats.cpu_wants_pd_time[0] ?
592                         div64_u64(idle_stats.c0nc_pg_time * 100,
593                         idle_stats.cpu_wants_pd_time[0]) : 0),
594                 (int)(idle_stats.cpu_wants_pd_time[4] ?
595                         div64_u64(idle_stats.c1nc_pg_time * 100,
596                         idle_stats.cpu_wants_pd_time[4]) : 0));
597
598         seq_printf(s, "\n");
599
600         seq_printf(s, "%19s %8s %8s %8s\n", "", "rail gating", "comp", "%");
601         seq_printf(s, "-------------------------------------------------\n");
602         for (bin = 0; bin < 32; bin++) {
603                 if (idle_stats.rail_gating_bin[bin] == 0)
604                         continue;
605                 seq_printf(s, "%6u - %6u ms: %8u %8u %7u%%\n",
606                         1 << (bin - 1), 1 << bin,
607                         idle_stats.rail_gating_bin[bin],
608                         idle_stats.rail_gating_done_count_bin[bin],
609                         idle_stats.rail_gating_done_count_bin[bin] * 100 /
610                                 idle_stats.rail_gating_bin[bin]);
611         }
612         seq_printf(s, "\n");
613
614         seq_printf(s, "%19s %8s %8s %8s\n", "", "c0nc gating", "comp", "%");
615         seq_printf(s, "-------------------------------------------------\n");
616         for (bin = 0; bin < 32; bin++) {
617                 if (idle_stats.c0nc_gating_bin[bin] == 0)
618                         continue;
619                 seq_printf(s, "%6u - %6u ms: %8u %8u %7u%%\n",
620                         1 << (bin - 1), 1 << bin,
621                         idle_stats.c0nc_gating_bin[bin],
622                         idle_stats.c0nc_gating_done_count_bin[bin],
623                         idle_stats.c0nc_gating_done_count_bin[bin] * 100 /
624                                 idle_stats.c0nc_gating_bin[bin]);
625         }
626         seq_printf(s, "\n");
627
628         seq_printf(s, "%19s %8s %8s %8s\n", "", "c1nc gating", "comp", "%");
629         seq_printf(s, "-------------------------------------------------\n");
630         for (bin = 0; bin < 32; bin++) {
631                 if (idle_stats.c1nc_gating_bin[bin] == 0)
632                         continue;
633                 seq_printf(s, "%6u - %6u ms: %8u %8u %7u%%\n",
634                         1 << (bin - 1), 1 << bin,
635                         idle_stats.c1nc_gating_bin[bin],
636                         idle_stats.c1nc_gating_done_count_bin[bin],
637                         idle_stats.c1nc_gating_done_count_bin[bin] * 100 /
638                                 idle_stats.c1nc_gating_bin[bin]);
639         }
640
641         seq_printf(s, "\n");
642         seq_printf(s, "%3s %20s %6s %10s\n",
643                 "int", "name", "count", "last count");
644         seq_printf(s, "--------------------------------------------\n");
645         for (i = 0; i < NR_IRQS; i++) {
646                 if (idle_stats.pd_int_count[i] == 0)
647                         continue;
648                 seq_printf(s, "%3d %20s %6d %10d\n",
649                         i, irq_to_desc(i)->action ?
650                                 irq_to_desc(i)->action->name ?: "???" : "???",
651                         idle_stats.pd_int_count[i],
652                         idle_stats.pd_int_count[i] -
653                                 idle_stats.last_pd_int_count[i]);
654                 idle_stats.last_pd_int_count[i] = idle_stats.pd_int_count[i];
655         };
656         return 0;
657 }
658 #endif
659
660 int __init tegra11x_cpuidle_init_soc(struct tegra_cpuidle_ops *idle_ops)
661 {
662         int i;
663         struct tegra_cpuidle_ops ops = {
664                 tegra11x_idle_power_down,
665                 tegra11x_cpu_idle_stats_pd_ready,
666                 tegra11x_cpu_idle_stats_pd_time,
667                 tegra11x_pd_is_allowed,
668 #ifdef CONFIG_DEBUG_FS
669                 tegra11x_pd_debug_show
670 #endif
671         };
672
673         cpu_clk_for_dvfs = tegra_get_clock_by_name("cpu_g");
674
675         for (i = 0; i < ARRAY_SIZE(pd_exit_latencies); i++)
676                 pd_exit_latencies[i] = tegra_pg_exit_latency;
677
678         *idle_ops = ops;
679         return 0;
680 }