Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932868AbcDTOUP (ORCPT ); Wed, 20 Apr 2016 10:20:15 -0400 Received: from mail-sn1nam02on0076.outbound.protection.outlook.com ([104.47.36.76]:45216 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750999AbcDTOUN convert rfc822-to-8bit (ORCPT ); Wed, 20 Apr 2016 10:20:13 -0400 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: Alexandre Belloni CC: Alessandro Zummo , Soren Brinkmann , Michal Simek , "rtc-linux@googlegroups.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Punnaiah Choudary Kalluri , Anirudha Sarangi , Srikanth Vemula , Srinivas Goud Subject: RE: [PATCH V2] rtc: zynqmp: Update seconds time programming logic Thread-Topic: [PATCH V2] rtc: zynqmp: Update seconds time programming logic Thread-Index: AQHRmwu85e8Tsb1XJ0eMWEP0RSc3ap+SXooAgACKfMA= Date: Wed, 20 Apr 2016 14:20:06 +0000 Message-ID: <3802E9A6666DF54886E2B9CBF743BA9825E0B53D@XAP-PVEXMBX01.xlnx.xilinx.com> References: <1461160279-40600-1-git-send-email-anuragku@xilinx.com> <20160420140310.GS29844@piout.net> In-Reply-To: <20160420140310.GS29844@piout.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.23.97.204] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-22272.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)(189002)(377454003)(13464003)(199003)(5003600100002)(5250100002)(5890100001)(97756001)(63266004)(10710500007)(4326007)(15975445007)(2950100001)(2920100001)(50466002)(11100500001)(2420400007)(50986999)(54356999)(4001430100002)(76176999)(86362001)(586003)(2906002)(5004730100002)(23726003)(5008740100001)(46406003)(3846002)(33656002)(87936001)(1096002)(106116001)(15650500001)(19580405001)(19580395003)(102836003)(16601075003)(106466001)(81166005)(6116002)(92566002)(55846006)(189998001)(107886002)(110136002)(47776003)(1220700001)(6806005)(107986001);DIR:OUT;SFP:1101;SCL:1;SRVR:BL2NAM02HT143;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;MLV:sfv;MX:1;A:1;LANG:en; X-MS-Office365-Filtering-Correlation-Id: f92b1654-46d1-4ab3-ac2f-08d36926e251 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(8251501002);SRVR:BL2NAM02HT143; X-Microsoft-Antispam-PRVS: <95b8c51e963041a981fd2b23a257e25d@BL2NAM02HT143.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521040)(601004)(2401047)(13023025)(8121501046)(13015025)(5005006)(13017025)(13018025)(13024025)(10201501046)(3002001);SRVR:BL2NAM02HT143;BCL:0;PCL:0;RULEID:;SRVR:BL2NAM02HT143; X-Forefront-PRVS: 0918748D70 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 14:20:11.3236 (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: BL2NAM02HT143 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5977 Lines: 151 Hi Alexandre, > -----Original Message----- > From: Alexandre Belloni [mailto:alexandre.belloni@free-electrons.com] > Sent: Wednesday, April 20, 2016 7:33 PM > To: Anurag Kumar Vulisha > Cc: Alessandro Zummo ; Soren Brinkmann > ; Michal Simek ; rtc- > linux@googlegroups.com; linux-arm-kernel@lists.infradead.org; linux- > kernel@vger.kernel.org; Punnaiah Choudary Kalluri ; > Anirudha Sarangi ; Srikanth Vemula > ; Srinivas Goud ; Anurag Kumar > Vulisha > Subject: Re: [PATCH V2] rtc: zynqmp: Update seconds time programming > logic > > On 20/04/2016 at 19:21:19 +0530, Anurag Kumar Vulisha wrote : > > We programe RTC time using SET_TIME_WRITE register and read the RTC > > current time using CURRENT_TIME register. When we set the time by > > writing into SET_TIME_WRITE Register and immediately try to read the > > rtc time from CURRENT_TIME register, the previous old value is > > returned instead of the new loaded time. This is because RTC takes > > nearly 1 sec to update the new loaded value into the CURRENT_TIME > > register. This behaviour is expected in our RTC IP. > > > > This patch updates the driver to read the current time from > > SET_TIME_WRITE register instead of CURRENT_TIME when rtc time is > > requested within an 1sec period after setting the RTC time. Doing so > > will ensure the correct time is given to the user. > > > > Since there is an delay of 1sec in updating the CURRENT_TIME we are > > loading set time +1sec while programming the SET_TIME_WRITE register, > > doing this will give correct time without any delay when read from > CURRENT_TIME. > > > > This patch updates the above said. > > > > Signed-off-by: Anurag Kumar Vulisha > > --- > > Changes in v2: > > 1. Updated the Time programming logic as suggested by Alexandre > Belloni > > 2. Changed the commit message > > --- > > drivers/rtc/rtc-zynqmp.c | 41 > > ++++++++++++++++++++++++++++++++++++----- > > 1 file changed, 36 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c index > > f87f971..ba4203a 100644 > > --- a/drivers/rtc/rtc-zynqmp.c > > +++ b/drivers/rtc/rtc-zynqmp.c > > @@ -64,6 +64,12 @@ static int xlnx_rtc_set_time(struct device *dev, struct > rtc_time *tm) > > struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); > > unsigned long new_time; > > > > + /* > > + * The value written will be updated after 1 sec into the > > + * seconds read register, so we need to program time +1 sec > > + * to get the correct time on read. > > + */ > > + tm->tm_sec += 1; > > new_time = rtc_tm_to_time64(tm); > > > > if (new_time > RTC_SEC_MAX_VAL) > > @@ -78,14 +84,41 @@ static int xlnx_rtc_set_time(struct device *dev, > > struct rtc_time *tm) > > > > writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR); > > > > + /* > > + * Clear the rtc interrupt status register after setting the > > + * time. During a read_time function, the code should read the > > + * RTC_INT_STATUS register and if bit 0 is still 0, it means > > + * that one second has not elapsed yet since RTC was set and > > + * the current time should be read from SET_TIME_READ register; > > + * otherwise, CURRENT_TIME register is read to report the time > > + */ > > + writel(RTC_INT_SEC, xrtcdev->reg_base + RTC_INT_STS); > > + > > return 0; > > } > > > > static int xlnx_rtc_read_time(struct device *dev, struct rtc_time > > *tm) { > > + int status; > > struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); > > > > - rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_CUR_TM), tm); > > + status = readl(xrtcdev->reg_base + RTC_INT_STS); > > + > > + if (status & RTC_INT_SEC) { > > + /* > > + * RTC has updated the CURRENT_TIME with the time written > into > > + * SET_TIME_WRITE register. > > + */ > > + rtc_time64_to_tm(readl(xrtcdev->reg_base + > RTC_CUR_TM), tm); > > + } else { > > + /* > > + * Time written in SET_TIME_WRITE has not yet updated into > > + * the seconds read register, so read the time from the > > + * SET_TIME_WRITE instead of CURRENT_TIME register. > > + */ > > + rtc_time64_to_tm(readl(xrtcdev->reg_base + > RTC_SET_TM_RD), tm); > > + tm->tm_sec -= 1; > > Well, I didn't point it out directly earlier but this doesn't work while my > example is working: > rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_SET_TM_RD) - 1, tm); > Think about what is happening when tm->tm_sec == 0 ... > Thanks for pointing it out, will change this part Regards, Anurag Kumar V > > + } > > > > return rtc_valid_tm(tm); > > } > > @@ -166,11 +199,9 @@ static irqreturn_t xlnx_rtc_interrupt(int irq, void > *id) > > if (!(status & (RTC_INT_SEC | RTC_INT_ALRM))) > > return IRQ_NONE; > > > > - /* Clear interrupt */ > > - writel(status, xrtcdev->reg_base + RTC_INT_STS); > > + /* Clear RTC_INT_ALRM interrupt only */ > > + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_STS); > > > > - if (status & RTC_INT_SEC) > > - rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_UF); > > if (status & RTC_INT_ALRM) > > rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF); > > > > -- > > 2.1.2 > > > > -- > Alexandre Belloni, Free Electrons > Embedded Linux, Kernel and Android engineering > http://free-electrons.com This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.