Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 1 | /* |
| 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> |
Shawn Guo | 41e7daf | 2011-09-28 17:16:06 +0800 | [diff] [blame] | 17 | #include <mach/common.h> |
| 18 | #include <mach/hardware.h> |
Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 19 | #include "crm_regs.h" |
| 20 | |
| 21 | static struct clk *gpc_dvfs_clk; |
| 22 | |
Arnaud Patard (Rtp) | 100aafc | 2011-08-27 15:21:12 +0200 | [diff] [blame] | 23 | static int mx5_suspend_prepare(void) |
| 24 | { |
| 25 | return clk_enable(gpc_dvfs_clk); |
| 26 | } |
| 27 | |
Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 28 | static int mx5_suspend_enter(suspend_state_t state) |
| 29 | { |
Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 30 | switch (state) { |
| 31 | case PM_SUSPEND_MEM: |
| 32 | mx5_cpu_lp_set(STOP_POWER_OFF); |
| 33 | break; |
| 34 | case PM_SUSPEND_STANDBY: |
| 35 | mx5_cpu_lp_set(WAIT_UNCLOCKED_POWER_OFF); |
| 36 | break; |
| 37 | default: |
| 38 | return -EINVAL; |
| 39 | } |
| 40 | |
| 41 | if (state == PM_SUSPEND_MEM) { |
| 42 | local_flush_tlb_all(); |
| 43 | flush_cache_all(); |
| 44 | |
| 45 | /*clear the EMPGC0/1 bits */ |
| 46 | __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR); |
| 47 | __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR); |
| 48 | } |
| 49 | cpu_do_idle(); |
Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 50 | return 0; |
| 51 | } |
| 52 | |
Arnaud Patard (Rtp) | 100aafc | 2011-08-27 15:21:12 +0200 | [diff] [blame] | 53 | static void mx5_suspend_finish(void) |
| 54 | { |
| 55 | clk_disable(gpc_dvfs_clk); |
| 56 | } |
| 57 | |
Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 58 | static int mx5_pm_valid(suspend_state_t state) |
| 59 | { |
| 60 | return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX); |
| 61 | } |
| 62 | |
| 63 | static const struct platform_suspend_ops mx5_suspend_ops = { |
| 64 | .valid = mx5_pm_valid, |
Arnaud Patard (Rtp) | 100aafc | 2011-08-27 15:21:12 +0200 | [diff] [blame] | 65 | .prepare = mx5_suspend_prepare, |
Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 66 | .enter = mx5_suspend_enter, |
Arnaud Patard (Rtp) | 100aafc | 2011-08-27 15:21:12 +0200 | [diff] [blame] | 67 | .finish = mx5_suspend_finish, |
Dinh Nguyen | f9e9fc2 | 2011-03-28 10:14:57 -0500 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | static int __init mx5_pm_init(void) |
| 71 | { |
| 72 | if (gpc_dvfs_clk == NULL) |
| 73 | gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs"); |
| 74 | |
| 75 | if (!IS_ERR(gpc_dvfs_clk)) { |
| 76 | if (cpu_is_mx51()) |
| 77 | suspend_set_ops(&mx5_suspend_ops); |
| 78 | } else |
| 79 | return -EPERM; |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | device_initcall(mx5_pm_init); |