2 * MMP2 Power Management Routines
4 * This software program is licensed subject to the GNU General Public License
5 * (GPL).Version 2,June 1991, available at http://www.fsf.org/copyleft/gpl.html
7 * (C) Copyright 2012 Marvell International Ltd.
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/err.h>
14 #include <linux/time.h>
15 #include <linux/delay.h>
16 #include <linux/suspend.h>
17 #include <linux/irq.h>
19 #include <linux/interrupt.h>
20 #include <asm/mach-types.h>
28 int mmp2_set_wake(struct irq_data
*d
, unsigned int on
)
30 unsigned long data
= 0;
33 /* enable wakeup sources */
36 case IRQ_MMP2_RTC_ALARM
:
37 data
= MPMU_WUCRM_PJ_WAKEUP(4) | MPMU_WUCRM_PJ_RTC_ALARM
;
40 data
= MPMU_WUCRM_PJ_WAKEUP(7);
43 /* mmc use WAKEUP2, same as GPIO wakeup source */
44 data
= MPMU_WUCRM_PJ_WAKEUP(2);
49 data
|= __raw_readl(MPMU_WUCRM_PJ
);
50 __raw_writel(data
, MPMU_WUCRM_PJ
);
54 data
= ~data
& __raw_readl(MPMU_WUCRM_PJ
);
55 __raw_writel(data
, MPMU_WUCRM_PJ
);
61 static void pm_scu_clk_disable(void)
65 /* close AXI fabric clock gate */
66 __raw_writel(0x0, CIU_REG(0x64));
67 __raw_writel(0x0, CIU_REG(0x68));
69 /* close MCB master clock gate */
70 val
= __raw_readl(CIU_REG(0x1c));
72 __raw_writel(val
, CIU_REG(0x1c));
77 static void pm_scu_clk_enable(void)
81 /* open AXI fabric clock gate */
82 __raw_writel(0x03003003, CIU_REG(0x64));
83 __raw_writel(0x00303030, CIU_REG(0x68));
85 /* open MCB master clock gate */
86 val
= __raw_readl(CIU_REG(0x1c));
88 __raw_writel(val
, CIU_REG(0x1c));
93 static void pm_mpmu_clk_disable(void)
96 * disable clocks in MPMU_CGR_PJ register
97 * except clock for APMU_PLL1, APMU_PLL1_2 and AP_26M
99 __raw_writel(0x0000a010, MPMU_CGR_PJ
);
102 static void pm_mpmu_clk_enable(void)
106 __raw_writel(0xdffefffe, MPMU_CGR_PJ
);
107 val
= __raw_readl(MPMU_PLL2_CTRL1
);
109 __raw_writel(val
, MPMU_PLL2_CTRL1
);
114 void mmp2_pm_enter_lowpower_mode(int state
)
116 uint32_t idle_cfg
, apcr
;
118 idle_cfg
= __raw_readl(APMU_PJ_IDLE_CFG
);
119 apcr
= __raw_readl(MPMU_PCR_PJ
);
120 apcr
&= ~(MPMU_PCR_PJ_SLPEN
| MPMU_PCR_PJ_DDRCORSD
| MPMU_PCR_PJ_APBSD
121 | MPMU_PCR_PJ_AXISD
| MPMU_PCR_PJ_VCTCXOSD
| (1 << 13));
122 idle_cfg
&= ~APMU_PJ_IDLE_CFG_PJ_IDLE
;
125 case POWER_MODE_SYS_SLEEP
:
126 apcr
|= MPMU_PCR_PJ_SLPEN
; /* set the SLPEN bit */
127 apcr
|= MPMU_PCR_PJ_VCTCXOSD
; /* set VCTCXOSD */
129 case POWER_MODE_CHIP_SLEEP
:
130 apcr
|= MPMU_PCR_PJ_SLPEN
;
132 case POWER_MODE_APPS_SLEEP
:
133 apcr
|= MPMU_PCR_PJ_APBSD
; /* set APBSD */
135 case POWER_MODE_APPS_IDLE
:
136 apcr
|= MPMU_PCR_PJ_AXISD
; /* set AXISDD bit */
137 apcr
|= MPMU_PCR_PJ_DDRCORSD
; /* set DDRCORSD bit */
138 idle_cfg
|= APMU_PJ_IDLE_CFG_PJ_PWRDWN
; /* PJ power down */
139 apcr
|= MPMU_PCR_PJ_SPSD
;
141 case POWER_MODE_CORE_EXTIDLE
:
142 idle_cfg
|= APMU_PJ_IDLE_CFG_PJ_IDLE
; /* set the IDLE bit */
143 idle_cfg
&= ~APMU_PJ_IDLE_CFG_ISO_MODE_CNTRL_MASK
;
144 idle_cfg
|= APMU_PJ_IDLE_CFG_PWR_SW(3)
145 | APMU_PJ_IDLE_CFG_L2_PWR_SW
;
147 case POWER_MODE_CORE_INTIDLE
:
148 apcr
&= ~MPMU_PCR_PJ_SPSD
;
152 /* set reserve bits */
153 apcr
|= (1 << 30) | (1 << 25);
155 /* finally write the registers back */
156 __raw_writel(idle_cfg
, APMU_PJ_IDLE_CFG
);
157 __raw_writel(apcr
, MPMU_PCR_PJ
); /* 0xfe086000 */
160 static int mmp2_pm_enter(suspend_state_t state
)
164 temp
= __raw_readl(MMP2_ICU_INT4_MASK
);
165 if (temp
& (1 << 1)) {
166 printk(KERN_ERR
"%s: PMIC interrupt is handling\n", __func__
);
170 temp
= __raw_readl(APMU_SRAM_PWR_DWN
);
171 temp
|= ((1 << 19) | (1 << 18));
172 __raw_writel(temp
, APMU_SRAM_PWR_DWN
);
173 pm_mpmu_clk_disable();
174 pm_scu_clk_disable();
176 printk(KERN_INFO
"%s: before suspend\n", __func__
);
178 printk(KERN_INFO
"%s: after suspend\n", __func__
);
180 pm_mpmu_clk_enable(); /* enable clocks in MPMU */
181 pm_scu_clk_enable(); /* enable clocks in SCU */
187 * Called after processes are frozen, but before we shut down devices.
189 static int mmp2_pm_prepare(void)
191 mmp2_pm_enter_lowpower_mode(POWER_MODE_SYS_SLEEP
);
197 * Called after devices are re-setup, but before processes are thawed.
199 static void mmp2_pm_finish(void)
201 mmp2_pm_enter_lowpower_mode(POWER_MODE_CORE_INTIDLE
);
204 static int mmp2_pm_valid(suspend_state_t state
)
206 return ((state
== PM_SUSPEND_STANDBY
) || (state
== PM_SUSPEND_MEM
));
210 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
212 static const struct platform_suspend_ops mmp2_pm_ops
= {
213 .valid
= mmp2_pm_valid
,
214 .prepare
= mmp2_pm_prepare
,
215 .enter
= mmp2_pm_enter
,
216 .finish
= mmp2_pm_finish
,
219 static int __init
mmp2_pm_init(void)
226 suspend_set_ops(&mmp2_pm_ops
);
229 * Set bit 0, Slow clock Select 32K clock input instead of VCXO
230 * VCXO is chosen by default, which would be disabled in suspend
232 __raw_writel(0x5, MPMU_SCCR
);
235 * Clear bit 23 of CIU_CPU_CONF
236 * direct PJ4 to DDR access through Memory Controller slow queue
237 * fast queue has issue and cause lcd will flick
239 __raw_writel(__raw_readl(CIU_REG(0x8)) & ~(0x1 << 23), CIU_REG(0x8));
241 /* Clear default low power control bit */
242 apcr
= __raw_readl(MPMU_PCR_PJ
);
243 apcr
&= ~(MPMU_PCR_PJ_SLPEN
| MPMU_PCR_PJ_DDRCORSD
244 | MPMU_PCR_PJ_APBSD
| MPMU_PCR_PJ_AXISD
| 1 << 13);
245 __raw_writel(apcr
, MPMU_PCR_PJ
);
250 late_initcall(mmp2_pm_init
);