blob: 4003a3160865f3b46684b02001fe7974f46b3688 [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,
Daniel Lezcano53af16a2014-05-09 06:43:26 +090050 .name = "C1",
51 .desc = "ARM power down",
52 },
53 },
54 .state_count = 2,
55 .safe_state_index = 0,
56};
57
Jingoo Hanf612a4f2013-10-21 10:53:03 +090058static int exynos_cpuidle_probe(struct platform_device *pdev)
Jaecheol Lee3d739982011-03-16 07:28:23 +090059{
Daniel Lezcano043c86b2014-05-09 06:43:26 +090060 int ret;
Jaecheol Lee3d739982011-03-16 07:28:23 +090061
Daniel Lezcano277f5042014-05-09 06:56:29 +090062 exynos_enter_aftr = (void *)(pdev->dev.platform_data);
63
Daniel Lezcano7880e452014-05-09 06:43:26 +090064 ret = cpuidle_register(&exynos_idle_driver, NULL);
Daniel Lezcano5db9f432013-01-18 21:57:58 -080065 if (ret) {
Jingoo Hanae7c4c82013-10-21 10:52:15 +090066 dev_err(&pdev->dev, "failed to register cpuidle driver\n");
Daniel Lezcano5db9f432013-01-18 21:57:58 -080067 return ret;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053068 }
Jaecheol Lee3d739982011-03-16 07:28:23 +090069
Jaecheol Lee3d739982011-03-16 07:28:23 +090070 return 0;
71}
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020072
73static struct platform_driver exynos_cpuidle_driver = {
74 .probe = exynos_cpuidle_probe,
75 .driver = {
76 .name = "exynos_cpuidle",
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020077 },
78};
79
80module_platform_driver(exynos_cpuidle_driver);