From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757902AbcBXWZ7 (ORCPT ); Wed, 24 Feb 2016 17:25:59 -0500 Received: from down.free-electrons.com ([37.187.137.238]:58828 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752148AbcBXWZ5 (ORCPT ); Wed, 24 Feb 2016 17:25:57 -0500 Date: Wed, 24 Feb 2016 23:25:55 +0100 From: Alexandre Belloni To: Joshua Henderson Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Alessandro Zummo , rtc-linux@googlegroups.com Subject: Re: [PATCH v2 2/2] rtc: rtc-pic32: Add PIC32 real time clock driver Message-ID: <20160224222555.GA12073@piout.net> References: <1455905390-3491-2-git-send-email-joshua.henderson@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1455905390-3491-2-git-send-email-joshua.henderson@microchip.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 19/02/2016 at 11:09:45 -0700, Joshua Henderson wrote : > +static int pic32_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) > +{ > + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); > + void __iomem *base = pdata->reg_base; > + unsigned int tries = 0; > + > + clk_enable(pdata->clk); > + > + do { > + rtc_tm->tm_hour = readb(base + PIC32_RTCHOUR); > + rtc_tm->tm_min = readb(base + PIC32_RTCMIN); > + rtc_tm->tm_mon = readb(base + PIC32_RTCMON); > + rtc_tm->tm_mday = readb(base + PIC32_RTCDAY); > + rtc_tm->tm_year = readb(base + PIC32_RTCYEAR); > + rtc_tm->tm_sec = readb(base + PIC32_RTCSEC); > + > + /* > + * The only way to work out whether the system was mid-update > + * when we read it is to check the second counter, and if it > + * is zero, then we re-try the entire read. > + */ > + tries = 1; > + } while (rtc_tm->tm_sec == 0 && tries < 2); > + This doesn't seem right. It will wait up to a second as tries will always be less than 2, this is probably not what you want. > + rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); > + rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); > + rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); > + rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); > + rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon) - 1; > + rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); > + > + rtc_tm->tm_year += 100; > + > + dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", > + 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, > + rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); > + > + clk_disable(pdata->clk); > + return rtc_valid_tm(rtc_tm); > +} > + -- Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com