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 | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 23 | static int exynos_enter_lowpower(struct cpuidle_device *dev, |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 24 | struct cpuidle_driver *drv, |
| 25 | int index) |
| 26 | { |
| 27 | int new_index = index; |
| 28 | |
Bartlomiej Zolnierkiewicz | 118f5c1 | 2013-12-20 19:47:23 +0100 | [diff] [blame] | 29 | /* AFTR can only be entered when cores other than CPU0 are offline */ |
| 30 | if (num_online_cpus() > 1 || dev->cpu != 0) |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 31 | new_index = drv->safe_state_index; |
| 32 | |
| 33 | if (new_index == 0) |
Amit Daniel Kachhap | 06c77b3 | 2012-05-12 16:29:21 +0900 | [diff] [blame] | 34 | return arm_cpuidle_simple_enter(dev, drv, new_index); |
Tomasz Figa | 01601b3 | 2014-08-05 14:43:10 +0200 | [diff] [blame] | 35 | |
| 36 | exynos_enter_aftr(); |
| 37 | |
| 38 | return new_index; |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 41 | static struct cpuidle_driver exynos_idle_driver = { |
| 42 | .name = "exynos_idle", |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 43 | .owner = THIS_MODULE, |
| 44 | .states = { |
| 45 | [0] = ARM_CPUIDLE_WFI_STATE, |
| 46 | [1] = { |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 47 | .enter = exynos_enter_lowpower, |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 48 | .exit_latency = 300, |
| 49 | .target_residency = 100000, |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 50 | .name = "C1", |
| 51 | .desc = "ARM power down", |
| 52 | }, |
| 53 | }, |
| 54 | .state_count = 2, |
| 55 | .safe_state_index = 0, |
| 56 | }; |
| 57 | |
Jingoo Han | f612a4f | 2013-10-21 10:53:03 +0900 | [diff] [blame] | 58 | static int exynos_cpuidle_probe(struct platform_device *pdev) |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 59 | { |
Daniel Lezcano | 043c86b | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 60 | int ret; |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 61 | |
Daniel Lezcano | 277f504 | 2014-05-09 06:56:29 +0900 | [diff] [blame] | 62 | exynos_enter_aftr = (void *)(pdev->dev.platform_data); |
| 63 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 64 | ret = cpuidle_register(&exynos_idle_driver, NULL); |
Daniel Lezcano | 5db9f43 | 2013-01-18 21:57:58 -0800 | [diff] [blame] | 65 | if (ret) { |
Jingoo Han | ae7c4c8 | 2013-10-21 10:52:15 +0900 | [diff] [blame] | 66 | dev_err(&pdev->dev, "failed to register cpuidle driver\n"); |
Daniel Lezcano | 5db9f43 | 2013-01-18 21:57:58 -0800 | [diff] [blame] | 67 | return ret; |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 68 | } |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 69 | |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 70 | return 0; |
| 71 | } |
Bartlomiej Zolnierkiewicz | 35baa33 | 2013-08-30 12:15:04 +0200 | [diff] [blame] | 72 | |
| 73 | static struct platform_driver exynos_cpuidle_driver = { |
| 74 | .probe = exynos_cpuidle_probe, |
| 75 | .driver = { |
| 76 | .name = "exynos_cpuidle", |
Bartlomiej Zolnierkiewicz | 35baa33 | 2013-08-30 12:15:04 +0200 | [diff] [blame] | 77 | }, |
| 78 | }; |
| 79 | |
| 80 | module_platform_driver(exynos_cpuidle_driver); |