All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/18] ARM: vf610: Suspend/resume with self-refresh mode
@ 2016-03-10  2:16 ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Stefan Agner

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

-- 
2.7.2

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 00/18] ARM: vf610: Suspend/resume with self-refresh mode
@ 2016-03-10  2:16 ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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

-- 
2.7.2

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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).

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 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

diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 18caacb..0a77ac6 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -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
diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
new file mode 100644
index 0000000..2c6a043
--- /dev/null
+++ b/drivers/irqchip/irq-vf610-gpc.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2016 Toradex AG
+ * Author: Stefan Agner <stefan@agner.ch>
+ *
+ * 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",
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_enable		= irq_chip_enable_parent,
+	.irq_disable		= irq_chip_disable_parent,
+	.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,
+					      &vf610_gpc_chip, NULL);
+
+	parent_fwspec = *fwspec;
+	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;
+	}
+
+	gpc_base = of_io_request_and_map(node, 0, "gpc");
+	if (WARN_ON(!gpc_base))
+		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);
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo-DgEjT+Ai2ygdnm+yROfE0A,
	mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, sergeimir-qv+LCo8X3VpBDgjK7y7TUQ,
	tglx-hfZtesqFncYOwBW4kG4KsQ, jason-NLaQJdtUoK4Be96aLqz0jA,
	marc.zyngier-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, mark.rutland-5wv7dgnIgG8,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA, 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).

Signed-off-by: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
---
 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

diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 18caacb..0a77ac6 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -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
diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
new file mode 100644
index 0000000..2c6a043
--- /dev/null
+++ b/drivers/irqchip/irq-vf610-gpc.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2016 Toradex AG
+ * Author: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
+ *
+ * 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",
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_enable		= irq_chip_enable_parent,
+	.irq_disable		= irq_chip_disable_parent,
+	.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,
+					      &vf610_gpc_chip, NULL);
+
+	parent_fwspec = *fwspec;
+	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;
+	}
+
+	gpc_base = of_io_request_and_map(node, 0, "gpc");
+	if (WARN_ON(!gpc_base))
+		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);
-- 
2.7.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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).

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 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

diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 18caacb..0a77ac6 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -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
diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
new file mode 100644
index 0000000..2c6a043
--- /dev/null
+++ b/drivers/irqchip/irq-vf610-gpc.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2016 Toradex AG
+ * Author: Stefan Agner <stefan@agner.ch>
+ *
+ * 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",
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_enable		= irq_chip_enable_parent,
+	.irq_disable		= irq_chip_disable_parent,
+	.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,
+					      &vf610_gpc_chip, NULL);
+
+	parent_fwspec = *fwspec;
+	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;
+	}
+
+	gpc_base = of_io_request_and_map(node, 0, "gpc");
+	if (WARN_ON(!gpc_base))
+		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);
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Stefan Agner

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 5e49fbd..909988d 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -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 {
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 5e49fbd..909988d 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -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

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
  2016-03-10  2:16 ` Stefan Agner
  (?)
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Stefan Agner

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

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
index 4d8b7f6..936ece6 100644
--- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
+++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
@@ -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
+			>;
+		};
 	};
 };
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: mark.rutland, devicetree, jason, pawel.moll, ijc+devicetree,
	marc.zyngier, linux-kernel, Stefan Agner, robh+dt, sergeimir,
	kernel, galak, tglx, linux-clk, linux-arm-kernel

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

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
index 4d8b7f6..936ece6 100644
--- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
+++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
@@ -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
+			>;
+		};
 	};
 };
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
index 4d8b7f6..936ece6 100644
--- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
+++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
@@ -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
+			>;
+		};
 	};
 };
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM
  2016-03-10  2:16 ` Stefan Agner
  (?)
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 909988d..b038ea4 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -91,6 +91,43 @@
 		interrupt-parent = <&gpc>;
 		ranges;
 
+		ocram0: sram@3f000000 {
+			compatible = "mmio-sram";
+			reg = <0x3f000000 0x40000>;
+
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x3f000000 0x40000>;
+
+			stbyram1@0 {
+				reg = <0x0 0x4000>;
+				label = "stbyram1";
+				pool;
+			};
+
+			stbyram2@4000 {
+				reg = <0x4000 0xc000>;
+				label = "stbyram2";
+				pool;
+			};
+		};
+
+		ocram1: sram@3f040000 {
+			compatible = "mmio-sram";
+			reg = <0x3f040000 0x40000>;
+		};
+
+		gfxram0: sram@3f400000 {
+			compatible = "mmio-sram";
+			reg = <0x3f400000 0x80000>;
+		};
+
+		/* used by L2 cache */
+		gfxram1: sram@3f480000 {
+			compatible = "mmio-sram";
+			reg = <0x3f480000 0x80000>;
+		};
+
 		aips0: aips-bus@40000000 {
 			compatible = "fsl,aips-bus", "simple-bus";
 			#address-cells = <1>;
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: mark.rutland, devicetree, jason, pawel.moll, ijc+devicetree,
	marc.zyngier, linux-kernel, Stefan Agner, robh+dt, sergeimir,
	kernel, galak, tglx, linux-clk, linux-arm-kernel

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

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 909988d..b038ea4 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -91,6 +91,43 @@
 		interrupt-parent = <&gpc>;
 		ranges;
 
+		ocram0: sram@3f000000 {
+			compatible = "mmio-sram";
+			reg = <0x3f000000 0x40000>;
+
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x3f000000 0x40000>;
+
+			stbyram1@0 {
+				reg = <0x0 0x4000>;
+				label = "stbyram1";
+				pool;
+			};
+
+			stbyram2@4000 {
+				reg = <0x4000 0xc000>;
+				label = "stbyram2";
+				pool;
+			};
+		};
+
+		ocram1: sram@3f040000 {
+			compatible = "mmio-sram";
+			reg = <0x3f040000 0x40000>;
+		};
+
+		gfxram0: sram@3f400000 {
+			compatible = "mmio-sram";
+			reg = <0x3f400000 0x80000>;
+		};
+
+		/* used by L2 cache */
+		gfxram1: sram@3f480000 {
+			compatible = "mmio-sram";
+			reg = <0x3f480000 0x80000>;
+		};
+
 		aips0: aips-bus@40000000 {
 			compatible = "fsl,aips-bus", "simple-bus";
 			#address-cells = <1>;
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 909988d..b038ea4 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -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>;
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 05/18] ARM: dts: vf610: add modules required for PM
  2016-03-10  2:16 ` Stefan Agner
  (?)
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Stefan Agner

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index b038ea4..335f4e5 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -434,6 +434,11 @@
 				reg = <0x40050000 0x400>;
 			};
 
+			scsc: scsc@40052000 {
+				compatible = "fsl,vf610-scsc";
+				reg = <0x40052000 0x1000>;
+			};
+
 			usbphy0: usbphy@40050800 {
 				compatible = "fsl,vf610-usbphy";
 				reg = <0x40050800 0x400>;
@@ -480,6 +485,13 @@
 				status = "disabled";
 			};
 
+			wakeup: wkpu@4006a000 {
+				compatible = "fsl,vf610-wkpu";
+				reg = <0x4006a000 0x1000>;
+				interrupts = <92 IRQ_TYPE_LEVEL_HIGH>;
+				clocks = <&clks VF610_CLK_WKPU>;
+			};
+
 			clks: ccm@4006b000 {
 				compatible = "fsl,vf610-ccm";
 				reg = <0x4006b000 0x1000>;
@@ -600,6 +612,13 @@
 				status = "disabled";
 			};
 
+			ddrmc: ddrmc@400ae000 {
+				compatible = "fsl,vf610-ddrmc";
+				reg = <0x400ae000 0x400>;
+				clocks = <&clks VF610_CLK_DDRMC>;
+				clock-names = "ddrc";
+			};
+
 			adc1: adc@400bb000 {
 				compatible = "fsl,vf610-adc";
 				reg = <0x400bb000 0x1000>;
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 05/18] ARM: dts: vf610: add modules required for PM
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: mark.rutland, devicetree, jason, pawel.moll, ijc+devicetree,
	marc.zyngier, linux-kernel, Stefan Agner, robh+dt, sergeimir,
	kernel, galak, tglx, linux-clk, linux-arm-kernel

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index b038ea4..335f4e5 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -434,6 +434,11 @@
 				reg = <0x40050000 0x400>;
 			};
 
+			scsc: scsc@40052000 {
+				compatible = "fsl,vf610-scsc";
+				reg = <0x40052000 0x1000>;
+			};
+
 			usbphy0: usbphy@40050800 {
 				compatible = "fsl,vf610-usbphy";
 				reg = <0x40050800 0x400>;
@@ -480,6 +485,13 @@
 				status = "disabled";
 			};
 
+			wakeup: wkpu@4006a000 {
+				compatible = "fsl,vf610-wkpu";
+				reg = <0x4006a000 0x1000>;
+				interrupts = <92 IRQ_TYPE_LEVEL_HIGH>;
+				clocks = <&clks VF610_CLK_WKPU>;
+			};
+
 			clks: ccm@4006b000 {
 				compatible = "fsl,vf610-ccm";
 				reg = <0x4006b000 0x1000>;
@@ -600,6 +612,13 @@
 				status = "disabled";
 			};
 
+			ddrmc: ddrmc@400ae000 {
+				compatible = "fsl,vf610-ddrmc";
+				reg = <0x400ae000 0x400>;
+				clocks = <&clks VF610_CLK_DDRMC>;
+				clock-names = "ddrc";
+			};
+
 			adc1: adc@400bb000 {
 				compatible = "fsl,vf610-adc";
 				reg = <0x400bb000 0x1000>;
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 05/18] ARM: dts: vf610: add modules required for PM
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index b038ea4..335f4e5 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -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>;
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration
  2016-03-10  2:16 ` Stefan Agner
  (?)
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-gate2.c |  7 +++++--
 drivers/clk/imx/clk.h       | 13 ++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/imx/clk-gate2.c b/drivers/clk/imx/clk-gate2.c
index 8935bff..db44a19 100644
--- a/drivers/clk/imx/clk-gate2.c
+++ b/drivers/clk/imx/clk-gate2.c
@@ -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;
diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h
index c94ac5c..9311755 100644
--- a/drivers/clk/imx/clk.h
+++ b/drivers/clk/imx/clk.h
@@ -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,
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: mark.rutland, devicetree, jason, pawel.moll, ijc+devicetree,
	marc.zyngier, linux-kernel, Stefan Agner, robh+dt, sergeimir,
	kernel, galak, tglx, linux-clk, linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-gate2.c |  7 +++++--
 drivers/clk/imx/clk.h       | 13 ++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/imx/clk-gate2.c b/drivers/clk/imx/clk-gate2.c
index 8935bff..db44a19 100644
--- a/drivers/clk/imx/clk-gate2.c
+++ b/drivers/clk/imx/clk-gate2.c
@@ -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;
diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h
index c94ac5c..9311755 100644
--- a/drivers/clk/imx/clk.h
+++ b/drivers/clk/imx/clk.h
@@ -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,
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-gate2.c |  7 +++++--
 drivers/clk/imx/clk.h       | 13 ++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/imx/clk-gate2.c b/drivers/clk/imx/clk-gate2.c
index 8935bff..db44a19 100644
--- a/drivers/clk/imx/clk-gate2.c
+++ b/drivers/clk/imx/clk-gate2.c
@@ -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;
diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h
index c94ac5c..9311755 100644
--- a/drivers/clk/imx/clk.h
+++ b/drivers/clk/imx/clk.h
@@ -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,
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 07/18] ARM: imx: clk-vf610: leave DDR clock on
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c             | 3 +++
 include/dt-bindings/clock/vf610-clock.h | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index 0a94d96..f0ff458 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
 
diff --git a/include/dt-bindings/clock/vf610-clock.h b/include/dt-bindings/clock/vf610-clock.h
index 56c16aa..cf2c00a 100644
--- a/include/dt-bindings/clock/vf610-clock.h
+++ b/include/dt-bindings/clock/vf610-clock.h
@@ -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 */
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 07/18] ARM: imx: clk-vf610: leave DDR clock on
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c             | 3 +++
 include/dt-bindings/clock/vf610-clock.h | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index 0a94d96..f0ff458 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
 
diff --git a/include/dt-bindings/clock/vf610-clock.h b/include/dt-bindings/clock/vf610-clock.h
index 56c16aa..cf2c00a 100644
--- a/include/dt-bindings/clock/vf610-clock.h
+++ b/include/dt-bindings/clock/vf610-clock.h
@@ -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 */
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 08/18] ARM: clk: add WKPU unit
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Stefan Agner

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c             | 2 ++
 include/dt-bindings/clock/vf610-clock.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index f0ff458..610a724 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
diff --git a/include/dt-bindings/clock/vf610-clock.h b/include/dt-bindings/clock/vf610-clock.h
index cf2c00a..7dc1b84 100644
--- a/include/dt-bindings/clock/vf610-clock.h
+++ b/include/dt-bindings/clock/vf610-clock.h
@@ -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 */
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 08/18] ARM: clk: add WKPU unit
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo-DgEjT+Ai2ygdnm+yROfE0A,
	mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, sergeimir-qv+LCo8X3VpBDgjK7y7TUQ,
	tglx-hfZtesqFncYOwBW4kG4KsQ, jason-NLaQJdtUoK4Be96aLqz0jA,
	marc.zyngier-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, mark.rutland-5wv7dgnIgG8,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA, Stefan Agner

Signed-off-by: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
---
 drivers/clk/imx/clk-vf610.c             | 2 ++
 include/dt-bindings/clock/vf610-clock.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index f0ff458..610a724 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
diff --git a/include/dt-bindings/clock/vf610-clock.h b/include/dt-bindings/clock/vf610-clock.h
index cf2c00a..7dc1b84 100644
--- a/include/dt-bindings/clock/vf610-clock.h
+++ b/include/dt-bindings/clock/vf610-clock.h
@@ -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 */
-- 
2.7.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 08/18] ARM: clk: add WKPU unit
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c             | 2 ++
 include/dt-bindings/clock/vf610-clock.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index f0ff458..610a724 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
diff --git a/include/dt-bindings/clock/vf610-clock.h b/include/dt-bindings/clock/vf610-clock.h
index cf2c00a..7dc1b84 100644
--- a/include/dt-bindings/clock/vf610-clock.h
+++ b/include/dt-bindings/clock/vf610-clock.h
@@ -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 */
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 09/18] ARM: vf610: clk: add suspend/resume support
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index 610a724..e2e2c43 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
+
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 09/18] ARM: vf610: clk: add suspend/resume support
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index 610a724..e2e2c43 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
+
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 10/18] tty: serial: fsl_lpuart: support suspend/resume
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c     | 12 ++++++------
 drivers/tty/serial/fsl_lpuart.c | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index e2e2c43..170a96c 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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));
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 3d79003..94e29ba 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -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);
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 10/18] tty: serial: fsl_lpuart: support suspend/resume
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo-DgEjT+Ai2ygdnm+yROfE0A,
	mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, sergeimir-qv+LCo8X3VpBDgjK7y7TUQ,
	tglx-hfZtesqFncYOwBW4kG4KsQ, jason-NLaQJdtUoK4Be96aLqz0jA,
	marc.zyngier-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, mark.rutland-5wv7dgnIgG8,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA, 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.

Signed-off-by: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
---
 drivers/clk/imx/clk-vf610.c     | 12 ++++++------
 drivers/tty/serial/fsl_lpuart.c | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index e2e2c43..170a96c 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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));
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 3d79003..94e29ba 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -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);
-- 
2.7.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 10/18] tty: serial: fsl_lpuart: support suspend/resume
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/clk/imx/clk-vf610.c     | 12 ++++++------
 drivers/tty/serial/fsl_lpuart.c | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index e2e2c43..170a96c 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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));
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 3d79003..94e29ba 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -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);
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 11/18] pinctrl: pinctrl-imx: implement suspend/resume
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 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(+)

diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index a5bb939..42fc9a9 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -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))
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.h b/drivers/pinctrl/freescale/pinctrl-imx.h
index 2a592f6..56851a6 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.h
+++ b/drivers/pinctrl/freescale/pinctrl-imx.h
@@ -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 */
diff --git a/drivers/pinctrl/freescale/pinctrl-vf610.c b/drivers/pinctrl/freescale/pinctrl-vf610.c
index 587d1ff..b6280a8 100644
--- a/drivers/pinctrl/freescale/pinctrl-vf610.c
+++ b/drivers/pinctrl/freescale/pinctrl-vf610.c
@@ -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,
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 11/18] pinctrl: pinctrl-imx: implement suspend/resume
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 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(+)

diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index a5bb939..42fc9a9 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -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))
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.h b/drivers/pinctrl/freescale/pinctrl-imx.h
index 2a592f6..56851a6 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.h
+++ b/drivers/pinctrl/freescale/pinctrl-imx.h
@@ -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 */
diff --git a/drivers/pinctrl/freescale/pinctrl-vf610.c b/drivers/pinctrl/freescale/pinctrl-vf610.c
index 587d1ff..b6280a8 100644
--- a/drivers/pinctrl/freescale/pinctrl-vf610.c
+++ b/drivers/pinctrl/freescale/pinctrl-vf610.c
@@ -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,
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 12/18] gpio: vf610: add system PM suspend/resume
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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).

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/gpio/gpio-vf610.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 6284bdb..1a022be 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -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,
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 12/18] gpio: vf610: add system PM suspend/resume
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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).

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/gpio/gpio-vf610.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 6284bdb..1a022be 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -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,
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 13/18] ARM: dts: vf610: add WKPU connection to GPIO
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 335f4e5..869b230 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -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@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@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@4004d000 {
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 13/18] ARM: dts: vf610: add WKPU connection to GPIO
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo-DgEjT+Ai2ygdnm+yROfE0A,
	mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, sergeimir-qv+LCo8X3VpBDgjK7y7TUQ,
	tglx-hfZtesqFncYOwBW4kG4KsQ, jason-NLaQJdtUoK4Be96aLqz0jA,
	marc.zyngier-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, mark.rutland-5wv7dgnIgG8,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA, 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.

Signed-off-by: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
---
 arch/arm/boot/dts/vfxxx.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 335f4e5..869b230 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -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@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@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@4004d000 {
-- 
2.7.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 13/18] ARM: dts: vf610: add WKPU connection to GPIO
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/boot/dts/vfxxx.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 335f4e5..869b230 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -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 {
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 14/18] gpio: vf610: add support for WKPU unit
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
 drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
 2 files changed, 157 insertions(+)

diff --git a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
index 436cc99..985ddfd 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
@@ -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.
 
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 1a022be..650a41a 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -36,6 +36,8 @@ struct vf610_gpio_port {
 	void __iomem *base;
 	void __iomem *gpio_base;
 	u8 irqc[VF610_GPIO_PER_PORT];
+	struct platform_device *pdev_wkpu;
+	s8 fsl_wakeup[VF610_GPIO_PER_PORT];
 	int irq;
 	u32 state;
 };
@@ -61,6 +63,14 @@ struct vf610_gpio_port {
 #define PORT_INT_EITHER_EDGE	0xb
 #define PORT_INT_LOGIC_ONE	0xc
 
+#define WKPU_WISR		0x14
+#define WKPU_IRER		0x18
+#define WKPU_WRER		0x1c
+#define WKPU_WIREER		0x28
+#define WKPU_WIFEER		0x2c
+#define WKPU_WIFER		0x30
+#define WKPU_WIPUER		0x34
+
 static struct irq_chip vf610_gpio_irq_chip;
 
 static const struct of_device_id vf610_gpio_dt_ids[] = {
@@ -68,6 +78,11 @@ static const struct of_device_id vf610_gpio_dt_ids[] = {
 	{ /* sentinel */ }
 };
 
+static const struct of_device_id vf610_wkpu_dt_ids[] = {
+	{ .compatible = "fsl,vf610-wkpu" },
+	{ /* sentinel */ }
+};
+
 static inline void vf610_gpio_writel(u32 val, void __iomem *reg)
 {
 	writel_relaxed(val, reg);
@@ -143,8 +158,26 @@ static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
 {
 	struct vf610_gpio_port *port =
 		gpiochip_get_data(irq_data_get_irq_chip_data(d));
+	s8 wkpu_gpio = port->fsl_wakeup[d->hwirq];
 	u8 irqc;
 
+	if (wkpu_gpio >= 0) {
+		void __iomem *base = platform_get_drvdata(port->pdev_wkpu);
+		u32 wireer, wifeer;
+		u32 mask = 1 << wkpu_gpio;
+
+		wireer = vf610_gpio_readl(base + WKPU_WIREER) & ~mask;
+		wifeer = vf610_gpio_readl(base + WKPU_WIFEER) & ~mask;
+
+		if (type & IRQ_TYPE_EDGE_RISING)
+			wireer |= mask;
+		if (type & IRQ_TYPE_EDGE_FALLING)
+			wifeer |= mask;
+
+		vf610_gpio_writel(wireer, base + WKPU_WIREER);
+		vf610_gpio_writel(wifeer, base + WKPU_WIFEER);
+	}
+
 	switch (type) {
 	case IRQ_TYPE_EDGE_RISING:
 		irqc = PORT_INT_RISING_EDGE;
@@ -198,6 +231,29 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
 {
 	struct vf610_gpio_port *port =
 		gpiochip_get_data(irq_data_get_irq_chip_data(d));
+	s8 wkpu_gpio = port->fsl_wakeup[d->hwirq];
+
+	if (wkpu_gpio >= 0) {
+		void __iomem *base = NULL;
+		u32 wrer, irer;
+
+		base = platform_get_drvdata(port->pdev_wkpu);
+
+		/* WKPU wakeup flag for LPSTOPx modes...  */
+		wrer = vf610_gpio_readl(base + WKPU_WRER);
+		irer = vf610_gpio_readl(base + WKPU_IRER);
+
+		if (enable) {
+			wrer |= 1 << wkpu_gpio;
+			irer |= 1 << wkpu_gpio;
+		} else {
+			wrer &= ~(1 << wkpu_gpio);
+			irer &= ~(1 << wkpu_gpio);
+		}
+
+		vf610_gpio_writel(wrer, base + WKPU_WRER);
+		vf610_gpio_writel(irer, base + WKPU_IRER);
+	}
 
 	if (enable)
 		enable_irq_wake(port->irq);
@@ -250,6 +306,43 @@ 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_wkpu(struct device_node *np, struct vf610_gpio_port *port)
+{
+	struct platform_device *pdev = NULL;
+	struct of_phandle_args arg;
+	int i, ret;
+
+	for (i = 0; i < VF610_GPIO_PER_PORT; i++)
+		port->fsl_wakeup[i] = -1;
+
+	for (i = 0;; i++) {
+		int gpioid, wakeupid, cnt;
+
+		ret = of_parse_phandle_with_fixed_args(np, "fsl,gpio-wakeup",
+							3, i, &arg);
+
+		if (ret == -ENOENT)
+			break;
+
+		if (!pdev)
+			pdev = of_find_device_by_node(arg.np);
+		of_node_put(arg.np);
+		if (!pdev)
+			return -EPROBE_DEFER;
+
+		gpioid = arg.args[0];
+		wakeupid = arg.args[1];
+		cnt = arg.args[2];
+
+		while (cnt-- && gpioid < VF610_GPIO_PER_PORT)
+			port->fsl_wakeup[gpioid++] = wakeupid++;
+	}
+
+	port->pdev_wkpu = pdev;
+
+	return 0;
+}
+
 static int vf610_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -277,6 +370,10 @@ static int vf610_gpio_probe(struct platform_device *pdev)
 	if (port->irq < 0)
 		return port->irq;
 
+	ret = vf610_gpio_wkpu(np, port);
+	if (ret < 0)
+		return ret;
+
 	gc = &port->gc;
 	gc->of_node = np;
 	gc->parent = dev;
@@ -327,6 +424,60 @@ static int __init gpio_vf610_init(void)
 }
 device_initcall(gpio_vf610_init);
 
+static irqreturn_t vf610_wkpu_irq(int irq, void *data)
+{
+	void __iomem *base = data;
+	u32 wisr;
+
+	wisr = vf610_gpio_readl(base + WKPU_WISR);
+	vf610_gpio_writel(wisr, base + WKPU_WISR);
+	pr_debug("%s, WKPU interrupt received, flags %08x\n", __func__, wisr);
+
+	return 0;
+}
+
+static int vf610_wkpu_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct resource *iores;
+	void __iomem *base;
+	int irq, err;
+
+	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(dev, iores);
+
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	err = devm_request_irq(dev, irq, vf610_wkpu_irq, 0, "wkpu-vf610", base);
+	if (err) {
+		dev_err(dev, "Error requesting IRQ!\n");
+		return err;
+	}
+
+	platform_set_drvdata(pdev, base);
+
+	return 0;
+}
+
+static struct platform_driver vf610_wkpu_driver = {
+	.driver		= {
+		.name	= "wkpu-vf610",
+		.of_match_table = vf610_wkpu_dt_ids,
+	},
+	.probe		= vf610_wkpu_probe,
+};
+
+static int __init vf610_wkpu_init(void)
+{
+	return platform_driver_register(&vf610_wkpu_driver);
+}
+device_initcall(vf610_wkpu_init);
+
 MODULE_AUTHOR("Stefan Agner <stefan@agner.ch>");
 MODULE_DESCRIPTION("Freescale VF610 GPIO");
 MODULE_LICENSE("GPL v2");
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 14/18] gpio: vf610: add support for WKPU unit
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
 drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
 2 files changed, 157 insertions(+)

diff --git a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
index 436cc99..985ddfd 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
@@ -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.
 
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 1a022be..650a41a 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -36,6 +36,8 @@ struct vf610_gpio_port {
 	void __iomem *base;
 	void __iomem *gpio_base;
 	u8 irqc[VF610_GPIO_PER_PORT];
+	struct platform_device *pdev_wkpu;
+	s8 fsl_wakeup[VF610_GPIO_PER_PORT];
 	int irq;
 	u32 state;
 };
@@ -61,6 +63,14 @@ struct vf610_gpio_port {
 #define PORT_INT_EITHER_EDGE	0xb
 #define PORT_INT_LOGIC_ONE	0xc
 
+#define WKPU_WISR		0x14
+#define WKPU_IRER		0x18
+#define WKPU_WRER		0x1c
+#define WKPU_WIREER		0x28
+#define WKPU_WIFEER		0x2c
+#define WKPU_WIFER		0x30
+#define WKPU_WIPUER		0x34
+
 static struct irq_chip vf610_gpio_irq_chip;
 
 static const struct of_device_id vf610_gpio_dt_ids[] = {
@@ -68,6 +78,11 @@ static const struct of_device_id vf610_gpio_dt_ids[] = {
 	{ /* sentinel */ }
 };
 
+static const struct of_device_id vf610_wkpu_dt_ids[] = {
+	{ .compatible = "fsl,vf610-wkpu" },
+	{ /* sentinel */ }
+};
+
 static inline void vf610_gpio_writel(u32 val, void __iomem *reg)
 {
 	writel_relaxed(val, reg);
@@ -143,8 +158,26 @@ static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
 {
 	struct vf610_gpio_port *port =
 		gpiochip_get_data(irq_data_get_irq_chip_data(d));
+	s8 wkpu_gpio = port->fsl_wakeup[d->hwirq];
 	u8 irqc;
 
+	if (wkpu_gpio >= 0) {
+		void __iomem *base = platform_get_drvdata(port->pdev_wkpu);
+		u32 wireer, wifeer;
+		u32 mask = 1 << wkpu_gpio;
+
+		wireer = vf610_gpio_readl(base + WKPU_WIREER) & ~mask;
+		wifeer = vf610_gpio_readl(base + WKPU_WIFEER) & ~mask;
+
+		if (type & IRQ_TYPE_EDGE_RISING)
+			wireer |= mask;
+		if (type & IRQ_TYPE_EDGE_FALLING)
+			wifeer |= mask;
+
+		vf610_gpio_writel(wireer, base + WKPU_WIREER);
+		vf610_gpio_writel(wifeer, base + WKPU_WIFEER);
+	}
+
 	switch (type) {
 	case IRQ_TYPE_EDGE_RISING:
 		irqc = PORT_INT_RISING_EDGE;
@@ -198,6 +231,29 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
 {
 	struct vf610_gpio_port *port =
 		gpiochip_get_data(irq_data_get_irq_chip_data(d));
+	s8 wkpu_gpio = port->fsl_wakeup[d->hwirq];
+
+	if (wkpu_gpio >= 0) {
+		void __iomem *base = NULL;
+		u32 wrer, irer;
+
+		base = platform_get_drvdata(port->pdev_wkpu);
+
+		/* WKPU wakeup flag for LPSTOPx modes...  */
+		wrer = vf610_gpio_readl(base + WKPU_WRER);
+		irer = vf610_gpio_readl(base + WKPU_IRER);
+
+		if (enable) {
+			wrer |= 1 << wkpu_gpio;
+			irer |= 1 << wkpu_gpio;
+		} else {
+			wrer &= ~(1 << wkpu_gpio);
+			irer &= ~(1 << wkpu_gpio);
+		}
+
+		vf610_gpio_writel(wrer, base + WKPU_WRER);
+		vf610_gpio_writel(irer, base + WKPU_IRER);
+	}
 
 	if (enable)
 		enable_irq_wake(port->irq);
@@ -250,6 +306,43 @@ 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_wkpu(struct device_node *np, struct vf610_gpio_port *port)
+{
+	struct platform_device *pdev = NULL;
+	struct of_phandle_args arg;
+	int i, ret;
+
+	for (i = 0; i < VF610_GPIO_PER_PORT; i++)
+		port->fsl_wakeup[i] = -1;
+
+	for (i = 0;; i++) {
+		int gpioid, wakeupid, cnt;
+
+		ret = of_parse_phandle_with_fixed_args(np, "fsl,gpio-wakeup",
+							3, i, &arg);
+
+		if (ret == -ENOENT)
+			break;
+
+		if (!pdev)
+			pdev = of_find_device_by_node(arg.np);
+		of_node_put(arg.np);
+		if (!pdev)
+			return -EPROBE_DEFER;
+
+		gpioid = arg.args[0];
+		wakeupid = arg.args[1];
+		cnt = arg.args[2];
+
+		while (cnt-- && gpioid < VF610_GPIO_PER_PORT)
+			port->fsl_wakeup[gpioid++] = wakeupid++;
+	}
+
+	port->pdev_wkpu = pdev;
+
+	return 0;
+}
+
 static int vf610_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -277,6 +370,10 @@ static int vf610_gpio_probe(struct platform_device *pdev)
 	if (port->irq < 0)
 		return port->irq;
 
+	ret = vf610_gpio_wkpu(np, port);
+	if (ret < 0)
+		return ret;
+
 	gc = &port->gc;
 	gc->of_node = np;
 	gc->parent = dev;
@@ -327,6 +424,60 @@ static int __init gpio_vf610_init(void)
 }
 device_initcall(gpio_vf610_init);
 
+static irqreturn_t vf610_wkpu_irq(int irq, void *data)
+{
+	void __iomem *base = data;
+	u32 wisr;
+
+	wisr = vf610_gpio_readl(base + WKPU_WISR);
+	vf610_gpio_writel(wisr, base + WKPU_WISR);
+	pr_debug("%s, WKPU interrupt received, flags %08x\n", __func__, wisr);
+
+	return 0;
+}
+
+static int vf610_wkpu_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct resource *iores;
+	void __iomem *base;
+	int irq, err;
+
+	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(dev, iores);
+
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	err = devm_request_irq(dev, irq, vf610_wkpu_irq, 0, "wkpu-vf610", base);
+	if (err) {
+		dev_err(dev, "Error requesting IRQ!\n");
+		return err;
+	}
+
+	platform_set_drvdata(pdev, base);
+
+	return 0;
+}
+
+static struct platform_driver vf610_wkpu_driver = {
+	.driver		= {
+		.name	= "wkpu-vf610",
+		.of_match_table = vf610_wkpu_dt_ids,
+	},
+	.probe		= vf610_wkpu_probe,
+};
+
+static int __init vf610_wkpu_init(void)
+{
+	return platform_driver_register(&vf610_wkpu_driver);
+}
+device_initcall(vf610_wkpu_init);
+
 MODULE_AUTHOR("Stefan Agner <stefan@agner.ch>");
 MODULE_DESCRIPTION("Freescale VF610 GPIO");
 MODULE_LICENSE("GPL v2");
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 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

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 9fbe624..ea2e8bd 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -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
diff --git a/arch/arm/mach-imx/common.h b/arch/arm/mach-imx/common.h
index 58a3846..737b1e4 100644
--- a/arch/arm/mach-imx/common.h
+++ b/arch/arm/mach-imx/common.h
@@ -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);
diff --git a/arch/arm/mach-imx/mach-vf610.c b/arch/arm/mach-imx/mach-vf610.c
index b20f6c1..5ba668f 100644
--- a/arch/arm/mach-imx/mach-vf610.c
+++ b/arch/arm/mach-imx/mach-vf610.c
@@ -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
diff --git a/arch/arm/mach-imx/pm-vf610.c b/arch/arm/mach-imx/pm-vf610.c
new file mode 100644
index 0000000..ecc7c9c
--- /dev/null
+++ b/arch/arm/mach-imx/pm-vf610.c
@@ -0,0 +1,634 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * Copyright 2016 Toradex AG
+ *
+ * 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
+ */
+
+#ifdef DEBUG
+#define pr_pmdebug(fmt, ...) pr_info("PM: VF610: " fmt "\n", ##__VA_ARGS__)
+#else
+#define pr_pmdebug(fmt, ...)
+#endif
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/genalloc.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+#include <linux/suspend.h>
+#include <linux/clk.h>
+#include <asm/cacheflush.h>
+#include <asm/fncpy.h>
+#include <asm/proc-fns.h>
+#include <asm/suspend.h>
+#include <asm/tlb.h>
+
+#include "common.h"
+
+#define DDRMC_PHY_OFFSET		0x400
+
+#define CCR				0x0
+#define BM_CCR_FIRC_EN			(0x1 << 16)
+#define BM_CCR_FXOSC_EN			(0x1 << 12)
+
+#define CCSR				0x8
+#define BM_CCSR_DDRC_CLK_SEL		(0x1 << 6)
+#define BM_CCSR_FAST_CLK_SEL		(0x1 << 5)
+#define BM_CCSR_SLOW_CLK_SEL		(0x1 << 4)
+#define BM_CCSR_SYS_CLK_SEL_MASK	(0x7 << 0)
+
+#define CACRR				0xc
+
+#define CLPCR				0x2c
+#define BM_CLPCR_ARM_CLK_DIS_ON_LPM	(0x1 << 5)
+#define BM_CLPCR_SBYOS			(0x1 << 6)
+#define BM_CLPCR_DIS_REF_OSC		(0x1 << 7)
+#define BM_CLPCR_ANADIG_STOP_MODE	(0x1 << 8)
+#define BM_CLPCR_FXOSC_BYPSEN		(0x1 << 10)
+#define BM_CLPCR_FXOSC_PWRDWN		(0x1 << 11)
+#define BM_CLPCR_MASK_CORE0_WFI		(0x1 << 22)
+#define BM_CLPCR_MASK_CORE1_WFI		(0x1 << 23)
+#define BM_CLPCR_MASK_SCU_IDLE		(0x1 << 24)
+#define BM_CLPCR_MASK_L2CC_IDLE		(0x1 << 25)
+
+#define CGPR				0x64
+#define BM_CGPR_INT_MEM_CLK_LPM		(0x1 << 17)
+
+#define GPC_PGCR			0x0
+#define BM_PGCR_DS_STOP			(0x1 << 7)
+#define BM_PGCR_DS_LPSTOP		(0x1 << 6)
+#define BM_PGCR_WB_STOP			(0x1 << 4)
+#define BM_PGCR_HP_OFF			(0x1 << 3)
+#define BM_PGCR_PG_PD1			(0x1 << 0)
+
+#define GPC_LPMR			0x40
+#define BM_LPMR_RUN			0x0
+#define BM_LPMR_STOP			0x2
+
+#define ANATOP_PLL1_CTRL		0x270
+#define ANATOP_PLL2_CTRL		0x30
+#define ANATOP_PLL2_PFD			0x100
+#define BM_PLL_POWERDOWN	(0x1 << 12)
+#define BM_PLL_ENABLE		(0x1 << 13)
+#define BM_PLL_BYPASS		(0x1 << 16)
+#define BM_PLL_LOCK		(0x1 << 31)
+#define BM_PLL_PFD2_CLKGATE	(0x1 << 15)
+#define BM_PLL_USB_POWER	(0x1 << 12)
+#define BM_PLL_EN_USB_CLKS	(0x1 << 6)
+
+#define VF610_DDRMC_IO_NUM		94
+#define VF610_IOMUX_DDR_IO_NUM		48
+#define VF610_ANATOP_IO_NUM		2
+
+static void __iomem *suspend_ocram_base;
+static void (*vf610_suspend_in_ocram_fn)(void __iomem *ocram_vbase);
+
+#ifdef DEBUG
+static void __iomem *uart_membase;
+static unsigned long uart_clk;
+#endif
+
+static const u32 vf610_iomuxc_ddr_io_offset[] __initconst = {
+	0x220, 0x224, 0x228, 0x22c, 0x230, 0x234, 0x238, 0x23c,
+	0x240, 0x244, 0x248, 0x24c, 0x250, 0x254, 0x258, 0x25c,
+	0x260, 0x264, 0x268, 0x26c, 0x270, 0x274, 0x278, 0x27c,
+	0x280, 0x284, 0x288, 0x28c, 0x290, 0x294, 0x298, 0x29c,
+	0x2a0, 0x2a4, 0x2a8, 0x2ac, 0x2b0, 0x2b4, 0x2b8, 0x2bc,
+	0x2c0, 0x2c4, 0x2c8, 0x2cc, 0x2d0, 0x2d4, 0x2d8, 0x21c,
+};
+
+
+static const u32 vf610_ddrmc_io_offset[] __initconst = {
+	0x00, 0x08, 0x28, 0x2c, 0x30, 0x34, 0x38,
+	0x40, 0x44, 0x48, 0x50, 0x54, 0x58, 0x5c,
+	0x60, 0x64, 0x68, 0x70, 0x74, 0x78, 0x7c,
+	0x84, 0x88, 0x98, 0x9c, 0xa4, 0xc0,
+	0x108, 0x10c, 0x114, 0x118, 0x120, 0x124,
+	0x128, 0x12c, 0x130, 0x134, 0x138, 0x13c,
+	0x148, 0x15c, 0x160, 0x164, 0x16c, 0x180,
+	0x184, 0x188, 0x18c, 0x198, 0x1a4, 0x1a8,
+	0x1b8, 0x1d4, 0x1d8, 0x1e0, 0x1e4, 0x1e8,
+	0x1ec, 0x1f0, 0x1f8, 0x210, 0x224, 0x228,
+	0x22c, 0x230, 0x23c, 0x240, 0x244, 0x248,
+	0x24c, 0x250, 0x25c, 0x268, 0x26c, 0x278,
+	0x268
+};
+
+static const u32 vf610_ddrmc_phy_io_offset[] __initconst = {
+	0x00, 0x04, 0x08, 0x0c, 0x10,
+	0x40, 0x44, 0x48, 0x4c, 0x50,
+	0x80, 0x84, 0x88, 0x8c, 0x90,
+	0xc4, 0xc8, 0xd0
+};
+
+/*
+ * suspend ocram space layout:
+ * ======================== high address ======================
+ *                              .
+ *                              .
+ *                              .
+ *                              ^
+ *                              ^
+ *                              ^
+ *                      vf610_suspend code
+ *              PM_INFO structure(vf610_cpu_pm_info)
+ * ======================== low address =======================
+ */
+
+struct vf610_pm_base {
+	phys_addr_t pbase;
+	void __iomem *vbase;
+};
+
+struct vf610_pm_socdata {
+	const char *anatop_compat;
+	const char *scsc_compat;
+	const char *wkpu_compat;
+	const char *ccm_compat;
+	const char *gpc_compat;
+	const char *src_compat;
+	const char *ddrmc_compat;
+	const char *iomuxc_compat;
+};
+
+static const struct vf610_pm_socdata vf610_pm_data __initconst = {
+	.anatop_compat = "fsl,vf610-anatop",
+	.scsc_compat = "fsl,vf610-scsc",
+	.wkpu_compat = "fsl,vf610-wkpu",
+	.ccm_compat = "fsl,vf610-ccm",
+	.gpc_compat = "fsl,vf610-gpc",
+	.src_compat = "fsl,vf610-src",
+	.ddrmc_compat = "fsl,vf610-ddrmc",
+	.iomuxc_compat = "fsl,vf610-iomuxc",
+};
+
+/*
+ * This structure is for passing necessary data for low level ocram
+ * suspend code(arch/arm/mach-imx/suspend-vf610.S), if this struct
+ * definition is changed, the offset definition in
+ * arch/arm/mach-imx/suspend-vf610.S must be also changed accordingly,
+ * otherwise, the suspend to ocram function will be broken!
+ */
+struct vf610_cpu_pm_info {
+	phys_addr_t pbase; /* The physical address of pm_info. */
+	phys_addr_t resume_addr; /* The physical resume address for asm code */
+	u32 cpu_type; /* Currently not used, leave it for alignment */
+	u32 pm_info_size; /* Size of pm_info. */
+	struct vf610_pm_base anatop_base;
+	struct vf610_pm_base scsc_base;
+	struct vf610_pm_base wkpu_base;
+	struct vf610_pm_base ccm_base;
+	struct vf610_pm_base gpc_base;
+	struct vf610_pm_base src_base;
+	struct vf610_pm_base ddrmc_base;
+	struct vf610_pm_base iomuxc_base;
+	struct vf610_pm_base l2_base;
+	u32 ccm_cacrr;
+	u32 ccm_ccsr;
+	u32 ddrmc_io_num; /* Number of MMDC IOs which need saved/restored. */
+	u32 ddrmc_io_val[VF610_DDRMC_IO_NUM][2]; /* To save offset and value */
+	u32 iomux_ddr_io_num;
+	u32 iomux_ddr_io_val[VF610_IOMUX_DDR_IO_NUM][2];
+} __aligned(8);
+
+#ifdef DEBUG
+static void vf610_uart_reinit(unsigned long int rate, unsigned long int baud)
+{
+	u8 tmp, c2;
+	u16 sbr, brfa;
+
+	/* UART_C2 */
+	c2 = __raw_readb(uart_membase + 0x3);
+	__raw_writeb(0, uart_membase + 0x3);
+
+	sbr = (u16) (rate / (baud * 16));
+	brfa = (rate / baud) - (sbr * 16);
+
+	tmp = ((sbr & 0x1f00) >> 8);
+	__raw_writeb(tmp, uart_membase + 0x0);
+	tmp = sbr & 0x00ff;
+	__raw_writeb(tmp, uart_membase + 0x1);
+
+	/* UART_C4 */
+	__raw_writeb(brfa & 0xf, uart_membase + 0xa);
+
+	__raw_writeb(c2, uart_membase + 0x3);
+}
+#else
+#define vf610_uart_reinit(rate, baud)
+#endif
+
+static void vf610_set(void __iomem *pll_base, u32 mask)
+{
+	writel(readl(pll_base) | mask, pll_base);
+}
+
+static void vf610_clr(void __iomem *pll_base, u32 mask)
+{
+	writel(readl(pll_base) & ~mask, pll_base);
+}
+
+int vf610_set_lpm(enum vf610_cpu_pwr_mode mode)
+{
+	struct vf610_cpu_pm_info *pm_info = suspend_ocram_base;
+	void __iomem *ccm_base = pm_info->ccm_base.vbase;
+	void __iomem *gpc_base = pm_info->gpc_base.vbase;
+	void __iomem *anatop = pm_info->anatop_base.vbase;
+	u32 ccr = readl_relaxed(ccm_base + CCR);
+	u32 ccsr = readl_relaxed(ccm_base + CCSR);
+	u32 cacrr = readl_relaxed(ccm_base + CACRR);
+	u32 cclpcr = 0;
+	u32 gpc_pgcr = 0;
+
+	switch (mode) {
+	case VF610_LP_STOP:
+		/* Store clock settings */
+		pm_info->ccm_ccsr = ccsr;
+		pm_info->ccm_cacrr = cacrr;
+
+		ccr |= BM_CCR_FIRC_EN;
+		writel_relaxed(ccr, ccm_base + CCR);
+
+		cclpcr |= BM_CLPCR_ANADIG_STOP_MODE;
+		cclpcr |= BM_CLPCR_SBYOS;
+
+		cclpcr |= BM_CLPCR_MASK_SCU_IDLE;
+		cclpcr |= BM_CLPCR_MASK_L2CC_IDLE;
+		cclpcr |= BM_CLPCR_MASK_CORE1_WFI;
+		writel_relaxed(cclpcr, ccm_base + CLPCR);
+
+		gpc_pgcr |= BM_PGCR_DS_STOP;
+		gpc_pgcr |= BM_PGCR_DS_LPSTOP;
+		gpc_pgcr |= BM_PGCR_WB_STOP;
+		gpc_pgcr |= BM_PGCR_HP_OFF;
+		gpc_pgcr |= BM_PGCR_PG_PD1;
+		writel_relaxed(gpc_pgcr, gpc_base + GPC_PGCR);
+		break;
+	case VF610_STOP:
+		cclpcr &= ~BM_CLPCR_ANADIG_STOP_MODE;
+		cclpcr |= BM_CLPCR_ARM_CLK_DIS_ON_LPM;
+		cclpcr |= BM_CLPCR_SBYOS;
+		writel_relaxed(cclpcr, ccm_base + CLPCR);
+
+		gpc_pgcr |= BM_PGCR_DS_STOP;
+		gpc_pgcr |= BM_PGCR_HP_OFF;
+		writel_relaxed(gpc_pgcr, gpc_base + GPC_PGCR);
+
+		/* fall-through */
+	case VF610_LP_RUN:
+		/* Store clock settings */
+		pm_info->ccm_ccsr = ccsr;
+		pm_info->ccm_cacrr = cacrr;
+
+		ccr |= BM_CCR_FIRC_EN;
+		writel_relaxed(ccr, ccm_base + CCR);
+
+		/* Enable PLL2 for DDR clock */
+		vf610_set(anatop + ANATOP_PLL2_CTRL, BM_PLL_ENABLE);
+		vf610_clr(anatop + ANATOP_PLL2_CTRL, BM_PLL_POWERDOWN);
+		vf610_clr(anatop + ANATOP_PLL2_CTRL, BM_PLL_BYPASS);
+		while (!(readl(anatop + ANATOP_PLL2_CTRL) & BM_PLL_LOCK));
+		vf610_clr(anatop + ANATOP_PLL2_PFD, BM_PLL_PFD2_CLKGATE);
+
+		/* Switch internal OSC's */
+		ccsr &= ~BM_CCSR_FAST_CLK_SEL;
+		ccsr &= ~BM_CCSR_SLOW_CLK_SEL;
+
+		/* Select PLL2 as DDR clock */
+		ccsr &= ~BM_CCSR_DDRC_CLK_SEL;
+		writel_relaxed(ccsr, ccm_base + CCSR);
+
+		ccsr &= ~BM_CCSR_SYS_CLK_SEL_MASK;
+		writel_relaxed(ccsr, ccm_base + CCSR);
+		vf610_uart_reinit(4000000UL, 115200);
+
+		vf610_set(anatop + ANATOP_PLL1_CTRL, BM_PLL_BYPASS);
+		writel_relaxed(BM_LPMR_STOP, gpc_base + GPC_LPMR);
+		break;
+	case VF610_RUN:
+		writel_relaxed(BM_LPMR_RUN, gpc_base + GPC_LPMR);
+
+		vf610_clr(anatop + ANATOP_PLL1_CTRL, BM_PLL_BYPASS);
+		while (!(readl(anatop + ANATOP_PLL1_CTRL) & BM_PLL_LOCK));
+
+		/* Restore clock settings */
+		writel(pm_info->ccm_ccsr, ccm_base + CCSR);
+
+		vf610_uart_reinit(uart_clk, 115200);
+		pr_pmdebug("resuming, uart_reinit done");
+
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int vf610_suspend_finish(unsigned long val)
+{
+	if (!vf610_suspend_in_ocram_fn) {
+		cpu_do_idle();
+	} else {
+		/*
+		 * call low level suspend function in ocram,
+		 * as we need to float DDR IO.
+		 */
+		local_flush_tlb_all();
+		flush_cache_all();
+		outer_flush_all();
+		vf610_suspend_in_ocram_fn(suspend_ocram_base);
+	}
+
+	return 0;
+}
+
+static int vf610_pm_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_STANDBY:
+		vf610_set_lpm(VF610_STOP);
+
+		/* zzZZZzzz */
+		cpu_do_idle();
+
+		vf610_set_lpm(VF610_RUN);
+		break;
+	case PM_SUSPEND_MEM:
+		vf610_set_lpm(VF610_LP_STOP);
+
+		cpu_suspend(0, vf610_suspend_finish);
+		outer_resume();
+
+		vf610_set_lpm(VF610_RUN);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int vf610_pm_valid(suspend_state_t state)
+{
+	return (state == PM_SUSPEND_STANDBY || state == PM_SUSPEND_MEM);
+}
+
+static const struct platform_suspend_ops vf610_pm_ops = {
+	.enter = vf610_pm_enter,
+	.valid = vf610_pm_valid,
+};
+
+static int __init imx_pm_get_base(struct vf610_pm_base *base,
+				const char *compat)
+{
+	struct device_node *node;
+	struct resource res;
+	int ret = 0;
+
+	node = of_find_compatible_node(NULL, NULL, compat);
+	if (!node) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	ret = of_address_to_resource(node, 0, &res);
+	if (ret)
+		goto put_node;
+
+	base->pbase = res.start;
+	base->vbase = ioremap(res.start, resource_size(&res));
+
+	if (!base->vbase)
+		ret = -ENOMEM;
+
+put_node:
+	of_node_put(node);
+out:
+	return ret;
+}
+
+#ifdef DEBUG
+static int __init vf610_uart_init(void)
+{
+	struct device_node *dn;
+	const char *name;
+	struct clk *clk;
+	int ret;
+
+	name = of_get_property(of_chosen, "stdout-path", NULL);
+	if (name == NULL)
+		return -ENODEV;
+
+	dn = of_find_node_by_path(name);
+	if (!dn)
+		return -ENODEV;
+
+	clk = of_clk_get(dn, 0);
+
+	if (!clk) {
+		ret = PTR_ERR(clk);
+		goto put_node;
+	}
+
+	uart_clk = clk_get_rate(clk);
+
+	uart_membase = of_iomap(dn, 0);
+	if (!clk) {
+		ret = -ENOMEM;
+		goto put_node;
+	}
+
+	ret = 0;
+
+put_node:
+	of_node_put(dn);
+	return ret;
+}
+#endif
+
+static int __init vf610_suspend_init(const struct vf610_pm_socdata *socdata)
+{
+	phys_addr_t ocram_pbase;
+	struct device_node *node;
+	struct platform_device *pdev;
+	struct vf610_cpu_pm_info *pm_info;
+	struct gen_pool *ocram_pool;
+	size_t ocram_size;
+	unsigned long ocram_base;
+	int ret = 0, reg = 0;
+	int i;
+
+#ifdef DEBUG
+	ret = vf610_uart_init();
+	if (ret < 0)
+		return ret;
+#endif
+
+	suspend_set_ops(&vf610_pm_ops);
+
+	node = of_find_compatible_node(NULL, NULL, "mmio-sram");
+	if (!node) {
+		pr_warn("%s: failed to find ocram node!\n", __func__);
+		return -ENODEV;
+	}
+
+	pdev = of_find_device_by_node(node);
+	if (!pdev) {
+		pr_warn("%s: failed to find ocram device!\n", __func__);
+		ret = -ENODEV;
+		goto put_node;
+	}
+
+	ocram_pool = gen_pool_get(&pdev->dev, "stbyram1");
+	if (!ocram_pool) {
+		pr_warn("%s: ocram pool unavailable!\n", __func__);
+		ret = -ENODEV;
+		goto put_node;
+	}
+
+	ocram_size = gen_pool_size(ocram_pool);
+	ocram_base = gen_pool_alloc(ocram_pool, ocram_size);
+	if (!ocram_base) {
+		pr_warn("%s: unable to alloc ocram!\n", __func__);
+		ret = -ENOMEM;
+		goto put_node;
+	}
+
+	ocram_pbase = gen_pool_virt_to_phys(ocram_pool, ocram_base);
+
+	suspend_ocram_base = __arm_ioremap_exec(ocram_pbase, ocram_size, false);
+
+	pm_info = suspend_ocram_base;
+	pm_info->pbase = ocram_pbase;
+	pm_info->resume_addr = virt_to_phys(cpu_resume);
+	pm_info->pm_info_size = sizeof(*pm_info);
+
+	ret = imx_pm_get_base(&pm_info->anatop_base, socdata->anatop_compat);
+	if (ret) {
+		pr_warn("%s: failed to get anatop base %d!\n", __func__, ret);
+		goto put_node;
+	}
+
+	ret = imx_pm_get_base(&pm_info->scsc_base, socdata->scsc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get scsc base %d!\n", __func__, ret);
+		goto scsc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->ccm_base, socdata->ccm_compat);
+	if (ret) {
+		pr_warn("%s: failed to get ccm base %d!\n", __func__, ret);
+		goto ccm_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->gpc_base, socdata->gpc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get gpc base %d!\n", __func__, ret);
+		goto gpc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->src_base, socdata->src_compat);
+	if (ret) {
+		pr_warn("%s: failed to get src base %d!\n", __func__, ret);
+		goto src_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->ddrmc_base, socdata->ddrmc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get ddrmc base %d!\n", __func__, ret);
+		goto ddrmc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->iomuxc_base, socdata->iomuxc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get iomuxc base %d!\n", __func__, ret);
+		goto iomuxc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->l2_base, "arm,pl310-cache");
+	if (ret == -ENODEV)
+		ret = 0;
+	if (ret) {
+		pr_warn("%s: failed to get pl310-cache base %d!\n",
+			__func__, ret);
+		goto pl310_cache_map_failed;
+	}
+
+	pm_info->ddrmc_io_num = VF610_DDRMC_IO_NUM;
+
+	/* Store DDRMC registers */
+	for (i = 0; i < ARRAY_SIZE(vf610_ddrmc_io_offset); i++, reg++) {
+		pm_info->ddrmc_io_val[reg][0] = vf610_ddrmc_io_offset[i];
+		pm_info->ddrmc_io_val[reg][1] =
+			readl_relaxed(pm_info->ddrmc_base.vbase +
+			vf610_ddrmc_io_offset[i]);
+	}
+
+	/* Store DDRMC PHY registers */
+	for (i = 0; i < ARRAY_SIZE(vf610_ddrmc_phy_io_offset); i++, reg++) {
+		pm_info->ddrmc_io_val[reg][0] = vf610_ddrmc_phy_io_offset[i] +
+			DDRMC_PHY_OFFSET;
+		pm_info->ddrmc_io_val[reg][1] =
+			readl_relaxed(pm_info->ddrmc_base.vbase +
+			DDRMC_PHY_OFFSET + vf610_ddrmc_phy_io_offset[i]);
+	}
+
+	/* Store IOMUX DDR pad registers */
+	pm_info->iomux_ddr_io_num = VF610_IOMUX_DDR_IO_NUM;
+	for (i = 0; i < ARRAY_SIZE(vf610_iomuxc_ddr_io_offset); i++) {
+		pm_info->iomux_ddr_io_val[i][0] = vf610_iomuxc_ddr_io_offset[i];
+		pm_info->iomux_ddr_io_val[i][1] =
+			readl_relaxed(pm_info->iomuxc_base.vbase +
+			vf610_iomuxc_ddr_io_offset[i]);
+	}
+
+	vf610_suspend_in_ocram_fn = fncpy(
+		suspend_ocram_base + sizeof(*pm_info),
+		&vf610_suspend, ocram_size - sizeof(*pm_info));
+
+	goto put_node;
+
+pl310_cache_map_failed:
+	iounmap(pm_info->iomuxc_base.vbase);
+iomuxc_map_failed:
+	iounmap(pm_info->ddrmc_base.vbase);
+ddrmc_map_failed:
+	iounmap(pm_info->src_base.vbase);
+src_map_failed:
+	iounmap(pm_info->gpc_base.vbase);
+gpc_map_failed:
+	iounmap(pm_info->ccm_base.vbase);
+ccm_map_failed:
+	iounmap(pm_info->scsc_base.vbase);
+scsc_map_failed:
+	iounmap(pm_info->anatop_base.vbase);
+put_node:
+	of_node_put(node);
+
+	return ret;
+}
+
+void __init vf610_pm_init(void)
+{
+	int ret;
+
+	if (IS_ENABLED(CONFIG_SUSPEND)) {
+		ret = vf610_suspend_init(&vf610_pm_data);
+		if (ret)
+			pr_warn("%s: No DDR LPM support with suspend %d!\n",
+				__func__, ret);
+	}
+}
+
diff --git a/arch/arm/mach-imx/suspend-vf610.S b/arch/arm/mach-imx/suspend-vf610.S
new file mode 100644
index 0000000..09ad246
--- /dev/null
+++ b/arch/arm/mach-imx/suspend-vf610.S
@@ -0,0 +1,437 @@
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2016 Toradex AG
+ *
+ * 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/linkage.h>
+#include <asm/assembler.h>
+#include <asm/asm-offsets.h>
+#include <asm/hardware/cache-l2x0.h>
+
+/*
+ * ==================== low level suspend ====================
+ *
+ * Better to follow below rules to use ARM registers:
+ * r0: pm_info structure address;
+ * r1 ~ r4: for saving pm_info members;
+ * r5 ~ r10: free registers;
+ * r11: io base address.
+ *
+ * suspend ocram space layout:
+ * ======================== high address ======================
+ *                              .
+ *                              .
+ *                              .
+ *                              ^
+ *                              ^
+ *                              ^
+ *                      vf610_suspend code
+ *              PM_INFO structure(vf610_cpu_pm_info)
+ * ======================== low address =======================
+ */
+
+/*
+ * Below offsets are based on struct vf610_cpu_pm_info
+ * which defined in arch/arm/mach-imx/pm-vf610.c, this
+ * structure contains necessary pm info for low level
+ * suspend related code.
+ */
+#define PM_INFO_PBASE_OFFSET			0x0
+#define PM_INFO_RESUME_ADDR_OFFSET		0x4
+#define PM_INFO_CPU_TYPE_OFFSET			0x8
+#define PM_INFO_PM_INFO_SIZE_OFFSET		0xC
+#define PM_INFO_VF610_ANATOP_P_OFFSET		0x10
+#define PM_INFO_VF610_ANATOP_V_OFFSET		0x14
+#define PM_INFO_VF610_SCSC_P_OFFSET		0x18
+#define PM_INFO_VF610_SCSC_V_OFFSET		0x1C
+#define PM_INFO_VF610_WKPU_P_OFFSET		0x20
+#define PM_INFO_VF610_WKPU_V_OFFSET		0x24
+#define PM_INFO_VF610_CCM_P_OFFSET		0x28
+#define PM_INFO_VF610_CCM_V_OFFSET		0x2C
+#define PM_INFO_VF610_GPC_P_OFFSET		0x30
+#define PM_INFO_VF610_GPC_V_OFFSET		0x34
+#define PM_INFO_VF610_SRC_P_OFFSET		0x38
+#define PM_INFO_VF610_SRC_V_OFFSET		0x3C
+#define PM_INFO_VF610_DDRMC_P_OFFSET		0x40
+#define PM_INFO_VF610_DDRMC_V_OFFSET		0x44
+#define PM_INFO_VF610_IOMUXC_P_OFFSET		0x48
+#define PM_INFO_VF610_IOMUXC_V_OFFSET		0x4c
+#define PM_INFO_VF610_L2_P_OFFSET		0x50
+#define PM_INFO_VF610_L2_V_OFFSET		0x54
+#define PM_INFO_CCM_CACRR			0x58
+#define PM_INFO_CCM_CCSR			0x5c
+#define PM_INFO_DDRMC_IO_NUM_OFFSET		0x60
+#define PM_INFO_DDRMC_IO_VAL_OFFSET		0x64
+#define PM_INFO_IOMUXC_DDR_IO_NUM_OFFSET	(0x64 + 94 * 2 * 4)
+#define PM_INFO_IOMUXC_DDR_IO_VAL_OFFSET	(0x68 + 94 * 2 * 4)
+
+#define VF610_ANADIG_PLL2_CTRL			0x30
+
+#define VF610_ANADIG_MISC0			0x150
+#define VF610_ANADIG_MISC0_CLK_24M_IRC_XTAL_SEL	(0x1 < 13)
+
+#define VF610_ANADIG_PLL1_CTRL			0x270
+
+#define VF610_ANADIG_POWERDOWN			(1 << 12)
+#define VF610_ANADIG_ENABLE			(1 << 13)
+#define VF610_ANADIG_BYPASS			(1 << 16)
+#define VF610_ANADIG_LOCK			(1 << 31)
+
+#define VF610_SCSC_SIRC				0x0
+#define VF610_SCSC_SIRC_SIRC_EN			(0x1 << 0)
+#define VF610_SCSC_SOSC				0x4
+#define VF610_SCSC_SOSC_SOSC_EN			(0x1 << 0)
+
+#define VF610_GPC_PGCR				0x0
+#define VF610_GPC_LPMR				0x40
+
+#define VF610_CCM_CCR				0x00
+#define VF610_CCM_CCR_FXOSC_EN			(0x1 << 12)
+
+#define VF610_CCM_CCSR				0x08
+#define VF610_CCM_CCSR_DDRC_CLK_SEL		(0x1 << 6)
+#define VF610_CCM_CCSR_FAST_CLK_SEL		(0x1 << 5)
+
+#define VF610_CCM_CACRR				0x0C
+
+#define VF610_CCM_CLPCR				0x2C
+#define VF610_CCM_CLPCR_DIS_REF_OSC		(0x1 << 7)
+#define VF610_CCM_CLPCR_FXOSC_PWRDWN		(0x1 << 11)
+
+#define VF610_CCM_CCGR0				0x40
+#define VF610_CCM_CCGR2				0x48
+#define VF610_CCM_CCGR3				0x4C
+#define VF610_CCM_CCGR4				0x50
+#define VF610_CCM_CCGR6				0x58
+
+#define VF610_SRC_GPR0				0x20
+#define VF610_SRC_GPR1				0x24
+#define VF610_SRC_MISC2				0x54
+
+#define VF610_DDRMC_CR00			0x0
+#define VF610_DDRMC_CR00_START			(0x1 << 0)
+
+#define VF610_DDRMC_CR33			0x84
+#define VF610_DDRMC_CR33_PWUP_SREF_EX		(0x1 << 0)
+
+#define VF610_DDRMC_CR34			0x88
+
+#define VF610_DDRMC_CR35			0x8C
+#define VF610_DDRMC_CR35_LP_CMD(cmd)		((cmd) << 8)
+
+#define VF610_DDRMC_CR80			0x140
+#define VF610_DDRMC_CR80_LP_COMPLETE		(0x1 << 9)
+#define VF610_DDRMC_CR80_INIT_COMPLETE		(0x1 << 8)
+#define VF610_DDRMC_CR81			0x144
+
+	.align 3
+
+	/*
+	 * Take DDR RAM out of Low-Power mode
+	 */
+	.macro resume_ddrmc ddrmc_base
+
+	/* Clear low power complete flag... */
+	ldr	r6, =VF610_DDRMC_CR80_LP_COMPLETE
+	str	r6, [\ddrmc_base, #VF610_DDRMC_CR81]
+
+	ldr	r6, [\ddrmc_base, #VF610_DDRMC_CR35]
+	orr	r6, r6, #VF610_DDRMC_CR35_LP_CMD(0x9)
+	str	r6, [\ddrmc_base, #VF610_DDRMC_CR35]
+
+1:
+	ldr	r5, [\ddrmc_base, #VF610_DDRMC_CR80]
+	ands 	r5, r5, #VF610_DDRMC_CR80_LP_COMPLETE
+	beq	1b
+
+	.endm
+
+	.macro enable_syspll pll_base
+
+	ldr	r5, [\pll_base]
+	orr	r5, r5, #VF610_ANADIG_ENABLE
+	bic	r5, r5, #VF610_ANADIG_POWERDOWN
+	bic	r5, r5, #VF610_ANADIG_BYPASS
+	str	r5, [\pll_base]
+
+1:
+	ldr	r5, [\pll_base]
+	tst 	r5, #VF610_ANADIG_LOCK
+	beq	1b
+
+	.endm
+
+ENTRY(vf610_suspend)
+	ldr	r1, [r0, #PM_INFO_PBASE_OFFSET]
+	ldr	r2, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+	ldr	r3, [r0, #PM_INFO_CPU_TYPE_OFFSET]
+	ldr	r4, [r0, #PM_INFO_PM_INFO_SIZE_OFFSET]
+
+	/*
+	 * make sure TLB contain the addr we want,
+	 * as we will access them after DDRMC IO floated.
+	 */
+
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+	ldr	r11, [r0, #PM_INFO_VF610_GPC_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+	ldr	r11, [r0, #PM_INFO_VF610_SRC_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+
+	ldr	r11, [r0, #PM_INFO_VF610_SRC_V_OFFSET]
+
+	/* Disable DDR RESET */
+	ldr	r6, [r11, #VF610_SRC_MISC2]
+	orr	r6, r6, #0x1
+	str	r6, [r11, #VF610_SRC_MISC2]
+
+	/* Set ENTRY/ARGUMENT register */
+	ldr	r6, =vf610_suspend
+	ldr	r7, =resume
+	sub	r7, r7, r6
+	add	r8, r1, r4
+	add	r9, r8, r7
+	str	r9, [r11, #VF610_SRC_GPR0]
+	str	r1, [r11, #VF610_SRC_GPR1]
+
+	/* Put memory in self refresh... */
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_V_OFFSET]
+
+	ldr	r6, =VF610_DDRMC_CR80_LP_COMPLETE
+	str	r6, [r11, #VF610_DDRMC_CR81]
+
+	ldr	r6, [r11, #VF610_DDRMC_CR35]
+	orr	r6, r6, #VF610_DDRMC_CR35_LP_CMD(0xA)
+	str	r6, [r11, #VF610_DDRMC_CR35]
+
+ddrmc_cmd_complete:
+	/* Hardware without CKE/RESET fixes seems to hang at this read.... */
+	ldr	r5, [r11, #VF610_DDRMC_CR80]
+	ands 	r5, r5, #VF610_DDRMC_CR80_LP_COMPLETE
+	beq	ddrmc_cmd_complete
+
+	/* switch to internal FIRC */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_V_OFFSET]
+	ldr	r5, [r11, #VF610_CCM_CCSR]
+	bic	r5, r5, #0x30 /* FAST_/SLOW_CLK_SEL */
+	str	r5, [r11, #VF610_CCM_CCSR]
+	bic	r5, r5, #0x07 /* SYS_CLK_SEL */
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	/* LP-Mode: STOP */
+	ldr	r11, [r0, #PM_INFO_VF610_GPC_V_OFFSET]
+	ldr	r6, =0x02
+	str	r6, [r11, #VF610_GPC_LPMR]
+
+	/* Zzz, enter stop mode */
+	wfi
+	nop
+	nop
+	nop
+	nop
+
+	/* If we get here, there is already an interrupt pending. Restore... */
+	ldr	r6, =0x00
+	str	r6, [r11, #VF610_GPC_LPMR]
+
+	/* Get previous CCSR/CACRR settings */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_V_OFFSET]
+	ldr	r5, [r0, #PM_INFO_CCM_CCSR]
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	ldr	r5, [r0, #PM_INFO_CCM_CACRR]
+	str	r5, [r11, #VF610_CCM_CACRR]
+
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_V_OFFSET]
+	resume_ddrmc r11
+
+	ret	lr
+
+/* Resume path if CPU uses the SRC_GPR0 (PERSISTENT_ENTRY0) */
+resume:
+	/* invalidate L1 I-cache first */
+	mov     r6, #0x0
+	mcr     p15, 0, r6, c7, c5, 0
+	mcr     p15, 0, r6, c7, c5, 6
+
+	/* enable the Icache and branch prediction */
+	mov     r6, #0x1800
+	mcr     p15, 0, r6, c1, c0, 0
+	isb
+
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_P_OFFSET]
+
+	ldr	r5, [r11, #VF610_CCM_CCSR]
+	orr	r5, r5, #(1 << 13)
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	/* enable IOMUX, PORT A-E */
+	ldr	r5, [r11, #VF610_CCM_CCGR2]
+	ldr	r6, =0xfff0000
+	orr	r5, r5, r6
+	str	r5, [r11, #VF610_CCM_CCGR2]
+
+	/* enable ANADIG and SCSM */
+	ldr	r5, [r11, #VF610_CCM_CCGR3]
+	orr	r5, r5, #0x33
+	str	r5, [r11, #VF610_CCM_CCGR3]
+
+	/* enable GPC, CCM and WKUP */
+	ldr	r5, [r11, #VF610_CCM_CCGR4]
+	orr	r5, r5, #0x3f00000
+	str	r5, [r11, #VF610_CCM_CCGR4]
+
+	/* enable DDRMC */
+	ldr	r5, [r11, #VF610_CCM_CCGR6]
+	orr	r5, r5, #0x30000000
+	str	r5, [r11, #VF610_CCM_CCGR6]
+
+#ifdef DEBUG
+	/* enable UART0 */
+	ldr	r5, [r11, #VF610_CCM_CCGR0]
+	orr	r5, r5, #0xC000
+	str	r5, [r11, #VF610_CCM_CCGR0]
+
+	/* Mux UART0 */
+	ldr	r5,=0x1021a2
+	ldr	r6,=0x40048080
+	str	r5, [r6, #0x0]
+	ldr	r5,=0x1021a1
+	ldr	r6,=0x40048084
+	str	r5, [r6, #0x0]
+#endif
+
+	/* Set IOMUX for DDR pads */
+	ldr	r11, [r0, #PM_INFO_VF610_IOMUXC_P_OFFSET]
+
+	ldr	r6, [r0, #PM_INFO_IOMUXC_DDR_IO_NUM_OFFSET]
+	ldr	r7, =PM_INFO_IOMUXC_DDR_IO_VAL_OFFSET
+	add	r7, r7, r0
+
+loop_iomuxc_ddr_restore:
+	ldr	r8, [r7], #0x4
+	ldr	r9, [r7], #0x4
+	str	r9, [r11, r8]
+	subs	r6, r6, #0x1
+	bne	loop_iomuxc_ddr_restore
+
+
+	/* Enable slow oscilators */
+	ldr	r11, [r0, #PM_INFO_VF610_SCSC_P_OFFSET]
+
+	ldr	r5, [r11, #VF610_SCSC_SOSC]
+	orr	r5, r5, #VF610_SCSC_SOSC_SOSC_EN
+	str	r5, [r11, #VF610_SCSC_SOSC]
+
+	ldr	r5, [r11, #VF610_SCSC_SIRC]
+	orr	r5, r5, #VF610_SCSC_SIRC_SIRC_EN
+	str	r5, [r11, #VF610_SCSC_SIRC]
+
+	/* Enable fast osciallator */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_P_OFFSET]
+
+	ldr	r5, [r11, #VF610_CCM_CLPCR]
+	bic	r5, r5, #VF610_CCM_CLPCR_DIS_REF_OSC
+	bic	r5, r5, #VF610_CCM_CLPCR_FXOSC_PWRDWN
+	str	r5, [r11, #VF610_CCM_CLPCR]
+
+	ldr	r5, [r11, #VF610_CCM_CCR]
+	orr	r5, r5, #VF610_CCM_CCR_FXOSC_EN
+	str	r5, [r11, #VF610_CCM_CCR]
+
+	ldr	r5, [r11, #VF610_CCM_CCSR]
+	orr	r5, r5, #VF610_CCM_CCSR_FAST_CLK_SEL
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	ldr	r11, [r0, #PM_INFO_VF610_ANATOP_P_OFFSET]
+
+	/* Select external FXOSC */
+	ldr	r5, [r11, #VF610_ANADIG_MISC0]
+	bic	r5, r5, #VF610_ANADIG_MISC0_CLK_24M_IRC_XTAL_SEL
+	str	r5, [r11, #VF610_ANADIG_MISC0]
+
+	add	r6, r11, #VF610_ANADIG_PLL1_CTRL
+	enable_syspll r6
+
+	/* enable pll2 only if required for DDR */
+	ldr	r5, [r0, #PM_INFO_CCM_CCSR]
+	tst 	r5, #VF610_CCM_CCSR_DDRC_CLK_SEL
+	bne	switch_sysclk
+
+	add	r6, r11, #VF610_ANADIG_PLL2_CTRL
+	enable_syspll r6
+
+switch_sysclk:
+
+	/* Enable PFD and switch to fast clock */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_P_OFFSET]
+
+	/* Get previous CCSR/CACRR settings */
+	ldr	r5, [r0, #PM_INFO_CCM_CCSR]
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	ldr	r5, [r0, #PM_INFO_CCM_CACRR]
+	str	r5, [r11, #VF610_CCM_CACRR]
+
+	/* Restore memory configuration */
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_P_OFFSET]
+
+	ldr	r6, [r0, #PM_INFO_DDRMC_IO_NUM_OFFSET]
+	ldr	r7, =PM_INFO_DDRMC_IO_VAL_OFFSET
+	add	r7, r7, r0
+
+	/* Clear start bit of first memory register, do not start yet... */
+	ldr	r8, [r7], #0x4
+	ldr	r9, [r7], #0x4
+	bic	r9, r9, #VF610_DDRMC_CR00_START
+	str	r9, [r11, r8]
+	subs	r6, r6, #0x1
+
+loop_ddrmc_restore:
+	ldr	r8, [r7], #0x4
+	ldr	r9, [r7], #0x4
+	str	r9, [r11, r8]
+	subs	r6, r6, #0x1
+	bne	loop_ddrmc_restore
+
+	/* Set PWUP_SREF_EX to avoid a full memory initialization */
+	ldr	r6, [r11, #VF610_DDRMC_CR33]
+	orr	r6, r6, #VF610_DDRMC_CR33_PWUP_SREF_EX
+	str	r6, [r11, #VF610_DDRMC_CR33]
+
+	/* Start initialization */
+	ldr	r6, =VF610_DDRMC_CR80_INIT_COMPLETE
+	str	r6, [r11, #VF610_DDRMC_CR81]
+
+	ldr	r6, [r11, #VF610_DDRMC_CR00]
+	orr	r6, r6, #VF610_DDRMC_CR00_START
+	str	r6, [r11, #VF610_DDRMC_CR00]
+
+ddrmc_initializing:
+	ldr	r5, [r11, #VF610_DDRMC_CR80]
+	ands 	r5, r5, #VF610_DDRMC_CR80_INIT_COMPLETE
+	beq	ddrmc_initializing
+
+	resume_ddrmc r11
+
+	/* LP-Mode: RUN */
+	ldr	r11, [r0, #PM_INFO_VF610_GPC_P_OFFSET]
+	ldr	r5, =0x0
+	str	r5, [r11, #VF610_GPC_LPMR]
+
+	/* get physical resume address from pm_info. */
+	ldr	lr, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+
+	ret	lr
+ENDPROC(vf610_suspend)
+
diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index 170a96c..27d4cf0 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
 
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 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

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 9fbe624..ea2e8bd 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -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
diff --git a/arch/arm/mach-imx/common.h b/arch/arm/mach-imx/common.h
index 58a3846..737b1e4 100644
--- a/arch/arm/mach-imx/common.h
+++ b/arch/arm/mach-imx/common.h
@@ -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);
diff --git a/arch/arm/mach-imx/mach-vf610.c b/arch/arm/mach-imx/mach-vf610.c
index b20f6c1..5ba668f 100644
--- a/arch/arm/mach-imx/mach-vf610.c
+++ b/arch/arm/mach-imx/mach-vf610.c
@@ -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
diff --git a/arch/arm/mach-imx/pm-vf610.c b/arch/arm/mach-imx/pm-vf610.c
new file mode 100644
index 0000000..ecc7c9c
--- /dev/null
+++ b/arch/arm/mach-imx/pm-vf610.c
@@ -0,0 +1,634 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * Copyright 2016 Toradex AG
+ *
+ * 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
+ */
+
+#ifdef DEBUG
+#define pr_pmdebug(fmt, ...) pr_info("PM: VF610: " fmt "\n", ##__VA_ARGS__)
+#else
+#define pr_pmdebug(fmt, ...)
+#endif
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/genalloc.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+#include <linux/suspend.h>
+#include <linux/clk.h>
+#include <asm/cacheflush.h>
+#include <asm/fncpy.h>
+#include <asm/proc-fns.h>
+#include <asm/suspend.h>
+#include <asm/tlb.h>
+
+#include "common.h"
+
+#define DDRMC_PHY_OFFSET		0x400
+
+#define CCR				0x0
+#define BM_CCR_FIRC_EN			(0x1 << 16)
+#define BM_CCR_FXOSC_EN			(0x1 << 12)
+
+#define CCSR				0x8
+#define BM_CCSR_DDRC_CLK_SEL		(0x1 << 6)
+#define BM_CCSR_FAST_CLK_SEL		(0x1 << 5)
+#define BM_CCSR_SLOW_CLK_SEL		(0x1 << 4)
+#define BM_CCSR_SYS_CLK_SEL_MASK	(0x7 << 0)
+
+#define CACRR				0xc
+
+#define CLPCR				0x2c
+#define BM_CLPCR_ARM_CLK_DIS_ON_LPM	(0x1 << 5)
+#define BM_CLPCR_SBYOS			(0x1 << 6)
+#define BM_CLPCR_DIS_REF_OSC		(0x1 << 7)
+#define BM_CLPCR_ANADIG_STOP_MODE	(0x1 << 8)
+#define BM_CLPCR_FXOSC_BYPSEN		(0x1 << 10)
+#define BM_CLPCR_FXOSC_PWRDWN		(0x1 << 11)
+#define BM_CLPCR_MASK_CORE0_WFI		(0x1 << 22)
+#define BM_CLPCR_MASK_CORE1_WFI		(0x1 << 23)
+#define BM_CLPCR_MASK_SCU_IDLE		(0x1 << 24)
+#define BM_CLPCR_MASK_L2CC_IDLE		(0x1 << 25)
+
+#define CGPR				0x64
+#define BM_CGPR_INT_MEM_CLK_LPM		(0x1 << 17)
+
+#define GPC_PGCR			0x0
+#define BM_PGCR_DS_STOP			(0x1 << 7)
+#define BM_PGCR_DS_LPSTOP		(0x1 << 6)
+#define BM_PGCR_WB_STOP			(0x1 << 4)
+#define BM_PGCR_HP_OFF			(0x1 << 3)
+#define BM_PGCR_PG_PD1			(0x1 << 0)
+
+#define GPC_LPMR			0x40
+#define BM_LPMR_RUN			0x0
+#define BM_LPMR_STOP			0x2
+
+#define ANATOP_PLL1_CTRL		0x270
+#define ANATOP_PLL2_CTRL		0x30
+#define ANATOP_PLL2_PFD			0x100
+#define BM_PLL_POWERDOWN	(0x1 << 12)
+#define BM_PLL_ENABLE		(0x1 << 13)
+#define BM_PLL_BYPASS		(0x1 << 16)
+#define BM_PLL_LOCK		(0x1 << 31)
+#define BM_PLL_PFD2_CLKGATE	(0x1 << 15)
+#define BM_PLL_USB_POWER	(0x1 << 12)
+#define BM_PLL_EN_USB_CLKS	(0x1 << 6)
+
+#define VF610_DDRMC_IO_NUM		94
+#define VF610_IOMUX_DDR_IO_NUM		48
+#define VF610_ANATOP_IO_NUM		2
+
+static void __iomem *suspend_ocram_base;
+static void (*vf610_suspend_in_ocram_fn)(void __iomem *ocram_vbase);
+
+#ifdef DEBUG
+static void __iomem *uart_membase;
+static unsigned long uart_clk;
+#endif
+
+static const u32 vf610_iomuxc_ddr_io_offset[] __initconst = {
+	0x220, 0x224, 0x228, 0x22c, 0x230, 0x234, 0x238, 0x23c,
+	0x240, 0x244, 0x248, 0x24c, 0x250, 0x254, 0x258, 0x25c,
+	0x260, 0x264, 0x268, 0x26c, 0x270, 0x274, 0x278, 0x27c,
+	0x280, 0x284, 0x288, 0x28c, 0x290, 0x294, 0x298, 0x29c,
+	0x2a0, 0x2a4, 0x2a8, 0x2ac, 0x2b0, 0x2b4, 0x2b8, 0x2bc,
+	0x2c0, 0x2c4, 0x2c8, 0x2cc, 0x2d0, 0x2d4, 0x2d8, 0x21c,
+};
+
+
+static const u32 vf610_ddrmc_io_offset[] __initconst = {
+	0x00, 0x08, 0x28, 0x2c, 0x30, 0x34, 0x38,
+	0x40, 0x44, 0x48, 0x50, 0x54, 0x58, 0x5c,
+	0x60, 0x64, 0x68, 0x70, 0x74, 0x78, 0x7c,
+	0x84, 0x88, 0x98, 0x9c, 0xa4, 0xc0,
+	0x108, 0x10c, 0x114, 0x118, 0x120, 0x124,
+	0x128, 0x12c, 0x130, 0x134, 0x138, 0x13c,
+	0x148, 0x15c, 0x160, 0x164, 0x16c, 0x180,
+	0x184, 0x188, 0x18c, 0x198, 0x1a4, 0x1a8,
+	0x1b8, 0x1d4, 0x1d8, 0x1e0, 0x1e4, 0x1e8,
+	0x1ec, 0x1f0, 0x1f8, 0x210, 0x224, 0x228,
+	0x22c, 0x230, 0x23c, 0x240, 0x244, 0x248,
+	0x24c, 0x250, 0x25c, 0x268, 0x26c, 0x278,
+	0x268
+};
+
+static const u32 vf610_ddrmc_phy_io_offset[] __initconst = {
+	0x00, 0x04, 0x08, 0x0c, 0x10,
+	0x40, 0x44, 0x48, 0x4c, 0x50,
+	0x80, 0x84, 0x88, 0x8c, 0x90,
+	0xc4, 0xc8, 0xd0
+};
+
+/*
+ * suspend ocram space layout:
+ * ======================== high address ======================
+ *                              .
+ *                              .
+ *                              .
+ *                              ^
+ *                              ^
+ *                              ^
+ *                      vf610_suspend code
+ *              PM_INFO structure(vf610_cpu_pm_info)
+ * ======================== low address =======================
+ */
+
+struct vf610_pm_base {
+	phys_addr_t pbase;
+	void __iomem *vbase;
+};
+
+struct vf610_pm_socdata {
+	const char *anatop_compat;
+	const char *scsc_compat;
+	const char *wkpu_compat;
+	const char *ccm_compat;
+	const char *gpc_compat;
+	const char *src_compat;
+	const char *ddrmc_compat;
+	const char *iomuxc_compat;
+};
+
+static const struct vf610_pm_socdata vf610_pm_data __initconst = {
+	.anatop_compat = "fsl,vf610-anatop",
+	.scsc_compat = "fsl,vf610-scsc",
+	.wkpu_compat = "fsl,vf610-wkpu",
+	.ccm_compat = "fsl,vf610-ccm",
+	.gpc_compat = "fsl,vf610-gpc",
+	.src_compat = "fsl,vf610-src",
+	.ddrmc_compat = "fsl,vf610-ddrmc",
+	.iomuxc_compat = "fsl,vf610-iomuxc",
+};
+
+/*
+ * This structure is for passing necessary data for low level ocram
+ * suspend code(arch/arm/mach-imx/suspend-vf610.S), if this struct
+ * definition is changed, the offset definition in
+ * arch/arm/mach-imx/suspend-vf610.S must be also changed accordingly,
+ * otherwise, the suspend to ocram function will be broken!
+ */
+struct vf610_cpu_pm_info {
+	phys_addr_t pbase; /* The physical address of pm_info. */
+	phys_addr_t resume_addr; /* The physical resume address for asm code */
+	u32 cpu_type; /* Currently not used, leave it for alignment */
+	u32 pm_info_size; /* Size of pm_info. */
+	struct vf610_pm_base anatop_base;
+	struct vf610_pm_base scsc_base;
+	struct vf610_pm_base wkpu_base;
+	struct vf610_pm_base ccm_base;
+	struct vf610_pm_base gpc_base;
+	struct vf610_pm_base src_base;
+	struct vf610_pm_base ddrmc_base;
+	struct vf610_pm_base iomuxc_base;
+	struct vf610_pm_base l2_base;
+	u32 ccm_cacrr;
+	u32 ccm_ccsr;
+	u32 ddrmc_io_num; /* Number of MMDC IOs which need saved/restored. */
+	u32 ddrmc_io_val[VF610_DDRMC_IO_NUM][2]; /* To save offset and value */
+	u32 iomux_ddr_io_num;
+	u32 iomux_ddr_io_val[VF610_IOMUX_DDR_IO_NUM][2];
+} __aligned(8);
+
+#ifdef DEBUG
+static void vf610_uart_reinit(unsigned long int rate, unsigned long int baud)
+{
+	u8 tmp, c2;
+	u16 sbr, brfa;
+
+	/* UART_C2 */
+	c2 = __raw_readb(uart_membase + 0x3);
+	__raw_writeb(0, uart_membase + 0x3);
+
+	sbr = (u16) (rate / (baud * 16));
+	brfa = (rate / baud) - (sbr * 16);
+
+	tmp = ((sbr & 0x1f00) >> 8);
+	__raw_writeb(tmp, uart_membase + 0x0);
+	tmp = sbr & 0x00ff;
+	__raw_writeb(tmp, uart_membase + 0x1);
+
+	/* UART_C4 */
+	__raw_writeb(brfa & 0xf, uart_membase + 0xa);
+
+	__raw_writeb(c2, uart_membase + 0x3);
+}
+#else
+#define vf610_uart_reinit(rate, baud)
+#endif
+
+static void vf610_set(void __iomem *pll_base, u32 mask)
+{
+	writel(readl(pll_base) | mask, pll_base);
+}
+
+static void vf610_clr(void __iomem *pll_base, u32 mask)
+{
+	writel(readl(pll_base) & ~mask, pll_base);
+}
+
+int vf610_set_lpm(enum vf610_cpu_pwr_mode mode)
+{
+	struct vf610_cpu_pm_info *pm_info = suspend_ocram_base;
+	void __iomem *ccm_base = pm_info->ccm_base.vbase;
+	void __iomem *gpc_base = pm_info->gpc_base.vbase;
+	void __iomem *anatop = pm_info->anatop_base.vbase;
+	u32 ccr = readl_relaxed(ccm_base + CCR);
+	u32 ccsr = readl_relaxed(ccm_base + CCSR);
+	u32 cacrr = readl_relaxed(ccm_base + CACRR);
+	u32 cclpcr = 0;
+	u32 gpc_pgcr = 0;
+
+	switch (mode) {
+	case VF610_LP_STOP:
+		/* Store clock settings */
+		pm_info->ccm_ccsr = ccsr;
+		pm_info->ccm_cacrr = cacrr;
+
+		ccr |= BM_CCR_FIRC_EN;
+		writel_relaxed(ccr, ccm_base + CCR);
+
+		cclpcr |= BM_CLPCR_ANADIG_STOP_MODE;
+		cclpcr |= BM_CLPCR_SBYOS;
+
+		cclpcr |= BM_CLPCR_MASK_SCU_IDLE;
+		cclpcr |= BM_CLPCR_MASK_L2CC_IDLE;
+		cclpcr |= BM_CLPCR_MASK_CORE1_WFI;
+		writel_relaxed(cclpcr, ccm_base + CLPCR);
+
+		gpc_pgcr |= BM_PGCR_DS_STOP;
+		gpc_pgcr |= BM_PGCR_DS_LPSTOP;
+		gpc_pgcr |= BM_PGCR_WB_STOP;
+		gpc_pgcr |= BM_PGCR_HP_OFF;
+		gpc_pgcr |= BM_PGCR_PG_PD1;
+		writel_relaxed(gpc_pgcr, gpc_base + GPC_PGCR);
+		break;
+	case VF610_STOP:
+		cclpcr &= ~BM_CLPCR_ANADIG_STOP_MODE;
+		cclpcr |= BM_CLPCR_ARM_CLK_DIS_ON_LPM;
+		cclpcr |= BM_CLPCR_SBYOS;
+		writel_relaxed(cclpcr, ccm_base + CLPCR);
+
+		gpc_pgcr |= BM_PGCR_DS_STOP;
+		gpc_pgcr |= BM_PGCR_HP_OFF;
+		writel_relaxed(gpc_pgcr, gpc_base + GPC_PGCR);
+
+		/* fall-through */
+	case VF610_LP_RUN:
+		/* Store clock settings */
+		pm_info->ccm_ccsr = ccsr;
+		pm_info->ccm_cacrr = cacrr;
+
+		ccr |= BM_CCR_FIRC_EN;
+		writel_relaxed(ccr, ccm_base + CCR);
+
+		/* Enable PLL2 for DDR clock */
+		vf610_set(anatop + ANATOP_PLL2_CTRL, BM_PLL_ENABLE);
+		vf610_clr(anatop + ANATOP_PLL2_CTRL, BM_PLL_POWERDOWN);
+		vf610_clr(anatop + ANATOP_PLL2_CTRL, BM_PLL_BYPASS);
+		while (!(readl(anatop + ANATOP_PLL2_CTRL) & BM_PLL_LOCK));
+		vf610_clr(anatop + ANATOP_PLL2_PFD, BM_PLL_PFD2_CLKGATE);
+
+		/* Switch internal OSC's */
+		ccsr &= ~BM_CCSR_FAST_CLK_SEL;
+		ccsr &= ~BM_CCSR_SLOW_CLK_SEL;
+
+		/* Select PLL2 as DDR clock */
+		ccsr &= ~BM_CCSR_DDRC_CLK_SEL;
+		writel_relaxed(ccsr, ccm_base + CCSR);
+
+		ccsr &= ~BM_CCSR_SYS_CLK_SEL_MASK;
+		writel_relaxed(ccsr, ccm_base + CCSR);
+		vf610_uart_reinit(4000000UL, 115200);
+
+		vf610_set(anatop + ANATOP_PLL1_CTRL, BM_PLL_BYPASS);
+		writel_relaxed(BM_LPMR_STOP, gpc_base + GPC_LPMR);
+		break;
+	case VF610_RUN:
+		writel_relaxed(BM_LPMR_RUN, gpc_base + GPC_LPMR);
+
+		vf610_clr(anatop + ANATOP_PLL1_CTRL, BM_PLL_BYPASS);
+		while (!(readl(anatop + ANATOP_PLL1_CTRL) & BM_PLL_LOCK));
+
+		/* Restore clock settings */
+		writel(pm_info->ccm_ccsr, ccm_base + CCSR);
+
+		vf610_uart_reinit(uart_clk, 115200);
+		pr_pmdebug("resuming, uart_reinit done");
+
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int vf610_suspend_finish(unsigned long val)
+{
+	if (!vf610_suspend_in_ocram_fn) {
+		cpu_do_idle();
+	} else {
+		/*
+		 * call low level suspend function in ocram,
+		 * as we need to float DDR IO.
+		 */
+		local_flush_tlb_all();
+		flush_cache_all();
+		outer_flush_all();
+		vf610_suspend_in_ocram_fn(suspend_ocram_base);
+	}
+
+	return 0;
+}
+
+static int vf610_pm_enter(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_STANDBY:
+		vf610_set_lpm(VF610_STOP);
+
+		/* zzZZZzzz */
+		cpu_do_idle();
+
+		vf610_set_lpm(VF610_RUN);
+		break;
+	case PM_SUSPEND_MEM:
+		vf610_set_lpm(VF610_LP_STOP);
+
+		cpu_suspend(0, vf610_suspend_finish);
+		outer_resume();
+
+		vf610_set_lpm(VF610_RUN);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int vf610_pm_valid(suspend_state_t state)
+{
+	return (state == PM_SUSPEND_STANDBY || state == PM_SUSPEND_MEM);
+}
+
+static const struct platform_suspend_ops vf610_pm_ops = {
+	.enter = vf610_pm_enter,
+	.valid = vf610_pm_valid,
+};
+
+static int __init imx_pm_get_base(struct vf610_pm_base *base,
+				const char *compat)
+{
+	struct device_node *node;
+	struct resource res;
+	int ret = 0;
+
+	node = of_find_compatible_node(NULL, NULL, compat);
+	if (!node) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	ret = of_address_to_resource(node, 0, &res);
+	if (ret)
+		goto put_node;
+
+	base->pbase = res.start;
+	base->vbase = ioremap(res.start, resource_size(&res));
+
+	if (!base->vbase)
+		ret = -ENOMEM;
+
+put_node:
+	of_node_put(node);
+out:
+	return ret;
+}
+
+#ifdef DEBUG
+static int __init vf610_uart_init(void)
+{
+	struct device_node *dn;
+	const char *name;
+	struct clk *clk;
+	int ret;
+
+	name = of_get_property(of_chosen, "stdout-path", NULL);
+	if (name == NULL)
+		return -ENODEV;
+
+	dn = of_find_node_by_path(name);
+	if (!dn)
+		return -ENODEV;
+
+	clk = of_clk_get(dn, 0);
+
+	if (!clk) {
+		ret = PTR_ERR(clk);
+		goto put_node;
+	}
+
+	uart_clk = clk_get_rate(clk);
+
+	uart_membase = of_iomap(dn, 0);
+	if (!clk) {
+		ret = -ENOMEM;
+		goto put_node;
+	}
+
+	ret = 0;
+
+put_node:
+	of_node_put(dn);
+	return ret;
+}
+#endif
+
+static int __init vf610_suspend_init(const struct vf610_pm_socdata *socdata)
+{
+	phys_addr_t ocram_pbase;
+	struct device_node *node;
+	struct platform_device *pdev;
+	struct vf610_cpu_pm_info *pm_info;
+	struct gen_pool *ocram_pool;
+	size_t ocram_size;
+	unsigned long ocram_base;
+	int ret = 0, reg = 0;
+	int i;
+
+#ifdef DEBUG
+	ret = vf610_uart_init();
+	if (ret < 0)
+		return ret;
+#endif
+
+	suspend_set_ops(&vf610_pm_ops);
+
+	node = of_find_compatible_node(NULL, NULL, "mmio-sram");
+	if (!node) {
+		pr_warn("%s: failed to find ocram node!\n", __func__);
+		return -ENODEV;
+	}
+
+	pdev = of_find_device_by_node(node);
+	if (!pdev) {
+		pr_warn("%s: failed to find ocram device!\n", __func__);
+		ret = -ENODEV;
+		goto put_node;
+	}
+
+	ocram_pool = gen_pool_get(&pdev->dev, "stbyram1");
+	if (!ocram_pool) {
+		pr_warn("%s: ocram pool unavailable!\n", __func__);
+		ret = -ENODEV;
+		goto put_node;
+	}
+
+	ocram_size = gen_pool_size(ocram_pool);
+	ocram_base = gen_pool_alloc(ocram_pool, ocram_size);
+	if (!ocram_base) {
+		pr_warn("%s: unable to alloc ocram!\n", __func__);
+		ret = -ENOMEM;
+		goto put_node;
+	}
+
+	ocram_pbase = gen_pool_virt_to_phys(ocram_pool, ocram_base);
+
+	suspend_ocram_base = __arm_ioremap_exec(ocram_pbase, ocram_size, false);
+
+	pm_info = suspend_ocram_base;
+	pm_info->pbase = ocram_pbase;
+	pm_info->resume_addr = virt_to_phys(cpu_resume);
+	pm_info->pm_info_size = sizeof(*pm_info);
+
+	ret = imx_pm_get_base(&pm_info->anatop_base, socdata->anatop_compat);
+	if (ret) {
+		pr_warn("%s: failed to get anatop base %d!\n", __func__, ret);
+		goto put_node;
+	}
+
+	ret = imx_pm_get_base(&pm_info->scsc_base, socdata->scsc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get scsc base %d!\n", __func__, ret);
+		goto scsc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->ccm_base, socdata->ccm_compat);
+	if (ret) {
+		pr_warn("%s: failed to get ccm base %d!\n", __func__, ret);
+		goto ccm_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->gpc_base, socdata->gpc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get gpc base %d!\n", __func__, ret);
+		goto gpc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->src_base, socdata->src_compat);
+	if (ret) {
+		pr_warn("%s: failed to get src base %d!\n", __func__, ret);
+		goto src_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->ddrmc_base, socdata->ddrmc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get ddrmc base %d!\n", __func__, ret);
+		goto ddrmc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->iomuxc_base, socdata->iomuxc_compat);
+	if (ret) {
+		pr_warn("%s: failed to get iomuxc base %d!\n", __func__, ret);
+		goto iomuxc_map_failed;
+	}
+
+	ret = imx_pm_get_base(&pm_info->l2_base, "arm,pl310-cache");
+	if (ret == -ENODEV)
+		ret = 0;
+	if (ret) {
+		pr_warn("%s: failed to get pl310-cache base %d!\n",
+			__func__, ret);
+		goto pl310_cache_map_failed;
+	}
+
+	pm_info->ddrmc_io_num = VF610_DDRMC_IO_NUM;
+
+	/* Store DDRMC registers */
+	for (i = 0; i < ARRAY_SIZE(vf610_ddrmc_io_offset); i++, reg++) {
+		pm_info->ddrmc_io_val[reg][0] = vf610_ddrmc_io_offset[i];
+		pm_info->ddrmc_io_val[reg][1] =
+			readl_relaxed(pm_info->ddrmc_base.vbase +
+			vf610_ddrmc_io_offset[i]);
+	}
+
+	/* Store DDRMC PHY registers */
+	for (i = 0; i < ARRAY_SIZE(vf610_ddrmc_phy_io_offset); i++, reg++) {
+		pm_info->ddrmc_io_val[reg][0] = vf610_ddrmc_phy_io_offset[i] +
+			DDRMC_PHY_OFFSET;
+		pm_info->ddrmc_io_val[reg][1] =
+			readl_relaxed(pm_info->ddrmc_base.vbase +
+			DDRMC_PHY_OFFSET + vf610_ddrmc_phy_io_offset[i]);
+	}
+
+	/* Store IOMUX DDR pad registers */
+	pm_info->iomux_ddr_io_num = VF610_IOMUX_DDR_IO_NUM;
+	for (i = 0; i < ARRAY_SIZE(vf610_iomuxc_ddr_io_offset); i++) {
+		pm_info->iomux_ddr_io_val[i][0] = vf610_iomuxc_ddr_io_offset[i];
+		pm_info->iomux_ddr_io_val[i][1] =
+			readl_relaxed(pm_info->iomuxc_base.vbase +
+			vf610_iomuxc_ddr_io_offset[i]);
+	}
+
+	vf610_suspend_in_ocram_fn = fncpy(
+		suspend_ocram_base + sizeof(*pm_info),
+		&vf610_suspend, ocram_size - sizeof(*pm_info));
+
+	goto put_node;
+
+pl310_cache_map_failed:
+	iounmap(pm_info->iomuxc_base.vbase);
+iomuxc_map_failed:
+	iounmap(pm_info->ddrmc_base.vbase);
+ddrmc_map_failed:
+	iounmap(pm_info->src_base.vbase);
+src_map_failed:
+	iounmap(pm_info->gpc_base.vbase);
+gpc_map_failed:
+	iounmap(pm_info->ccm_base.vbase);
+ccm_map_failed:
+	iounmap(pm_info->scsc_base.vbase);
+scsc_map_failed:
+	iounmap(pm_info->anatop_base.vbase);
+put_node:
+	of_node_put(node);
+
+	return ret;
+}
+
+void __init vf610_pm_init(void)
+{
+	int ret;
+
+	if (IS_ENABLED(CONFIG_SUSPEND)) {
+		ret = vf610_suspend_init(&vf610_pm_data);
+		if (ret)
+			pr_warn("%s: No DDR LPM support with suspend %d!\n",
+				__func__, ret);
+	}
+}
+
diff --git a/arch/arm/mach-imx/suspend-vf610.S b/arch/arm/mach-imx/suspend-vf610.S
new file mode 100644
index 0000000..09ad246
--- /dev/null
+++ b/arch/arm/mach-imx/suspend-vf610.S
@@ -0,0 +1,437 @@
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2016 Toradex AG
+ *
+ * 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/linkage.h>
+#include <asm/assembler.h>
+#include <asm/asm-offsets.h>
+#include <asm/hardware/cache-l2x0.h>
+
+/*
+ * ==================== low level suspend ====================
+ *
+ * Better to follow below rules to use ARM registers:
+ * r0: pm_info structure address;
+ * r1 ~ r4: for saving pm_info members;
+ * r5 ~ r10: free registers;
+ * r11: io base address.
+ *
+ * suspend ocram space layout:
+ * ======================== high address ======================
+ *                              .
+ *                              .
+ *                              .
+ *                              ^
+ *                              ^
+ *                              ^
+ *                      vf610_suspend code
+ *              PM_INFO structure(vf610_cpu_pm_info)
+ * ======================== low address =======================
+ */
+
+/*
+ * Below offsets are based on struct vf610_cpu_pm_info
+ * which defined in arch/arm/mach-imx/pm-vf610.c, this
+ * structure contains necessary pm info for low level
+ * suspend related code.
+ */
+#define PM_INFO_PBASE_OFFSET			0x0
+#define PM_INFO_RESUME_ADDR_OFFSET		0x4
+#define PM_INFO_CPU_TYPE_OFFSET			0x8
+#define PM_INFO_PM_INFO_SIZE_OFFSET		0xC
+#define PM_INFO_VF610_ANATOP_P_OFFSET		0x10
+#define PM_INFO_VF610_ANATOP_V_OFFSET		0x14
+#define PM_INFO_VF610_SCSC_P_OFFSET		0x18
+#define PM_INFO_VF610_SCSC_V_OFFSET		0x1C
+#define PM_INFO_VF610_WKPU_P_OFFSET		0x20
+#define PM_INFO_VF610_WKPU_V_OFFSET		0x24
+#define PM_INFO_VF610_CCM_P_OFFSET		0x28
+#define PM_INFO_VF610_CCM_V_OFFSET		0x2C
+#define PM_INFO_VF610_GPC_P_OFFSET		0x30
+#define PM_INFO_VF610_GPC_V_OFFSET		0x34
+#define PM_INFO_VF610_SRC_P_OFFSET		0x38
+#define PM_INFO_VF610_SRC_V_OFFSET		0x3C
+#define PM_INFO_VF610_DDRMC_P_OFFSET		0x40
+#define PM_INFO_VF610_DDRMC_V_OFFSET		0x44
+#define PM_INFO_VF610_IOMUXC_P_OFFSET		0x48
+#define PM_INFO_VF610_IOMUXC_V_OFFSET		0x4c
+#define PM_INFO_VF610_L2_P_OFFSET		0x50
+#define PM_INFO_VF610_L2_V_OFFSET		0x54
+#define PM_INFO_CCM_CACRR			0x58
+#define PM_INFO_CCM_CCSR			0x5c
+#define PM_INFO_DDRMC_IO_NUM_OFFSET		0x60
+#define PM_INFO_DDRMC_IO_VAL_OFFSET		0x64
+#define PM_INFO_IOMUXC_DDR_IO_NUM_OFFSET	(0x64 + 94 * 2 * 4)
+#define PM_INFO_IOMUXC_DDR_IO_VAL_OFFSET	(0x68 + 94 * 2 * 4)
+
+#define VF610_ANADIG_PLL2_CTRL			0x30
+
+#define VF610_ANADIG_MISC0			0x150
+#define VF610_ANADIG_MISC0_CLK_24M_IRC_XTAL_SEL	(0x1 < 13)
+
+#define VF610_ANADIG_PLL1_CTRL			0x270
+
+#define VF610_ANADIG_POWERDOWN			(1 << 12)
+#define VF610_ANADIG_ENABLE			(1 << 13)
+#define VF610_ANADIG_BYPASS			(1 << 16)
+#define VF610_ANADIG_LOCK			(1 << 31)
+
+#define VF610_SCSC_SIRC				0x0
+#define VF610_SCSC_SIRC_SIRC_EN			(0x1 << 0)
+#define VF610_SCSC_SOSC				0x4
+#define VF610_SCSC_SOSC_SOSC_EN			(0x1 << 0)
+
+#define VF610_GPC_PGCR				0x0
+#define VF610_GPC_LPMR				0x40
+
+#define VF610_CCM_CCR				0x00
+#define VF610_CCM_CCR_FXOSC_EN			(0x1 << 12)
+
+#define VF610_CCM_CCSR				0x08
+#define VF610_CCM_CCSR_DDRC_CLK_SEL		(0x1 << 6)
+#define VF610_CCM_CCSR_FAST_CLK_SEL		(0x1 << 5)
+
+#define VF610_CCM_CACRR				0x0C
+
+#define VF610_CCM_CLPCR				0x2C
+#define VF610_CCM_CLPCR_DIS_REF_OSC		(0x1 << 7)
+#define VF610_CCM_CLPCR_FXOSC_PWRDWN		(0x1 << 11)
+
+#define VF610_CCM_CCGR0				0x40
+#define VF610_CCM_CCGR2				0x48
+#define VF610_CCM_CCGR3				0x4C
+#define VF610_CCM_CCGR4				0x50
+#define VF610_CCM_CCGR6				0x58
+
+#define VF610_SRC_GPR0				0x20
+#define VF610_SRC_GPR1				0x24
+#define VF610_SRC_MISC2				0x54
+
+#define VF610_DDRMC_CR00			0x0
+#define VF610_DDRMC_CR00_START			(0x1 << 0)
+
+#define VF610_DDRMC_CR33			0x84
+#define VF610_DDRMC_CR33_PWUP_SREF_EX		(0x1 << 0)
+
+#define VF610_DDRMC_CR34			0x88
+
+#define VF610_DDRMC_CR35			0x8C
+#define VF610_DDRMC_CR35_LP_CMD(cmd)		((cmd) << 8)
+
+#define VF610_DDRMC_CR80			0x140
+#define VF610_DDRMC_CR80_LP_COMPLETE		(0x1 << 9)
+#define VF610_DDRMC_CR80_INIT_COMPLETE		(0x1 << 8)
+#define VF610_DDRMC_CR81			0x144
+
+	.align 3
+
+	/*
+	 * Take DDR RAM out of Low-Power mode
+	 */
+	.macro resume_ddrmc ddrmc_base
+
+	/* Clear low power complete flag... */
+	ldr	r6, =VF610_DDRMC_CR80_LP_COMPLETE
+	str	r6, [\ddrmc_base, #VF610_DDRMC_CR81]
+
+	ldr	r6, [\ddrmc_base, #VF610_DDRMC_CR35]
+	orr	r6, r6, #VF610_DDRMC_CR35_LP_CMD(0x9)
+	str	r6, [\ddrmc_base, #VF610_DDRMC_CR35]
+
+1:
+	ldr	r5, [\ddrmc_base, #VF610_DDRMC_CR80]
+	ands 	r5, r5, #VF610_DDRMC_CR80_LP_COMPLETE
+	beq	1b
+
+	.endm
+
+	.macro enable_syspll pll_base
+
+	ldr	r5, [\pll_base]
+	orr	r5, r5, #VF610_ANADIG_ENABLE
+	bic	r5, r5, #VF610_ANADIG_POWERDOWN
+	bic	r5, r5, #VF610_ANADIG_BYPASS
+	str	r5, [\pll_base]
+
+1:
+	ldr	r5, [\pll_base]
+	tst 	r5, #VF610_ANADIG_LOCK
+	beq	1b
+
+	.endm
+
+ENTRY(vf610_suspend)
+	ldr	r1, [r0, #PM_INFO_PBASE_OFFSET]
+	ldr	r2, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+	ldr	r3, [r0, #PM_INFO_CPU_TYPE_OFFSET]
+	ldr	r4, [r0, #PM_INFO_PM_INFO_SIZE_OFFSET]
+
+	/*
+	 * make sure TLB contain the addr we want,
+	 * as we will access them after DDRMC IO floated.
+	 */
+
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+	ldr	r11, [r0, #PM_INFO_VF610_GPC_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+	ldr	r11, [r0, #PM_INFO_VF610_SRC_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_V_OFFSET]
+	ldr	r6, [r11, #0x0]
+
+	ldr	r11, [r0, #PM_INFO_VF610_SRC_V_OFFSET]
+
+	/* Disable DDR RESET */
+	ldr	r6, [r11, #VF610_SRC_MISC2]
+	orr	r6, r6, #0x1
+	str	r6, [r11, #VF610_SRC_MISC2]
+
+	/* Set ENTRY/ARGUMENT register */
+	ldr	r6, =vf610_suspend
+	ldr	r7, =resume
+	sub	r7, r7, r6
+	add	r8, r1, r4
+	add	r9, r8, r7
+	str	r9, [r11, #VF610_SRC_GPR0]
+	str	r1, [r11, #VF610_SRC_GPR1]
+
+	/* Put memory in self refresh... */
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_V_OFFSET]
+
+	ldr	r6, =VF610_DDRMC_CR80_LP_COMPLETE
+	str	r6, [r11, #VF610_DDRMC_CR81]
+
+	ldr	r6, [r11, #VF610_DDRMC_CR35]
+	orr	r6, r6, #VF610_DDRMC_CR35_LP_CMD(0xA)
+	str	r6, [r11, #VF610_DDRMC_CR35]
+
+ddrmc_cmd_complete:
+	/* Hardware without CKE/RESET fixes seems to hang@this read.... */
+	ldr	r5, [r11, #VF610_DDRMC_CR80]
+	ands 	r5, r5, #VF610_DDRMC_CR80_LP_COMPLETE
+	beq	ddrmc_cmd_complete
+
+	/* switch to internal FIRC */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_V_OFFSET]
+	ldr	r5, [r11, #VF610_CCM_CCSR]
+	bic	r5, r5, #0x30 /* FAST_/SLOW_CLK_SEL */
+	str	r5, [r11, #VF610_CCM_CCSR]
+	bic	r5, r5, #0x07 /* SYS_CLK_SEL */
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	/* LP-Mode: STOP */
+	ldr	r11, [r0, #PM_INFO_VF610_GPC_V_OFFSET]
+	ldr	r6, =0x02
+	str	r6, [r11, #VF610_GPC_LPMR]
+
+	/* Zzz, enter stop mode */
+	wfi
+	nop
+	nop
+	nop
+	nop
+
+	/* If we get here, there is already an interrupt pending. Restore... */
+	ldr	r6, =0x00
+	str	r6, [r11, #VF610_GPC_LPMR]
+
+	/* Get previous CCSR/CACRR settings */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_V_OFFSET]
+	ldr	r5, [r0, #PM_INFO_CCM_CCSR]
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	ldr	r5, [r0, #PM_INFO_CCM_CACRR]
+	str	r5, [r11, #VF610_CCM_CACRR]
+
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_V_OFFSET]
+	resume_ddrmc r11
+
+	ret	lr
+
+/* Resume path if CPU uses the SRC_GPR0 (PERSISTENT_ENTRY0) */
+resume:
+	/* invalidate L1 I-cache first */
+	mov     r6, #0x0
+	mcr     p15, 0, r6, c7, c5, 0
+	mcr     p15, 0, r6, c7, c5, 6
+
+	/* enable the Icache and branch prediction */
+	mov     r6, #0x1800
+	mcr     p15, 0, r6, c1, c0, 0
+	isb
+
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_P_OFFSET]
+
+	ldr	r5, [r11, #VF610_CCM_CCSR]
+	orr	r5, r5, #(1 << 13)
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	/* enable IOMUX, PORT A-E */
+	ldr	r5, [r11, #VF610_CCM_CCGR2]
+	ldr	r6, =0xfff0000
+	orr	r5, r5, r6
+	str	r5, [r11, #VF610_CCM_CCGR2]
+
+	/* enable ANADIG and SCSM */
+	ldr	r5, [r11, #VF610_CCM_CCGR3]
+	orr	r5, r5, #0x33
+	str	r5, [r11, #VF610_CCM_CCGR3]
+
+	/* enable GPC, CCM and WKUP */
+	ldr	r5, [r11, #VF610_CCM_CCGR4]
+	orr	r5, r5, #0x3f00000
+	str	r5, [r11, #VF610_CCM_CCGR4]
+
+	/* enable DDRMC */
+	ldr	r5, [r11, #VF610_CCM_CCGR6]
+	orr	r5, r5, #0x30000000
+	str	r5, [r11, #VF610_CCM_CCGR6]
+
+#ifdef DEBUG
+	/* enable UART0 */
+	ldr	r5, [r11, #VF610_CCM_CCGR0]
+	orr	r5, r5, #0xC000
+	str	r5, [r11, #VF610_CCM_CCGR0]
+
+	/* Mux UART0 */
+	ldr	r5,=0x1021a2
+	ldr	r6,=0x40048080
+	str	r5, [r6, #0x0]
+	ldr	r5,=0x1021a1
+	ldr	r6,=0x40048084
+	str	r5, [r6, #0x0]
+#endif
+
+	/* Set IOMUX for DDR pads */
+	ldr	r11, [r0, #PM_INFO_VF610_IOMUXC_P_OFFSET]
+
+	ldr	r6, [r0, #PM_INFO_IOMUXC_DDR_IO_NUM_OFFSET]
+	ldr	r7, =PM_INFO_IOMUXC_DDR_IO_VAL_OFFSET
+	add	r7, r7, r0
+
+loop_iomuxc_ddr_restore:
+	ldr	r8, [r7], #0x4
+	ldr	r9, [r7], #0x4
+	str	r9, [r11, r8]
+	subs	r6, r6, #0x1
+	bne	loop_iomuxc_ddr_restore
+
+
+	/* Enable slow oscilators */
+	ldr	r11, [r0, #PM_INFO_VF610_SCSC_P_OFFSET]
+
+	ldr	r5, [r11, #VF610_SCSC_SOSC]
+	orr	r5, r5, #VF610_SCSC_SOSC_SOSC_EN
+	str	r5, [r11, #VF610_SCSC_SOSC]
+
+	ldr	r5, [r11, #VF610_SCSC_SIRC]
+	orr	r5, r5, #VF610_SCSC_SIRC_SIRC_EN
+	str	r5, [r11, #VF610_SCSC_SIRC]
+
+	/* Enable fast osciallator */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_P_OFFSET]
+
+	ldr	r5, [r11, #VF610_CCM_CLPCR]
+	bic	r5, r5, #VF610_CCM_CLPCR_DIS_REF_OSC
+	bic	r5, r5, #VF610_CCM_CLPCR_FXOSC_PWRDWN
+	str	r5, [r11, #VF610_CCM_CLPCR]
+
+	ldr	r5, [r11, #VF610_CCM_CCR]
+	orr	r5, r5, #VF610_CCM_CCR_FXOSC_EN
+	str	r5, [r11, #VF610_CCM_CCR]
+
+	ldr	r5, [r11, #VF610_CCM_CCSR]
+	orr	r5, r5, #VF610_CCM_CCSR_FAST_CLK_SEL
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	ldr	r11, [r0, #PM_INFO_VF610_ANATOP_P_OFFSET]
+
+	/* Select external FXOSC */
+	ldr	r5, [r11, #VF610_ANADIG_MISC0]
+	bic	r5, r5, #VF610_ANADIG_MISC0_CLK_24M_IRC_XTAL_SEL
+	str	r5, [r11, #VF610_ANADIG_MISC0]
+
+	add	r6, r11, #VF610_ANADIG_PLL1_CTRL
+	enable_syspll r6
+
+	/* enable pll2 only if required for DDR */
+	ldr	r5, [r0, #PM_INFO_CCM_CCSR]
+	tst 	r5, #VF610_CCM_CCSR_DDRC_CLK_SEL
+	bne	switch_sysclk
+
+	add	r6, r11, #VF610_ANADIG_PLL2_CTRL
+	enable_syspll r6
+
+switch_sysclk:
+
+	/* Enable PFD and switch to fast clock */
+	ldr	r11, [r0, #PM_INFO_VF610_CCM_P_OFFSET]
+
+	/* Get previous CCSR/CACRR settings */
+	ldr	r5, [r0, #PM_INFO_CCM_CCSR]
+	str	r5, [r11, #VF610_CCM_CCSR]
+
+	ldr	r5, [r0, #PM_INFO_CCM_CACRR]
+	str	r5, [r11, #VF610_CCM_CACRR]
+
+	/* Restore memory configuration */
+	ldr	r11, [r0, #PM_INFO_VF610_DDRMC_P_OFFSET]
+
+	ldr	r6, [r0, #PM_INFO_DDRMC_IO_NUM_OFFSET]
+	ldr	r7, =PM_INFO_DDRMC_IO_VAL_OFFSET
+	add	r7, r7, r0
+
+	/* Clear start bit of first memory register, do not start yet... */
+	ldr	r8, [r7], #0x4
+	ldr	r9, [r7], #0x4
+	bic	r9, r9, #VF610_DDRMC_CR00_START
+	str	r9, [r11, r8]
+	subs	r6, r6, #0x1
+
+loop_ddrmc_restore:
+	ldr	r8, [r7], #0x4
+	ldr	r9, [r7], #0x4
+	str	r9, [r11, r8]
+	subs	r6, r6, #0x1
+	bne	loop_ddrmc_restore
+
+	/* Set PWUP_SREF_EX to avoid a full memory initialization */
+	ldr	r6, [r11, #VF610_DDRMC_CR33]
+	orr	r6, r6, #VF610_DDRMC_CR33_PWUP_SREF_EX
+	str	r6, [r11, #VF610_DDRMC_CR33]
+
+	/* Start initialization */
+	ldr	r6, =VF610_DDRMC_CR80_INIT_COMPLETE
+	str	r6, [r11, #VF610_DDRMC_CR81]
+
+	ldr	r6, [r11, #VF610_DDRMC_CR00]
+	orr	r6, r6, #VF610_DDRMC_CR00_START
+	str	r6, [r11, #VF610_DDRMC_CR00]
+
+ddrmc_initializing:
+	ldr	r5, [r11, #VF610_DDRMC_CR80]
+	ands 	r5, r5, #VF610_DDRMC_CR80_INIT_COMPLETE
+	beq	ddrmc_initializing
+
+	resume_ddrmc r11
+
+	/* LP-Mode: RUN */
+	ldr	r11, [r0, #PM_INFO_VF610_GPC_P_OFFSET]
+	ldr	r5, =0x0
+	str	r5, [r11, #VF610_GPC_LPMR]
+
+	/* get physical resume address from pm_info. */
+	ldr	lr, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
+
+	ret	lr
+ENDPROC(vf610_suspend)
+
diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
index 170a96c..27d4cf0 100644
--- a/drivers/clk/imx/clk-vf610.c
+++ b/drivers/clk/imx/clk-vf610.c
@@ -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);
 
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 16/18] ARM: vf610: PM: enable Suspend-to-RAM only if hardware fixes are in place
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/mach-imx/pm-vf610.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/pm-vf610.c b/arch/arm/mach-imx/pm-vf610.c
index ecc7c9c..3da93e9 100644
--- a/arch/arm/mach-imx/pm-vf610.c
+++ b/arch/arm/mach-imx/pm-vf610.c
@@ -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");
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 16/18] ARM: vf610: PM: enable Suspend-to-RAM only if hardware fixes are in place
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/mach-imx/pm-vf610.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/pm-vf610.c b/arch/arm/mach-imx/pm-vf610.c
index ecc7c9c..3da93e9 100644
--- a/arch/arm/mach-imx/pm-vf610.c
+++ b/arch/arm/mach-imx/pm-vf610.c
@@ -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");
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 17/18] Documentation: dt: add Vybrid DDR memory controller bindings
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 .../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

diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
new file mode 100644
index 0000000..56a71d6
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
@@ -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@400ae000 {
+		compatible = "fsl,vf610-ddrmc";
+		reg = <0x400ae000 0x1000>;
+		clocks = <&clks VF610_CLK_DDRMC>;
+		clock-names = "ddrc";
+		fsl,has-cke-reset-pulls;
+	}
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 17/18] Documentation: dt: add Vybrid DDR memory controller bindings
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo-DgEjT+Ai2ygdnm+yROfE0A,
	mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, sergeimir-qv+LCo8X3VpBDgjK7y7TUQ,
	tglx-hfZtesqFncYOwBW4kG4KsQ, jason-NLaQJdtUoK4Be96aLqz0jA,
	marc.zyngier-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, mark.rutland-5wv7dgnIgG8,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA, 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.

Signed-off-by: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
---
 .../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

diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
new file mode 100644
index 0000000..56a71d6
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
@@ -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@400ae000 {
+		compatible = "fsl,vf610-ddrmc";
+		reg = <0x400ae000 0x1000>;
+		clocks = <&clks VF610_CLK_DDRMC>;
+		clock-names = "ddrc";
+		fsl,has-cke-reset-pulls;
+	}
-- 
2.7.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 17/18] Documentation: dt: add Vybrid DDR memory controller bindings
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 .../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

diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
new file mode 100644
index 0000000..56a71d6
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
@@ -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;
+	}
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 18/18] ARM: vf610: PM: enable SNVS access
  2016-03-10  2:16 ` Stefan Agner
@ 2016-03-10  2:16   ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: shawnguo, mturquette, sboyd
  Cc: kernel, sergeimir, tglx, jason, marc.zyngier, robh+dt,
	pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, 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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/mach-imx/suspend-vf610.S | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/mach-imx/suspend-vf610.S b/arch/arm/mach-imx/suspend-vf610.S
index 09ad246..6df0622 100644
--- a/arch/arm/mach-imx/suspend-vf610.S
+++ b/arch/arm/mach-imx/suspend-vf610.S
@@ -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]
 
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* [PATCH 18/18] ARM: vf610: PM: enable SNVS access
@ 2016-03-10  2:16   ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-10  2:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 arch/arm/mach-imx/suspend-vf610.S | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/mach-imx/suspend-vf610.S b/arch/arm/mach-imx/suspend-vf610.S
index 09ad246..6df0622 100644
--- a/arch/arm/mach-imx/suspend-vf610.S
+++ b/arch/arm/mach-imx/suspend-vf610.S
@@ -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]
 
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 96+ messages in thread

* Re: [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
  2016-03-10  2:16   ` Stefan Agner
  (?)
@ 2016-03-10 21:19     ` kbuild test robot
  -1 siblings, 0 replies; 96+ messages in thread
From: kbuild test robot @ 2016-03-10 21:19 UTC (permalink / raw)
  To: Stefan Agner
  Cc: kbuild-all, shawnguo, mturquette, sboyd, kernel, sergeimir, tglx,
	jason, marc.zyngier, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk, Stefan Agner

[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]

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

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 7259 bytes --]

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
@ 2016-03-10 21:19     ` kbuild test robot
  0 siblings, 0 replies; 96+ messages in thread
From: kbuild test robot @ 2016-03-10 21:19 UTC (permalink / raw)
  Cc: kbuild-all, shawnguo, mturquette, sboyd, kernel, sergeimir, tglx,
	jason, marc.zyngier, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk, Stefan Agner

[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]

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

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 7259 bytes --]

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
@ 2016-03-10 21:19     ` kbuild test robot
  0 siblings, 0 replies; 96+ messages in thread
From: kbuild test robot @ 2016-03-10 21:19 UTC (permalink / raw)
  To: linux-arm-kernel

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>

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-11  3:41     ` Marc Zyngier
  0 siblings, 0 replies; 96+ messages in thread
From: Marc Zyngier @ 2016-03-11  3:41 UTC (permalink / raw)
  To: Stefan Agner
  Cc: shawnguo, mturquette, sboyd, kernel, sergeimir, tglx, jason,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed,  9 Mar 2016 18:16:42 -0800
Stefan Agner <stefan@agner.ch> wrote:

Hi Stefan,

> 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).
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  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
> 
> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> index 18caacb..0a77ac6 100644
> --- a/drivers/irqchip/Makefile
> +++ b/drivers/irqchip/Makefile
> @@ -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
> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
> new file mode 100644
> index 0000000..2c6a043
> --- /dev/null
> +++ b/drivers/irqchip/irq-vf610-gpc.c
> @@ -0,0 +1,138 @@
> +/*
> + * Copyright (C) 2016 Toradex AG
> + * Author: Stefan Agner <stefan@agner.ch>
> + *
> + * 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",
> +	.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.

> +	.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,
> +					      &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?

> +	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;
> +	}
> +
> +	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...

> +
> +	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);

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

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-11  3:41     ` Marc Zyngier
  0 siblings, 0 replies; 96+ messages in thread
From: Marc Zyngier @ 2016-03-11  3:41 UTC (permalink / raw)
  To: Stefan Agner
  Cc: shawnguo-DgEjT+Ai2ygdnm+yROfE0A,
	mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ, sergeimir-qv+LCo8X3VpBDgjK7y7TUQ,
	tglx-hfZtesqFncYOwBW4kG4KsQ, jason-NLaQJdtUoK4Be96aLqz0jA,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA

On Wed,  9 Mar 2016 18:16:42 -0800
Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org> wrote:

Hi Stefan,

> 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).
> 
> Signed-off-by: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
> ---
>  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
> 
> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> index 18caacb..0a77ac6 100644
> --- a/drivers/irqchip/Makefile
> +++ b/drivers/irqchip/Makefile
> @@ -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
> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
> new file mode 100644
> index 0000000..2c6a043
> --- /dev/null
> +++ b/drivers/irqchip/irq-vf610-gpc.c
> @@ -0,0 +1,138 @@
> +/*
> + * Copyright (C) 2016 Toradex AG
> + * Author: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
> + *
> + * 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",
> +	.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.

> +	.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,
> +					      &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?

> +	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;
> +	}
> +
> +	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...

> +
> +	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);

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

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-11  3:41     ` Marc Zyngier
  0 siblings, 0 replies; 96+ messages in thread
From: Marc Zyngier @ 2016-03-11  3:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed,  9 Mar 2016 18:16:42 -0800
Stefan Agner <stefan@agner.ch> wrote:

Hi Stefan,

> 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).
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  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
> 
> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> index 18caacb..0a77ac6 100644
> --- a/drivers/irqchip/Makefile
> +++ b/drivers/irqchip/Makefile
> @@ -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
> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
> new file mode 100644
> index 0000000..2c6a043
> --- /dev/null
> +++ b/drivers/irqchip/irq-vf610-gpc.c
> @@ -0,0 +1,138 @@
> +/*
> + * Copyright (C) 2016 Toradex AG
> + * Author: Stefan Agner <stefan@agner.ch>
> + *
> + * 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",
> +	.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.

> +	.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,
> +					      &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?

> +	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;
> +	}
> +
> +	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...

> +
> +	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);

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

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
  2016-03-11  3:41     ` Marc Zyngier
  (?)
@ 2016-03-11 18:11       ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-11 18:11 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: shawnguo, mturquette, sboyd, kernel, sergeimir, tglx, jason,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

Hi Marc,

On 2016-03-10 19:41, Marc Zyngier wrote:
> On Wed,  9 Mar 2016 18:16:42 -0800
> Stefan Agner <stefan@agner.ch> wrote:
> 
> Hi Stefan,
> 
>> 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).
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
>> ---
>>  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
>>
>> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
>> index 18caacb..0a77ac6 100644
>> --- a/drivers/irqchip/Makefile
>> +++ b/drivers/irqchip/Makefile
>> @@ -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
>> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
>> new file mode 100644
>> index 0000000..2c6a043
>> --- /dev/null
>> +++ b/drivers/irqchip/irq-vf610-gpc.c
>> @@ -0,0 +1,138 @@
>> +/*
>> + * Copyright (C) 2016 Toradex AG
>> + * Author: Stefan Agner <stefan@agner.ch>
>> + *
>> + * 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",
>> +	.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).

> 
>> +	.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,
>> +					      &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)

> 
>> +	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;
>> +	}
>> +
>> +	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);

>> +
>> +	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);
> 
> It would be good to have some binding documentation as well.

Will add that

Thanks!

--
Stefan

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-11 18:11       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-11 18:11 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: mark.rutland, devicetree, jason, pawel.moll, ijc+devicetree,
	mturquette, sboyd, linux-kernel, robh+dt, sergeimir, kernel,
	galak, tglx, shawnguo, linux-clk, linux-arm-kernel

Hi Marc,

On 2016-03-10 19:41, Marc Zyngier wrote:
> On Wed,  9 Mar 2016 18:16:42 -0800
> Stefan Agner <stefan@agner.ch> wrote:
> 
> Hi Stefan,
> 
>> 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).
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
>> ---
>>  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
>>
>> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
>> index 18caacb..0a77ac6 100644
>> --- a/drivers/irqchip/Makefile
>> +++ b/drivers/irqchip/Makefile
>> @@ -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
>> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
>> new file mode 100644
>> index 0000000..2c6a043
>> --- /dev/null
>> +++ b/drivers/irqchip/irq-vf610-gpc.c
>> @@ -0,0 +1,138 @@
>> +/*
>> + * Copyright (C) 2016 Toradex AG
>> + * Author: Stefan Agner <stefan@agner.ch>
>> + *
>> + * 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",
>> +	.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).

> 
>> +	.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,
>> +					      &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)

> 
>> +	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;
>> +	}
>> +
>> +	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);

>> +
>> +	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);
> 
> It would be good to have some binding documentation as well.

Will add that

Thanks!

--
Stefan

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-11 18:11       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-11 18:11 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc,

On 2016-03-10 19:41, Marc Zyngier wrote:
> On Wed,  9 Mar 2016 18:16:42 -0800
> Stefan Agner <stefan@agner.ch> wrote:
> 
> Hi Stefan,
> 
>> 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).
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
>> ---
>>  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
>>
>> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
>> index 18caacb..0a77ac6 100644
>> --- a/drivers/irqchip/Makefile
>> +++ b/drivers/irqchip/Makefile
>> @@ -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
>> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
>> new file mode 100644
>> index 0000000..2c6a043
>> --- /dev/null
>> +++ b/drivers/irqchip/irq-vf610-gpc.c
>> @@ -0,0 +1,138 @@
>> +/*
>> + * Copyright (C) 2016 Toradex AG
>> + * Author: Stefan Agner <stefan@agner.ch>
>> + *
>> + * 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",
>> +	.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).

> 
>> +	.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,
>> +					      &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)

> 
>> +	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;
>> +	}
>> +
>> +	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);

>> +
>> +	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);
> 
> It would be good to have some binding documentation as well.

Will add that

Thanks!

--
Stefan

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
  2016-03-11 18:11       ` Stefan Agner
@ 2016-03-12  0:21         ` Marc Zyngier
  -1 siblings, 0 replies; 96+ messages in thread
From: Marc Zyngier @ 2016-03-12  0:21 UTC (permalink / raw)
  To: Stefan Agner
  Cc: shawnguo, mturquette, sboyd, kernel, sergeimir, tglx, jason,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Fri, 11 Mar 2016 10:11:43 -0800
Stefan Agner <stefan@agner.ch> wrote:

> Hi Marc,
> 
> On 2016-03-10 19:41, Marc Zyngier wrote:
> > On Wed,  9 Mar 2016 18:16:42 -0800
> > Stefan Agner <stefan@agner.ch> wrote:
> > 
> > Hi Stefan,
> > 
> >> 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).
> >>
> >> Signed-off-by: Stefan Agner <stefan@agner.ch>
> >> ---
> >>  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
> >>
> >> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> >> index 18caacb..0a77ac6 100644
> >> --- a/drivers/irqchip/Makefile
> >> +++ b/drivers/irqchip/Makefile
> >> @@ -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
> >> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
> >> new file mode 100644
> >> index 0000000..2c6a043
> >> --- /dev/null
> >> +++ b/drivers/irqchip/irq-vf610-gpc.c
> >> @@ -0,0 +1,138 @@
> >> +/*
> >> + * Copyright (C) 2016 Toradex AG
> >> + * Author: Stefan Agner <stefan@agner.ch>
> >> + *
> >> + * 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",
> >> +	.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).
> 
> > 
> >> +	.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,
> >> +					      &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)
> 

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.
-- 
Jazz is not dead. It just smells funny.

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-12  0:21         ` Marc Zyngier
  0 siblings, 0 replies; 96+ messages in thread
From: Marc Zyngier @ 2016-03-12  0:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, 11 Mar 2016 10:11:43 -0800
Stefan Agner <stefan@agner.ch> wrote:

> Hi Marc,
> 
> On 2016-03-10 19:41, Marc Zyngier wrote:
> > On Wed,  9 Mar 2016 18:16:42 -0800
> > Stefan Agner <stefan@agner.ch> wrote:
> > 
> > Hi Stefan,
> > 
> >> 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).
> >>
> >> Signed-off-by: Stefan Agner <stefan@agner.ch>
> >> ---
> >>  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
> >>
> >> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> >> index 18caacb..0a77ac6 100644
> >> --- a/drivers/irqchip/Makefile
> >> +++ b/drivers/irqchip/Makefile
> >> @@ -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
> >> diff --git a/drivers/irqchip/irq-vf610-gpc.c b/drivers/irqchip/irq-vf610-gpc.c
> >> new file mode 100644
> >> index 0000000..2c6a043
> >> --- /dev/null
> >> +++ b/drivers/irqchip/irq-vf610-gpc.c
> >> @@ -0,0 +1,138 @@
> >> +/*
> >> + * Copyright (C) 2016 Toradex AG
> >> + * Author: Stefan Agner <stefan@agner.ch>
> >> + *
> >> + * 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",
> >> +	.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).
> 
> > 
> >> +	.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,
> >> +					      &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)
> 

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.
-- 
Jazz is not dead. It just smells funny.

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 08/18] ARM: clk: add WKPU unit
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-16  1:13     ` Stephen Boyd
  -1 siblings, 0 replies; 96+ messages in thread
From: Stephen Boyd @ 2016-03-16  1:13 UTC (permalink / raw)
  To: Stefan Agner
  Cc: shawnguo, mturquette, kernel, sergeimir, tglx, jason,
	marc.zyngier, robh+dt, pawel.moll, mark.rutland, ijc+devicetree,
	galak, devicetree, linux-arm-kernel, linux-kernel, linux-clk

On 03/09, Stefan Agner wrote:
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---

Acked-by: Stephen Boyd <sboyd@codeaurora.org>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 08/18] ARM: clk: add WKPU unit
@ 2016-03-16  1:13     ` Stephen Boyd
  0 siblings, 0 replies; 96+ messages in thread
From: Stephen Boyd @ 2016-03-16  1:13 UTC (permalink / raw)
  To: linux-arm-kernel

On 03/09, Stefan Agner wrote:
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---

Acked-by: Stephen Boyd <sboyd@codeaurora.org>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 14/18] gpio: vf610: add support for WKPU unit
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-17 20:00     ` Rob Herring
  -1 siblings, 0 replies; 96+ messages in thread
From: Rob Herring @ 2016-03-17 20:00 UTC (permalink / raw)
  To: Stefan Agner
  Cc: shawnguo, mturquette, sboyd, kernel, sergeimir, tglx, jason,
	marc.zyngier, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:55PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
>  drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
>  2 files changed, 157 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
> index 436cc99..985ddfd 100644
> --- a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
> +++ b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
> @@ -22,6 +22,12 @@ Required properties for GPIO node:
>        4 = active high level-sensitive.
>        8 = active low level-sensitive.
>  
> +Option properties:

Optional

> +- fsl,gpio-wakeup : map GPIOs to WKPU unit, 3 argument cells per phandle

phandle to what?

> +      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#>

> +
>  Note: Each GPIO port should have an alias correctly numbered in "aliases"
>  node.
>  
> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
> index 1a022be..650a41a 100644
> --- a/drivers/gpio/gpio-vf610.c
> +++ b/drivers/gpio/gpio-vf610.c

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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 14/18] gpio: vf610: add support for WKPU unit
@ 2016-03-17 20:00     ` Rob Herring
  0 siblings, 0 replies; 96+ messages in thread
From: Rob Herring @ 2016-03-17 20:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:55PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
>  drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
>  2 files changed, 157 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
> index 436cc99..985ddfd 100644
> --- a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
> +++ b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
> @@ -22,6 +22,12 @@ Required properties for GPIO node:
>        4 = active high level-sensitive.
>        8 = active low level-sensitive.
>  
> +Option properties:

Optional

> +- fsl,gpio-wakeup : map GPIOs to WKPU unit, 3 argument cells per phandle

phandle to what?

> +      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#>

> +
>  Note: Each GPIO port should have an alias correctly numbered in "aliases"
>  node.
>  
> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
> index 1a022be..650a41a 100644
> --- a/drivers/gpio/gpio-vf610.c
> +++ b/drivers/gpio/gpio-vf610.c

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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 14/18] gpio: vf610: add support for WKPU unit
  2016-03-17 20:00     ` Rob Herring
@ 2016-03-17 22:12       ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-17 22:12 UTC (permalink / raw)
  To: Rob Herring
  Cc: shawnguo, mturquette, sboyd, kernel, sergeimir, tglx, jason,
	marc.zyngier, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

Hi Rob,

On 2016-03-17 13:00, Rob Herring wrote:
> On Wed, Mar 09, 2016 at 06:16:55PM -0800, Stefan Agner wrote:
>> 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.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
>> ---
>>  .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
>>  drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
>>  2 files changed, 157 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
>> index 436cc99..985ddfd 100644
>> --- a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
>> +++ b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
>> @@ -22,6 +22,12 @@ Required properties for GPIO node:
>>        4 = active high level-sensitive.
>>        8 = active low level-sensitive.
>>
>> +Option properties:
> 
> Optional
> 
>> +- fsl,gpio-wakeup : map GPIOs to WKPU unit, 3 argument cells per phandle
> 
> phandle to what?
> 
>> +      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#>
> 

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


>> +
>>  Note: Each GPIO port should have an alias correctly numbered in "aliases"
>>  node.
>>
>> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
>> index 1a022be..650a41a 100644
>> --- a/drivers/gpio/gpio-vf610.c
>> +++ b/drivers/gpio/gpio-vf610.c
> 
> 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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 14/18] gpio: vf610: add support for WKPU unit
@ 2016-03-17 22:12       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-17 22:12 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Rob,

On 2016-03-17 13:00, Rob Herring wrote:
> On Wed, Mar 09, 2016 at 06:16:55PM -0800, Stefan Agner wrote:
>> 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.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
>> ---
>>  .../devicetree/bindings/gpio/gpio-vf610.txt        |   6 +
>>  drivers/gpio/gpio-vf610.c                          | 151 +++++++++++++++++++++
>>  2 files changed, 157 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
>> index 436cc99..985ddfd 100644
>> --- a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
>> +++ b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt
>> @@ -22,6 +22,12 @@ Required properties for GPIO node:
>>        4 = active high level-sensitive.
>>        8 = active low level-sensitive.
>>
>> +Option properties:
> 
> Optional
> 
>> +- fsl,gpio-wakeup : map GPIOs to WKPU unit, 3 argument cells per phandle
> 
> phandle to what?
> 
>> +      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#>
> 

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


>> +
>>  Note: Each GPIO port should have an alias correctly numbered in "aliases"
>>  node.
>>
>> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
>> index 1a022be..650a41a 100644
>> --- a/drivers/gpio/gpio-vf610.c
>> +++ b/drivers/gpio/gpio-vf610.c
> 
> 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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 17/18] Documentation: dt: add Vybrid DDR memory controller bindings
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-18 16:10     ` Rob Herring
  -1 siblings, 0 replies; 96+ messages in thread
From: Rob Herring @ 2016-03-18 16:10 UTC (permalink / raw)
  To: Stefan Agner
  Cc: shawnguo, mturquette, sboyd, kernel, sergeimir, tglx, jason,
	marc.zyngier, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:58PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  .../bindings/arm/freescale/fsl,vf610-ddrmc.txt     | 23 ++++++++++++++++++++++

Move to bindings/memory-controllers/

>  1 file changed, 23 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
> 
> diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
> new file mode 100644
> index 0000000..56a71d6
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
> @@ -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@400ae000 {

memory-controller@...

> +		compatible = "fsl,vf610-ddrmc";
> +		reg = <0x400ae000 0x1000>;
> +		clocks = <&clks VF610_CLK_DDRMC>;
> +		clock-names = "ddrc";
> +		fsl,has-cke-reset-pulls;
> +	}
> -- 
> 2.7.2
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 17/18] Documentation: dt: add Vybrid DDR memory controller bindings
@ 2016-03-18 16:10     ` Rob Herring
  0 siblings, 0 replies; 96+ messages in thread
From: Rob Herring @ 2016-03-18 16:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:58PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  .../bindings/arm/freescale/fsl,vf610-ddrmc.txt     | 23 ++++++++++++++++++++++

Move to bindings/memory-controllers/

>  1 file changed, 23 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
> 
> diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
> new file mode 100644
> index 0000000..56a71d6
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/arm/freescale/fsl,vf610-ddrmc.txt
> @@ -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 {

memory-controller at ...

> +		compatible = "fsl,vf610-ddrmc";
> +		reg = <0x400ae000 0x1000>;
> +		clocks = <&clks VF610_CLK_DDRMC>;
> +		clock-names = "ddrc";
> +		fsl,has-cke-reset-pulls;
> +	}
> -- 
> 2.7.2
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-31  8:07     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:07 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:42PM -0800, Stefan Agner wrote:
> +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;
> +	}
> +
> +	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

> +		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);
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller
@ 2016-03-31  8:07     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:07 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:42PM -0800, Stefan Agner wrote:
> +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;
> +	}
> +
> +	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

> +		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);
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-31  8:19     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:19 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:44PM -0800, Stefan Agner wrote:
> Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the
> Colibri default wakeup pin SO-DIMM 45.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

> ---
>  arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
> index 4d8b7f6..936ece6 100644
> --- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
> +++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
> @@ -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;

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

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

Shawn

> +		};
> +	};
>  };
>  
>  &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
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
@ 2016-03-31  8:19     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:19 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:44PM -0800, Stefan Agner wrote:
> Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the
> Colibri default wakeup pin SO-DIMM 45.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

> ---
>  arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
> index 4d8b7f6..936ece6 100644
> --- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
> +++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
> @@ -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;

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

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

Shawn

> +		};
> +	};
>  };
>  
>  &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
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-31  8:21     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:21 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:43PM -0800, Stefan Agner wrote:
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

Shawn

> ---
>  arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
> index 5e49fbd..909988d 100644
> --- a/arch/arm/boot/dts/vfxxx.dtsi
> +++ b/arch/arm/boot/dts/vfxxx.dtsi
> @@ -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 {
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent
@ 2016-03-31  8:21     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:43PM -0800, Stefan Agner wrote:
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

Shawn

> ---
>  arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
> index 5e49fbd..909988d 100644
> --- a/arch/arm/boot/dts/vfxxx.dtsi
> +++ b/arch/arm/boot/dts/vfxxx.dtsi
> @@ -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
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-31  8:33     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:33 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:45PM -0800, Stefan Agner wrote:
> Add Vybrids massive on-chip SRAM areas. Make use of the memory
> region functionality to denominate the retained SRAM area in
> LPSTOP2 and LPSTOP3.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

Shawn

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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM
@ 2016-03-31  8:33     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:33 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:45PM -0800, Stefan Agner wrote:
> Add Vybrids massive on-chip SRAM areas. Make use of the memory
> region functionality to denominate the retained SRAM area in
> LPSTOP2 and LPSTOP3.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

Shawn

> ---
>  arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
> index 909988d..b038ea4 100644
> --- a/arch/arm/boot/dts/vfxxx.dtsi
> +++ b/arch/arm/boot/dts/vfxxx.dtsi
> @@ -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>;
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 05/18] ARM: dts: vf610: add modules required for PM
@ 2016-03-31  8:34     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:34 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:46PM -0800, Stefan Agner wrote:
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
> index b038ea4..335f4e5 100644
> --- a/arch/arm/boot/dts/vfxxx.dtsi
> +++ b/arch/arm/boot/dts/vfxxx.dtsi
> @@ -434,6 +434,11 @@
>  				reg = <0x40050000 0x400>;
>  			};
>  
> +			scsc: scsc@40052000 {
> +				compatible = "fsl,vf610-scsc";

These new compatible strings should be documented somewhere.

Shawn

> +				reg = <0x40052000 0x1000>;
> +			};
> +
>  			usbphy0: usbphy@40050800 {
>  				compatible = "fsl,vf610-usbphy";
>  				reg = <0x40050800 0x400>;
> @@ -480,6 +485,13 @@
>  				status = "disabled";
>  			};
>  
> +			wakeup: wkpu@4006a000 {
> +				compatible = "fsl,vf610-wkpu";
> +				reg = <0x4006a000 0x1000>;
> +				interrupts = <92 IRQ_TYPE_LEVEL_HIGH>;
> +				clocks = <&clks VF610_CLK_WKPU>;
> +			};
> +
>  			clks: ccm@4006b000 {
>  				compatible = "fsl,vf610-ccm";
>  				reg = <0x4006b000 0x1000>;
> @@ -600,6 +612,13 @@
>  				status = "disabled";
>  			};
>  
> +			ddrmc: ddrmc@400ae000 {
> +				compatible = "fsl,vf610-ddrmc";
> +				reg = <0x400ae000 0x400>;
> +				clocks = <&clks VF610_CLK_DDRMC>;
> +				clock-names = "ddrc";
> +			};
> +
>  			adc1: adc@400bb000 {
>  				compatible = "fsl,vf610-adc";
>  				reg = <0x400bb000 0x1000>;
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 05/18] ARM: dts: vf610: add modules required for PM
@ 2016-03-31  8:34     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:34 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ, sergeimir-qv+LCo8X3VpBDgjK7y7TUQ,
	tglx-hfZtesqFncYOwBW4kG4KsQ, jason-NLaQJdtUoK4Be96aLqz0jA,
	marc.zyngier-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, mark.rutland-5wv7dgnIgG8,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA

On Wed, Mar 09, 2016 at 06:16:46PM -0800, Stefan Agner wrote:
> Signed-off-by: Stefan Agner <stefan-XLVq0VzYD2Y@public.gmane.org>
> ---
>  arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
> index b038ea4..335f4e5 100644
> --- a/arch/arm/boot/dts/vfxxx.dtsi
> +++ b/arch/arm/boot/dts/vfxxx.dtsi
> @@ -434,6 +434,11 @@
>  				reg = <0x40050000 0x400>;
>  			};
>  
> +			scsc: scsc@40052000 {
> +				compatible = "fsl,vf610-scsc";

These new compatible strings should be documented somewhere.

Shawn

> +				reg = <0x40052000 0x1000>;
> +			};
> +
>  			usbphy0: usbphy@40050800 {
>  				compatible = "fsl,vf610-usbphy";
>  				reg = <0x40050800 0x400>;
> @@ -480,6 +485,13 @@
>  				status = "disabled";
>  			};
>  
> +			wakeup: wkpu@4006a000 {
> +				compatible = "fsl,vf610-wkpu";
> +				reg = <0x4006a000 0x1000>;
> +				interrupts = <92 IRQ_TYPE_LEVEL_HIGH>;
> +				clocks = <&clks VF610_CLK_WKPU>;
> +			};
> +
>  			clks: ccm@4006b000 {
>  				compatible = "fsl,vf610-ccm";
>  				reg = <0x4006b000 0x1000>;
> @@ -600,6 +612,13 @@
>  				status = "disabled";
>  			};
>  
> +			ddrmc: ddrmc@400ae000 {
> +				compatible = "fsl,vf610-ddrmc";
> +				reg = <0x400ae000 0x400>;
> +				clocks = <&clks VF610_CLK_DDRMC>;
> +				clock-names = "ddrc";
> +			};
> +
>  			adc1: adc@400bb000 {
>  				compatible = "fsl,vf610-adc";
>  				reg = <0x400bb000 0x1000>;
> -- 
> 2.7.2
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 05/18] ARM: dts: vf610: add modules required for PM
@ 2016-03-31  8:34     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31  8:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:46PM -0800, Stefan Agner wrote:
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  arch/arm/boot/dts/vfxxx.dtsi | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
> index b038ea4..335f4e5 100644
> --- a/arch/arm/boot/dts/vfxxx.dtsi
> +++ b/arch/arm/boot/dts/vfxxx.dtsi
> @@ -434,6 +434,11 @@
>  				reg = <0x40050000 0x400>;
>  			};
>  
> +			scsc: scsc at 40052000 {
> +				compatible = "fsl,vf610-scsc";

These new compatible strings should be documented somewhere.

Shawn

> +				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>;
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-31 11:37     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31 11:37 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:47PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration
@ 2016-03-31 11:37     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31 11:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:47PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>

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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 09/18] ARM: vf610: clk: add suspend/resume support
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-31 11:39     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31 11:39 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:50PM -0800, Stefan Agner wrote:
> @@ -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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 09/18] ARM: vf610: clk: add suspend/resume support
@ 2016-03-31 11:39     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31 11:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:50PM -0800, Stefan Agner wrote:
> @@ -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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 10/18] tty: serial: fsl_lpuart: support suspend/resume
  2016-03-10  2:16   ` Stefan Agner
@ 2016-03-31 11:41     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31 11:41 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:51PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  drivers/clk/imx/clk-vf610.c     | 12 ++++++------

It should go to a separate patch.

Shawn

>  drivers/tty/serial/fsl_lpuart.c | 16 ++++++++++++++--
>  2 files changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
> index e2e2c43..170a96c 100644
> --- a/drivers/clk/imx/clk-vf610.c
> +++ b/drivers/clk/imx/clk-vf610.c
> @@ -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));
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index 3d79003..94e29ba 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -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);
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 10/18] tty: serial: fsl_lpuart: support suspend/resume
@ 2016-03-31 11:41     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-03-31 11:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:51PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  drivers/clk/imx/clk-vf610.c     | 12 ++++++------

It should go to a separate patch.

Shawn

>  drivers/tty/serial/fsl_lpuart.c | 16 ++++++++++++++--
>  2 files changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/clk/imx/clk-vf610.c b/drivers/clk/imx/clk-vf610.c
> index e2e2c43..170a96c 100644
> --- a/drivers/clk/imx/clk-vf610.c
> +++ b/drivers/clk/imx/clk-vf610.c
> @@ -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));
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index 3d79003..94e29ba 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -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);
> -- 
> 2.7.2
> 
> 

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent
  2016-03-31  8:21     ` Shawn Guo
@ 2016-03-31 17:53       ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:53 UTC (permalink / raw)
  To: Shawn Guo
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On 2016-03-31 01:21, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:43PM -0800, Stefan Agner wrote:
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> So this patch cannot be applied before the fsl,vf610-gpc driver gets
> landed on mainline.

Yes!

--
Stefan

>> ---
>>  arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
>> index 5e49fbd..909988d 100644
>> --- a/arch/arm/boot/dts/vfxxx.dtsi
>> +++ b/arch/arm/boot/dts/vfxxx.dtsi
>> @@ -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 {
>> --
>> 2.7.2
>>
>>

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent
@ 2016-03-31 17:53       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:53 UTC (permalink / raw)
  To: linux-arm-kernel

On 2016-03-31 01:21, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:43PM -0800, Stefan Agner wrote:
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> So this patch cannot be applied before the fsl,vf610-gpc driver gets
> landed on mainline.

Yes!

--
Stefan

>> ---
>>  arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++-
>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
>> index 5e49fbd..909988d 100644
>> --- a/arch/arm/boot/dts/vfxxx.dtsi
>> +++ b/arch/arm/boot/dts/vfxxx.dtsi
>> @@ -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
>>
>>

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
  2016-03-31  8:19     ` Shawn Guo
  (?)
@ 2016-03-31 17:55       ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:55 UTC (permalink / raw)
  To: Shawn Guo
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On 2016-03-31 01:19, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:44PM -0800, Stefan Agner wrote:
>> Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the
>> Colibri default wakeup pin SO-DIMM 45.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> 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.

>> ---
>>  arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
>>  1 file changed, 22 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> index 4d8b7f6..936ece6 100644
>> --- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> +++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> @@ -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;
> 
> Please use generic 'wakeup-source' instead.  See the following document
> for details.
> 
> Documentation/devicetree/bindings/power/wakeup-source.txt

Will do.

--
Stefan

> 
>> +		};
>> +	};
>>  };
>>
>>  &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
>>
>>

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
@ 2016-03-31 17:55       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:55 UTC (permalink / raw)
  To: Shawn Guo
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On 2016-03-31 01:19, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:44PM -0800, Stefan Agner wrote:
>> Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the
>> Colibri default wakeup pin SO-DIMM 45.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> 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.

>> ---
>>  arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
>>  1 file changed, 22 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> index 4d8b7f6..936ece6 100644
>> --- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> +++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> @@ -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;
> 
> Please use generic 'wakeup-source' instead.  See the following document
> for details.
> 
> Documentation/devicetree/bindings/power/wakeup-source.txt

Will do.

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key
@ 2016-03-31 17:55       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:55 UTC (permalink / raw)
  To: linux-arm-kernel

On 2016-03-31 01:19, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:44PM -0800, Stefan Agner wrote:
>> Enable GPIO wakeup key on Vybrid PAD 41 which is routed to the
>> Colibri default wakeup pin SO-DIMM 45.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> 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.

>> ---
>>  arch/arm/boot/dts/vf-colibri-eval-v3.dtsi | 22 ++++++++++++++++++++++
>>  1 file changed, 22 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> index 4d8b7f6..936ece6 100644
>> --- a/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> +++ b/arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
>> @@ -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;
> 
> Please use generic 'wakeup-source' instead.  See the following document
> for details.
> 
> Documentation/devicetree/bindings/power/wakeup-source.txt

Will do.

--
Stefan

> 
>> +		};
>> +	};
>>  };
>>
>>  &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
>>
>>

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM
  2016-03-31  8:33     ` Shawn Guo
@ 2016-03-31 17:57       ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:57 UTC (permalink / raw)
  To: Shawn Guo
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On 2016-03-31 01:33, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:45PM -0800, Stefan Agner wrote:
>> Add Vybrids massive on-chip SRAM areas. Make use of the memory
>> region functionality to denominate the retained SRAM area in
>> LPSTOP2 and LPSTOP3.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> This one looks fine to me.  I was going to pick it up separately, but it
> doesn't apply.

... see below

>> ---
>>  arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
>>  1 file changed, 37 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
>> index 909988d..b038ea4 100644
>> --- a/arch/arm/boot/dts/vfxxx.dtsi
>> +++ b/arch/arm/boot/dts/vfxxx.dtsi
>> @@ -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


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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM
@ 2016-03-31 17:57       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:57 UTC (permalink / raw)
  To: linux-arm-kernel

On 2016-03-31 01:33, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:45PM -0800, Stefan Agner wrote:
>> Add Vybrids massive on-chip SRAM areas. Make use of the memory
>> region functionality to denominate the retained SRAM area in
>> LPSTOP2 and LPSTOP3.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> This one looks fine to me.  I was going to pick it up separately, but it
> doesn't apply.

... see below

>> ---
>>  arch/arm/boot/dts/vfxxx.dtsi | 37 +++++++++++++++++++++++++++++++++++++
>>  1 file changed, 37 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
>> index 909988d..b038ea4 100644
>> --- a/arch/arm/boot/dts/vfxxx.dtsi
>> +++ b/arch/arm/boot/dts/vfxxx.dtsi
>> @@ -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


>>  		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
>>
>>

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration
  2016-03-31 11:37     ` Shawn Guo
@ 2016-03-31 17:59       ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:59 UTC (permalink / raw)
  To: Shawn Guo
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On 2016-03-31 04:37, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:47PM -0800, Stefan Agner wrote:
>> 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.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> 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 :-/

> 
> 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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration
@ 2016-03-31 17:59       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-03-31 17:59 UTC (permalink / raw)
  To: linux-arm-kernel

On 2016-03-31 04:37, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:47PM -0800, Stefan Agner wrote:
>> 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.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
> 
> 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 :-/

> 
> 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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
  2016-03-10  2:16   ` Stefan Agner
@ 2016-04-01  2:25     ` Shawn Guo
  -1 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-04-01  2:25 UTC (permalink / raw)
  To: Stefan Agner
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On Wed, Mar 09, 2016 at 06:16:56PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
@ 2016-04-01  2:25     ` Shawn Guo
  0 siblings, 0 replies; 96+ messages in thread
From: Shawn Guo @ 2016-04-01  2:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 09, 2016 at 06:16:56PM -0800, Stefan Agner wrote:
> 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.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* Re: [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
  2016-04-01  2:25     ` Shawn Guo
@ 2016-04-01  6:40       ` Stefan Agner
  -1 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-04-01  6:40 UTC (permalink / raw)
  To: Shawn Guo
  Cc: mturquette, sboyd, kernel, sergeimir, tglx, jason, marc.zyngier,
	robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk

On 2016-03-31 19:25, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:56PM -0800, Stefan Agner wrote:
>> 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.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
>> ---
>>  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.

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

^ permalink raw reply	[flat|nested] 96+ messages in thread

* [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support
@ 2016-04-01  6:40       ` Stefan Agner
  0 siblings, 0 replies; 96+ messages in thread
From: Stefan Agner @ 2016-04-01  6:40 UTC (permalink / raw)
  To: linux-arm-kernel

On 2016-03-31 19:25, Shawn Guo wrote:
> On Wed, Mar 09, 2016 at 06:16:56PM -0800, Stefan Agner wrote:
>> 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.
>>
>> Signed-off-by: Stefan Agner <stefan@agner.ch>
>> ---
>>  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.

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

^ permalink raw reply	[flat|nested] 96+ messages in thread

end of thread, other threads:[~2016-04-01  6:43 UTC | newest]

Thread overview: 96+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10  2:16 [PATCH 00/18] ARM: vf610: Suspend/resume with self-refresh mode Stefan Agner
2016-03-10  2:16 ` Stefan Agner
2016-03-10  2:16 ` [PATCH 01/18] irqchip: vf610-gpc: add Vybrid GPC IRQ controller Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-11  3:41   ` Marc Zyngier
2016-03-11  3:41     ` Marc Zyngier
2016-03-11  3:41     ` Marc Zyngier
2016-03-11 18:11     ` Stefan Agner
2016-03-11 18:11       ` Stefan Agner
2016-03-11 18:11       ` Stefan Agner
2016-03-12  0:21       ` Marc Zyngier
2016-03-12  0:21         ` Marc Zyngier
2016-03-31  8:07   ` Shawn Guo
2016-03-31  8:07     ` Shawn Guo
2016-03-10  2:16 ` [PATCH 02/18] ARM: dts: vf610: add GPC as new interrupt parent Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-31  8:21   ` Shawn Guo
2016-03-31  8:21     ` Shawn Guo
2016-03-31 17:53     ` Stefan Agner
2016-03-31 17:53       ` Stefan Agner
2016-03-10  2:16 ` [PATCH 03/18] ARM: dts: vf610-colibri: GPIO wakeup key Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-31  8:19   ` Shawn Guo
2016-03-31  8:19     ` Shawn Guo
2016-03-31 17:55     ` Stefan Agner
2016-03-31 17:55       ` Stefan Agner
2016-03-31 17:55       ` Stefan Agner
2016-03-10  2:16 ` [PATCH 04/18] ARM: dts: vf610: add on-chip SRAM Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-31  8:33   ` Shawn Guo
2016-03-31  8:33     ` Shawn Guo
2016-03-31 17:57     ` Stefan Agner
2016-03-31 17:57       ` Stefan Agner
2016-03-10  2:16 ` [PATCH 05/18] ARM: dts: vf610: add modules required for PM Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-31  8:34   ` Shawn Guo
2016-03-31  8:34     ` Shawn Guo
2016-03-31  8:34     ` Shawn Guo
2016-03-10  2:16 ` [PATCH 06/18] ARM: imx: clk-gate2: allow custom gate configuration Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-31 11:37   ` Shawn Guo
2016-03-31 11:37     ` Shawn Guo
2016-03-31 17:59     ` Stefan Agner
2016-03-31 17:59       ` Stefan Agner
2016-03-10  2:16 ` [PATCH 07/18] ARM: imx: clk-vf610: leave DDR clock on Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16 ` [PATCH 08/18] ARM: clk: add WKPU unit Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-16  1:13   ` Stephen Boyd
2016-03-16  1:13     ` Stephen Boyd
2016-03-10  2:16 ` [PATCH 09/18] ARM: vf610: clk: add suspend/resume support Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-31 11:39   ` Shawn Guo
2016-03-31 11:39     ` Shawn Guo
2016-03-10  2:16 ` [PATCH 10/18] tty: serial: fsl_lpuart: support suspend/resume Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-31 11:41   ` Shawn Guo
2016-03-31 11:41     ` Shawn Guo
2016-03-10  2:16 ` [PATCH 11/18] pinctrl: pinctrl-imx: implement suspend/resume Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16 ` [PATCH 12/18] gpio: vf610: add system PM suspend/resume Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16 ` [PATCH 13/18] ARM: dts: vf610: add WKPU connection to GPIO Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16 ` [PATCH 14/18] gpio: vf610: add support for WKPU unit Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-17 20:00   ` Rob Herring
2016-03-17 20:00     ` Rob Herring
2016-03-17 22:12     ` Stefan Agner
2016-03-17 22:12       ` Stefan Agner
2016-03-10  2:16 ` [PATCH 15/18] ARM: vf610: PM: initial suspend/resume support Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10 21:19   ` kbuild test robot
2016-03-10 21:19     ` kbuild test robot
2016-03-10 21:19     ` kbuild test robot
2016-04-01  2:25   ` Shawn Guo
2016-04-01  2:25     ` Shawn Guo
2016-04-01  6:40     ` Stefan Agner
2016-04-01  6:40       ` Stefan Agner
2016-03-10  2:16 ` [PATCH 16/18] ARM: vf610: PM: enable Suspend-to-RAM only if hardware fixes are in place Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16 ` [PATCH 17/18] Documentation: dt: add Vybrid DDR memory controller bindings Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-10  2:16   ` Stefan Agner
2016-03-18 16:10   ` Rob Herring
2016-03-18 16:10     ` Rob Herring
2016-03-10  2:16 ` [PATCH 18/18] ARM: vf610: PM: enable SNVS access Stefan Agner
2016-03-10  2:16   ` Stefan Agner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.