ARM: i.MX: Fix FIQ interrupt handling for TZIC
[deliverable/linux.git] / arch / arm / mach-imx / cpuidle-imx6q.c
CommitLineData
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
e5f9dec8 13#include "common.h"
12bb3440 14#include "cpuidle.h"
a25d67a4 15#include "hardware.h"
12bb3440 16
e5f9dec8
SG
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{
e5f9dec8
SG
23 if (atomic_inc_return(&master) == num_online_cpus()) {
24 /*
25 * With this lock, we prevent other cpu to exit and enter
26 * this function again and become the master.
27 */
28 if (!spin_trylock(&master_lock))
29 goto idle;
8fb76a07 30 imx6_set_lpm(WAIT_UNCLOCKED);
e5f9dec8 31 cpu_do_idle();
8fb76a07 32 imx6_set_lpm(WAIT_CLOCKED);
e5f9dec8
SG
33 spin_unlock(&master_lock);
34 goto done;
35 }
36
37idle:
38 cpu_do_idle();
39done:
40 atomic_dec(&master);
e5f9dec8
SG
41
42 return index;
43}
44
12bb3440
SG
45static struct cpuidle_driver imx6q_cpuidle_driver = {
46 .name = "imx6q_cpuidle",
47 .owner = THIS_MODULE,
e5f9dec8
SG
48 .states = {
49 /* WFI */
50 ARM_CPUIDLE_WFI_STATE,
51 /* WAIT */
52 {
53 .exit_latency = 50,
54 .target_residency = 75,
b82b6cca 55 .flags = CPUIDLE_FLAG_TIMER_STOP,
e5f9dec8
SG
56 .enter = imx6q_enter_wait,
57 .name = "WAIT",
58 .desc = "Clock off",
59 },
60 },
61 .state_count = 2,
62 .safe_state_index = 0,
12bb3440
SG
63};
64
29380905
LS
65/*
66 * i.MX6 Q/DL has an erratum (ERR006687) that prevents the FEC from waking the
67 * CPUs when they are in wait(unclocked) state. As the hardware workaround isn't
68 * applicable to all boards, disable the deeper idle state when the workaround
69 * isn't present and the FEC is in use.
70 */
71void imx6q_cpuidle_fec_irqs_used(void)
72{
73 imx6q_cpuidle_driver.states[1].disabled = true;
74}
2cb9caa4 75EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_used);
29380905
LS
76
77void imx6q_cpuidle_fec_irqs_unused(void)
78{
79 imx6q_cpuidle_driver.states[1].disabled = false;
80}
2cb9caa4 81EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_unused);
29380905 82
12bb3440
SG
83int __init imx6q_cpuidle_init(void)
84{
fa6be65e 85 /* Set INT_MEM_CLK_LPM bit to get a reliable WAIT mode support */
dfea953a 86 imx6q_set_int_mem_clk_lpm(true);
e5f9dec8 87
54a4644b 88 return cpuidle_register(&imx6q_cpuidle_driver, NULL);
12bb3440 89}
This page took 0.166912 seconds and 5 git commands to generate.