From patchwork Tue Nov 18 11:15:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 41011 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 17F84241C9 for ; Tue, 18 Nov 2014 11:20:46 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id t10sf2985911eei.0 for ; Tue, 18 Nov 2014 03:20:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=mGxIBFRTq6AwB+dJME9sf0tRRAjqd7ugmkP+6Rr+kUA=; b=dekwZirm/7Fkjn59mPmzgUXEhX3fNpeeZTrELD7xPXEy0goNFLDEoHMzZ/YbNkjKJP 5QUBp9bb+WUib6/aQmr9c9J4JMZUv2CkFC4pMCa8/u++U21DK+tX8/f94DdWRITlVU7O epgpIlKHBFCVQ5ImHhg/te/B1t3RIUTaPLMR4q1gE02KOZQYzuoUA81iO1D1fBkWkuiW FvcgY0yakl/U8KwVs6/Mmg9STVcCut1jtp4849unrzimygK2n75NXAPSuQT4+Nek3YP5 knoilarn0oA20NLPXvzJuvSVoXAnCiYSnRaqQEqxZDfU0RThGZZ44EhVB6diIbiedalD 4/sA== X-Gm-Message-State: ALoCoQk9hgcYs/GGKItIX6rkqdHcid4b3nmDC47bWI0A5Rgj6acLcQTTi1Yfl/1Xops4EMJiXoBH X-Received: by 10.180.106.67 with SMTP id gs3mr5539357wib.3.1416309645305; Tue, 18 Nov 2014 03:20:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.197 with SMTP id q5ls1368270lal.39.gmail; Tue, 18 Nov 2014 03:20:45 -0800 (PST) X-Received: by 10.152.203.196 with SMTP id ks4mr17631319lac.78.1416309645028; Tue, 18 Nov 2014 03:20:45 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id am7si46183047lac.124.2014.11.18.03.20.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 03:20:45 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id s18so6143251lam.35 for ; Tue, 18 Nov 2014 03:20:44 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr35043176lad.44.1416309644944; Tue, 18 Nov 2014 03:20:44 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp1310494lbc; Tue, 18 Nov 2014 03:20:43 -0800 (PST) X-Received: by 10.66.218.42 with SMTP id pd10mr3137882pac.151.1416309641501; Tue, 18 Nov 2014 03:20:41 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mn10si10132601pbc.208.2014.11.18.03.20.40 for ; Tue, 18 Nov 2014 03:20:41 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754096AbaKRLUh (ORCPT + 26 others); Tue, 18 Nov 2014 06:20:37 -0500 Received: from mail-pd0-f181.google.com ([209.85.192.181]:35478 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753169AbaKRLUe (ORCPT ); Tue, 18 Nov 2014 06:20:34 -0500 Received: by mail-pd0-f181.google.com with SMTP id z10so5835315pdj.26 for ; Tue, 18 Nov 2014 03:20:33 -0800 (PST) X-Received: by 10.68.65.16 with SMTP id t16mr18722569pbs.70.1416309633551; Tue, 18 Nov 2014 03:20:33 -0800 (PST) Received: from wangdeqiang.com ([210.21.223.3]) by mx.google.com with ESMTPSA id l13sm7556923pbq.40.2014.11.18.03.20.29 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 03:20:33 -0800 (PST) From: "pang.xunlei" To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , John Stultz , Arnd Bergmann , "pang.xunlei" Subject: [RFC PATCH v3 5/5] rtc/mc13xxx: Eliminate time problems Date: Tue, 18 Nov 2014 19:15:20 +0800 Message-Id: <1416309320-7498-6-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1416309320-7498-1-git-send-email-pang.xunlei@linaro.org> References: <1416309320-7498-1-git-send-email-pang.xunlei@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pang.xunlei@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch is an example to demonstrate how to make rtc drivers of time-safe hardwares time-safe based on our foregoing work. Provided mc13xxx_rtc_set_mmss() has been already converted to use 64-bit seconds which will be done in my future patches, now we can easily tackle all time problems in rtc-mc13xxx.c(time-safe hardware): - Replace rtc_time_to_tm() with rtc_time64_to_tm() - Replace rtc_tm_to_time() with rtc_tm_to_time64() Then, this driver can work properly with no time issues. Signed-off-by: pang.xunlei --- drivers/rtc/rtc-mc13xxx.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c index 0765606..124996d 100644 --- a/drivers/rtc/rtc-mc13xxx.c +++ b/drivers/rtc/rtc-mc13xxx.c @@ -83,7 +83,7 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) return ret; } while (days1 != days2); - rtc_time_to_tm(days1 * SEC_PER_DAY + seconds, tm); + rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm); return rtc_valid_tm(tm); } @@ -159,7 +159,7 @@ static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct mc13xxx_rtc *priv = dev_get_drvdata(dev); unsigned seconds, days; - unsigned long s1970; + time64_t s1970; int enabled, pending; int ret; @@ -189,10 +189,10 @@ out: alarm->enabled = enabled; alarm->pending = pending; - s1970 = days * SEC_PER_DAY + seconds; + s1970 = (time64_t)days * SEC_PER_DAY + seconds; - rtc_time_to_tm(s1970, &alarm->time); - dev_dbg(dev, "%s: %lu\n", __func__, s1970); + rtc_time64_to_tm(s1970, &alarm->time); + dev_dbg(dev, "%s: %lld\n", __func__, (long long)s1970); return 0; } @@ -200,8 +200,8 @@ out: static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct mc13xxx_rtc *priv = dev_get_drvdata(dev); - unsigned long s1970; - unsigned seconds, days; + time64_t s1970; + u32 seconds, days; int ret; mc13xxx_lock(priv->mc13xxx); @@ -215,20 +215,17 @@ static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) if (unlikely(ret)) goto out; - ret = rtc_tm_to_time(&alarm->time, &s1970); - if (unlikely(ret)) - goto out; + s1970 = rtc_tm_to_time64(&alarm->time); - dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff", - s1970); + dev_dbg(dev, "%s: o%2.s %lld\n", __func__, alarm->enabled ? "n" : "ff", + (long long)s1970); ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled, MC13XXX_IRQ_TODA); if (unlikely(ret)) goto out; - seconds = s1970 % SEC_PER_DAY; - days = s1970 / SEC_PER_DAY; + days = div_s64_rem(s1970, SEC_PER_DAY, &seconds); ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days); if (unlikely(ret))