blob: b17d9a8418b0cd1772c376c4569dd38e803053ac [file] [log] [blame]
Thomas Gleixner9952f692019-05-28 10:10:04 -07001// SPDX-License-Identifier: GPL-2.0-only
Rob Herringbe6a98d2012-10-12 12:45:34 -05002/*
3 * Copyright 2012 Calxeda, Inc.
4 *
Daniel Lezcanoa8e39c32013-04-26 11:05:44 +00005 * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7
Rob Herringbe6a98d2012-10-12 12:45:34 -05006 * Copyright 2012 Freescale Semiconductor, Inc.
7 * Copyright 2012 Linaro Ltd.
8 *
Daniel Lezcanoa8e39c32013-04-26 11:05:44 +00009 * Maintainer: Rob Herring <rob.herring@calxeda.com>
Rob Herringbe6a98d2012-10-12 12:45:34 -050010 */
11
12#include <linux/cpuidle.h>
Rob Herring34a5eeb2013-02-26 16:16:53 -060013#include <linux/cpu_pm.h>
Rob Herringbe6a98d2012-10-12 12:45:34 -050014#include <linux/init.h>
Rob Herringa4101462013-02-26 16:05:46 -060015#include <linux/mm.h>
Daniel Lezcano60a66e32013-09-27 12:47:45 +020016#include <linux/platform_device.h>
Mark Rutlandbe120392015-07-31 15:46:19 +010017#include <linux/psci.h>
18
Rob Herringbe6a98d2012-10-12 12:45:34 -050019#include <asm/cpuidle.h>
Rob Herringbe6a98d2012-10-12 12:45:34 -050020#include <asm/suspend.h>
Mark Rutlandbe120392015-07-31 15:46:19 +010021
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 Herringbe6a98d2012-10-12 12:45:34 -050028
29static int calxeda_idle_finish(unsigned long val)
30{
Mark Rutlandbe120392015-07-31 15:46:19 +010031 return psci_ops.cpu_suspend(CALXEDA_IDLE_PARAM, __pa(cpu_resume));
Rob Herringbe6a98d2012-10-12 12:45:34 -050032}
33
34static int calxeda_pwrdown_idle(struct cpuidle_device *dev,
35 struct cpuidle_driver *drv,
36 int index)
37{
Rob Herring34a5eeb2013-02-26 16:16:53 -060038 cpu_pm_enter();
Rob Herringbe6a98d2012-10-12 12:45:34 -050039 cpu_suspend(0, calxeda_idle_finish);
Rob Herring34a5eeb2013-02-26 16:16:53 -060040 cpu_pm_exit();
41
Rob Herringbe6a98d2012-10-12 12:45:34 -050042 return index;
43}
44
Rob Herringbe6a98d2012-10-12 12:45:34 -050045static struct cpuidle_driver calxeda_idle_driver = {
46 .name = "calxeda_idle",
Rob Herringbe6a98d2012-10-12 12:45:34 -050047 .states = {
48 ARM_CPUIDLE_WFI_STATE,
49 {
50 .name = "PG",
51 .desc = "Power Gate",
Rob Herringbe6a98d2012-10-12 12:45:34 -050052 .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 Przywara57815322013-12-13 21:49:19 +010061static int calxeda_cpuidle_probe(struct platform_device *pdev)
Rob Herringbe6a98d2012-10-12 12:45:34 -050062{
Daniel Lezcano0b210d92013-04-23 08:54:42 +000063 return cpuidle_register(&calxeda_idle_driver, NULL);
Rob Herringbe6a98d2012-10-12 12:45:34 -050064}
Daniel Lezcano60a66e32013-09-27 12:47:45 +020065
66static struct platform_driver calxeda_cpuidle_plat_driver = {
67 .driver = {
68 .name = "cpuidle-calxeda",
Daniel Lezcano60a66e32013-09-27 12:47:45 +020069 },
70 .probe = calxeda_cpuidle_probe,
71};
Paul Gortmaker090d1cf2015-05-01 20:10:57 -040072builtin_platform_driver(calxeda_cpuidle_plat_driver);