Skip to contentSkip to conversation

OMAP2/3: PM sync-up

PATCH Superseded Kevin Hilman 5 participants 31 messages May 15, 2009 – May 28, 2009

Subsystems (8)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover OMAP2/3: PM sync-up

This series is intended to push the core PM support from linux-omap into mainline. It applies on top of Tony's two recent series:

- [PATCH 0/8] Omap fixes for 2.6.30-rc5
- [PATCH 0/5] More omap header clean-up for the merge window after 2.6.30

Upon review/acceptance, Tony will merge into is for-next branch so all OMAP stuff can come from one place.

In addition to the linux-omap sync, several OMAP3 init fixes are required to ensure that the chip can hit full-chip retention on idle and suspend.

Compile tested on OMAP2, Boot tested on OMAP3430SDP and can hit full-chip retention in suspend and in idle.

Jouni Hogander (1):
OMAP: Add new function to check wether there is irq pending

Kevin Hilman (9):
OMAP2/3: PM: push core PM code from linux-omap
OMAP3: PM: Force IVA2 into idle during bootup
OMAP3: PM: Add wake-up bit defintiions for CONTROL_PADCONF_X
OMAP3: PM: UART: disable clocks when idle and off-mode support
OMAP3: PM: Add D2D clocks and auto-idle setup to PRCM init
OMAP3: PM: D2D clockdomain supports SW supervised transitions
OMAP3: PM: Ensure PRCM interrupts are cleared at boot
OMAP3: PM: Clear pending PRCM reset flags on init
OMAP3: PM: prevent module wakeups from waking IVA2

Peter 'p2' De Schrijver (1):
OMAP3: PM: Ensure MUSB block can idle when driver not loaded

 arch/arm/mach-omap2/Makefile              |    3 +
 arch/arm/mach-omap2/clock34xx.c           |    3 +
 arch/arm/mach-omap2/clock34xx.h           |   33 ++-
 arch/arm/mach-omap2/clockdomains.h        |    2 +-
 arch/arm/mach-omap2/cm-regbits-34xx.h     |   14 +
 arch/arm/mach-omap2/irq.c                 |   17 +-
 arch/arm/mach-omap2/pm-debug.c            |  152 ++++++
 arch/arm/mach-omap2/pm.c                  |  155 ++++---
 arch/arm/mach-omap2/pm.h                  |   53 +++
 arch/arm/mach-omap2/pm24xx.c              |  558 ++++++++++++++++++++++
 arch/arm/mach-omap2/pm34xx.c              |  711 +++++++++++++++++++++++++++++
 arch/arm/mach-omap2/prcm-common.h         |    2 +
 arch/arm/mach-omap2/prm.h                 |    2 +
 arch/arm/mach-omap2/sdrc.c                |    5 +-
 arch/arm/mach-omap2/serial.c              |  391 +++++++++++++++-
 arch/arm/mach-omap2/sleep24xx.S           |    1 -
 arch/arm/mach-omap2/sleep34xx.S           |  543 ++++++++++++++++++++++
 arch/arm/mach-omap2/usb-musb.c            |    7 +-
 arch/arm/plat-omap/Kconfig                |    2 +-
 arch/arm/plat-omap/common.c               |    1 -
 arch/arm/plat-omap/include/mach/common.h  |    2 -
 arch/arm/plat-omap/include/mach/control.h |   13 +
 arch/arm/plat-omap/include/mach/irqs.h    |    1 +
 arch/arm/plat-omap/include/mach/pm.h      |  345 --------------
 arch/arm/plat-omap/include/mach/serial.h  |    9 +
 drivers/mtd/onenand/omap2.c               |    1 -
 26 files changed, 2570 insertions(+), 456 deletions(-)
 create mode 100644 arch/arm/mach-omap2/pm-debug.c
 create mode 100644 arch/arm/mach-omap2/pm.h
 create mode 100644 arch/arm/mach-omap2/pm24xx.c
 create mode 100644 arch/arm/mach-omap2/pm34xx.c
 create mode 100644 arch/arm/mach-omap2/sleep34xx.S
 delete mode 100644 arch/arm/plat-omap/include/mach/pm.h
#1 lore raw

PATCH 1/11 OMAP2/3: PM: push core PM code from linux-omap

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Following this will be a series of patches from the 'PM branch' of the linux-omap tree to add full PM hardware support from the linux-omap tree.

Much of this PM core code was written by Jouni Hogander with significant contributions from Paul Walmsley as well as many others from Nokia, Texas Instruments and linux-omap community.

---
 arch/arm/mach-omap2/Makefile         |    3 +
 arch/arm/mach-omap2/pm-debug.c       |  152 +++++++++
 arch/arm/mach-omap2/pm.c             |  155 +++++-----
 arch/arm/mach-omap2/pm.h             |   53 +++
 arch/arm/mach-omap2/pm24xx.c         |  557 +++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/pm34xx.c         |  607 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/prcm-common.h    |    2 +
 arch/arm/mach-omap2/sdrc.c           |    5 +-
 arch/arm/mach-omap2/sleep24xx.S      |    1 -
 arch/arm/mach-omap2/sleep34xx.S      |  543 ++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/usb-musb.c       |    1 -
 arch/arm/plat-omap/Kconfig           |    2 +-
 arch/arm/plat-omap/common.c          |    1 -
 arch/arm/plat-omap/include/mach/pm.h |  345 -------------------
 drivers/mtd/onenand/omap2.c          |    1 -
 15 files changed, 2002 insertions(+), 426 deletions(-)
 create mode 100644 arch/arm/mach-omap2/pm-debug.c
 create mode 100644 arch/arm/mach-omap2/pm.h
 create mode 100644 arch/arm/mach-omap2/pm24xx.c
 create mode 100644 arch/arm/mach-omap2/pm34xx.c
 create mode 100644 arch/arm/mach-omap2/sleep34xx.S
 delete mode 100644 arch/arm/plat-omap/include/mach/pm.h
arch/arm/mach-omap2/Makefile +3 -0
index e4f6f61..f6383a0 100644
@@ -26,7 +26,10 @@ obj-$(CONFIG_ARCH_OMAP2)		+= sdrc2xxx.o
 # Power Management
 ifeq ($(CONFIG_PM),y)
 obj-y					+= pm.o
+obj-$(CONFIG_ARCH_OMAP2)		+= pm24xx.o
 obj-$(CONFIG_ARCH_OMAP24XX)		+= sleep24xx.o
+obj-$(CONFIG_ARCH_OMAP3)		+= pm34xx.o sleep34xx.o
+obj-$(CONFIG_PM_DEBUG)			+= pm-debug.o
 endif
 
 # Clock framework
arch/arm/mach-omap2/pm-debug.c new file +152 -0

152 lines not on this page · raw message

arch/arm/mach-omap2/pm.c +80 -75

188 lines not on this page · raw message

arch/arm/mach-omap2/pm.h new file +53 -0

53 lines not on this page · raw message

arch/arm/mach-omap2/pm24xx.c new file +557 -0

557 lines not on this page · raw message

arch/arm/mach-omap2/pm34xx.c new file +607 -0

607 lines not on this page · raw message

arch/arm/mach-omap2/prcm-common.h +2 -0
index 812d50e..cb1ae84 100644
@@ -276,6 +276,8 @@
 /* CM_FCLKEN_WKUP, CM_ICLKEN_WKUP, PM_WKEN_WKUP shared bits */
 #define OMAP3430_EN_GPIO1				(1 << 3)
 #define OMAP3430_EN_GPIO1_SHIFT				3
+#define OMAP3430_EN_GPT12				(1 << 1)
+#define OMAP3430_EN_GPT12_SHIFT				1
 #define OMAP3430_EN_GPT1				(1 << 0)
 #define OMAP3430_EN_GPT1_SHIFT				0
 
arch/arm/mach-omap2/sdrc.c +4 -1
index 2a30060..993fd25 100644
@@ -56,9 +56,12 @@ struct omap_sdrc_params *omap2_sdrc_get_params(unsigned long r)
 {
 	struct omap_sdrc_params *sp;
 
+	if (!sdrc_init_params)
+		return NULL;
+
 	sp = sdrc_init_params;
 
-	while (sp->rate != r)
+	while (sp->rate && sp->rate != r)
 		sp++;
 
 	if (!sp->rate)
arch/arm/mach-omap2/sleep24xx.S +0 -1
index bf9e961..130aadb 100644
@@ -28,7 +28,6 @@
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 #include <mach/io.h>
-#include <mach/pm.h>
 
 #include <mach/omap24xx.h>
 
arch/arm/mach-omap2/sleep34xx.S new file +543 -0

543 lines not on this page · raw message

arch/arm/mach-omap2/usb-musb.c +0 -1
index 34a56a1..215d463 100644
@@ -28,7 +28,6 @@
 
 #include <mach/hardware.h>
 #include <mach/irqs.h>
-#include <mach/pm.h>
 #include <mach/mux.h>
 #include <mach/usb.h>
 
arch/arm/plat-omap/Kconfig +1 -1
index 9dd68fa..4bc9ed7 100644
@@ -171,7 +171,7 @@ endchoice
 
 config OMAP_SERIAL_WAKE
 	bool "Enable wake-up events for serial ports"
-	depends on OMAP_MUX
+	depends on ARCH_OMAP1 && OMAP_MUX
 	default y
 	help
 	  Select this option if you want to have your system wake up
arch/arm/plat-omap/common.c +0 -1
index e1add78..ec218a3 100644
@@ -11,7 +11,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
-#include <linux/pm.h>
 #include <linux/console.h>
 #include <linux/serial.h>
 #include <linux/tty.h>
arch/arm/plat-omap/include/mach/pm.h deleted +0 -345

345 lines not on this page · raw message

drivers/mtd/onenand/omap2.c +0 -1
index f2e9de1..6391e3d 100644
@@ -39,7 +39,6 @@
 #include <mach/gpmc.h>
 #include <mach/onenand.h>
 #include <mach/gpio.h>
-#include <mach/pm.h>
 
 #include <mach/dma.h>
 
Signature · 1 line
1.6.2.2
#2 lore raw

PATCH 2/11 OMAP: Add new function to check wether there is irq pending

From: Jouni Hogander <[email protected]>

Add common omap2/3 function to check wether there is irq pending. Switch to use it in omap2 pm code instead of its own.

---
 arch/arm/mach-omap2/irq.c              |   17 ++++++++++++++++-
 arch/arm/mach-omap2/pm24xx.c           |   19 +++----------------
 arch/arm/plat-omap/include/mach/irqs.h |    1 +
 3 files changed, 20 insertions(+), 17 deletions(-)
arch/arm/mach-omap2/irq.c +16 -1
index 998c5c4..f5de43d 100644
@@ -28,7 +28,6 @@
 #define INTC_MIR_CLEAR0		0x0088
 #define INTC_MIR_SET0		0x008c
 #define INTC_PENDING_IRQ0	0x0098
-
 /* Number of IRQ state bits in each MIR register */
 #define IRQ_BITS_PER_REG	32
 
@@ -157,6 +156,22 @@ static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
 	intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
 }
 
+int omap_irq_pending(void)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
+		struct omap_irq_bank *bank = irq_banks + i;
+		int irq;
+
+		for (irq = 0; irq < bank->nr_irqs; irq += 32)
+			if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
+					       ((irq >> 5) << 5)))
+				return 1;
+	}
+	return 0;
+}
+
 void __init omap_init_irq(void)
 {
 	unsigned long nr_of_irqs = 0;
arch/arm/mach-omap2/pm24xx.c +3 -16
index 2a2d1a3..da4294d 100644
@@ -77,19 +77,6 @@ static int omap2_fclks_active(void)
 	return 0;
 }
 
-static int omap2_irq_pending(void)
-{
-	u32 pending_reg = 0x480fe098;
-	int i;
-
-	for (i = 0; i < 4; i++) {
-		if (omap_readl(pending_reg))
-			return 1;
-		pending_reg += 0x20;
-	}
-	return 0;
-}
-
 static void omap2_enter_full_retention(void)
 {
 	u32 l;
@@ -128,7 +115,7 @@ static void omap2_enter_full_retention(void)
 
 	/* One last check for pending IRQs to avoid extra latency due
 	 * to sleeping unnecessarily. */
-	if (omap2_irq_pending())
+	if (omap_irq_pending())
 		goto no_sleep;
 
 	/* Jump to SRAM suspend code */
@@ -274,13 +261,13 @@ static void omap2_pm_idle(void)
 	local_fiq_disable();
 
 	if (!omap2_can_sleep()) {
-		if (!atomic_read(&sleep_block) && omap2_irq_pending())
+		if (!atomic_read(&sleep_block) && omap_irq_pending())
 			goto out;
 		omap2_enter_mpu_retention();
 		goto out;
 	}
 
-	if (omap2_irq_pending())
+	if (omap_irq_pending())
 		goto out;
 
 	omap2_enter_full_retention();
arch/arm/plat-omap/include/mach/irqs.h +1 -0
index 7f57ee6..f5f7c92 100644
@@ -467,6 +467,7 @@
 
 #ifndef __ASSEMBLY__
 extern void omap_init_irq(void);
+extern int omap_irq_pending(void);
 #endif
 
 #include <mach/hardware.h>
Signature · 1 line
1.6.2.2
#3 lore raw

PATCH 3/11 OMAP3: PM: Force IVA2 into idle during bootup

---
 arch/arm/mach-omap2/pm34xx.c              |   50 +++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/control.h |    5 +++
 2 files changed, 55 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/pm34xx.c +50 -0
index 0fb6bec..1a13362 100644
@@ -358,6 +358,54 @@ static struct platform_suspend_ops omap_pm_ops = {
 	.valid		= suspend_valid_only_mem,
 };
 
+
+/**
+ * omap3_iva_idle(): ensure IVA is in idle so it can be put into
+ *                   retention
+ *
+ * In cases where IVA2 is activated by bootcode, it may prevent
+ * full-chip retention or off-mode because it is not idle.  This
+ * function forces the IVA2 into idle state so it can go
+ * into retention/off and thus allow full-chip retention/off.
+ *
+ **/
+static void __init omap3_iva_idle(void)
+{
+	/* ensure IVA2 clock is disabled */
+	cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
+
+	/* if no clock activity, nothing else to do */
+	if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
+	      OMAP3430_CLKACTIVITY_IVA2_MASK))
+		return;
+
+	/* Reset IVA2 */
+	prm_write_mod_reg(OMAP3430_RST1_IVA2 |
+			  OMAP3430_RST2_IVA2 |
+			  OMAP3430_RST3_IVA2,
+			  OMAP3430_IVA2_MOD, RM_RSTCTRL);
+
+	/* Enable IVA2 clock */
+	cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2,
+			 OMAP3430_IVA2_MOD, CM_FCLKEN);
+
+	/* Set IVA2 boot mode to 'idle' */
+	omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
+			 OMAP343X_CONTROL_IVA2_BOOTMOD);
+
+	/* Un-reset IVA2 */
+	prm_write_mod_reg(0, OMAP3430_IVA2_MOD, RM_RSTCTRL);
+
+	/* Disable IVA2 clock */
+	cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
+
+	/* Reset IVA2 */
+	prm_write_mod_reg(OMAP3430_RST1_IVA2 |
+			  OMAP3430_RST2_IVA2 |
+			  OMAP3430_RST3_IVA2,
+			  OMAP3430_IVA2_MOD, RM_RSTCTRL);
+}
+
 static void __init prcm_setup_regs(void)
 {
 	/* reset modem */
@@ -517,6 +565,8 @@ static void __init prcm_setup_regs(void)
 	 * it is selected to mpu wakeup goup */
 	prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
 			  OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
+
+	omap3_iva_idle();
 }
 
 static int __init pwrdms_setup(struct powerdomain *pwrdm)
arch/arm/plat-omap/include/mach/control.h +5 -0
index 269147f..d38697b 100644
@@ -189,6 +189,11 @@
 #define OMAP2_PBIASLITEPWRDNZ0		(1 << 1)
 #define OMAP2_PBIASLITEVMODE0		(1 << 0)
 
+/* CONTROL_IVA2_BOOTMOD bits */
+#define OMAP3_IVA2_BOOTMOD_SHIFT	0
+#define OMAP3_IVA2_BOOTMOD_MASK		(0xf << 0)
+#define OMAP3_IVA2_BOOTMOD_IDLE		(0x1 << 0)
+
 #ifndef __ASSEMBLY__
 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
 extern void __iomem *omap_ctrl_base_get(void);
Signature · 1 line
1.6.2.2
#4 lore raw

PATCH 4/11 OMAP3: PM: Add wake-up bit defintiions for CONTROL_PADCONF_X

---
 arch/arm/plat-omap/include/mach/control.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/mach/control.h +4 -0
index d38697b..a9f05e5 100644
@@ -194,6 +194,10 @@
 #define OMAP3_IVA2_BOOTMOD_MASK		(0xf << 0)
 #define OMAP3_IVA2_BOOTMOD_IDLE		(0x1 << 0)
 
+/* CONTROL_PADCONF_X bits */
+#define OMAP3_PADCONF_WAKEUPEVENT0	(1 << 15)
+#define OMAP3_PADCONF_WAKEUPENABLE0	(1 << 14)
+
 #ifndef __ASSEMBLY__
 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
 extern void __iomem *omap_ctrl_base_get(void);
Signature · 1 line
1.6.2.2
#5 lore raw

PATCH 5/11 OMAP3: PM: UART: disable clocks when idle and off-mode support

This patch allows the UART clocks to be disabled when the OMAP UARTs are inactive, thus permitting the chip to hit retention in idle. After the timeout of an activity timer, each UART is allowed to disable its clocks so the system can enter retention. The activity timer is (re)activated on any UART interrupt, UART wake event or any IO pad wakeup. The actual disable of the UART clocks is done in the 'prepare_idle' hook called from the OMAP idle loop.

While the activity timer is active, the smart-idle mode of the UART is also disabled. This is due to a "feature" of the UART module that after a UART wakeup, the smart-idle mode may be entered before the UART has communicated the interrupt, or upon TX, an idle mode may be entered before the TX FIFOs are emptied.

Upon suspend, the 'prepare_suspend' hook cancels any pending activity timers and allows the clocks to be disabled.

To enable the clock-disabling feature of this patch, do

  # echo 1 > /sys/power/clocks_off_while_idle

In addition, upon disabling clocks the UART state is saved in case of an off-mode transition while clocks are off.

Special thanks to Tero Kristo for the initial ideas and first versions of UART idle support, and to Jouni Hogander for extra testing and bugfixes.

Tested on OMAP3 (Beagle, custom HW) and OMAP2 (n810)

Cc Tero Kristo <[email protected]>
Cc Jouni Hogander <[email protected]>
---
 arch/arm/mach-omap2/pm24xx.c             |   16 ++-
 arch/arm/mach-omap2/pm34xx.c             |   15 ++
 arch/arm/mach-omap2/serial.c             |  391 ++++++++++++++++++++++++++++--
 arch/arm/plat-omap/include/mach/common.h |    2 -
 arch/arm/plat-omap/include/mach/serial.h |    9 +
 5 files changed, 406 insertions(+), 27 deletions(-)
arch/arm/mach-omap2/pm24xx.c +15 -1
index da4294d..026cc30 100644
@@ -72,6 +72,11 @@ static int omap2_fclks_active(void)
 
 	f1 = cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
 	f2 = cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2);
+
+	/* Ignore UART clocks.  These are handled by UART core (serial.c) */
+	f1 &= ~(OMAP24XX_EN_UART1 | OMAP24XX_EN_UART2);
+	f2 &= ~OMAP24XX_EN_UART3;
+
 	if (f1 | f2)
 		return 1;
 	return 0;
@@ -118,12 +123,20 @@ static void omap2_enter_full_retention(void)
 	if (omap_irq_pending())
 		goto no_sleep;
 
+	omap_uart_prepare_idle(0);
+	omap_uart_prepare_idle(1);
+	omap_uart_prepare_idle(2);
+
 	/* Jump to SRAM suspend code */
 	omap2_sram_suspend(sdrc_read_reg(SDRC_DLLA_CTRL),
 			   OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL),
 			   OMAP_SDRC_REGADDR(SDRC_POWER));
-no_sleep:
 
+	omap_uart_resume_idle(2);
+	omap_uart_resume_idle(1);
+	omap_uart_resume_idle(0);
+
+no_sleep:
 	if (omap2_pm_debug) {
 		unsigned long long tmp;
 
@@ -297,6 +310,7 @@ static int omap2_pm_suspend(void)
 	mir1 = omap_readl(0x480fe0a4);
 	omap_writel(1 << 5, 0x480fe0ac);
 
+	omap_uart_prepare_suspend();
 	omap2_enter_full_retention();
 
 	omap_writel(mir1, 0x480fe0a4);
arch/arm/mach-omap2/pm34xx.c +15 -0
index 1a13362..24a146c 100644
@@ -27,6 +27,7 @@
 #include <mach/clockdomain.h>
 #include <mach/powerdomain.h>
 #include <mach/control.h>
+#include <mach/serial.h>
 
 #include "cm.h"
 #include "cm-regbits-34xx.h"
@@ -170,9 +171,15 @@ static void omap_sram_idle(void)
 		return;
 	}
 	omap2_gpio_prepare_for_retention();
+	omap_uart_prepare_idle(0);
+	omap_uart_prepare_idle(1);
+	omap_uart_prepare_idle(2);
 
 	_omap_sram_idle(NULL, save_state);
 
+	omap_uart_resume_idle(2);
+	omap_uart_resume_idle(1);
+	omap_uart_resume_idle(0);
 	omap2_gpio_resume_after_retention();
 }
 
@@ -205,6 +212,11 @@ static int omap3_fclks_active(void)
 				  CM_FCLKEN);
 	fck_per = cm_read_mod_reg(OMAP3430_PER_MOD,
 				  CM_FCLKEN);
+
+	/* Ignore UART clocks.  These are handled by UART core (serial.c) */
+	fck_core1 &= ~(OMAP3430_EN_UART1 | OMAP3430_EN_UART2);
+	fck_per &= ~OMAP3430_EN_UART3;
+
 	if (fck_core1 | fck_core3 | fck_sgx | fck_dss |
 	    fck_cam | fck_per | fck_usbhost)
 		return 1;
@@ -215,6 +227,8 @@ static int omap3_can_sleep(void)
 {
 	if (!enable_dyn_sleep)
 		return 0;
+	if (!omap_uart_can_sleep())
+		return 0;
 	if (omap3_fclks_active())
 		return 0;
 	if (atomic_read(&sleep_block) > 0)
@@ -307,6 +321,7 @@ static int omap3_pm_suspend(void)
 			goto restore;
 	}
 
+	omap_uart_prepare_suspend();
 	omap_sram_idle();
 
 restore:
arch/arm/mach-omap2/serial.c +367 -24

440 lines not on this page · raw message

arch/arm/plat-omap/include/mach/common.h +0 -2
index 0ecf36d..834f0b3 100644
@@ -33,8 +33,6 @@ struct sys_timer;
 
 extern void omap_map_common_io(void);
 extern struct sys_timer omap_timer;
-extern void omap_serial_init(void);
-extern void omap_serial_enable_clocks(int enable);
 #if defined(CONFIG_I2C_OMAP) || defined(CONFIG_I2C_OMAP_MODULE)
 extern int omap_register_i2c_bus(int bus_id, u32 clkrate,
 				 struct i2c_board_info const *info,
arch/arm/plat-omap/include/mach/serial.h +9 -0
index 8a676a0..8e89585 100644
@@ -40,4 +40,13 @@
 			__ret;						\
 			})
 
+#ifndef __ASSEMBLER__
+extern void omap_serial_init(void);
+extern int omap_uart_can_sleep(void);
+extern void omap_uart_check_wakeup(void);
+extern void omap_uart_prepare_suspend(void);
+extern void omap_uart_prepare_idle(int num);
+extern void omap_uart_resume_idle(int num);
+#endif
+
 #endif
Signature · 1 line
1.6.2.2
#6 lore raw

PATCH 6/11 OMAP3: PM: Add D2D clocks and auto-idle setup to PRCM init

Add D2D clocks (modem_fck, sad2d_ick, mad2d_ick) to clock framework and ensure that auto-idle bits are set for these clocks during PRCM init.

Also add omap3_d2d_idle() function called durint PRCM setup which ensures D2D pins are MUX'd correctly to enable retention for standalone (no-modem) devices.

---
 arch/arm/mach-omap2/clock34xx.c           |    3 ++
 arch/arm/mach-omap2/clock34xx.h           |   33 +++++++++++++++++++++++++++-
 arch/arm/mach-omap2/cm-regbits-34xx.h     |   14 ++++++++++++
 arch/arm/mach-omap2/pm34xx.c              |   25 ++++++++++++++++++++-
 arch/arm/plat-omap/include/mach/control.h |    4 +++
 5 files changed, 75 insertions(+), 4 deletions(-)
arch/arm/mach-omap2/clock34xx.c +3 -0
index ba05aa4..13a36cf 100644
@@ -129,6 +129,9 @@ static struct omap_clk omap34xx_clks[] = {
 	CLK(NULL,	"sgx_fck",	&sgx_fck,	CK_3430ES2),
 	CLK(NULL,	"sgx_ick",	&sgx_ick,	CK_3430ES2),
 	CLK(NULL,	"d2d_26m_fck",	&d2d_26m_fck,	CK_3430ES1),
+	CLK(NULL,	"modem_fck",	&modem_fck,	CK_343X),
+	CLK(NULL,	"sad2d_ick",	&sad2d_ick,	CK_343X),
+	CLK(NULL,	"mad2d_ick",	&mad2d_ick,	CK_343X),
 	CLK(NULL,	"gpt10_fck",	&gpt10_fck,	CK_343X),
 	CLK(NULL,	"gpt11_fck",	&gpt11_fck,	CK_343X),
 	CLK(NULL,	"cpefuse_fck",	&cpefuse_fck,	CK_3430ES2),
arch/arm/mach-omap2/clock34xx.h +31 -2
index 496f0e9..e433aec 100644
@@ -1230,6 +1230,37 @@ static struct clk d2d_26m_fck = {
 	.recalc		= &followparent_recalc,
 };
 
+static struct clk modem_fck = {
+	.name		= "modem_fck",
+	.ops		= &clkops_omap2_dflt_wait,
+	.parent		= &sys_ck,
+	.init		= &omap2_init_clk_clkdm,
+	.enable_reg	= OMAP_CM_REGADDR(CORE_MOD, CM_FCLKEN1),
+	.enable_bit	= OMAP3430_EN_MODEM_SHIFT,
+	.clkdm_name	= "d2d_clkdm",
+	.recalc		= &followparent_recalc,
+};
+
+static struct clk sad2d_ick = {
+	.name		= "sad2d_ick",
+	.ops		= &clkops_omap2_dflt_wait,
+	.parent		= &l3_ick,
+	.enable_reg	= OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN1),
+	.enable_bit	= OMAP3430_EN_SAD2D_SHIFT,
+	.clkdm_name	= "d2d_clkdm",
+	.recalc		= &followparent_recalc,
+};
+
+static struct clk mad2d_ick = {
+	.name		= "mad2d_ick",
+	.ops		= &clkops_omap2_dflt_wait,
+	.parent		= &l3_ick,
+	.enable_reg	= OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN3),
+	.enable_bit	= OMAP3430_EN_MAD2D_SHIFT,
+	.clkdm_name	= "d2d_clkdm",
+	.recalc		= &followparent_recalc,
+};
+
 static const struct clksel omap343x_gpt_clksel[] = {
 	{ .parent = &omap_32k_fck, .rates = gpt_32k_rates },
 	{ .parent = &sys_ck,	   .rates = gpt_sys_rates },
@@ -1947,8 +1978,6 @@ static struct clk usb_l4_ick = {
 	.recalc		= &omap2_clksel_recalc,
 };
 
-/* XXX MDM_INTC_ICK, SAD2D_ICK ?? */
-
 /* SECURITY_L4_ICK2 based clocks */
 
 static struct clk security_l4_ick2 = {
arch/arm/mach-omap2/cm-regbits-34xx.h +14 -0
index 6f3f5a3..6923deb 100644
@@ -145,6 +145,8 @@
 #define OMAP3430_CLKACTIVITY_MPU_MASK			(1 << 0)
 
 /* CM_FCLKEN1_CORE specific bits */
+#define OMAP3430_EN_MODEM				(1 << 31)
+#define OMAP3430_EN_MODEM_SHIFT				31
 
 /* CM_ICLKEN1_CORE specific bits */
 #define OMAP3430_EN_ICR					(1 << 29)
@@ -161,6 +163,8 @@
 #define OMAP3430_EN_MAILBOXES_SHIFT			7
 #define OMAP3430_EN_OMAPCTRL				(1 << 6)
 #define OMAP3430_EN_OMAPCTRL_SHIFT			6
+#define OMAP3430_EN_SAD2D				(1 << 3)
+#define OMAP3430_EN_SAD2D_SHIFT				3
 #define OMAP3430_EN_SDRC				(1 << 1)
 #define OMAP3430_EN_SDRC_SHIFT				1
 
@@ -176,6 +180,10 @@
 #define OMAP3430_EN_DES1				(1 << 0)
 #define OMAP3430_EN_DES1_SHIFT				0
 
+/* CM_ICLKEN3_CORE */
+#define OMAP3430_EN_MAD2D_SHIFT				3
+#define OMAP3430_EN_MAD2D				(1 << 3)
+
 /* CM_FCLKEN3_CORE specific bits */
 #define OMAP3430ES2_EN_TS_SHIFT				1
 #define OMAP3430ES2_EN_TS_MASK				(1 << 1)
@@ -231,6 +239,8 @@
 #define OMAP3430ES2_ST_CPEFUSE_MASK			(1 << 0)
 
 /* CM_AUTOIDLE1_CORE */
+#define OMAP3430_AUTO_MODEM				(1 << 31)
+#define OMAP3430_AUTO_MODEM_SHIFT			31
 #define OMAP3430ES2_AUTO_MMC3				(1 << 30)
 #define OMAP3430ES2_AUTO_MMC3_SHIFT			30
 #define OMAP3430ES2_AUTO_ICR				(1 << 29)
@@ -287,6 +297,8 @@
 #define OMAP3430_AUTO_HSOTGUSB_SHIFT			4
 #define OMAP3430ES1_AUTO_D2D				(1 << 3)
 #define OMAP3430ES1_AUTO_D2D_SHIFT			3
+#define OMAP3430_AUTO_SAD2D				(1 << 3)
+#define OMAP3430_AUTO_SAD2D_SHIFT			3
 #define OMAP3430_AUTO_SSI				(1 << 0)
 #define OMAP3430_AUTO_SSI_SHIFT				0
 
@@ -308,6 +320,8 @@
 #define	OMAP3430ES2_AUTO_USBTLL				(1 << 2)
 #define OMAP3430ES2_AUTO_USBTLL_SHIFT			2
 #define OMAP3430ES2_AUTO_USBTLL_MASK			(1 << 2)
+#define OMAP3430_AUTO_MAD2D_SHIFT			3
+#define OMAP3430_AUTO_MAD2D				(1 << 3)
 
 /* CM_CLKSEL_CORE */
 #define OMAP3430_CLKSEL_SSI_SHIFT			8
arch/arm/mach-omap2/pm34xx.c +23 -2
index 24a146c..a7734c7 100644
@@ -421,14 +421,32 @@ static void __init omap3_iva_idle(void)
 			  OMAP3430_IVA2_MOD, RM_RSTCTRL);
 }
 
-static void __init prcm_setup_regs(void)
+static void __init omap3_d2d_idle(void)
 {
+	u16 mask, padconf;
+
+	/* In a stand alone OMAP3430 where there is not a stacked
+	 * modem for the D2D Idle Ack and D2D MStandby must be pulled
+	 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
+	 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
+	mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
+	padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
+	padconf |= mask;
+	omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
+
+	padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
+	padconf |= mask;
+	omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
+
 	/* reset modem */
 	prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON |
 			  OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST,
 			  CORE_MOD, RM_RSTCTRL);
 	prm_write_mod_reg(0, CORE_MOD, RM_RSTCTRL);
+}
 
+static void __init prcm_setup_regs(void)
+{
 	/* XXX Reset all wkdeps. This should be done when initializing
 	 * powerdomains */
 	prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
@@ -448,6 +466,7 @@ static void __init prcm_setup_regs(void)
 	 * Note that in the long run this should be done by clockfw
 	 */
 	cm_write_mod_reg(
+		OMAP3430_AUTO_MODEM |
 		OMAP3430ES2_AUTO_MMC3 |
 		OMAP3430ES2_AUTO_ICR |
 		OMAP3430_AUTO_AES2 |
@@ -475,7 +494,7 @@ static void __init prcm_setup_regs(void)
 		OMAP3430_AUTO_OMAPCTRL |
 		OMAP3430ES1_AUTO_FSHOSTUSB |
 		OMAP3430_AUTO_HSOTGUSB |
-		OMAP3430ES1_AUTO_D2D | /* This is es1 only */
+		OMAP3430_AUTO_SAD2D |
 		OMAP3430_AUTO_SSI,
 		CORE_MOD, CM_AUTOIDLE1);
 
@@ -489,6 +508,7 @@ static void __init prcm_setup_regs(void)
 
 	if (omap_rev() > OMAP3430_REV_ES1_0) {
 		cm_write_mod_reg(
+			OMAP3430_AUTO_MAD2D |
 			OMAP3430ES2_AUTO_USBTLL,
 			CORE_MOD, CM_AUTOIDLE3);
 	}
@@ -582,6 +602,7 @@ static void __init prcm_setup_regs(void)
 			  OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
 
 	omap3_iva_idle();
+	omap3_d2d_idle();
 }
 
 static int __init pwrdms_setup(struct powerdomain *pwrdm)
arch/arm/plat-omap/include/mach/control.h +4 -0
index a9f05e5..fcc5a9b 100644
@@ -144,6 +144,10 @@
 #define OMAP343X_CONTROL_PBIAS_LITE	(OMAP2_CONTROL_GENERAL + 0x02b0)
 #define OMAP343X_CONTROL_TEMP_SENSOR	(OMAP2_CONTROL_GENERAL + 0x02b4)
 
+/* 34xx D2D idle-related pins, handled by PM core */
+#define OMAP3_PADCONF_SAD2D_MSTANDBY   0x250
+#define OMAP3_PADCONF_SAD2D_IDLEACK    0x254
+
 /*
  * REVISIT: This list of registers is not comprehensive - there are more
  * that should be added.
Signature · 1 line
1.6.2.2
#7 lore raw

PATCH 7/11 OMAP3: PM: D2D clockdomain supports SW supervised transitions

---
 arch/arm/mach-omap2/clockdomains.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/clockdomains.h +1 -1
index 281d5da..fe319ae 100644
@@ -195,7 +195,7 @@ static struct clockdomain sgx_clkdm = {
 static struct clockdomain d2d_clkdm = {
 	.name		= "d2d_clkdm",
 	.pwrdm		= { .name = "core_pwrdm" },
-	.flags		= CLKDM_CAN_HWSUP,
+	.flags		= CLKDM_CAN_HWSUP_SWSUP,
 	.clktrctrl_mask = OMAP3430ES1_CLKTRCTRL_D2D_MASK,
 	.omap_chip	= OMAP_CHIP_INIT(CHIP_IS_OMAP3430),
 };
Signature · 1 line
1.6.2.2
#8 lore raw

PATCH 8/11 OMAP3: PM: Ensure MUSB block can idle when driver not loaded

From: Peter 'p2' De Schrijver <[email protected]>

Otherwise, bootloaders may leave MUSB in a state which prevents retention.

---
 arch/arm/mach-omap2/usb-musb.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/usb-musb.c +6 -0
index 215d463..57e857e 100644
@@ -31,6 +31,8 @@
 #include <mach/mux.h>
 #include <mach/usb.h>
 
+#define OTG_SYSCONFIG	(OMAP34XX_HSUSB_OTG_BASE + 0x404)
+
 static struct resource musb_resources[] = {
 	[0] = { /* start and end set dynamically */
 		.flags	= IORESOURCE_MEM,
@@ -183,4 +185,8 @@ void __init usb_musb_init(void)
 		printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
 		return;
 	}
+
+	/* Ensure force-idle mode for OTG controller */
+	if (cpu_is_omap34xx())
+		omap_writel(0, OTG_SYSCONFIG);
 }
Signature · 1 line
1.6.2.2
#9 lore raw

PATCH 9/11 OMAP3: PM: Ensure PRCM interrupts are cleared at boot

---
 arch/arm/mach-omap2/pm34xx.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/pm34xx.c +3 -0
index a7734c7..9b29414 100644
@@ -601,6 +601,9 @@ static void __init prcm_setup_regs(void)
 	prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
 			  OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
 
+	/* Clear any pending PRCM interrupts */
+	prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
+
 	omap3_iva_idle();
 	omap3_d2d_idle();
 }
Signature · 1 line
1.6.2.2
#10 lore raw

PATCH 10/11 OMAP3: PM: Clear pending PRCM reset flags on init

---
 arch/arm/mach-omap2/pm34xx.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/pm34xx.c +9 -0
index 9b29414..7ed01e5 100644
@@ -601,6 +601,15 @@ static void __init prcm_setup_regs(void)
 	prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
 			  OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
 
+	/* Clear any pending 'reset' flags */
+	prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
+	prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
+	prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, RM_RSTST);
+	prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, RM_RSTST);
+	prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, RM_RSTST);
+	prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, RM_RSTST);
+	prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, RM_RSTST);
+
 	/* Clear any pending PRCM interrupts */
 	prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
 
Signature · 1 line
1.6.2.2
#11 lore raw

PATCH 11/11 OMAP3: PM: prevent module wakeups from waking IVA2

By default, prevent functional wakeups from inside a module from waking up the IVA2. Let DSP Bridge code handle this when loaded.

---
 arch/arm/mach-omap2/pm34xx.c |    6 ++++++
 arch/arm/mach-omap2/prm.h    |    2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/pm34xx.c +6 -0
index 7ed01e5..22d686e 100644
@@ -601,6 +601,12 @@ static void __init prcm_setup_regs(void)
 	prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
 			  OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
 
+	/* Don't attach IVA interrupts */
+	prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
+	prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
+	prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
+	prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
+
 	/* Clear any pending 'reset' flags */
 	prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
 	prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
arch/arm/mach-omap2/prm.h +2 -0
index 7c8e0c4..9937e28 100644
@@ -203,9 +203,11 @@
 
 #define OMAP3430_PM_MPUGRPSEL				0x00a4
 #define OMAP3430_PM_MPUGRPSEL1				OMAP3430_PM_MPUGRPSEL
+#define OMAP3430ES2_PM_MPUGRPSEL3			0x00f8
 
 #define OMAP3430_PM_IVAGRPSEL				0x00a8
 #define OMAP3430_PM_IVAGRPSEL1				OMAP3430_PM_IVAGRPSEL
+#define OMAP3430ES2_PM_IVAGRPSEL3			0x00f4
 
 #define OMAP3430_PM_PREPWSTST				0x00e8
 
Signature · 1 line
1.6.2.2
#12 lore raw

Re: [PATCH 08/11] OMAP3: PM: Ensure MUSB block can idle when driver not loaded

In reply to Kevin Hilman
Quoted 2 lines · Kevin Hilman

Otherwise, bootloaders may leave MUSB in a state which prevents retention.

Hmm, so what happens if a boot loader has touched this MUSB thing, but the kernel which is being run doesn't have CONFIG_USB_MUSB_SOC enabled?

#13 lore raw

Re: [PATCH 08/11] OMAP3: PM: Ensure MUSB block can idle when driver not loaded

Quoted 6 lines · Russell King - ARM Linux
Quoted 2 lines · Kevin Hilman

Otherwise, bootloaders may leave MUSB in a state which prevents retention.

Hmm, so what happens if a boot loader has touched this MUSB thing, but the kernel which is being run doesn't have CONFIG_USB_MUSB_SOC enabled?

Then the OMAP will not be able to hit retention.

That Makefile change happened after this series was initially made. I think we should change the Makefile back to always compile usb-musb.c and move the #ifdef CONFIG_USB_MUSB_SOC into usb-musb.c

Tony, any objections?

Kevin

maintainer
#14 lore raw

Re: [PATCH 08/11] OMAP3: PM: Ensure MUSB block can idle when driver not loaded

Quoted 9 lines · Kevin Hilman
Quoted 6 lines · Russell King - ARM Linux
Quoted 2 lines · Kevin Hilman

Otherwise, bootloaders may leave MUSB in a state which prevents retention.

Hmm, so what happens if a boot loader has touched this MUSB thing, but the kernel which is being run doesn't have CONFIG_USB_MUSB_SOC enabled?

Quoted 7 lines

Then the OMAP will not be able to hit retention.

That Makefile change happened after this series was initially made. I think we should change the Makefile back to always compile usb-musb.c and move the #ifdef CONFIG_USB_MUSB_SOC into usb-musb.c

Tony, any objections?

Sounds good to me, I like patches that make things behave in a predictable way.

We already have enough of these mysterious problems where "the same kernel behaves in a different way on my board" when some registers are only tweaked in the bootloader.

Regards,

Tony

#15 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

In reply to Kevin Hilman
Quoted 11 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Following this will be a series of patches from the 'PM branch' of the linux-omap tree to add full PM hardware support from the linux-omap tree.

Much of this PM core code was written by Jouni Hogander with significant contributions from Paul Walmsley as well as many others from Nokia, Texas Instruments and linux-omap community.

Overall comment, I think we need to rework the idle support code so that enable_hlt/disable_hlt can be used even when pm_idle has been overridden, rather than OMAP going off and inventing its own mechanisms.

Quoted 37 lines
arch/arm/mach-omap2/pm24xx.c new file +31 -0
new file mode 100644
index 0000000..2a2d1a3
@@ -0,0 +1,557 @@
+/*
+ * OMAP2 Power Management Routines
+ *
+ * Copyright (C) 2005 Texas Instruments, Inc.
+ * Copyright (C) 2006-2008 Nokia Corporation
+ *
+ * Written by:
+ * Richard Woodruff <[email protected]>
+ * Tony Lindgren
+ * Juha Yrjola
+ * Amit Kucheria <[email protected]>
+ * Igor Stoppa <[email protected]>
+ *
+ * Based on pm.c for omap1
+ *
+ * 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.
+ */
+
+#include <linux/suspend.h>
+#include <linux/sched.h>
+#include <linux/proc_fs.h>
+#include <linux/interrupt.h>
+#include <linux/sysfs.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/time.h>

arch/arm/mach-omap2/pm24xx.c line 41

Quoted 10 lines
arch/arm/mach-omap2/pm24xx.c new file +10 -0
+
+#include <asm/mach/time.h>
+#include <asm/mach/irq.h>
+#include <asm/mach-types.h>
+
+#include <mach/irqs.h>
+#include <mach/clock.h>
+#include <mach/sram.h>
+#include <mach/control.h>
+#include <mach/gpio.h>

Should be linux/gpio.h

Quoted 15 lines
arch/arm/mach-omap2/pm24xx.c new file +15 -0
+/*
+ * Note that you can use clock_event_device->min_delta_ns if you want to
+ * avoid reprogramming timer too often when using CONFIG_NO_HZ.
+ */
+static void omap2_pm_idle(void)
+{
+	local_irq_disable();
+	local_fiq_disable();
+
+	if (!omap2_can_sleep()) {
+		if (!atomic_read(&sleep_block) && omap2_irq_pending())
+			goto out;
+		omap2_enter_mpu_retention();
+		goto out;
+	}

arch/arm/mach-omap2/pm24xx.c line 291

Quoted 10 lines
arch/arm/mach-omap2/pm24xx.c new file +10 -0
+
+	if (omap2_irq_pending())
+		goto out;
+
+	omap2_enter_full_retention();
+
+out:
+	local_fiq_enable();
+	local_irq_enable();
+}

It's totally unclear what the comment above the function has to do with the function itself.

Quoted 21 lines
arch/arm/mach-omap2/pm34xx.c new file +15 -0
new file mode 100644
index 0000000..0fb6bec
@@ -0,0 +1,607 @@
+/*
+ * OMAP3 Power Management Routines
+ *
+ * Copyright (C) 2006-2008 Nokia Corporation
+ * Tony Lindgren <[email protected]>
+ * Jouni Hogander
+ *
+ * Copyright (C) 2005 Texas Instruments, Inc.
+ * Richard Woodruff <[email protected]>
+ *
+ * Based on pm.c for omap1
+ *
+ * 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.

arch/arm/mach-omap2/pm34xx.c line 25

Quoted 10 lines
arch/arm/mach-omap2/pm34xx.c new file +10 -0
+ */
+
+#include <linux/pm.h>
+#include <linux/suspend.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/err.h>
+
+#include <mach/gpio.h>

Should be linux/gpio.h

arch/arm/mach-omap2/pm34xx.c line 278

Quoted 10 lines
arch/arm/mach-omap2/pm34xx.c new file +10 -0
+static void omap3_pm_idle(void)
+{
+	local_irq_disable();
+	local_fiq_disable();
+
+	if (!omap3_can_sleep())
+		goto out;
+
+	if (omap_irq_pending())
+		goto out;

So what happens if an IRQ becomes pending at this precise point?

Quoted 33 lines
arch/arm/mach-omap2/pm34xx.c new file +33 -0
+
+	omap_sram_idle();
+
+out:
+	local_fiq_enable();
+	local_irq_enable();
+}
+	/* IRQ mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x12
+	msr    cpsr, r0	/*go into IRQ mode*/
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM*/
+	mov    sp, r4	/*update the SP */
+	mov    lr, r5	/*update the LR */
+	msr    spsr, r6	/*update the SPSR */
+
+	/* ABORT mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x17
+	msr    cpsr, r0	/* go into ABORT mode */
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM */
+	mov    sp, r4		/*update the SP */
+	mov    lr, r5		/*update the LR */
+	msr    spsr, r6		/*update the SPSR */
+
+	/* UNDEEF mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x1B
+	msr    cpsr, r0		/*go into UNDEF mode */
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM */
+	mov    sp, r4		/*update the SP*/
+	mov    lr, r5		/*update the LR*/
+	msr    spsr, r6		/*update the SPSR*/

arch/arm/mach-omap2/pm34xx.c line 78

Quoted 10 lines
arch/arm/mach-omap2/pm34xx.c new file +10 -0
+
+	/* SYSTEM (USER) mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x1F
+	msr    cpsr, r0		/*go into USR mode */
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM*/
+	mov    sp, r4		/*update the SP */
+	mov    lr, r5		/*update the LR */
+	msr    spsr, r6		/*update the SPSR */
+	msr    cpsr, r7		/*back to original mode*/

There is a function which re-initializes the abort mode registers already - cpu_init(). Please use that if possible instead.

#16 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Following this will be a series of patches from the 'PM branch' of the linux-omap tree to add full PM hardware support from the linux-omap tree.

Quoted 7 lines
Quoted 3 lines

Much of this PM core code was written by Jouni Hogander with significant contributions from Paul Walmsley as well as many others from Nokia, Texas Instruments and linux-omap community.

Overall comment, I think we need to rework the idle support code so that enable_hlt/disable_hlt can be used even when pm_idle has been overridden, rather than OMAP going off and inventing its own mechanisms.

Would adding:

	if (hlt_counter)
		cpu_relax();

to the beginning of omap*_pm_idle functions be sufficient? That will at least allow the hlt stuff to behave as expected.

The only thing the OMAP /sys/power/sleep_while_idle hook adds to this functionality is the ability to control this from sysfs.

Any objections to /sys/power/enable_hlt?

Quoted 41 lines
Quoted 41 lines
arch/arm/mach-omap2/pm24xx.c new file +35 -0
new file mode 100644
index 0000000..2a2d1a3
@@ -0,0 +1,557 @@
+/*
+ * OMAP2 Power Management Routines
+ *
+ * Copyright (C) 2005 Texas Instruments, Inc.
+ * Copyright (C) 2006-2008 Nokia Corporation
+ *
+ * Written by:
+ * Richard Woodruff <[email protected]>
+ * Tony Lindgren
+ * Juha Yrjola
+ * Amit Kucheria <[email protected]>
+ * Igor Stoppa <[email protected]>
+ *
+ * Based on pm.c for omap1
+ *
+ * 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.
+ */
+
+#include <linux/suspend.h>
+#include <linux/sched.h>
+#include <linux/proc_fs.h>
+#include <linux/interrupt.h>
+#include <linux/sysfs.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/time.h>
+
+#include <asm/mach/time.h>
+#include <asm/mach/irq.h>
+#include <asm/mach-types.h>
Quoted 8 lines

arch/arm/mach-omap2/pm24xx.c line 41

Quoted 6 lines
arch/arm/mach-omap2/pm24xx.c new file +6 -0
+
+#include <mach/irqs.h>
+#include <mach/clock.h>
+#include <mach/sram.h>
+#include <mach/control.h>
+#include <mach/gpio.h>

Should be linux/gpio.h

Ack

Quoted 20 lines
Quoted 20 lines
arch/arm/mach-omap2/pm24xx.c new file +20 -0
+/*
+ * Note that you can use clock_event_device->min_delta_ns if you want to
+ * avoid reprogramming timer too often when using CONFIG_NO_HZ.
+ */
+static void omap2_pm_idle(void)
+{
+	local_irq_disable();
+	local_fiq_disable();
+
+	if (!omap2_can_sleep()) {
+		if (!atomic_read(&sleep_block) && omap2_irq_pending())
+			goto out;
+		omap2_enter_mpu_retention();
+		goto out;
+	}
+
+	if (omap2_irq_pending())
+		goto out;
+
+	omap2_enter_full_retention();
Quoted 8 lines

arch/arm/mach-omap2/pm24xx.c line 291

Quoted 5 lines
arch/arm/mach-omap2/pm24xx.c new file +5 -0
+
+out:
+	local_fiq_enable();
+	local_irq_enable();
+}

It's totally unclear what the comment above the function has to do with the function itself.

Indeed. Will be removed.

Quoted 25 lines
Quoted 25 lines
arch/arm/mach-omap2/pm34xx.c new file +19 -0
new file mode 100644
index 0000000..0fb6bec
@@ -0,0 +1,607 @@
+/*
+ * OMAP3 Power Management Routines
+ *
+ * Copyright (C) 2006-2008 Nokia Corporation
+ * Tony Lindgren <[email protected]>
+ * Jouni Hogander
+ *
+ * Copyright (C) 2005 Texas Instruments, Inc.
+ * Richard Woodruff <[email protected]>
+ *
+ * Based on pm.c for omap1
+ *
+ * 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.
+ */
+
+#include <linux/pm.h>
+#include <linux/suspend.h>
Quoted 8 lines

arch/arm/mach-omap2/pm34xx.c line 25

Quoted 6 lines
arch/arm/mach-omap2/pm34xx.c new file +6 -0
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/err.h>
+
+#include <mach/gpio.h>

Should be linux/gpio.h

Ack

Quoted 4 lines
Quoted 4 lines
arch/arm/mach-omap2/pm34xx.c new file +4 -0
+static void omap3_pm_idle(void)
+{
+	local_irq_disable();
+	local_fiq_disable();
Quoted 8 lines

arch/arm/mach-omap2/pm34xx.c line 278

Quoted 6 lines
arch/arm/mach-omap2/pm34xx.c new file +6 -0
+
+	if (!omap3_can_sleep())
+		goto out;
+
+	if (omap_irq_pending())
+		goto out;

So what happens if an IRQ becomes pending at this precise point?

Then it gets missed this time, and will be triggered upon wakeup. If it's a wakeup-capable interrupt, then it will wake the system immediately.

In subsequent series of the PM branch, this will be going away in favor of using the [enable|disable]_irq_wake() and the lazy IRQ disabling features.

Quoted 38 lines
Quoted 38 lines
arch/arm/mach-omap2/pm34xx.c new file +38 -0
+
+	omap_sram_idle();
+
+out:
+	local_fiq_enable();
+	local_irq_enable();
+}
+	/* IRQ mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x12
+	msr    cpsr, r0	/*go into IRQ mode*/
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM*/
+	mov    sp, r4	/*update the SP */
+	mov    lr, r5	/*update the LR */
+	msr    spsr, r6	/*update the SPSR */
+
+	/* ABORT mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x17
+	msr    cpsr, r0	/* go into ABORT mode */
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM */
+	mov    sp, r4		/*update the SP */
+	mov    lr, r5		/*update the LR */
+	msr    spsr, r6		/*update the SPSR */
+
+	/* UNDEEF mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x1B
+	msr    cpsr, r0		/*go into UNDEF mode */
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM */
+	mov    sp, r4		/*update the SP*/
+	mov    lr, r5		/*update the LR*/
+	msr    spsr, r6		/*update the SPSR*/
+
+	/* SYSTEM (USER) mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x1F
+	msr    cpsr, r0		/*go into USR mode */
Quoted 8 lines

arch/arm/mach-omap2/pm34xx.c line 78

Quoted 5 lines
arch/arm/mach-omap2/pm34xx.c new file +5 -0
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM*/
+	mov    sp, r4		/*update the SP */
+	mov    lr, r5		/*update the LR */
+	msr    spsr, r6		/*update the SPSR */
+	msr    cpsr, r7		/*back to original mode*/

There is a function which re-initializes the abort mode registers already - cpu_init(). Please use that if possible instead.

OK, will investigate.

Kevin

#17 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 19 lines · Kevin Hilman
Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Following this will be a series of patches from the 'PM branch' of the linux-omap tree to add full PM hardware support from the linux-omap tree.

Quoted 7 lines
Quoted 3 lines

Much of this PM core code was written by Jouni Hogander with significant contributions from Paul Walmsley as well as many others from Nokia, Texas Instruments and linux-omap community.

Overall comment, I think we need to rework the idle support code so that enable_hlt/disable_hlt can be used even when pm_idle has been overridden, rather than OMAP going off and inventing its own mechanisms.

Quoted 7 lines

Would adding:

	if (hlt_counter)
		cpu_relax();

to the beginning of omap*_pm_idle functions be sufficient? That will at least allow the hlt stuff to behave as expected.

Yes, but the comment was also directed at the other functions which increment/decrement that atomic_t variable to enable/disable sleep mode.

Quoted 4 lines

The only thing the OMAP /sys/power/sleep_while_idle hook adds to this functionality is the ability to control this from sysfs.

Any objections to /sys/power/enable_hlt?

That seems to be rather dangerous, even with your atomic based code which bugs if the count goes below zero.

The problem here is that such an interface is extremely fragile. Consider what happens if a program disables HLT, and then gets killed off for some reason. How does this reference get balanced again?

I think a better solution would be a char device driver which has to be kept open as long as a reference is held. When userspace closes it (be that because the program has exited, been killed, etc) you can drop any pending references.

#18 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 22 lines · Russell King - ARM Linux
Quoted 21 lines · Kevin Hilman
Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Following this will be a series of patches from the 'PM branch' of the linux-omap tree to add full PM hardware support from the linux-omap tree.

Quoted 7 lines
Quoted 3 lines

Much of this PM core code was written by Jouni Hogander with significant contributions from Paul Walmsley as well as many others from Nokia, Texas Instruments and linux-omap community.

Overall comment, I think we need to rework the idle support code so that enable_hlt/disable_hlt can be used even when pm_idle has been overridden, rather than OMAP going off and inventing its own mechanisms.

Would adding:

Quoted 8 lines
Quoted 5 lines
	if (hlt_counter)
		cpu_relax();

to the beginning of omap*_pm_idle functions be sufficient? That will at least allow the hlt stuff to behave as expected.

Yes, but the comment was also directed at the other functions which increment/decrement that atomic_t variable to enable/disable sleep mode.

Ah, right. The sleep_block stuff is only used in OMAP2, we don't use that anymore in OMAP3. In fact, even OMAP2 users of this should be updated to use the OMAP PM layer, so I'll just drop the sleep_block hooks.

Quoted 7 lines
Quoted 4 lines

The only thing the OMAP /sys/power/sleep_while_idle hook adds to this functionality is the ability to control this from sysfs.

Any objections to /sys/power/enable_hlt?

That seems to be rather dangerous, even with your atomic based code which bugs if the count goes below zero.

Atomic sleep_block code to be removed.

Quoted 8 lines

The problem here is that such an interface is extremely fragile. Consider what happens if a program disables HLT, and then gets killed off for some reason. How does this reference get balanced again?

I think a better solution would be a char device driver which has to be kept open as long as a reference is held. When userspace closes it (be that because the program has exited, been killed, etc) you can drop any pending references.

OK, this interface is not intended for users/applications. It is intended only for OMAP PM developers who are developing the PM code and want to prevent idle for various reasons during development. It is not intended for productions systems.

What about leaving /sys/power/sleep_while_idle but only if CONFIG_PM_DEBUG=y?

Kevin

#19 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 9 lines · Kevin Hilman
Quoted 8 lines

The problem here is that such an interface is extremely fragile. Consider what happens if a program disables HLT, and then gets killed off for some reason. How does this reference get balanced again?

I think a better solution would be a char device driver which has to be kept open as long as a reference is held. When userspace closes it (be that because the program has exited, been killed, etc) you can drop any pending references.

Quoted 7 lines

OK, this interface is not intended for users/applications. It is intended only for OMAP PM developers who are developing the PM code and want to prevent idle for various reasons during development. It is not intended for productions systems.

What about leaving /sys/power/sleep_while_idle but only if CONFIG_PM_DEBUG=y?

Sounds like debugfs is the good place for this then.

Signature · 6 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#20 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 15 lines · Artem Bityutskiy
Quoted 14 lines · Kevin Hilman
Quoted 8 lines

The problem here is that such an interface is extremely fragile. Consider what happens if a program disables HLT, and then gets killed off for some reason. How does this reference get balanced again?

I think a better solution would be a char device driver which has to be kept open as long as a reference is held. When userspace closes it (be that because the program has exited, been killed, etc) you can drop any pending references.

OK, this interface is not intended for users/applications. It is intended only for OMAP PM developers who are developing the PM code and want to prevent idle for various reasons during development. It is not intended for productions systems.

Quoted 5 lines
Quoted 2 lines

What about leaving /sys/power/sleep_while_idle but only if CONFIG_PM_DEBUG=y?

Sounds like debugfs is the good place for this then.

Sound OK to me.

Kevin

#21 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

In reply to Russell King - ARM Linux
Quoted 22 lines · Russell King - ARM Linux
Quoted 21 lines · Kevin Hilman
Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Following this will be a series of patches from the 'PM branch' of the linux-omap tree to add full PM hardware support from the linux-omap tree.

Quoted 7 lines
Quoted 3 lines

Much of this PM core code was written by Jouni Hogander with significant contributions from Paul Walmsley as well as many others from Nokia, Texas Instruments and linux-omap community.

Overall comment, I think we need to rework the idle support code so that enable_hlt/disable_hlt can be used even when pm_idle has been overridden, rather than OMAP going off and inventing its own mechanisms.

Would adding:

Quoted 9 lines
Quoted 5 lines
	if (hlt_counter)
		cpu_relax();

to the beginning of omap*_pm_idle functions be sufficient? That will at least allow the hlt stuff to behave as expected.

Yes, but the comment was also directed at the other functions which increment/decrement that atomic_t variable to enable/disable sleep mode.

Russell,

Do you have a preference in how to export the hlt_counter to platform-specific code?

The patch below creates a can_hlt() function that can be called from platform-specific idle code.

Kevin

Quoted 1 line

From 23c802a0a1e9bb24ca51af9cf18b972590f8d1dc Mon Sep 17 00:00:00 2001

From: Kevin Hilman <[email protected]>
Date: Tue, 19 May 2009 11:34:12 -0700
Subject: [PATCH] ARM: add can_hlt() for platform PM code to check before idling

When platform-specific code overrides pm_idle, the hlt_counter is no longer used. Create a can_hlt() check which returns the hlt_counter so platform code can check it and thus honor the requests of enable_hlt()/disable_hlt() users.

---
 arch/arm/include/asm/system.h |    1 +
 arch/arm/kernel/process.c     |    7 +++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
arch/arm/include/asm/system.h +1 -0
index bd4dc8e..ff9e2dd 100644
@@ -313,6 +313,7 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
 
 extern void disable_hlt(void);
 extern void enable_hlt(void);
+extern int can_hlt(void);
 
 #include <asm-generic/cmpxchg-local.h>
 
arch/arm/kernel/process.c +7 -0
index c3265a2..1b414b8 100644
@@ -68,6 +68,13 @@ void enable_hlt(void)
 
 EXPORT_SYMBOL(enable_hlt);
 
+int can_hlt(void)
+{
+	return !hlt_counter;
+}
+
+EXPORT_SYMBOL(can_hlt);
+
 static int __init nohlt_setup(char *__unused)
 {
 	hlt_counter = 1;
Signature · 1 line
1.6.2.2
#22 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 30 lines · Kevin Hilman
Quoted 28 lines · Russell King - ARM Linux
Quoted 26 lines · Kevin Hilman
Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Following this will be a series of patches from the 'PM branch' of the linux-omap tree to add full PM hardware support from the linux-omap tree.

Quoted 7 lines
Quoted 3 lines

Much of this PM core code was written by Jouni Hogander with significant contributions from Paul Walmsley as well as many others from Nokia, Texas Instruments and linux-omap community.

Overall comment, I think we need to rework the idle support code so that enable_hlt/disable_hlt can be used even when pm_idle has been overridden, rather than OMAP going off and inventing its own mechanisms.

Would adding:

	if (hlt_counter)
		cpu_relax();

to the beginning of omap*_pm_idle functions be sufficient? That will at least allow the hlt stuff to behave as expected.

Quoted 8 lines
Quoted 3 lines

Yes, but the comment was also directed at the other functions which increment/decrement that atomic_t variable to enable/disable sleep mode.

Russell,

Do you have a preference in how to export the hlt_counter to platform-specific code?

Sorry, I haven't had time to look at this, and the work I did to change the idle loop got lost when I last re-built my git tree.

But... your patch isn't what I was meaning. I was meaning to avoid calling the idle function (_any_ idle function) if hlt_counter was non-zero.

#23 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

In reply to Russell King - ARM Linux

[ adding Richard W. to To: since he can probably shed some light here ]

Quoted 4 lines · Russell King - ARM Linux
Quoted 3 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

[...]

[excerpt of sleep34xx.S]

Quoted 31 lines
Quoted 31 lines
arch/arm/mach-omap2/sleep34xx.S new file +31 -0
+	/* IRQ mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x12
+	msr    cpsr, r0	/*go into IRQ mode*/
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM*/
+	mov    sp, r4	/*update the SP */
+	mov    lr, r5	/*update the LR */
+	msr    spsr, r6	/*update the SPSR */
+
+	/* ABORT mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x17
+	msr    cpsr, r0	/* go into ABORT mode */
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM */
+	mov    sp, r4		/*update the SP */
+	mov    lr, r5		/*update the LR */
+	msr    spsr, r6		/*update the SPSR */
+
+	/* UNDEEF mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x1B
+	msr    cpsr, r0		/*go into UNDEF mode */
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM */
+	mov    sp, r4		/*update the SP*/
+	mov    lr, r5		/*update the LR*/
+	msr    spsr, r6		/*update the SPSR*/
+
+	/* SYSTEM (USER) mode */
+	bic    r0, r7, #0x1F
+	orr    r0, r0, #0x1F
+	msr    cpsr, r0		/*go into USR mode */
Quoted 8 lines

arch/arm/mach-omap2/sleep34xx.S line 231

Quoted 5 lines
arch/arm/mach-omap2/sleep34xx.S new file +5 -0
+	ldmia  r3!,{r4-r6}	/*load the SP and LR from SDRAM*/
+	mov    sp, r4		/*update the SP */
+	mov    lr, r5		/*update the LR */
+	msr    spsr, r6		/*update the SPSR */
+	msr    cpsr, r7		/*back to original mode*/

There is a function which re-initializes the abort mode registers already - cpu_init(). Please use that if possible instead.

Upon a quick glance, using cpu_init() would not cover all the things that this code does. cpu_init() only handles the init of sp for the various modes, where this code saves/resores all the banked registers:
sp, lr and spsr as well as r8-r12 of FIQ mode.

The question in my mind however is whether the lr and spsr need to be saved/restored? Do we really need to preserve the context of these handlers across idle? Presumably we should not hit idle/suspend in the middle of one of these handlers, so do we need to save anything other than the stp? Maybe Richard can shed some light here as to why that was added.

Kevin

#24 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 9 lines · Kevin Hilman

[ adding Richard W. to To: since he can probably shed some light here ]

Quoted 4 lines · Russell King - ARM Linux
Quoted 3 lines · Kevin Hilman

This patch is to sync the core linux-omap PM code with mainline. This code has evolved and been used for a while the linux-omap tree, but the attempt here is to finally get this into mainline.

Quoted 6 lines

[...]

Upon a quick glance, using cpu_init() would not cover all the things that this code does. cpu_init() only handles the init of sp for the various modes, where this code saves/resores all the banked registers:
sp, lr and spsr as well as r8-r12 of FIQ mode.

It doesn't touch sp, lr and spsr for the other modes because there's no requirement to do so. Think about it for a moment.

Is there any point to saving LR and SPSR for the abort, FIQ and IRQ modes? No - LR and SPSR are overwritten by the hardware immediately upon entry to the relevent mode via an exception.

What about SP? We use SP in the vector entry code, and we need to ensure that this is re-initialized. We never change their value, so we know that these are constant, and therefore if we initialize them once we can repeat the same initialization to restore their values when those values are lost. This is precisely what cpu_init() does.

As for FIQ r8-r12, yes this is missing, and it's something that needs to be handled by _every_ platform which puts the CPU into low power state, be that PXA, S3C2410, and so forth. We have code to allow the FIQ vector to be managed, and as yet those architectures which do support sleep modes don't use FIQ mode, hence why there's nothing for it yet. Feel free to add the necessary suspend/resume code to (eg) arch/arm/kernel/fiq.c to fill this hole though.

Lastly is system mode. The kernel doesn't use system mode, and this mode doesn't exist in all CPUs (its marked as unpredictable on many older CPUs.) We need a _generic_ extension to support that mode _if_ it is used. Presently it is not used, and so we simply don't bother saving those registers.

Quoted 3 lines

The question in my mind however is whether the lr and spsr need to be saved/restored? Do we really need to preserve the context of these handlers across idle?

Idle is called essentially in process context, with the exception that it's SVC mode rather than user mode. That means no exception handlers will be running.

So I think you'll find cpu_init() does everything you require.

#25 lore raw

RE: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

In reply to Kevin Hilman
Quoted 6 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Monday, May 18, 2009 12:09 PM
To: Russell King - ARM Linux; Woodruff, Richard

Quoted 7 lines
Quoted 2 lines

There is a function which re-initializes the abort mode registers already - cpu_init(). Please use that if possible instead.

Upon a quick glance, using cpu_init() would not cover all the things that this code does. cpu_init() only handles the init of sp for the various modes, where this code saves/resores all the banked registers:
sp, lr and spsr as well as r8-r12 of FIQ mode.

cpu_init() is not yet accessible at the point this code is running. You could reduce the context perhaps trying to optimize to what the Linux-ARM implementation is today or do a more generic save like is there now.

This code is copied into place from the .S code into SRAM. Its position independent and is not linked for this address. If you want to call functions outside of it you need to manually setup linkage.

Calling outside functions on the way _DOWN_ is ok. For instance in current TI reference code all cache flush is calling to kernel functions. This saves in space, duplication maintenance and is actually _much_ quicker as it executes from a cached address range. The cache flush code takes 770uS from kernel area and takes 2.2mS from sram (non-cached map).

Calling functions on the way _UP_ from wake is NOT easy (like the one you propose) as the MMU is not yet enabled. The MMU is enabled only below this. Calling cpu_init() is not do able here. Even if you dress up the calling pointer to the physical address, it won't work as cpu_init() makes a global variable dereferences (smp_processor_id & stacks[]).

Regards,
Richard W.

#26 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 1 line · Richard

cpu_init() is not yet accessible at the point this code is running.

Not at that _exact_ point, but there's no need what so ever for it to be at that exact point. There's nothing stopping a call to cpu_init() happening later. Much later.

Quoted 7 lines

You could reduce the context perhaps trying to optimize to what the Linux-ARM implementation is today or do a more generic save like is there now.

This code is copied into place from the .S code into SRAM. Its position independent and is not linked for this address. If you want to call functions outside of it you need to manually setup linkage.

I wouldn't want to.

Quoted 6 lines

Calling functions on the way _UP_ from wake is NOT easy (like the one you propose) as the MMU is not yet enabled. The MMU is enabled only below this. Calling cpu_init() is not do able here. Even if you dress up the calling pointer to the physical address, it won't work as cpu_init() makes a global variable dereferences (smp_processor_id & stacks[]).

As long as IRQs and FIQs are disabled, you are in a 100% predictable environment.

1. No IRQ or FIQ will be entered; if they are the CPU is buggy.
2. No data or prefetch abort will be entered _unless_ you purposely access some non-present memory (and you're not exactly going to start paging memory in with IRQs disabled.)

So restoring the abort and IRQ mode register state is just plain not necessary in your SRAM code.

Let's look at the code. Here are the pertinent bits from Kevin's patch:

static void omap3_pm_idle(void)

{
        local_irq_disable();
        local_fiq_disable();

        omap_sram_idle();

        local_fiq_enable();
        local_irq_enable();
}

static void omap_sram_idle(void)

{
        _omap_sram_idle(NULL, save_state);
}
        _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
                                         omap34xx_cpu_suspend_sz);
        pm_idle = omap3_pm_idle;

_omap_sram_idle() is the assembly code we're discussing, and here we're referring to its version in SRAM. From the above code, we can clearly see that this is entered with FIQs and IRQs disabled. So everything inside omap_sram_idle() is running in a well defined environment provided prefetch and data aborts don't happen.

There is nothing stopping this from becoming:

static void omap3_pm_idle(void)

{
        local_irq_disable();
        local_fiq_disable();

        omap_sram_idle();

+ cpu_init();

        local_fiq_enable();
        local_irq_enable();
}

and having the saving of IRQ, FIQ and abort mode registers removed from the SRAM code.

Other SoCs do precisely this - let's look at PXA:

        pxa_cpu_pm_fns->enter(state);
        cpu_init();

The call to the enter method essentially calls the core specific suspend function (eg, pxa25x_cpu_suspend()), which is an assembly function which ultimately ends up powering down the core resulting in full loss of state in the CPU. We seem to be able to avoid having to save the exception mode registers there.

The same thing is done with sa11x0 and Samsung SoCs.

I don't see any reason for OMAP to be "special" in this regard.

#27 lore raw

RE: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 10 lines

From: Russell King - ARM Linux [mailto:[email protected]]
Sent: Monday, May 18, 2009 3:25 PM

The call to the enter method essentially calls the core specific suspend function (eg, pxa25x_cpu_suspend()), which is an assembly function which ultimately ends up powering down the core resulting in full loss of state in the CPU. We seem to be able to avoid having to save the exception mode registers there.

Quoted 3 lines

The same thing is done with sa11x0 and Samsung SoCs.

I don't see any reason for OMAP to be "special" in this regard.

The code flow is:
- Wakeup event
- ARM reboots and uses SOC mask ROM context restore helper
- Mask ROM code jump to restore pointers with MMU OFF.
- Restore code resets ARM CortexA8 state
-*- Trustzone SMI calls are made to restore some secure state
- Jump back from SRAM to C code

The dangling question to me is if any of the cpu state is needed by the trustzone monitor code as a precondition. The doc's I have led me to believe its ok, but I've not verified this.

Regards,
Richard W.

#28 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 11 lines · Richard

The code flow is:
- Wakeup event
- ARM reboots and uses SOC mask ROM context restore helper
- Mask ROM code jump to restore pointers with MMU OFF.
- Restore code resets ARM CortexA8 state
-*- Trustzone SMI calls are made to restore some secure state
- Jump back from SRAM to C code

The dangling question to me is if any of the cpu state is needed by the trustzone monitor code as a precondition. The doc's I have led me to believe its ok, but I've not verified this.

There shouldn't be - it would be _really_ silly if the trustzone monitor had pre-requisits for the exception mode registers. There's no way that Linux's use of the exception mode registers is anywhere near the same as other OSes, and Linux's use of the exception mode registers has changed over time anyway. We make no promise that we'll keep the way we're using these registers today either.

So there are no external guarantees about what useful state the kernel puts into these registers. Having external code rely on some state there would itself be broken.

There's also the problem that if there was a dependency on the insecure exception mode registers from within the trusted environment, that'd surely be a rather big security problem in itself.

#29 lore raw

RE: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

Quoted 24 lines

From: Russell King - ARM Linux [mailto:[email protected]]
Sent: Monday, May 18, 2009 4:11 PM

Quoted 11 lines · Richard

The code flow is:
- Wakeup event
- ARM reboots and uses SOC mask ROM context restore helper
- Mask ROM code jump to restore pointers with MMU OFF.
- Restore code resets ARM CortexA8 state
-*- Trustzone SMI calls are made to restore some secure state
- Jump back from SRAM to C code

The dangling question to me is if any of the cpu state is needed by the trustzone monitor code as a precondition. The doc's I have led me to believe its ok, but I've not verified this.

There shouldn't be - it would be _really_ silly if the trustzone monitor had pre-requisits for the exception mode registers. There's no way that Linux's use of the exception mode registers is anywhere near the same as other OSes, and Linux's use of the exception mode registers has changed over time anyway. We make no promise that we'll keep the way we're using these registers today either.

Quoted 7 lines

So there are no external guarantees about what useful state the kernel puts into these registers. Having external code rely on some state there would itself be broken.

There's also the problem that if there was a dependency on the insecure exception mode registers from within the trusted environment, that'd surely be a rather big security problem in itself.

Yes those are reasonable comments.

In OMAP2 time security required nasty hacks to Linux vectors code (and other OSes).

For OMAP3 the security API does take parameters to say if local OS interrupts are allowed or not. In the case they are there the vector base in monitor is used. Some stacking does occur to allow return. So yes as long as local IRQs are off it should be ok. Changes still need validation.

Security does something to SOC resources like DMA which have caused confusion. For instance you call the API and specify a DMA channel. This is ok. But you will find some status left in channel which needs clean up before a successful sleep can happen.

Regards,
Richard W.

#30 lore raw

Re: [PATCH 01/11] OMAP2/3: PM: push core PM code from linux-omap

In reply to Russell King - ARM Linux
Quoted 77 lines · Russell King - ARM Linux
Quoted 1 line · Richard

cpu_init() is not yet accessible at the point this code is running.

Not at that _exact_ point, but there's no need what so ever for it to be at that exact point. There's nothing stopping a call to cpu_init() happening later. Much later.

Quoted 7 lines

You could reduce the context perhaps trying to optimize to what the Linux-ARM implementation is today or do a more generic save like is there now.

This code is copied into place from the .S code into SRAM. Its position independent and is not linked for this address. If you want to call functions outside of it you need to manually setup linkage.

I wouldn't want to.

Quoted 6 lines

Calling functions on the way _UP_ from wake is NOT easy (like the one you propose) as the MMU is not yet enabled. The MMU is enabled only below this. Calling cpu_init() is not do able here. Even if you dress up the calling pointer to the physical address, it won't work as cpu_init() makes a global variable dereferences (smp_processor_id & stacks[]).

As long as IRQs and FIQs are disabled, you are in a 100% predictable environment.

1. No IRQ or FIQ will be entered; if they are the CPU is buggy.
2. No data or prefetch abort will be entered _unless_ you purposely access some non-present memory (and you're not exactly going to start paging memory in with IRQs disabled.)

So restoring the abort and IRQ mode register state is just plain not necessary in your SRAM code.

Let's look at the code. Here are the pertinent bits from Kevin's patch:

static void omap3_pm_idle(void)

{
        local_irq_disable();
        local_fiq_disable();

        omap_sram_idle();

        local_fiq_enable();
        local_irq_enable();
}

static void omap_sram_idle(void)

{
        _omap_sram_idle(NULL, save_state);
}
        _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
                                         omap34xx_cpu_suspend_sz);
        pm_idle = omap3_pm_idle;

_omap_sram_idle() is the assembly code we're discussing, and here we're referring to its version in SRAM. From the above code, we can clearly see that this is entered with FIQs and IRQs disabled. So everything inside omap_sram_idle() is running in a well defined environment provided prefetch and data aborts don't happen.

There is nothing stopping this from becoming:

static void omap3_pm_idle(void)

{
        local_irq_disable();
        local_fiq_disable();

        omap_sram_idle();
(quoted diff) +1 -0
+	cpu_init();
 
        local_fiq_enable();
        local_irq_enable();

}

Quoted 2 lines

and having the saving of IRQ, FIQ and abort mode registers removed from the SRAM code.

I did some quick experiments on a kernel that includes full OFF-mode support and this and this is working fine.

For it to work for both idle and suspend, I put the cpu_init() immediately after the return from SRAM (IOW, right after the call to _omap_sram_idle() inside omap_sram_idle()).

Now I can totally drop all the sp/lr/spsr save/restore code from the asm code. Nice!

Quoted 11 lines

Other SoCs do precisely this - let's look at PXA:

        pxa_cpu_pm_fns->enter(state);
        cpu_init();

The call to the enter method essentially calls the core specific suspend function (eg, pxa25x_cpu_suspend()), which is an assembly function which ultimately ends up powering down the core resulting in full loss of state in the CPU. We seem to be able to avoid having to save the exception mode registers there.

Quoted 3 lines

The same thing is done with sa11x0 and Samsung SoCs.

I don't see any reason for OMAP to be "special" in this regard.

Neither do I. Thanks for the review and the suggestion.

Kevin