From patchwork Sat Aug 18 13:14:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lothar_Wa=C3=9Fmann?= X-Patchwork-Id: 178466 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B98A72C00A6 for ; Sat, 18 Aug 2012 23:18:33 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T2irb-000121-6b; Sat, 18 Aug 2012 13:14:51 +0000 Received: from mail.karo-electronics.de ([81.173.242.67]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T2irX-00011o-D4 for linux-arm-kernel@lists.infradead.org; Sat, 18 Aug 2012 13:14:48 +0000 Message-ID: <20527.38172.621130.368019@ipc1.ka-ro> Date: Sat, 18 Aug 2012 15:14:04 +0200 From: =?utf-8?Q?Lothar_Wa=C3=9Fmann?= To: Shawn Guo Mime-Version: 1.0 Subject: Re: [PATCH] rtc: snvs: improve timeout handling in snvs_rtc_enable() In-Reply-To: <20120818124652.GH24242@S2101-09.ap.freescale.net> References: <1345277408-30044-1-git-send-email-LW@KARO-electronics.de> <20120818124652.GH24242@S2101-09.ap.freescale.net> X-Mailer: VM 8.1.0 under 23.2.1 (x86_64-pc-linux-gnu) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Alessandro Zummo , Kim Phillips , rtc-linux@googlegroups.com, Sascha Hauer , Stephen Boyd , Andrew Morton , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org Shawn Guo writes: > On Sat, Aug 18, 2012 at 10:10:08AM +0200, Lothar Waßmann wrote: > > If snvs_rtc_enable() happens to be descheduled for a period longer > > than the timout period, a timeout may be indicated even if the RTC > > status has changed meanwhile. Force a status read at the end of the > > timeout period to prevent bogus timeout errors. > > > > > > Signed-off-by: Lothar Waßmann > > --- > > drivers/rtc/rtc-snvs.c | 22 +++++++++++++--------- > > 1 files changed, 13 insertions(+), 9 deletions(-) > > > > Compile tested only due to lack of HW. > > Tested-by: Shawn Guo > > A small nitpick below. > > > > > diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c > > index 912f116..dc921b2 100644 > > --- a/drivers/rtc/rtc-snvs.c > > +++ b/drivers/rtc/rtc-snvs.c > > @@ -81,6 +81,13 @@ static void rtc_write_sync_lp(void __iomem *ioaddr) > > } > > } > > > > +static int snvs_rtc_enable_done(int enable, void __iomem *addr) > > Can we rename parameter "addr" to "ioaddr" and put it before "enable", > also change "enable" to bool? > OK. The resulting assembler code of the patch below is identical to the previous version of this patch. Signed-off-by: Lothar Waßmann Tested-by: Shawn Guo --- drivers/rtc/rtc-snvs.c | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c index 912f116..a757cb9 100644 --- a/drivers/rtc/rtc-snvs.c +++ b/drivers/rtc/rtc-snvs.c @@ -81,6 +81,13 @@ static void rtc_write_sync_lp(void __iomem *ioaddr) } } +static int snvs_rtc_enable_done(void __iomem *ioaddr, bool enable) +{ + u32 lpcr = readl(ioaddr + SNVS_LPCR); + + return enable ^ !(lpcr & SNVS_LPCR_SRTC_ENV); +} + static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable) { unsigned long timeout = jiffies + msecs_to_jiffies(1); @@ -99,18 +106,15 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable) spin_unlock_irqrestore(&data->lock, flags); while (1) { - lpcr = readl(data->ioaddr + SNVS_LPCR); + if (snvs_rtc_enable_done(data->ioaddr, enable)) + break; - if (enable) { - if (lpcr & SNVS_LPCR_SRTC_ENV) - break; - } else { - if (!(lpcr & SNVS_LPCR_SRTC_ENV)) + if (time_after(jiffies, timeout)) { + if (snvs_rtc_enable_done(data->ioaddr, enable)) break; + else + return -ETIMEDOUT; } - - if (time_after(jiffies, timeout)) - return -ETIMEDOUT; } return 0;