Skip to contentSkip to conversation

add initial imx6q support

PATCH Superseded Shawn Guo 5 participants 18 messages Sep 15, 2011 – Sep 20, 2011

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

v2 cover add initial imx6q support

This patch series adds the initial support for imx6q, which is a Cortex-A9 Quad Core based SoC.

We chose to add imx6q support into mach-imx other than mach-mx5 or a new mach-mx6, because we intend to merge mach-mx5 into mach-imx, so that we have only mach-imx for imx family.

It's based on v3.1-rc6 with the patches below applied.

* [PATCH v2 0/5] Convert DEBUG_LL UART selection to a Kconfig choice
http://thread.gmane.org/gmane.linux.ports.arm.kernel/129702

* [PATCH v4 2/2] ARM: l2x0: Add OF based initialization
http://article.gmane.org/gmane.linux.kernel/1164401

* [PATCH 1/7] ARM: l2x0: add empty l2x0_of_init
http://article.gmane.org/gmane.linux.ports.arm.kernel/130878

* [PATCH 0/5] GIC OF bindings
http://thread.gmane.org/gmane.linux.drivers.devicetree/8093/

For suspend/resume support, it needs the following extra patches as the prerequisite.

* [PATCH 00/11] Add L2 cache cleaning to generic CPU suspend
http://thread.gmane.org/gmane.linux.ports.arm.kernel/130957/

* [PATCH v2 0/5] CPU PM notifiers
http://thread.gmane.org/gmane.linux.ports.arm.kernel/131212/focus=131353

* [PATCH v2 2/2] ARM: smp_scu: remove __init annotation from scu_enable()
http://permalink.gmane.org/gmane.linux.ports.arm.kernel/131358

I hope I have made all changes I agree to change. But please let me know if I missed any.

Changes since v1:
* Use the existing IMX_IO_P2V for static mapping
* Fix the MXC_INTERNAL_IRQS breakage introduced by GIC definition
* Retrieve clock frequency for fixed clocks from device tree
* Drop early_initcall from imx_src_init() and call it from imx6q platform initialization
* Use readl_relaxed/writel_relaxed rather than __raw_readl/__raw_writel as suggested by Arnd
* Kill unnecessary imx_local_timer_pre_suspend/resume functions
* Kill Kconfig symbol MACH_IMX6Q
* Rebase to rmk's "Add L2 cache cleaning to generic CPU suspend" series so that we can retain L2 cache with necessary L2 register save/restore across suspend/resume cycle
* Rebase to Rob's new "GIC OF bindings" series

Thanks.

Shawn Guo (6):
arm/imx6q: add device tree source
arm/imx6q: add core definitions and low-level debug uart arm/imx6q: add core drivers clock, gpc, mmdc and src arm/imx6q: add smp and cpu hotplug support arm/imx6q: add device tree machine support arm/imx6q: add suspend/resume support

 Documentation/devicetree/bindings/arm/fsl.txt |    6 +
 arch/arm/Kconfig                              |    2 +-
 arch/arm/Kconfig.debug                        |    7 +
 arch/arm/Makefile                             |    1 +
 arch/arm/boot/dts/imx6q-sabreauto.dts         |   71 +
 arch/arm/boot/dts/imx6q.dtsi                  |  547 +++++++
 arch/arm/mach-imx/Kconfig                     |   29 +-
 arch/arm/mach-imx/Makefile                    |   10 +
 arch/arm/mach-imx/Makefile.boot               |    4 +
 arch/arm/mach-imx/clock-imx6q.c               | 1997 +++++++++++++++++++++++++
 arch/arm/mach-imx/gpc.c                       |  113 ++
 arch/arm/mach-imx/head-v7.S                   |   98 ++
 arch/arm/mach-imx/hotplug.c                   |   44 +
 arch/arm/mach-imx/lluart.c                    |   32 +
 arch/arm/mach-imx/localtimer.c                |   35 +
 arch/arm/mach-imx/mach-imx6q.c                |   73 +
 arch/arm/mach-imx/mmdc.c                      |   71 +
 arch/arm/mach-imx/platsmp.c                   |   85 ++
 arch/arm/mach-imx/pm-imx6q.c                  |   88 ++
 arch/arm/mach-imx/src.c                       |   49 +
 arch/arm/mm/Kconfig                           |    2 +-
 arch/arm/plat-mxc/Kconfig                     |    5 +
 arch/arm/plat-mxc/include/mach/common.h       |   25 +
 arch/arm/plat-mxc/include/mach/debug-macro.S  |    2 +
 arch/arm/plat-mxc/include/mach/entry-macro.S  |   15 +-
 arch/arm/plat-mxc/include/mach/hardware.h     |    6 +
 arch/arm/plat-mxc/include/mach/irqs.h         |   10 +-
 arch/arm/plat-mxc/include/mach/memory.h       |    3 +
 arch/arm/plat-mxc/include/mach/mx6q.h         |   33 +
 29 files changed, 3457 insertions(+), 6 deletions(-)
author
#1 lore raw

PATCH v2 1/6 arm/imx6q: add device tree source

It adds device tree source and documentation for imx6q platform.

---
 Documentation/devicetree/bindings/arm/fsl.txt |    6 +
 arch/arm/boot/dts/imx6q-sabreauto.dts         |   71 ++++
 arch/arm/boot/dts/imx6q.dtsi                  |  547 +++++++++++++++++++++++++
 3 files changed, 624 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/fsl.txt
 create mode 100644 arch/arm/boot/dts/imx6q-sabreauto.dts
 create mode 100644 arch/arm/boot/dts/imx6q.dtsi
Documentation/devicetree/bindings/arm/fsl.txt new file +6 -0
new file mode 100644
index 0000000..345bfc0
@@ -0,0 +1,6 @@
+Freescale i.MX Platforms Device Tree Bindings
+-----------------------------------------------
+
+i.MX6 Quad SABRE Automotive Board
+Required root node properties:
+    - compatible = "fsl,imx6q-sabreauto", "fsl,imx6q";
arch/arm/boot/dts/imx6q-sabreauto.dts new file +71 -0

71 lines not on this page · raw message

arch/arm/boot/dts/imx6q.dtsi new file +547 -0

547 lines not on this page · raw message

Signature · 1 line
1.7.4.1
author
#2 lore raw

PATCH v2 2/6 arm/imx6q: add core definitions and low-level debug uart

In reply to Shawn Guo

It adds the core definitions and low-level debug uart support for imx6q.

---
 arch/arm/Kconfig                             |    2 +-
 arch/arm/Kconfig.debug                       |    7 +++++
 arch/arm/Makefile                            |    1 +
 arch/arm/mach-imx/Kconfig                    |   15 +++++++++++-
 arch/arm/mach-imx/Makefile                   |    2 +
 arch/arm/mach-imx/Makefile.boot              |    4 +++
 arch/arm/mach-imx/lluart.c                   |   32 +++++++++++++++++++++++++
 arch/arm/plat-mxc/Kconfig                    |    5 ++++
 arch/arm/plat-mxc/include/mach/debug-macro.S |    2 +
 arch/arm/plat-mxc/include/mach/entry-macro.S |   15 +++++++++++-
 arch/arm/plat-mxc/include/mach/hardware.h    |    6 ++++
 arch/arm/plat-mxc/include/mach/irqs.h        |   10 ++++++-
 arch/arm/plat-mxc/include/mach/memory.h      |    3 ++
 arch/arm/plat-mxc/include/mach/mx6q.h        |   33 ++++++++++++++++++++++++++
 14 files changed, 132 insertions(+), 5 deletions(-)
 create mode 100644 arch/arm/mach-imx/lluart.c
 create mode 100644 arch/arm/plat-mxc/include/mach/mx6q.h
arch/arm/Kconfig +1 -1
index bc9981b..415a954 100644
@@ -1360,7 +1360,7 @@ config SMP
 	depends on REALVIEW_EB_ARM11MP || REALVIEW_EB_A9MP || \
 		 MACH_REALVIEW_PB11MP || MACH_REALVIEW_PBX || ARCH_OMAP4 || \
 		 ARCH_EXYNOS4 || ARCH_TEGRA || ARCH_U8500 || ARCH_VEXPRESS_CA9X4 || \
-		 ARCH_MSM_SCORPIONMP || ARCH_SHMOBILE
+		 ARCH_MSM_SCORPIONMP || ARCH_SHMOBILE || SOC_IMX6Q
 	select USE_GENERIC_SMP_HELPERS
 	select HAVE_ARM_SCU if !ARCH_MSM_SCORPIONMP
 	help
arch/arm/Kconfig.debug +7 -0
index 965d59a..68fc155 100644
@@ -155,6 +155,13 @@ choice
 		  Say Y here if you want kernel low-level debugging support
 		  on i.MX50 or i.MX53.
 
+	config DEBUG_IMX6Q_UART
+		bool "i.MX6Q Debug UART"
+		depends on SOC_IMX6Q
+		help
+		  Say Y here if you want kernel low-level debugging support
+		  on i.MX6Q.
+
 	config DEBUG_S3C_UART0
 		depends on PLAT_SAMSUNG
 		bool "Use S3C UART 0 for low-level debug"
arch/arm/Makefile +1 -0
index 70c424e..3a0bbe4 100644
@@ -159,6 +159,7 @@ machine-$(CONFIG_ARCH_MX2)		:= imx
 machine-$(CONFIG_ARCH_MX25)		:= imx
 machine-$(CONFIG_ARCH_MX3)		:= imx
 machine-$(CONFIG_ARCH_MX5)		:= mx5
+machine-$(CONFIG_ARCH_MX6)		:= imx
 machine-$(CONFIG_ARCH_MXS)		:= mxs
 machine-$(CONFIG_ARCH_NETX)		:= netx
 machine-$(CONFIG_ARCH_NOMADIK)		:= nomadik
arch/arm/mach-imx/Kconfig +14 -1
index 0519dd7..e88e366 100644
@@ -58,7 +58,6 @@ config SOC_IMX35
 	select ARCH_MX35
 	select MXC_AVIC
 
-
 if ARCH_MX1
 
 comment "MX1 platforms:"
@@ -606,3 +605,17 @@ config MACH_VPR200
 	  configurations for the board and its peripherals.
 
 endif
+
+if ARCH_MX6
+comment "i.MX6 family:"
+
+config SOC_IMX6Q
+	bool "i.MX6 Quad support"
+	select ARM_GIC
+	select CPU_V7
+	select USE_OF
+
+	help
+	  This enables support for Freescale i.MX6 Quad processor.
+
+endif
arch/arm/mach-imx/Makefile +2 -0
index e9eb36d..96ecc96 100644
@@ -61,3 +61,5 @@ obj-$(CONFIG_MACH_MX35_3DS) += mach-mx35_3ds.o
 obj-$(CONFIG_MACH_EUKREA_CPUIMX35) += mach-cpuimx35.o
 obj-$(CONFIG_MACH_EUKREA_MBIMXSD35_BASEBOARD) += eukrea_mbimxsd35-baseboard.o
 obj-$(CONFIG_MACH_VPR200) += mach-vpr200.o
+
+obj-$(CONFIG_DEBUG_LL) += lluart.o
arch/arm/mach-imx/Makefile.boot +4 -0
index ebee18b..389a0e3 100644
@@ -17,3 +17,7 @@ initrd_phys-$(CONFIG_MACH_MX27)	:= 0xA0800000
 zreladdr-$(CONFIG_ARCH_MX3)	:= 0x80008000
 params_phys-$(CONFIG_ARCH_MX3)	:= 0x80000100
 initrd_phys-$(CONFIG_ARCH_MX3)	:= 0x80800000
+
+zreladdr-$(CONFIG_SOC_IMX6Q)	:= 0x10008000
+params_phys-$(CONFIG_SOC_IMX6Q)	:= 0x10000100
+initrd_phys-$(CONFIG_SOC_IMX6Q)	:= 0x10800000
arch/arm/mach-imx/lluart.c new file +32 -0
new file mode 100644
index 0000000..d4ab6f2
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <asm/page.h>
+#include <asm/sizes.h>
+#include <asm/mach/map.h>
+#include <mach/hardware.h>
+
+static struct map_desc imx_lluart_desc = {
+#ifdef CONFIG_DEBUG_IMX6Q_UART
+	.virtual	= MX6Q_IO_P2V(MX6Q_UART4_BASE_ADDR),
+	.pfn		= __phys_to_pfn(MX6Q_UART4_BASE_ADDR),
+	.length		= MX6Q_UART4_SIZE,
+	.type		= MT_DEVICE,
+#endif
+};
+
+void __init imx_lluart_map_io(void)
+{
+	if (imx_lluart_desc.virtual)
+		iotable_init(&imx_lluart_desc, 1);
+}
arch/arm/plat-mxc/Kconfig +5 -0
index a5353fc..e548f9b 100644
@@ -48,6 +48,11 @@ config ARCH_MX51
 	help
 	  This enables support for systems based on the Freescale i.MX51 family
 
+config ARCH_MX6
+	bool "i.MX6"
+	help
+	  This enables support for systems based on the Freescale i.MX6 family
+
 endchoice
 
 source "arch/arm/mach-imx/Kconfig"
arch/arm/plat-mxc/include/mach/debug-macro.S +2 -0
index 07cfdbe..f2ce2cb 100644
@@ -24,6 +24,8 @@
 #define UART_PADDR	MX51_UART1_BASE_ADDR
 #elif defined (CONFIG_DEBUG_IMX50_IMX53_UART)
 #define UART_PADDR	MX53_UART1_BASE_ADDR
+#elif defined (CONFIG_DEBUG_IMX6Q_UART)
+#define UART_PADDR	MX6Q_UART4_BASE_ADDR
 #endif
 
 #define UART_VADDR	IMX_IO_ADDRESS(UART_PADDR)
arch/arm/plat-mxc/include/mach/entry-macro.S +14 -1
index 066d464..341f800 100644
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 2007 Lennert Buytenhek <[email protected]>
- *  Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ *  Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.
  */
 
 /*
@@ -11,6 +11,17 @@
 
 #include <mach/hardware.h>
 
+#ifdef CONFIG_ARM_GIC
+#include <asm/hardware/entry-macro-gic.S>
+
+	.macro	disable_fiq
+	.endm
+
+	.macro	arch_ret_to_user, tmp1, tmp2
+	.endm
+
+#else
+
 #define AVIC_NIMASK	0x04
 
 	@ this macro disables fast irq (not implemented)
@@ -78,3 +89,5 @@
 	movs \irqnr, \irqnr
 #endif
 	.endm
+
+#endif /* CONFIG_ARM_GIC */
arch/arm/plat-mxc/include/mach/hardware.h +6 -0
index a8bfd56..ee28c56 100644
@@ -86,6 +86,11 @@
  *	SPBA0	0x70000000+0x100000	->	0xf5400000+0x100000
  *	AIPS1	0x73f00000+0x100000	->	0xf5700000+0x100000
  *	AIPS2	0x83f00000+0x100000	->	0xf4300000+0x100000
+ * mx6q:
+ *	SCU	0x00a00000+0x001000	->	0xf4000000+0x001000
+ *	CCM	0x020c4000+0x004000	->	0xf42c4000+0x004000
+ *	ANATOP	0x020c8000+0x001000	->	0xf42c8000+0x001000
+ *	UART4	0x021f0000+0x004000	->	0xf42f0000+0x004000
  */
 #define IMX_IO_P2V(x)	(						\
 			0xf4000000 +					\
@@ -97,6 +102,7 @@
 
 #include <mach/mxc.h>
 
+#include <mach/mx6q.h>
 #include <mach/mx50.h>
 #include <mach/mx51.h>
 #include <mach/mx53.h>
arch/arm/plat-mxc/include/mach/irqs.h +8 -2
index 00e812b..fd9efb0 100644
@@ -14,9 +14,15 @@
 #include <asm-generic/gpio.h>
 
 /*
- * SoCs with TZIC interrupt controller have 128 IRQs, those with AVIC have 64
+ * SoCs with GIC interrupt controller have 160 IRQs, those with TZIC
+ * have 128 IRQs, and those with AVIC have 64.
+ *
+ * To support single image, the biggest number should be defined on
+ * top of the list.
  */
-#ifdef CONFIG_MXC_TZIC
+#if defined CONFIG_ARM_GIC
+#define MXC_INTERNAL_IRQS	160
+#elif defined CONFIG_MXC_TZIC
 #define MXC_INTERNAL_IRQS	128
 #else
 #define MXC_INTERNAL_IRQS	64
arch/arm/plat-mxc/include/mach/memory.h +3 -0
index 11be5cd..2b8e186 100644
@@ -19,6 +19,7 @@
 #define MX50_PHYS_OFFSET	UL(0x70000000)
 #define MX51_PHYS_OFFSET	UL(0x90000000)
 #define MX53_PHYS_OFFSET	UL(0x70000000)
+#define MX6Q_PHYS_OFFSET	UL(0x10000000)
 
 #if !defined(CONFIG_RUNTIME_PHYS_OFFSET)
 # if defined CONFIG_ARCH_MX1
@@ -37,6 +38,8 @@
 #  define PLAT_PHYS_OFFSET		MX51_PHYS_OFFSET
 # elif defined CONFIG_ARCH_MX53
 #  define PLAT_PHYS_OFFSET		MX53_PHYS_OFFSET
+# elif defined CONFIG_SOC_IMX6Q
+#  define PLAT_PHYS_OFFSET		MX6Q_PHYS_OFFSET
 # endif
 #endif
 
arch/arm/plat-mxc/include/mach/mx6q.h new file +33 -0
new file mode 100644
index 0000000..254a561
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#ifndef __MACH_MX6Q_H__
+#define __MACH_MX6Q_H__
+
+#define MX6Q_IO_P2V(x)			IMX_IO_P2V(x)
+#define MX6Q_IO_ADDRESS(x)		IOMEM(MX6Q_IO_P2V(x))
+
+/*
+ * The following are the blocks that need to be statically mapped.
+ * For other blocks, the base address really should be retrieved from
+ * device tree.
+ */
+#define MX6Q_SCU_BASE_ADDR		0x00a00000
+#define MX6Q_SCU_SIZE			0x1000
+#define MX6Q_CCM_BASE_ADDR		0x020c4000
+#define MX6Q_CCM_SIZE			0x4000
+#define MX6Q_ANATOP_BASE_ADDR		0x020c8000
+#define MX6Q_ANATOP_SIZE		0x1000
+#define MX6Q_UART4_BASE_ADDR		0x021f0000
+#define MX6Q_UART4_SIZE			0x4000
+
+#endif	/* __MACH_MX6Q_H__ */
Signature · 1 line
1.7.4.1
maintainer
#3 lore raw

PATCH v2 2/6 arm/imx6q: add core definitions and low-level debug uart

Quoted 21 lines · Shawn Guo

It adds the core definitions and low-level debug uart support for imx6q.

#define UART_VADDR IMX_IO_ADDRESS(UART_PADDR)

arch/arm/plat-mxc/include/mach/entry-macro.S +1 -1
index 066d464..341f800 100644
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 2007 Lennert Buytenhek <[email protected]>
- *  Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ *  Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.
  */
 
 /*
@@ -11,6 +11,17 @@
 
 #include <mach/hardware.h>
 

arch/arm/plat-mxc/include/mach/entry-macro.S line 23

Quoted 10 lines
arch/arm/plat-mxc/include/mach/entry-macro.S +10 -0
+#ifdef CONFIG_ARM_GIC
+#include <asm/hardware/entry-macro-gic.S>
+
+	.macro	disable_fiq
+	.endm
+
+	.macro	arch_ret_to_user, tmp1, tmp2
+	.endm
+
+#else

That's the third interrupt entry code handled here with ifdefs. I remember there was some infrastructure to have multiple irq controllers. I can't find any pointers, but I think Eric (added him to Cc) told me about it.
As this is also the last roadblock to compile i.MX3 and i.MX5 into a single kernel this might be the right moment to work on this.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#4 lore raw

PATCH v2 2/6 arm/imx6q: add core definitions and low-level debug uart

Quoted 31 lines · Sascha Hauer
Quoted 30 lines · Shawn Guo

It adds the core definitions and low-level debug uart support for imx6q.

?#define UART_VADDR ? IMX_IO_ADDRESS(UART_PADDR)

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
index 066d464..341f800 100644
@@ -1,6 +1,6 @@

?/*
? * ?Copyright (C) 2007 Lennert Buytenhek <[email protected]>
- * ?Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * ?Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved. ? */

?/*

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
@@ -11,6 +11,17 @@
 

?#include <mach/hardware.h>

arch/arm/plat-mxc/include/mach/entry-macro.S +9 -0
+#ifdef CONFIG_ARM_GIC
+#include <asm/hardware/entry-macro-gic.S>
+
+ ? ? .macro ?disable_fiq
+ ? ? .endm
+
+ ? ? .macro ?arch_ret_to_user, tmp1, tmp2
+ ? ? .endm
+
Quoted 8 lines
Quoted 1 line

+#else

That's the third interrupt entry code handled here with ifdefs. I remember there was some infrastructure to have multiple irq controllers. I can't find any pointers, but I think Eric (added him to Cc) told me about it.
As this is also the last roadblock to compile i.MX3 and i.MX5 into a single kernel this might be the right moment to work on this.

It's CONFIG_MULTIPLE_IRQ_HANDLER. And check arch/arm/mach-pxa/irq.c for example. Basically to use a C function to handle the interrupts, and have each machine to specify the correct handler.

E.g. in pxa - there are pxa25x_handle_irq, pxa3xx_handle_irq ...

Quoted 9 lines

Sascha

--

Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
maintainer
#5 lore raw

PATCH v2 2/6 arm/imx6q: add core definitions and low-level debug uart

Quoted 41 lines · Eric Miao
Quoted 31 lines · Sascha Hauer
Quoted 30 lines · Shawn Guo

It adds the core definitions and low-level debug uart support for imx6q.

?#define UART_VADDR ? IMX_IO_ADDRESS(UART_PADDR)

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
index 066d464..341f800 100644
@@ -1,6 +1,6 @@

?/*
? * ?Copyright (C) 2007 Lennert Buytenhek <[email protected]>
- * ?Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * ?Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved. ? */

?/*

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
@@ -11,6 +11,17 @@
 

?#include <mach/hardware.h>

arch/arm/plat-mxc/include/mach/entry-macro.S +9 -0
+#ifdef CONFIG_ARM_GIC
+#include <asm/hardware/entry-macro-gic.S>
+
+ ? ? .macro ?disable_fiq
+ ? ? .endm
+
+ ? ? .macro ?arch_ret_to_user, tmp1, tmp2
+ ? ? .endm
+
Quoted 8 lines
Quoted 1 line

+#else

That's the third interrupt entry code handled here with ifdefs. I remember there was some infrastructure to have multiple irq controllers. I can't find any pointers, but I think Eric (added him to Cc) told me about it.
As this is also the last roadblock to compile i.MX3 and i.MX5 into a single kernel this might be the right moment to work on this.

Quoted 5 lines

It's CONFIG_MULTIPLE_IRQ_HANDLER. And check arch/arm/mach-pxa/irq.c for example. Basically to use a C function to handle the interrupts, and have each machine to specify the correct handler.

E.g. in pxa - there are pxa25x_handle_irq, pxa3xx_handle_irq ...

Nice, it's already merged. I should have used grep instead of google. For reference, it's CONFIG_MULTI_IRQ_HANDLER.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#6 lore raw

PATCH v2 2/6 arm/imx6q: add core definitions and low-level debug uart

Quoted 42 lines · Sascha Hauer
Quoted 41 lines · Eric Miao
Quoted 39 lines · Sascha Hauer
Quoted 21 lines · Shawn Guo

It adds the core definitions and low-level debug uart support for imx6q.

?#define UART_VADDR ? IMX_IO_ADDRESS(UART_PADDR)

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
index 066d464..341f800 100644
@@ -1,6 +1,6 @@

?/*
? * ?Copyright (C) 2007 Lennert Buytenhek <[email protected]>
- * ?Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * ?Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved. ? */

?/*

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
@@ -11,6 +11,17 @@
 

?#include <mach/hardware.h>

arch/arm/plat-mxc/include/mach/entry-macro.S line 23

Quoted 10 lines
arch/arm/plat-mxc/include/mach/entry-macro.S +10 -0
+#ifdef CONFIG_ARM_GIC
+#include <asm/hardware/entry-macro-gic.S>
+
+ ? ? .macro ?disable_fiq
+ ? ? .endm
+
+ ? ? .macro ?arch_ret_to_user, tmp1, tmp2
+ ? ? .endm
+
+#else

That's the third interrupt entry code handled here with ifdefs. I remember there was some infrastructure to have multiple irq controllers. I can't find any pointers, but I think Eric (added him to Cc) told me about it.
As this is also the last roadblock to compile i.MX3 and i.MX5 into a single kernel this might be the right moment to work on this.

Quoted 8 lines
Quoted 5 lines

It's CONFIG_MULTIPLE_IRQ_HANDLER. And check arch/arm/mach-pxa/irq.c for example. Basically to use a C function to handle the interrupts, and have each machine to specify the correct handler.

E.g. in pxa - there are pxa25x_handle_irq, pxa3xx_handle_irq ...

Nice, it's already merged. I should have used grep instead of google. For reference, it's CONFIG_MULTI_IRQ_HANDLER.

My poor memory :-)

Quoted 9 lines

Sascha

--

Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
#7 lore raw

PATCH v2 2/6 arm/imx6q: add core definitions and low-level debug uart

In reply to Sascha Hauer
Quoted 34 lines · Sascha Hauer
Quoted 33 lines · Eric Miao
Quoted 32 lines · Sascha Hauer
Quoted 31 lines · Shawn Guo

It adds the core definitions and low-level debug uart support for imx6q.

?#define UART_VADDR ? IMX_IO_ADDRESS(UART_PADDR)

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
index 066d464..341f800 100644
@@ -1,6 +1,6 @@

?/*
? * ?Copyright (C) 2007 Lennert Buytenhek <[email protected]>
- * ?Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * ?Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved. ? */

?/*

arch/arm/plat-mxc/include/mach/entry-macro.S +0 -0
@@ -11,6 +11,17 @@
 

?#include <mach/hardware.h>

arch/arm/plat-mxc/include/mach/entry-macro.S +10 -0
+#ifdef CONFIG_ARM_GIC
+#include <asm/hardware/entry-macro-gic.S>
+
+ ? ? .macro ?disable_fiq
+ ? ? .endm
+
+ ? ? .macro ?arch_ret_to_user, tmp1, tmp2
+ ? ? .endm
+
+#else
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

That's the third interrupt entry code handled here with ifdefs. I remember there was some infrastructure to have multiple irq controllers. I can't find any pointers, but I think Eric (added him to Cc) told me about it.
As this is also the last roadblock to compile i.MX3 and i.MX5 into a single kernel this might be the right moment to work on this.

It seems to be a work that basically need to touch very imx platforms. I would like to work on it, but I do not think it belongs to this series.

Regards,
Shawn

Quoted 9 lines
Quoted 5 lines

It's CONFIG_MULTIPLE_IRQ_HANDLER. And check arch/arm/mach-pxa/irq.c for example. Basically to use a C function to handle the interrupts, and have each machine to specify the correct handler.

E.g. in pxa - there are pxa25x_handle_irq, pxa3xx_handle_irq ...

Nice, it's already merged. I should have used grep instead of google. For reference, it's CONFIG_MULTI_IRQ_HANDLER.

author
#8 lore raw

PATCH v2 3/6 arm/imx6q: add core drivers clock, gpc, mmdc and src

In reply to Shawn Guo

It adds a number of core drivers support for imx6q, including clock, General Power Controller (gpc), Multi Mode DDR Controller(mmdc) and System Reset Controller (src).

---
 arch/arm/mach-imx/Kconfig       |   13 +
 arch/arm/mach-imx/Makefile      |    4 +
 arch/arm/mach-imx/clock-imx6q.c | 1997 +++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/gpc.c         |  113 +++
 arch/arm/mach-imx/mmdc.c        |   71 ++
 arch/arm/mach-imx/src.c         |   49 +
 6 files changed, 2247 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-imx/clock-imx6q.c
 create mode 100644 arch/arm/mach-imx/gpc.c
 create mode 100644 arch/arm/mach-imx/mmdc.c
 create mode 100644 arch/arm/mach-imx/src.c
arch/arm/mach-imx/Kconfig +13 -0
index e88e366..af73b3e 100644
@@ -1,5 +1,15 @@
 config IMX_HAVE_DMA_V1
 	bool
+
+config HAVE_IMX_GPC
+	bool
+
+config HAVE_IMX_MMDC
+	bool
+
+config HAVE_IMX_SRC
+	bool
+
 #
 # ARCH_MX31 and ARCH_MX35 are left for compatibility
 # Some usages assume that having one of them implies not having (e.g.) ARCH_MX2.
@@ -613,6 +623,9 @@ config SOC_IMX6Q
 	bool "i.MX6 Quad support"
 	select ARM_GIC
 	select CPU_V7
+	select HAVE_IMX_GPC
+	select HAVE_IMX_MMDC
+	select HAVE_IMX_SRC
 	select USE_OF
 
 	help
arch/arm/mach-imx/Makefile +4 -0
index 96ecc96..8c21fda 100644
@@ -63,3 +63,7 @@ obj-$(CONFIG_MACH_EUKREA_MBIMXSD35_BASEBOARD) += eukrea_mbimxsd35-baseboard.o
 obj-$(CONFIG_MACH_VPR200) += mach-vpr200.o
 
 obj-$(CONFIG_DEBUG_LL) += lluart.o
+obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
+obj-$(CONFIG_HAVE_IMX_MMDC) += mmdc.o
+obj-$(CONFIG_HAVE_IMX_SRC) += src.o
+obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o
arch/arm/mach-imx/clock-imx6q.c new file +1997 -0

1,997 lines not on this page · raw message

arch/arm/mach-imx/gpc.c new file +113 -0

113 lines not on this page · raw message

arch/arm/mach-imx/mmdc.c new file +71 -0

71 lines not on this page · raw message

arch/arm/mach-imx/src.c new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
1.7.4.1
author
#9 lore raw

PATCH v2 4/6 arm/imx6q: add smp and cpu hotplug support

In reply to Shawn Guo

It adds smp and cpu hotplug support for imx6q.

---
 arch/arm/mach-imx/Kconfig               |    1 +
 arch/arm/mach-imx/Makefile              |    4 ++
 arch/arm/mach-imx/head-v7.S             |   71 ++++++++++++++++++++++++++
 arch/arm/mach-imx/hotplug.c             |   44 ++++++++++++++++
 arch/arm/mach-imx/localtimer.c          |   35 +++++++++++++
 arch/arm/mach-imx/platsmp.c             |   85 +++++++++++++++++++++++++++++++
 arch/arm/plat-mxc/include/mach/common.h |    6 ++
 7 files changed, 246 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-imx/head-v7.S
 create mode 100644 arch/arm/mach-imx/hotplug.c
 create mode 100644 arch/arm/mach-imx/localtimer.c
 create mode 100644 arch/arm/mach-imx/platsmp.c
arch/arm/mach-imx/Kconfig +1 -0
index af73b3e..6ec758d 100644
@@ -623,6 +623,7 @@ config SOC_IMX6Q
 	bool "i.MX6 Quad support"
 	select ARM_GIC
 	select CPU_V7
+	select HAVE_ARM_SCU
 	select HAVE_IMX_GPC
 	select HAVE_IMX_MMDC
 	select HAVE_IMX_SRC
arch/arm/mach-imx/Makefile +4 -0
index 8c21fda..d46b2e7 100644
@@ -66,4 +66,8 @@ obj-$(CONFIG_DEBUG_LL) += lluart.o
 obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
 obj-$(CONFIG_HAVE_IMX_MMDC) += mmdc.o
 obj-$(CONFIG_HAVE_IMX_SRC) += src.o
+obj-$(CONFIG_CPU_V7) += head-v7.o
+obj-$(CONFIG_SMP) += platsmp.o
+obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
+obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
 obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o
arch/arm/mach-imx/head-v7.S new file +71 -0

71 lines not on this page · raw message

arch/arm/mach-imx/hotplug.c new file +44 -0

44 lines not on this page · raw message

arch/arm/mach-imx/localtimer.c new file +35 -0
new file mode 100644
index 0000000..3a16351
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <linux/clockchips.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <asm/smp_twd.h>
+
+/*
+ * Setup the local clock events for a CPU.
+ */
+int __cpuinit local_timer_setup(struct clock_event_device *evt)
+{
+	struct device_node *np;
+
+	np = of_find_compatible_node(NULL, NULL, "arm,smp-twd");
+	if (!twd_base) {
+		twd_base = of_iomap(np, 0);
+		WARN_ON(!twd_base);
+	}
+	evt->irq = irq_of_parse_and_map(np, 0);
+	twd_timer_setup(evt);
+
+	return 0;
+}
arch/arm/mach-imx/platsmp.c new file +85 -0

85 lines not on this page · raw message

arch/arm/plat-mxc/include/mach/common.h +6 -0
index 4e3d978..48dbc27 100644
@@ -72,4 +72,10 @@ extern void mxc_arch_reset_init(void __iomem *);
 extern void mx51_efikamx_reset(void);
 extern int mx53_revision(void);
 extern int mx53_display_revision(void);
+
+extern void imx_enable_cpu(int cpu, bool enable);
+extern void imx_set_cpu_jump(int cpu, void *jump_addr);
+#ifdef CONFIG_SMP
+extern void v7_secondary_startup(void);
+#endif
 #endif
Signature · 1 line
1.7.4.1
author
#10 lore raw

PATCH v2 5/6 arm/imx6q: add device tree machine support

In reply to Shawn Guo

It adds generic device tree based machine support for imx6q.

---
 arch/arm/mach-imx/Makefile              |    2 +-
 arch/arm/mach-imx/mach-imx6q.c          |   73 +++++++++++++++++++++++++++++++
 arch/arm/mm/Kconfig                     |    2 +-
 arch/arm/plat-mxc/include/mach/common.h |   15 ++++++-
 4 files changed, 88 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/mach-imx/mach-imx6q.c
arch/arm/mach-imx/Makefile +1 -1
index d46b2e7..16737ba 100644
@@ -70,4 +70,4 @@ obj-$(CONFIG_CPU_V7) += head-v7.o
 obj-$(CONFIG_SMP) += platsmp.o
 obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
 obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
-obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o
+obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o
arch/arm/mach-imx/mach-imx6q.c new file +73 -0

73 lines not on this page · raw message

arch/arm/mm/Kconfig +1 -1
index 88633fe..c3ce146 100644
@@ -822,7 +822,7 @@ config CACHE_L2X0
 		   REALVIEW_EB_A9MP || SOC_IMX35 || SOC_IMX31 || MACH_REALVIEW_PBX || \
 		   ARCH_NOMADIK || ARCH_OMAP4 || ARCH_EXYNOS4 || ARCH_TEGRA || \
 		   ARCH_U8500 || ARCH_VEXPRESS_CA9X4 || ARCH_SHMOBILE || \
-		   ARCH_PRIMA2 || ARCH_ZYNQ || ARCH_CNS3XXX
+		   ARCH_PRIMA2 || ARCH_ZYNQ || ARCH_CNS3XXX || ARCH_MX6
 	default y
 	select OUTER_CACHE
 	select OUTER_CACHE_SYNC
arch/arm/plat-mxc/include/mach/common.h +13 -2
index 48dbc27..9c5be7b 100644
@@ -64,6 +64,7 @@ extern int mx51_clocks_init(unsigned long ckil, unsigned long osc,
 			unsigned long ckih1, unsigned long ckih2);
 extern int mx53_clocks_init(unsigned long ckil, unsigned long osc,
 			unsigned long ckih1, unsigned long ckih2);
+extern int mx6q_clocks_init(void);
 extern struct platform_device *mxc_register_gpio(char *name, int id,
 	resource_size_t iobase, resource_size_t iosize, int irq, int irq_high);
 extern int mxc_register_device(struct platform_device *pdev, void *data);
@@ -73,9 +74,19 @@ extern void mx51_efikamx_reset(void);
 extern int mx53_revision(void);
 extern int mx53_display_revision(void);
 
-extern void imx_enable_cpu(int cpu, bool enable);
-extern void imx_set_cpu_jump(int cpu, void *jump_addr);
+#ifdef CONFIG_DEBUG_LL
+extern void imx_lluart_map_io(void);
+#else
+static inline void imx_lluart_map_io(void) {}
+#endif
 #ifdef CONFIG_SMP
 extern void v7_secondary_startup(void);
+extern void imx_scu_map_io(void);
+#else
+static inline void imx_scu_map_io(void) {}
 #endif
+extern void imx_enable_cpu(int cpu, bool enable);
+extern void imx_set_cpu_jump(int cpu, void *jump_addr);
+extern void imx_src_init(void);
+extern void imx_gpc_init(void);
 #endif
Signature · 1 line
1.7.4.1
author
#11 lore raw

PATCH v2 6/6 arm/imx6q: add suspend/resume support

In reply to Shawn Guo

It adds suspend/resume support for imx6q.

---
 arch/arm/mach-imx/Makefile              |    2 +-
 arch/arm/mach-imx/head-v7.S             |   27 +++++++++
 arch/arm/mach-imx/pm-imx6q.c            |   88 +++++++++++++++++++++++++++++++
 arch/arm/plat-mxc/include/mach/common.h |    8 +++
 4 files changed, 124 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-imx/pm-imx6q.c
arch/arm/mach-imx/Makefile +1 -1
index 16737ba..c787151 100644
@@ -70,4 +70,4 @@ obj-$(CONFIG_CPU_V7) += head-v7.o
 obj-$(CONFIG_SMP) += platsmp.o
 obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
 obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
-obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o
+obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o pm-imx6q.o
arch/arm/mach-imx/head-v7.S +27 -0
index ede908b..0a86685 100644
@@ -69,3 +69,30 @@ ENTRY(v7_secondary_startup)
 	b	secondary_startup
 ENDPROC(v7_secondary_startup)
 #endif
+
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+
+	/*
+	 * Restore L2 AUX_CTRL register saved by suspend procedure
+	 * and enable L2
+	 */
+	adr	r4, 1f
+	ldmia	r4, {r5, r6, r7}
+	sub	r4, r4, r5
+	add	r6, r6, r4
+	add	r7, r7, r4
+	ldr	r0, [r6]
+	ldr	r7, [r7]
+	ldr	r1, [r7]
+	str	r1, [r0, #L2X0_AUX_CTRL]
+	ldr	r1, =0x1
+	str	r1, [r0, #L2X0_CTRL]
+
+	b	cpu_resume
+
+	.align
+1:	.long	.
+	.long	pl310_pbase
+	.long	pl310_aux_ctrl_paddr
+ENDPROC(v7_cpu_resume)
arch/arm/mach-imx/pm-imx6q.c new file +88 -0

88 lines not on this page · raw message

arch/arm/plat-mxc/include/mach/common.h +8 -0
index 9c5be7b..6673d7d 100644
@@ -13,6 +13,7 @@
 
 struct platform_device;
 struct clk;
+enum mxc_cpu_pwr_mode;
 
 extern void mx1_map_io(void);
 extern void mx21_map_io(void);
@@ -79,14 +80,21 @@ extern void imx_lluart_map_io(void);
 #else
 static inline void imx_lluart_map_io(void) {}
 #endif
+extern void v7_cpu_resume(void);
 #ifdef CONFIG_SMP
 extern void v7_secondary_startup(void);
 extern void imx_scu_map_io(void);
+extern void imx_smp_prepare(void);
 #else
 static inline void imx_scu_map_io(void) {}
+static inline void imx_smp_prepare(void) {}
 #endif
 extern void imx_enable_cpu(int cpu, bool enable);
 extern void imx_set_cpu_jump(int cpu, void *jump_addr);
 extern void imx_src_init(void);
 extern void imx_gpc_init(void);
+extern void imx_gpc_pre_suspend(void);
+extern void imx_gpc_post_resume(void);
+extern int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode);
+extern void imx6q_pm_init(void);
 #endif
Signature · 1 line
1.7.4.1
#12 lore raw

PATCH v2 6/6 arm/imx6q: add suspend/resume support

Quoted 46 lines · Shawn Guo

It adds suspend/resume support for imx6q.

---
 arch/arm/mach-imx/Makefile              |    2 +-
 arch/arm/mach-imx/head-v7.S             |   27 +++++++++
 arch/arm/mach-imx/pm-imx6q.c            |   88 +++++++++++++++++++++++++++++++
 arch/arm/plat-mxc/include/mach/common.h |    8 +++
 4 files changed, 124 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-imx/pm-imx6q.c
arch/arm/mach-imx/Makefile +1 -1
index 16737ba..c787151 100644
@@ -70,4 +70,4 @@ obj-$(CONFIG_CPU_V7) += head-v7.o
 obj-$(CONFIG_SMP) += platsmp.o
 obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
 obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
-obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o
+obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o pm-imx6q.o
arch/arm/mach-imx/head-v7.S +16 -0
index ede908b..0a86685 100644
@@ -69,3 +69,30 @@ ENTRY(v7_secondary_startup)
 	b	secondary_startup
 ENDPROC(v7_secondary_startup)
 #endif
+
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+
+	/*
+	 * Restore L2 AUX_CTRL register saved by suspend procedure
+	 * and enable L2
+	 */
+	adr	r4, 1f
+	ldmia	r4, {r5, r6, r7}
+	sub	r4, r4, r5
+	add	r6, r6, r4
+	add	r7, r7, r4
+	ldr	r0, [r6]
+	ldr	r7, [r7]
+	ldr	r1, [r7]

arch/arm/mach-imx/head-v7.S ENTRY(v7_secondary_startup) · line 97

Quoted 10 lines
arch/arm/mach-imx/head-v7.S +10 -0
+	str	r1, [r0, #L2X0_AUX_CTRL]
+	ldr	r1, =0x1
+	str	r1, [r0, #L2X0_CTRL]
+
+	b	cpu_resume
+
+	.align
+1:	.long	.
+	.long	pl310_pbase
+	.long	pl310_aux_ctrl_paddr

Would not something like:

	adr	r4, pl310_pbase
	ldmia	r4, {r6, r7}
	[...]

pl310_pbase:

	.long 0
pl310_aux_ctrl:
	.long 0

be better and faster ? Why play with virtual addresses ?
Of course you should initialize the values, but then you can access them through a PC relative load when running physical.
Your code should be in the .data section for it to be writable (adr does not work across sections), have a look at Russell's code in sleep.S it is very well commented and similar to what you need.

Quoted 24 lines
arch/arm/mach-imx/head-v7.S +1 -0
+ENDPROC(v7_cpu_resume)
arch/arm/mach-imx/pm-imx6q.c new file +17 -0
new file mode 100644
index 0000000..124bcd5
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/suspend.h>
+#include <asm/proc-fns.h>

arch/arm/mach-imx/pm-imx6q.c line 27

Quoted 10 lines
arch/arm/mach-imx/pm-imx6q.c new file +10 -0
+#include <asm/suspend.h>
+#include <asm/hardware/cache-l2x0.h>
+#include <mach/common.h>
+#include <mach/hardware.h>
+
+static void __iomem *pl310_vbase;
+void __iomem *pl310_pbase;
+
+static volatile unsigned long pl310_aux_ctrl;
+volatile unsigned long pl310_aux_ctrl_paddr;

I think that by defining those variables in assembly you would make your life much simpler.
I think you know your L2 is already initialized here to make sure you save the right aux value. Hence you should clean the variables above from L2 to make sure they are available at reset from DRAM (L2 is retained and you do not clean it on suspend, correct ?)

I do not think that code to save/restore L2 config belongs here though. More below.

Quoted 29 lines
arch/arm/mach-imx/pm-imx6q.c new file +29 -0
+
+static int imx6q_suspend_finish(unsigned long val)
+{
+	cpu_do_idle();
+	return 0;
+}
+
+static int imx6q_pm_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_MEM:
+		imx6q_set_lpm(STOP_POWER_OFF);
+		imx_gpc_pre_suspend();
+		imx_set_cpu_jump(0, v7_cpu_resume);
+		/* Zzz ... */
+		cpu_suspend(0, imx6q_suspend_finish);
+		imx_smp_prepare();
+		imx_gpc_post_resume();
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct platform_suspend_ops imx6q_pm_ops = {
+	.enter = imx6q_pm_enter,
+	.valid = suspend_valid_only_mem,

arch/arm/mach-imx/pm-imx6q.c line 66

Quoted 10 lines
arch/arm/mach-imx/pm-imx6q.c new file +10 -0
+};
+
+void __init imx6q_pm_init(void)
+{
+	struct device_node *np;
+	u32 reg[2];
+
+	np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache");
+	of_property_read_u32_array(np, "reg", reg, ARRAY_SIZE(reg));
+	pl310_vbase = ioremap(reg[0], reg[1]);

Mmmm...is this vma ever released ? L2 is already mapped in the L2 driver from DT or through static mappings.
Overall, I think that code to restore PL310 belongs in cache-l2x0.c, not here. We can easily write an assembly stub that reinitialize L2 before resume if that's something we should and can do (security ?).

Lorenzo

#13 lore raw

PATCH v2 6/6 arm/imx6q: add suspend/resume support

Hi Lorenzo,

Quoted 64 lines · Lorenzo Pieralisi
Quoted 46 lines · Shawn Guo

It adds suspend/resume support for imx6q.

---
 arch/arm/mach-imx/Makefile              |    2 +-
 arch/arm/mach-imx/head-v7.S             |   27 +++++++++
 arch/arm/mach-imx/pm-imx6q.c            |   88 +++++++++++++++++++++++++++++++
 arch/arm/plat-mxc/include/mach/common.h |    8 +++
 4 files changed, 124 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-imx/pm-imx6q.c
arch/arm/mach-imx/Makefile +1 -1
index 16737ba..c787151 100644
@@ -70,4 +70,4 @@ obj-$(CONFIG_CPU_V7) += head-v7.o
 obj-$(CONFIG_SMP) += platsmp.o
 obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
 obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
-obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o
+obj-$(CONFIG_SOC_IMX6Q) += clock-imx6q.o mach-imx6q.o pm-imx6q.o
arch/arm/mach-imx/head-v7.S +16 -0
index ede908b..0a86685 100644
@@ -69,3 +69,30 @@ ENTRY(v7_secondary_startup)
 	b	secondary_startup
 ENDPROC(v7_secondary_startup)
 #endif
+
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+
+	/*
+	 * Restore L2 AUX_CTRL register saved by suspend procedure
+	 * and enable L2
+	 */
+	adr	r4, 1f
+	ldmia	r4, {r5, r6, r7}
+	sub	r4, r4, r5
+	add	r6, r6, r4
+	add	r7, r7, r4
+	ldr	r0, [r6]
+	ldr	r7, [r7]
+	ldr	r1, [r7]

arch/arm/mach-imx/head-v7.S ENTRY(v7_secondary_startup) · line 97

Quoted 10 lines
arch/arm/mach-imx/head-v7.S +10 -0
+	str	r1, [r0, #L2X0_AUX_CTRL]
+	ldr	r1, =0x1
+	str	r1, [r0, #L2X0_CTRL]
+
+	b	cpu_resume
+
+	.align
+1:	.long	.
+	.long	pl310_pbase
+	.long	pl310_aux_ctrl_paddr

Would not something like:

	adr	r4, pl310_pbase
	ldmia	r4, {r6, r7}
	[...]
Quoted 8 lines

pl310_pbase:

	.long 0
pl310_aux_ctrl:
	.long 0

be better and faster ? Why play with virtual addresses ?
Of course you should initialize the values, but then you can access them through a PC relative load when running physical.

Thanks for the comment. I agree with you that it's better, though my first thought on the existing approach is I can access the global variables defined in C file directly from assembly code.

Quoted 3 lines

Your code should be in the .data section for it to be writable (adr does not work across sections), have a look at Russell's code in sleep.S it is very well commented and similar to what you need.

Thanks for pointing me the example.

Quoted 30 lines
Quoted 30 lines
arch/arm/mach-imx/head-v7.S +1 -0
+ENDPROC(v7_cpu_resume)
arch/arm/mach-imx/pm-imx6q.c new file +22 -0
new file mode 100644
index 0000000..124bcd5
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/suspend.h>
+#include <asm/proc-fns.h>
+#include <asm/suspend.h>
+#include <asm/hardware/cache-l2x0.h>
+#include <mach/common.h>
+#include <mach/hardware.h>
+
Quoted 8 lines

arch/arm/mach-imx/pm-imx6q.c line 27

Quoted 5 lines
arch/arm/mach-imx/pm-imx6q.c new file +5 -0
+static void __iomem *pl310_vbase;
+void __iomem *pl310_pbase;
+
+static volatile unsigned long pl310_aux_ctrl;
+volatile unsigned long pl310_aux_ctrl_paddr;

I think that by defining those variables in assembly you would make your life much simpler.

Yes. But I need a function call to learn the address of those variables from assembly now.

Quoted 4 lines

I think you know your L2 is already initialized here to make sure you save the right aux value. Hence you should clean the variables above from L2 to make sure they are available at reset from DRAM (L2 is retained and you do not clean it on suspend, correct ?)

Yes, agreed. It's right thing to do for being safe. Actually, I did it when I saved the variables during suspend. If I do not do, it simply does not work. But later, when I moved the saving to init function since it needs to be done for only once, I found it works even without the cache clean. Then I dropped it. To be safe, now I'm adding it back with following your comment.

Quoted 38 lines

I do not think that code to save/restore L2 config belongs here though. More below.

Quoted 34 lines
arch/arm/mach-imx/pm-imx6q.c new file +34 -0
+
+static int imx6q_suspend_finish(unsigned long val)
+{
+	cpu_do_idle();
+	return 0;
+}
+
+static int imx6q_pm_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_MEM:
+		imx6q_set_lpm(STOP_POWER_OFF);
+		imx_gpc_pre_suspend();
+		imx_set_cpu_jump(0, v7_cpu_resume);
+		/* Zzz ... */
+		cpu_suspend(0, imx6q_suspend_finish);
+		imx_smp_prepare();
+		imx_gpc_post_resume();
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct platform_suspend_ops imx6q_pm_ops = {
+	.enter = imx6q_pm_enter,
+	.valid = suspend_valid_only_mem,
+};
+
+void __init imx6q_pm_init(void)
+{
+	struct device_node *np;
Quoted 8 lines

arch/arm/mach-imx/pm-imx6q.c line 66

Quoted 5 lines
arch/arm/mach-imx/pm-imx6q.c new file +5 -0
+	u32 reg[2];
+
+	np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache");
+	of_property_read_u32_array(np, "reg", reg, ARRAY_SIZE(reg));
+	pl310_vbase = ioremap(reg[0], reg[1]);

Mmmm...is this vma ever released ? L2 is already mapped in the L2 driver from DT or through static mappings.

I think we can do another mapping even it's been done in the L2 driver, no?

Quoted 4 lines

Overall, I think that code to restore PL310 belongs in cache-l2x0.c, not here. We can easily write an assembly stub that reinitialize L2 before resume if that's something we should and can do (security ?).

I would be definitely happy to see that, but before rmk agrees on that, I have to find a way around in the platform code.

Here is the updated patch. If it looks better to you, I will incorporate it in the v3 of the series.

8<---

arch/arm/mach-imx/head-v7.S +32 -0
index ede908b..5a486a9 100644
@@ -69,3 +69,35 @@ ENTRY(v7_secondary_startup)
 	b	secondary_startup
 ENDPROC(v7_secondary_startup)
 #endif
+
+ENTRY(pl310_get_save_ptr)
+	ldr	r0, =pl310_pbase
+	mov	pc, lr
+ENDPROC(pl310_get_save_ptr)
+
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+	bl	pl310_resume
+	b	cpu_resume
+ENDPROC(v7_cpu_resume)
+
+/*
+ * The following code is located into the .data section.  This is to
+ * allow pl310_pbase and pl310_aux_ctrl to be accessed with a relative
+ * load as we are running on physical address here.
+ */
+	.data
+	.align
+ENTRY(pl310_resume)
+	adr	r2, pl310_pbase
+	ldmia	r2, {r0, r1}
+	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
+	mov	r1, #0x1
+	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
+	mov	pc, lr
+ENDPROC(pl310_resume)
+
+pl310_pbase:
+	.long	0
+pl310_aux_ctrl:
+	.long	0
arch/arm/mach-imx/pm-imx6q.c new file +88 -0

88 lines not on this page · raw message

Signature · 2 lines
Regards,
Shawn
#14 lore raw

PATCH v2 6/6 arm/imx6q: add suspend/resume support

Hi Shawn,

Quoted 9 lines · Shawn Guo

Hi Lorenzo,

Quoted 6 lines · Lorenzo Pieralisi
Quoted 5 lines · Shawn Guo

It adds suspend/resume support for imx6q.

---

[...]

Quoted 37 lines
Quoted 37 lines
Quoted 15 lines
(quoted diff) +15 -0
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+
+	/*
+	 * Restore L2 AUX_CTRL register saved by suspend procedure
+	 * and enable L2
+	 */
+	adr	r4, 1f
+	ldmia	r4, {r5, r6, r7}
+	sub	r4, r4, r5
+	add	r6, r6, r4
+	add	r7, r7, r4
+	ldr	r0, [r6]
+	ldr	r7, [r7]
+	ldr	r1, [r7]

Review

Quoted 10 lines
(quoted diff) +10 -0
+	str	r1, [r0, #L2X0_AUX_CTRL]
+	ldr	r1, =0x1
+	str	r1, [r0, #L2X0_CTRL]
+
+	b	cpu_resume
+
+	.align
+1:	.long	.
+	.long	pl310_pbase
+	.long	pl310_aux_ctrl_paddr

Would not something like:

	adr	r4, pl310_pbase
	ldmia	r4, {r6, r7}
	[...]

pl310_pbase:

	.long 0
pl310_aux_ctrl:
	.long 0
Quoted 8 lines
Quoted 3 lines

be better and faster ? Why play with virtual addresses ?
Of course you should initialize the values, but then you can access them through a PC relative load when running physical.

Thanks for the comment. I agree with you that it's better, though my first thought on the existing approach is I can access the global variables defined in C file directly from assembly code.

You can even access assembly variables from C code, declare them

	.globl pl310_base

and

extern unsigned int pl310_base;

in your C code and you are all set. But I would avoid global variables, comments below.

Quoted 6 lines
Quoted 3 lines

Your code should be in the .data section for it to be writable (adr does not work across sections), have a look at Russell's code in sleep.S it is very well commented and similar to what you need.

Thanks for pointing me the example.

You are welcome, my pleasure.

Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
arch/arm/mach-imx/head-v7.S +1 -0
+ENDPROC(v7_cpu_resume)
arch/arm/mach-imx/pm-imx6q.c new file +22 -0
new file mode 100644
index 0000000..124bcd5
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/suspend.h>
+#include <asm/proc-fns.h>
+#include <asm/suspend.h>
+#include <asm/hardware/cache-l2x0.h>
+#include <mach/common.h>
+#include <mach/hardware.h>
+
Quoted 8 lines

arch/arm/mach-imx/pm-imx6q.c line 27

Quoted 5 lines
arch/arm/mach-imx/pm-imx6q.c new file +5 -0
+static void __iomem *pl310_vbase;
+void __iomem *pl310_pbase;
+
+static volatile unsigned long pl310_aux_ctrl;
+volatile unsigned long pl310_aux_ctrl_paddr;

I think that by defining those variables in assembly you would make your life much simpler.

Quoted 3 lines

Yes. But I need a function call to learn the address of those variables from assembly now.

No, you do not, see above.

Quoted 59 lines
Quoted 4 lines

I think you know your L2 is already initialized here to make sure you save the right aux value. Hence you should clean the variables above from L2 to make sure they are available at reset from DRAM (L2 is retained and you do not clean it on suspend, correct ?)

Yes, agreed. It's right thing to do for being safe. Actually, I did it when I saved the variables during suspend. If I do not do, it simply does not work. But later, when I moved the saving to init function since it needs to be done for only once, I found it works even without the cache clean. Then I dropped it. To be safe, now I'm adding it back with following your comment.

Quoted 38 lines

I do not think that code to save/restore L2 config belongs here though. More below.

Quoted 34 lines
arch/arm/mach-imx/pm-imx6q.c new file +34 -0
+
+static int imx6q_suspend_finish(unsigned long val)
+{
+	cpu_do_idle();
+	return 0;
+}
+
+static int imx6q_pm_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_MEM:
+		imx6q_set_lpm(STOP_POWER_OFF);
+		imx_gpc_pre_suspend();
+		imx_set_cpu_jump(0, v7_cpu_resume);
+		/* Zzz ... */
+		cpu_suspend(0, imx6q_suspend_finish);
+		imx_smp_prepare();
+		imx_gpc_post_resume();
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct platform_suspend_ops imx6q_pm_ops = {
+	.enter = imx6q_pm_enter,
+	.valid = suspend_valid_only_mem,
+};
+
+void __init imx6q_pm_init(void)
+{
+	struct device_node *np;
Quoted 8 lines

arch/arm/mach-imx/pm-imx6q.c

Quoted 5 lines
arch/arm/mach-imx/pm-imx6q.c new file +5 -0
+	u32 reg[2];
+
+	np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache");
+	of_property_read_u32_array(np, "reg", reg, ARRAY_SIZE(reg));
+	pl310_vbase = ioremap(reg[0], reg[1]);

Mmmm...is this vma ever released ? L2 is already mapped in the L2 driver from DT or through static mappings.

Quoted 3 lines

I think we can do another mapping even it's been done in the L2 driver, no?

I still think that it is not really clean. But more importantly you should release the mapping when you are done with it (iounmap).

Quoted 6 lines
Quoted 4 lines

Overall, I think that code to restore PL310 belongs in cache-l2x0.c, not here. We can easily write an assembly stub that reinitialize L2 before resume if that's something we should and can do (security ?).

I would be definitely happy to see that, but before rmk agrees on that, I have to find a way around in the platform code.

I am working on that; your point is fair, but security notwithstanding there is nothing that can prevent us from having an assembly hook to resume L2 in a platform independent manner. More to come.

Quoted 10 lines

Here is the updated patch. If it looks better to you, I will incorporate it in the v3 of the series.

8<---

arch/arm/mach-imx/head-v7.S +0 -0
index ede908b..5a486a9 100644

arch/arm/mach-imx/head-v7.S ENTRY(v7_secondary_startup) · line 77

Quoted 9 lines
arch/arm/mach-imx/head-v7.S +6 -0
@@ -69,3 +69,35 @@ ENTRY(v7_secondary_startup)
 	b	secondary_startup
 ENDPROC(v7_secondary_startup)
 #endif
+
+ENTRY(pl310_get_save_ptr)
+	ldr	r0, =pl310_pbase
+	mov	pc, lr
+ENDPROC(pl310_get_save_ptr)
+

You do not need a function to do that. Just declare the label as

.globl

and from C you can access those values. See above.

It would be nicer to avoid global variables altogether though. You can write an assembly function taking the values to be saved and returning the pointer to flush from L1 and L2.

Quoted 16 lines
arch/arm/mach-imx/head-v7.S +16 -0
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+	bl	pl310_resume
+	b	cpu_resume
+ENDPROC(v7_cpu_resume)
+
+/*
+ * The following code is located into the .data section.  This is to
+ * allow pl310_pbase and pl310_aux_ctrl to be accessed with a relative
+ * load as we are running on physical address here.
+ */
+	.data
+	.align
+ENTRY(pl310_resume)
+	adr	r2, pl310_pbase
+	ldmia	r2, {r0, r1}

arch/arm/mach-imx/head-v7.S ENTRY(v7_secondary_startup) · line 103

Quoted 10 lines
arch/arm/mach-imx/head-v7.S +10 -0
+	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
+	mov	r1, #0x1
+	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
+	mov	pc, lr
+ENDPROC(pl310_resume)
+
+pl310_pbase:
+	.long	0
+pl310_aux_ctrl:
+	.long	0

You might want to inline it and avoid the jump.

I still think that we should try to generalize the approach, security issues notwithstanding.

Lorenzo

#15 lore raw

PATCH v2 6/6 arm/imx6q: add suspend/resume support

Quoted 63 lines · Lorenzo Pieralisi

Hi Shawn,

Quoted 9 lines · Shawn Guo

Hi Lorenzo,

Quoted 6 lines · Lorenzo Pieralisi
Quoted 5 lines · Shawn Guo

It adds suspend/resume support for imx6q.

---

[...]

Quoted 37 lines
Quoted 37 lines
Quoted 15 lines
(quoted diff) +15 -0
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+
+	/*
+	 * Restore L2 AUX_CTRL register saved by suspend procedure
+	 * and enable L2
+	 */
+	adr	r4, 1f
+	ldmia	r4, {r5, r6, r7}
+	sub	r4, r4, r5
+	add	r6, r6, r4
+	add	r7, r7, r4
+	ldr	r0, [r6]
+	ldr	r7, [r7]
+	ldr	r1, [r7]

Review

Quoted 10 lines
(quoted diff) +10 -0
+	str	r1, [r0, #L2X0_AUX_CTRL]
+	ldr	r1, =0x1
+	str	r1, [r0, #L2X0_CTRL]
+
+	b	cpu_resume
+
+	.align
+1:	.long	.
+	.long	pl310_pbase
+	.long	pl310_aux_ctrl_paddr

Would not something like:

	adr	r4, pl310_pbase
	ldmia	r4, {r6, r7}
	[...]

pl310_pbase:

	.long 0
pl310_aux_ctrl:
	.long 0
Quoted 8 lines
Quoted 3 lines

be better and faster ? Why play with virtual addresses ?
Of course you should initialize the values, but then you can access them through a PC relative load when running physical.

Thanks for the comment. I agree with you that it's better, though my first thought on the existing approach is I can access the global variables defined in C file directly from assembly code.

You can even access assembly variables from C code, declare them

Quoted 9 lines
	.globl pl310_base

and

extern unsigned int pl310_base;

in your C code and you are all set. But I would avoid global variables, comments below.

Ah, thanks. As you can see, I'm still at entry level of assembly :)

Quoted 113 lines
Quoted 6 lines
Quoted 3 lines

Your code should be in the .data section for it to be writable (adr does not work across sections), have a look at Russell's code in sleep.S it is very well commented and similar to what you need.

Thanks for pointing me the example.

You are welcome, my pleasure.

Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
arch/arm/mach-imx/head-v7.S +1 -0
+ENDPROC(v7_cpu_resume)
arch/arm/mach-imx/pm-imx6q.c new file +22 -0
new file mode 100644
index 0000000..124bcd5
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/suspend.h>
+#include <asm/proc-fns.h>
+#include <asm/suspend.h>
+#include <asm/hardware/cache-l2x0.h>
+#include <mach/common.h>
+#include <mach/hardware.h>
+
Quoted 8 lines

arch/arm/mach-imx/pm-imx6q.c line 27

Quoted 5 lines
arch/arm/mach-imx/pm-imx6q.c new file +5 -0
+static void __iomem *pl310_vbase;
+void __iomem *pl310_pbase;
+
+static volatile unsigned long pl310_aux_ctrl;
+volatile unsigned long pl310_aux_ctrl_paddr;

I think that by defining those variables in assembly you would make your life much simpler.

Quoted 3 lines

Yes. But I need a function call to learn the address of those variables from assembly now.

No, you do not, see above.

Quoted 59 lines
Quoted 4 lines

I think you know your L2 is already initialized here to make sure you save the right aux value. Hence you should clean the variables above from L2 to make sure they are available at reset from DRAM (L2 is retained and you do not clean it on suspend, correct ?)

Yes, agreed. It's right thing to do for being safe. Actually, I did it when I saved the variables during suspend. If I do not do, it simply does not work. But later, when I moved the saving to init function since it needs to be done for only once, I found it works even without the cache clean. Then I dropped it. To be safe, now I'm adding it back with following your comment.

Quoted 46 lines

I do not think that code to save/restore L2 config belongs here though. More below.

Quoted 29 lines
arch/arm/mach-imx/pm-imx6q.c new file +29 -0
+
+static int imx6q_suspend_finish(unsigned long val)
+{
+	cpu_do_idle();
+	return 0;
+}
+
+static int imx6q_pm_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_MEM:
+		imx6q_set_lpm(STOP_POWER_OFF);
+		imx_gpc_pre_suspend();
+		imx_set_cpu_jump(0, v7_cpu_resume);
+		/* Zzz ... */
+		cpu_suspend(0, imx6q_suspend_finish);
+		imx_smp_prepare();
+		imx_gpc_post_resume();
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct platform_suspend_ops imx6q_pm_ops = {
+	.enter = imx6q_pm_enter,
+	.valid = suspend_valid_only_mem,

arch/arm/mach-imx/pm-imx6q.c

Quoted 10 lines
arch/arm/mach-imx/pm-imx6q.c new file +10 -0
+};
+
+void __init imx6q_pm_init(void)
+{
+	struct device_node *np;
+	u32 reg[2];
+
+	np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache");
+	of_property_read_u32_array(np, "reg", reg, ARRAY_SIZE(reg));
+	pl310_vbase = ioremap(reg[0], reg[1]);

Mmmm...is this vma ever released ? L2 is already mapped in the L2 driver from DT or through static mappings.

Quoted 7 lines
Quoted 3 lines

I think we can do another mapping even it's been done in the L2 driver, no?

I still think that it is not really clean. But more importantly you should release the mapping when you are done with it (iounmap).

Yes, I should iounmap it.

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

Overall, I think that code to restore PL310 belongs in cache-l2x0.c, not here. We can easily write an assembly stub that reinitialize L2 before resume if that's something we should and can do (security ?).

I would be definitely happy to see that, but before rmk agrees on that, I have to find a way around in the platform code.

I am working on that; your point is fair, but security notwithstanding there is nothing that can prevent us from having an assembly hook to resume L2 in a platform independent manner. More to come.

Great. I will definitely migrate imx6q to that once it gets merged.

Quoted 22 lines
Quoted 10 lines

Here is the updated patch. If it looks better to you, I will incorporate it in the v3 of the series.

8<---

arch/arm/mach-imx/head-v7.S +0 -0
index ede908b..5a486a9 100644

arch/arm/mach-imx/head-v7.S ENTRY(v7_secondary_startup) · line 77

Quoted 9 lines
arch/arm/mach-imx/head-v7.S +6 -0
@@ -69,3 +69,35 @@ ENTRY(v7_secondary_startup)
 	b	secondary_startup
 ENDPROC(v7_secondary_startup)
 #endif
+
+ENTRY(pl310_get_save_ptr)
+	ldr	r0, =pl310_pbase
+	mov	pc, lr
+ENDPROC(pl310_get_save_ptr)
+

You do not need a function to do that. Just declare the label as

Quoted 8 lines

.globl

and from C you can access those values. See above.

It would be nicer to avoid global variables altogether though. You can write an assembly function taking the values to be saved and returning the pointer to flush from L1 and L2.

Thanks for the suggestion. But I feel good about the current implementation.

Quoted 20 lines
Quoted 20 lines
arch/arm/mach-imx/head-v7.S +20 -0
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+	bl	pl310_resume
+	b	cpu_resume
+ENDPROC(v7_cpu_resume)
+
+/*
+ * The following code is located into the .data section.  This is to
+ * allow pl310_pbase and pl310_aux_ctrl to be accessed with a relative
+ * load as we are running on physical address here.
+ */
+	.data
+	.align
+ENTRY(pl310_resume)
+	adr	r2, pl310_pbase
+	ldmia	r2, {r0, r1}
+	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
+	mov	r1, #0x1
+	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
+	mov	pc, lr
Quoted 9 lines

arch/arm/mach-imx/head-v7.S ENTRY(v7_secondary_startup) · line 103

Quoted 6 lines
arch/arm/mach-imx/head-v7.S +6 -0
+ENDPROC(pl310_resume)
+
+pl310_pbase:
+	.long	0
+pl310_aux_ctrl:
+	.long	0

You might want to inline it and avoid the jump.

One reason that I implemented pl310_resume as a function call is that I was trying to minimize the code that we have to put in .data section. Now I do not think it's a point that really matters. So following your suggestion, here it is. Please let me know it is not what you meant to see.

/*
* The following code is located into the .data section. This is to
* allow pl310_pbase and pl310_aux_ctrl to be accessed with a relative
* load as we are running on physical address here.
*/

        .data
        .align

        .macro  pl310_resume
        adr     r2, pl310_pbase
        ldmia   r2, {r0, r1}
        str     r1, [r0, #L2X0_AUX_CTRL]        @ restore aux_ctrl
        mov     r1, #0x1
        str     r1, [r0, #L2X0_CTRL]            @ re-enable L2
        .endm

ENTRY(v7_cpu_resume)

        bl      v7_invalidate_l1
        pl310_resume
        b       cpu_resume

ENDPROC(v7_cpu_resume)

.globl
pl310_pbase:
.long 0
pl310_aux_ctrl:
.long 0

Signature · 2 lines
Regards,
Shawn
#16 lore raw

PATCH v2 6/6 arm/imx6q: add suspend/resume support

On Sat, Sep 17, 2011 at 04:30:09PM +0800, Shawn Guo wrote:
[...]

Quoted 51 lines
Quoted 20 lines
Quoted 20 lines
arch/arm/mach-imx/head-v7.S +20 -0
+ENTRY(v7_cpu_resume)
+	bl	v7_invalidate_l1
+	bl	pl310_resume
+	b	cpu_resume
+ENDPROC(v7_cpu_resume)
+
+/*
+ * The following code is located into the .data section.  This is to
+ * allow pl310_pbase and pl310_aux_ctrl to be accessed with a relative
+ * load as we are running on physical address here.
+ */
+	.data
+	.align
+ENTRY(pl310_resume)
+	adr	r2, pl310_pbase
+	ldmia	r2, {r0, r1}
+	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
+	mov	r1, #0x1
+	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
+	mov	pc, lr
Quoted 9 lines

arch/arm/mach-imx/head-v7.S ENTRY(v7_secondary_startup) · line 103

Quoted 6 lines
arch/arm/mach-imx/head-v7.S +6 -0
+ENDPROC(pl310_resume)
+
+pl310_pbase:
+	.long	0
+pl310_aux_ctrl:
+	.long	0

You might want to inline it and avoid the jump.

One reason that I implemented pl310_resume as a function call is that I was trying to minimize the code that we have to put in .data section. Now I do not think it's a point that really matters. So following your suggestion, here it is. Please let me know it is not what you meant to see.

/*
* The following code is located into the .data section. This is to
* allow pl310_pbase and pl310_aux_ctrl to be accessed with a relative
* load as we are running on physical address here.
*/

        .data
        .align

        .macro  pl310_resume
        adr     r2, pl310_pbase
        ldmia   r2, {r0, r1}
        str     r1, [r0, #L2X0_AUX_CTRL]        @ restore aux_ctrl
        mov     r1, #0x1
        str     r1, [r0, #L2X0_CTRL]            @ re-enable L2
        .endm
Quoted 7 lines

ENTRY(v7_cpu_resume)

        bl      v7_invalidate_l1
        pl310_resume
        b       cpu_resume

ENDPROC(v7_cpu_resume)

.globl

Sorry. This is a left-over of .globl playing, which should not be here.

Quoted 5 lines

pl310_pbase:
.long 0
pl310_aux_ctrl:
.long 0

Signature · 2 lines
Regards,
Shawn
#17 lore raw

PATCH v2 6/6 arm/imx6q: add suspend/resume support

In reply to Shawn Guo
Quoted 13 lines · Shawn Guo
Quoted 12 lines · Lorenzo Pieralisi

Hi Shawn,

Quoted 9 lines · Shawn Guo

Hi Lorenzo,

Quoted 6 lines · Lorenzo Pieralisi
Quoted 5 lines · Shawn Guo

It adds suspend/resume support for imx6q.

---

[...]

Quoted 26 lines

One reason that I implemented pl310_resume as a function call is that I was trying to minimize the code that we have to put in .data section. Now I do not think it's a point that really matters. So following your suggestion, here it is. Please let me know it is not what you meant to see.

/*
* The following code is located into the .data section. This is to
* allow pl310_pbase and pl310_aux_ctrl to be accessed with a relative
* load as we are running on physical address here.
*/

        .data
        .align

        .macro  pl310_resume
        adr     r2, pl310_pbase
        ldmia   r2, {r0, r1}
        str     r1, [r0, #L2X0_AUX_CTRL]        @ restore aux_ctrl
        mov     r1, #0x1
        str     r1, [r0, #L2X0_CTRL]            @ re-enable L2
        .endm

ENTRY(v7_cpu_resume)

        bl      v7_invalidate_l1
        pl310_resume
        b       cpu_resume
Quoted 7 lines

ENDPROC(v7_cpu_resume)

.globl
pl310_pbase:
.long 0
pl310_aux_ctrl:
.long 0

Yes, it does look simpler and better to me, but I still think there are going to be other platforms doing the same precise thing if they run secure, so we may want to generalize it; let's discuss it and converge.

Thanks for reworking it,
Lorenzo