From patchwork Sat Aug 18 08:10:08 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: 178432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-we0-f184.google.com (mail-we0-f184.google.com [74.125.82.184]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 86D902C008B for ; Sat, 18 Aug 2012 18:10:38 +1000 (EST) Received: by weyx10 with SMTP id x10sf1343130wey.11 for ; Sat, 18 Aug 2012 01:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:from:to:cc:subject:date:message-id :x-mailer:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type :content-transfer-encoding; bh=wEHCN3muYDEIzgQ7dwqSWCIOfz4Ahmj1wYwYmcTelj0=; b=RbAGcpVfNAtG6V5a1VQIU8+eeqBu1e6HO2oO3mGWYXycWOLOahfvajPDCAd9LSVOzF ZWx7sBWRChk+JZA83JbmlJu1onanXK2zD2rJkWnet08lSYfouMpfGWvoFl6LuXQ6XjKP p8TXUkbnjQV9VpzcUNED1vlUa0NoCh0hewnYc= Received: by 10.180.92.104 with SMTP id cl8mr506206wib.0.1345277434683; Sat, 18 Aug 2012 01:10:34 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.216.141.22 with SMTP id f22ls5142241wej.0.gmail; Sat, 18 Aug 2012 01:10:34 -0700 (PDT) Received: by 10.180.105.38 with SMTP id gj6mr948261wib.0.1345277434205; Sat, 18 Aug 2012 01:10:34 -0700 (PDT) Received: by 10.180.105.38 with SMTP id gj6mr948260wib.0.1345277434156; Sat, 18 Aug 2012 01:10:34 -0700 (PDT) Received: from mail.karo-electronics.de (mail.karo-electronics.de. [81.173.242.67]) by gmr-mx.google.com with ESMTPS id cd1si1687580wib.1.2012.08.18.01.10.33 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 18 Aug 2012 01:10:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of LW@karo-electronics.de designates 81.173.242.67 as permitted sender) client-ip=81.173.242.67; From: =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= To: rtc-linux@googlegroups.com Cc: =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= , Andrew Morton , Shawn Guo , Alessandro Zummo , Kim Phillips , Sascha Hauer , Stephen Boyd , linux-arm-kernel@lists.infradead.org Subject: [rtc-linux] [PATCH] rtc: snvs: improve timeout handling in snvs_rtc_enable() Date: Sat, 18 Aug 2012 10:10:08 +0200 Message-Id: <1345277408-30044-1-git-send-email-LW@KARO-electronics.de> X-Mailer: git-send-email 1.7.2.5 MIME-Version: 1.0 X-Original-Sender: lw@karo-electronics.de X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of LW@karo-electronics.de designates 81.173.242.67 as permitted sender) smtp.mail=LW@karo-electronics.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , 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 Tested-by: Shawn Guo --- drivers/rtc/rtc-snvs.c | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) Compile tested only due to lack of HW. 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) +{ + u32 lpcr = readl(addr + 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(enable, data->ioaddr)) + 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(enable, data->ioaddr)) break; + else + return -ETIMEDOUT; } - - if (time_after(jiffies, timeout)) - return -ETIMEDOUT; } return 0;