Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [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> |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 16 | #include <asm/system_misc.h> |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 17 | #include <asm/tlbflush.h> |
| 18 | #include <mach/common.h> |
| 19 | #include <mach/hardware.h> |
| 20 | #include "crm-regs-imx5.h" |
| 21 | |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 22 | /* |
| 23 | * The WAIT_UNCLOCKED_POWER_OFF state only requires <= 500ns to exit. |
| 24 | * This is also the lowest power state possible without affecting |
| 25 | * non-cpu parts of the system. For these reasons, imx5 should default |
| 26 | * to always using this state for cpu idling. The PM_SUSPEND_STANDBY also |
| 27 | * uses this state and needs to take no action when registers remain confgiured |
| 28 | * for this state. |
| 29 | */ |
| 30 | #define IMX5_DEFAULT_CPU_IDLE_STATE WAIT_UNCLOCKED_POWER_OFF |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * set cpu low power mode before WFI instruction. This function is called |
| 34 | * mx5 because it can be used for mx50, mx51, and mx53. |
| 35 | */ |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 36 | static void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode) |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 37 | { |
| 38 | u32 plat_lpc, arm_srpgcr, ccm_clpcr; |
| 39 | u32 empgc0, empgc1; |
| 40 | int stop_mode = 0; |
| 41 | |
| 42 | /* always allow platform to issue a deep sleep mode request */ |
| 43 | plat_lpc = __raw_readl(MXC_CORTEXA8_PLAT_LPC) & |
| 44 | ~(MXC_CORTEXA8_PLAT_LPC_DSM); |
| 45 | ccm_clpcr = __raw_readl(MXC_CCM_CLPCR) & ~(MXC_CCM_CLPCR_LPM_MASK); |
| 46 | arm_srpgcr = __raw_readl(MXC_SRPG_ARM_SRPGCR) & ~(MXC_SRPGCR_PCR); |
| 47 | empgc0 = __raw_readl(MXC_SRPG_EMPGC0_SRPGCR) & ~(MXC_SRPGCR_PCR); |
| 48 | empgc1 = __raw_readl(MXC_SRPG_EMPGC1_SRPGCR) & ~(MXC_SRPGCR_PCR); |
| 49 | |
| 50 | switch (mode) { |
| 51 | case WAIT_CLOCKED: |
| 52 | break; |
| 53 | case WAIT_UNCLOCKED: |
| 54 | ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET; |
| 55 | break; |
| 56 | case WAIT_UNCLOCKED_POWER_OFF: |
| 57 | case STOP_POWER_OFF: |
| 58 | plat_lpc |= MXC_CORTEXA8_PLAT_LPC_DSM |
| 59 | | MXC_CORTEXA8_PLAT_LPC_DBG_DSM; |
| 60 | if (mode == WAIT_UNCLOCKED_POWER_OFF) { |
| 61 | ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET; |
| 62 | ccm_clpcr &= ~MXC_CCM_CLPCR_VSTBY; |
| 63 | ccm_clpcr &= ~MXC_CCM_CLPCR_SBYOS; |
| 64 | stop_mode = 0; |
| 65 | } else { |
| 66 | ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET; |
| 67 | ccm_clpcr |= 0x3 << MXC_CCM_CLPCR_STBY_COUNT_OFFSET; |
| 68 | ccm_clpcr |= MXC_CCM_CLPCR_VSTBY; |
| 69 | ccm_clpcr |= MXC_CCM_CLPCR_SBYOS; |
| 70 | stop_mode = 1; |
| 71 | } |
| 72 | arm_srpgcr |= MXC_SRPGCR_PCR; |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 73 | break; |
| 74 | case STOP_POWER_ON: |
| 75 | ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET; |
| 76 | break; |
| 77 | default: |
| 78 | printk(KERN_WARNING "UNKNOWN cpu power mode: %d\n", mode); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | __raw_writel(plat_lpc, MXC_CORTEXA8_PLAT_LPC); |
| 83 | __raw_writel(ccm_clpcr, MXC_CCM_CLPCR); |
| 84 | __raw_writel(arm_srpgcr, MXC_SRPG_ARM_SRPGCR); |
| 85 | |
| 86 | /* Enable NEON SRPG for all but MX50TO1.0. */ |
| 87 | if (mx50_revision() != IMX_CHIP_REVISION_1_0) |
| 88 | __raw_writel(arm_srpgcr, MXC_SRPG_NEON_SRPGCR); |
| 89 | |
| 90 | if (stop_mode) { |
| 91 | empgc0 |= MXC_SRPGCR_PCR; |
| 92 | empgc1 |= MXC_SRPGCR_PCR; |
| 93 | |
| 94 | __raw_writel(empgc0, MXC_SRPG_EMPGC0_SRPGCR); |
| 95 | __raw_writel(empgc1, MXC_SRPG_EMPGC1_SRPGCR); |
| 96 | } |
| 97 | } |
| 98 | |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 99 | static int mx5_suspend_enter(suspend_state_t state) |
| 100 | { |
| 101 | switch (state) { |
| 102 | case PM_SUSPEND_MEM: |
| 103 | mx5_cpu_lp_set(STOP_POWER_OFF); |
| 104 | break; |
| 105 | case PM_SUSPEND_STANDBY: |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 106 | /* DEFAULT_IDLE_STATE already configured */ |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 107 | break; |
| 108 | default: |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | |
| 112 | if (state == PM_SUSPEND_MEM) { |
| 113 | local_flush_tlb_all(); |
| 114 | flush_cache_all(); |
| 115 | |
| 116 | /*clear the EMPGC0/1 bits */ |
| 117 | __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR); |
| 118 | __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR); |
| 119 | } |
| 120 | cpu_do_idle(); |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 121 | |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 122 | /* return registers to default idle state */ |
| 123 | mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE); |
| 124 | return 0; |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static int mx5_pm_valid(suspend_state_t state) |
| 128 | { |
| 129 | return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX); |
| 130 | } |
| 131 | |
| 132 | static const struct platform_suspend_ops mx5_suspend_ops = { |
| 133 | .valid = mx5_pm_valid, |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 134 | .enter = mx5_suspend_enter, |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 135 | }; |
| 136 | |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 137 | static void imx5_pm_idle(void) |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 138 | { |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 139 | if (likely(!tzic_enable_wake())) |
| 140 | cpu_do_idle(); |
| 141 | } |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 142 | |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 143 | static int __init imx5_pm_common_init(void) |
| 144 | { |
| 145 | int ret; |
| 146 | struct clk *gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs"); |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 147 | |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 148 | if (IS_ERR(gpc_dvfs_clk)) |
| 149 | return PTR_ERR(gpc_dvfs_clk); |
| 150 | |
| 151 | ret = clk_prepare_enable(gpc_dvfs_clk); |
| 152 | if (ret) |
| 153 | return ret; |
| 154 | |
| 155 | arm_pm_idle = imx5_pm_idle; |
| 156 | |
| 157 | /* Set the registers to the default cpu idle state. */ |
| 158 | mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE); |
Sascha Hauer | 784a90c | 2011-11-07 12:36:48 +0100 | [diff] [blame] | 159 | |
| 160 | return 0; |
| 161 | } |
Robert Lee | 565fa91 | 2012-05-21 17:50:26 -0500 | [diff] [blame^] | 162 | |
| 163 | void __init imx51_pm_init(void) |
| 164 | { |
| 165 | int ret = imx5_pm_common_init(); |
| 166 | if (!ret) |
| 167 | suspend_set_ops(&mx5_suspend_ops); |
| 168 | } |