blob: be19e9ce839a7db8f0eaa151f4b1aea8a666642d [file] [log] [blame]
Dinh Nguyenf9e9fc22011-03-28 10:14:57 -05001/*
2 * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11#include <linux/suspend.h>
12#include <linux/clk.h>
13#include <linux/io.h>
14#include <linux/err.h>
15#include <asm/cacheflush.h>
16#include <asm/tlbflush.h>
17#include <mach/system.h>
18#include "crm_regs.h"
19
20static struct clk *gpc_dvfs_clk;
21
Arnaud Patard (Rtp)100aafc2011-08-27 15:21:12 +020022static int mx5_suspend_prepare(void)
23{
24 return clk_enable(gpc_dvfs_clk);
25}
26
Dinh Nguyenf9e9fc22011-03-28 10:14:57 -050027static int mx5_suspend_enter(suspend_state_t state)
28{
Dinh Nguyenf9e9fc22011-03-28 10:14:57 -050029 switch (state) {
30 case PM_SUSPEND_MEM:
31 mx5_cpu_lp_set(STOP_POWER_OFF);
32 break;
33 case PM_SUSPEND_STANDBY:
34 mx5_cpu_lp_set(WAIT_UNCLOCKED_POWER_OFF);
35 break;
36 default:
37 return -EINVAL;
38 }
39
40 if (state == PM_SUSPEND_MEM) {
41 local_flush_tlb_all();
42 flush_cache_all();
43
44 /*clear the EMPGC0/1 bits */
45 __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR);
46 __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR);
47 }
48 cpu_do_idle();
Dinh Nguyenf9e9fc22011-03-28 10:14:57 -050049 return 0;
50}
51
Arnaud Patard (Rtp)100aafc2011-08-27 15:21:12 +020052static void mx5_suspend_finish(void)
53{
54 clk_disable(gpc_dvfs_clk);
55}
56
Dinh Nguyenf9e9fc22011-03-28 10:14:57 -050057static int mx5_pm_valid(suspend_state_t state)
58{
59 return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX);
60}
61
62static const struct platform_suspend_ops mx5_suspend_ops = {
63 .valid = mx5_pm_valid,
Arnaud Patard (Rtp)100aafc2011-08-27 15:21:12 +020064 .prepare = mx5_suspend_prepare,
Dinh Nguyenf9e9fc22011-03-28 10:14:57 -050065 .enter = mx5_suspend_enter,
Arnaud Patard (Rtp)100aafc2011-08-27 15:21:12 +020066 .finish = mx5_suspend_finish,
Dinh Nguyenf9e9fc22011-03-28 10:14:57 -050067};
68
69static int __init mx5_pm_init(void)
70{
71 if (gpc_dvfs_clk == NULL)
72 gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs");
73
74 if (!IS_ERR(gpc_dvfs_clk)) {
75 if (cpu_is_mx51())
76 suspend_set_ops(&mx5_suspend_ops);
77 } else
78 return -EPERM;
79
80 return 0;
81}
82device_initcall(mx5_pm_init);