blob: 7c0151263828332464ae3021bcb1b1ee980f615c [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
Jaecheol Lee3d739982011-03-16 07:28:23 +090011#include <linux/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080012#include <linux/cpu_pm.h>
Kyungmin Park76ee4552011-11-08 19:57:59 +090013#include <linux/export.h>
Arnd Bergmann96c3a252014-03-19 18:29:36 +010014#include <linux/module.h>
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020015#include <linux/platform_device.h>
Jaecheol Lee3d739982011-03-16 07:28:23 +090016
17#include <asm/proc-fns.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080018#include <asm/suspend.h>
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090019#include <asm/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080020
Daniel Lezcano277f5042014-05-09 06:56:29 +090021static void (*exynos_enter_aftr)(void);
Kukjin Kimccd458c2012-12-31 10:06:48 -080022
Daniel Lezcano712bb692014-05-09 06:52:59 +090023static int idle_finisher(unsigned long flags)
24{
25 exynos_enter_aftr();
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080026 cpu_do_idle();
Daniel Lezcano20115fa2014-05-09 06:43:27 +090027
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080028 return 1;
29}
30
Daniel Lezcano7880e452014-05-09 06:43:26 +090031static int exynos_enter_core0_aftr(struct cpuidle_device *dev,
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080032 struct cpuidle_driver *drv,
33 int index)
34{
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080035 cpu_pm_enter();
36 cpu_suspend(0, idle_finisher);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080037 cpu_pm_exit();
38
Deepthi Dharware978aa72011-10-28 16:20:09 +053039 return index;
Jaecheol Lee3d739982011-03-16 07:28:23 +090040}
41
Daniel Lezcano7880e452014-05-09 06:43:26 +090042static int exynos_enter_lowpower(struct cpuidle_device *dev,
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080043 struct cpuidle_driver *drv,
44 int index)
45{
46 int new_index = index;
47
Bartlomiej Zolnierkiewicz118f5c12013-12-20 19:47:23 +010048 /* AFTR can only be entered when cores other than CPU0 are offline */
49 if (num_online_cpus() > 1 || dev->cpu != 0)
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080050 new_index = drv->safe_state_index;
51
52 if (new_index == 0)
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090053 return arm_cpuidle_simple_enter(dev, drv, new_index);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080054 else
Daniel Lezcano7880e452014-05-09 06:43:26 +090055 return exynos_enter_core0_aftr(dev, drv, new_index);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080056}
57
Daniel Lezcano7880e452014-05-09 06:43:26 +090058static struct cpuidle_driver exynos_idle_driver = {
59 .name = "exynos_idle",
Daniel Lezcano53af16a2014-05-09 06:43:26 +090060 .owner = THIS_MODULE,
61 .states = {
62 [0] = ARM_CPUIDLE_WFI_STATE,
63 [1] = {
Daniel Lezcano7880e452014-05-09 06:43:26 +090064 .enter = exynos_enter_lowpower,
Daniel Lezcano53af16a2014-05-09 06:43:26 +090065 .exit_latency = 300,
66 .target_residency = 100000,
67 .flags = CPUIDLE_FLAG_TIME_VALID,
68 .name = "C1",
69 .desc = "ARM power down",
70 },
71 },
72 .state_count = 2,
73 .safe_state_index = 0,
74};
75
Jingoo Hanf612a4f2013-10-21 10:53:03 +090076static int exynos_cpuidle_probe(struct platform_device *pdev)
Jaecheol Lee3d739982011-03-16 07:28:23 +090077{
Daniel Lezcano043c86b2014-05-09 06:43:26 +090078 int ret;
Jaecheol Lee3d739982011-03-16 07:28:23 +090079
Daniel Lezcano277f5042014-05-09 06:56:29 +090080 exynos_enter_aftr = (void *)(pdev->dev.platform_data);
81
Daniel Lezcano7880e452014-05-09 06:43:26 +090082 ret = cpuidle_register(&exynos_idle_driver, NULL);
Daniel Lezcano5db9f432013-01-18 21:57:58 -080083 if (ret) {
Jingoo Hanae7c4c82013-10-21 10:52:15 +090084 dev_err(&pdev->dev, "failed to register cpuidle driver\n");
Daniel Lezcano5db9f432013-01-18 21:57:58 -080085 return ret;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053086 }
Jaecheol Lee3d739982011-03-16 07:28:23 +090087
Jaecheol Lee3d739982011-03-16 07:28:23 +090088 return 0;
89}
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020090
91static struct platform_driver exynos_cpuidle_driver = {
92 .probe = exynos_cpuidle_probe,
93 .driver = {
94 .name = "exynos_cpuidle",
95 .owner = THIS_MODULE,
96 },
97};
98
99module_platform_driver(exynos_cpuidle_driver);