blob: 05cb00c79406c6ffebce5ce4aada9d43010d8485 [file] [log] [blame]
Daniel Lezcano7880e452014-05-09 06:43:26 +09001/* linux/arch/arm/mach-exynos/cpuidle.c
Jaecheol Lee3d739982011-03-16 07:28:23 +09002 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9*/
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080014#include <linux/cpu_pm.h>
Jaecheol Lee3d739982011-03-16 07:28:23 +090015#include <linux/io.h>
Kyungmin Park76ee4552011-11-08 19:57:59 +090016#include <linux/export.h>
Arnd Bergmann96c3a252014-03-19 18:29:36 +010017#include <linux/module.h>
Kyungmin Park76ee4552011-11-08 19:57:59 +090018#include <linux/time.h>
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020019#include <linux/platform_device.h>
Jaecheol Lee3d739982011-03-16 07:28:23 +090020
21#include <asm/proc-fns.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080022#include <asm/suspend.h>
23#include <asm/unified.h>
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090024#include <asm/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080025
26#include <plat/cpu.h>
Amit Daniel Kachhap89693012013-07-24 14:06:13 +090027#include <plat/pm.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080028
Kukjin Kimb5fd1302013-12-19 04:22:09 +090029#include <mach/map.h>
30
Daniel Lezcano277f5042014-05-09 06:56:29 +090031static void (*exynos_enter_aftr)(void);
Kukjin Kimccd458c2012-12-31 10:06:48 -080032
Daniel Lezcano712bb692014-05-09 06:52:59 +090033static int idle_finisher(unsigned long flags)
34{
35 exynos_enter_aftr();
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080036 cpu_do_idle();
Daniel Lezcano20115fa2014-05-09 06:43:27 +090037
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080038 return 1;
39}
40
Daniel Lezcano7880e452014-05-09 06:43:26 +090041static int exynos_enter_core0_aftr(struct cpuidle_device *dev,
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080042 struct cpuidle_driver *drv,
43 int index)
44{
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080045 cpu_pm_enter();
46 cpu_suspend(0, idle_finisher);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080047 cpu_pm_exit();
48
Deepthi Dharware978aa72011-10-28 16:20:09 +053049 return index;
Jaecheol Lee3d739982011-03-16 07:28:23 +090050}
51
Daniel Lezcano7880e452014-05-09 06:43:26 +090052static int exynos_enter_lowpower(struct cpuidle_device *dev,
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080053 struct cpuidle_driver *drv,
54 int index)
55{
56 int new_index = index;
57
Bartlomiej Zolnierkiewicz118f5c12013-12-20 19:47:23 +010058 /* AFTR can only be entered when cores other than CPU0 are offline */
59 if (num_online_cpus() > 1 || dev->cpu != 0)
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080060 new_index = drv->safe_state_index;
61
62 if (new_index == 0)
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090063 return arm_cpuidle_simple_enter(dev, drv, new_index);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080064 else
Daniel Lezcano7880e452014-05-09 06:43:26 +090065 return exynos_enter_core0_aftr(dev, drv, new_index);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080066}
67
Daniel Lezcano7880e452014-05-09 06:43:26 +090068static struct cpuidle_driver exynos_idle_driver = {
69 .name = "exynos_idle",
Daniel Lezcano53af16a2014-05-09 06:43:26 +090070 .owner = THIS_MODULE,
71 .states = {
72 [0] = ARM_CPUIDLE_WFI_STATE,
73 [1] = {
Daniel Lezcano7880e452014-05-09 06:43:26 +090074 .enter = exynos_enter_lowpower,
Daniel Lezcano53af16a2014-05-09 06:43:26 +090075 .exit_latency = 300,
76 .target_residency = 100000,
77 .flags = CPUIDLE_FLAG_TIME_VALID,
78 .name = "C1",
79 .desc = "ARM power down",
80 },
81 },
82 .state_count = 2,
83 .safe_state_index = 0,
84};
85
Jingoo Hanf612a4f2013-10-21 10:53:03 +090086static int exynos_cpuidle_probe(struct platform_device *pdev)
Jaecheol Lee3d739982011-03-16 07:28:23 +090087{
Daniel Lezcano043c86b2014-05-09 06:43:26 +090088 int ret;
Jaecheol Lee3d739982011-03-16 07:28:23 +090089
Daniel Lezcano277f5042014-05-09 06:56:29 +090090 exynos_enter_aftr = (void *)(pdev->dev.platform_data);
91
Daniel Lezcano7880e452014-05-09 06:43:26 +090092 ret = cpuidle_register(&exynos_idle_driver, NULL);
Daniel Lezcano5db9f432013-01-18 21:57:58 -080093 if (ret) {
Jingoo Hanae7c4c82013-10-21 10:52:15 +090094 dev_err(&pdev->dev, "failed to register cpuidle driver\n");
Daniel Lezcano5db9f432013-01-18 21:57:58 -080095 return ret;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053096 }
Jaecheol Lee3d739982011-03-16 07:28:23 +090097
Jaecheol Lee3d739982011-03-16 07:28:23 +090098 return 0;
99}
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +0200100
101static struct platform_driver exynos_cpuidle_driver = {
102 .probe = exynos_cpuidle_probe,
103 .driver = {
104 .name = "exynos_cpuidle",
105 .owner = THIS_MODULE,
106 },
107};
108
109module_platform_driver(exynos_cpuidle_driver);