1 // SPDX-License-Identifier: GPL-2.0-only
3 * MMP2 Power Management Routines
5 * (C) Copyright 2012 Marvell International Ltd.
9 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/err.h>
12 #include <linux/time.h>
13 #include <linux/delay.h>
14 #include <linux/suspend.h>
15 #include <linux/irq.h>
17 #include <linux/interrupt.h>
18 #include <asm/mach-types.h>
20 #include <linux/soc/mmp/cputype.h>
26 int mmp2_set_wake(struct irq_data
*d
, unsigned int on
)
28 unsigned long data
= 0;
31 /* enable wakeup sources */
34 case IRQ_MMP2_RTC_ALARM
:
35 data
= MPMU_WUCRM_PJ_WAKEUP(4) | MPMU_WUCRM_PJ_RTC_ALARM
;
38 data
= MPMU_WUCRM_PJ_WAKEUP(7);
41 /* mmc use WAKEUP2, same as GPIO wakeup source */
42 data
= MPMU_WUCRM_PJ_WAKEUP(2);
47 data
|= __raw_readl(MPMU_WUCRM_PJ
);
48 __raw_writel(data
, MPMU_WUCRM_PJ
);
52 data
= ~data
& __raw_readl(MPMU_WUCRM_PJ
);
53 __raw_writel(data
, MPMU_WUCRM_PJ
);
59 static void pm_scu_clk_disable(void)
63 /* close AXI fabric clock gate */
64 __raw_writel(0x0, CIU_REG(0x64));
65 __raw_writel(0x0, CIU_REG(0x68));
67 /* close MCB master clock gate */
68 val
= __raw_readl(CIU_REG(0x1c));
70 __raw_writel(val
, CIU_REG(0x1c));
75 static void pm_scu_clk_enable(void)
79 /* open AXI fabric clock gate */
80 __raw_writel(0x03003003, CIU_REG(0x64));
81 __raw_writel(0x00303030, CIU_REG(0x68));
83 /* open MCB master clock gate */
84 val
= __raw_readl(CIU_REG(0x1c));
86 __raw_writel(val
, CIU_REG(0x1c));
91 static void pm_mpmu_clk_disable(void)
94 * disable clocks in MPMU_CGR_PJ register
95 * except clock for APMU_PLL1, APMU_PLL1_2 and AP_26M
97 __raw_writel(0x0000a010, MPMU_CGR_PJ
);
100 static void pm_mpmu_clk_enable(void)
104 __raw_writel(0xdffefffe, MPMU_CGR_PJ
);
105 val
= __raw_readl(MPMU_PLL2_CTRL1
);
107 __raw_writel(val
, MPMU_PLL2_CTRL1
);
112 void mmp2_pm_enter_lowpower_mode(int state
)
114 uint32_t idle_cfg
, apcr
;
116 idle_cfg
= __raw_readl(APMU_PJ_IDLE_CFG
);
117 apcr
= __raw_readl(MPMU_PCR_PJ
);
118 apcr
&= ~(MPMU_PCR_PJ_SLPEN
| MPMU_PCR_PJ_DDRCORSD
| MPMU_PCR_PJ_APBSD
119 | MPMU_PCR_PJ_AXISD
| MPMU_PCR_PJ_VCTCXOSD
| (1 << 13));
120 idle_cfg
&= ~APMU_PJ_IDLE_CFG_PJ_IDLE
;
123 case POWER_MODE_SYS_SLEEP
:
124 apcr
|= MPMU_PCR_PJ_SLPEN
; /* set the SLPEN bit */
125 apcr
|= MPMU_PCR_PJ_VCTCXOSD
; /* set VCTCXOSD */
127 case POWER_MODE_CHIP_SLEEP
:
128 apcr
|= MPMU_PCR_PJ_SLPEN
;
130 case POWER_MODE_APPS_SLEEP
:
131 apcr
|= MPMU_PCR_PJ_APBSD
; /* set APBSD */
133 case POWER_MODE_APPS_IDLE
:
134 apcr
|= MPMU_PCR_PJ_AXISD
; /* set AXISDD bit */
135 apcr
|= MPMU_PCR_PJ_DDRCORSD
; /* set DDRCORSD bit */
136 idle_cfg
|= APMU_PJ_IDLE_CFG_PJ_PWRDWN
; /* PJ power down */
137 apcr
|= MPMU_PCR_PJ_SPSD
;
139 case POWER_MODE_CORE_EXTIDLE
:
140 idle_cfg
|= APMU_PJ_IDLE_CFG_PJ_IDLE
; /* set the IDLE bit */
141 idle_cfg
&= ~APMU_PJ_IDLE_CFG_ISO_MODE_CNTRL_MASK
;
142 idle_cfg
|= APMU_PJ_IDLE_CFG_PWR_SW(3)
143 | APMU_PJ_IDLE_CFG_L2_PWR_SW
;
145 case POWER_MODE_CORE_INTIDLE
:
146 apcr
&= ~MPMU_PCR_PJ_SPSD
;
150 /* set reserve bits */
151 apcr
|= (1 << 30) | (1 << 25);
153 /* finally write the registers back */
154 __raw_writel(idle_cfg
, APMU_PJ_IDLE_CFG
);
155 __raw_writel(apcr
, MPMU_PCR_PJ
); /* 0xfe086000 */
158 static int mmp2_pm_enter(suspend_state_t state
)
162 temp
= __raw_readl(MMP2_ICU_INT4_MASK
);
163 if (temp
& (1 << 1)) {
164 printk(KERN_ERR
"%s: PMIC interrupt is handling\n", __func__
);
168 temp
= __raw_readl(APMU_SRAM_PWR_DWN
);
169 temp
|= ((1 << 19) | (1 << 18));
170 __raw_writel(temp
, APMU_SRAM_PWR_DWN
);
171 pm_mpmu_clk_disable();
172 pm_scu_clk_disable();
174 printk(KERN_INFO
"%s: before suspend\n", __func__
);
176 printk(KERN_INFO
"%s: after suspend\n", __func__
);
178 pm_mpmu_clk_enable(); /* enable clocks in MPMU */
179 pm_scu_clk_enable(); /* enable clocks in SCU */
185 * Called after processes are frozen, but before we shut down devices.
187 static int mmp2_pm_prepare(void)
189 mmp2_pm_enter_lowpower_mode(POWER_MODE_SYS_SLEEP
);
195 * Called after devices are re-setup, but before processes are thawed.
197 static void mmp2_pm_finish(void)
199 mmp2_pm_enter_lowpower_mode(POWER_MODE_CORE_INTIDLE
);
202 static int mmp2_pm_valid(suspend_state_t state
)
204 return ((state
== PM_SUSPEND_STANDBY
) || (state
== PM_SUSPEND_MEM
));
208 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
210 static const struct platform_suspend_ops mmp2_pm_ops
= {
211 .valid
= mmp2_pm_valid
,
212 .prepare
= mmp2_pm_prepare
,
213 .enter
= mmp2_pm_enter
,
214 .finish
= mmp2_pm_finish
,
217 static int __init
mmp2_pm_init(void)
224 suspend_set_ops(&mmp2_pm_ops
);
227 * Set bit 0, Slow clock Select 32K clock input instead of VCXO
228 * VCXO is chosen by default, which would be disabled in suspend
230 __raw_writel(0x5, MPMU_SCCR
);
233 * Clear bit 23 of CIU_CPU_CONF
234 * direct PJ4 to DDR access through Memory Controller slow queue
235 * fast queue has issue and cause lcd will flick
237 __raw_writel(__raw_readl(CIU_REG(0x8)) & ~(0x1 << 23), CIU_REG(0x8));
239 /* Clear default low power control bit */
240 apcr
= __raw_readl(MPMU_PCR_PJ
);
241 apcr
&= ~(MPMU_PCR_PJ_SLPEN
| MPMU_PCR_PJ_DDRCORSD
242 | MPMU_PCR_PJ_APBSD
| MPMU_PCR_PJ_AXISD
| 1 << 13);
243 __raw_writel(apcr
, MPMU_PCR_PJ
);
248 late_initcall(mmp2_pm_init
);