Re: OMAP35x GP TIMER as a wakeup trigger

2009-04-28 Thread Ashwin Bihari
On Mon, Apr 27, 2009 at 6:17 PM, Kevin Hilman
 wrote:
> Ashwin Bihari  writes:
>
>> I need to implement a timer as a wake up trigger while my custom board
>> is in the suspended state. I read in the TRM that all of the GPTIMERs
>> have the capability of generating a wake up interrupt. I'm using the
>> 2.6.28-rc8 PM Kernel which contains the patch to enable all the
>> GPTIMERS as wake up sources.
>
> Try the patch below on the current PM branch.  I use this for
> debugging PM code when no other wakeup sources (keypad, UART, etc. are
> working.)
>
> Kevin
>

Kevin.

The patch worked like a charm, thank you very much.

-- Ashwin
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: OMAP35x GP TIMER as a wakeup trigger

2009-04-27 Thread Kevin Hilman
Ashwin Bihari  writes:

> I need to implement a timer as a wake up trigger while my custom board
> is in the suspended state. I read in the TRM that all of the GPTIMERs
> have the capability of generating a wake up interrupt. I'm using the
> 2.6.28-rc8 PM Kernel which contains the patch to enable all the
> GPTIMERS as wake up sources.

Try the patch below on the current PM branch.  I use this for
debugging PM code when no other wakeup sources (keypad, UART, etc. are
working.) 

Kevin


>From bf81b7cce8967a425f1aa3d73782c1eb0367ce1a Mon Sep 17 00:00:00 2001
From: Kevin Hilman 
Date: Fri, 24 Apr 2009 16:13:47 -0700
Subject: [PATCH] OMAP3: PM: Add feature to wake from suspend on timer

If a non-zero value is written to /sys/power/wakeup_timer_seconds,
A timer wakeup event will wake the system and resume after the
configured number of seconds.

Signed-off-by: Kevin Hilman 
---
 arch/arm/mach-omap2/pm.c   |   15 +--
 arch/arm/mach-omap2/pm.h   |3 +++
 arch/arm/mach-omap2/pm34xx.c   |   22 ++
 arch/arm/mach-omap2/timer-gp.c |2 ++
 4 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap2/pm.c b/arch/arm/mach-omap2/pm.c
index 50d95cd..dde0af3 100644
--- a/arch/arm/mach-omap2/pm.c
+++ b/arch/arm/mach-omap2/pm.c
@@ -42,6 +42,7 @@ unsigned short enable_dyn_sleep;
 unsigned short clocks_off_while_idle;
 unsigned short enable_off_mode;
 unsigned short voltage_off_while_idle;
+unsigned short wakeup_timer_seconds;
 atomic_t sleep_block = ATOMIC_INIT(0);
 
 static ssize_t idle_show(struct kobject *, struct kobj_attribute *, char *);
@@ -76,6 +77,9 @@ static struct kobj_attribute vdd2_lock_attr =
 
 #endif
 
+static struct kobj_attribute wakeup_timer_seconds_attr =
+   __ATTR(wakeup_timer_seconds, 0644, idle_show, idle_store);
+
 static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr,
 char *buf)
 {
@@ -87,6 +91,8 @@ static ssize_t idle_show(struct kobject *kobj, struct 
kobj_attribute *attr,
return sprintf(buf, "%hu\n", enable_off_mode);
else if (attr == &voltage_off_while_idle_attr)
return sprintf(buf, "%hu\n", voltage_off_while_idle);
+   else if (attr == &wakeup_timer_seconds_attr)
+   return sprintf(buf, "%hu\n", wakeup_timer_seconds);
else
return -EINVAL;
 }
@@ -96,8 +102,7 @@ static ssize_t idle_store(struct kobject *kobj, struct 
kobj_attribute *attr,
 {
unsigned short value;
 
-   if (sscanf(buf, "%hu", &value) != 1 ||
-   (value != 0 && value != 1)) {
+   if (sscanf(buf, "%hu", &value) != 1) {
printk(KERN_ERR "idle_store: Invalid value\n");
return -EINVAL;
}
@@ -109,6 +114,8 @@ static ssize_t idle_store(struct kobject *kobj, struct 
kobj_attribute *attr,
} else if (attr == &enable_off_mode_attr) {
enable_off_mode = value;
omap3_pm_off_mode_enable(enable_off_mode);
+   } else if (attr == &wakeup_timer_seconds_attr) {
+   wakeup_timer_seconds = value;
} else if (attr == &voltage_off_while_idle_attr) {
voltage_off_while_idle = value;
if (voltage_off_while_idle)
@@ -255,6 +262,10 @@ static int __init omap_pm_init(void)
printk(KERN_ERR "sysfs_create_file failed: %d\n", error);
return error;
}
+   error = sysfs_create_file(power_kobj,
+ &wakeup_timer_seconds_attr.attr);
+   if (error)
+   printk(KERN_ERR "sysfs_create_file failed: %d\n", error);
 #ifdef CONFIG_OMAP_PM_SRF
error = sysfs_create_file(power_kobj,
  &vdd1_opp_attr.attr);
diff --git a/arch/arm/mach-omap2/pm.h b/arch/arm/mach-omap2/pm.h
index 942a990..66effed 100644
--- a/arch/arm/mach-omap2/pm.h
+++ b/arch/arm/mach-omap2/pm.h
@@ -30,6 +30,9 @@ extern unsigned short voltage_off_while_idle;
 extern atomic_t sleep_block;
 extern void *omap3_secure_ram_storage;
 
+extern unsigned short wakeup_timer_seconds;
+extern struct omap_dm_timer *gptimer_wakeup;
+
 extern void omap2_block_sleep(void);
 extern void omap2_allow_sleep(void);
 #ifdef CONFIG_ARCH_OMAP3
diff --git a/arch/arm/mach-omap2/pm34xx.c b/arch/arm/mach-omap2/pm34xx.c
index d8795b5..3f41417 100644
--- a/arch/arm/mach-omap2/pm34xx.c
+++ b/arch/arm/mach-omap2/pm34xx.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -41,6 +42,8 @@
 #include 
 #include 
 #include 
+#include 
+
 #include 
 
 #include "cm.h"
@@ -552,6 +555,22 @@ out:
 static void (*saved_idle)(void);
 static suspend_state_t suspend_state;
 
+static void omap2_pm_wakeup_on_timer(u32 seconds)
+{
+   u32 tick_rate, cycles;
+
+   if (!seconds)
+   return;
+
+   tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup));
+   cycles = tick_rate * seconds;
+   omap_dm_timer_stop(gptimer_

RE: OMAP35x GP TIMER as a wakeup trigger

2009-04-27 Thread Dasgupta, Romit
Ashwin,
  Please see below:
>Could someone familiar with this scheme quickly elaborate all the
>steps that I need to go through to get the system to come out of
>suspend purely on the timer? Is it is just enough to setup the timer
>correctly, enable the interrupt in the appropriate register and assume
>that the PM layer will get the interrupt and do the right thing, or is
>there more that I have to do?
[Romit] Already this is being done during the CPU Idle path. Yes you need to 
program the GPT 1 into oneshot mode with expiry time as appropriate. Also set 
the CM_CLKSEL_WKUP.CLKSEL_GPT1 to sys_32K clock. 
PM_MPUGRPSEL_WKUP.GRPSEL_GPT1, PM_WKEN_WKUP.EN_GPT1 should be set.

>
>Also, as as additional thing, if the PM layer handles the interrupt
>and begins the wake-up process, if I could know where that
>specifically happens, that'd be great since I need to know that the
>wake-up process is being triggered by the GPTIMER as opposed to the
>other wakeup triggers and deal with that differently.

 [Romit] prcm_interrupt_handler. Look for PM_WKST_WKUP.

Thanks,
-Romit

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


Re: OMAP35x GP TIMER as a wakeup trigger

2009-04-27 Thread Ashwin Bihari
On Mon, Apr 27, 2009 at 12:08 PM, Premi, Sanjeev  wrote:
>> -Original Message-
>> From: linux-omap-ow...@vger.kernel.org
>> [mailto:linux-omap-ow...@vger.kernel.org] On Behalf Of Ashwin Bihari
>> Sent: Monday, April 27, 2009 9:20 PM
>> To: linux-omap@vger.kernel.org Mailing List
>> Subject: OMAP35x GP TIMER as a wakeup trigger
>>
>> Greetings,
>>
>> I need to implement a timer as a wake up trigger while my custom board
>> is in the suspended state. I read in the TRM that all of the GPTIMERs
>> have the capability of generating a wake up interrupt. I'm using the
>> 2.6.28-rc8 PM Kernel which contains the patch to enable all the
>> GPTIMERS as wake up sources.
>
> Are you refering to the "suspend" state coming from:
> echo mem > /sys/power/state
> OR
> One of the idle states C0-C6?
>
> To understand the wakeup sequence from suspend; take a look at:
> arch/arm/mach-omap2/serial.c
> ...esp the IOPAD configuration.
>
> You will have to do something similar.
>
> ~sanjeev
>
Sanjeev,

I was talking about the former (echo mem > /sys/power/state) and I
will take a look at the serial.c file and might return with more
questions. :)

Regards
-- Ashwin
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: OMAP35x GP TIMER as a wakeup trigger

2009-04-27 Thread Premi, Sanjeev
> -Original Message-
> From: linux-omap-ow...@vger.kernel.org 
> [mailto:linux-omap-ow...@vger.kernel.org] On Behalf Of Ashwin Bihari
> Sent: Monday, April 27, 2009 9:20 PM
> To: linux-omap@vger.kernel.org Mailing List
> Subject: OMAP35x GP TIMER as a wakeup trigger
> 
> Greetings,
> 
> I need to implement a timer as a wake up trigger while my custom board
> is in the suspended state. I read in the TRM that all of the GPTIMERs
> have the capability of generating a wake up interrupt. I'm using the
> 2.6.28-rc8 PM Kernel which contains the patch to enable all the
> GPTIMERS as wake up sources.

Are you refering to the "suspend" state coming from:
echo mem > /sys/power/state
OR
One of the idle states C0-C6?

To understand the wakeup sequence from suspend; take a look at:
arch/arm/mach-omap2/serial.c
...esp the IOPAD configuration.

You will have to do something similar.

~sanjeev

> 
> Could someone familiar with this scheme quickly elaborate all the
> steps that I need to go through to get the system to come out of
> suspend purely on the timer? Is it is just enough to setup the timer
> correctly, enable the interrupt in the appropriate register and assume
> that the PM layer will get the interrupt and do the right thing, or is
> there more that I have to do?
> 
> Also, as as additional thing, if the PM layer handles the interrupt
> and begins the wake-up process, if I could know where that
> specifically happens, that'd be great since I need to know that the
> wake-up process is being triggered by the GPTIMER as opposed to the
> other wakeup triggers and deal with that differently.
> 
> Regards
> -- Ashwin
> --
> To unsubscribe from this list: send the line "unsubscribe 
> linux-omap" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> --
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html