xref: /linux/arch/arm/mach-s3c/cpuidle-s3c64xx.c (revision 71b9114d2c13a648fbe6523dd859e611c316ad90)
1*71b9114dSArnd Bergmann // SPDX-License-Identifier: GPL-2.0
2*71b9114dSArnd Bergmann //
3*71b9114dSArnd Bergmann // Copyright (c) 2011 Wolfson Microelectronics, plc
4*71b9114dSArnd Bergmann // Copyright (c) 2011 Samsung Electronics Co., Ltd.
5*71b9114dSArnd Bergmann //		http://www.samsung.com
6*71b9114dSArnd Bergmann 
7*71b9114dSArnd Bergmann #include <linux/kernel.h>
8*71b9114dSArnd Bergmann #include <linux/init.h>
9*71b9114dSArnd Bergmann #include <linux/cpuidle.h>
10*71b9114dSArnd Bergmann #include <linux/io.h>
11*71b9114dSArnd Bergmann #include <linux/export.h>
12*71b9114dSArnd Bergmann #include <linux/time.h>
13*71b9114dSArnd Bergmann 
14*71b9114dSArnd Bergmann #include <asm/cpuidle.h>
15*71b9114dSArnd Bergmann 
16*71b9114dSArnd Bergmann #include <plat/cpu.h>
17*71b9114dSArnd Bergmann #include <mach/map.h>
18*71b9114dSArnd Bergmann 
19*71b9114dSArnd Bergmann #include "regs-sys-s3c64xx.h"
20*71b9114dSArnd Bergmann #include "regs-syscon-power-s3c64xx.h"
21*71b9114dSArnd Bergmann 
22*71b9114dSArnd Bergmann static int s3c64xx_enter_idle(struct cpuidle_device *dev,
23*71b9114dSArnd Bergmann 			      struct cpuidle_driver *drv,
24*71b9114dSArnd Bergmann 			      int index)
25*71b9114dSArnd Bergmann {
26*71b9114dSArnd Bergmann 	unsigned long tmp;
27*71b9114dSArnd Bergmann 
28*71b9114dSArnd Bergmann 	/* Setup PWRCFG to enter idle mode */
29*71b9114dSArnd Bergmann 	tmp = __raw_readl(S3C64XX_PWR_CFG);
30*71b9114dSArnd Bergmann 	tmp &= ~S3C64XX_PWRCFG_CFG_WFI_MASK;
31*71b9114dSArnd Bergmann 	tmp |= S3C64XX_PWRCFG_CFG_WFI_IDLE;
32*71b9114dSArnd Bergmann 	__raw_writel(tmp, S3C64XX_PWR_CFG);
33*71b9114dSArnd Bergmann 
34*71b9114dSArnd Bergmann 	cpu_do_idle();
35*71b9114dSArnd Bergmann 
36*71b9114dSArnd Bergmann 	return index;
37*71b9114dSArnd Bergmann }
38*71b9114dSArnd Bergmann 
39*71b9114dSArnd Bergmann static struct cpuidle_driver s3c64xx_cpuidle_driver = {
40*71b9114dSArnd Bergmann 	.name	= "s3c64xx_cpuidle",
41*71b9114dSArnd Bergmann 	.owner  = THIS_MODULE,
42*71b9114dSArnd Bergmann 	.states = {
43*71b9114dSArnd Bergmann 		{
44*71b9114dSArnd Bergmann 			.enter            = s3c64xx_enter_idle,
45*71b9114dSArnd Bergmann 			.exit_latency     = 1,
46*71b9114dSArnd Bergmann 			.target_residency = 1,
47*71b9114dSArnd Bergmann 			.name             = "IDLE",
48*71b9114dSArnd Bergmann 			.desc             = "System active, ARM gated",
49*71b9114dSArnd Bergmann 		},
50*71b9114dSArnd Bergmann 	},
51*71b9114dSArnd Bergmann 	.state_count = 1,
52*71b9114dSArnd Bergmann };
53*71b9114dSArnd Bergmann 
54*71b9114dSArnd Bergmann static int __init s3c64xx_init_cpuidle(void)
55*71b9114dSArnd Bergmann {
56*71b9114dSArnd Bergmann 	if (soc_is_s3c64xx())
57*71b9114dSArnd Bergmann 		return cpuidle_register(&s3c64xx_cpuidle_driver, NULL);
58*71b9114dSArnd Bergmann 	return 0;
59*71b9114dSArnd Bergmann }
60*71b9114dSArnd Bergmann device_initcall(s3c64xx_init_cpuidle);
61