Skip to contentSkip to conversation

ARM: vf610: Suspend/resume with self-refresh mode

PATCH In review Stefan Agner 6 participants 41 messages Mar 10, 2016 – Apr 1, 2016

Subsystems (12)
lore
Share & tools
lore

Stefan Agner

author reviewer
#0 lore raw

cover ARM: vf610: Suspend/resume with self-refresh mode

This is a reworked and extended respin of an older patchset posted back in 2014:
http://lkml.iu.edu/hypermail/linux/kernel/1409.2/03734.html

This implementation supports Vybrids STOP (standby) and LPSTOP2 mode (mem). Only the latter puts the memory in self-refresh mode and the SoC in a deep sleep state. However, self-refresh is only supported if external pull-ups/downs are populated (which not all hardware revisions have in place), therefor this patchset also introduces a device tree property to denote whether memory can be put into self-refresh mode or not.

The LPSTOP2 implementation is similar to the i.MX 6 implementation:
Entering and resuming from self-refresh mode is implemented in assembler, and the function is copied to SRAM while entering suspend mode.

There are several fixes and extensions necessary to make suspend actually working, mainly because most blocks loose its state in LPSTOP2 mode.

Feedback welcome! Especially the linking between the GPIOs of the WKPU unit (which allows to use some GPIOs as wake-up source) and the regular GPIO block seems rather hacky...

The code has been tested on a Colibri VF50 and VF61. Currently there is an issue with USB Host not correctly restoring after resume which could not yet been resolved.

Stefan Agner (18):
irqchip: vf610-gpc: add Vybrid GPC IRQ controller
ARM: dts: vf610: add GPC as new interrupt parent
ARM: dts: vf610-colibri: GPIO wakeup key
ARM: dts: vf610: add on-chip SRAM
ARM: dts: vf610: add modules required for PM
ARM: imx: clk-gate2: allow custom gate configuration
ARM: imx: clk-vf610: leave DDR clock on
ARM: clk: add WKPU unit
ARM: vf610: clk: add suspend/resume support
tty: serial: fsl_lpuart: support suspend/resume
pinctrl: pinctrl-imx: implement suspend/resume
gpio: vf610: add system PM suspend/resume
ARM: dts: vf610: add WKPU connection to GPIO
gpio: vf610: add support for WKPU unit
ARM: vf610: PM: initial suspend/resume support
ARM: vf610: PM: enable Suspend-to-RAM only if hardware fixes are in
place
Documentation: dt: add Vybrid DDR memory controller bindings
ARM: vf610: PM: enable SNVS access

 .../bindings/arm/freescale/fsl,vf610-ddrmc.txt     |  23 +
 .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
 arch/arm/boot/dts/vf-colibri-eval-v3.dtsi          |  22 +
 arch/arm/boot/dts/vfxxx.dtsi                       |  74 ++-
 arch/arm/mach-imx/Makefile                         |   3 +
 arch/arm/mach-imx/common.h                         |  10 +
 arch/arm/mach-imx/mach-vf610.c                     |   8 +
 arch/arm/mach-imx/pm-vf610.c                       | 649 +++++++++++++++++++++
 arch/arm/mach-imx/suspend-vf610.S                  | 448 ++++++++++++++
 drivers/clk/imx/clk-gate2.c                        |   7 +-
 drivers/clk/imx/clk-vf610.c                        |  83 ++-
 drivers/clk/imx/clk.h                              |  13 +-
 drivers/gpio/gpio-vf610.c                          | 188 ++++++
 drivers/irqchip/Makefile                           |   1 +
 drivers/irqchip/irq-vf610-gpc.c                    | 138 +++++
 drivers/pinctrl/freescale/pinctrl-imx.c            |  63 ++
 drivers/pinctrl/freescale/pinctrl-imx.h            |   3 +
 drivers/pinctrl/freescale/pinctrl-vf610.c          |   6 +
 drivers/tty/serial/fsl_lpuart.c                    |  16 +-
 include/dt-bindings/clock/vf610-clock.h            |   4 +-
 20 files changed, 1750 insertions(+), 15 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
 create mode 100644 arch/arm/mach-imx/pm-vf610.c
 create mode 100644 arch/arm/mach-imx/suspend-vf610.S
 create mode 100644 drivers/irqchip/irq-vf610-gpc.c
Signature · 1 line
2.7.2
author reviewer
#6 lore raw

PATCH 2/18 ARM: dts: vf610: add GPC as new interrupt parent

---
 arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/boot/dts/vfxxx.dtsi +9 -1
index 5e49fbd..909988d 100644
@@ -88,7 +88,7 @@
 		#address-cells = <1>;
 		#size-cells = <1>;
 		compatible = "simple-bus";
-		interrupt-parent = <&mscm_ir>;
+		interrupt-parent = <&gpc>;
 		ranges;
 
 		aips0: aips-bus@40000000 {
@@ -475,6 +475,14 @@
 				reg = <0x4006e000 0x1000>;
 				interrupts = <96 IRQ_TYPE_LEVEL_HIGH>;
 			};
+
+			gpc: gpc@4006c000 {
+				compatible = "fsl,vf610-gpc";
+				reg = <0x4006c000 0x1000>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+				interrupt-parent = <&mscm_ir>;
+			};
 		};
 
 		aips1: aips-bus@40080000 {
Signature · 1 line
2.7.2
author reviewer
#1 lore raw

PATCH 1/18 irqchip: vf610-gpc: add Vybrid GPC IRQ controller

In reply to Stefan Agner

This patch introduces a driver for Vybrids GPC (Global Power Controller). Vybrids GPC IP is simpler than the one found in i.MX 6: There is no power gating control (GPC) and the GPC INTC does not need to clear IRQ masks for an interrupt to get routed to the GIC (the mask only applys for wake-up control).

---
 drivers/irqchip/Makefile        |   1 +
 drivers/irqchip/irq-vf610-gpc.c | 138 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100644 drivers/irqchip/irq-vf610-gpc.c
drivers/irqchip/Makefile +1 -0
index 18caacb..0a77ac6 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TS4800_IRQ)		+= irq-ts4800.o
 obj-$(CONFIG_XTENSA)			+= irq-xtensa-pic.o
 obj-$(CONFIG_XTENSA_MX)			+= irq-xtensa-mx.o
 obj-$(CONFIG_IRQ_CROSSBAR)		+= irq-crossbar.o
+obj-$(CONFIG_SOC_VF610)			+= irq-vf610-gpc.o
 obj-$(CONFIG_SOC_VF610)			+= irq-vf610-mscm-ir.o
 obj-$(CONFIG_BCM7038_L1_IRQ)		+= irq-bcm7038-l1.o
 obj-$(CONFIG_BCM7120_L2_IRQ)		+= irq-bcm7120-l2.o
drivers/irqchip/irq-vf610-gpc.c new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
2.7.2
author reviewer
#9 lore raw

PATCH 3/18 ARM: dts: vf610-colibri: GPIO wakeup key

In reply to Stefan Agner

Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the Colibri default wakeup pin SO-DIMM 45.

---
 arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi +22 -0
index 4d8b7f6..936ece6 100644
@@ -39,6 +39,8 @@
  *     OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <dt-bindings/input/input.h>
+
 / {
 	chosen {
 		stdout-path = "serial0:115200n8";
@@ -74,6 +76,20 @@
 		gpio = <&gpio2 19 GPIO_ACTIVE_LOW>; /* USBH_PEN resp. USBH_P_EN */
 		vin-supply = <&reg_5v0>;
 	};
+
+	gpio-keys {
+		compatible = "gpio-keys";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_gpiokeys>;
+
+		power {
+			label = "Wake-Up";
+			gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
+			linux,code = <KEY_WAKEUP>;
+			debounce-interval = <10>;
+			gpio-key,wakeup;
+		};
+	};
 };
 
 &bl {
@@ -157,5 +173,11 @@
 				VF610_PAD_PTB21__GPIO_43	0x22ed
 			>;
 		};
+
+		pinctrl_gpiokeys: gpiokeys {
+			fsl,pins = <
+				VF610_PAD_PTB19__GPIO_41	0x218d
+			>;
+		};
 	};
 };
Signature · 1 line
2.7.2
author reviewer
#12 lore raw

PATCH 4/18 ARM: dts: vf610: add on-chip SRAM

In reply to Stefan Agner

Add Vybrids massive on-chip SRAM areas. Make use of the memory region functionality to denominate the retained SRAM area in LPSTOP2 and LPSTOP3.

---
 arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
arch/arm/boot/dts/vfxxx.dtsi +37 -0
index 909988d..b038ea4 100644
@@ -91,6 +91,43 @@
 		interrupt-parent = <&gpc>;
 		ranges;
 
+		ocram0: sram at 3f000000 {
+			compatible = "mmio-sram";
+			reg = <0x3f000000 0x40000>;
+
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x3f000000 0x40000>;
+
+			stbyram1 at 0 {
+				reg = <0x0 0x4000>;
+				label = "stbyram1";
+				pool;
+			};
+
+			stbyram2 at 4000 {
+				reg = <0x4000 0xc000>;
+				label = "stbyram2";
+				pool;
+			};
+		};
+
+		ocram1: sram at 3f040000 {
+			compatible = "mmio-sram";
+			reg = <0x3f040000 0x40000>;
+		};
+
+		gfxram0: sram at 3f400000 {
+			compatible = "mmio-sram";
+			reg = <0x3f400000 0x80000>;
+		};
+
+		/* used by L2 cache */
+		gfxram1: sram at 3f480000 {
+			compatible = "mmio-sram";
+			reg = <0x3f480000 0x80000>;
+		};
+
 		aips0: aips-bus at 40000000 {
 			compatible = "fsl,aips-bus", "simple-bus";
 			#address-cells = <1>;
Signature · 1 line
2.7.2
author reviewer
#15 lore raw

PATCH 5/18 ARM: dts: vf610: add modules required for PM

In reply to Stefan Agner
---
 arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm/boot/dts/vfxxx.dtsi +19 -0
index b038ea4..335f4e5 100644
@@ -434,6 +434,11 @@
 				reg = <0x40050000 0x400>;
 			};
 
+			scsc: scsc at 40052000 {
+				compatible = "fsl,vf610-scsc";
+				reg = <0x40052000 0x1000>;
+			};
+
 			usbphy0: usbphy at 40050800 {
 				compatible = "fsl,vf610-usbphy";
 				reg = <0x40050800 0x400>;
@@ -480,6 +485,13 @@
 				status = "disabled";
 			};
 
+			wakeup: wkpu at 4006a000 {
+				compatible = "fsl,vf610-wkpu";
+				reg = <0x4006a000 0x1000>;
+				interrupts = <92 IRQ_TYPE_LEVEL_HIGH>;
+				clocks = <&clks VF610_CLK_WKPU>;
+			};
+
 			clks: ccm at 4006b000 {
 				compatible = "fsl,vf610-ccm";
 				reg = <0x4006b000 0x1000>;
@@ -600,6 +612,13 @@
 				status = "disabled";
 			};
 
+			ddrmc: ddrmc at 400ae000 {
+				compatible = "fsl,vf610-ddrmc";
+				reg = <0x400ae000 0x400>;
+				clocks = <&clks VF610_CLK_DDRMC>;
+				clock-names = "ddrc";
+			};
+
 			adc1: adc at 400bb000 {
 				compatible = "fsl,vf610-adc";
 				reg = <0x400bb000 0x1000>;
Signature · 1 line
2.7.2
author reviewer
#17 lore raw

PATCH 6/18 ARM: imx: clk-gate2: allow custom gate configuration

In reply to Stefan Agner

The 2-bit gates found i.MX and Vybrid SoC support different clock configuration:

0b00: clk disabled
0b01: clk enabled in RUN mode but disabled in WAIT and STOP mode 0b10: clk enabled in RUN, WAIT and STOP mode (only Vybrid) 0b11: clk enabled in RUN and WAIT mode

For some clocks, we might want to configure different behaviour, e.g. a memory clock should be on even in STOP mode. Add a new function imx_clk_gate2_cgr which allow to configure specific gate values through the cgr_val parameter.

---
 drivers/clk/imx/clk-gate2.c |  7 +++++--
 drivers/clk/imx/clk.h       | 13 ++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/clk/imx/clk-gate2.c +5 -2
index 8935bff..db44a19 100644
@@ -31,6 +31,7 @@ struct clk_gate2 {
 	struct clk_hw hw;
 	void __iomem	*reg;
 	u8		bit_idx;
+	u8		cgr_val;
 	u8		flags;
 	spinlock_t	*lock;
 	unsigned int	*share_count;
@@ -50,7 +51,8 @@ static int clk_gate2_enable(struct clk_hw *hw)
 		goto out;
 
 	reg = readl(gate->reg);
-	reg |= 3 << gate->bit_idx;
+	reg &= ~(3 << gate->bit_idx);
+	reg |= gate->cgr_val << gate->bit_idx;
 	writel(reg, gate->reg);
 
 out:
@@ -125,7 +127,7 @@ static struct clk_ops clk_gate2_ops = {
 
 struct clk *clk_register_gate2(struct device *dev, const char *name,
 		const char *parent_name, unsigned long flags,
-		void __iomem *reg, u8 bit_idx,
+		void __iomem *reg, u8 bit_idx, u8 cgr_val,
 		u8 clk_gate2_flags, spinlock_t *lock,
 		unsigned int *share_count)
 {
@@ -140,6 +142,7 @@ struct clk *clk_register_gate2(struct device *dev, const char *name,
 	/* struct clk_gate2 assignments */
 	gate->reg = reg;
 	gate->bit_idx = bit_idx;
+	gate->cgr_val = cgr_val;
 	gate->flags = clk_gate2_flags;
 	gate->lock = lock;
 	gate->share_count = share_count;
drivers/clk/imx/clk.h +10 -3
index c94ac5c..9311755 100644
@@ -41,7 +41,7 @@ struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name,
 
 struct clk *clk_register_gate2(struct device *dev, const char *name,
 		const char *parent_name, unsigned long flags,
-		void __iomem *reg, u8 bit_idx,
+		void __iomem *reg, u8 bit_idx, u8 cgr_val,
 		u8 clk_gate_flags, spinlock_t *lock,
 		unsigned int *share_count);
 
@@ -55,7 +55,7 @@ static inline struct clk *imx_clk_gate2(const char *name, const char *parent,
 		void __iomem *reg, u8 shift)
 {
 	return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
-			shift, 0, &imx_ccm_lock, NULL);
+			shift, 0x3, 0, &imx_ccm_lock, NULL);
 }
 
 static inline struct clk *imx_clk_gate2_shared(const char *name,
@@ -63,7 +63,14 @@ static inline struct clk *imx_clk_gate2_shared(const char *name,
 		unsigned int *share_count)
 {
 	return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
-			shift, 0, &imx_ccm_lock, share_count);
+			shift, 0x3, 0, &imx_ccm_lock, share_count);
+}
+
+static inline struct clk *imx_clk_gate2_cgr(const char *name, const char *parent,
+		void __iomem *reg, u8 shift, u8 cgr_val)
+{
+	return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
+			shift, cgr_val, 0, &imx_ccm_lock, NULL);
 }
 
 struct clk *imx_clk_pfd(const char *name, const char *parent_name,
Signature · 1 line
2.7.2
author reviewer
#20 lore raw

PATCH 7/18 ARM: imx: clk-vf610: leave DDR clock on

In reply to Stefan Agner

To use STOP mode without putting DDR3 into self-refresh mode, we need to keep the DDR clock enabled. Use the new gate configuration with a value of 2 to make sure that the clock is enabled in RUN, WAIT and STOP mode.

---
 drivers/clk/imx/clk-vf610.c             | 3 +++
 include/dt-bindings/clock/vf610-clock.h | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-vf610.c +3 -0
index 0a94d96..f0ff458 100644
@@ -119,6 +119,7 @@ static unsigned int const clks_init_on[] __initconst = {
 	VF610_CLK_SYS_BUS,
 	VF610_CLK_DDR_SEL,
 	VF610_CLK_DAP,
+	VF610_CLK_DDRMC,
 };
 
 static struct clk * __init vf610_get_fixed_clock(
@@ -233,6 +234,8 @@ static void __init vf610_clocks_init(struct device_node *ccm_node)
 	clk[VF610_CLK_PLL4_MAIN_DIV] = clk_register_divider_table(NULL, "pll4_audio_div", "pll4_audio", 0, CCM_CACRR, 6, 3, 0, pll4_audio_div_table, &imx_ccm_lock);
 	clk[VF610_CLK_PLL6_MAIN_DIV] = imx_clk_divider("pll6_video_div", "pll6_video", CCM_CACRR, 21, 1);
 
+	clk[VF610_CLK_DDRMC] = imx_clk_gate2_cgr("ddrmc", "ddr_sel", CCM_CCGR6, CCM_CCGRx_CGn(14), 0x2);
+
 	clk[VF610_CLK_USBPHY0] = imx_clk_gate("usbphy0", "pll3_usb_otg", PLL3_CTRL, 6);
 	clk[VF610_CLK_USBPHY1] = imx_clk_gate("usbphy1", "pll7_usb_host", PLL7_CTRL, 6);
 
include/dt-bindings/clock/vf610-clock.h +2 -1
index 56c16aa..cf2c00a 100644
@@ -195,6 +195,7 @@
 #define VF610_CLK_SNVS			182
 #define VF610_CLK_DAP			183
 #define VF610_CLK_OCOTP         184
-#define VF610_CLK_END			185
+#define VF610_CLK_DDRMC			185
+#define VF610_CLK_END			186
 
 #endif /* __DT_BINDINGS_CLOCK_VF610_H */
Signature · 1 line
2.7.2
author reviewer
#21 lore raw

PATCH 8/18 ARM: clk: add WKPU unit

In reply to Stefan Agner
---
 drivers/clk/imx/clk-vf610.c             | 2 ++
 include/dt-bindings/clock/vf610-clock.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-vf610.c +2 -0
index f0ff458..610a724 100644
@@ -120,6 +120,7 @@ static unsigned int const clks_init_on[] __initconst = {
 	VF610_CLK_DDR_SEL,
 	VF610_CLK_DAP,
 	VF610_CLK_DDRMC,
+	VF610_CLK_WKPU,
 };
 
 static struct clk * __init vf610_get_fixed_clock(
@@ -235,6 +236,7 @@ static void __init vf610_clocks_init(struct device_node *ccm_node)
 	clk[VF610_CLK_PLL6_MAIN_DIV] = imx_clk_divider("pll6_video_div", "pll6_video", CCM_CACRR, 21, 1);
 
 	clk[VF610_CLK_DDRMC] = imx_clk_gate2_cgr("ddrmc", "ddr_sel", CCM_CCGR6, CCM_CCGRx_CGn(14), 0x2);
+	clk[VF610_CLK_WKPU] = imx_clk_gate2_cgr("wkpu", "ipg_bus", CCM_CCGR4, CCM_CCGRx_CGn(10), 0x2);
 
 	clk[VF610_CLK_USBPHY0] = imx_clk_gate("usbphy0", "pll3_usb_otg", PLL3_CTRL, 6);
 	clk[VF610_CLK_USBPHY1] = imx_clk_gate("usbphy1", "pll7_usb_host", PLL7_CTRL, 6);
include/dt-bindings/clock/vf610-clock.h +2 -1
index cf2c00a..7dc1b84 100644
@@ -196,6 +196,7 @@
 #define VF610_CLK_DAP			183
 #define VF610_CLK_OCOTP         184
 #define VF610_CLK_DDRMC			185
-#define VF610_CLK_END			186
+#define VF610_CLK_WKPU			186
+#define VF610_CLK_END			187
 
 #endif /* __DT_BINDINGS_CLOCK_VF610_H */
Signature · 1 line
2.7.2
author reviewer
#23 lore raw

PATCH 9/18 ARM: vf610: clk: add suspend/resume support

In reply to Stefan Agner

The clock register are lost when enterying LPSTOPx, hence provide suspend/resume functions restoring them. The clock gates get restored by the individual driver, hence we do not need to restore them here.

---
 drivers/clk/imx/clk-vf610.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/clk/imx/clk-vf610.c +49 -0
index 610a724..e2e2c43 100644
@@ -10,6 +10,7 @@
 
 #include <linux/of_address.h>
 #include <linux/clk.h>
+#include <linux/syscore_ops.h>
 #include <dt-bindings/clock/vf610-clock.h>
 
 #include "clk.h"
@@ -40,6 +41,7 @@
 #define CCM_CCGR9		(ccm_base + 0x64)
 #define CCM_CCGR10		(ccm_base + 0x68)
 #define CCM_CCGR11		(ccm_base + 0x6c)
+#define CCM_CCGRx(x)		(CCM_CCGR0 + (x) * 4)
 #define CCM_CMEOR0		(ccm_base + 0x70)
 #define CCM_CMEOR1		(ccm_base + 0x74)
 #define CCM_CMEOR2		(ccm_base + 0x78)
@@ -115,6 +117,13 @@ static struct clk_div_table pll4_audio_div_table[] = {
 static struct clk *clk[VF610_CLK_END];
 static struct clk_onecell_data clk_data;
 
+static u32 cscmr1;
+static u32 cscmr2;
+static u32 cscdr1;
+static u32 cscdr2;
+static u32 cscdr3;
+static u32 ccgr[12];
+
 static unsigned int const clks_init_on[] __initconst = {
 	VF610_CLK_SYS_BUS,
 	VF610_CLK_DDR_SEL,
@@ -134,6 +143,43 @@ static struct clk * __init vf610_get_fixed_clock(
 	return clk;
 };
 
+static int vf610_clk_suspend(void)
+{
+	int i;
+
+	cscmr1 = readl_relaxed(CCM_CSCMR1);
+	cscmr2 = readl_relaxed(CCM_CSCMR2);
+
+	cscdr1 = readl_relaxed(CCM_CSCDR1);
+	cscdr2 = readl_relaxed(CCM_CSCDR2);
+	cscdr3 = readl_relaxed(CCM_CSCDR3);
+
+	for (i = 0; i < 12; i++)
+		ccgr[i] = readl_relaxed(CCM_CCGRx(i));
+
+	return 0;
+}
+
+static void vf610_clk_resume(void)
+{
+	int i;
+
+	writel_relaxed(cscmr1, CCM_CSCMR1);
+	writel_relaxed(cscmr2, CCM_CSCMR2);
+
+	writel_relaxed(cscdr1, CCM_CSCDR1);
+	writel_relaxed(cscdr2, CCM_CSCDR2);
+	writel_relaxed(cscdr3, CCM_CSCDR3);
+
+	for (i = 0; i < 12; i++)
+		writel_relaxed(ccgr[i], CCM_CCGRx(i));
+}
+
+static struct syscore_ops vf610_clk_syscore_ops = {
+	.suspend = vf610_clk_suspend,
+	.resume = vf610_clk_resume,
+};
+
 static void __init vf610_clocks_init(struct device_node *ccm_node)
 {
 	struct device_node *np;
@@ -414,9 +460,12 @@ static void __init vf610_clocks_init(struct device_node *ccm_node)
 	for (i = 0; i < ARRAY_SIZE(clks_init_on); i++)
 		clk_prepare_enable(clk[clks_init_on[i]]);
 
+	register_syscore_ops(&vf610_clk_syscore_ops);
+
 	/* Add the clocks to provider list */
 	clk_data.clks = clk;
 	clk_data.clk_num = ARRAY_SIZE(clk);
 	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
 }
 CLK_OF_DECLARE(vf610, "fsl,vf610-ccm", vf610_clocks_init);
+
Signature · 1 line
2.7.2
author reviewer
#25 lore raw

PATCH 10/18 tty: serial: fsl_lpuart: support suspend/resume

In reply to Stefan Agner

In order to allow wake support in STOP sleep mode, clocks are needed. Use imx_clk_gate2_cgr to disable automatic clock gating in low power mode STOP. This allows to enable wake by UART using:
echo enabled > /sys/class/tty/ttyLP0/power/wakeup

However, if wake is not enabled, the driver should disable the clocks explicitly to save power.

---
 drivers/clk/imx/clk-vf610.c     | 12 ++++++------
 drivers/tty/serial/fsl_lpuart.c | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)
drivers/clk/imx/clk-vf610.c +6 -6
index e2e2c43..170a96c 100644
@@ -315,12 +315,12 @@ static void __init vf610_clocks_init(struct device_node *ccm_node)
 
 	clk[VF610_CLK_PIT] = imx_clk_gate2("pit", "ipg_bus", CCM_CCGR1, CCM_CCGRx_CGn(7));
 
-	clk[VF610_CLK_UART0] = imx_clk_gate2("uart0", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(7));
-	clk[VF610_CLK_UART1] = imx_clk_gate2("uart1", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(8));
-	clk[VF610_CLK_UART2] = imx_clk_gate2("uart2", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(9));
-	clk[VF610_CLK_UART3] = imx_clk_gate2("uart3", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(10));
-	clk[VF610_CLK_UART4] = imx_clk_gate2("uart4", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(9));
-	clk[VF610_CLK_UART5] = imx_clk_gate2("uart5", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(10));
+	clk[VF610_CLK_UART0] = imx_clk_gate2_cgr("uart0", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(7), 0x2);
+	clk[VF610_CLK_UART1] = imx_clk_gate2_cgr("uart1", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(8), 0x2);
+	clk[VF610_CLK_UART2] = imx_clk_gate2_cgr("uart2", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(9), 0x2);
+	clk[VF610_CLK_UART3] = imx_clk_gate2_cgr("uart3", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(10), 0x2);
+	clk[VF610_CLK_UART4] = imx_clk_gate2_cgr("uart4", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(9), 0x2);
+	clk[VF610_CLK_UART5] = imx_clk_gate2_cgr("uart5", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(10), 0x2);
 
 	clk[VF610_CLK_I2C0] = imx_clk_gate2("i2c0", "ipg_bus", CCM_CCGR4, CCM_CCGRx_CGn(6));
 	clk[VF610_CLK_I2C1] = imx_clk_gate2("i2c1", "ipg_bus", CCM_CCGR4, CCM_CCGRx_CGn(7));
drivers/tty/serial/fsl_lpuart.c +14 -2
index 3d79003..94e29ba 100644
@@ -483,9 +483,8 @@ static void lpuart_dma_rx_complete(void *arg)
 	spin_unlock_irqrestore(&sport->port.lock, flags);
 }
 
-static void lpuart_timer_func(unsigned long data)
+static void lpuart_dma_rx_terminate(struct lpuart_port *sport)
 {
-	struct lpuart_port *sport = (struct lpuart_port *)data;
 	struct tty_port *port = &sport->port.state->port;
 	struct dma_tx_state state;
 	unsigned long flags;
@@ -510,6 +509,11 @@ static void lpuart_timer_func(unsigned long data)
 	spin_unlock_irqrestore(&sport->port.lock, flags);
 }
 
+static void lpuart_timer_func(unsigned long data)
+{
+	lpuart_dma_rx_terminate((struct lpuart_port *)data);
+}
+
 static inline void lpuart_prepare_rx(struct lpuart_port *sport)
 {
 	unsigned long flags;
@@ -1915,7 +1919,12 @@ static int lpuart_suspend(struct device *dev)
 		writeb(temp, sport->port.membase + UARTCR2);
 	}
 
+	if (sport->dma_rx_in_progress)
+		lpuart_dma_rx_terminate(sport);
+
 	uart_suspend_port(&lpuart_reg, &sport->port);
+	if (sport->port.suspended && !sport->port.irq_wake)
+		clk_disable_unprepare(sport->clk);
 
 	return 0;
 }
@@ -1925,6 +1934,9 @@ static int lpuart_resume(struct device *dev)
 	struct lpuart_port *sport = dev_get_drvdata(dev);
 	unsigned long temp;
 
+	if (sport->port.suspended && !sport->port.irq_wake)
+		clk_prepare_enable(sport->clk);
+
 	if (sport->lpuart32) {
 		lpuart32_setup_watermark(sport);
 		temp = lpuart32_read(sport->port.membase + UARTCTRL);
Signature · 1 line
2.7.2
author reviewer
#27 lore raw

PATCH 11/18 pinctrl: pinctrl-imx: implement suspend/resume

In reply to Stefan Agner

In some SoC's using the IMX pin controller, the IP looses its state when entering lowest power modes. Enhance the driver with suspend/ resume functions restoring the pin states.

---
 drivers/pinctrl/freescale/pinctrl-imx.c   | 63 +++++++++++++++++++++++++++++++
 drivers/pinctrl/freescale/pinctrl-imx.h   |  3 ++
 drivers/pinctrl/freescale/pinctrl-vf610.c |  6 +++
 3 files changed, 72 insertions(+)
drivers/pinctrl/freescale/pinctrl-imx.c +63 -0
index a5bb939..42fc9a9 100644
@@ -24,6 +24,7 @@
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
 #include <linux/slab.h>
+#include <linux/syscore_ops.h>
 
 #include "../core.h"
 #include "pinctrl-imx.h"
@@ -42,6 +43,8 @@ struct imx_pinctrl {
 	void __iomem *base;
 	void __iomem *input_sel_base;
 	const struct imx_pinctrl_soc_info *info;
+	u32 *mux_regs;
+	u32 *input_regs;
 };
 
 static const inline struct imx_pin_group *imx_pinctrl_find_group_by_name(
@@ -689,6 +692,54 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
 	return 0;
 }
 
+static int __maybe_unused imx_pinctrl_suspend(struct device *dev)
+{
+	struct imx_pinctrl *ipctl = dev_get_drvdata(dev);
+	const struct imx_pinctrl_soc_info *info = ipctl->info;
+	int i;
+
+	for (i = 0; i < info->npins; i++) {
+		const struct imx_pin_reg *pin_reg = &info->pin_regs[i];
+
+		if (pin_reg->mux_reg == -1)
+			continue;
+
+		ipctl->mux_regs[i] = readl(ipctl->base + pin_reg->mux_reg);
+	}
+
+	for (i = 0; i < info->ninput_regs; i++)
+		ipctl->input_regs[i] = readl(ipctl->base +
+				info->input_regs_offset + i * sizeof(u32 *));
+
+	return 0;
+}
+
+static int __maybe_unused imx_pinctrl_resume(struct device *dev)
+{
+	struct imx_pinctrl *ipctl = dev_get_drvdata(dev);
+	const struct imx_pinctrl_soc_info *info = ipctl->info;
+	const struct imx_pin_reg *pin_reg;
+	int i;
+
+	for (i = 0; i < info->npins; i++) {
+		pin_reg = &info->pin_regs[i];
+		if (pin_reg->mux_reg == -1)
+			continue;
+
+		writel(ipctl->mux_regs[i], ipctl->base + pin_reg->mux_reg);
+	}
+
+	for (i = 0; i < info->ninput_regs; i++)
+		writel(ipctl->input_regs[i], ipctl->base +
+				info->input_regs_offset + i * sizeof(u32 *));
+
+	return 0;
+}
+
+const struct dev_pm_ops imx_pinctrl_dev_pm_ops = {
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(imx_pinctrl_suspend, imx_pinctrl_resume)
+};
+
 int imx_pinctrl_probe(struct platform_device *pdev,
 		      struct imx_pinctrl_soc_info *info)
 {
@@ -719,6 +770,18 @@ int imx_pinctrl_probe(struct platform_device *pdev,
 		info->pin_regs[i].conf_reg = -1;
 	}
 
+#ifdef CONFIG_PM_SLEEP
+	ipctl->mux_regs = devm_kzalloc(&pdev->dev, sizeof(u32 *) *
+				       info->npins, GFP_KERNEL);
+	if (!ipctl->mux_regs)
+		return -ENOMEM;
+
+	ipctl->input_regs = devm_kzalloc(&pdev->dev, sizeof(u32 *) *
+					 info->ninput_regs, GFP_KERNEL);
+	if (!ipctl->input_regs)
+		return -ENOMEM;
+#endif
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	ipctl->base = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(ipctl->base))
drivers/pinctrl/freescale/pinctrl-imx.h +3 -0
index 2a592f6..56851a6 100644
@@ -81,6 +81,8 @@ struct imx_pinctrl_soc_info {
 	unsigned int group_index;
 	struct imx_pmx_func *functions;
 	unsigned int nfunctions;
+	unsigned int input_regs_offset;
+	unsigned int ninput_regs;
 	unsigned int flags;
 };
 
@@ -99,4 +101,5 @@ struct imx_pinctrl_soc_info {
 int imx_pinctrl_probe(struct platform_device *pdev,
 			struct imx_pinctrl_soc_info *info);
 int imx_pinctrl_remove(struct platform_device *pdev);
+extern const struct dev_pm_ops imx_pinctrl_dev_pm_ops;
 #endif /* __DRIVERS_PINCTRL_IMX_H */
drivers/pinctrl/freescale/pinctrl-vf610.c +6 -0
index 587d1ff..b6280a8 100644
@@ -19,6 +19,9 @@
 
 #include "pinctrl-imx.h"
 
+#define VF610_INPUT_REG_CNT		49
+#define VF610_INPUT_REG_BASE		0x2ec
+
 enum vf610_pads {
 	VF610_PAD_PTA6 = 0,
 	VF610_PAD_PTA8 = 1,
@@ -299,6 +302,8 @@ static const struct pinctrl_pin_desc vf610_pinctrl_pads[] = {
 static struct imx_pinctrl_soc_info vf610_pinctrl_info = {
 	.pins = vf610_pinctrl_pads,
 	.npins = ARRAY_SIZE(vf610_pinctrl_pads),
+	.input_regs_offset = VF610_INPUT_REG_BASE,
+	.ninput_regs = VF610_INPUT_REG_CNT,
 	.flags = SHARE_MUX_CONF_REG | ZERO_OFFSET_VALID,
 };
 
@@ -316,6 +321,7 @@ static struct platform_driver vf610_pinctrl_driver = {
 	.driver = {
 		.name = "vf610-pinctrl",
 		.of_match_table = vf610_pinctrl_of_match,
+		.pm = &imx_pinctrl_dev_pm_ops,
 	},
 	.probe = vf610_pinctrl_probe,
 	.remove = imx_pinctrl_remove,
Signature · 1 line
2.7.2
author reviewer
#28 lore raw

PATCH 12/18 gpio: vf610: add system PM suspend/resume

In reply to Stefan Agner

Store the state of the GPIO module (which contains the GPIO output state) in memory during suspend. The driver already maintains an interrupt configuration in memory, hence we can use this configuration to restore the port control register (PCR).

---
 drivers/gpio/gpio-vf610.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
drivers/gpio/gpio-vf610.c +37 -0
index 6284bdb..1a022be 100644
@@ -37,6 +37,7 @@ struct vf610_gpio_port {
 	void __iomem *gpio_base;
 	u8 irqc[VF610_GPIO_PER_PORT];
 	int irq;
+	u32 state;
 };
 
 #define GPIO_PDOR		0x00
@@ -215,6 +216,40 @@ static struct irq_chip vf610_gpio_irq_chip = {
 	.irq_set_wake	= vf610_gpio_irq_set_wake,
 };
 
+static int __maybe_unused vf610_gpio_suspend(struct device *dev)
+{
+	struct vf610_gpio_port *port = dev_get_drvdata(dev);
+
+	port->state = vf610_gpio_readl(port->gpio_base + GPIO_PDOR);
+
+	/*
+	 * There is no need to store Port state since we maintain the state
+	 * alread in the irqc array
+	 */
+
+	return 0;
+}
+
+static int __maybe_unused vf610_gpio_resume(struct device *dev)
+{
+	struct vf610_gpio_port *port = dev_get_drvdata(dev);
+	int i;
+
+	vf610_gpio_writel(port->state, port->gpio_base + GPIO_PDOR);
+
+	for (i = 0; i < port->gc.ngpio; i++) {
+		u32 irqc = port->irqc[i] << PORT_PCR_IRQC_OFFSET;
+
+		vf610_gpio_writel(irqc, port->base + PORT_PCR(i));
+	}
+
+	return 0;
+}
+
+static const struct dev_pm_ops vf610_gpio_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(vf610_gpio_suspend, vf610_gpio_resume)
+};
+
 static int vf610_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -272,6 +307,7 @@ static int vf610_gpio_probe(struct platform_device *pdev)
 	}
 	gpiochip_set_chained_irqchip(gc, &vf610_gpio_irq_chip, port->irq,
 				     vf610_gpio_irq_handler);
+	platform_set_drvdata(pdev, port);
 
 	return 0;
 }
@@ -279,6 +315,7 @@ static int vf610_gpio_probe(struct platform_device *pdev)
 static struct platform_driver vf610_gpio_driver = {
 	.driver		= {
 		.name	= "gpio-vf610",
+		.pm = &vf610_gpio_pm_ops,
 		.of_match_table = vf610_gpio_dt_ids,
 	},
 	.probe		= vf610_gpio_probe,
Signature · 1 line
2.7.2
author reviewer
#29 lore raw

PATCH 13/18 ARM: dts: vf610: add WKPU connection to GPIO

In reply to Stefan Agner

Some GPIO have extended wake-up capabilities through the WKPU module. Encode the connection between the GPIO's and the WKPU interrupt sources in the device tree.

---
 arch/arm/boot/dts/vfxxx.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm/boot/dts/vfxxx.dtsi +8 -0
index 335f4e5..869b230 100644
@@ -383,6 +383,7 @@
 				interrupt-controller;
 				#interrupt-cells = <2>;
 				gpio-ranges = <&iomuxc 0 0 32>;
+				fsl,gpio-wakeup = <&wakeup 22 0 8>; /* PTB0...PTB7 */
 			};
 
 			gpio1: gpio at 4004a000 {
@@ -394,6 +395,10 @@
 				interrupt-controller;
 				#interrupt-cells = <2>;
 				gpio-ranges = <&iomuxc 0 32 32>;
+				fsl,gpio-wakeup = <&wakeup 1 8 2>, /* PTB11, PTB12 (NMI)*/
+						<&wakeup 4 10 1>, /* PTB14 */
+						<&wakeup 6 11 1>, /* PTB16 */
+						<&wakeup 9 12 2>; /* PTB19, PTB20 */
 			};
 
 			gpio2: gpio at 4004b000 {
@@ -416,6 +421,9 @@
 				interrupt-controller;
 				#interrupt-cells = <2>;
 				gpio-ranges = <&iomuxc 0 96 32>;
+				fsl,gpio-wakeup = <&wakeup 1 14 1>, /* PTB27 */
+						<&wakeup 7 15 1>, /* PTC30 */
+						<&wakeup 29 16 1>; /* PTE20 */
 			};
 
 			gpio4: gpio at 4004d000 {
Signature · 1 line
2.7.2
author reviewer
#30 lore raw

PATCH 14/18 gpio: vf610: add support for WKPU unit

In reply to Stefan Agner

WKPU unit support within the VF610 GPIO driver. The WKPU unit allows some GPIO to be the wakeup source from lowest power modes LPSTOPx. The relationship between the GPIO banks and the WKPU GPIO numbering can be derived from the device tree property fsl,gpio-wakeup.

---
 .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
 drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
 2 files changed, 157 insertions(+)
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +6 -0
index 436cc99..985ddfd 100644
@@ -22,6 +22,12 @@ Required properties for GPIO node:
       4 = active high level-sensitive.
       8 = active low level-sensitive.
 
+Option properties:
+- fsl,gpio-wakeup : map GPIOs to WKPU unit, 3 argument cells per phandle
+      cell 1: First GPIO (relative to the GPIO block)
+      cell 2: First GPIO of the WKPU unit
+      cell 3: Number of consecutive GPIO's
+
 Note: Each GPIO port should have an alias correctly numbered in "aliases"
 node.
 
drivers/gpio/gpio-vf610.c +151 -0

201 lines not on this page · raw message

Signature · 1 line
2.7.2
author reviewer
#33 lore raw

PATCH 15/18 ARM: vf610: PM: initial suspend/resume support

In reply to Stefan Agner

Add system suspend and resume support for Vybrid SoC. The standby sleep state puts the SoC in STOP mode. The SoC can be woken through an interrupt from GPC (Global Power Controller). The GPC can use any interrupt as wake-up source. To save power the main PLL1 is bypassed and uses the 24MHz on-chip oscillator. However, memory clock need to be at full speed, hence the PLL2 needs to be on to keep the memory clocked. The mode is completely implemented in C since we can access the full memory at all times. The mode provides most power saving while being able to be woken by any IRQ as wake-up source.

The mem sleep state (Suspend-to-RAM) uses Vybrid's LPSTOP2 mode. This mode powergates most parts of the SoC expect some peripherials such as Wake-Up controller (WKPU) or LP RTC. Parts of the internal SRAM is retained too. The suspend code written in assembly runs from this SRAM. The code puts the main memory (DDR3) into self-refresh mode and takes it out of self-refresh mode on resume. Verified with Colibri VF50/VF61 V1.2A.

---
 arch/arm/mach-imx/Makefile        |   3 +
 arch/arm/mach-imx/common.h        |  10 +
 arch/arm/mach-imx/mach-vf610.c    |   8 +
 arch/arm/mach-imx/pm-vf610.c      | 634 ++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/suspend-vf610.S | 437 ++++++++++++++++++++++++++
 drivers/clk/imx/clk-vf610.c       |  17 +
 6 files changed, 1109 insertions(+)
 create mode 100644 arch/arm/mach-imx/pm-vf610.c
 create mode 100644 arch/arm/mach-imx/suspend-vf610.S
arch/arm/mach-imx/Makefile +3 -0
index 9fbe624..ea2e8bd 100644
@@ -90,8 +90,11 @@ ifeq ($(CONFIG_SUSPEND),y)
 AFLAGS_suspend-imx6.o :=-Wa,-march=armv7-a
 obj-$(CONFIG_SOC_IMX6) += suspend-imx6.o
 obj-$(CONFIG_SOC_IMX53) += suspend-imx53.o
+AFLAGS_suspend-vf610.o :=-Wa,-march=armv7-a
+obj-$(CONFIG_SOC_VF610) += suspend-vf610.o
 endif
 obj-$(CONFIG_SOC_IMX6) += pm-imx6.o
+obj-$(CONFIG_SOC_VF610) += pm-vf610.o
 
 obj-$(CONFIG_SOC_IMX50) += mach-imx50.o
 obj-$(CONFIG_SOC_IMX51) += mach-imx51.o
arch/arm/mach-imx/common.h +10 -0
index 58a3846..737b1e4 100644
@@ -76,6 +76,13 @@ enum mxc_cpu_pwr_mode {
 	STOP_POWER_OFF,		/* STOP + SRPG */
 };
 
+enum vf610_cpu_pwr_mode {
+	VF610_RUN,
+	VF610_LP_RUN,
+	VF610_STOP,
+	VF610_LP_STOP,
+};
+
 enum mx3_cpu_pwr_mode {
 	MX3_RUN,
 	MX3_WAIT,
@@ -120,11 +127,13 @@ void v7_cpu_resume(void);
 void imx53_suspend(void __iomem *ocram_vbase);
 extern const u32 imx53_suspend_sz;
 void imx6_suspend(void __iomem *ocram_vbase);
+void vf610_suspend(void __iomem *ocram_vbase);
 #else
 static inline void v7_cpu_resume(void) {}
 static inline void imx53_suspend(void __iomem *ocram_vbase) {}
 static const u32 imx53_suspend_sz;
 static inline void imx6_suspend(void __iomem *ocram_vbase) {}
+static inline void vf610_suspend(void __iomem *ocram_vbase) {}
 #endif
 
 void imx6_pm_ccm_init(const char *ccm_compat);
@@ -133,6 +142,7 @@ void imx6dl_pm_init(void);
 void imx6sl_pm_init(void);
 void imx6sx_pm_init(void);
 void imx6ul_pm_init(void);
+void vf610_pm_init(void);
 
 #ifdef CONFIG_PM
 void imx51_pm_init(void);
arch/arm/mach-imx/mach-vf610.c +8 -0
index b20f6c1..5ba668f 100644
@@ -11,6 +11,13 @@
 #include <linux/irqchip.h>
 #include <asm/mach/arch.h>
 #include <asm/hardware/cache-l2x0.h>
+#include "common.h"
+
+static void __init vf610_init_machine(void)
+{
+	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
+	vf610_pm_init();
+}
 
 static const char * const vf610_dt_compat[] __initconst = {
 	"fsl,vf500",
@@ -24,5 +31,6 @@ static const char * const vf610_dt_compat[] __initconst = {
 DT_MACHINE_START(VYBRID_VF610, "Freescale Vybrid VF5xx/VF6xx (Device Tree)")
 	.l2c_aux_val	= 0,
 	.l2c_aux_mask	= ~0,
+	.init_machine	= vf610_init_machine,
 	.dt_compat	= vf610_dt_compat,
 MACHINE_END
arch/arm/mach-imx/pm-vf610.c new file +634 -0

634 lines not on this page · raw message

arch/arm/mach-imx/suspend-vf610.S new file +437 -0

437 lines not on this page · raw message

drivers/clk/imx/clk-vf610.c +17 -0
index 170a96c..27d4cf0 100644
@@ -117,6 +117,11 @@ static struct clk_div_table pll4_audio_div_table[] = {
 static struct clk *clk[VF610_CLK_END];
 static struct clk_onecell_data clk_data;
 
+static u32 anadig_pll3_ctrl;
+static u32 anadig_pll4_ctrl;
+static u32 anadig_pll5_ctrl;
+static u32 anadig_pll6_ctrl;
+static u32 anadig_pll7_ctrl;
 static u32 cscmr1;
 static u32 cscmr2;
 static u32 cscdr1;
@@ -147,6 +152,12 @@ static int vf610_clk_suspend(void)
 {
 	int i;
 
+	anadig_pll3_ctrl = readl_relaxed(PLL3_CTRL);
+	anadig_pll4_ctrl = readl_relaxed(PLL4_CTRL);
+	anadig_pll5_ctrl = readl_relaxed(PLL5_CTRL);
+	anadig_pll6_ctrl = readl_relaxed(PLL6_CTRL);
+	anadig_pll7_ctrl = readl_relaxed(PLL7_CTRL);
+
 	cscmr1 = readl_relaxed(CCM_CSCMR1);
 	cscmr2 = readl_relaxed(CCM_CSCMR2);
 
@@ -164,6 +175,12 @@ static void vf610_clk_resume(void)
 {
 	int i;
 
+	writel_relaxed(anadig_pll3_ctrl, PLL3_CTRL);
+	writel_relaxed(anadig_pll4_ctrl, PLL4_CTRL);
+	writel_relaxed(anadig_pll5_ctrl, PLL5_CTRL);
+	writel_relaxed(anadig_pll6_ctrl, PLL6_CTRL);
+	writel_relaxed(anadig_pll7_ctrl, PLL7_CTRL);
+
 	writel_relaxed(cscmr1, CCM_CSCMR1);
 	writel_relaxed(cscmr2, CCM_CSCMR2);
 
Signature · 1 line
2.7.2
author reviewer
#37 lore raw

PATCH 16/18 ARM: vf610: PM: enable Suspend-to-RAM only if hardware fixes are in place

In reply to Stefan Agner

To use self-refresh mode for DDR3 SDRAM memory in LPSTOPx mode, the hardware need to have pull-ups/downs populated on RESET/CKE line of the DDR memory. Read the device tree property which indicates whether a given board has such resistors populated.

---
 arch/arm/mach-imx/pm-vf610.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
arch/arm/mach-imx/pm-vf610.c +16 -1
index ecc7c9c..3da93e9 100644
@@ -93,6 +93,7 @@
 
 static void __iomem *suspend_ocram_base;
 static void (*vf610_suspend_in_ocram_fn)(void __iomem *ocram_vbase);
+static bool has_cke_reset_pulls;
 
 #ifdef DEBUG
 static void __iomem *uart_membase;
@@ -382,7 +383,8 @@ static int vf610_pm_enter(suspend_state_t state)
 
 static int vf610_pm_valid(suspend_state_t state)
 {
-	return (state == PM_SUSPEND_STANDBY || state == PM_SUSPEND_MEM);
+	return (state == PM_SUSPEND_STANDBY ||
+		(state == PM_SUSPEND_MEM && has_cke_reset_pulls));
 }
 
 static const struct platform_suspend_ops vf610_pm_ops = {
@@ -476,6 +478,19 @@ static int __init vf610_suspend_init(const struct vf610_pm_socdata *socdata)
 		return ret;
 #endif
 
+	node = of_find_compatible_node(NULL, NULL, socdata->ddrmc_compat);
+	if (node) {
+		has_cke_reset_pulls =
+			of_property_read_bool(node, "fsl,has-cke-reset-pulls");
+
+		of_node_put(node);
+	}
+
+	if (has_cke_reset_pulls)
+		pr_info("PM: CKE/RESET pulls available, enable Suspend-to-RAM\n");
+	else
+		pr_info("PM: No CKE/RESET pulls, disable Suspend-to-RAM\n");
+
 	suspend_set_ops(&vf610_pm_ops);
 
 	node = of_find_compatible_node(NULL, NULL, "mmio-sram");
Signature · 1 line
2.7.2
author reviewer
#38 lore raw

PATCH 17/18 Documentation: dt: add Vybrid DDR memory controller bindings

In reply to Stefan Agner

Add device-tree bindings of Vybrids LPDDR2/DDR3 SDRAM Memory Controller. Access to the device is required to put the memory into self-refresh mode.

---
 .../bindings/arm/freescale/fsl,vf610-ddrmc.txt     | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt new file +23 -0
new file mode 100644
index 0000000..56a71d6
@@ -0,0 +1,23 @@
+Freescale Vybrid LPDDR2/DDR3 SDRAM Memory Controller
+
+The memory controller supports high performance applications for 16-bit or
+8-bit DDR2, or LPDDR SDRAM memories.
+
+Required properties:
+- compatible:	"fsl,vf610-ddrmc"
+- reg:		the register range of the DDRMC registers
+- clocks:	DDRMC main clock to clock memory and access registers.
+- clock-names:	Must contain "ddrc", matching entry in the clocks property.
+- fsl,has-cke-reset-pulls:
+		States whether pull-down/up are populated on DDR CKE/RESET
+		signals to allow using DDR self-refresh modes (see Vybrid
+		Hardware Development Guide for details).
+
+Example:
+	ddrmc: ddrmc at 400ae000 {
+		compatible = "fsl,vf610-ddrmc";
+		reg = <0x400ae000 0x1000>;
+		clocks = <&clks VF610_CLK_DDRMC>;
+		clock-names = "ddrc";
+		fsl,has-cke-reset-pulls;
+	}
Signature · 1 line
2.7.2
author reviewer
#40 lore raw

PATCH 18/18 ARM: vf610: PM: enable SNVS access

In reply to Stefan Agner

Restore access to SNVS which seems to be done by the boot ROM on normal boot. This is required for RTC wakeup not ending up in a interrupt storm, since the SNVS RTC driver can not acknowledge the wakeup alarm without write access.

---
 arch/arm/mach-imx/suspend-vf610.S | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/mach-imx/suspend-vf610.S +11 -0
index 09ad246..6df0622 100644
@@ -429,6 +429,17 @@ ddrmc_initializing:
 	ldr	r5, =0x0
 	str	r5, [r11, #VF610_GPC_LPMR]
 
+	/* Enable SNVS */
+	ldr	r3, [r0, #PM_INFO_VF610_CCM_P_OFFSET]
+	ldr	r4, [r3, #VF610_CCM_CCGR6]
+	orr	r4, r4, #0x0000C000
+	str	r4, [r3, #VF610_CCM_CCGR6]
+
+	/* Enable SNVS access (RTC) */
+	ldr	r11, =0x400a7000
+	ldr	r4, =0x80000100
+	str	r4, [r11, #0x4]
+
 	/* get physical resume address from pm_info. */
 	ldr	lr, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
 
Signature · 1 line
2.7.2
#34 lore raw

Re: [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support

In reply to Stefan Agner
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Stefan,

[auto build test ERROR on shawnguo/for-next]
[also build test ERROR on v4.5-rc7]
[cannot apply to next-20160310]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Stefan-Agner/ARM-vf610-Suspend-resume-with-self-refresh-mode/20160310-102621
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux.git for-next
config: arm-vf610m4_defconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All errors (new ones prefixed by >>):

arch/arm/mach-imx/pm-vf610.c: In function 'vf610_suspend_finish':

>> arch/arm/mach-imx/pm-vf610.c:348:3: error: implicit declaration of function 'local_flush_tlb_all' [-Werror=implicit-function-declaration]
      local_flush_tlb_all();
      ^

cc1: some warnings being treated as errors

vim +/local_flush_tlb_all +348 arch/arm/mach-imx/pm-vf610.c

342 cpu_do_idle();
343 } else {
344 /*
345 * call low level suspend function in ocram,
346 * as we need to float DDR IO.
347 */

 > 348			local_flush_tlb_all();

349 flush_cache_all();
350 outer_flush_all();
351 vf610_suspend_in_ocram_fn(suspend_ocram_base);

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/octet-stream
Size: 7259 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160311/1c30b81c/attachment.obj>

#2 lore raw

Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller

In reply to Stefan Agner

On Wed, 9 Mar 2016 18:16:42 -0800
Stefan Agner <[email protected]> wrote:

Hi Stefan,

Quoted 81 lines

This patch introduces a driver for Vybrids GPC (Global Power Controller). Vybrids GPC IP is simpler than the one found in i.MX 6: There is no power gating control (GPC) and the GPC INTC does not need to clear IRQ masks for an interrupt to get routed to the GIC (the mask only applys for wake-up control).

---
 drivers/irqchip/Makefile        |   1 +
 drivers/irqchip/irq-vf610-gpc.c | 138 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100644 drivers/irqchip/irq-vf610-gpc.c
drivers/irqchip/Makefile +1 -0
index 18caacb..0a77ac6 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TS4800_IRQ)		+= irq-ts4800.o
 obj-$(CONFIG_XTENSA)			+= irq-xtensa-pic.o
 obj-$(CONFIG_XTENSA_MX)			+= irq-xtensa-mx.o
 obj-$(CONFIG_IRQ_CROSSBAR)		+= irq-crossbar.o
+obj-$(CONFIG_SOC_VF610)			+= irq-vf610-gpc.o
 obj-$(CONFIG_SOC_VF610)			+= irq-vf610-mscm-ir.o
 obj-$(CONFIG_BCM7038_L1_IRQ)		+= irq-bcm7038-l1.o
 obj-$(CONFIG_BCM7120_L2_IRQ)		+= irq-bcm7120-l2.o
drivers/irqchip/irq-vf610-gpc.c new file +50 -0
new file mode 100644
index 0000000..2c6a043
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2016 Toradex AG
+ * Author: Stefan Agner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *
+ * The GPC (General Power Controller) irqchip driver takes care of the
+ * interrupt wakeup functionality.
+ *
+ * o All peripheral interrupts of the Vybrid SoC can be used as wakeup
+ *   source from STOP mode. In LPSTOP mode however, the GPC is unpowered
+ *   too and cannot be used to as a wakeup source. The WKPU (Wakeup Unit)
+ *   is responsible for wakeups from LPSTOP modes.
+ */
+
+#include <linux/cpu_pm.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqdomain.h>
+#include <linux/mfd/syscon.h>
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/regmap.h>
+
+#define IMR_NUM			4
+#define VF610_GPC_IMR1		0x044
+#define VF610_GPC_MAX_IRQS	(IMR_NUM * 32)
+
+static void __iomem *gpc_base;
+
+static int vf610_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
+{
+	unsigned int idx = d->hwirq / 32;
+	void __iomem *reg_imr = gpc_base + VF610_GPC_IMR1 + (idx * 4);
+	u32 mask = 1 << d->hwirq % 32;
+
+	if (on)
+		writel_relaxed(readl_relaxed(reg_imr) & ~mask, reg_imr);
+	else
+		writel_relaxed(readl_relaxed(reg_imr) | mask, reg_imr);
+
+	/*
+	 * Do *not* call into the parent, as the GIC doesn't have any
+	 * wake-up facility...

drivers/irqchip/irq-vf610-gpc.c line 60

Quoted 10 lines
drivers/irqchip/irq-vf610-gpc.c new file +10 -0
+	 */
+	return 0;
+}
+
+static struct irq_chip vf610_gpc_chip = {
+	.name			= "vf610-gpc",
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_enable		= irq_chip_enable_parent,
+	.irq_disable		= irq_chip_disable_parent,

Any reason why you are providing enable/disable methods? This driver seems to be GIC specific (various comments in the code), but the GIC doesn't implement those.

Quoted 15 lines
drivers/irqchip/irq-vf610-gpc.c new file +15 -0
+	.irq_eoi		= irq_chip_eoi_parent,
+	.irq_retrigger		= irq_chip_retrigger_hierarchy,
+	.irq_set_wake		= vf610_gpc_irq_set_wake,
+};
+
+static int vf610_gpc_domain_alloc(struct irq_domain *domain, unsigned int virq,
+				  unsigned int nr_irqs, void *arg)
+{
+	int i;
+	irq_hw_number_t hwirq;
+	struct irq_fwspec *fwspec = arg;
+	struct irq_fwspec parent_fwspec;
+
+	if (!irq_domain_get_of_node(domain->parent))
+		return -EINVAL;

drivers/irqchip/irq-vf610-gpc.c line 85

Quoted 10 lines
drivers/irqchip/irq-vf610-gpc.c new file +10 -0
+
+	if (fwspec->param_count != 2)
+		return -EINVAL;
+
+	hwirq = fwspec->param[0];
+	for (i = 0; i < nr_irqs; i++)
+		irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
+					      &vf610_gpc_chip, NULL);
+
+	parent_fwspec = *fwspec;

Now I'm confused. The next irqchip in the hierarchy cannot be the GIC, because that's the wrong fwspec format (the GIC expect 3 parameters). Glancing at patch #2, I can see that this points to the mscm, so maybe it is that the comments are just wrong?

Quoted 28 lines
drivers/irqchip/irq-vf610-gpc.c new file +28 -0
+	parent_fwspec.fwnode = domain->parent->fwnode;
+	return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs,
+					    &parent_fwspec);
+}
+
+static int vf610_gpc_domain_translate(struct irq_domain *d,
+					  struct irq_fwspec *fwspec,
+					  unsigned long *hwirq,
+					  unsigned int *type)
+{
+	if (WARN_ON(fwspec->param_count < 2))
+		return -EINVAL;
+	*hwirq = fwspec->param[0];
+	*type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
+	return 0;
+}
+
+static const struct irq_domain_ops gpc_irq_domain_ops = {
+	.translate = vf610_gpc_domain_translate,
+	.alloc = vf610_gpc_domain_alloc,
+	.free = irq_domain_free_irqs_common,
+};
+
+static int __init vf610_gpc_of_init(struct device_node *node,
+			       struct device_node *parent)
+{
+	struct irq_domain *domain, *domain_parent;
+	int i;

drivers/irqchip/irq-vf610-gpc.c line 123

Quoted 10 lines
drivers/irqchip/irq-vf610-gpc.c new file +10 -0
+
+	domain_parent = irq_find_host(parent);
+	if (!domain_parent) {
+		pr_err("vf610_gpc: interrupt-parent not found\n");
+		return -EINVAL;
+	}
+
+	gpc_base = of_io_request_and_map(node, 0, "gpc");
+	if (WARN_ON(!gpc_base))
+		return PTR_ERR(gpc_base);

If gpc_base is NULL, PTR_ERR(NULL) returns 0. Probably not what you want here...

Quoted 5 lines
drivers/irqchip/irq-vf610-gpc.c new file +5 -0
+
+	domain = irq_domain_add_hierarchy(domain_parent, 0, VF610_GPC_MAX_IRQS,
+					  node, &gpc_irq_domain_ops, NULL);
+	if (!domain) {
+		iounmap(gpc_base);

drivers/irqchip/irq-vf610-gpc.c line 138

Quoted 10 lines
drivers/irqchip/irq-vf610-gpc.c new file +10 -0
+		return -ENOMEM;
+	}
+
+	/* Initially mask all interrupts for wakeup */
+	for (i = 0; i < IMR_NUM; i++)
+		writel_relaxed(~0, gpc_base + VF610_GPC_IMR1 + i * 4);
+
+	return 0;
+}
+IRQCHIP_DECLARE(vf610_gpc, "fsl,vf610-gpc", vf610_gpc_of_init);

It would be good to have some binding documentation as well.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny.
author reviewer
#3 lore raw

Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller

Hi Marc,

Quoted 92 lines · Marc Zyngier

On Wed, 9 Mar 2016 18:16:42 -0800
Stefan Agner <[email protected]> wrote:

Hi Stefan,

Quoted 87 lines

This patch introduces a driver for Vybrids GPC (Global Power Controller). Vybrids GPC IP is simpler than the one found in i.MX 6: There is no power gating control (GPC) and the GPC INTC does not need to clear IRQ masks for an interrupt to get routed to the GIC (the mask only applys for wake-up control).

---
 drivers/irqchip/Makefile        |   1 +
 drivers/irqchip/irq-vf610-gpc.c | 138 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100644 drivers/irqchip/irq-vf610-gpc.c
drivers/irqchip/Makefile +1 -0
index 18caacb..0a77ac6 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TS4800_IRQ)		+= irq-ts4800.o
 obj-$(CONFIG_XTENSA)			+= irq-xtensa-pic.o
 obj-$(CONFIG_XTENSA_MX)			+= irq-xtensa-mx.o
 obj-$(CONFIG_IRQ_CROSSBAR)		+= irq-crossbar.o
+obj-$(CONFIG_SOC_VF610)			+= irq-vf610-gpc.o
 obj-$(CONFIG_SOC_VF610)			+= irq-vf610-mscm-ir.o
 obj-$(CONFIG_BCM7038_L1_IRQ)		+= irq-bcm7038-l1.o
 obj-$(CONFIG_BCM7120_L2_IRQ)		+= irq-bcm7120-l2.o
drivers/irqchip/irq-vf610-gpc.c new file +56 -0
new file mode 100644
index 0000000..2c6a043
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2016 Toradex AG
+ * Author: Stefan Agner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *
+ * The GPC (General Power Controller) irqchip driver takes care of the
+ * interrupt wakeup functionality.
+ *
+ * o All peripheral interrupts of the Vybrid SoC can be used as wakeup
+ *   source from STOP mode. In LPSTOP mode however, the GPC is unpowered
+ *   too and cannot be used to as a wakeup source. The WKPU (Wakeup Unit)
+ *   is responsible for wakeups from LPSTOP modes.
+ */
+
+#include <linux/cpu_pm.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqdomain.h>
+#include <linux/mfd/syscon.h>
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/regmap.h>
+
+#define IMR_NUM			4
+#define VF610_GPC_IMR1		0x044
+#define VF610_GPC_MAX_IRQS	(IMR_NUM * 32)
+
+static void __iomem *gpc_base;
+
+static int vf610_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
+{
+	unsigned int idx = d->hwirq / 32;
+	void __iomem *reg_imr = gpc_base + VF610_GPC_IMR1 + (idx * 4);
+	u32 mask = 1 << d->hwirq % 32;
+
+	if (on)
+		writel_relaxed(readl_relaxed(reg_imr) & ~mask, reg_imr);
+	else
+		writel_relaxed(readl_relaxed(reg_imr) | mask, reg_imr);
+
+	/*
+	 * Do *not* call into the parent, as the GIC doesn't have any
+	 * wake-up facility...
+	 */
+	return 0;
+}
+
+static struct irq_chip vf610_gpc_chip = {
+	.name			= "vf610-gpc",
Quoted 8 lines

drivers/irqchip/irq-vf610-gpc.c line 60

Quoted 4 lines
drivers/irqchip/irq-vf610-gpc.c new file +4 -0
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_enable		= irq_chip_enable_parent,
+	.irq_disable		= irq_chip_disable_parent,

Any reason why you are providing enable/disable methods? This driver seems to be GIC specific (various comments in the code), but the GIC doesn't implement those.

There is another IRQ controller between the CPU's IRQ controller and the
peripherals: the MSCM Interrupt Router (drivers/irqchip/irq-vf610-mscm-ir.c).

This router allows to select to which CPU an interrupt gets routed (VF6xx variants of Vybrid with a Cortex-A5 and Cortex-M4 core).

Quoted 23 lines
Quoted 23 lines
drivers/irqchip/irq-vf610-gpc.c new file +22 -0
+	.irq_eoi		= irq_chip_eoi_parent,
+	.irq_retrigger		= irq_chip_retrigger_hierarchy,
+	.irq_set_wake		= vf610_gpc_irq_set_wake,
+};
+
+static int vf610_gpc_domain_alloc(struct irq_domain *domain, unsigned int virq,
+				  unsigned int nr_irqs, void *arg)
+{
+	int i;
+	irq_hw_number_t hwirq;
+	struct irq_fwspec *fwspec = arg;
+	struct irq_fwspec parent_fwspec;
+
+	if (!irq_domain_get_of_node(domain->parent))
+		return -EINVAL;
+
+	if (fwspec->param_count != 2)
+		return -EINVAL;
+
+	hwirq = fwspec->param[0];
+	for (i = 0; i < nr_irqs; i++)
+		irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
Quoted 8 lines

drivers/irqchip/irq-vf610-gpc.c line 85

Quoted 3 lines
drivers/irqchip/irq-vf610-gpc.c new file +3 -0
+					      &vf610_gpc_chip, NULL);
+
+	parent_fwspec = *fwspec;

Now I'm confused. The next irqchip in the hierarchy cannot be the GIC, because that's the wrong fwspec format (the GIC expect 3 parameters). Glancing at patch #2, I can see that this points to the mscm, so maybe it is that the comments are just wrong?

The above should explain that...

So with this driver the domain hierarchy stacks 3 IRQ controllers

GPC -> MSCM-IR -> NVIC/GIC (depending on CPU)

Quoted 34 lines
Quoted 34 lines
drivers/irqchip/irq-vf610-gpc.c new file +33 -0
+	parent_fwspec.fwnode = domain->parent->fwnode;
+	return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs,
+					    &parent_fwspec);
+}
+
+static int vf610_gpc_domain_translate(struct irq_domain *d,
+					  struct irq_fwspec *fwspec,
+					  unsigned long *hwirq,
+					  unsigned int *type)
+{
+	if (WARN_ON(fwspec->param_count < 2))
+		return -EINVAL;
+	*hwirq = fwspec->param[0];
+	*type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
+	return 0;
+}
+
+static const struct irq_domain_ops gpc_irq_domain_ops = {
+	.translate = vf610_gpc_domain_translate,
+	.alloc = vf610_gpc_domain_alloc,
+	.free = irq_domain_free_irqs_common,
+};
+
+static int __init vf610_gpc_of_init(struct device_node *node,
+			       struct device_node *parent)
+{
+	struct irq_domain *domain, *domain_parent;
+	int i;
+
+	domain_parent = irq_find_host(parent);
+	if (!domain_parent) {
+		pr_err("vf610_gpc: interrupt-parent not found\n");
+		return -EINVAL;
Quoted 9 lines

drivers/irqchip/irq-vf610-gpc.c line 123

Quoted 5 lines
drivers/irqchip/irq-vf610-gpc.c new file +5 -0
+	}
+
+	gpc_base = of_io_request_and_map(node, 0, "gpc");
+	if (WARN_ON(!gpc_base))
+		return PTR_ERR(gpc_base);

If gpc_base is NULL, PTR_ERR(NULL) returns 0. Probably not what you want here...

Hm, of_io_request_and_map actually returns a ERR_PTR, hence WARN_ON is not appropriate as it is used here.

Will remove that and replace with

if (IS_ERR(gpc_base))

	return PTR_ERR(gpc_base);
Quoted 9 lines
Quoted 9 lines
drivers/irqchip/irq-vf610-gpc.c new file +9 -0
+
+	domain = irq_domain_add_hierarchy(domain_parent, 0, VF610_GPC_MAX_IRQS,
+					  node, &gpc_irq_domain_ops, NULL);
+	if (!domain) {
+		iounmap(gpc_base);
+		return -ENOMEM;
+	}
+
+	/* Initially mask all interrupts for wakeup */
Quoted 8 lines

drivers/irqchip/irq-vf610-gpc.c line 138

Quoted 6 lines
drivers/irqchip/irq-vf610-gpc.c new file +6 -0
+	for (i = 0; i < IMR_NUM; i++)
+		writel_relaxed(~0, gpc_base + VF610_GPC_IMR1 + i * 4);
+
+	return 0;
+}
+IRQCHIP_DECLARE(vf610_gpc, "fsl,vf610-gpc", vf610_gpc_of_init);

It would be good to have some binding documentation as well.

Will add that

Thanks!

--
Stefan

#4 lore raw

Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller

Quoted 143 lines · On Fri, 11 Mar 2016 10:11:43 -0800 Stefan Agner <[email protected]> wrote:

Hi Marc,

Quoted 92 lines · Marc Zyngier

On Wed, 9 Mar 2016 18:16:42 -0800
Stefan Agner <[email protected]> wrote:

Hi Stefan,

Quoted 87 lines

This patch introduces a driver for Vybrids GPC (Global Power Controller). Vybrids GPC IP is simpler than the one found in i.MX 6: There is no power gating control (GPC) and the GPC INTC does not need to clear IRQ masks for an interrupt to get routed to the GIC (the mask only applys for wake-up control).

---
 drivers/irqchip/Makefile        |   1 +
 drivers/irqchip/irq-vf610-gpc.c | 138 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100644 drivers/irqchip/irq-vf610-gpc.c
drivers/irqchip/Makefile +1 -0
index 18caacb..0a77ac6 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TS4800_IRQ)		+= irq-ts4800.o
 obj-$(CONFIG_XTENSA)			+= irq-xtensa-pic.o
 obj-$(CONFIG_XTENSA_MX)			+= irq-xtensa-mx.o
 obj-$(CONFIG_IRQ_CROSSBAR)		+= irq-crossbar.o
+obj-$(CONFIG_SOC_VF610)			+= irq-vf610-gpc.o
 obj-$(CONFIG_SOC_VF610)			+= irq-vf610-mscm-ir.o
 obj-$(CONFIG_BCM7038_L1_IRQ)		+= irq-bcm7038-l1.o
 obj-$(CONFIG_BCM7120_L2_IRQ)		+= irq-bcm7120-l2.o
drivers/irqchip/irq-vf610-gpc.c new file +56 -0
new file mode 100644
index 0000000..2c6a043
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2016 Toradex AG
+ * Author: Stefan Agner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *
+ * The GPC (General Power Controller) irqchip driver takes care of the
+ * interrupt wakeup functionality.
+ *
+ * o All peripheral interrupts of the Vybrid SoC can be used as wakeup
+ *   source from STOP mode. In LPSTOP mode however, the GPC is unpowered
+ *   too and cannot be used to as a wakeup source. The WKPU (Wakeup Unit)
+ *   is responsible for wakeups from LPSTOP modes.
+ */
+
+#include <linux/cpu_pm.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqdomain.h>
+#include <linux/mfd/syscon.h>
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/regmap.h>
+
+#define IMR_NUM			4
+#define VF610_GPC_IMR1		0x044
+#define VF610_GPC_MAX_IRQS	(IMR_NUM * 32)
+
+static void __iomem *gpc_base;
+
+static int vf610_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
+{
+	unsigned int idx = d->hwirq / 32;
+	void __iomem *reg_imr = gpc_base + VF610_GPC_IMR1 + (idx * 4);
+	u32 mask = 1 << d->hwirq % 32;
+
+	if (on)
+		writel_relaxed(readl_relaxed(reg_imr) & ~mask, reg_imr);
+	else
+		writel_relaxed(readl_relaxed(reg_imr) | mask, reg_imr);
+
+	/*
+	 * Do *not* call into the parent, as the GIC doesn't have any
+	 * wake-up facility...
+	 */
+	return 0;
+}
+
+static struct irq_chip vf610_gpc_chip = {
+	.name			= "vf610-gpc",
Quoted 8 lines

drivers/irqchip/irq-vf610-gpc.c line 60

Quoted 4 lines
drivers/irqchip/irq-vf610-gpc.c new file +4 -0
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_enable		= irq_chip_enable_parent,
+	.irq_disable		= irq_chip_disable_parent,

Any reason why you are providing enable/disable methods? This driver seems to be GIC specific (various comments in the code), but the GIC doesn't implement those.

There is another IRQ controller between the CPU's IRQ controller and the
peripherals: the MSCM Interrupt Router (drivers/irqchip/irq-vf610-mscm-ir.c).

This router allows to select to which CPU an interrupt gets routed (VF6xx variants of Vybrid with a Cortex-A5 and Cortex-M4 core).

Quoted 23 lines
Quoted 23 lines
drivers/irqchip/irq-vf610-gpc.c new file +22 -0
+	.irq_eoi		= irq_chip_eoi_parent,
+	.irq_retrigger		= irq_chip_retrigger_hierarchy,
+	.irq_set_wake		= vf610_gpc_irq_set_wake,
+};
+
+static int vf610_gpc_domain_alloc(struct irq_domain *domain, unsigned int virq,
+				  unsigned int nr_irqs, void *arg)
+{
+	int i;
+	irq_hw_number_t hwirq;
+	struct irq_fwspec *fwspec = arg;
+	struct irq_fwspec parent_fwspec;
+
+	if (!irq_domain_get_of_node(domain->parent))
+		return -EINVAL;
+
+	if (fwspec->param_count != 2)
+		return -EINVAL;
+
+	hwirq = fwspec->param[0];
+	for (i = 0; i < nr_irqs; i++)
+		irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
Quoted 8 lines

drivers/irqchip/irq-vf610-gpc.c line 85

Quoted 3 lines
drivers/irqchip/irq-vf610-gpc.c new file +3 -0
+					      &vf610_gpc_chip, NULL);
+
+	parent_fwspec = *fwspec;

Now I'm confused. The next irqchip in the hierarchy cannot be the GIC, because that's the wrong fwspec format (the GIC expect 3 parameters). Glancing at patch #2, I can see that this points to the mscm, so maybe it is that the comments are just wrong?

Quoted 6 lines

The above should explain that...

So with this driver the domain hierarchy stacks 3 IRQ controllers

GPC -> MSCM-IR -> NVIC/GIC (depending on CPU)

In which case, can you drop the references to the GIC in the various comments (in the commit message and in the set_wake function)? This irqchip never "see" the GIC directly, and the MSCM-IR always acts as an "impedance matcher".

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny.
maintainer
#31 lore raw

Re: [PATCH 14/18] gpio: vf610: add support for WKPU unit

In reply to Stefan Agner
Quoted 16 lines · Stefan Agner

WKPU unit support within the VF610 GPIO driver. The WKPU unit allows some GPIO to be the wakeup source from lowest power modes LPSTOPx. The relationship between the GPIO banks and the WKPU GPIO numbering can be derived from the device tree property fsl,gpio-wakeup.

---
 .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
 drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
 2 files changed, 157 insertions(+)
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +0 -0
index 436cc99..985ddfd 100644

Documentation/devicetree/bindings/gpio/gpio-vf610.txt Required properties for GPIO node: · line 25

Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +1 -0
@@ -22,6 +22,12 @@ Required properties for GPIO node:
       4 = active high level-sensitive.
       8 = active low level-sensitive.
 
+Option properties:

Optional

Documentation/devicetree/bindings/gpio/gpio-vf610.txt Required properties for GPIO node: · line 26

Quoted 1 line
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +1 -0
+- fsl,gpio-wakeup : map GPIOs to WKPU unit, 3 argument cells per phandle

phandle to what?

Documentation/devicetree/bindings/gpio/gpio-vf610.txt Required properties for GPIO node: · line 29

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +3 -0
+      cell 1: First GPIO (relative to the GPIO block)
+      cell 2: First GPIO of the WKPU unit
+      cell 3: Number of consecutive GPIO's

An interrupt-map could work here instead even though I'm guessing you don't make the WKPU an interrupt parent. Your table would look something like this:

<WKPU# <&gpio> GPIO#>

drivers/gpio/gpio-vf610.c

Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +1 -0
+
 Note: Each GPIO port should have an alias correctly numbered in "aliases"
 node.
 
drivers/gpio/gpio-vf610.c +0 -0
index 1a022be..650a41a 100644

The WKPU seems to purely be an interrupt controller. Perhaps you should use stacked irq domain here. Then it would not be tied into the GPIO controller at all.

Rob

author reviewer
#32 lore raw

Re: [PATCH 14/18] gpio: vf610: add support for WKPU unit

Hi Rob,

Quoted 32 lines · Rob Herring
Quoted 16 lines · Stefan Agner

WKPU unit support within the VF610 GPIO driver. The WKPU unit allows some GPIO to be the wakeup source from lowest power modes LPSTOPx. The relationship between the GPIO banks and the WKPU GPIO numbering can be derived from the device tree property fsl,gpio-wakeup.

---
 .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
 drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
 2 files changed, 157 insertions(+)
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +0 -0
index 436cc99..985ddfd 100644

Documentation/devicetree/bindings/gpio/gpio-vf610.txt Required properties for GPIO node: · line 25

Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +1 -0
@@ -22,6 +22,12 @@ Required properties for GPIO node:
       4 = active high level-sensitive.
       8 = active low level-sensitive.
 
+Option properties:

Optional

Documentation/devicetree/bindings/gpio/gpio-vf610.txt Required properties for GPIO node: · line 26

Quoted 1 line
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +1 -0
+- fsl,gpio-wakeup : map GPIOs to WKPU unit, 3 argument cells per phandle

phandle to what?

Documentation/devicetree/bindings/gpio/gpio-vf610.txt Required properties for GPIO node: · line 29

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +3 -0
+      cell 1: First GPIO (relative to the GPIO block)
+      cell 2: First GPIO of the WKPU unit
+      cell 3: Number of consecutive GPIO's
Quoted 6 lines

An interrupt-map could work here instead even though I'm guessing you don't make the WKPU an interrupt parent. Your table would look something like this:

<WKPU# <&gpio> GPIO#>

Hm, that would need two interrupt parents since the main interrupt for the GPIO's would still be GIC...

Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-vf610.txt +1 -0
+
 Note: Each GPIO port should have an alias correctly numbered in "aliases"
 node.
 
Quoted 8 lines

drivers/gpio/gpio-vf610.c

Quoted 4 lines
drivers/gpio/gpio-vf610.c +0 -0
index 1a022be..650a41a 100644

The WKPU seems to purely be an interrupt controller. Perhaps you should use stacked irq domain here. Then it would not be tied into the GPIO controller at all.

It actually allows to configure pull-up/downs, that is why I chose to implement it as a GPIO controller. Although the pull-up/down part is not implemented yet.

But when I think about it, it actually is probably more a pinctrl with interrupt capabilities?

--
Stefan

maintainer
#39 lore raw

Re: [PATCH 17/18] Documentation: dt: add Vybrid DDR memory controller bindings

In reply to Stefan Agner
Quoted 7 lines · Stefan Agner

Add device-tree bindings of Vybrids LPDDR2/DDR3 SDRAM Memory Controller. Access to the device is required to put the memory into self-refresh mode.

---
 .../bindings/arm/freescale/fsl,vf610-ddrmc.txt     | 23 ++++++++++++++++++++++

Move to bindings/memory-controllers/

Quoted 16 lines
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt new file +7 -0
new file mode 100644
index 0000000..56a71d6
@@ -0,0 +1,23 @@
+Freescale Vybrid LPDDR2/DDR3 SDRAM Memory Controller
+
+The memory controller supports high performance applications for 16-bit or
+8-bit DDR2, or LPDDR SDRAM memories.
+
+Required properties:
+- compatible:	"fsl,vf610-ddrmc"

Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt new file +10 -0
+- reg:		the register range of the DDRMC registers
+- clocks:	DDRMC main clock to clock memory and access registers.
+- clock-names:	Must contain "ddrc", matching entry in the clocks property.
+- fsl,has-cke-reset-pulls:
+		States whether pull-down/up are populated on DDR CKE/RESET
+		signals to allow using DDR self-refresh modes (see Vybrid
+		Hardware Development Guide for details).
+
+Example:
+	ddrmc: ddrmc at 400ae000 {

memory-controller at ...

Quoted 9 lines
Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt new file +6 -0
+		compatible = "fsl,vf610-ddrmc";
+		reg = <0x400ae000 0x1000>;
+		clocks = <&clks VF610_CLK_DDRMC>;
+		clock-names = "ddrc";
+		fsl,has-cke-reset-pulls;
+	}
Signature · 1 line
2.7.2
#5 lore raw

Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller

In reply to Stefan Agner
Quoted 4 lines · Stefan Agner
drivers/irqchip/irq-vf610-gpc.c new file +4 -0
+static int __init vf610_gpc_of_init(struct device_node *node,
+			       struct device_node *parent)
+{
+	struct irq_domain *domain, *domain_parent;

drivers/irqchip/irq-vf610-gpc.c line 122

Quoted 10 lines
drivers/irqchip/irq-vf610-gpc.c new file +10 -0
+	int i;
+
+	domain_parent = irq_find_host(parent);
+	if (!domain_parent) {
+		pr_err("vf610_gpc: interrupt-parent not found\n");
+		return -EINVAL;
+	}
+
+	gpc_base = of_io_request_and_map(node, 0, "gpc");
+	if (WARN_ON(!gpc_base))

of_io_request_and_map() doesn't return NULL for error but an error code encoded by ERR_PTR(). That said, you should use IS_ERR(gpc_base) rather than !gpc_base for error check.

Shawn

Quoted 20 lines
drivers/irqchip/irq-vf610-gpc.c new file +16 -0
+		return PTR_ERR(gpc_base);
+
+	domain = irq_domain_add_hierarchy(domain_parent, 0, VF610_GPC_MAX_IRQS,
+					  node, &gpc_irq_domain_ops, NULL);
+	if (!domain) {
+		iounmap(gpc_base);
+		return -ENOMEM;
+	}
+
+	/* Initially mask all interrupts for wakeup */
+	for (i = 0; i < IMR_NUM; i++)
+		writel_relaxed(~0, gpc_base + VF610_GPC_IMR1 + i * 4);
+
+	return 0;
+}
+IRQCHIP_DECLARE(vf610_gpc, "fsl,vf610-gpc", vf610_gpc_of_init);
Signature · 1 line
2.7.2
#10 lore raw

Re: [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key

In reply to Stefan Agner
Quoted 4 lines · Stefan Agner

Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the Colibri default wakeup pin SO-DIMM 45.

I think this one can be merged independently, right? One small comment below though.

Quoted 23 lines
---
 arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi +4 -0
index 4d8b7f6..936ece6 100644
@@ -39,6 +39,8 @@
  *     OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <dt-bindings/input/input.h>
+
 / {
 	chosen {
 		stdout-path = "serial0:115200n8";
@@ -74,6 +76,20 @@
 		gpio = <&gpio2 19 GPIO_ACTIVE_LOW>; /* USBH_PEN resp. USBH_P_EN */
 		vin-supply = <&reg_5v0>;
 	};
+
+	gpio-keys {

arch/arm/boot/dts/vf-colibri-eval-v3.dtsi line 90

Quoted 10 lines
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi +10 -0
+		compatible = "gpio-keys";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_gpiokeys>;
+
+		power {
+			label = "Wake-Up";
+			gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
+			linux,code = <KEY_WAKEUP>;
+			debounce-interval = <10>;
+			gpio-key,wakeup;

Please use generic 'wakeup-source' instead. See the following document for details.

Documentation/devicetree/bindings/power/wakeup-source.txt

Shawn

Quoted 21 lines
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi +8 -0
+		};
+	};
 };
 
 &bl {
@@ -157,5 +173,11 @@
 				VF610_PAD_PTB21__GPIO_43	0x22ed
 			>;
 		};
+
+		pinctrl_gpiokeys: gpiokeys {
+			fsl,pins = <
+				VF610_PAD_PTB19__GPIO_41	0x218d
+			>;
+		};
 	};
 };
Signature · 1 line
2.7.2
#7 lore raw

Re: [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent

In reply to Stefan Agner
Quoted 1 line · Stefan Agner

So this patch cannot be applied before the fsl,vf610-gpc driver gets landed on mainline.

Shawn

Quoted 36 lines
---
 arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/boot/dts/vfxxx.dtsi +9 -1
index 5e49fbd..909988d 100644
@@ -88,7 +88,7 @@
 		#address-cells = <1>;
 		#size-cells = <1>;
 		compatible = "simple-bus";
-		interrupt-parent = <&mscm_ir>;
+		interrupt-parent = <&gpc>;
 		ranges;
 
 		aips0: aips-bus at 40000000 {
@@ -475,6 +475,14 @@
 				reg = <0x4006e000 0x1000>;
 				interrupts = <96 IRQ_TYPE_LEVEL_HIGH>;
 			};
+
+			gpc: gpc at 4006c000 {
+				compatible = "fsl,vf610-gpc";
+				reg = <0x4006c000 0x1000>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+				interrupt-parent = <&mscm_ir>;
+			};
 		};
 
 		aips1: aips-bus at 40080000 {
Signature · 1 line
2.7.2
#13 lore raw

Re: [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM

In reply to Stefan Agner
Quoted 5 lines · Stefan Agner

Add Vybrids massive on-chip SRAM areas. Make use of the memory region functionality to denominate the retained SRAM area in LPSTOP2 and LPSTOP3.

This one looks fine to me. I was going to pick it up separately, but it doesn't apply.

Shawn

Quoted 56 lines
---
 arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
arch/arm/boot/dts/vfxxx.dtsi +37 -0
index 909988d..b038ea4 100644
@@ -91,6 +91,43 @@
 		interrupt-parent = <&gpc>;
 		ranges;
 
+		ocram0: sram at 3f000000 {
+			compatible = "mmio-sram";
+			reg = <0x3f000000 0x40000>;
+
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x3f000000 0x40000>;
+
+			stbyram1 at 0 {
+				reg = <0x0 0x4000>;
+				label = "stbyram1";
+				pool;
+			};
+
+			stbyram2 at 4000 {
+				reg = <0x4000 0xc000>;
+				label = "stbyram2";
+				pool;
+			};
+		};
+
+		ocram1: sram at 3f040000 {
+			compatible = "mmio-sram";
+			reg = <0x3f040000 0x40000>;
+		};
+
+		gfxram0: sram at 3f400000 {
+			compatible = "mmio-sram";
+			reg = <0x3f400000 0x80000>;
+		};
+
+		/* used by L2 cache */
+		gfxram1: sram at 3f480000 {
+			compatible = "mmio-sram";
+			reg = <0x3f480000 0x80000>;
+		};
+
 		aips0: aips-bus at 40000000 {
 			compatible = "fsl,aips-bus", "simple-bus";
 			#address-cells = <1>;
Signature · 1 line
2.7.2
#16 lore raw

Re: [PATCH 05/18] ARM: dts: vf610: add modules required for PM

In reply to Stefan Agner
Quoted 10 lines · Stefan Agner
---
 arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm/boot/dts/vfxxx.dtsi +0 -0
index b038ea4..335f4e5 100644

arch/arm/boot/dts/vfxxx.dtsi line 438

Quoted 5 lines
arch/arm/boot/dts/vfxxx.dtsi +2 -0
@@ -434,6 +434,11 @@
 				reg = <0x40050000 0x400>;
 			};
 
+			scsc: scsc at 40052000 {
+				compatible = "fsl,vf610-scsc";

These new compatible strings should be documented somewhere.

Shawn

Quoted 38 lines
arch/arm/boot/dts/vfxxx.dtsi +17 -0
+				reg = <0x40052000 0x1000>;
+			};
+
 			usbphy0: usbphy at 40050800 {
 				compatible = "fsl,vf610-usbphy";
 				reg = <0x40050800 0x400>;
@@ -480,6 +485,13 @@
 				status = "disabled";
 			};
 
+			wakeup: wkpu at 4006a000 {
+				compatible = "fsl,vf610-wkpu";
+				reg = <0x4006a000 0x1000>;
+				interrupts = <92 IRQ_TYPE_LEVEL_HIGH>;
+				clocks = <&clks VF610_CLK_WKPU>;
+			};
+
 			clks: ccm at 4006b000 {
 				compatible = "fsl,vf610-ccm";
 				reg = <0x4006b000 0x1000>;
@@ -600,6 +612,13 @@
 				status = "disabled";
 			};
 
+			ddrmc: ddrmc at 400ae000 {
+				compatible = "fsl,vf610-ddrmc";
+				reg = <0x400ae000 0x400>;
+				clocks = <&clks VF610_CLK_DDRMC>;
+				clock-names = "ddrc";
+			};
+
 			adc1: adc at 400bb000 {
 				compatible = "fsl,vf610-adc";
 				reg = <0x400bb000 0x1000>;
Signature · 1 line
2.7.2
#18 lore raw

Re: [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration

In reply to Stefan Agner
Quoted 8 lines · Stefan Agner

The 2-bit gates found i.MX and Vybrid SoC support different clock configuration:

0b00: clk disabled
0b01: clk enabled in RUN mode but disabled in WAIT and STOP mode 0b10: clk enabled in RUN, WAIT and STOP mode (only Vybrid) 0b11: clk enabled in RUN and WAIT mode

Quoted 6 lines

For some clocks, we might want to configure different behaviour, e.g. a memory clock should be on even in STOP mode. Add a new function imx_clk_gate2_cgr which allow to configure specific gate values through the cgr_val parameter.

It's not appropriate to use 'ARM:' as subject prefix any more, since clock drivers had been moved to drivers/clk.

I applied patch 6 ~ 9 with updating the subject prefix as below.

clk: imx: vf610: add suspend/resume support
clk: imx: vf610: add WKPU unit
clk: imx: vf610: leave DDR clock on
clk: imx: clk-gate2: allow custom gate configuration

Shawn

#24 lore raw

Re: [PATCH 09/18] ARM: vf610: clk: add suspend/resume support

In reply to Stefan Agner

drivers/clk/imx/clk-vf610.c static void __init vf610_clocks_init(struct device_node *ccm_node) · line 471

Quoted 13 lines · Stefan Agner
drivers/clk/imx/clk-vf610.c +3 -0
@@ -414,9 +460,12 @@ static void __init vf610_clocks_init(struct device_node *ccm_node)
 	for (i = 0; i < ARRAY_SIZE(clks_init_on); i++)
 		clk_prepare_enable(clk[clks_init_on[i]]);
 
+	register_syscore_ops(&vf610_clk_syscore_ops);
+
 	/* Add the clocks to provider list */
 	clk_data.clks = clk;
 	clk_data.clk_num = ARRAY_SIZE(clk);
 	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
 }
 CLK_OF_DECLARE(vf610, "fsl,vf610-ccm", vf610_clocks_init);
+

This is an unrelated change and brings in an 'new blank line at EOF' warning. I dropped it when applying the patch.

Shawn

#26 lore raw

Re: [PATCH 10/18] tty: serial: fsl_lpuart: support suspend/resume

In reply to Stefan Agner
Quoted 11 lines · Stefan Agner

In order to allow wake support in STOP sleep mode, clocks are needed. Use imx_clk_gate2_cgr to disable automatic clock gating in low power mode STOP. This allows to enable wake by UART using:
echo enabled > /sys/class/tty/ttyLP0/power/wakeup

However, if wake is not enabled, the driver should disable the clocks explicitly to save power.

---
 drivers/clk/imx/clk-vf610.c     | 12 ++++++------

It should go to a separate patch.

Shawn

Quoted 80 lines
 drivers/tty/serial/fsl_lpuart.c | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)
drivers/clk/imx/clk-vf610.c +6 -6
index e2e2c43..170a96c 100644
@@ -315,12 +315,12 @@ static void __init vf610_clocks_init(struct device_node *ccm_node)
 
 	clk[VF610_CLK_PIT] = imx_clk_gate2("pit", "ipg_bus", CCM_CCGR1, CCM_CCGRx_CGn(7));
 
-	clk[VF610_CLK_UART0] = imx_clk_gate2("uart0", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(7));
-	clk[VF610_CLK_UART1] = imx_clk_gate2("uart1", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(8));
-	clk[VF610_CLK_UART2] = imx_clk_gate2("uart2", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(9));
-	clk[VF610_CLK_UART3] = imx_clk_gate2("uart3", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(10));
-	clk[VF610_CLK_UART4] = imx_clk_gate2("uart4", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(9));
-	clk[VF610_CLK_UART5] = imx_clk_gate2("uart5", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(10));
+	clk[VF610_CLK_UART0] = imx_clk_gate2_cgr("uart0", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(7), 0x2);
+	clk[VF610_CLK_UART1] = imx_clk_gate2_cgr("uart1", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(8), 0x2);
+	clk[VF610_CLK_UART2] = imx_clk_gate2_cgr("uart2", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(9), 0x2);
+	clk[VF610_CLK_UART3] = imx_clk_gate2_cgr("uart3", "ipg_bus", CCM_CCGR0, CCM_CCGRx_CGn(10), 0x2);
+	clk[VF610_CLK_UART4] = imx_clk_gate2_cgr("uart4", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(9), 0x2);
+	clk[VF610_CLK_UART5] = imx_clk_gate2_cgr("uart5", "ipg_bus", CCM_CCGR6, CCM_CCGRx_CGn(10), 0x2);
 
 	clk[VF610_CLK_I2C0] = imx_clk_gate2("i2c0", "ipg_bus", CCM_CCGR4, CCM_CCGRx_CGn(6));
 	clk[VF610_CLK_I2C1] = imx_clk_gate2("i2c1", "ipg_bus", CCM_CCGR4, CCM_CCGRx_CGn(7));
drivers/tty/serial/fsl_lpuart.c +14 -2
index 3d79003..94e29ba 100644
@@ -483,9 +483,8 @@ static void lpuart_dma_rx_complete(void *arg)
 	spin_unlock_irqrestore(&sport->port.lock, flags);
 }
 
-static void lpuart_timer_func(unsigned long data)
+static void lpuart_dma_rx_terminate(struct lpuart_port *sport)
 {
-	struct lpuart_port *sport = (struct lpuart_port *)data;
 	struct tty_port *port = &sport->port.state->port;
 	struct dma_tx_state state;
 	unsigned long flags;
@@ -510,6 +509,11 @@ static void lpuart_timer_func(unsigned long data)
 	spin_unlock_irqrestore(&sport->port.lock, flags);
 }
 
+static void lpuart_timer_func(unsigned long data)
+{
+	lpuart_dma_rx_terminate((struct lpuart_port *)data);
+}
+
 static inline void lpuart_prepare_rx(struct lpuart_port *sport)
 {
 	unsigned long flags;
@@ -1915,7 +1919,12 @@ static int lpuart_suspend(struct device *dev)
 		writeb(temp, sport->port.membase + UARTCR2);
 	}
 
+	if (sport->dma_rx_in_progress)
+		lpuart_dma_rx_terminate(sport);
+
 	uart_suspend_port(&lpuart_reg, &sport->port);
+	if (sport->port.suspended && !sport->port.irq_wake)
+		clk_disable_unprepare(sport->clk);
 
 	return 0;
 }
@@ -1925,6 +1934,9 @@ static int lpuart_resume(struct device *dev)
 	struct lpuart_port *sport = dev_get_drvdata(dev);
 	unsigned long temp;
 
+	if (sport->port.suspended && !sport->port.irq_wake)
+		clk_prepare_enable(sport->clk);
+
 	if (sport->lpuart32) {
 		lpuart32_setup_watermark(sport);
 		temp = lpuart32_read(sport->port.membase + UARTCTRL);
Signature · 1 line
2.7.2
author reviewer
#8 lore raw

Re: [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent

In reply to Shawn Guo
Quoted 5 lines · Shawn Guo
Quoted 1 line · Stefan Agner

So this patch cannot be applied before the fsl,vf610-gpc driver gets landed on mainline.

Yes!

--
Stefan

Quoted 36 lines
Quoted 36 lines
---
 arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/boot/dts/vfxxx.dtsi +9 -2
index 5e49fbd..909988d 100644
@@ -88,7 +88,7 @@
 		#address-cells = <1>;
 		#size-cells = <1>;
 		compatible = "simple-bus";
-		interrupt-parent = <&mscm_ir>;
+		interrupt-parent = <&gpc>;
 		ranges;
 
 		aips0: aips-bus at 40000000 {
@@ -475,6 +475,14 @@
 				reg = <0x4006e000 0x1000>;
 				interrupts = <96 IRQ_TYPE_LEVEL_HIGH>;
 			};
+
+			gpc: gpc at 4006c000 {
+				compatible = "fsl,vf610-gpc";
+				reg = <0x4006c000 0x1000>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+				interrupt-parent = <&mscm_ir>;
+			};
 		};
 
 		aips1: aips-bus at 40080000 {
--

2.7.2

author reviewer
#11 lore raw

Re: [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key

In reply to Shawn Guo
Quoted 9 lines · Shawn Guo
Quoted 4 lines · Stefan Agner

Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the Colibri default wakeup pin SO-DIMM 45.

I think this one can be merged independently, right? One small comment below though.

Yes, shouldn't cause any trouble even if wakeup/suspend is not yet implemented.

Quoted 37 lines
Quoted 23 lines
---
 arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi +4 -0
index 4d8b7f6..936ece6 100644
@@ -39,6 +39,8 @@
  *     OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <dt-bindings/input/input.h>
+
 / {
 	chosen {
 		stdout-path = "serial0:115200n8";
@@ -74,6 +76,20 @@
 		gpio = <&gpio2 19 GPIO_ACTIVE_LOW>; /* USBH_PEN resp. USBH_P_EN */
 		vin-supply = <&reg_5v0>;
 	};
+
+	gpio-keys {

arch/arm/boot/dts/vf-colibri-eval-v3.dtsi line 90

Quoted 10 lines
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi +10 -0
+		compatible = "gpio-keys";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_gpiokeys>;
+
+		power {
+			label = "Wake-Up";
+			gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
+			linux,code = <KEY_WAKEUP>;
+			debounce-interval = <10>;
+			gpio-key,wakeup;

Please use generic 'wakeup-source' instead. See the following document for details.

Quoted 1 line

Documentation/devicetree/bindings/power/wakeup-source.txt

Will do.

--
Stefan

Quoted 22 lines
Quoted 22 lines
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi +8 -1
+		};
+	};
 };
 
 &bl {
@@ -157,5 +173,11 @@
 				VF610_PAD_PTB21__GPIO_43	0x22ed
 			>;
 		};
+
+		pinctrl_gpiokeys: gpiokeys {
+			fsl,pins = <
+				VF610_PAD_PTB19__GPIO_41	0x218d
+			>;
+		};
 	};
 };
--

2.7.2

author reviewer
#14 lore raw

Re: [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM

In reply to Shawn Guo
Quoted 9 lines · Shawn Guo
Quoted 5 lines · Stefan Agner

Add Vybrids massive on-chip SRAM areas. Make use of the memory region functionality to denominate the retained SRAM area in LPSTOP2 and LPSTOP3.

This one looks fine to me. I was going to pick it up separately, but it doesn't apply.

... see below

Quoted 10 lines

arch/arm/boot/dts/vfxxx.dtsi line 91

Quoted 10 lines
---
 arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
arch/arm/boot/dts/vfxxx.dtsi +0 -0
index 909988d..b038ea4 100644
@@ -91,6 +91,43 @@
 		interrupt-parent = <&gpc>;

I guess this gpc interrupt parent causes the apply problem. I will move this patch to the top so it can be applied before the GPC driver and dt changes.

--
Stefan

Quoted 46 lines
Quoted 46 lines
arch/arm/boot/dts/vfxxx.dtsi +37 -1
 		ranges;
 
+		ocram0: sram at 3f000000 {
+			compatible = "mmio-sram";
+			reg = <0x3f000000 0x40000>;
+
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x3f000000 0x40000>;
+
+			stbyram1 at 0 {
+				reg = <0x0 0x4000>;
+				label = "stbyram1";
+				pool;
+			};
+
+			stbyram2 at 4000 {
+				reg = <0x4000 0xc000>;
+				label = "stbyram2";
+				pool;
+			};
+		};
+
+		ocram1: sram at 3f040000 {
+			compatible = "mmio-sram";
+			reg = <0x3f040000 0x40000>;
+		};
+
+		gfxram0: sram at 3f400000 {
+			compatible = "mmio-sram";
+			reg = <0x3f400000 0x80000>;
+		};
+
+		/* used by L2 cache */
+		gfxram1: sram at 3f480000 {
+			compatible = "mmio-sram";
+			reg = <0x3f480000 0x80000>;
+		};
+
 		aips0: aips-bus at 40000000 {
 			compatible = "fsl,aips-bus", "simple-bus";
 			#address-cells = <1>;
--

2.7.2

author reviewer
#19 lore raw

Re: [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration

In reply to Shawn Guo
Quoted 14 lines · Shawn Guo
Quoted 13 lines · Stefan Agner

The 2-bit gates found i.MX and Vybrid SoC support different clock configuration:

0b00: clk disabled
0b01: clk enabled in RUN mode but disabled in WAIT and STOP mode 0b10: clk enabled in RUN, WAIT and STOP mode (only Vybrid) 0b11: clk enabled in RUN and WAIT mode

For some clocks, we might want to configure different behaviour, e.g. a memory clock should be on even in STOP mode. Add a new function imx_clk_gate2_cgr which allow to configure specific gate values through the cgr_val parameter.

Quoted 4 lines
Quoted 1 line

It's not appropriate to use 'ARM:' as subject prefix any more, since clock drivers had been moved to drivers/clk.

Agreed. Evidence on how long I dragged those patches in my own tree :-/

Quoted 7 lines

I applied patch 6 ~ 9 with updating the subject prefix as below.

clk: imx: vf610: add suspend/resume support
clk: imx: vf610: add WKPU unit
clk: imx: vf610: leave DDR clock on
clk: imx: clk-gate2: allow custom gate configuration

Thanks!

--
Stefan

#35 lore raw

Re: [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support

In reply to Stefan Agner
Quoted 19 lines · Stefan Agner

Add system suspend and resume support for Vybrid SoC. The standby sleep state puts the SoC in STOP mode. The SoC can be woken through an interrupt from GPC (Global Power Controller). The GPC can use any interrupt as wake-up source. To save power the main PLL1 is bypassed and uses the 24MHz on-chip oscillator. However, memory clock need to be at full speed, hence the PLL2 needs to be on to keep the memory clocked. The mode is completely implemented in C since we can access the full memory at all times. The mode provides most power saving while being able to be woken by any IRQ as wake-up source.

The mem sleep state (Suspend-to-RAM) uses Vybrid's LPSTOP2 mode. This mode powergates most parts of the SoC expect some peripherials such as Wake-Up controller (WKPU) or LP RTC. Parts of the internal SRAM is retained too. The suspend code written in assembly runs from this SRAM. The code puts the main memory (DDR3) into self-refresh mode and takes it out of self-refresh mode on resume. Verified with Colibri VF50/VF61 V1.2A.

Quoted 10 lines
---
 arch/arm/mach-imx/Makefile        |   3 +
 arch/arm/mach-imx/common.h        |  10 +
 arch/arm/mach-imx/mach-vf610.c    |   8 +
 arch/arm/mach-imx/pm-vf610.c      | 634 ++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/suspend-vf610.S | 437 ++++++++++++++++++++++++++
 drivers/clk/imx/clk-vf610.c       |  17 +
 6 files changed, 1109 insertions(+)
 create mode 100644 arch/arm/mach-imx/pm-vf610.c
 create mode 100644 arch/arm/mach-imx/suspend-vf610.S

I know this is how we implemented suspend for i.MX6. But this is not the direction moving forward. When people was pushing a pile of code adding suspend for i.MX7D, I refused to take it and asked them to push those hardware details into firmware and use PSCI to implement suspend. I would like to suggest the same for Vybrid.

Shawn

author reviewer
#36 lore raw

Re: [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support

Quoted 31 lines · Shawn Guo
Quoted 19 lines · Stefan Agner

Add system suspend and resume support for Vybrid SoC. The standby sleep state puts the SoC in STOP mode. The SoC can be woken through an interrupt from GPC (Global Power Controller). The GPC can use any interrupt as wake-up source. To save power the main PLL1 is bypassed and uses the 24MHz on-chip oscillator. However, memory clock need to be at full speed, hence the PLL2 needs to be on to keep the memory clocked. The mode is completely implemented in C since we can access the full memory at all times. The mode provides most power saving while being able to be woken by any IRQ as wake-up source.

The mem sleep state (Suspend-to-RAM) uses Vybrid's LPSTOP2 mode. This mode powergates most parts of the SoC expect some peripherials such as Wake-Up controller (WKPU) or LP RTC. Parts of the internal SRAM is retained too. The suspend code written in assembly runs from this SRAM. The code puts the main memory (DDR3) into self-refresh mode and takes it out of self-refresh mode on resume. Verified with Colibri VF50/VF61 V1.2A.

Quoted 10 lines
---
 arch/arm/mach-imx/Makefile        |   3 +
 arch/arm/mach-imx/common.h        |  10 +
 arch/arm/mach-imx/mach-vf610.c    |   8 +
 arch/arm/mach-imx/pm-vf610.c      | 634 ++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/suspend-vf610.S | 437 ++++++++++++++++++++++++++
 drivers/clk/imx/clk-vf610.c       |  17 +
 6 files changed, 1109 insertions(+)
 create mode 100644 arch/arm/mach-imx/pm-vf610.c
 create mode 100644 arch/arm/mach-imx/suspend-vf610.S
Quoted 5 lines

I know this is how we implemented suspend for i.MX6. But this is not the direction moving forward. When people was pushing a pile of code adding suspend for i.MX7D, I refused to take it and asked them to push those hardware details into firmware and use PSCI to implement suspend. I would like to suggest the same for Vybrid.

Yeah I saw your comment on the i.MX7D patchset, and kind of hoped it does not apply for Vybrid :-)

I see, need to look into PSCI closer, and see how much work it would be to set that up and transfer the code into it...

--
Stefan