• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #include "common.h"
14 #include "cpuidle.h"
15 #include "hardware.h"
16 
17 static int num_idle_cpus = 0;
18 static DEFINE_SPINLOCK(cpuidle_lock);
19 
imx6q_enter_wait(struct cpuidle_device * dev,struct cpuidle_driver * drv,int index)20 static int imx6q_enter_wait(struct cpuidle_device *dev,
21 			    struct cpuidle_driver *drv, int index)
22 {
23 	spin_lock(&cpuidle_lock);
24 	if (++num_idle_cpus == num_online_cpus())
25 		imx6_set_lpm(WAIT_UNCLOCKED);
26 	spin_unlock(&cpuidle_lock);
27 
28 	cpu_do_idle();
29 
30 	spin_lock(&cpuidle_lock);
31 	if (num_idle_cpus-- == num_online_cpus())
32 		imx6_set_lpm(WAIT_CLOCKED);
33 	spin_unlock(&cpuidle_lock);
34 
35 	return index;
36 }
37 
38 static struct cpuidle_driver imx6q_cpuidle_driver = {
39 	.name = "imx6q_cpuidle",
40 	.owner = THIS_MODULE,
41 	.states = {
42 		/* WFI */
43 		ARM_CPUIDLE_WFI_STATE,
44 		/* WAIT */
45 		{
46 			.exit_latency = 50,
47 			.target_residency = 75,
48 			.flags = CPUIDLE_FLAG_TIMER_STOP,
49 			.enter = imx6q_enter_wait,
50 			.name = "WAIT",
51 			.desc = "Clock off",
52 		},
53 	},
54 	.state_count = 2,
55 	.safe_state_index = 0,
56 };
57 
imx6q_cpuidle_init(void)58 int __init imx6q_cpuidle_init(void)
59 {
60 	/* Set INT_MEM_CLK_LPM bit to get a reliable WAIT mode support */
61 	imx6q_set_int_mem_clk_lpm(true);
62 
63 	return cpuidle_register(&imx6q_cpuidle_driver, NULL);
64 }
65