From patchwork Thu Nov 27 12:02:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 415471 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ie0-x23c.google.com (mail-ie0-x23c.google.com [IPv6:2607:f8b0:4001:c03::23c]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E36961401EF for ; Thu, 27 Nov 2014 23:03:39 +1100 (AEDT) Received: by mail-ie0-f188.google.com with SMTP id tr6sf629266ieb.15 for ; Thu, 27 Nov 2014 04:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:content-type:precedence:mailing-list:list-id:list-post :list-help:list-archive:sender:list-subscribe:list-unsubscribe; bh=OljsJcyEY07k91hsguwI5gBa9k8oTsh60fB74cnnM3Y=; b=ng+PAdYhhsv2p4LUE4uVX2aKzz4ID/cLAcYlMbUEQgbcphzgBYl2onw1ca0xagF9Cr kihHQ7IPCueztdI3ii58eynpOoIg4h3Uhl8ZoFDonM/zp+LEIU+c+N9xToE8S0kcf/SR /tnOaJYb2CIJLB/99tB6KeEwXCQnezO2EZ5WAHDy5cz1G3dBG4XI68uiiobCYTpSXcZO bV5LPyC4ORyveeq7bx0h0c518ByQOlcmR371MZekDqeEPinTA00+cpJqG904bUv3jhVT 6zJ2nBXRL4tLZUOh3F5t8NuDMk9CSUirQMyB3WjyKplZXzR+++vqLUFqAgcWYSE554uE LS4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:content-type:precedence :mailing-list:list-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe; bh=OljsJcyEY07k91hsguwI5gBa9k8oTsh60fB74cnnM3Y=; b=bxMZ7PbZJK3x5HZWdF4DHCtAiXXgAr3fwxl/8UwAijVjLzXSAkkMSbsIfoj7FdP0by PCwG8rGCY8EzUsKmybQgeYbnR1NfpxsW5ypEzXK6kF+5cID18tmOHEhfYM/N8B+Oc8cy r3GCtYPX0vyEzZuN+A2kaOiPgcQb9pU5oukmjoKpxIbUJTDe1/b4gU4POk7e4hYPkNVF I//Mu9UmVkUWxlgWzPHzaudBhUSrnb6gNq/Yt4qRKBLeX0CuxUeGO0yMXXRl8PS5oqic Dut+mfwZ4/FywuCDsZfPIl1eotqTQgSMx+ekhQX/qxXU8EvbDdzxG41awUnEUp9kPNCv 8S8g== X-Received: by 10.140.20.175 with SMTP id 44mr649872qgj.4.1417089818184; Thu, 27 Nov 2014 04:03:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.140.34.21 with SMTP id k21ls26719qgk.16.gmail; Thu, 27 Nov 2014 04:03:37 -0800 (PST) X-Received: by 10.224.156.76 with SMTP id v12mr34738689qaw.8.1417089817903; Thu, 27 Nov 2014 04:03:37 -0800 (PST) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com. [209.85.220.54]) by gmr-mx.google.com with ESMTPS id kj3si863644pdb.1.2014.11.27.04.03.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Nov 2014 04:03:37 -0800 (PST) Received-SPF: pass (google.com: domain of pang.xunlei@linaro.org designates 209.85.220.54 as permitted sender) client-ip=209.85.220.54; Received: by mail-pa0-f54.google.com with SMTP id fb1so4871072pad.41 for ; Thu, 27 Nov 2014 04:03:37 -0800 (PST) X-Gm-Message-State: ALoCoQlg8ulTVfaalHkUk6OnK0c+jg4PG20EvZd+xHiQy8x3ljlIK/fi/yCNUtc92Zz+uaStujQt X-Received: by 10.68.250.131 with SMTP id zc3mr61812157pbc.34.1417089817708; Thu, 27 Nov 2014 04:03:37 -0800 (PST) Received: from wangdeqiang.com ([210.21.223.3]) by mx.google.com with ESMTPSA id cf12sm6955128pdb.77.2014.11.27.04.03.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Nov 2014 04:03:37 -0800 (PST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , Sven Schnelle , Xunlei Pang , John Stultz , Arnd Bergmann Subject: [rtc-linux] [RFC PATCH 4/4] rtc/imxdi: Update driver to address time issues Date: Thu, 27 Nov 2014 20:02:40 +0800 Message-Id: <1417089760-26848-5-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1417089760-26848-1-git-send-email-pang.xunlei@linaro.org> References: <1417089760-26848-1-git-send-email-pang.xunlei@linaro.org> X-Original-Sender: pang.xunlei@linaro.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of pang.xunlei@linaro.org designates 209.85.220.54 as permitted sender) smtp.mail=pang.xunlei@linaro.org 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: , List-Unsubscribe: , The rtc/imxdi rtc driver has a number of y2038/y2106 issues, the worst one is its hardware only supports 32-bit time. This patch resolves them based on our foregoing efforts: - Replace rtc_time_to_tm() with rtc_hw32_to_time64()/rtc_time64_to_tm() - Replace rtc_tm_to_time() with rtc_tm_to_time64()/rtc_time64_to_hw32() - Use rtc_time64_to_hw32() to handle dryice_rtc_set_mmss() After this patch, the drivers should not have any remaining y2038/y2106 issues. Cc: John Stultz Cc: Arnd Bergmann Signed-off-by: Xunlei Pang --- drivers/rtc/rtc-imxdi.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c index 34d76b2..015290f 100644 --- a/drivers/rtc/rtc-imxdi.c +++ b/drivers/rtc/rtc-imxdi.c @@ -197,10 +197,10 @@ out: static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct imxdi_dev *imxdi = dev_get_drvdata(dev); - unsigned long now; + time64_t now; - now = __raw_readl(imxdi->ioaddr + DTCMR); - rtc_time_to_tm(now, tm); + now = rtc_hw32_to_time64(__raw_readl(imxdi->ioaddr + DTCMR)); + rtc_time64_to_tm(now, tm); return 0; } @@ -213,17 +213,16 @@ static int dryice_rtc_set_mmss(struct device *dev, time64_t secs) { struct imxdi_dev *imxdi = dev_get_drvdata(dev); int rc; + u32 hwtime; + + rc = rtc_time64_to_hw32(secs, &hwtime); + if (rc < 0) + return rc; /* zero the fractional part first */ rc = di_write_wait(imxdi, 0, DTCLR); if (rc == 0) - /* - * y2106 issue: - * On 32bit systems the time64_t secs value gets cast to - * a 32bit long, and thus we can only write a maximum value - * of y2016 - */ - rc = di_write_wait(imxdi, secs, DTCMR); + rc = di_write_wait(imxdi, hwtime, DTCMR); return rc; } @@ -248,10 +247,10 @@ static int dryice_rtc_alarm_irq_enable(struct device *dev, static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct imxdi_dev *imxdi = dev_get_drvdata(dev); - u32 dcamr; + time64_t alarm_time; - dcamr = __raw_readl(imxdi->ioaddr + DCAMR); - rtc_time_to_tm(dcamr, &alarm->time); + alarm_time = rtc_hw32_to_time64(__raw_readl(imxdi->ioaddr + DCAMR)); + rtc_time64_to_tm(alarm_time, &alarm->time); /* alarm is enabled if the interrupt is enabled */ alarm->enabled = (__raw_readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0; @@ -273,21 +272,23 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct imxdi_dev *imxdi = dev_get_drvdata(dev); - unsigned long now; - unsigned long alarm_time; + time64_t alarm_time, now; + u32 alarm_hwtime; int rc; - rc = rtc_tm_to_time(&alarm->time, &alarm_time); - if (rc) - return rc; + alarm_time = rtc_tm_to_time64(&alarm->time); + now = rtc_hw32_to_time64(__raw_readl(imxdi->ioaddr + DTCMR)); /* don't allow setting alarm in the past */ - now = __raw_readl(imxdi->ioaddr + DTCMR); if (alarm_time < now) return -EINVAL; + rc = rtc_time64_to_hw32(alarm_time, &alarm_hwtime); + if (rc < 0) + return rc; + /* write the new alarm time */ - rc = di_write_wait(imxdi, (u32)alarm_time, DCAMR); + rc = di_write_wait(imxdi, alarm_hwtime, DCAMR); if (rc) return rc;