Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Calxeda, Inc. |
| 3 | * |
Daniel Lezcano | a8e39c3 | 2013-04-26 11:05:44 +0000 | [diff] [blame] | 4 | * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7 |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 5 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 6 | * Copyright 2012 Linaro Ltd. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program. If not, see <http://www.gnu.org/licenses/>. |
Daniel Lezcano | a8e39c3 | 2013-04-26 11:05:44 +0000 | [diff] [blame] | 19 | * |
| 20 | * Maintainer: Rob Herring <rob.herring@calxeda.com> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/cpuidle.h> |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 24 | #include <linux/cpu_pm.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 25 | #include <linux/init.h> |
Rob Herring | a410146 | 2013-02-26 16:05:46 -0600 | [diff] [blame] | 26 | #include <linux/mm.h> |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 28 | #include <asm/cpuidle.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 29 | #include <asm/suspend.h> |
Rob Herring | a410146 | 2013-02-26 16:05:46 -0600 | [diff] [blame] | 30 | #include <asm/psci.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 31 | |
| 32 | static int calxeda_idle_finish(unsigned long val) |
| 33 | { |
Rob Herring | a410146 | 2013-02-26 16:05:46 -0600 | [diff] [blame] | 34 | const struct psci_power_state ps = { |
| 35 | .type = PSCI_POWER_STATE_TYPE_POWER_DOWN, |
| 36 | }; |
| 37 | return psci_ops.cpu_suspend(ps, __pa(cpu_resume)); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static int calxeda_pwrdown_idle(struct cpuidle_device *dev, |
| 41 | struct cpuidle_driver *drv, |
| 42 | int index) |
| 43 | { |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 44 | cpu_pm_enter(); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 45 | cpu_suspend(0, calxeda_idle_finish); |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 46 | cpu_pm_exit(); |
| 47 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 48 | return index; |
| 49 | } |
| 50 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 51 | static struct cpuidle_driver calxeda_idle_driver = { |
| 52 | .name = "calxeda_idle", |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 53 | .states = { |
| 54 | ARM_CPUIDLE_WFI_STATE, |
| 55 | { |
| 56 | .name = "PG", |
| 57 | .desc = "Power Gate", |
| 58 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 59 | .exit_latency = 30, |
| 60 | .power_usage = 50, |
| 61 | .target_residency = 200, |
| 62 | .enter = calxeda_pwrdown_idle, |
| 63 | }, |
| 64 | }, |
| 65 | .state_count = 2, |
| 66 | }; |
| 67 | |
Andre Przywara | 5781532 | 2013-12-13 21:49:19 +0100 | [diff] [blame] | 68 | static int calxeda_cpuidle_probe(struct platform_device *pdev) |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 69 | { |
Daniel Lezcano | 0b210d9 | 2013-04-23 08:54:42 +0000 | [diff] [blame] | 70 | return cpuidle_register(&calxeda_idle_driver, NULL); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 71 | } |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame] | 72 | |
| 73 | static struct platform_driver calxeda_cpuidle_plat_driver = { |
| 74 | .driver = { |
| 75 | .name = "cpuidle-calxeda", |
| 76 | .owner = THIS_MODULE, |
| 77 | }, |
| 78 | .probe = calxeda_cpuidle_probe, |
| 79 | }; |
| 80 | |
| 81 | module_platform_driver(calxeda_cpuidle_plat_driver); |