xref: /linux/drivers/cpuidle/cpuidle-zynq.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*9952f691SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2bd2a337aSMichal Simek /*
3bd2a337aSMichal Simek  * Copyright (C) 2012-2013 Xilinx
4bd2a337aSMichal Simek  *
5bd2a337aSMichal Simek  * CPU idle support for Xilinx Zynq
6bd2a337aSMichal Simek  *
7bd2a337aSMichal Simek  * based on arch/arm/mach-at91/cpuidle.c
8bd2a337aSMichal Simek  *
9bd2a337aSMichal Simek  * The cpu idle uses wait-for-interrupt and RAM self refresh in order
10bd2a337aSMichal Simek  * to implement two idle states -
11bd2a337aSMichal Simek  * #1 wait-for-interrupt
12bd2a337aSMichal Simek  * #2 wait-for-interrupt and RAM self refresh
13bd2a337aSMichal Simek  *
14bd2a337aSMichal Simek  * Maintainer: Michal Simek <michal.simek@xilinx.com>
15bd2a337aSMichal Simek  */
16bd2a337aSMichal Simek 
17bd2a337aSMichal Simek #include <linux/init.h>
18bd2a337aSMichal Simek #include <linux/cpuidle.h>
193e8ceca6SDaniel Lezcano #include <linux/platform_device.h>
20bd2a337aSMichal Simek #include <asm/cpuidle.h>
21bd2a337aSMichal Simek 
22bd2a337aSMichal Simek #define ZYNQ_MAX_STATES		2
23bd2a337aSMichal Simek 
24bd2a337aSMichal Simek /* Actual code that puts the SoC in different idle states */
zynq_enter_idle(struct cpuidle_device * dev,struct cpuidle_driver * drv,int index)25bd2a337aSMichal Simek static int zynq_enter_idle(struct cpuidle_device *dev,
26bd2a337aSMichal Simek 			   struct cpuidle_driver *drv, int index)
27bd2a337aSMichal Simek {
28bd2a337aSMichal Simek 	/* Add code for DDR self refresh start */
29bd2a337aSMichal Simek 	cpu_do_idle();
30bd2a337aSMichal Simek 
31bd2a337aSMichal Simek 	return index;
32bd2a337aSMichal Simek }
33bd2a337aSMichal Simek 
34bd2a337aSMichal Simek static struct cpuidle_driver zynq_idle_driver = {
35bd2a337aSMichal Simek 	.name = "zynq_idle",
36bd2a337aSMichal Simek 	.owner = THIS_MODULE,
37bd2a337aSMichal Simek 	.states = {
38bd2a337aSMichal Simek 		ARM_CPUIDLE_WFI_STATE,
39bd2a337aSMichal Simek 		{
40bd2a337aSMichal Simek 			.enter			= zynq_enter_idle,
41bd2a337aSMichal Simek 			.exit_latency		= 10,
42bd2a337aSMichal Simek 			.target_residency	= 10000,
43bd2a337aSMichal Simek 			.name			= "RAM_SR",
44bd2a337aSMichal Simek 			.desc			= "WFI and RAM Self Refresh",
45bd2a337aSMichal Simek 		},
46bd2a337aSMichal Simek 	},
47bd2a337aSMichal Simek 	.safe_state_index = 0,
48bd2a337aSMichal Simek 	.state_count = ZYNQ_MAX_STATES,
49bd2a337aSMichal Simek };
50bd2a337aSMichal Simek 
51bd2a337aSMichal Simek /* Initialize CPU idle by registering the idle states */
zynq_cpuidle_probe(struct platform_device * pdev)523e8ceca6SDaniel Lezcano static int zynq_cpuidle_probe(struct platform_device *pdev)
53bd2a337aSMichal Simek {
54bd2a337aSMichal Simek 	pr_info("Xilinx Zynq CpuIdle Driver started\n");
55bd2a337aSMichal Simek 
56bd2a337aSMichal Simek 	return cpuidle_register(&zynq_idle_driver, NULL);
57bd2a337aSMichal Simek }
58bd2a337aSMichal Simek 
593e8ceca6SDaniel Lezcano static struct platform_driver zynq_cpuidle_driver = {
603e8ceca6SDaniel Lezcano 	.driver = {
613e8ceca6SDaniel Lezcano 		.name = "cpuidle-zynq",
623e8ceca6SDaniel Lezcano 	},
633e8ceca6SDaniel Lezcano 	.probe = zynq_cpuidle_probe,
643e8ceca6SDaniel Lezcano };
65090d1cf1SPaul Gortmaker builtin_platform_driver(zynq_cpuidle_driver);
66