Patchwork [3/3] rtc: rtc-s3c: Add BCD register initialization codes

login
register
mail settings
Submitter Kukjin Kim
Date July 21, 2010, 8:57 a.m.
Message ID <1279702666-13021-4-git-send-email-kgene.kim@samsung.com>
Download mbox | patch
Permalink /patch/59418/
State New
Headers show

Comments

Kukjin Kim - July 21, 2010, 8:57 a.m.
From: Taekgyun Ko <taeggyun.ko@samsung.com>

RTC needs to be initialized when BCD registers have invalid value.

Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
---
 drivers/rtc/rtc-s3c.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
Sergei Shtylyov - July 21, 2010, 2:42 p.m.
Hello.

Kukjin Kim wrote:

> From: Taekgyun Ko <taeggyun.ko@samsung.com>

> RTC needs to be initialized when BCD registers have invalid value.

> Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
> Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
[...]
> diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> index 2040017..e96e109 100644
> --- a/drivers/rtc/rtc-s3c.c
> +++ b/drivers/rtc/rtc-s3c.c
> @@ -536,10 +536,20 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
>  
>  	s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
>  
> -	if (s3c_rtc_cpu_type == TYPE_S3C64XX)
> +	if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
>  		rtc->max_user_freq = 32768;
> -	else
> +
> +		/* Check RTC Time */
> +
> +		for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
> +			tmp = readb(s3c_rtc_base + i);
> +
> +			if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) > 0x9))

   There is no need to have parens around > operations.

WBR, Sergei
Wan ZongShun - July 22, 2010, 1:50 a.m.
2010/7/21 Kukjin Kim <kgene.kim@samsung.com>:
> From: Taekgyun Ko <taeggyun.ko@samsung.com>
>
> RTC needs to be initialized when BCD registers have invalid value.

Do you mean that the hardware register does not have default value?
Any results if no initialized value here?

>
> Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
> Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
> ---
>  drivers/rtc/rtc-s3c.c |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> index 2040017..e96e109 100644
> --- a/drivers/rtc/rtc-s3c.c
> +++ b/drivers/rtc/rtc-s3c.c
> @@ -536,10 +536,20 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
>
>        s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
>
> -       if (s3c_rtc_cpu_type == TYPE_S3C64XX)
> +       if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
>                rtc->max_user_freq = 32768;
> -       else
> +
> +               /* Check RTC Time */
> +
> +               for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
> +                       tmp = readb(s3c_rtc_base + i);
> +
> +                       if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) > 0x9))
> +                               writeb(0, s3c_rtc_base + i);
> +               }
> +       } else {
>                rtc->max_user_freq = 128;
> +       }
>
>        platform_set_drvdata(pdev, rtc);
>
> --
> 1.6.2.5
>
> --
> You received this message because you are subscribed to "rtc-linux".
> Membership options at http://groups.google.com/group/rtc-linux .
> Please read http://groups.google.com/group/rtc-linux/web/checklist
> before submitting a driver.
Kukjin Kim - July 23, 2010, 7:04 a.m.
Sergei Shtylyov wrote:
> 
> Hello.
> 
Hi :-)

> Kukjin Kim wrote:
> 
> > From: Taekgyun Ko <taeggyun.ko@samsung.com>
> 
> > RTC needs to be initialized when BCD registers have invalid value.
> 
> > Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
> > Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
> [...]
> > diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> > index 2040017..e96e109 100644
> > --- a/drivers/rtc/rtc-s3c.c
> > +++ b/drivers/rtc/rtc-s3c.c
> > @@ -536,10 +536,20 @@ static int __devinit s3c_rtc_probe(struct
> platform_device *pdev)
> >
> >  	s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
> >
> > -	if (s3c_rtc_cpu_type == TYPE_S3C64XX)
> > +	if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
> >  		rtc->max_user_freq = 32768;
> > -	else
> > +
> > +		/* Check RTC Time */
> > +
> > +		for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
> > +			tmp = readb(s3c_rtc_base + i);
> > +
> > +			if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) >
0x9))
> 
>    There is no need to have parens around > operations.
> 
Ok...you're right. will fix it.

Thanks.

Best regards,
Kgene.
--
Kukjin Kim <kgene.kim@samsung.com>, Senior Engineer,
SW Solution Development Team, Samsung Electronics Co., Ltd.
Kukjin Kim - July 23, 2010, 7:34 a.m.
Wan ZongShun wrote:
> 
> 2010/7/21 Kukjin Kim <kgene.kim@samsung.com>:
> > From: Taekgyun Ko <taeggyun.ko@samsung.com>
> >
> > RTC needs to be initialized when BCD registers have invalid value.
> 
> Do you mean that the hardware register does not have default value?
> Any results if no initialized value here?
> 
Hi,

Yes..I mean that it has no default value.
As you know, it has to be keep the previous time value after reset..and the reset value is not defined.

So added check that functionality, because if it has no valid BCD value, RTC time does not move on.
Of course, if we set time at that time, RTC works well...I mean just need initialize that.

> >
> > Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
> > Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
> > ---
> >  drivers/rtc/rtc-s3c.c |   14 ++++++++++++--
> >  1 files changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> > index 2040017..e96e109 100644
> > --- a/drivers/rtc/rtc-s3c.c
> > +++ b/drivers/rtc/rtc-s3c.c
> > @@ -536,10 +536,20 @@ static int __devinit s3c_rtc_probe(struct
> platform_device *pdev)
> >
> >        s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
> >
> > -       if (s3c_rtc_cpu_type == TYPE_S3C64XX)
> > +       if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
> >                rtc->max_user_freq = 32768;
> > -       else
> > +
> > +               /* Check RTC Time */
> > +
> > +               for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
> > +                       tmp = readb(s3c_rtc_base + i);
> > +
> > +                       if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) > 0x9))
> > +                               writeb(0, s3c_rtc_base + i);
> > +               }
> > +       } else {
> >                rtc->max_user_freq = 128;
> > +       }
> >
> >        platform_set_drvdata(pdev, rtc);
> >
> > --
> > 1.6.2.5
> >


Thanks.

Best regards,
Kgene.
--
Kukjin Kim <kgene.kim@samsung.com>, Senior Engineer,
SW Solution Development Team, Samsung Electronics Co., Ltd.
Wan ZongShun - July 23, 2010, 9:28 a.m.
2010/7/23 Kukjin Kim <kgene.kim@samsung.com>:
> Wan ZongShun wrote:
>>
>> 2010/7/21 Kukjin Kim <kgene.kim@samsung.com>:
>> > From: Taekgyun Ko <taeggyun.ko@samsung.com>
>> >
>> > RTC needs to be initialized when BCD registers have invalid value.
>>
>> Do you mean that the hardware register does not have default value?
>> Any results if no initialized value here?
>>
> Hi,
>
> Yes..I mean that it has no default value.
> As you know, it has to be keep the previous time value after reset..and the reset value is not defined.
>

So, reset is no use to this RTC BCD registers, it still keep previous
time value.

> So added check that functionality, because if it has no valid BCD value, RTC time does not move on.
> Of course, if we set time at that time, RTC works well...I mean just need initialize that.
>

Okay,good patch.:)

In addtion,For making sure to get valid value, it is much better to
use also 'rtc_valid_tm(tm)' to check returning time value in your
s3c_rtc_gettime() and s3c_rtc_getalarm(() functions.


>> >
>> > Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
>> > Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
>> > ---
>> >  drivers/rtc/rtc-s3c.c |   14 ++++++++++++--
>> >  1 files changed, 12 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
>> > index 2040017..e96e109 100644
>> > --- a/drivers/rtc/rtc-s3c.c
>> > +++ b/drivers/rtc/rtc-s3c.c
>> > @@ -536,10 +536,20 @@ static int __devinit s3c_rtc_probe(struct
>> platform_device *pdev)
>> >
>> >        s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
>> >
>> > -       if (s3c_rtc_cpu_type == TYPE_S3C64XX)
>> > +       if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
>> >                rtc->max_user_freq = 32768;
>> > -       else
>> > +
>> > +               /* Check RTC Time */
>> > +
>> > +               for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
>> > +                       tmp = readb(s3c_rtc_base + i);
>> > +
>> > +                       if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) > 0x9))
>> > +                               writeb(0, s3c_rtc_base + i);
>> > +               }
>> > +       } else {
>> >                rtc->max_user_freq = 128;
>> > +       }
>> >
>> >        platform_set_drvdata(pdev, rtc);
>> >
>> > --
>> > 1.6.2.5
>> >
>
>
> Thanks.
>
> Best regards,
> Kgene.
> --
> Kukjin Kim <kgene.kim@samsung.com>, Senior Engineer,
> SW Solution Development Team, Samsung Electronics Co., Ltd.
>
> --
> You received this message because you are subscribed to "rtc-linux".
> Membership options at http://groups.google.com/group/rtc-linux .
> Please read http://groups.google.com/group/rtc-linux/web/checklist
> before submitting a driver.
Kukjin Kim - July 27, 2010, 1:11 p.m.
Wan ZongShun wrote:

> 
> 2010/7/23 Kukjin Kim <kgene.kim@samsung.com>:
> > Wan ZongShun wrote:
> >>
> >> 2010/7/21 Kukjin Kim <kgene.kim@samsung.com>:
> >> > From: Taekgyun Ko <taeggyun.ko@samsung.com>
> >> >
> >> > RTC needs to be initialized when BCD registers have invalid value.
> >>
> >> Do you mean that the hardware register does not have default value?
> >> Any results if no initialized value here?
> >>
> > Hi,
> >
> > Yes..I mean that it has no default value.
> > As you know, it has to be keep the previous time value after reset..and the reset
> value is not defined.
> >
> 
> So, reset is no use to this RTC BCD registers, it still keep previous
> time value.
> 
> > So added check that functionality, because if it has no valid BCD value, RTC
> time does not move on.
> > Of course, if we set time at that time, RTC works well...I mean just need initialize
> that.
> >
> 
> Okay,good patch.:)
> 
Thanks ;-)

> In addtion,For making sure to get valid value, it is much better to
> use also 'rtc_valid_tm(tm)' to check returning time value in your
> s3c_rtc_gettime() and s3c_rtc_getalarm(() functions.
> 
Ok..will do it later as per your suggestion.

> 
> >> >
> >> > Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
> >> > Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
> >> > ---
> >> >  drivers/rtc/rtc-s3c.c |   14 ++++++++++++--
> >> >  1 files changed, 12 insertions(+), 2 deletions(-)
> >> >
(snip)


Thanks.

Best regards,
Kgene.
--
Kukjin Kim <kgene.kim@samsung.com>, Senior Engineer,
SW Solution Development Team, Samsung Electronics Co., Ltd.
Ben Dooks - July 28, 2010, 6:17 p.m.
On 21/07/10 09:57, Kukjin Kim wrote:
> From: Taekgyun Ko <taeggyun.ko@samsung.com>
> 
> RTC needs to be initialized when BCD registers have invalid value.
> 
> Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
> Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
> ---
>  drivers/rtc/rtc-s3c.c |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> index 2040017..e96e109 100644
> --- a/drivers/rtc/rtc-s3c.c
> +++ b/drivers/rtc/rtc-s3c.c
> @@ -536,10 +536,20 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
>  
>  	s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
>  
> -	if (s3c_rtc_cpu_type == TYPE_S3C64XX)
> +	if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
>  		rtc->max_user_freq = 32768;
> -	else
> +
> +		/* Check RTC Time */
> +
> +		for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
> +			tmp = readb(s3c_rtc_base + i);
> +
> +			if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) > 0x9))
> +				writeb(0, s3c_rtc_base + i);

This is something we should probably do for all SoCs.
Kukjin Kim - July 29, 2010, 1:55 a.m.
Ben Dooks wrote:
> 
> On 21/07/10 09:57, Kukjin Kim wrote:
> > From: Taekgyun Ko <taeggyun.ko@samsung.com>
> >
> > RTC needs to be initialized when BCD registers have invalid value.
> >
> > Signed-off-by: Taekgyun Ko <taeggyun.ko@samsung.com>
> > Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
> > ---
> >  drivers/rtc/rtc-s3c.c |   14 ++++++++++++--
> >  1 files changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> > index 2040017..e96e109 100644
> > --- a/drivers/rtc/rtc-s3c.c
> > +++ b/drivers/rtc/rtc-s3c.c
> > @@ -536,10 +536,20 @@ static int __devinit s3c_rtc_probe(struct
> platform_device *pdev)
> >
> >  	s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
> >
> > -	if (s3c_rtc_cpu_type == TYPE_S3C64XX)
> > +	if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
> >  		rtc->max_user_freq = 32768;
> > -	else
> > +
> > +		/* Check RTC Time */
> > +
> > +		for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
> > +			tmp = readb(s3c_rtc_base + i);
> > +
> > +			if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) >
0x9))
> > +				writeb(0, s3c_rtc_base + i);
> 
> This is something we should probably do for all SoCs.

Yeah...ok...will move it.

Thanks.

Best regards,
Kgene.
--
Kukjin Kim <kgene.kim@samsung.com>, Senior Engineer,
SW Solution Development Team, Samsung Electronics Co., Ltd.

Patch

diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 2040017..e96e109 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -536,10 +536,20 @@  static int __devinit s3c_rtc_probe(struct platform_device *pdev)
 
 	s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
 
-	if (s3c_rtc_cpu_type == TYPE_S3C64XX)
+	if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
 		rtc->max_user_freq = 32768;
-	else
+
+		/* Check RTC Time */
+
+		for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
+			tmp = readb(s3c_rtc_base + i);
+
+			if (((tmp & 0xf) > 0x9) || (((tmp >> 4) & 0xf) > 0x9))
+				writeb(0, s3c_rtc_base + i);
+		}
+	} else {
 		rtc->max_user_freq = 128;
+	}
 
 	platform_set_drvdata(pdev, rtc);