]>
Commit | Line | Data |
---|---|---|
12bb3440 SG |
1 | /* |
2 | * Copyright (C) 2012 Freescale Semiconductor, Inc. | |
3 | * | |
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. | |
7 | */ | |
8 | ||
9 | #include <linux/cpuidle.h> | |
10 | #include <linux/module.h> | |
11 | #include <asm/cpuidle.h> | |
12 | ||
47096103 BD |
13 | #include <soc/imx/cpuidle.h> |
14 | ||
e5f9dec8 | 15 | #include "common.h" |
12bb3440 | 16 | #include "cpuidle.h" |
a25d67a4 | 17 | #include "hardware.h" |
12bb3440 | 18 | |
ace6b822 KO |
19 | static int num_idle_cpus = 0; |
20 | static DEFINE_SPINLOCK(cpuidle_lock); | |
e5f9dec8 SG |
21 | |
22 | static int imx6q_enter_wait(struct cpuidle_device *dev, | |
23 | struct cpuidle_driver *drv, int index) | |
24 | { | |
ace6b822 KO |
25 | spin_lock(&cpuidle_lock); |
26 | if (++num_idle_cpus == num_online_cpus()) | |
8fb76a07 | 27 | imx6_set_lpm(WAIT_UNCLOCKED); |
ace6b822 | 28 | spin_unlock(&cpuidle_lock); |
e5f9dec8 | 29 | |
e5f9dec8 | 30 | cpu_do_idle(); |
ace6b822 KO |
31 | |
32 | spin_lock(&cpuidle_lock); | |
33 | if (num_idle_cpus-- == num_online_cpus()) | |
34 | imx6_set_lpm(WAIT_CLOCKED); | |
35 | spin_unlock(&cpuidle_lock); | |
e5f9dec8 SG |
36 | |
37 | return index; | |
38 | } | |
39 | ||
12bb3440 SG |
40 | static struct cpuidle_driver imx6q_cpuidle_driver = { |
41 | .name = "imx6q_cpuidle", | |
42 | .owner = THIS_MODULE, | |
e5f9dec8 SG |
43 | .states = { |
44 | /* WFI */ | |
45 | ARM_CPUIDLE_WFI_STATE, | |
46 | /* WAIT */ | |
47 | { | |
48 | .exit_latency = 50, | |
49 | .target_residency = 75, | |
b82b6cca | 50 | .flags = CPUIDLE_FLAG_TIMER_STOP, |
e5f9dec8 SG |
51 | .enter = imx6q_enter_wait, |
52 | .name = "WAIT", | |
53 | .desc = "Clock off", | |
54 | }, | |
55 | }, | |
56 | .state_count = 2, | |
57 | .safe_state_index = 0, | |
12bb3440 SG |
58 | }; |
59 | ||
29380905 LS |
60 | /* |
61 | * i.MX6 Q/DL has an erratum (ERR006687) that prevents the FEC from waking the | |
62 | * CPUs when they are in wait(unclocked) state. As the hardware workaround isn't | |
63 | * applicable to all boards, disable the deeper idle state when the workaround | |
64 | * isn't present and the FEC is in use. | |
65 | */ | |
66 | void imx6q_cpuidle_fec_irqs_used(void) | |
67 | { | |
68 | imx6q_cpuidle_driver.states[1].disabled = true; | |
69 | } | |
2cb9caa4 | 70 | EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_used); |
29380905 LS |
71 | |
72 | void imx6q_cpuidle_fec_irqs_unused(void) | |
73 | { | |
74 | imx6q_cpuidle_driver.states[1].disabled = false; | |
75 | } | |
2cb9caa4 | 76 | EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_unused); |
29380905 | 77 | |
12bb3440 SG |
78 | int __init imx6q_cpuidle_init(void) |
79 | { | |
fa6be65e | 80 | /* Set INT_MEM_CLK_LPM bit to get a reliable WAIT mode support */ |
8765caa5 | 81 | imx6_set_int_mem_clk_lpm(true); |
e5f9dec8 | 82 | |
54a4644b | 83 | return cpuidle_register(&imx6q_cpuidle_driver, NULL); |
12bb3440 | 84 | } |