devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Arnaud Ebalard <arno@natisbad.org>
Cc: "Mark Rutland" <mark.rutland@arm.com>,
	"Alessandro Zummo" <a.zummo@towertech.it>,
	"Peter Huewe" <peter.huewe@infineon.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Thierry Reding" <treding@nvidia.com>,
	"Mark Brown" <broonie@kernel.org>,
	devicetree@vger.kernel.org, rtc-linux@googlegroups.com,
	"Pawel Moll" <pawel.moll@arm.com>,
	"Ian Campbell" <ijc+devicetree@hellion.org.uk>,
	"Stephen Warren" <swarren@wwwdotorg.org>,
	linux-doc@vger.kernel.org,
	"Rob Herring" <rob.herring@calxeda.com>,
	"Jason Gunthorpe" <jgunthorpe@obsidianresearch.com>,
	"Uwe Kleine-König" <uwe@kleine-koenig.org>,
	linux-arm-kernel@lists.infradead.org,
	"Rob Landley" <rob@landley.net>,
	"Kumar Gala" <galak@codeaurora.org>,
	"Grant Likely" <grant.likely@linaro.org>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Jason Cooper" <jason@lakedaemon.net>
Subject: Re: [PATCHv0 1/3] rtc: rtc-isl12057: fix masking of register values
Date: Thu, 6 Nov 2014 09:29:46 +0100	[thread overview]
Message-ID: <20141106082946.GN8316@pengutronix.de> (raw)
In-Reply-To: <917b6e5e869fce697dec8a1597dfd2f671bf5c46.1415222752.git.arno@natisbad.org>

Hello Arnaud,

On Wed, Nov 05, 2014 at 10:42:25PM +0100, Arnaud Ebalard wrote:
> When Intersil ISL12057 support was added by commit 70e123373c05 ("rtc:
> Add support for Intersil ISL12057 I2C RTC chip"), two masks for time
> registers values imported from the device were either wrong or
> omitted, leading to additional bits from those registers to impact
> read values:
> 
>  - mask for hour register value when reading it in AM/PM mode. As
>    AM/PM mode is not the usual mode used by the driver, this error
>    would only have an impact on an externally configured RTC hour
>    later read by the driver.
>  - mask for month value. The lack of masking would provide an
>    erroneous value if century bit is set.
> 
> This patch fixes those two masks.
> 
> Fixes: 70e123373c05 ("rtc: Add support for Intersil ISL12057 I2C RTC chip")
> Signed-off-by: Arnaud Ebalard <arno@natisbad.org>
> ---
>  drivers/rtc/rtc-isl12057.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-isl12057.c b/drivers/rtc/rtc-isl12057.c
> index 455b601d731d..8132fbc7e10a 100644
> --- a/drivers/rtc/rtc-isl12057.c
> +++ b/drivers/rtc/rtc-isl12057.c
> @@ -88,7 +88,7 @@ static void isl12057_rtc_regs_to_tm(struct rtc_time *tm, u8 *regs)
>  	tm->tm_min = bcd2bin(regs[ISL12057_REG_RTC_MN]);
>  
>  	if (regs[ISL12057_REG_RTC_HR] & ISL12057_REG_RTC_HR_MIL) { /* AM/PM */
> -		tm->tm_hour = bcd2bin(regs[ISL12057_REG_RTC_HR] & 0x0f);
> +		tm->tm_hour = bcd2bin(regs[ISL12057_REG_RTC_HR] & 0x1f);
>  		if (regs[ISL12057_REG_RTC_HR] & ISL12057_REG_RTC_HR_PM)
>  			tm->tm_hour += 12;
>  	} else {					    /* 24 hour mode */
> @@ -96,8 +96,8 @@ static void isl12057_rtc_regs_to_tm(struct rtc_time *tm, u8 *regs)
>  	}
>  
>  	tm->tm_mday = bcd2bin(regs[ISL12057_REG_RTC_DT]);
> -	tm->tm_wday = bcd2bin(regs[ISL12057_REG_RTC_DW]) - 1; /* starts at 1 */
> +	tm->tm_wday = bcd2bin(regs[ISL12057_REG_RTC_DW]) - 1;  /* starts at 1 */
unrelated change?

> -	tm->tm_mon  = bcd2bin(regs[ISL12057_REG_RTC_MO]) - 1; /* starts at 1 */
> +	tm->tm_mon  = bcd2bin(regs[ISL12057_REG_RTC_MO] & 0x1f) - 1; /* ditto */
>  	tm->tm_year = bcd2bin(regs[ISL12057_REG_RTC_YR]) + 100;
>  }
This patch definitly improves the driver, still I see room for more
improvement (all but the first issue are unrelated to this patch):

 - There is a century bit in the RTC_MO driver that is now correctly
   masked to determine the month. Shouldn't it be used to flag if year
   is >= 2100? That seems to match the hardware leap year handling.
   (I.e. it considers RTC_YR=0 not to be a leap year iff RTC_MO_CENTURY
   is set.)

 - I wonder how tm_wday should be handled. It seems to be hardly used by
   callers of rtc_read_time. Is it better to report the hardware state
   here or the weekday matching year/month/day?

 - IMHO the probe function shouldn't clear the OSCILLATOR FAILURE BIT
   (OSF). It's an indicator that the stored time is wrong. Instead this
   bit should be evaluated in the read_time callback. (If it's set,
   return -ENODATA.) And only clear the bit in .set_time when the
   registers were updated. I think most drivers get that wrong.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

  reply	other threads:[~2014-11-06  8:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05 21:42 [PATCHv0 0/3] rtc: rtc-isl12057: fixes and alarm support Arnaud Ebalard
     [not found] ` <cover.1415222752.git.arno-LkuqDEemtHBg9hUCZPvPmw@public.gmane.org>
2014-11-05 21:42   ` [PATCHv0 1/3] rtc: rtc-isl12057: fix masking of register values Arnaud Ebalard
2014-11-06  8:29     ` Uwe Kleine-König [this message]
2014-11-06 23:34       ` Arnaud Ebalard
2014-11-05 21:42   ` [PATCHv0 2/3] rtc: rtc-isl12057: fix isil vs isl naming for intersil Arnaud Ebalard
2014-11-06  5:32     ` Mark Brown
2014-11-06 22:46       ` Arnaud Ebalard
2014-11-07  6:39         ` Uwe Kleine-König
2014-11-05 21:42   ` [PATCHv0 3/3] rtc: rtc-isl12057: add alarm support to Intersil ISL12057 RTC driver Arnaud Ebalard
2014-11-06  5:50     ` Mark Brown
2014-11-06  5:59       ` Guenter Roeck
2014-11-06  6:07         ` Mark Brown
2014-11-06 23:30       ` Arnaud Ebalard
2014-11-07  7:58         ` Uwe Kleine-König
2014-11-07  9:37           ` Arnaud Ebalard
2014-11-07  9:53           ` Mark Brown
2014-11-07  9:47         ` Mark Brown
2014-11-06  8:49     ` Uwe Kleine-König
2014-11-06 22:47       ` Arnaud Ebalard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141106082946.GN8316@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=a.zummo@towertech.it \
    --cc=arno@natisbad.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=grant.likely@linaro.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=jason@lakedaemon.net \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=peter.huewe@infineon.com \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=rtc-linux@googlegroups.com \
    --cc=swarren@wwwdotorg.org \
    --cc=treding@nvidia.com \
    --cc=uwe@kleine-koenig.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).