Skip to contentSkip to conversation

socfpga: support suspend to ram

PATCH Superseded Alan Tull 2 participants 6 messages May 28, 2015 – May 29, 2015

Subsystems (6)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Alan Tull

author
#0 lore raw

v5 cover socfpga: support suspend to ram

Support suspend to ram on socfpga.
* allocate space in ocram using sram driver.
* Add a function in ocram to place DDR in self-refresh and suspend.
* Prevent suspend if EDAC is enabled.
* Add a device tree binding document for the Altera SOCFPGA SDRAM controller that is used to put DDR in self-refresh mode.

Alan Tull (2):
ARM: socfpga: support suspend to ram
ARM: socfpga: dts: add sdram controller dt binding doc

 .../arm/altera/socfpga-sdram-controller.txt        |   12 ++
 arch/arm/mach-socfpga/Kconfig                      |   10 +-
 arch/arm/mach-socfpga/Makefile                     |    1 +
 arch/arm/mach-socfpga/core.h                       |    6 +-
 arch/arm/mach-socfpga/pm.c                         |  149 ++++++++++++++++++++
 arch/arm/mach-socfpga/self-refresh.S               |  136 ++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c                    |    6 +-
 drivers/edac/altera_edac.c                         |   20 +++
 8 files changed, 337 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-sdram-controller.txt
 create mode 100644 arch/arm/mach-socfpga/pm.c
 create mode 100644 arch/arm/mach-socfpga/self-refresh.S
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v5 1/2 ARM: socfpga: support suspend to ram

Add code that requests that the sdr controller go into self-refresh mode. This code is run from ocram.

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA. If the EDAC is enabled, it will prevent the platform from going into suspend.

Example of how to request to suspend to ram:

 $ echo enabled > \
/sys/devices/soc/ffc02000.serial0/tty/ttyS0/power/wakeup
 $ echo -n mem > /sys/power/state
Cc Pavel Machek <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Steffen Trumtrar <[email protected]>

---
v2: use Generic on-chip SRAM driver to allocate ocram
rm fncpy_align since generic allocator handles alignment check __arm_ioremap_exec return code
check for NULL pointers
add a comment regarding sdram controller configuration
v3: fix renamed #define
propagate socfpga_setup_ocram_self_refresh error code
v4: Kconfig: don't need to select GENERIC_ALLOCATER
add CONFIG_SOCFPGA_SUSPEND
make s2r and EDAC support mutually exclusive socfpga.c: add sdr_ctl_base_addr
return error if ocram not available in device tree update copyright years
v5: remove compile time dependency
edac driver will prevent suspend
don't configure scu standby mode; done in enable_scu(). fix comments about required sdram controller configuration

---
 arch/arm/mach-socfpga/Kconfig        |   10 ++-
 arch/arm/mach-socfpga/Makefile       |    1 +
 arch/arm/mach-socfpga/core.h         |    6 +-
 arch/arm/mach-socfpga/pm.c           |  149 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/self-refresh.S |  136 +++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c      |    6 +-
 drivers/edac/altera_edac.c           |   20 +++++
 7 files changed, 325 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-socfpga/pm.c
 create mode 100644 arch/arm/mach-socfpga/self-refresh.S
arch/arm/mach-socfpga/Kconfig +9 -1
index b5f8d75..b26a684 100644
@@ -1,4 +1,4 @@
-config ARCH_SOCFPGA
+menuconfig ARCH_SOCFPGA
 	bool "Altera SOCFPGA family" if ARCH_MULTI_V7
 	select ARM_AMBA
 	select ARM_GIC
@@ -8,3 +8,11 @@ config ARCH_SOCFPGA
 	select HAVE_ARM_SCU
 	select HAVE_ARM_TWD if SMP
 	select MFD_SYSCON
+
+if ARCH_SOCFPGA
+config SOCFPGA_SUSPEND
+	bool "Suspend to RAM on SOCFPGA"
+	help
+	  Select this if you want to enable Suspend-to-RAM on SOCFPGA
+	  platforms.
+endif
arch/arm/mach-socfpga/Makefile +1 -0
index 6dd7a93..b8f9e23 100644
@@ -4,3 +4,4 @@
 
 obj-y					:= socfpga.o
 obj-$(CONFIG_SMP)	+= headsmp.o platsmp.o
+obj-$(CONFIG_SOCFPGA_SUSPEND)	+= pm.o self-refresh.o
arch/arm/mach-socfpga/core.h +5 -1
index 7637b7f..35472f2 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright 2012 Pavel Machek <[email protected]>
- * Copyright (C) 2012 Altera Corporation
+ * Copyright (C) 2012-2015 Altera Corporation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,6 +40,10 @@ extern void socfpga_sysmgr_init(void);
 
 extern void __iomem *sys_manager_base_addr;
 extern void __iomem *rst_manager_base_addr;
+extern void __iomem *sdr_ctl_base_addr;
+
+u32 socfpga_sdram_self_refresh(u32 sdr_base);
+extern unsigned int socfpga_sdram_self_refresh_sz;
 
 extern struct smp_operations socfpga_smp_ops;
 extern char secondary_trampoline, secondary_trampoline_end;
arch/arm/mach-socfpga/pm.c new file +149 -0

149 lines not on this page · raw message

arch/arm/mach-socfpga/self-refresh.S new file +136 -0

136 lines not on this page · raw message

arch/arm/mach-socfpga/socfpga.c +5 -1
index a154920..19643a7 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2012 Altera Corporation
+ *  Copyright (C) 2012-2015 Altera Corporation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@
 
 void __iomem *sys_manager_base_addr;
 void __iomem *rst_manager_base_addr;
+void __iomem *sdr_ctl_base_addr;
 unsigned long socfpga_cpu1start_addr;
 
 void __init socfpga_sysmgr_init(void)
@@ -49,6 +50,9 @@ void __init socfpga_sysmgr_init(void)
 
 	np = of_find_compatible_node(NULL, NULL, "altr,rst-mgr");
 	rst_manager_base_addr = of_iomap(np, 0);
+
+	np = of_find_compatible_node(NULL, NULL, "altr,sdr-ctl");
+	sdr_ctl_base_addr = of_iomap(np, 0);
 }
 
 static void __init socfpga_init_irq(void)
drivers/edac/altera_edac.c +20 -0
index 3c4929f..806b63b 100644
@@ -388,6 +388,23 @@ static int altr_sdram_remove(struct platform_device *pdev)
 	return 0;
 }
 
+/*
+ * If you want to suspend, need to disable EDAC by removing it
+ * from the device tree or defconfig.
+ */
+#ifdef CONFIG_PM
+static int altr_sdram_prepare(struct device *dev)
+{
+	pr_err("Suspend not allowed when EDAC is enabled.\n");
+
+	return -EPERM;
+}
+
+const struct dev_pm_ops altr_sdram_pm_ops = {
+	.prepare = altr_sdram_prepare,
+};
+#endif
+
 static const struct of_device_id altr_sdram_ctrl_of_match[] = {
 	{ .compatible = "altr,sdram-edac", },
 	{},
@@ -399,6 +416,9 @@ static struct platform_driver altr_sdram_edac_driver = {
 	.remove = altr_sdram_remove,
 	.driver = {
 		.name = "altr_sdram_edac",
+#ifdef CONFIG_PM
+		.pm = &altr_sdram_pm_ops,
+#endif
 		.of_match_table = altr_sdram_ctrl_of_match,
 	},
 };
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCHv5 1/2] ARM: socfpga: support suspend to ram

Quoted 36 lines · Alan Tull

Add code that requests that the sdr controller go into self-refresh mode. This code is run from ocram.

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA. If the EDAC is enabled, it will prevent the platform from going into suspend.

Example of how to request to suspend to ram:

 $ echo enabled > \
/sys/devices/soc/ffc02000.serial0/tty/ttyS0/power/wakeup
 $ echo -n mem > /sys/power/state
Cc Pavel Machek <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Steffen Trumtrar <[email protected]>

---
v2: use Generic on-chip SRAM driver to allocate ocram
rm fncpy_align since generic allocator handles alignment check __arm_ioremap_exec return code
check for NULL pointers
add a comment regarding sdram controller configuration
v3: fix renamed #define
propagate socfpga_setup_ocram_self_refresh error code
v4: Kconfig: don't need to select GENERIC_ALLOCATER
add CONFIG_SOCFPGA_SUSPEND
make s2r and EDAC support mutually exclusive socfpga.c: add sdr_ctl_base_addr
return error if ocram not available in device tree update copyright years
v5: remove compile time dependency
edac driver will prevent suspend
don't configure scu standby mode; done in enable_scu(). fix comments about required sdram controller configuration

Quoted 12 lines
---
 arch/arm/mach-socfpga/Kconfig        |   10 ++-
 arch/arm/mach-socfpga/Makefile       |    1 +
 arch/arm/mach-socfpga/core.h         |    6 +-
 arch/arm/mach-socfpga/pm.c           |  149 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/self-refresh.S |  136 +++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c      |    6 +-
 drivers/edac/altera_edac.c           |   20 +++++
 7 files changed, 325 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-socfpga/pm.c
 create mode 100644 arch/arm/mach-socfpga/self-refresh.S

Which branch are you basing this patch on? I got a trivial patch conflict in Kconfig when I applied to arm-soc/for-next and v4.1-rc5.

Also, I'm getting these sparse warnings:

arch/arm/mach-socfpga/pm.c:86:25: warning: incorrect type in argument 1 (different address spaces)
arch/arm/mach-socfpga/pm.c:86:25: expected void *<noident>
arch/arm/mach-socfpga/pm.c:86:25: got void [noderef]
<asn:2>*[assigned] suspend_ocram_base arch/arm/mach-socfpga/pm.c:108:52: warning: cast removes address space of expression

Dinh

author
#3 lore raw

Re: [PATCHv5 1/2] ARM: socfpga: support suspend to ram

Quoted 52 lines · Dinh Nguyen
Quoted 36 lines · Alan Tull

Add code that requests that the sdr controller go into self-refresh mode. This code is run from ocram.

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA. If the EDAC is enabled, it will prevent the platform from going into suspend.

Example of how to request to suspend to ram:

 $ echo enabled > \
/sys/devices/soc/ffc02000.serial0/tty/ttyS0/power/wakeup
 $ echo -n mem > /sys/power/state
Cc Pavel Machek <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Steffen Trumtrar <[email protected]>

---
v2: use Generic on-chip SRAM driver to allocate ocram
rm fncpy_align since generic allocator handles alignment check __arm_ioremap_exec return code
check for NULL pointers
add a comment regarding sdram controller configuration
v3: fix renamed #define
propagate socfpga_setup_ocram_self_refresh error code
v4: Kconfig: don't need to select GENERIC_ALLOCATER
add CONFIG_SOCFPGA_SUSPEND
make s2r and EDAC support mutually exclusive socfpga.c: add sdr_ctl_base_addr
return error if ocram not available in device tree update copyright years
v5: remove compile time dependency
edac driver will prevent suspend
don't configure scu standby mode; done in enable_scu(). fix comments about required sdram controller configuration

Quoted 12 lines
---
 arch/arm/mach-socfpga/Kconfig        |   10 ++-
 arch/arm/mach-socfpga/Makefile       |    1 +
 arch/arm/mach-socfpga/core.h         |    6 +-
 arch/arm/mach-socfpga/pm.c           |  149 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/self-refresh.S |  136 +++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c      |    6 +-
 drivers/edac/altera_edac.c           |   20 +++++
 7 files changed, 325 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-socfpga/pm.c
 create mode 100644 arch/arm/mach-socfpga/self-refresh.S
Quoted 2 lines

Which branch are you basing this patch on? I got a trivial patch conflict in Kconfig when I applied to arm-soc/for-next and v4.1-rc5.

Based on your socfpga_for_next_arria10 branch from
git://git.kernel.org/pub/scm/linux/kernel/git/dinguyen/linux.git

Quoted 11 lines

Also, I'm getting these sparse warnings:

arch/arm/mach-socfpga/pm.c:86:25: warning: incorrect type in argument 1 (different address spaces)
arch/arm/mach-socfpga/pm.c:86:25: expected void *<noident>
arch/arm/mach-socfpga/pm.c:86:25: got void [noderef]
<asn:2>*[assigned] suspend_ocram_base arch/arm/mach-socfpga/pm.c:108:52: warning: cast removes address space of expression

Quoted 2 lines

Dinh

It appears to want suspend_ocram_base to be void * instead of void __iomem *.

Alan

author
#4 lore raw

Re: [PATCHv5 1/2] ARM: socfpga: support suspend to ram

In reply to Dinh Nguyen
Quoted 65 lines · Dinh Nguyen
Quoted 36 lines · Alan Tull

Add code that requests that the sdr controller go into self-refresh mode. This code is run from ocram.

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA. If the EDAC is enabled, it will prevent the platform from going into suspend.

Example of how to request to suspend to ram:

 $ echo enabled > \
/sys/devices/soc/ffc02000.serial0/tty/ttyS0/power/wakeup
 $ echo -n mem > /sys/power/state
Cc Pavel Machek <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Steffen Trumtrar <[email protected]>

---
v2: use Generic on-chip SRAM driver to allocate ocram
rm fncpy_align since generic allocator handles alignment check __arm_ioremap_exec return code
check for NULL pointers
add a comment regarding sdram controller configuration
v3: fix renamed #define
propagate socfpga_setup_ocram_self_refresh error code
v4: Kconfig: don't need to select GENERIC_ALLOCATER
add CONFIG_SOCFPGA_SUSPEND
make s2r and EDAC support mutually exclusive socfpga.c: add sdr_ctl_base_addr
return error if ocram not available in device tree update copyright years
v5: remove compile time dependency
edac driver will prevent suspend
don't configure scu standby mode; done in enable_scu(). fix comments about required sdram controller configuration

Quoted 12 lines
---
 arch/arm/mach-socfpga/Kconfig        |   10 ++-
 arch/arm/mach-socfpga/Makefile       |    1 +
 arch/arm/mach-socfpga/core.h         |    6 +-
 arch/arm/mach-socfpga/pm.c           |  149 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/self-refresh.S |  136 +++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c      |    6 +-
 drivers/edac/altera_edac.c           |   20 +++++
 7 files changed, 325 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-socfpga/pm.c
 create mode 100644 arch/arm/mach-socfpga/self-refresh.S

Which branch are you basing this patch on? I got a trivial patch conflict in Kconfig when I applied to arm-soc/for-next and v4.1-rc5.

Also, I'm getting these sparse warnings:

arch/arm/mach-socfpga/pm.c:86:25: warning: incorrect type in argument 1 (different address spaces)
arch/arm/mach-socfpga/pm.c:86:25: expected void *<noident>
arch/arm/mach-socfpga/pm.c:86:25: got void [noderef]
<asn:2>*[assigned] suspend_ocram_base arch/arm/mach-socfpga/pm.c:108:52: warning: cast removes address space of expression

Quoted 2 lines

Dinh

The problem is that fncpy wants parameter 1 to be void* and __arm_ioremap_exec wants 'void __ioram *'.

I get other warnings if I declare 'void *suspend_ocram_base' or cast it as (void *) for fncpy(). It looks like we are stuck with this warning.

However sparse kindly pointed out that I needed to fix a declaration in altera_edac.c:

-const struct dev_pm_ops altr_sdram_pm_ops = { +static const struct dev_pm_ops altr_sdram_pm_ops = {

I'll fix that in the next rev.

Alan

author
#5 lore raw

PATCH v5 2/2 ARM: socfpga: dts: add sdram controller dt binding doc

In reply to Alan Tull

Add binding doc for Altera SOCFPGA SDRAM controller.

---
v4: Add bindings doc
v5: No change for v5

---
 .../arm/altera/socfpga-sdram-controller.txt        |   12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-sdram-controller.txt
Documentation/devicetree/bindings/arm/altera/socfpga-sdram-controller.txt new file +12 -0
new file mode 100644
index 0000000..77ca635
@@ -0,0 +1,12 @@
+Altera SOCFPGA SDRAM Controller
+
+Required properties:
+- compatible : Should contain "altr,sdr-ctl" and "syscon".
+  syscon is required by the Altera SOCFPGA SDRAM EDAC.
+- reg : Should contain 1 register range (address and length)
+
+Example:
+	sdr: sdr at ffc25000 {
+		compatible = "altr,sdr-ctl", "syscon";
+		reg = <0xffc25000 0x1000>;
+	};
Signature · 1 line
1.7.9.5