blob: ea9728fde9b3c8b1c1e79426d0ec056ce0e518fd [file] [log] [blame]
Rob Herringbe6a98d2012-10-12 12:45:34 -05001/*
2 * Copyright 2012 Calxeda, Inc.
3 *
Daniel Lezcanoa8e39c32013-04-26 11:05:44 +00004 * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7
Rob Herringbe6a98d2012-10-12 12:45:34 -05005 * 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 Lezcanoa8e39c32013-04-26 11:05:44 +000019 *
20 * Maintainer: Rob Herring <rob.herring@calxeda.com>
Rob Herringbe6a98d2012-10-12 12:45:34 -050021 */
22
23#include <linux/cpuidle.h>
Rob Herring34a5eeb2013-02-26 16:16:53 -060024#include <linux/cpu_pm.h>
Rob Herringbe6a98d2012-10-12 12:45:34 -050025#include <linux/init.h>
Rob Herringa4101462013-02-26 16:05:46 -060026#include <linux/mm.h>
Daniel Lezcano60a66e32013-09-27 12:47:45 +020027#include <linux/platform_device.h>
Mark Rutlandbe120392015-07-31 15:46:19 +010028#include <linux/psci.h>
29
Rob Herringbe6a98d2012-10-12 12:45:34 -050030#include <asm/cpuidle.h>
Rob Herringbe6a98d2012-10-12 12:45:34 -050031#include <asm/suspend.h>
Mark Rutlandbe120392015-07-31 15:46:19 +010032
33#include <uapi/linux/psci.h>
34
35#define CALXEDA_IDLE_PARAM \
36 ((0 << PSCI_0_2_POWER_STATE_ID_SHIFT) | \
37 (0 << PSCI_0_2_POWER_STATE_AFFL_SHIFT) | \
38 (PSCI_POWER_STATE_TYPE_POWER_DOWN << PSCI_0_2_POWER_STATE_TYPE_SHIFT))
Rob Herringbe6a98d2012-10-12 12:45:34 -050039
40static int calxeda_idle_finish(unsigned long val)
41{
Mark Rutlandbe120392015-07-31 15:46:19 +010042 return psci_ops.cpu_suspend(CALXEDA_IDLE_PARAM, __pa(cpu_resume));
Rob Herringbe6a98d2012-10-12 12:45:34 -050043}
44
45static int calxeda_pwrdown_idle(struct cpuidle_device *dev,
46 struct cpuidle_driver *drv,
47 int index)
48{
Rob Herring34a5eeb2013-02-26 16:16:53 -060049 cpu_pm_enter();
Rob Herringbe6a98d2012-10-12 12:45:34 -050050 cpu_suspend(0, calxeda_idle_finish);
Rob Herring34a5eeb2013-02-26 16:16:53 -060051 cpu_pm_exit();
52
Rob Herringbe6a98d2012-10-12 12:45:34 -050053 return index;
54}
55
Rob Herringbe6a98d2012-10-12 12:45:34 -050056static struct cpuidle_driver calxeda_idle_driver = {
57 .name = "calxeda_idle",
Rob Herringbe6a98d2012-10-12 12:45:34 -050058 .states = {
59 ARM_CPUIDLE_WFI_STATE,
60 {
61 .name = "PG",
62 .desc = "Power Gate",
Rob Herringbe6a98d2012-10-12 12:45:34 -050063 .exit_latency = 30,
64 .power_usage = 50,
65 .target_residency = 200,
66 .enter = calxeda_pwrdown_idle,
67 },
68 },
69 .state_count = 2,
70};
71
Andre Przywara57815322013-12-13 21:49:19 +010072static int calxeda_cpuidle_probe(struct platform_device *pdev)
Rob Herringbe6a98d2012-10-12 12:45:34 -050073{
Daniel Lezcano0b210d92013-04-23 08:54:42 +000074 return cpuidle_register(&calxeda_idle_driver, NULL);
Rob Herringbe6a98d2012-10-12 12:45:34 -050075}
Daniel Lezcano60a66e32013-09-27 12:47:45 +020076
77static struct platform_driver calxeda_cpuidle_plat_driver = {
78 .driver = {
79 .name = "cpuidle-calxeda",
Daniel Lezcano60a66e32013-09-27 12:47:45 +020080 },
81 .probe = calxeda_cpuidle_probe,
82};
Paul Gortmaker090d1cf2015-05-01 20:10:57 -040083builtin_platform_driver(calxeda_cpuidle_plat_driver);