* [PATCHv3] OMAP3: Serial: Improved sleep logic
@ 2010-02-11 13:39 Tero Kristo
2010-02-11 23:11 ` Tony Lindgren
0 siblings, 1 reply; 2+ messages in thread
From: Tero Kristo @ 2010-02-11 13:39 UTC (permalink / raw)
To: linux-omap
From: Tero Kristo <tero.kristo@nokia.com>
This patch contains following improvements:
- Only RX interrupt will now kick the sleep prevent timer
- TX fifo status is checked before disabling clocks, this will prevent
on-going transmission to be cut
- Smartidle is disabled while entering idle if we have data in the transmit
buffer because having this enabled would prevent wakeups from the TX
interrupt and this would cause pauses while sending large blocks of data
- Sleep prevent timer is changed to use ktime_get() instead of a jiffy timer
as jiffy timers are not valid within idle loop (tick scheduler is stopped)
- Added RX ignore timer for ignoring the first character received during
first millisecond of wakeup, this prevents garbage character to be received
in low sleep states
Signed-off-by: Tero Kristo <tero.kristo@nokia.com>
---
arch/arm/mach-omap2/serial.c | 81 ++++++++++++++++++++++++++++-------------
1 files changed, 55 insertions(+), 26 deletions(-)
diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c
index 837b347..75ce549 100644
--- a/arch/arm/mach-omap2/serial.c
+++ b/arch/arm/mach-omap2/serial.c
@@ -23,12 +23,15 @@
#include <linux/serial_reg.h>
#include <linux/clk.h>
#include <linux/io.h>
+#include <linux/delay.h>
#include <plat/common.h>
#include <plat/board.h>
#include <plat/clock.h>
#include <plat/control.h>
+#include <asm/div64.h>
+
#include "prm.h"
#include "pm.h"
#include "prm-regbits-34xx.h"
@@ -36,13 +39,14 @@
#define UART_OMAP_NO_EMPTY_FIFO_READ_IP_REV 0x52
#define UART_OMAP_WER 0x17 /* Wake-up enable register */
-#define DEFAULT_TIMEOUT (5 * HZ)
+#define DEFAULT_TIMEOUT (5LL * NSEC_PER_SEC)
struct omap_uart_state {
int num;
int can_sleep;
- struct timer_list timer;
- u32 timeout;
+ ktime_t expire_time;
+ ktime_t garbage_time;
+ u64 timeout;
void __iomem *wk_st;
void __iomem *wk_en;
@@ -231,6 +235,9 @@ static inline void omap_uart_enable_clocks(struct omap_uart_state *uart)
clk_enable(uart->fck);
uart->clocked = 1;
omap_uart_restore_context(uart);
+
+ /* Set up garbage timer to ignore RX during first 1ms */
+ uart->garbage_time = ktime_add_ns(ktime_get(), NSEC_PER_MSEC);
}
#ifdef CONFIG_PM
@@ -302,9 +309,7 @@ static void omap_uart_block_sleep(struct omap_uart_state *uart)
omap_uart_smart_idle_enable(uart, 0);
uart->can_sleep = 0;
if (uart->timeout)
- mod_timer(&uart->timer, jiffies + uart->timeout);
- else
- del_timer(&uart->timer);
+ uart->expire_time = ktime_add_ns(ktime_get(), uart->timeout);
}
static void omap_uart_allow_sleep(struct omap_uart_state *uart)
@@ -317,25 +322,28 @@ static void omap_uart_allow_sleep(struct omap_uart_state *uart)
if (!uart->clocked)
return;
- omap_uart_smart_idle_enable(uart, 1);
+ if (serial_read_reg(uart->p, UART_LSR) & UART_LSR_TEMT)
+ omap_uart_smart_idle_enable(uart, 1);
uart->can_sleep = 1;
- del_timer(&uart->timer);
-}
-
-static void omap_uart_idle_timer(unsigned long data)
-{
- struct omap_uart_state *uart = (struct omap_uart_state *)data;
-
- omap_uart_allow_sleep(uart);
}
void omap_uart_prepare_idle(int num)
{
struct omap_uart_state *uart;
+ ktime_t t;
list_for_each_entry(uart, &uart_list, node) {
+ if (num == uart->num && !uart->can_sleep) {
+ t = ktime_get();
+ if (t.tv64 > uart->expire_time.tv64)
+ uart->can_sleep = 1;
+ }
if (num == uart->num && uart->can_sleep) {
- omap_uart_disable_clocks(uart);
+ if (serial_read_reg(uart->p, UART_LSR) &
+ UART_LSR_TEMT)
+ omap_uart_disable_clocks(uart);
+ else
+ omap_uart_smart_idle_enable(uart, 0);
return;
}
}
@@ -360,6 +368,7 @@ void omap_uart_resume_idle(int num)
/* Check for normal UART wakeup */
if (__raw_readl(uart->wk_st) & uart->wk_mask)
omap_uart_block_sleep(uart);
+
return;
}
}
@@ -407,10 +416,24 @@ int omap_uart_can_sleep(void)
static irqreturn_t omap_uart_interrupt(int irq, void *dev_id)
{
struct omap_uart_state *uart = dev_id;
+ u8 lsr;
+ int ret = IRQ_NONE;
- omap_uart_block_sleep(uart);
+ lsr = serial_read_reg(uart->p, UART_LSR);
+ /* Check for receive interrupt */
+ if (lsr & UART_LSR_DR) {
+ omap_uart_block_sleep(uart);
+ if (uart->garbage_time.tv64 &&
+ ktime_get().tv64 < uart->garbage_time.tv64) {
+ serial_read_reg(uart->p, UART_RX);
+ uart->garbage_time.tv64 = 0;
+ ret = IRQ_HANDLED;
+ }
+ }
+ if (lsr & UART_LSR_TEMT && uart->can_sleep)
+ omap_uart_smart_idle_enable(uart, 1);
- return IRQ_NONE;
+ return ret;
}
static void omap_uart_idle_init(struct omap_uart_state *uart)
@@ -420,9 +443,9 @@ static void omap_uart_idle_init(struct omap_uart_state *uart)
uart->can_sleep = 0;
uart->timeout = DEFAULT_TIMEOUT;
- setup_timer(&uart->timer, omap_uart_idle_timer,
- (unsigned long) uart);
- mod_timer(&uart->timer, jiffies + uart->timeout);
+
+ uart->expire_time = ktime_add_ns(ktime_get(), uart->timeout);
+
omap_uart_smart_idle_enable(uart, 0);
if (cpu_is_omap34xx()) {
@@ -505,8 +528,12 @@ static ssize_t sleep_timeout_show(struct device *dev,
struct platform_device, dev);
struct omap_uart_state *uart = container_of(pdev,
struct omap_uart_state, pdev);
+ u64 val;
+
+ val = uart->timeout;
- return sprintf(buf, "%u\n", uart->timeout / HZ);
+ do_div(val, NSEC_PER_SEC);
+ return sprintf(buf, "%llu\n", val);
}
static ssize_t sleep_timeout_store(struct device *dev,
@@ -524,10 +551,12 @@ static ssize_t sleep_timeout_store(struct device *dev,
return -EINVAL;
}
- uart->timeout = value * HZ;
- if (uart->timeout)
- mod_timer(&uart->timer, jiffies + uart->timeout);
- else
+ uart->timeout = (u64)value * NSEC_PER_SEC;
+ if (uart->timeout) {
+ uart->expire_time = ktime_get();
+ uart->expire_time =
+ ktime_add_ns(uart->expire_time, uart->timeout);
+ } else
/* A zero value means disable timeout feature */
omap_uart_block_sleep(uart);
--
1.5.4.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCHv3] OMAP3: Serial: Improved sleep logic
2010-02-11 13:39 [PATCHv3] OMAP3: Serial: Improved sleep logic Tero Kristo
@ 2010-02-11 23:11 ` Tony Lindgren
0 siblings, 0 replies; 2+ messages in thread
From: Tony Lindgren @ 2010-02-11 23:11 UTC (permalink / raw)
To: Tero Kristo; +Cc: linux-omap
* Tero Kristo <tero.kristo@nokia.com> [100211 03:48]:
> From: Tero Kristo <tero.kristo@nokia.com>
>
> This patch contains following improvements:
> - Only RX interrupt will now kick the sleep prevent timer
> - TX fifo status is checked before disabling clocks, this will prevent
> on-going transmission to be cut
> - Smartidle is disabled while entering idle if we have data in the transmit
> buffer because having this enabled would prevent wakeups from the TX
> interrupt and this would cause pauses while sending large blocks of data
> - Sleep prevent timer is changed to use ktime_get() instead of a jiffy timer
> as jiffy timers are not valid within idle loop (tick scheduler is stopped)
> - Added RX ignore timer for ignoring the first character received during
> first millisecond of wakeup, this prevents garbage character to be received
> in low sleep states
Cool, sounds like the way to go. Note that current mainline kernel has
the DEFAULT_TIMEOUT set to 0 because of the lost/corrupt characters.
> --- a/arch/arm/mach-omap2/serial.c
> +++ b/arch/arm/mach-omap2/serial.c
> @@ -36,13 +39,14 @@
> #define UART_OMAP_NO_EMPTY_FIFO_READ_IP_REV 0x52
> #define UART_OMAP_WER 0x17 /* Wake-up enable register */
>
> -#define DEFAULT_TIMEOUT (5 * HZ)
> +#define DEFAULT_TIMEOUT (5LL * NSEC_PER_SEC)
Won't apply to mainline..
> @@ -420,9 +443,9 @@ static void omap_uart_idle_init(struct omap_uart_state *uart)
>
> uart->can_sleep = 0;
> uart->timeout = DEFAULT_TIMEOUT;
> - setup_timer(&uart->timer, omap_uart_idle_timer,
> - (unsigned long) uart);
> - mod_timer(&uart->timer, jiffies + uart->timeout);
> +
> + uart->expire_time = ktime_add_ns(ktime_get(), uart->timeout);
> +
> omap_uart_smart_idle_enable(uart, 0);
>
> if (cpu_is_omap34xx()) {
And the above should probably be:
if (uart->timeout)
uart->expire_time = ktime_add_ns(ktime_get(), uart->timeout);
In order to support zero default timeout. Some other changes
may be necessary too if DEFAULT_TIMEOUT is 0.
Regards,
Tony
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-02-11 23:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-11 13:39 [PATCHv3] OMAP3: Serial: Improved sleep logic Tero Kristo
2010-02-11 23:11 ` Tony Lindgren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox