From patchwork Fri Feb 12 18:22:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 78911 X-Patchwork-Delegate: khilman@deeprootsystems.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1CGWslK028830 for ; Fri, 12 Feb 2010 16:34:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756405Ab0BLQe1 (ORCPT ); Fri, 12 Feb 2010 11:34:27 -0500 Received: from smtp.nokia.com ([192.100.105.134]:63748 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756903Ab0BLQe0 (ORCPT ); Fri, 12 Feb 2010 11:34:26 -0500 Received: from vaebh106.NOE.Nokia.com (vaebh106.europe.nokia.com [10.160.244.32]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o1CGYNDG017218 for ; Fri, 12 Feb 2010 10:34:25 -0600 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by vaebh106.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 12 Feb 2010 18:34:23 +0200 Received: from mgw-sa01.ext.nokia.com ([147.243.1.47]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Fri, 12 Feb 2010 18:34:23 +0200 Received: from localhost.localdomain (sokoban.nmp.nokia.com [172.22.215.13]) by mgw-sa01.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o1CGYLS4013979 for ; Fri, 12 Feb 2010 18:34:22 +0200 From: Tero Kristo To: linux-omap@vger.kernel.org Subject: [PATCHv4] OMAP3: Serial: Improved sleep logic Date: Fri, 12 Feb 2010 20:22:35 +0200 Message-Id: <1265998955-4334-1-git-send-email-tero.kristo@nokia.com> X-Mailer: git-send-email 1.5.4.3 In-Reply-To: <> References: <> X-OriginalArrivalTime: 12 Feb 2010 16:34:23.0387 (UTC) FILETIME=[3BEDDEB0:01CAAC01] X-Nokia-AV: Clean Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 12 Feb 2010 16:34:27 +0000 (UTC) diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c index 5f3035e..4be9ace 100644 --- a/arch/arm/mach-omap2/serial.c +++ b/arch/arm/mach-omap2/serial.c @@ -29,6 +29,8 @@ #include #include +#include + #include "prm.h" #include "pm.h" #include "prm-regbits-34xx.h" @@ -42,13 +44,14 @@ * disabled via sysfs. This also causes that any deeper omap sleep states are * blocked. */ -#define DEFAULT_TIMEOUT 0 +#define DEFAULT_TIMEOUT (0LL * 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; @@ -243,6 +246,9 @@ static inline void omap_uart_save_context(struct omap_uart_state *uart) {} static inline void omap_uart_restore_context(struct omap_uart_state *uart) {} #endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */ +static void omap_uart_smart_idle_enable(struct omap_uart_state *uart, + int enable); + static inline void omap_uart_enable_clocks(struct omap_uart_state *uart) { if (uart->clocked) @@ -250,8 +256,12 @@ static inline void omap_uart_enable_clocks(struct omap_uart_state *uart) clk_enable(uart->ick); clk_enable(uart->fck); + omap_uart_smart_idle_enable(uart, 0); 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 @@ -263,6 +273,7 @@ static inline void omap_uart_disable_clocks(struct omap_uart_state *uart) omap_uart_save_context(uart); uart->clocked = 0; + omap_uart_smart_idle_enable(uart, 1); clk_disable(uart->ick); clk_disable(uart->fck); } @@ -320,12 +331,9 @@ static void omap_uart_block_sleep(struct omap_uart_state *uart) { omap_uart_enable_clocks(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) @@ -338,16 +346,7 @@ static void omap_uart_allow_sleep(struct omap_uart_state *uart) if (!uart->clocked) return; - 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) @@ -355,8 +354,14 @@ void omap_uart_prepare_idle(int num) struct omap_uart_state *uart; list_for_each_entry(uart, &uart_list, node) { + if (num == uart->num && !uart->can_sleep && uart->timeout) + if (ktime_get().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); return; } } @@ -404,6 +409,10 @@ int omap_uart_can_sleep(void) if (!uart->clocked) continue; + if (!uart->can_sleep && uart->timeout && + ktime_get().tv64 > uart->expire_time.tv64) + uart->can_sleep = 1; + if (!uart->can_sleep) { can_sleep = 0; continue; @@ -428,10 +437,22 @@ 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; + } + } - return IRQ_NONE; + return ret; } static void omap_uart_idle_init(struct omap_uart_state *uart) @@ -441,10 +462,8 @@ 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); if (uart->timeout) - 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()) { @@ -527,8 +546,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, @@ -546,10 +569,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);