Skip to contentSkip to conversation

socfpga: support suspend to ram

PATCH Superseded Alan Tull 3 participants 13 messages May 22, 2015 – May 28, 2015

Subsystems (5)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Alan Tull

author
#0 lore raw

v4 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.
* SDRAM ECC is mutually exclusive with using ocram for suspend, so disable SDRAM ECC if socfpga suspend 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                         |  150 +++++++++++++++++++
 arch/arm/mach-socfpga/self-refresh.S               |  157 ++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c                    |    6 +-
 drivers/edac/Kconfig                               |    2 +-
 8 files changed, 340 insertions(+), 4 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 v4 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.

This patch assumes that u-boot has already configured sdr:
sdr.ctrlcfg.lowpwreq.selfrfshmask = 3 sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8 sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA platforms. CONFIG_SOCFPGA_SUSPEND enables suspend-to-RAM and prevents selecting CONFIG_EDAC_ALTERA_MC.

How 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

---
 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           |  150 ++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/self-refresh.S |  157 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c      |    6 +-
 drivers/edac/Kconfig                 |    2 +-
 7 files changed, 328 insertions(+), 4 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 a0f3b1c..498b271 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
@@ -39,6 +39,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, u32 scu_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 +150 -0

150 lines not on this page · raw message

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

157 lines not on this page · raw message

arch/arm/mach-socfpga/socfpga.c +5 -1
index f5e597c..a807aa0 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
@@ -30,6 +30,7 @@
 void __iomem *socfpga_scu_base_addr = ((void __iomem *)(SOCFPGA_SCU_VIRT_BASE));
 void __iomem *sys_manager_base_addr;
 void __iomem *rst_manager_base_addr;
+void __iomem *sdr_ctl_base_addr;
 unsigned long socfpga_cpu1start_addr;
 
 static struct map_desc scu_io_desc __initdata = {
@@ -82,6 +83,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/Kconfig +1 -1
index cb59619..9b69b97 100644
@@ -378,7 +378,7 @@ config EDAC_OCTEON_PCI
 
 config EDAC_ALTERA_MC
 	tristate "Altera SDRAM Memory Controller EDAC"
-	depends on EDAC_MM_EDAC && ARCH_SOCFPGA
+	depends on EDAC_MM_EDAC && ARCH_SOCFPGA && !SOCFPGA_SUSPEND
 	help
 	  Support for error detection and correction on the
 	  Altera SDRAM memory controller. Note that the
Signature · 1 line
1.7.9.5
author
#10 lore raw

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

---
 .../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
#11 lore raw

Re: [PATCH v4 2/2] ARM: socfpga: dts: add sdram controller dt binding doc

Quoted 16 lines · Alan Tull

Add binding doc for Altera SOCFPGA SDRAM controller.

---
v4: Add bindings doc

---
 .../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 +0 -0
new file mode 100644
index 0000000..77ca635

Documentation/devicetree/bindings/arm/altera/socfpga-sdram-controller.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/arm/altera/socfpga-sdram-controller.txt new file +10 -0
@@ -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";

Is the syscon binding good idea? Should the EDAC driver be fixed to accept altr,sdr-ctl binding, instead?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw

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

In reply to Alan Tull

Hi!

Quoted 3 lines

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA platforms. CONFIG_SOCFPGA_SUSPEND enables suspend-to-RAM and prevents selecting CONFIG_EDAC_ALTERA_MC.

Do we went to have the dependency at the .config time? We would like to do generic kernels booting on many machines, this kind of breaks that...

arch/arm/mach-socfpga/self-refresh.S line 36

Quoted 3 lines
arch/arm/mach-socfpga/self-refresh.S new file +3 -0
+	/*
+	 * This code assumes that the bootloader has already
+	 * properly configured the sdram controller:

Which bootloaders can do that?

arch/arm/mach-socfpga/self-refresh.S line 40

Quoted 3 lines
arch/arm/mach-socfpga/self-refresh.S new file +3 -0
+	 * sdr.ctrlcfg.lowpwreq.selfrfshmask = 3
+	 * sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8
+	 * sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Would it make sense to configure it in Linux?

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw

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

In reply to Alan Tull

Hi Alan,

Quoted 38 lines · Alan Tull

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

This patch assumes that u-boot has already configured sdr:
sdr.ctrlcfg.lowpwreq.selfrfshmask = 3 sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8 sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA platforms. CONFIG_SOCFPGA_SUSPEND enables suspend-to-RAM and prevents selecting CONFIG_EDAC_ALTERA_MC.

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

<snip>

arch/arm/mach-socfpga/pm.c line 110

Quoted 11 lines
arch/arm/mach-socfpga/pm.c new file +11 -0
+
+static int socfpga_pm_suspend(unsigned long arg)
+{
+	u32 ret;
+
+	if (!sdr_ctl_base_addr || !socfpga_scu_base_addr)
+		return -EFAULT;
+
+	ret = socfpga_sdram_self_refresh_in_ocram(
+		(u32)sdr_ctl_base_addr, (u32)socfpga_scu_base_addr);
+

I had a patch that removed socfpga_scu_base_addr from being a global and just a local variable in:

f6e14376fb20 ARM: socfpga: use of_iomap to map the SCU

This patch will be in v4.2 and is currently in arm-soc/next or at my fork: kernel/git/dinguyen/linux.git socfpga_for_next_arria10

So you will either need to make socfpga_scu_base_addr global again, or you can use the asm instruction to get the SCU base addr.

Sorry about that..

Dinh

author
#12 lore raw

Re: [PATCH v4 2/2] ARM: socfpga: dts: add sdram controller dt binding doc

In reply to Pavel Machek
Quoted 23 lines · Pavel Machek
Quoted 22 lines · Alan Tull

Add binding doc for Altera SOCFPGA SDRAM controller.

---
v4: Add bindings doc

---
 .../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 +6 -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)
Quoted 8 lines

Documentation/devicetree/bindings/arm/altera/socfpga-sdram-controller.txt line 10

Quoted 4 lines
Documentation/devicetree/bindings/arm/altera/socfpga-sdram-controller.txt new file +4 -0
+
+Example:
+	sdr: sdr at ffc25000 {
+		compatible = "altr,sdr-ctl", "syscon";

Is the syscon binding good idea? Should the EDAC driver be fixed to accept altr,sdr-ctl binding, instead?
Pavel

What problems do you see here? I'd like to avoid changing the EDAC if possible.

We have 3 things (EDAC, fpga bridges, suspend) that need access to the sdc. They access 3 nonoverlapping sets of registers within the sdc to get at 3 different sets of functionality. Both EDAC and the fpga bridge are using syscon. The suspend code can't use syscon because it has to be assembly running in OCRAM to enable self-refresh for the DDR.

Thor Thayer ended up using syscon for the EDAC after a thorough discussion on lkml and several revisions of the EDAC driver that tried it several different ways before finally ending up back where he started.

Alan Tull

Quoted 8 lines
Signature · 6 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#3 lore raw

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

In reply to Pavel Machek
Quoted 10 lines · Pavel Machek

Hi!

Quoted 3 lines

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA platforms. CONFIG_SOCFPGA_SUSPEND enables suspend-to-RAM and prevents selecting CONFIG_EDAC_ALTERA_MC.

Do we went to have the dependency at the .config time? We would like to do generic kernels booting on many machines, this kind of breaks that...

Hi Pavel,

Thanks for the feedback.

Yes I agree.

One possibility is that I could add a suspend function to EDAC that always fails with a helpful message like "Suspend with EDAC not supported." If someone wants to suspend, they'll have to take the EDAC out of the device tree so its probe will bomb out. I'm not sure how normal it is to have suspend functions in the kernel that always fail, though.

Quoted 5 lines

arch/arm/mach-socfpga/self-refresh.S line 36

Quoted 3 lines
arch/arm/mach-socfpga/self-refresh.S new file +3 -0
+	/*
+	 * This code assumes that the bootloader has already
+	 * properly configured the sdram controller:

Which bootloaders can do that?

Whatever bootloader is configuring the sdram controller for the board.

Quoted 9 lines

arch/arm/mach-socfpga/self-refresh.S line 40

Quoted 4 lines
arch/arm/mach-socfpga/self-refresh.S new file +3 -0
+	 * sdr.ctrlcfg.lowpwreq.selfrfshmask = 3
+	 * sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8
+	 * sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Would it make sense to configure it in Linux?

Thanks,
Pavel

The bootloader is responsible for configuring the sdram controller with parameters appropriate for whatever vendor's DDR is on the board, so that's where this must go.

Now I realize I should make this message more general, since it is true for the socfpga cyclone5 devkit, but may need to be adjusted for other boards.

Alan

#4 lore raw

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

Hi!

Quoted 10 lines

Thanks for the feedback.

Yes I agree.

One possibility is that I could add a suspend function to EDAC that always fails with a helpful message like "Suspend with EDAC not supported." If someone wants to suspend, they'll have to take the EDAC out of the device tree so its probe will bomb out. I'm not sure how normal it is to have suspend functions in the kernel that always fail, though.

"Interesting" solution, but better than config exclusion, I'd say.

Quoted 8 lines
Quoted 5 lines

arch/arm/mach-socfpga/self-refresh.S line 36

Quoted 3 lines
arch/arm/mach-socfpga/self-refresh.S new file +3 -0
+	/*
+	 * This code assumes that the bootloader has already
+	 * properly configured the sdram controller:

Which bootloaders can do that?

Whatever bootloader is configuring the sdram controller for the board.

Ok, so direct question: will mainline u-boot 2015.04 configure the controller correctly?

Quoted 6 lines
Quoted 5 lines

arch/arm/mach-socfpga/self-refresh.S line 40

Quoted 3 lines
arch/arm/mach-socfpga/self-refresh.S new file +3 -0
+	 * sdr.ctrlcfg.lowpwreq.selfrfshmask = 3
+	 * sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8
+	 * sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Would it make sense to configure it in Linux?

Quoted 7 lines

The bootloader is responsible for configuring the sdram controller with parameters appropriate for whatever vendor's DDR is on the board, so that's where this must go.

Now I realize I should make this message more general, since it is true for the socfpga cyclone5 devkit, but may need to be adjusted for other boards.

Aha, ok, the comment really needs to be fixed.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#7 lore raw

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

In reply to Dinh Nguyen
Quoted 64 lines · Dinh Nguyen

Hi Alan,

Quoted 38 lines · Alan Tull

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

This patch assumes that u-boot has already configured sdr:
sdr.ctrlcfg.lowpwreq.selfrfshmask = 3 sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8 sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA platforms. CONFIG_SOCFPGA_SUSPEND enables suspend-to-RAM and prevents selecting CONFIG_EDAC_ALTERA_MC.

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

<snip>

arch/arm/mach-socfpga/pm.c line 110

Quoted 11 lines
arch/arm/mach-socfpga/pm.c new file +11 -0
+
+static int socfpga_pm_suspend(unsigned long arg)
+{
+	u32 ret;
+
+	if (!sdr_ctl_base_addr || !socfpga_scu_base_addr)
+		return -EFAULT;
+
+	ret = socfpga_sdram_self_refresh_in_ocram(
+		(u32)sdr_ctl_base_addr, (u32)socfpga_scu_base_addr);
+

I had a patch that removed socfpga_scu_base_addr from being a global and just a local variable in:

f6e14376fb20 ARM: socfpga: use of_iomap to map the SCU

This patch will be in v4.2 and is currently in arm-soc/next or at my fork: kernel/git/dinguyen/linux.git socfpga_for_next_arria10

Quoted 7 lines

So you will either need to make socfpga_scu_base_addr global again, or you can use the asm instruction to get the SCU base addr.

Sorry about that..

Dinh

I can't make socfpga_scu_base_addr a global from platsmp.c since that file may or may not be compiled in.

That leaves me with the option of adding the code that was removed from socfpga.c back where it was or taking that same code moving it to pm.c

What's your preference?

Alan

#8 lore raw

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

Quoted 69 lines · atull
Quoted 67 lines · Dinh Nguyen

Hi Alan,

Quoted 38 lines · Alan Tull

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

This patch assumes that u-boot has already configured sdr:
sdr.ctrlcfg.lowpwreq.selfrfshmask = 3 sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8 sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA platforms. CONFIG_SOCFPGA_SUSPEND enables suspend-to-RAM and prevents selecting CONFIG_EDAC_ALTERA_MC.

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

<snip>

arch/arm/mach-socfpga/pm.c line 110

Quoted 11 lines
arch/arm/mach-socfpga/pm.c new file +11 -0
+
+static int socfpga_pm_suspend(unsigned long arg)
+{
+	u32 ret;
+
+	if (!sdr_ctl_base_addr || !socfpga_scu_base_addr)
+		return -EFAULT;
+
+	ret = socfpga_sdram_self_refresh_in_ocram(
+		(u32)sdr_ctl_base_addr, (u32)socfpga_scu_base_addr);
+

I had a patch that removed socfpga_scu_base_addr from being a global and just a local variable in:

f6e14376fb20 ARM: socfpga: use of_iomap to map the SCU

This patch will be in v4.2 and is currently in arm-soc/next or at my fork: kernel/git/dinguyen/linux.git socfpga_for_next_arria10

So you will either need to make socfpga_scu_base_addr global again, or you can use the asm instruction to get the SCU base addr.

Quoted 7 lines
Quoted 4 lines

Sorry about that..

Dinh

I can't make socfpga_scu_base_addr a global from platsmp.c since that file may or may not be compiled in.

Ah, okay..

Quoted 4 lines

That leaves me with the option of adding the code that was removed from socfpga.c back where it was or taking that same code moving it to pm.c

I think you only need the scu base address in socfpga_sdram_self_refresh(), so you can probably just use the single line assembly code to get it there.

Dinh

author
#5 lore raw

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

In reply to Pavel Machek
Quoted 21 lines · Pavel Machek

Hi!

Quoted 10 lines

Thanks for the feedback.

Yes I agree.

One possibility is that I could add a suspend function to EDAC that always fails with a helpful message like "Suspend with EDAC not supported." If someone wants to suspend, they'll have to take the EDAC out of the device tree so its probe will bomb out. I'm not sure how normal it is to have suspend functions in the kernel that always fail, though.

"Interesting" solution, but better than config exclusion, I'd say.

Quoted 6 lines
Quoted 5 lines

arch/arm/mach-socfpga/self-refresh.S line 36

Quoted 3 lines
arch/arm/mach-socfpga/self-refresh.S new file +3 -0
+	/*
+	 * This code assumes that the bootloader has already
+	 * properly configured the sdram controller:

Which bootloaders can do that?

Quoted 5 lines
Quoted 2 lines

Whatever bootloader is configuring the sdram controller for the board.

Ok, so direct question: will mainline u-boot 2015.04 configure the controller correctly?

Should be in 2015.07

Alan Tull

author
#9 lore raw

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

In reply to Dinh Nguyen
Quoted 84 lines · Dinh Nguyen
Quoted 69 lines · atull
Quoted 67 lines · Dinh Nguyen

Hi Alan,

Quoted 38 lines · Alan Tull

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

This patch assumes that u-boot has already configured sdr:
sdr.ctrlcfg.lowpwreq.selfrfshmask = 3 sdr.ctrlcfg.lowpwrtiming.clkdisablecycles = 8 sdr.ctrlcfg.dramtiming4.selfrfshexit = 512

Suspend-to-RAM and EDAC support are mutually exclusive on SOCFPGA platforms. CONFIG_SOCFPGA_SUSPEND enables suspend-to-RAM and prevents selecting CONFIG_EDAC_ALTERA_MC.

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

<snip>

arch/arm/mach-socfpga/pm.c line 110

Quoted 11 lines
arch/arm/mach-socfpga/pm.c new file +11 -0
+
+static int socfpga_pm_suspend(unsigned long arg)
+{
+	u32 ret;
+
+	if (!sdr_ctl_base_addr || !socfpga_scu_base_addr)
+		return -EFAULT;
+
+	ret = socfpga_sdram_self_refresh_in_ocram(
+		(u32)sdr_ctl_base_addr, (u32)socfpga_scu_base_addr);
+

I had a patch that removed socfpga_scu_base_addr from being a global and just a local variable in:

f6e14376fb20 ARM: socfpga: use of_iomap to map the SCU

This patch will be in v4.2 and is currently in arm-soc/next or at my fork: kernel/git/dinguyen/linux.git socfpga_for_next_arria10

So you will either need to make socfpga_scu_base_addr global again, or you can use the asm instruction to get the SCU base addr.

Quoted 7 lines
Quoted 4 lines

Sorry about that..

Dinh

I can't make socfpga_scu_base_addr a global from platsmp.c since that file may or may not be compiled in.

Ah, okay..

Quoted 4 lines

That leaves me with the option of adding the code that was removed from socfpga.c back where it was or taking that same code moving it to pm.c

Quoted 6 lines

I think you only need the scu base address in socfpga_sdram_self_refresh(), so you can probably just use the single line assembly code to get it there.

Dinh

I realized that I don't need to touch the scu self refresh bit at all here. It's handled in scu_enable().

Alan