Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 1 | /* linux/arch/arm/mach-exynos/cpuidle.c |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 2 | * |
| 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 Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 14 | #include <linux/cpu_pm.h> |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 15 | #include <linux/io.h> |
Kyungmin Park | 76ee455 | 2011-11-08 19:57:59 +0900 | [diff] [blame] | 16 | #include <linux/export.h> |
Arnd Bergmann | 96c3a25 | 2014-03-19 18:29:36 +0100 | [diff] [blame] | 17 | #include <linux/module.h> |
Kyungmin Park | 76ee455 | 2011-11-08 19:57:59 +0900 | [diff] [blame] | 18 | #include <linux/time.h> |
Bartlomiej Zolnierkiewicz | 35baa33 | 2013-08-30 12:15:04 +0200 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 20 | |
| 21 | #include <asm/proc-fns.h> |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 22 | #include <asm/suspend.h> |
| 23 | #include <asm/unified.h> |
Amit Daniel Kachhap | 06c77b3 | 2012-05-12 16:29:21 +0900 | [diff] [blame] | 24 | #include <asm/cpuidle.h> |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 25 | |
| 26 | #include <plat/cpu.h> |
Amit Daniel Kachhap | 8969301 | 2013-07-24 14:06:13 +0900 | [diff] [blame] | 27 | #include <plat/pm.h> |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 28 | |
Kukjin Kim | b5fd130 | 2013-12-19 04:22:09 +0900 | [diff] [blame] | 29 | #include <mach/map.h> |
| 30 | |
Daniel Lezcano | 277f504 | 2014-05-09 06:56:29 +0900 | [diff] [blame^] | 31 | static void (*exynos_enter_aftr)(void); |
Kukjin Kim | ccd458c | 2012-12-31 10:06:48 -0800 | [diff] [blame] | 32 | |
Daniel Lezcano | 712bb69 | 2014-05-09 06:52:59 +0900 | [diff] [blame] | 33 | static int idle_finisher(unsigned long flags) |
| 34 | { |
| 35 | exynos_enter_aftr(); |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 36 | cpu_do_idle(); |
Daniel Lezcano | 20115fa | 2014-05-09 06:43:27 +0900 | [diff] [blame] | 37 | |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 38 | return 1; |
| 39 | } |
| 40 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 41 | static int exynos_enter_core0_aftr(struct cpuidle_device *dev, |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 42 | struct cpuidle_driver *drv, |
| 43 | int index) |
| 44 | { |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 45 | cpu_pm_enter(); |
| 46 | cpu_suspend(0, idle_finisher); |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 47 | cpu_pm_exit(); |
| 48 | |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 49 | return index; |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 50 | } |
| 51 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 52 | static int exynos_enter_lowpower(struct cpuidle_device *dev, |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 53 | struct cpuidle_driver *drv, |
| 54 | int index) |
| 55 | { |
| 56 | int new_index = index; |
| 57 | |
Bartlomiej Zolnierkiewicz | 118f5c1 | 2013-12-20 19:47:23 +0100 | [diff] [blame] | 58 | /* AFTR can only be entered when cores other than CPU0 are offline */ |
| 59 | if (num_online_cpus() > 1 || dev->cpu != 0) |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 60 | new_index = drv->safe_state_index; |
| 61 | |
| 62 | if (new_index == 0) |
Amit Daniel Kachhap | 06c77b3 | 2012-05-12 16:29:21 +0900 | [diff] [blame] | 63 | return arm_cpuidle_simple_enter(dev, drv, new_index); |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 64 | else |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 65 | return exynos_enter_core0_aftr(dev, drv, new_index); |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 68 | static struct cpuidle_driver exynos_idle_driver = { |
| 69 | .name = "exynos_idle", |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 70 | .owner = THIS_MODULE, |
| 71 | .states = { |
| 72 | [0] = ARM_CPUIDLE_WFI_STATE, |
| 73 | [1] = { |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 74 | .enter = exynos_enter_lowpower, |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 75 | .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 Han | f612a4f | 2013-10-21 10:53:03 +0900 | [diff] [blame] | 86 | static int exynos_cpuidle_probe(struct platform_device *pdev) |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 87 | { |
Daniel Lezcano | 043c86b | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 88 | int ret; |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 89 | |
Daniel Lezcano | 277f504 | 2014-05-09 06:56:29 +0900 | [diff] [blame^] | 90 | exynos_enter_aftr = (void *)(pdev->dev.platform_data); |
| 91 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 92 | ret = cpuidle_register(&exynos_idle_driver, NULL); |
Daniel Lezcano | 5db9f43 | 2013-01-18 21:57:58 -0800 | [diff] [blame] | 93 | if (ret) { |
Jingoo Han | ae7c4c8 | 2013-10-21 10:52:15 +0900 | [diff] [blame] | 94 | dev_err(&pdev->dev, "failed to register cpuidle driver\n"); |
Daniel Lezcano | 5db9f43 | 2013-01-18 21:57:58 -0800 | [diff] [blame] | 95 | return ret; |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 96 | } |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 97 | |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 98 | return 0; |
| 99 | } |
Bartlomiej Zolnierkiewicz | 35baa33 | 2013-08-30 12:15:04 +0200 | [diff] [blame] | 100 | |
| 101 | static struct platform_driver exynos_cpuidle_driver = { |
| 102 | .probe = exynos_cpuidle_probe, |
| 103 | .driver = { |
| 104 | .name = "exynos_cpuidle", |
| 105 | .owner = THIS_MODULE, |
| 106 | }, |
| 107 | }; |
| 108 | |
| 109 | module_platform_driver(exynos_cpuidle_driver); |