2 * Copyright (C) 2012 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/cpuidle.h>
10 #include <linux/module.h>
11 #include <asm/cpuidle.h>
12 #include <asm/proc-fns.h>
18 static atomic_t master
= ATOMIC_INIT(0);
19 static DEFINE_SPINLOCK(master_lock
);
21 static int imx6q_enter_wait(struct cpuidle_device
*dev
,
22 struct cpuidle_driver
*drv
, int index
)
24 if (atomic_inc_return(&master
) == num_online_cpus()) {
26 * With this lock, we prevent other cpu to exit and enter
27 * this function again and become the master.
29 if (!spin_trylock(&master_lock
))
31 imx6q_set_lpm(WAIT_UNCLOCKED
);
33 imx6q_set_lpm(WAIT_CLOCKED
);
34 spin_unlock(&master_lock
);
46 static struct cpuidle_driver imx6q_cpuidle_driver
= {
47 .name
= "imx6q_cpuidle",
51 ARM_CPUIDLE_WFI_STATE
,
55 .target_residency
= 75,
56 .flags
= CPUIDLE_FLAG_TIMER_STOP
,
57 .enter
= imx6q_enter_wait
,
63 .safe_state_index
= 0,
66 int __init
imx6q_cpuidle_init(void)
68 /* Set INT_MEM_CLK_LPM bit to get a reliable WAIT mode support */
69 imx6q_set_int_mem_clk_lpm(true);
71 return cpuidle_register(&imx6q_cpuidle_driver
, NULL
);