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