mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] RTC: RK808: fix the rtc time reading issue
@ 2015-01-14  2:43 Chris Zhong
  2015-01-14 18:00 ` Sonny Rao
  2015-01-14 18:39 ` Doug Anderson
  0 siblings, 2 replies; 7+ messages in thread
From: Chris Zhong @ 2015-01-14  2:43 UTC (permalink / raw)
  To: akpm
  Cc: dianders, heiko, linux-rockchip, Chris Zhong, Alessandro Zummo,
	rtc-linux, linux-kernel

After we set the GET_TIME bit, the rtc time couldn't be read immediately,
we should wait up to 31.25 us, about one cycle of 32khz. Otherwise reading
RTC time will return a old time. If clear the GET_TIME bit after setting,
the time of i2c transfer certainly more than 31.25us.

Signed-off-by: Chris Zhong <zyw@rock-chips.com>

---

 drivers/rtc/rtc-rk808.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
index df42257..8dae322 100644
--- a/drivers/rtc/rtc-rk808.c
+++ b/drivers/rtc/rtc-rk808.c
@@ -67,15 +67,20 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
 	/* Force an update of the shadowed registers right now */
 	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
-				 0);
+				 BIT_RTC_CTRL_REG_RTC_GET_TIME);
 	if (ret) {
 		dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
 		return ret;
 	}
 
+	/* After we set the GET_TIME bit, the rtc time couldn't be read
+	 * immediately, we should wait up to 31.25 us, about one cycle of
+	 * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
+	 * certainly more than 31.25us.
+	 */
 	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
-				 BIT_RTC_CTRL_REG_RTC_GET_TIME);
+				 0);
 	if (ret) {
 		dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
 		return ret;
-- 
1.9.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RTC: RK808: fix the rtc time reading issue
  2015-01-14  2:43 [PATCH] RTC: RK808: fix the rtc time reading issue Chris Zhong
@ 2015-01-14 18:00 ` Sonny Rao
  2015-01-14 18:36   ` Doug Anderson
  2015-01-14 18:39 ` Doug Anderson
  1 sibling, 1 reply; 7+ messages in thread
From: Sonny Rao @ 2015-01-14 18:00 UTC (permalink / raw)
  To: Chris Zhong
  Cc: Andrew Morton, Douglas Anderson, Heiko Stübner,
	linux-rockchip, Alessandro Zummo, rtc-linux, linux-kernel

On Tue, Jan 13, 2015 at 6:43 PM, Chris Zhong <zyw@rock-chips.com> wrote:
> After we set the GET_TIME bit, the rtc time couldn't be read immediately,
> we should wait up to 31.25 us, about one cycle of 32khz. Otherwise reading
> RTC time will return a old time. If clear the GET_TIME bit after setting,
> the time of i2c transfer certainly more than 31.25us.
>
> Signed-off-by: Chris Zhong <zyw@rock-chips.com>
>
> ---
>
>  drivers/rtc/rtc-rk808.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
> index df42257..8dae322 100644
> --- a/drivers/rtc/rtc-rk808.c
> +++ b/drivers/rtc/rtc-rk808.c
> @@ -67,15 +67,20 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
>         /* Force an update of the shadowed registers right now */
>         ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
>                                  BIT_RTC_CTRL_REG_RTC_GET_TIME,
> -                                0);
> +                                BIT_RTC_CTRL_REG_RTC_GET_TIME);
>         if (ret) {
>                 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
>                 return ret;
>         }
>
> +       /* After we set the GET_TIME bit, the rtc time couldn't be read
> +        * immediately, we should wait up to 31.25 us, about one cycle of
> +        * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
> +        * certainly more than 31.25us.
> +        */

Chris, it looks like you swapped the set and the clear of this bit,
and you're relying on the fact that the i2c transaction takes a
certain amount of time after the RTC_GET_TIME BIT is set.   I'm not
sure how long it actually takes, but why not just put in a usleep()
for the minimum wait time?

>         ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
>                                  BIT_RTC_CTRL_REG_RTC_GET_TIME,
> -                                BIT_RTC_CTRL_REG_RTC_GET_TIME);
> +                                0);
>         if (ret) {
>                 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
>                 return ret;
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RTC: RK808: fix the rtc time reading issue
  2015-01-14 18:00 ` Sonny Rao
@ 2015-01-14 18:36   ` Doug Anderson
  2015-01-14 19:44     ` Sonny Rao
  0 siblings, 1 reply; 7+ messages in thread
From: Doug Anderson @ 2015-01-14 18:36 UTC (permalink / raw)
  To: Sonny Rao
  Cc: Chris Zhong, Andrew Morton, Heiko Stübner,
	open list:ARM/Rockchip SoC...,
	Alessandro Zummo, rtc-linux, linux-kernel

Sonny,

> Chris, it looks like you swapped the set and the clear of this bit,
> and you're relying on the fact that the i2c transaction takes a
> certain amount of time after the RTC_GET_TIME BIT is set.   I'm not
> sure how long it actually takes, but why not just put in a usleep()
> for the minimum wait time?

I think we are safe.

At 400kHz (the max speed of this part) each bit can be transferred no
faster than 2.5us.  In order to do a valid i2c transaction we need to
_at least_ write the address of the device and the data onto the bus,
which is 16 bits.  16 * 2.5us = 40us.  That's above the 31.25us

Personally I think what Chris has is fine, with the comment.

-Doug

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RTC: RK808: fix the rtc time reading issue
  2015-01-14  2:43 [PATCH] RTC: RK808: fix the rtc time reading issue Chris Zhong
  2015-01-14 18:00 ` Sonny Rao
@ 2015-01-14 18:39 ` Doug Anderson
  1 sibling, 0 replies; 7+ messages in thread
From: Doug Anderson @ 2015-01-14 18:39 UTC (permalink / raw)
  To: Chris Zhong
  Cc: Andrew Morton, Heiko Stübner, open list:ARM/Rockchip SoC...,
	Alessandro Zummo, rtc-linux, linux-kernel

Chris,

On Tue, Jan 13, 2015 at 6:43 PM, Chris Zhong <zyw@rock-chips.com> wrote:
> +       /* After we set the GET_TIME bit, the rtc time couldn't be read
> +        * immediately, we should wait up to 31.25 us, about one cycle of
> +        * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
> +        * certainly more than 31.25us.
> +        */

No idea what Andrew thinks of this, but other multiline comments in
this file look slightly different (there's a line containing just /*).


>         ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
>                                  BIT_RTC_CTRL_REG_RTC_GET_TIME,
> -                                BIT_RTC_CTRL_REG_RTC_GET_TIME);
> +                                0);
>         if (ret) {
>                 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
>                 return ret;

Above is just a nit.  I'll leave it up to Andrew to say whether he
wants you to spin, or he'll fix it up, or he doesn't care and he'll
land it as-is.

Reviewed-by: Doug Anderson <dianders@chromium.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RTC: RK808: fix the rtc time reading issue
  2015-01-14 18:36   ` Doug Anderson
@ 2015-01-14 19:44     ` Sonny Rao
  2015-01-14 22:53       ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Sonny Rao @ 2015-01-14 19:44 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Chris Zhong, Andrew Morton, Heiko Stübner,
	open list:ARM/Rockchip SoC...,
	Alessandro Zummo, rtc-linux, linux-kernel

On Wed, Jan 14, 2015 at 10:36 AM, Doug Anderson <dianders@chromium.org> wrote:
> Sonny,
>
>> Chris, it looks like you swapped the set and the clear of this bit,
>> and you're relying on the fact that the i2c transaction takes a
>> certain amount of time after the RTC_GET_TIME BIT is set.   I'm not
>> sure how long it actually takes, but why not just put in a usleep()
>> for the minimum wait time?
>
> I think we are safe.
>
> At 400kHz (the max speed of this part) each bit can be transferred no
> faster than 2.5us.  In order to do a valid i2c transaction we need to
> _at least_ write the address of the device and the data onto the bus,
> which is 16 bits.  16 * 2.5us = 40us.  That's above the 31.25us
>
> Personally I think what Chris has is fine, with the comment.

Ok, I'm fine with that if we're sure it's slow enough.  Comment
explaining would certainly help.

>
> -Doug

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RTC: RK808: fix the rtc time reading issue
  2015-01-14 19:44     ` Sonny Rao
@ 2015-01-14 22:53       ` Andrew Morton
  2015-01-14 22:56         ` Doug Anderson
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2015-01-14 22:53 UTC (permalink / raw)
  To: Sonny Rao
  Cc: Doug Anderson, Chris Zhong, Heiko Stübner,
	open list:ARM/Rockchip SoC...,
	Alessandro Zummo, rtc-linux, linux-kernel

On Wed, 14 Jan 2015 11:44:02 -0800 Sonny Rao <sonnyrao@chromium.org> wrote:

> On Wed, Jan 14, 2015 at 10:36 AM, Doug Anderson <dianders@chromium.org> wrote:
> > Sonny,
> >
> >> Chris, it looks like you swapped the set and the clear of this bit,
> >> and you're relying on the fact that the i2c transaction takes a
> >> certain amount of time after the RTC_GET_TIME BIT is set.   I'm not
> >> sure how long it actually takes, but why not just put in a usleep()
> >> for the minimum wait time?
> >
> > I think we are safe.
> >
> > At 400kHz (the max speed of this part) each bit can be transferred no
> > faster than 2.5us.  In order to do a valid i2c transaction we need to
> > _at least_ write the address of the device and the data onto the bus,
> > which is 16 bits.  16 * 2.5us = 40us.  That's above the 31.25us
> >
> > Personally I think what Chris has is fine, with the comment.
> 
> Ok, I'm fine with that if we're sure it's slow enough.  Comment
> explaining would certainly help.

Thanks, all.  I did this:

--- a/drivers/rtc/rtc-rk808.c~rtc-rk808-fix-the-rtc-time-reading-issue-fix
+++ a/drivers/rtc/rtc-rk808.c
@@ -73,10 +73,11 @@ static int rk808_rtc_readtime(struct dev
 		return ret;
 	}
 
-	/* After we set the GET_TIME bit, the rtc time couldn't be read
-	 * immediately, we should wait up to 31.25 us, about one cycle of
+	/*
+	 * After we set the GET_TIME bit, the rtc time can't be read
+	 * immediately. So we should wait up to 31.25 us, about one cycle of
 	 * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
-	 * certainly more than 31.25us.
+	 * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
 	 */
 	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
_


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RTC: RK808: fix the rtc time reading issue
  2015-01-14 22:53       ` Andrew Morton
@ 2015-01-14 22:56         ` Doug Anderson
  0 siblings, 0 replies; 7+ messages in thread
From: Doug Anderson @ 2015-01-14 22:56 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Sonny Rao, Chris Zhong, Heiko Stübner,
	open list:ARM/Rockchip SoC...,
	Alessandro Zummo, rtc-linux, linux-kernel

Andrew,

On Wed, Jan 14, 2015 at 2:53 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Wed, 14 Jan 2015 11:44:02 -0800 Sonny Rao <sonnyrao@chromium.org> wrote:
>
>> On Wed, Jan 14, 2015 at 10:36 AM, Doug Anderson <dianders@chromium.org> wrote:
>> > Sonny,
>> >
>> >> Chris, it looks like you swapped the set and the clear of this bit,
>> >> and you're relying on the fact that the i2c transaction takes a
>> >> certain amount of time after the RTC_GET_TIME BIT is set.   I'm not
>> >> sure how long it actually takes, but why not just put in a usleep()
>> >> for the minimum wait time?
>> >
>> > I think we are safe.
>> >
>> > At 400kHz (the max speed of this part) each bit can be transferred no
>> > faster than 2.5us.  In order to do a valid i2c transaction we need to
>> > _at least_ write the address of the device and the data onto the bus,
>> > which is 16 bits.  16 * 2.5us = 40us.  That's above the 31.25us
>> >
>> > Personally I think what Chris has is fine, with the comment.
>>
>> Ok, I'm fine with that if we're sure it's slow enough.  Comment
>> explaining would certainly help.
>
> Thanks, all.  I did this:
>
> --- a/drivers/rtc/rtc-rk808.c~rtc-rk808-fix-the-rtc-time-reading-issue-fix
> +++ a/drivers/rtc/rtc-rk808.c
> @@ -73,10 +73,11 @@ static int rk808_rtc_readtime(struct dev
>                 return ret;
>         }
>
> -       /* After we set the GET_TIME bit, the rtc time couldn't be read
> -        * immediately, we should wait up to 31.25 us, about one cycle of
> +       /*
> +        * After we set the GET_TIME bit, the rtc time can't be read
> +        * immediately. So we should wait up to 31.25 us, about one cycle of
>          * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
> -        * certainly more than 31.25us.
> +        * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
>          */
>         ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
>                                  BIT_RTC_CTRL_REG_RTC_GET_TIME,

Looks great to me, thanks.

-Doug

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-01-14 22:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-14  2:43 [PATCH] RTC: RK808: fix the rtc time reading issue Chris Zhong
2015-01-14 18:00 ` Sonny Rao
2015-01-14 18:36   ` Doug Anderson
2015-01-14 19:44     ` Sonny Rao
2015-01-14 22:53       ` Andrew Morton
2015-01-14 22:56         ` Doug Anderson
2015-01-14 18:39 ` Doug Anderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®