Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933725AbcDLMb1 (ORCPT ); Tue, 12 Apr 2016 08:31:27 -0400 Received: from mail-cys01nam02on0087.outbound.protection.outlook.com ([104.47.37.87]:40016 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932392AbcDLMbZ (ORCPT ); Tue, 12 Apr 2016 08:31:25 -0400 X-Greylist: delayed 922 seconds by postgrey-1.27 at vger.kernel.org; Tue, 12 Apr 2016 08:31:25 EDT Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; From: Anurag Kumar Vulisha To: Alessandro Zummo , Alexandre Belloni , CC: Michal Simek , , , , Punnaiah Choudary Kalluri , Anirudha Sarangi , Srikanth Vemula , "Anurag Kumar Vulisha" Subject: [PATCH 2/3] RTC: Write Calibration value before set time Date: Tue, 12 Apr 2016 17:45:45 +0530 Message-ID: <1460463346-24923-2-git-send-email-anuragku@xilinx.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1460463346-24923-1-git-send-email-anuragku@xilinx.com> References: <1460463346-24923-1-git-send-email-anuragku@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-22254.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.83;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(36386004)(76176999)(42186005)(107886002)(52956003)(33646002)(4001430100002)(5003940100001)(2906002)(6806005)(586003)(92566002)(87936001)(103686003)(19580395003)(106466001)(4001450100002)(86362001)(189998001)(11100500001)(5001770100001)(47776003)(229853001)(1220700001)(46386002)(2950100001)(50466002)(63266004)(4326007)(50226001)(90966002)(19580405001)(48376002)(81166005)(50986999)(36756003)(5008740100001)(1096002)(107986001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1NAM02HT071;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;MLV:sfv;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: bff7cce4-7030-4050-8991-08d362cc3364 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(8251501002);SRVR:CY1NAM02HT071; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(13023025)(13017025)(8121501046)(13018025)(13024025)(13015025)(10201501046)(3002001);SRVR:CY1NAM02HT071;BCL:0;PCL:0;RULEID:;SRVR:CY1NAM02HT071; X-Forefront-PRVS: 0910AAF391 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2016 12:15:56.0855 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.83];Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1NAM02HT071 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2608 Lines: 83 It is suggested to programe CALIB_WRITE register with the calibration value before updating the SET_TIME_WRITE register, doing so will clear the Tick Counter and force the next second to be signaled exactly in 1 second. This patch updates the same. Signed-off-by: Anurag Kumar Vulisha --- drivers/rtc/rtc-zynqmp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c index 6adb603..f87f971 100644 --- a/drivers/rtc/rtc-zynqmp.c +++ b/drivers/rtc/rtc-zynqmp.c @@ -56,6 +56,7 @@ struct xlnx_rtc_dev { void __iomem *reg_base; int alarm_irq; int sec_irq; + int calibval; }; static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm) @@ -68,6 +69,13 @@ static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm) if (new_time > RTC_SEC_MAX_VAL) return -EINVAL; + /* + * Writing into calibration register will clear the Tick Counter and + * force the next second to be signaled exactly in 1 second period + */ + xrtcdev->calibval &= RTC_CALIB_MASK; + writel(xrtcdev->calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); + writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR); return 0; @@ -121,7 +129,7 @@ static int xlnx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) return 0; } -static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval) +static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev) { u32 rtc_ctrl; @@ -136,8 +144,8 @@ static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval) * to default value suggested as per design spec * to correct RTC delay in frequency over period of time. */ - calibval &= RTC_CALIB_MASK; - writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); + xrtcdev->calibval &= RTC_CALIB_MASK; + writel(xrtcdev->calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); } static const struct rtc_class_ops xlnx_rtc_ops = { @@ -174,7 +182,6 @@ static int xlnx_rtc_probe(struct platform_device *pdev) struct xlnx_rtc_dev *xrtcdev; struct resource *res; int ret; - unsigned int calibvalue; xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL); if (!xrtcdev) @@ -215,11 +222,11 @@ static int xlnx_rtc_probe(struct platform_device *pdev) } ret = of_property_read_u32(pdev->dev.of_node, "calibration", - &calibvalue); + &xrtcdev->calibval); if (ret) - calibvalue = RTC_CALIB_DEF; + xrtcdev->calibval = RTC_CALIB_DEF; - xlnx_init_rtc(xrtcdev, calibvalue); + xlnx_init_rtc(xrtcdev); device_init_wakeup(&pdev->dev, 1); -- 2.1.2