Message ID | 1347643742-19966-7-git-send-email-jose.goncalves@inov.pt |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
Dear José Miguel Gonçalves, > A better approach to avoid reading the RTC during updates, as sugested in > the S3C2416 User's Manual. > > Signed-off-by: José Miguel Gonçalves <jose.goncalves@inov.pt> > --- > Changes for v2: > - New patch > --- > drivers/rtc/s3c24x0_rtc.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/rtc/s3c24x0_rtc.c b/drivers/rtc/s3c24x0_rtc.c > index c16ff2e..7d04b74 100644 > --- a/drivers/rtc/s3c24x0_rtc.c > +++ b/drivers/rtc/s3c24x0_rtc.c > @@ -65,20 +65,26 @@ int rtc_get(struct rtc_time *tmp) > uchar sec, min, hour, mday, wday, mon, year; > __maybe_unused uchar a_sec, a_min, a_hour, a_date, > a_mon, a_year, a_armed; > + int have_retried = 0; > > /* enable access to RTC registers */ > SetRTC_Access(RTC_ENABLE); > > /* read RTC registers */ > do { > - sec = readb(&rtc->bcdsec); > min = readb(&rtc->bcdmin); > hour = readb(&rtc->bcdhour); > mday = readb(&rtc->bcddate); > wday = readb(&rtc->bcdday); > mon = readb(&rtc->bcdmon); > year = readb(&rtc->bcdyear); > - } while (sec != readb(&rtc->bcdsec)); > + sec = readb(&rtc->bcdsec); > + /* > + * The only way to work out whether the RTC was mid-update > + * when we read it is to check the seconds counter. > + * If it's zero, then we re-try the entire read. > + */ > + } while ((sec == 0) && !(have_retried++)); You don't need that parens around (have_retried++) > > /* read ALARM registers */ > a_sec = readb(&rtc->almsec); Best regards, Marek Vasut
diff --git a/drivers/rtc/s3c24x0_rtc.c b/drivers/rtc/s3c24x0_rtc.c index c16ff2e..7d04b74 100644 --- a/drivers/rtc/s3c24x0_rtc.c +++ b/drivers/rtc/s3c24x0_rtc.c @@ -65,20 +65,26 @@ int rtc_get(struct rtc_time *tmp) uchar sec, min, hour, mday, wday, mon, year; __maybe_unused uchar a_sec, a_min, a_hour, a_date, a_mon, a_year, a_armed; + int have_retried = 0; /* enable access to RTC registers */ SetRTC_Access(RTC_ENABLE); /* read RTC registers */ do { - sec = readb(&rtc->bcdsec); min = readb(&rtc->bcdmin); hour = readb(&rtc->bcdhour); mday = readb(&rtc->bcddate); wday = readb(&rtc->bcdday); mon = readb(&rtc->bcdmon); year = readb(&rtc->bcdyear); - } while (sec != readb(&rtc->bcdsec)); + sec = readb(&rtc->bcdsec); + /* + * The only way to work out whether the RTC was mid-update + * when we read it is to check the seconds counter. + * If it's zero, then we re-try the entire read. + */ + } while ((sec == 0) && !(have_retried++)); /* read ALARM registers */ a_sec = readb(&rtc->almsec);
A better approach to avoid reading the RTC during updates, as sugested in the S3C2416 User's Manual. Signed-off-by: José Miguel Gonçalves <jose.goncalves@inov.pt> --- Changes for v2: - New patch --- drivers/rtc/s3c24x0_rtc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)