1
2
3
4
5
6
7
8
9#include <linux/cpuidle.h>
10#include <linux/module.h>
11#include <asm/cpuidle.h>
12#include <asm/proc-fns.h>
13
14#include "common.h"
15#include "cpuidle.h"
16
17static atomic_t master = ATOMIC_INIT(0);
18static DEFINE_SPINLOCK(master_lock);
19
20static int imx6q_enter_wait(struct cpuidle_device *dev,
21 struct cpuidle_driver *drv, int index)
22{
23 if (atomic_inc_return(&master) == num_online_cpus()) {
24
25
26
27
28 if (!spin_trylock(&master_lock))
29 goto idle;
30 imx6q_set_lpm(WAIT_UNCLOCKED);
31 cpu_do_idle();
32 imx6q_set_lpm(WAIT_CLOCKED);
33 spin_unlock(&master_lock);
34 goto done;
35 }
36
37idle:
38 cpu_do_idle();
39done:
40 atomic_dec(&master);
41
42 return index;
43}
44
45static struct cpuidle_driver imx6q_cpuidle_driver = {
46 .name = "imx6q_cpuidle",
47 .owner = THIS_MODULE,
48 .states = {
49
50 ARM_CPUIDLE_WFI_STATE,
51
52 {
53 .exit_latency = 50,
54 .target_residency = 75,
55 .flags = CPUIDLE_FLAG_TIME_VALID |
56 CPUIDLE_FLAG_TIMER_STOP,
57 .enter = imx6q_enter_wait,
58 .name = "WAIT",
59 .desc = "Clock off",
60 },
61 },
62 .state_count = 2,
63 .safe_state_index = 0,
64};
65
66int __init imx6q_cpuidle_init(void)
67{
68
69 imx_scu_standby_enable();
70
71
72 imx6q_set_chicken_bit();
73
74 return cpuidle_register(&imx6q_cpuidle_driver, NULL);
75}
76