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: 41617 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7280B244C2 for ; Thu, 27 Nov 2014 12:03:56 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id k14sf2938884wgh.8 for ; Thu, 27 Nov 2014 04:03:55 -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=2d1+nMi0xWU25FVLgJrbp/dtY7Y0x8YdMCCJ/qIPwz4=; b=fgh81Qpu9gYNgclvuqQXjebSC7jlISpgy5iRU+Irt2y+pRR5Cl85LsF0jj7boNbS1z mYjrjPXrtchjtwnXgDyBjO6CHZv3jhuDep8o1xxDCYcj15UrU9ufHoXo8DH5PZpbIgzb Uuw9SZTmh5NfpgHfYZj698Hkf8lsXL1pBrxL35YBa/LngtWym5qQxegLLm/U+X7efbTZ 3jD1FRsOHFjFNa5gtzM/q7vLF6KlGNt+/aG1U1IacsQ4ysq7IuV/v+KhvcMLPTNS3fso m8HgFnB6Zh0WMbzkUTL6nPnX/f7Gvbj4bpw1l6L7KW7KLrQLI/yHkf+lPC2ECHIlZi3n yl0A== X-Gm-Message-State: ALoCoQmrFRqusSayGbPLJla95N6b1r2xxskUF3aKr37++rtzRcyO6Frckx6DatdgExnr/WVexyoD X-Received: by 10.194.133.39 with SMTP id oz7mr2301508wjb.3.1417089835777; Thu, 27 Nov 2014 04:03:55 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.165 with SMTP id x5ls416931lal.34.gmail; Thu, 27 Nov 2014 04:03:55 -0800 (PST) X-Received: by 10.112.144.228 with SMTP id sp4mr38006584lbb.58.1417089835583; Thu, 27 Nov 2014 04:03:55 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id uc2si5925773lac.80.2014.11.27.04.03.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Nov 2014 04:03:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id hz20so4136933lab.34 for ; Thu, 27 Nov 2014 04:03:55 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr38737801lbc.34.1417089835405; Thu, 27 Nov 2014 04:03:55 -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 ew9csp786931lbc; Thu, 27 Nov 2014 04:03:54 -0800 (PST) X-Received: by 10.66.159.3 with SMTP id wy3mr61559176pab.98.1417089832300; Thu, 27 Nov 2014 04:03:52 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vz6si11421798pab.0.2014.11.27.04.03.51 for ; Thu, 27 Nov 2014 04:03:52 -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 S1754971AbaK0MDk (ORCPT + 26 others); Thu, 27 Nov 2014 07:03:40 -0500 Received: from mail-pd0-f181.google.com ([209.85.192.181]:61701 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754867AbaK0MDi (ORCPT ); Thu, 27 Nov 2014 07:03:38 -0500 Received: by mail-pd0-f181.google.com with SMTP id z10so4751187pdj.26 for ; Thu, 27 Nov 2014 04:03:37 -0800 (PST) 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: [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> 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.47 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: , 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;