ARM: tegra11x: timer save/restore is removed
[linux-2.6.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 #ifdef CONFIG_TRUSTED_FOUNDATIONS
377         unsigned int cpu = cpu_number(dev->cpu);
378 #endif
379
380         if (!arch_timer_get_state(&timer_context)) {
381                 if ((timer_context.cntp_ctl & ARCH_TIMER_CTRL_ENABLE) &&
382                     ~(timer_context.cntp_ctl & ARCH_TIMER_CTRL_IT_MASK)) {
383                         if (timer_context.cntp_tval <= 0) {
384                                 cpu_do_idle();
385                                 return false;
386                         }
387                         request = div_u64((u64)timer_context.cntp_tval *
388                                         1000000, timer_context.cntfrq);
389 #ifdef CONFIG_TEGRA_LP2_CPU_TIMER
390                         if (request >= state->target_residency) {
391                                 timer_context.cntp_tval -= state->exit_latency *
392                                         (timer_context.cntfrq / 1000000);
393                                 __asm__("mcr p15, 0, %0, c14, c2, 0\n"
394                                         :
395                                         :
396                                         "r"(timer_context.cntp_tval));
397                         }
398 #endif
399                 }
400         }
401
402         if (!tegra_is_cpu_wake_timer_ready(dev->cpu) ||
403             (request < state->target_residency) ||
404             (!ts) || (ts->nohz_mode == NOHZ_MODE_INACTIVE)) {
405                 /*
406                  * Not enough time left to enter LP2, or wake timer not ready
407                  */
408                 cpu_do_idle();
409                 return false;
410         }
411
412         cpu_pm_enter();
413
414 #if !defined(CONFIG_TEGRA_LP2_CPU_TIMER)
415         sleep_time = request - state->exit_latency;
416         clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
417         tegra_pd_set_trigger(sleep_time);
418 #endif
419         idle_stats.tear_down_count[cpu_number(dev->cpu)]++;
420
421         entry_time = ktime_get();
422
423         /* Save time this CPU must be awakened by. */
424         tegra_cpu_wake_by_time[dev->cpu] = ktime_to_us(entry_time) + request;
425         smp_wmb();
426
427 #ifdef CONFIG_TRUSTED_FOUNDATIONS
428         if ((cpu == 0) || (cpu == 4)) {
429                 tegra_generic_smc(0xFFFFFFFC, 0xFFFFFFE7,
430                                 (TEGRA_RESET_HANDLER_BASE +
431                                 tegra_cpu_reset_handler_offset));
432         }
433 #endif
434         cpu_suspend(0, tegra3_sleep_cpu_secondary_finish);
435
436         tegra_cpu_wake_by_time[dev->cpu] = LLONG_MAX;
437
438 #ifdef CONFIG_TEGRA_LP2_CPU_TIMER
439         if (!arch_timer_get_state(&timer_context))
440                 sleep_completed = (timer_context.cntp_tval <= 0);
441 #else
442         sleep_completed = !tegra_pd_timer_remain();
443         tegra_pd_set_trigger(0);
444         clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
445 #endif
446         sleep_time = ktime_to_us(ktime_sub(ktime_get(), entry_time));
447         idle_stats.cpu_pg_time[cpu_number(dev->cpu)] += sleep_time;
448         if (sleep_completed) {
449                 /*
450                  * Stayed in LP2 for the full time until timer expires,
451                  * adjust the exit latency based on measurement
452                  */
453                 int offset = sleep_time - request;
454                 int latency = pd_exit_latencies[cpu_number(dev->cpu)] +
455                         offset / 16;
456                 latency = clamp(latency, 0, 10000);
457                 pd_exit_latencies[cpu_number(dev->cpu)] = latency;
458                 state->exit_latency = latency;          /* for idle governor */
459                 smp_wmb();
460         }
461 #endif
462         cpu_pm_exit();
463
464         return true;
465 }
466
467 bool tegra11x_idle_power_down(struct cpuidle_device *dev,
468                            struct cpuidle_state *state)
469 {
470         bool power_down;
471         bool cpu_gating_only = false;
472         bool power_gating_cpu_only = true;
473         s64 request = ktime_to_us(tick_nohz_get_sleep_length());
474
475         tegra_set_cpu_in_pd(dev->cpu);
476         cpu_gating_only = (((fast_cluster_power_down_mode
477                         << TEGRA_POWER_CLUSTER_PART_SHIFT)
478                         & TEGRA_POWER_CLUSTER_PART_MASK) == 0);
479
480         if (is_lp_cluster()) {
481                 if (slow_cluster_power_gating_noncpu &&
482                         (request > tegra_min_residency_noncpu()))
483                                 power_gating_cpu_only = false;
484                 else
485                         power_gating_cpu_only = true;
486         } else if (!cpu_gating_only &&
487                 (num_online_cpus() == 1) &&
488                 tegra_rail_off_is_allowed()) {
489                 if (fast_cluster_power_down_mode &&
490                         TEGRA_POWER_CLUSTER_FORCE_MASK)
491                         power_gating_cpu_only = cpu_gating_only;
492                 else if (request > tegra_min_residency_noncpu())
493                         power_gating_cpu_only = false;
494                 else
495                         power_gating_cpu_only = true;
496         } else
497                 power_gating_cpu_only = true;
498
499         if (power_gating_cpu_only)
500                 power_down = tegra_cpu_core_power_down(dev, state, request);
501         else
502                 power_down = tegra_cpu_cluster_power_down(dev, state, request);
503
504         tegra_clear_cpu_in_pd(dev->cpu);
505
506         return power_down;
507 }
508
509 #ifdef CONFIG_DEBUG_FS
510 int tegra11x_pd_debug_show(struct seq_file *s, void *data)
511 {
512         int bin;
513         int i;
514         seq_printf(s, "                                    cpu0     cpu1     cpu2     cpu3     cpulp\n");
515         seq_printf(s, "-----------------------------------------------------------------------------\n");
516         seq_printf(s, "cpu ready:                      %8u %8u %8u %8u %8u\n",
517                 idle_stats.cpu_ready_count[0],
518                 idle_stats.cpu_ready_count[1],
519                 idle_stats.cpu_ready_count[2],
520                 idle_stats.cpu_ready_count[3],
521                 idle_stats.cpu_ready_count[4]);
522         seq_printf(s, "tear down:                      %8u %8u %8u %8u %8u\n",
523                 idle_stats.tear_down_count[0],
524                 idle_stats.tear_down_count[1],
525                 idle_stats.tear_down_count[2],
526                 idle_stats.tear_down_count[3],
527                 idle_stats.tear_down_count[4]);
528         seq_printf(s, "rail gating count:      %8u\n",
529                 idle_stats.rail_gating_count);
530         seq_printf(s, "rail gating completed:  %8u %7u%%\n",
531                 idle_stats.rail_gating_done_count,
532                 idle_stats.rail_gating_done_count * 100 /
533                         (idle_stats.rail_gating_count ?: 1));
534
535         seq_printf(s, "c0nc gating count:      %8u\n",
536                 idle_stats.c0nc_gating_count);
537         seq_printf(s, "c0nc gating completed:  %8u %7u%%\n",
538                 idle_stats.c0nc_gating_done_count,
539                 idle_stats.c0nc_gating_done_count * 100 /
540                         (idle_stats.c0nc_gating_count ?: 1));
541
542         seq_printf(s, "c1nc gating count:      %8u\n",
543                 idle_stats.c1nc_gating_count);
544         seq_printf(s, "c1nc gating completed:  %8u %7u%%\n",
545                 idle_stats.c1nc_gating_done_count,
546                 idle_stats.c1nc_gating_done_count * 100 /
547                         (idle_stats.c1nc_gating_count ?: 1));
548
549         seq_printf(s, "\n");
550         seq_printf(s, "cpu ready time:                 " \
551                         "%8llu %8llu %8llu %8llu %8llu ms\n",
552                 div64_u64(idle_stats.cpu_wants_pd_time[0], 1000),
553                 div64_u64(idle_stats.cpu_wants_pd_time[1], 1000),
554                 div64_u64(idle_stats.cpu_wants_pd_time[2], 1000),
555                 div64_u64(idle_stats.cpu_wants_pd_time[3], 1000),
556                 div64_u64(idle_stats.cpu_wants_pd_time[4], 1000));
557
558         seq_printf(s, "cpu power gating time:          " \
559                         "%8llu %8llu %8llu %8llu %8llu ms\n",
560                 div64_u64(idle_stats.cpu_pg_time[0], 1000),
561                 div64_u64(idle_stats.cpu_pg_time[1], 1000),
562                 div64_u64(idle_stats.cpu_pg_time[2], 1000),
563                 div64_u64(idle_stats.cpu_pg_time[3], 1000),
564                 div64_u64(idle_stats.cpu_pg_time[4], 1000));
565
566         seq_printf(s, "power gated %%:                 " \
567                         "%7d%% %7d%% %7d%% %7d%% %7d%%\n",
568                 (int)(idle_stats.cpu_wants_pd_time[0] ?
569                         div64_u64(idle_stats.cpu_pg_time[0] * 100,
570                         idle_stats.cpu_wants_pd_time[0]) : 0),
571                 (int)(idle_stats.cpu_wants_pd_time[1] ?
572                         div64_u64(idle_stats.cpu_pg_time[1] * 100,
573                         idle_stats.cpu_wants_pd_time[1]) : 0),
574                 (int)(idle_stats.cpu_wants_pd_time[2] ?
575                         div64_u64(idle_stats.cpu_pg_time[2] * 100,
576                         idle_stats.cpu_wants_pd_time[2]) : 0),
577                 (int)(idle_stats.cpu_wants_pd_time[3] ?
578                         div64_u64(idle_stats.cpu_pg_time[3] * 100,
579                         idle_stats.cpu_wants_pd_time[3]) : 0),
580                 (int)(idle_stats.cpu_wants_pd_time[4] ?
581                         div64_u64(idle_stats.cpu_pg_time[4] * 100,
582                         idle_stats.cpu_wants_pd_time[4]) : 0));
583
584         seq_printf(s, "\n");
585         seq_printf(s, "rail gating time  c0nc gating time  c1nc gating time\n");
586         seq_printf(s, "%8llu ms          %8llu ms          %8llu ms\n",
587                 div64_u64(idle_stats.rail_pd_time, 1000),
588                 div64_u64(idle_stats.c0nc_pg_time, 1000),
589                 div64_u64(idle_stats.c1nc_pg_time, 1000));
590         seq_printf(s, "%8d%%             %8d%%             %8d%%\n",
591                 (int)(idle_stats.cpu_wants_pd_time[0] ?
592                         div64_u64(idle_stats.rail_pd_time * 100,
593                         idle_stats.cpu_wants_pd_time[0]) : 0),
594                 (int)(idle_stats.cpu_wants_pd_time[0] ?
595                         div64_u64(idle_stats.c0nc_pg_time * 100,
596                         idle_stats.cpu_wants_pd_time[0]) : 0),
597                 (int)(idle_stats.cpu_wants_pd_time[4] ?
598                         div64_u64(idle_stats.c1nc_pg_time * 100,
599                         idle_stats.cpu_wants_pd_time[4]) : 0));
600
601         seq_printf(s, "\n");
602
603         seq_printf(s, "%19s %8s %8s %8s\n", "", "rail gating", "comp", "%");
604         seq_printf(s, "-------------------------------------------------\n");
605         for (bin = 0; bin < 32; bin++) {
606                 if (idle_stats.rail_gating_bin[bin] == 0)
607                         continue;
608                 seq_printf(s, "%6u - %6u ms: %8u %8u %7u%%\n",
609                         1 << (bin - 1), 1 << bin,
610                         idle_stats.rail_gating_bin[bin],
611                         idle_stats.rail_gating_done_count_bin[bin],
612                         idle_stats.rail_gating_done_count_bin[bin] * 100 /
613                                 idle_stats.rail_gating_bin[bin]);
614         }
615         seq_printf(s, "\n");
616
617         seq_printf(s, "%19s %8s %8s %8s\n", "", "c0nc gating", "comp", "%");
618         seq_printf(s, "-------------------------------------------------\n");
619         for (bin = 0; bin < 32; bin++) {
620                 if (idle_stats.c0nc_gating_bin[bin] == 0)
621                         continue;
622                 seq_printf(s, "%6u - %6u ms: %8u %8u %7u%%\n",
623                         1 << (bin - 1), 1 << bin,
624                         idle_stats.c0nc_gating_bin[bin],
625                         idle_stats.c0nc_gating_done_count_bin[bin],
626                         idle_stats.c0nc_gating_done_count_bin[bin] * 100 /
627                                 idle_stats.c0nc_gating_bin[bin]);
628         }
629         seq_printf(s, "\n");
630
631         seq_printf(s, "%19s %8s %8s %8s\n", "", "c1nc gating", "comp", "%");
632         seq_printf(s, "-------------------------------------------------\n");
633         for (bin = 0; bin < 32; bin++) {
634                 if (idle_stats.c1nc_gating_bin[bin] == 0)
635                         continue;
636                 seq_printf(s, "%6u - %6u ms: %8u %8u %7u%%\n",
637                         1 << (bin - 1), 1 << bin,
638                         idle_stats.c1nc_gating_bin[bin],
639                         idle_stats.c1nc_gating_done_count_bin[bin],
640                         idle_stats.c1nc_gating_done_count_bin[bin] * 100 /
641                                 idle_stats.c1nc_gating_bin[bin]);
642         }
643
644         seq_printf(s, "\n");
645         seq_printf(s, "%3s %20s %6s %10s\n",
646                 "int", "name", "count", "last count");
647         seq_printf(s, "--------------------------------------------\n");
648         for (i = 0; i < NR_IRQS; i++) {
649                 if (idle_stats.pd_int_count[i] == 0)
650                         continue;
651                 seq_printf(s, "%3d %20s %6d %10d\n",
652                         i, irq_to_desc(i)->action ?
653                                 irq_to_desc(i)->action->name ?: "???" : "???",
654                         idle_stats.pd_int_count[i],
655                         idle_stats.pd_int_count[i] -
656                                 idle_stats.last_pd_int_count[i]);
657                 idle_stats.last_pd_int_count[i] = idle_stats.pd_int_count[i];
658         };
659         return 0;
660 }
661 #endif
662
663 int __init tegra11x_cpuidle_init_soc(struct tegra_cpuidle_ops *idle_ops)
664 {
665         int i;
666         struct tegra_cpuidle_ops ops = {
667                 tegra11x_idle_power_down,
668                 tegra11x_cpu_idle_stats_pd_ready,
669                 tegra11x_cpu_idle_stats_pd_time,
670                 tegra11x_pd_is_allowed,
671 #ifdef CONFIG_DEBUG_FS
672                 tegra11x_pd_debug_show
673 #endif
674         };
675
676         cpu_clk_for_dvfs = tegra_get_clock_by_name("cpu_g");
677
678         for (i = 0; i < ARRAY_SIZE(pd_exit_latencies); i++)
679                 pd_exit_latencies[i] = tegra_pg_exit_latency;
680
681         *idle_ops = ops;
682         return 0;
683 }