Skip to contentSkip to conversation

ARM: imx: add suspend in ocram support for i.mx6q

PATCH Superseded Anson Huang 3 participants 5 messages Jan 14, 2014 – Jan 15, 2014

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/3 ARM: imx: add suspend in ocram support for i.mx6q

When system enter suspend, we can set the DDR IO to high-Z state to save DDR IOs' power consumption, this operation can save many power(from ~26mA at 1.5V to ~15mA at 1.5V, measured on i.MX6Q SabreSD board, R25) of DDR IOs. To achieve that, we need to copy the suspend code to ocram and run the low level hardware related code(set DDR IOs to high-Z state) in ocram.

If there is no ocram space available, then system will still do suspend in external DDR, hence no DDR IOs will be set to high-Z.

The OCRAM usage layout is as below,

ocram suspend region(4K currently):
======================== high address ======================

                              .
                              .
                              .
                              ^
                              ^
                              ^
                      imx6_suspend code
      reserved space(to make imx6_suspend aligned with 8)
             PM_INFO structure(imx6_cpu_pm_info)

======================== low address =======================

---
Changes since V4:
1. Create socdata to pass cpu type, mmdc io num, mmdc offset and compatible name for each soc, so that we can avoid cpu type check and dts change;
2. Improve asm code function declaration to avoid cast.

 arch/arm/mach-imx/Makefile       |    3 +-
 arch/arm/mach-imx/common.h       |    8 +-
 arch/arm/mach-imx/hardware.h     |    4 +-
 arch/arm/mach-imx/mach-imx6q.c   |    2 +-
 arch/arm/mach-imx/mach-imx6sl.c  |    3 +-
 arch/arm/mach-imx/pm-imx6q.c     |  280 ++++++++++++++++++++++++++++++++++-
 arch/arm/mach-imx/suspend-imx6.S |  303 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 592 insertions(+), 11 deletions(-)
 create mode 100644 arch/arm/mach-imx/suspend-imx6.S
arch/arm/mach-imx/Makefile +2 -1
index befcaf5..3d96a45 100644
@@ -102,7 +102,8 @@ obj-$(CONFIG_SOC_IMX6Q) += clk-imx6q.o mach-imx6q.o
 obj-$(CONFIG_SOC_IMX6SL) += clk-imx6sl.o mach-imx6sl.o
 
 ifeq ($(CONFIG_PM),y)
-obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o headsmp.o
+AFLAGS_suspend-imx6.o :=-Wa,-march=armv7-a
+obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o headsmp.o suspend-imx6.o
 # i.MX6SL reuses i.MX6Q code
 obj-$(CONFIG_SOC_IMX6SL) += pm-imx6q.o headsmp.o
 endif
arch/arm/mach-imx/common.h +7 -1
index 4f4a95c..a363e71 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2013 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2004-2014 Freescale Semiconductor, Inc. All Rights Reserved.
  */
 
 /*
@@ -145,11 +145,17 @@ void imx_cpu_die(unsigned int cpu);
 int imx_cpu_kill(unsigned int cpu);
 
 #ifdef CONFIG_PM
+void imx6_suspend(void __iomem *ocram_vbase);
 void imx6q_pm_init(void);
+void imx6dl_pm_init(void);
+void imx6sl_pm_init(void);
 void imx6q_pm_set_ccm_base(void __iomem *base);
 void imx5_pm_init(void);
 #else
+static inline void imx6_suspend(void __iomem *ocram_vbase) {}
 static inline void imx6q_pm_init(void) {}
+static inline void imx6dl_pm_init(void) {}
+static inline void imx6sl_pm_init(void) {}
 static inline void imx6q_pm_set_ccm_base(void __iomem *base) {}
 static inline void imx5_pm_init(void) {}
 #endif
arch/arm/mach-imx/hardware.h +3 -1
index a3b0b04..abf43bb 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2004-2007, 2014 Freescale Semiconductor, Inc. All Rights Reserved.
  * Copyright 2008 Juergen Beisert, kernel at pengutronix.de
  *
  * This program is free software; you can redistribute it and/or
@@ -20,7 +20,9 @@
 #ifndef __ASM_ARCH_MXC_HARDWARE_H__
 #define __ASM_ARCH_MXC_HARDWARE_H__
 
+#ifndef __ASSEMBLY__
 #include <asm/io.h>
+#endif
 #include <asm/sizes.h>
 
 #define addr_in_module(addr, mod) \
arch/arm/mach-imx/mach-imx6q.c +1 -1
index e51e3da..e629593 100644
@@ -212,7 +212,7 @@ static void __init imx6q_init_machine(void)
 	of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
 
 	imx_anatop_init();
-	imx6q_pm_init();
+	cpu_is_imx6q() ?  imx6q_pm_init() : imx6dl_pm_init();
 	imx6q_1588_init();
 }
 
arch/arm/mach-imx/mach-imx6sl.c +1 -2
index 0f4fd4c..aa873d8 100644
@@ -55,8 +55,7 @@ static void __init imx6sl_init_machine(void)
 
 	imx6sl_fec_init();
 	imx_anatop_init();
-	/* Reuse imx6q pm code */
-	imx6q_pm_init();
+	imx6sl_pm_init();
 }
 
 static void __init imx6sl_init_irq(void)
arch/arm/mach-imx/pm-imx6q.c +275 -5

332 lines not on this page · raw message

arch/arm/mach-imx/suspend-imx6.S new file +303 -0

303 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v5 2/3 ARM: imx: add suspend in ocram support for i.mx6dl

i.MX6DL's suspend in ocram function is derived from i.MX6Q, it can lower the DDR IO power from ~26mA at 1.5V to ~15mA at 1.5V, measured on i.MX6DL SabreSD board, R25.

---
 arch/arm/mach-imx/pm-imx6q.c |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
arch/arm/mach-imx/pm-imx6q.c +21 -1
index fb18de7..daf177d 100644
@@ -118,6 +118,26 @@ static const struct imx6_pm_socdata imx6q_pm_data __initconst = {
 	},
 };
 
+static const struct imx6_pm_socdata imx6dl_pm_data __initconst = {
+	.cpu_type = MXC_CPU_IMX6DL,
+	.mmdc_compat = "fsl,imx6q-mmdc",
+	.src_compat = "fsl,imx6q-src",
+	.iomuxc_compat = "fsl,imx6dl-iomuxc",
+	.gpc_compat = "fsl,imx6q-gpc",
+	.mmdc_io_num = 33,
+	.mmdc_io_offset = {
+		0x470, 0x474, 0x478, 0x47c, /* DQM0 ~ DQM3 */
+		0x480, 0x484, 0x488, 0x48c, /* DQM4 ~ DQM7 */
+		0x464, 0x490, 0x4ac, 0x4b0, /* CAS, RAS, SDCLK_0, SDCLK_1 */
+		0x4bc, 0x4c0, 0x4c4, 0x4c8, /* DRAM_SDQS0 ~ DRAM_SDQS3 */
+		0x4cc, 0x4d0, 0x4d4, 0x4d8, /* DRAM_SDQS4 ~ DRAM_SDQS7 */
+		0x764, 0x770, 0x778, 0x77c, /* GPR_B0DS ~ GPR_B3DS */
+		0x780, 0x784, 0x78c, 0x748, /* GPR_B4DS ~ GPR_B7DS */
+		0x4b4, 0x4b8, 0x750, 0x760, /* SODT0, SODT1, MODE_CTL, MODE */
+		0x74c,			    /* GPR_ADDS */
+	},
+};
+
 /*
  * This structure is for passing necessary data for low level ocram
  * suspend code(arch/arm/mach-imx/suspend-imx6.S), if this struct
@@ -504,7 +524,7 @@ void __init imx6q_pm_init(void)
 
 void __init imx6dl_pm_init(void)
 {
-	imx6_pm_common_init(NULL);
+	imx6_pm_common_init(&imx6dl_pm_data);
 }
 
 void __init imx6sl_pm_init(void)
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v5 3/3 ARM: imx: add suspend in ocram support for i.mx6sl

In reply to Anson Huang

i.MX6SL's suspend in ocram function is derived from i.MX6Q, it can lower the DDR IO power from ~10mA at 1.2V to ~1mA at 1.2V, measured on i.MX6SL EVK board, SH5.

---
 arch/arm/mach-imx/Makefile       |    2 +-
 arch/arm/mach-imx/pm-imx6q.c     |   18 +++++++++-
 arch/arm/mach-imx/suspend-imx6.S |   74 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 2 deletions(-)
arch/arm/mach-imx/Makefile +1 -1
index 3d96a45..f2df89f 100644
@@ -105,7 +105,7 @@ ifeq ($(CONFIG_PM),y)
 AFLAGS_suspend-imx6.o :=-Wa,-march=armv7-a
 obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o headsmp.o suspend-imx6.o
 # i.MX6SL reuses i.MX6Q code
-obj-$(CONFIG_SOC_IMX6SL) += pm-imx6q.o headsmp.o
+obj-$(CONFIG_SOC_IMX6SL) += pm-imx6q.o headsmp.o suspend-imx6.o
 endif
 
 # i.MX5 based machines
arch/arm/mach-imx/pm-imx6q.c +17 -1
index daf177d..ea7d518 100644
@@ -138,6 +138,22 @@ static const struct imx6_pm_socdata imx6dl_pm_data __initconst = {
 	},
 };
 
+static const struct imx6_pm_socdata imx6sl_pm_data __initconst = {
+	.cpu_type = MXC_CPU_IMX6SL,
+	.mmdc_compat = "fsl,imx6sl-mmdc",
+	.src_compat = "fsl,imx6sl-src",
+	.iomuxc_compat = "fsl,imx6sl-iomuxc",
+	.gpc_compat = "fsl,imx6sl-gpc",
+	.mmdc_io_num = 19,
+	.mmdc_io_offset = {
+		0x30c, 0x310, 0x314, 0x318, /* DQM0 ~ DQM3 */
+		0x5c4, 0x5cc, 0x5d4, 0x5d8, /* GPR_B0DS ~ GPR_B3DS */
+		0x300, 0x31c, 0x338, 0x5ac, /* CAS, RAS, SDCLK_0, GPR_ADDS */
+		0x33c, 0x340, 0x5b0, 0x5c0, /* SODT0, SODT1, MODE_CTL, MODE */
+		0x330, 0x334, 0x320,	    /* SDCKE0, SDCKE1, RESET */
+	},
+};
+
 /*
  * This structure is for passing necessary data for low level ocram
  * suspend code(arch/arm/mach-imx/suspend-imx6.S), if this struct
@@ -529,5 +545,5 @@ void __init imx6dl_pm_init(void)
 
 void __init imx6sl_pm_init(void)
 {
-	imx6_pm_common_init(NULL);
+	imx6_pm_common_init(&imx6sl_pm_data);
 }
arch/arm/mach-imx/suspend-imx6.S +74 -0

108 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v5 1/3 ARM: imx: add suspend in ocram support for i.mx6q

In reply to Anson Huang
Quoted 16 lines · Anson Huang

When system enter suspend, we can set the DDR IO to high-Z state to save DDR IOs' power consumption, this operation can save many power(from ~26mA at 1.5V to ~15mA at 1.5V, measured on i.MX6Q SabreSD board, R25) of DDR IOs. To achieve that, we need to copy the suspend code to ocram and run the low level hardware related code(set DDR IOs to high-Z state) in ocram.

If there is no ocram space available, then system will still do suspend in external DDR, hence no DDR IOs will be set to high-Z.

The OCRAM usage layout is as below,

ocram suspend region(4K currently):
======================== high address ======================

Quoted 8 lines
                              .
                              .
                              .
                              ^
                              ^
                              ^
                      imx6_suspend code
      reserved space(to make imx6_suspend aligned with 8)

We can remove this line now, right? Same for the comment in code.

Quoted 4 lines

PM_INFO structure(imx6_cpu_pm_info)
======================== low address =======================

<snip>

Quoted 48 lines
arch/arm/mach-imx/suspend-imx6.S new file +48 -0
+ENTRY(imx6_suspend)
+	ldr	r1, [r0, #PM_INFO_PBASE_OFFSET]
+	ldr	r2, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+	ldr	r3, [r0, #PM_INFO_CPU_TYPE_OFFSET]
+	ldr	r4, [r0, #PM_INFO_PM_INFO_SIZE_OFFSET]
+
+	/*
+	 * counting the resume address in iram
+	 * to set it in SRC register.
+	 */
+	ldr	r6, =imx6_suspend
+	ldr	r7, =resume
+	sub	r7, r7, r6
+	add	r8, r1, r4
+	add	r9, r8, r7
+
+	/*
+	 * make sure TLB contain the addr we want,
+	 * as we will access them after MMDC IO floated.
+	 */
+
+	ldr	r11, [r0, #PM_INFO_MX6Q_CCM_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+	ldr	r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+
+	/* use r11 to store the IO address */
+	ldr	r11, [r0, #PM_INFO_MX6Q_SRC_V_OFFSET]
+	/* store physical resume addr and pm_info address. */
+	str	r9, [r11, #MX6Q_SRC_GPR1]
+	str	r1, [r11, #MX6Q_SRC_GPR2]
+
+	/* need to sync L2 cache before DSM. */
+	sync_l2_cache
+
+	ldr	r11, [r0, #PM_INFO_MX6Q_MMDC_V_OFFSET]
+	/*
+	 * put DDR explicitly into self-refresh and
+	 * disable automatic power savings.
+	 */
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	orr	r7, r7, #0x1
+	str	r7, [r11, #MX6Q_MMDC_MAPSR]
+
+	/* make the DDR explicitly enter self-refresh. */
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	orr	r7, r7, #(1 << 21)
+	str	r7, [r11, #MX6Q_MMDC_MAPSR]

arch/arm/mach-imx/suspend-imx6.S line 146

Quoted 10 lines
arch/arm/mach-imx/suspend-imx6.S new file +10 -0
+
+poll_dvfs_set_1:
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	ands	r7, r7, #(1 << 25)
+	beq	poll_dvfs_set_1
+
+	ldr	r11, [r0, #PM_INFO_MX6Q_IOMUXC_V_OFFSET]
+	ldr	r6, =0x0
+	ldr	r7, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
+	ldr	r8, =PM_INFO_MMDC_IO_VAL_OFFSET

If we add the following instruction here

	add     r8, r0, r8

arch/arm/mach-imx/suspend-imx6.S line 148

Quoted 2 lines
arch/arm/mach-imx/suspend-imx6.S new file +2 -0
+set_mmdc_io_lpm:
+	ldr	r9, [r0, r8]

, it can be replaced by the following one

	ldr     r9, [r8], #0x8

arch/arm/mach-imx/suspend-imx6.S line 150

Quoted 2 lines
arch/arm/mach-imx/suspend-imx6.S new file +2 -0
+	str	r6, [r11, r9]
+	add	r8, r8, #0x8

, and then we can save this one in the loop, right?

arch/arm/mach-imx/suspend-imx6.S line 152

Quoted 2 lines
arch/arm/mach-imx/suspend-imx6.S new file +2 -0
+	sub	r7, r7, #0x1
+	cmp     r7, #0x0

The sequence of 'sub ...; cmp ..., #0' and 'and ...; cmp ..., #0' can generally be replaced by 'subs ...' and 'ands' respectively to save one instruction, right?

The above two comments apply to a few other places in the code.

Quoted 63 lines
arch/arm/mach-imx/suspend-imx6.S new file +63 -0
+	bne	set_mmdc_io_lpm
+
+	/*
+	 * mask all GPC interrupts before
+	 * enabling the RBC counters to
+	 * avoid the counter starting too
+	 * early if an interupt is already
+	 * pending.
+	 */
+	ldr	r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
+	ldr	r6, [r11, #MX6Q_GPC_IMR1]
+	ldr	r7, [r11, #MX6Q_GPC_IMR2]
+	ldr	r8, [r11, #MX6Q_GPC_IMR3]
+	ldr	r9, [r11, #MX6Q_GPC_IMR4]
+
+	ldr	r10, =0xffffffff
+	str	r10, [r11, #MX6Q_GPC_IMR1]
+	str	r10, [r11, #MX6Q_GPC_IMR2]
+	str	r10, [r11, #MX6Q_GPC_IMR3]
+	str	r10, [r11, #MX6Q_GPC_IMR4]
+
+	/*
+	 * enable the RBC bypass counter here
+	 * to hold off the interrupts. RBC counter
+	 * = 32 (1ms), Minimum RBC delay should be
+	 * 400us for the analog LDOs to power down.
+	 */
+	ldr	r11, [r0, #PM_INFO_MX6Q_CCM_V_OFFSET]
+	ldr	r10, [r11, #MX6Q_CCM_CCR]
+	bic	r10, r10, #(0x3f << 21)
+	orr	r10, r10, #(0x20 << 21)
+	str	r10, [r11, #MX6Q_CCM_CCR]
+
+	/* enable the counter. */
+	ldr	r10, [r11, #MX6Q_CCM_CCR]
+	orr	r10, r10, #(0x1 << 27)
+	str	r10, [r11, #MX6Q_CCM_CCR]
+
+	/* unmask all the GPC interrupts. */
+	ldr	r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
+	str	r6, [r11, #MX6Q_GPC_IMR1]
+	str	r7, [r11, #MX6Q_GPC_IMR2]
+	str	r8, [r11, #MX6Q_GPC_IMR3]
+	str	r9, [r11, #MX6Q_GPC_IMR4]
+
+	/*
+	 * now delay for a short while (3usec)
+	 * ARM is at 1GHz at this point
+	 * so a short loop should be enough.
+	 * this delay is required to ensure that
+	 * the RBC counter can start counting in
+	 * case an interrupt is already pending
+	 * or in case an interrupt arrives just
+	 * as ARM is about to assert DSM_request.
+	 */
+	ldr     r6, =2000
+rbc_loop:
+	sub     r6, r6, #0x1
+	cmp     r6, #0x0
+	bne     rbc_loop
+
+	/* Zzz, enter stop mode */
+	wfi

arch/arm/mach-imx/suspend-imx6.S line 225

Quoted 10 lines
arch/arm/mach-imx/suspend-imx6.S new file +10 -0
+	nop
+	nop
+	nop
+	nop
+
+	/*
+	 * run to here means there is pending
+	 * wakeup source, system should auto
+	 * resume, we need to restore MMDC IO first
+	 */

The MMDC restoring code looks identical between the case of wakeup source pending and the normal resume case, except that the former runs at virtual address and the later runs at the physical. Can we make a macro for it to save some code duplication?

Shawn

Quoted 82 lines
arch/arm/mach-imx/suspend-imx6.S new file +78 -0
+	ldr	r11, [r0, #PM_INFO_MX6Q_IOMUXC_V_OFFSET]
+	ldr	r6, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
+	ldr	r7, =PM_INFO_MMDC_IO_VAL_OFFSET
+restore_mmdc_io:
+	ldr	r8, [r0, r7]
+	add	r7, r7, #0x4
+	ldr	r9, [r0, r7]
+	add	r7, r7, #0x4
+	str	r9, [r11, r8]
+	sub	r6, r6, #0x1
+	cmp     r6, #0x0
+	bne	restore_mmdc_io
+
+	ldr	r11, [r0, #PM_INFO_MX6Q_MMDC_V_OFFSET]
+	/* let DDR out of self-refresh. */
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	bic	r7, r7, #(1 << 21)
+	str	r7, [r11, #MX6Q_MMDC_MAPSR]
+
+poll_dvfs_clear_2:
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	ands	r7, r7, #(1 << 25)
+	bne     poll_dvfs_clear_2
+	/* enable DDR auto power saving */
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	bic	r7, r7, #0x1
+	str	r7, [r11, #MX6Q_MMDC_MAPSR]
+	/* return to suspend finish */
+	mov	pc, lr
+
+resume:
+	/* invalidate L1 I-cache first */
+	mov     r6, #0x0
+	mcr     p15, 0, r6, c7, c5, 0
+	mcr     p15, 0, r6, c7, c5, 0
+	mcr     p15, 0, r6, c7, c5, 6
+	/* enable the Icache and branch prediction */
+	mov     r6, #0x1800
+	mcr     p15, 0, r6, c1, c0, 0
+	isb
+
+	/* get physical resume address from pm_info. */
+	ldr	lr, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+	/* clear core0's entry and parameter */
+	ldr	r11, [r0, #PM_INFO_MX6Q_SRC_P_OFFSET]
+	mov	r7, #0
+	str	r7, [r11, #MX6Q_SRC_GPR1]
+	str	r7, [r11, #MX6Q_SRC_GPR2]
+
+	ldr	r11, [r0, #PM_INFO_MX6Q_IOMUXC_P_OFFSET]
+	ldr	r6, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
+	ldr	r7, =PM_INFO_MMDC_IO_VAL_OFFSET
+dsm_restore_mmdc_io:
+	ldr	r8, [r0, r7]
+	add	r7, r7, #0x4
+	ldr	r9, [r0, r7]
+	add	r7, r7, #0x4
+	str	r9, [r11, r8]
+	sub	r6, r6, #0x1
+	cmp     r6, #0x0
+	bne	dsm_restore_mmdc_io
+
+	ldr	r11, [r0, #PM_INFO_MX6Q_MMDC_P_OFFSET]
+	/* let DDR out of self-refresh */
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	bic	r7, r7, #(1 << 21)
+	str	r7, [r11, #MX6Q_MMDC_MAPSR]
+
+poll_dvfs_clear_1:
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	ands	r7, r7, #(1 << 25)
+	bne	poll_dvfs_clear_1
+	/* enable DDR auto power saving */
+	ldr	r7, [r11, #MX6Q_MMDC_MAPSR]
+	bic	r7, r7, #0x1
+	str	r7, [r11, #MX6Q_MMDC_MAPSR]
+	mov	pc, lr
+ENDPROC(imx6_suspend)
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v5 1/3 ARM: imx: add suspend in ocram support for i.mx6q

Hi, Shawn
these comments should be applicable, will optimize this asm code in V6, thanks.

Sent from Anson's iPhone

Quoted 283 lines

? 2014?1?15??11:42?"Shawn Guo" <[email protected]> ???

Quoted 17 lines · Anson Huang

When system enter suspend, we can set the DDR IO to high-Z state to save DDR IOs' power consumption, this operation can save many power(from ~26mA at 1.5V to ~15mA at 1.5V, measured on i.MX6Q SabreSD board, R25) of DDR IOs. To achieve that, we need to copy the suspend code to ocram and run the low level hardware related code(set DDR IOs to high-Z state) in ocram.

If there is no ocram space available, then system will still do suspend in external DDR, hence no DDR IOs will be set to high-Z.

The OCRAM usage layout is as below,

ocram suspend region(4K currently):
======================== high address ======================

Quoted 8 lines
                             .
                             .
                             .
                             ^
                             ^
                             ^
                     imx6_suspend code
     reserved space(to make imx6_suspend aligned with 8)

We can remove this line now, right? Same for the comment in code.

Quoted 4 lines

PM_INFO structure(imx6_cpu_pm_info)
======================== low address =======================

<snip>

Quoted 48 lines
arch/arm/mach-imx/suspend-imx6.S new file +48 -0
+ENTRY(imx6_suspend)
+    ldr    r1, [r0, #PM_INFO_PBASE_OFFSET]
+    ldr    r2, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+    ldr    r3, [r0, #PM_INFO_CPU_TYPE_OFFSET]
+    ldr    r4, [r0, #PM_INFO_PM_INFO_SIZE_OFFSET]
+
+    /*
+     * counting the resume address in iram
+     * to set it in SRC register.
+     */
+    ldr    r6, =imx6_suspend
+    ldr    r7, =resume
+    sub    r7, r7, r6
+    add    r8, r1, r4
+    add    r9, r8, r7
+
+    /*
+     * make sure TLB contain the addr we want,
+     * as we will access them after MMDC IO floated.
+     */
+
+    ldr    r11, [r0, #PM_INFO_MX6Q_CCM_V_OFFSET]
+    ldr    r6, [r11, #0x0]
+    ldr    r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
+    ldr    r6, [r11, #0x0]
+
+    /* use r11 to store the IO address */
+    ldr    r11, [r0, #PM_INFO_MX6Q_SRC_V_OFFSET]
+    /* store physical resume addr and pm_info address. */
+    str    r9, [r11, #MX6Q_SRC_GPR1]
+    str    r1, [r11, #MX6Q_SRC_GPR2]
+
+    /* need to sync L2 cache before DSM. */
+    sync_l2_cache
+
+    ldr    r11, [r0, #PM_INFO_MX6Q_MMDC_V_OFFSET]
+    /*
+     * put DDR explicitly into self-refresh and
+     * disable automatic power savings.
+     */
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    orr    r7, r7, #0x1
+    str    r7, [r11, #MX6Q_MMDC_MAPSR]
+
+    /* make the DDR explicitly enter self-refresh. */
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    orr    r7, r7, #(1 << 21)
+    str    r7, [r11, #MX6Q_MMDC_MAPSR]

arch/arm/mach-imx/suspend-imx6.S line 146

Quoted 10 lines
arch/arm/mach-imx/suspend-imx6.S new file +10 -0
+
+poll_dvfs_set_1:
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    ands    r7, r7, #(1 << 25)
+    beq    poll_dvfs_set_1
+
+    ldr    r11, [r0, #PM_INFO_MX6Q_IOMUXC_V_OFFSET]
+    ldr    r6, =0x0
+    ldr    r7, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
+    ldr    r8, =PM_INFO_MMDC_IO_VAL_OFFSET

If we add the following instruction here

   add     r8, r0, r8

arch/arm/mach-imx/suspend-imx6.S line 148

Quoted 2 lines
arch/arm/mach-imx/suspend-imx6.S new file +2 -0
+set_mmdc_io_lpm:
+    ldr    r9, [r0, r8]

, it can be replaced by the following one

   ldr     r9, [r8], #0x8

arch/arm/mach-imx/suspend-imx6.S line 150

Quoted 2 lines
arch/arm/mach-imx/suspend-imx6.S new file +2 -0
+    str    r6, [r11, r9]
+    add    r8, r8, #0x8

, and then we can save this one in the loop, right?

arch/arm/mach-imx/suspend-imx6.S line 152

Quoted 2 lines
arch/arm/mach-imx/suspend-imx6.S new file +2 -0
+    sub    r7, r7, #0x1
+    cmp     r7, #0x0

The sequence of 'sub ...; cmp ..., #0' and 'and ...; cmp ..., #0' can generally be replaced by 'subs ...' and 'ands' respectively to save one instruction, right?

The above two comments apply to a few other places in the code.

Quoted 63 lines
arch/arm/mach-imx/suspend-imx6.S new file +63 -0
+    bne    set_mmdc_io_lpm
+
+    /*
+     * mask all GPC interrupts before
+     * enabling the RBC counters to
+     * avoid the counter starting too
+     * early if an interupt is already
+     * pending.
+     */
+    ldr    r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
+    ldr    r6, [r11, #MX6Q_GPC_IMR1]
+    ldr    r7, [r11, #MX6Q_GPC_IMR2]
+    ldr    r8, [r11, #MX6Q_GPC_IMR3]
+    ldr    r9, [r11, #MX6Q_GPC_IMR4]
+
+    ldr    r10, =0xffffffff
+    str    r10, [r11, #MX6Q_GPC_IMR1]
+    str    r10, [r11, #MX6Q_GPC_IMR2]
+    str    r10, [r11, #MX6Q_GPC_IMR3]
+    str    r10, [r11, #MX6Q_GPC_IMR4]
+
+    /*
+     * enable the RBC bypass counter here
+     * to hold off the interrupts. RBC counter
+     * = 32 (1ms), Minimum RBC delay should be
+     * 400us for the analog LDOs to power down.
+     */
+    ldr    r11, [r0, #PM_INFO_MX6Q_CCM_V_OFFSET]
+    ldr    r10, [r11, #MX6Q_CCM_CCR]
+    bic    r10, r10, #(0x3f << 21)
+    orr    r10, r10, #(0x20 << 21)
+    str    r10, [r11, #MX6Q_CCM_CCR]
+
+    /* enable the counter. */
+    ldr    r10, [r11, #MX6Q_CCM_CCR]
+    orr    r10, r10, #(0x1 << 27)
+    str    r10, [r11, #MX6Q_CCM_CCR]
+
+    /* unmask all the GPC interrupts. */
+    ldr    r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
+    str    r6, [r11, #MX6Q_GPC_IMR1]
+    str    r7, [r11, #MX6Q_GPC_IMR2]
+    str    r8, [r11, #MX6Q_GPC_IMR3]
+    str    r9, [r11, #MX6Q_GPC_IMR4]
+
+    /*
+     * now delay for a short while (3usec)
+     * ARM is at 1GHz at this point
+     * so a short loop should be enough.
+     * this delay is required to ensure that
+     * the RBC counter can start counting in
+     * case an interrupt is already pending
+     * or in case an interrupt arrives just
+     * as ARM is about to assert DSM_request.
+     */
+    ldr     r6, =2000
+rbc_loop:
+    sub     r6, r6, #0x1
+    cmp     r6, #0x0
+    bne     rbc_loop
+
+    /* Zzz, enter stop mode */
+    wfi

arch/arm/mach-imx/suspend-imx6.S line 225

Quoted 10 lines
arch/arm/mach-imx/suspend-imx6.S new file +10 -0
+    nop
+    nop
+    nop
+    nop
+
+    /*
+     * run to here means there is pending
+     * wakeup source, system should auto
+     * resume, we need to restore MMDC IO first
+     */

The MMDC restoring code looks identical between the case of wakeup source pending and the normal resume case, except that the former runs at virtual address and the later runs at the physical. Can we make a macro for it to save some code duplication?

Shawn

Quoted 80 lines
arch/arm/mach-imx/suspend-imx6.S new file +78 -0
+    ldr    r11, [r0, #PM_INFO_MX6Q_IOMUXC_V_OFFSET]
+    ldr    r6, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
+    ldr    r7, =PM_INFO_MMDC_IO_VAL_OFFSET
+restore_mmdc_io:
+    ldr    r8, [r0, r7]
+    add    r7, r7, #0x4
+    ldr    r9, [r0, r7]
+    add    r7, r7, #0x4
+    str    r9, [r11, r8]
+    sub    r6, r6, #0x1
+    cmp     r6, #0x0
+    bne    restore_mmdc_io
+
+    ldr    r11, [r0, #PM_INFO_MX6Q_MMDC_V_OFFSET]
+    /* let DDR out of self-refresh. */
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    bic    r7, r7, #(1 << 21)
+    str    r7, [r11, #MX6Q_MMDC_MAPSR]
+
+poll_dvfs_clear_2:
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    ands    r7, r7, #(1 << 25)
+    bne     poll_dvfs_clear_2
+    /* enable DDR auto power saving */
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    bic    r7, r7, #0x1
+    str    r7, [r11, #MX6Q_MMDC_MAPSR]
+    /* return to suspend finish */
+    mov    pc, lr
+
+resume:
+    /* invalidate L1 I-cache first */
+    mov     r6, #0x0
+    mcr     p15, 0, r6, c7, c5, 0
+    mcr     p15, 0, r6, c7, c5, 0
+    mcr     p15, 0, r6, c7, c5, 6
+    /* enable the Icache and branch prediction */
+    mov     r6, #0x1800
+    mcr     p15, 0, r6, c1, c0, 0
+    isb
+
+    /* get physical resume address from pm_info. */
+    ldr    lr, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+    /* clear core0's entry and parameter */
+    ldr    r11, [r0, #PM_INFO_MX6Q_SRC_P_OFFSET]
+    mov    r7, #0
+    str    r7, [r11, #MX6Q_SRC_GPR1]
+    str    r7, [r11, #MX6Q_SRC_GPR2]
+
+    ldr    r11, [r0, #PM_INFO_MX6Q_IOMUXC_P_OFFSET]
+    ldr    r6, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
+    ldr    r7, =PM_INFO_MMDC_IO_VAL_OFFSET
+dsm_restore_mmdc_io:
+    ldr    r8, [r0, r7]
+    add    r7, r7, #0x4
+    ldr    r9, [r0, r7]
+    add    r7, r7, #0x4
+    str    r9, [r11, r8]
+    sub    r6, r6, #0x1
+    cmp     r6, #0x0
+    bne    dsm_restore_mmdc_io
+
+    ldr    r11, [r0, #PM_INFO_MX6Q_MMDC_P_OFFSET]
+    /* let DDR out of self-refresh */
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    bic    r7, r7, #(1 << 21)
+    str    r7, [r11, #MX6Q_MMDC_MAPSR]
+
+poll_dvfs_clear_1:
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    ands    r7, r7, #(1 << 25)
+    bne    poll_dvfs_clear_1
+    /* enable DDR auto power saving */
+    ldr    r7, [r11, #MX6Q_MMDC_MAPSR]
+    bic    r7, r7, #0x1
+    str    r7, [r11, #MX6Q_MMDC_MAPSR]
+    mov    pc, lr
+ENDPROC(imx6_suspend)
Signature · 1 line
1.7.9.5