blob: ba9b34b579f3d1a2757004f05a19412fd0c6043b [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 Lezcano7880e452014-05-09 06:43:26 +090023static int exynos_enter_lowpower(struct cpuidle_device *dev,
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080024 struct cpuidle_driver *drv,
25 int index)
26{
27 int new_index = index;
28
Bartlomiej Zolnierkiewicz118f5c12013-12-20 19:47:23 +010029 /* AFTR can only be entered when cores other than CPU0 are offline */
30 if (num_online_cpus() > 1 || dev->cpu != 0)
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080031 new_index = drv->safe_state_index;
32
33 if (new_index == 0)
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090034 return arm_cpuidle_simple_enter(dev, drv, new_index);
Tomasz Figa01601b32014-08-05 14:43:10 +020035
36 exynos_enter_aftr();
37
38 return new_index;
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080039}
40
Daniel Lezcano7880e452014-05-09 06:43:26 +090041static struct cpuidle_driver exynos_idle_driver = {
42 .name = "exynos_idle",
Daniel Lezcano53af16a2014-05-09 06:43:26 +090043 .owner = THIS_MODULE,
44 .states = {
45 [0] = ARM_CPUIDLE_WFI_STATE,
46 [1] = {
Daniel Lezcano7880e452014-05-09 06:43:26 +090047 .enter = exynos_enter_lowpower,
Daniel Lezcano53af16a2014-05-09 06:43:26 +090048 .exit_latency = 300,
49 .target_residency = 100000,
50 .flags = CPUIDLE_FLAG_TIME_VALID,
51 .name = "C1",
52 .desc = "ARM power down",
53 },
54 },
55 .state_count = 2,
56 .safe_state_index = 0,
57};
58
Jingoo Hanf612a4f2013-10-21 10:53:03 +090059static int exynos_cpuidle_probe(struct platform_device *pdev)
Jaecheol Lee3d739982011-03-16 07:28:23 +090060{
Daniel Lezcano043c86b2014-05-09 06:43:26 +090061 int ret;
Jaecheol Lee3d739982011-03-16 07:28:23 +090062
Daniel Lezcano277f5042014-05-09 06:56:29 +090063 exynos_enter_aftr = (void *)(pdev->dev.platform_data);
64
Daniel Lezcano7880e452014-05-09 06:43:26 +090065 ret = cpuidle_register(&exynos_idle_driver, NULL);
Daniel Lezcano5db9f432013-01-18 21:57:58 -080066 if (ret) {
Jingoo Hanae7c4c82013-10-21 10:52:15 +090067 dev_err(&pdev->dev, "failed to register cpuidle driver\n");
Daniel Lezcano5db9f432013-01-18 21:57:58 -080068 return ret;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053069 }
Jaecheol Lee3d739982011-03-16 07:28:23 +090070
Jaecheol Lee3d739982011-03-16 07:28:23 +090071 return 0;
72}
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020073
74static struct platform_driver exynos_cpuidle_driver = {
75 .probe = exynos_cpuidle_probe,
76 .driver = {
77 .name = "exynos_cpuidle",
78 .owner = THIS_MODULE,
79 },
80};
81
82module_platform_driver(exynos_cpuidle_driver);