Thomas Gleixner | 9952f69 | 2019-05-28 10:10:04 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2012 Calxeda, Inc. |
| 4 | * |
Daniel Lezcano | a8e39c3 | 2013-04-26 11:05:44 +0000 | [diff] [blame] | 5 | * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7 |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 6 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 7 | * Copyright 2012 Linaro Ltd. |
| 8 | * |
Daniel Lezcano | a8e39c3 | 2013-04-26 11:05:44 +0000 | [diff] [blame] | 9 | * Maintainer: Rob Herring <rob.herring@calxeda.com> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/cpuidle.h> |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 13 | #include <linux/cpu_pm.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 14 | #include <linux/init.h> |
Rob Herring | a410146 | 2013-02-26 16:05:46 -0600 | [diff] [blame] | 15 | #include <linux/mm.h> |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Mark Rutland | be12039 | 2015-07-31 15:46:19 +0100 | [diff] [blame] | 17 | #include <linux/psci.h> |
| 18 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 19 | #include <asm/cpuidle.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 20 | #include <asm/suspend.h> |
Mark Rutland | be12039 | 2015-07-31 15:46:19 +0100 | [diff] [blame] | 21 | |
| 22 | #include <uapi/linux/psci.h> |
| 23 | |
| 24 | #define CALXEDA_IDLE_PARAM \ |
| 25 | ((0 << PSCI_0_2_POWER_STATE_ID_SHIFT) | \ |
| 26 | (0 << PSCI_0_2_POWER_STATE_AFFL_SHIFT) | \ |
| 27 | (PSCI_POWER_STATE_TYPE_POWER_DOWN << PSCI_0_2_POWER_STATE_TYPE_SHIFT)) |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 28 | |
| 29 | static int calxeda_idle_finish(unsigned long val) |
| 30 | { |
Mark Rutland | be12039 | 2015-07-31 15:46:19 +0100 | [diff] [blame] | 31 | return psci_ops.cpu_suspend(CALXEDA_IDLE_PARAM, __pa(cpu_resume)); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static int calxeda_pwrdown_idle(struct cpuidle_device *dev, |
| 35 | struct cpuidle_driver *drv, |
| 36 | int index) |
| 37 | { |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 38 | cpu_pm_enter(); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 39 | cpu_suspend(0, calxeda_idle_finish); |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 40 | cpu_pm_exit(); |
| 41 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 42 | return index; |
| 43 | } |
| 44 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 45 | static struct cpuidle_driver calxeda_idle_driver = { |
| 46 | .name = "calxeda_idle", |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 47 | .states = { |
| 48 | ARM_CPUIDLE_WFI_STATE, |
| 49 | { |
| 50 | .name = "PG", |
| 51 | .desc = "Power Gate", |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 52 | .exit_latency = 30, |
| 53 | .power_usage = 50, |
| 54 | .target_residency = 200, |
| 55 | .enter = calxeda_pwrdown_idle, |
| 56 | }, |
| 57 | }, |
| 58 | .state_count = 2, |
| 59 | }; |
| 60 | |
Andre Przywara | 5781532 | 2013-12-13 21:49:19 +0100 | [diff] [blame] | 61 | static int calxeda_cpuidle_probe(struct platform_device *pdev) |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 62 | { |
Daniel Lezcano | 0b210d9 | 2013-04-23 08:54:42 +0000 | [diff] [blame] | 63 | return cpuidle_register(&calxeda_idle_driver, NULL); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 64 | } |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame] | 65 | |
| 66 | static struct platform_driver calxeda_cpuidle_plat_driver = { |
| 67 | .driver = { |
| 68 | .name = "cpuidle-calxeda", |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame] | 69 | }, |
| 70 | .probe = calxeda_cpuidle_probe, |
| 71 | }; |
Paul Gortmaker | 090d1cf | 2015-05-01 20:10:57 -0400 | [diff] [blame] | 72 | builtin_platform_driver(calxeda_cpuidle_plat_driver); |