linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: em3027: correct month value
@ 2019-10-31  7:36 Ilya Ledvich
  2019-10-31  9:53 ` Nobuhiro Iwamatsu
  0 siblings, 1 reply; 8+ messages in thread
From: Ilya Ledvich @ 2019-10-31  7:36 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: linux-rtc, Ilya Ledvich

The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
This may result in the RTC not rolling over correctly.

Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>
---
 drivers/rtc/rtc-em3027.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index 77cca1392253..ef3792543f93 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -71,7 +71,7 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
 	tm->tm_hour	= bcd2bin(buf[2]);
 	tm->tm_mday	= bcd2bin(buf[3]);
 	tm->tm_wday	= bcd2bin(buf[4]);
-	tm->tm_mon	= bcd2bin(buf[5]);
+	tm->tm_mon	= bcd2bin(buf[5]) - 1;
 	tm->tm_year	= bcd2bin(buf[6]) + 100;
 
 	return 0;
@@ -94,7 +94,7 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
 	buf[3] = bin2bcd(tm->tm_hour);
 	buf[4] = bin2bcd(tm->tm_mday);
 	buf[5] = bin2bcd(tm->tm_wday);
-	buf[6] = bin2bcd(tm->tm_mon);
+	buf[6] = bin2bcd(tm->tm_mon) + 1;
 	buf[7] = bin2bcd(tm->tm_year % 100);
 
 	/* write time/date registers */
-- 
2.20.1


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

* Re: [PATCH] rtc: em3027: correct month value
  2019-10-31  7:36 [PATCH] rtc: em3027: correct month value Ilya Ledvich
@ 2019-10-31  9:53 ` Nobuhiro Iwamatsu
  2019-10-31 10:27   ` Alexandre Belloni
  0 siblings, 1 reply; 8+ messages in thread
From: Nobuhiro Iwamatsu @ 2019-10-31  9:53 UTC (permalink / raw)
  To: Ilya Ledvich; +Cc: Alexandre Belloni, linux-rtc

Hi,

2019年10月31日(木) 16:57 Ilya Ledvich <ilya@compulab.co.il>:
>
> The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
> This may result in the RTC not rolling over correctly.
>
> Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>
> ---
>  drivers/rtc/rtc-em3027.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
> index 77cca1392253..ef3792543f93 100644
> --- a/drivers/rtc/rtc-em3027.c
> +++ b/drivers/rtc/rtc-em3027.c
> @@ -71,7 +71,7 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
>         tm->tm_hour     = bcd2bin(buf[2]);
>         tm->tm_mday     = bcd2bin(buf[3]);
>         tm->tm_wday     = bcd2bin(buf[4]);
> -       tm->tm_mon      = bcd2bin(buf[5]);
> +       tm->tm_mon      = bcd2bin(buf[5]) - 1;
>         tm->tm_year     = bcd2bin(buf[6]) + 100;
>
>         return 0;
> @@ -94,7 +94,7 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
>         buf[3] = bin2bcd(tm->tm_hour);
>         buf[4] = bin2bcd(tm->tm_mday);
>         buf[5] = bin2bcd(tm->tm_wday);
> -       buf[6] = bin2bcd(tm->tm_mon);
> +       buf[6] = bin2bcd(tm->tm_mon) + 1;

I think '+'1 should be set in bin2bcd().

>         buf[7] = bin2bcd(tm->tm_year % 100);
>
>         /* write time/date registers */
> --
> 2.20.1
>

Best regards,
  Nobuhiro

-- 
Nobuhiro Iwamatsu
   iwamatsu at {nigauri.org / debian.org}
   GPG ID: 40AD1FA6

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

* Re: [PATCH] rtc: em3027: correct month value
  2019-10-31  9:53 ` Nobuhiro Iwamatsu
@ 2019-10-31 10:27   ` Alexandre Belloni
  2019-10-31 12:07     ` Ilya Ledvich
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alexandre Belloni @ 2019-10-31 10:27 UTC (permalink / raw)
  To: Nobuhiro Iwamatsu; +Cc: Ilya Ledvich, linux-rtc

On 31/10/2019 18:53:00+0900, Nobuhiro Iwamatsu wrote:
> Hi,
> 
> 2019年10月31日(木) 16:57 Ilya Ledvich <ilya@compulab.co.il>:
> >
> > The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
> > This may result in the RTC not rolling over correctly.
> >
> > Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>
> > ---
> >  drivers/rtc/rtc-em3027.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
> > index 77cca1392253..ef3792543f93 100644
> > --- a/drivers/rtc/rtc-em3027.c
> > +++ b/drivers/rtc/rtc-em3027.c
> > @@ -71,7 +71,7 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
> >         tm->tm_hour     = bcd2bin(buf[2]);
> >         tm->tm_mday     = bcd2bin(buf[3]);
> >         tm->tm_wday     = bcd2bin(buf[4]);
> > -       tm->tm_mon      = bcd2bin(buf[5]);
> > +       tm->tm_mon      = bcd2bin(buf[5]) - 1;
> >         tm->tm_year     = bcd2bin(buf[6]) + 100;
> >
> >         return 0;
> > @@ -94,7 +94,7 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
> >         buf[3] = bin2bcd(tm->tm_hour);
> >         buf[4] = bin2bcd(tm->tm_mday);
> >         buf[5] = bin2bcd(tm->tm_wday);
> > -       buf[6] = bin2bcd(tm->tm_mon);
> > +       buf[6] = bin2bcd(tm->tm_mon) + 1;
> 
> I think '+'1 should be set in bin2bcd().
> 

This is correct.

Ilya, could you also run
https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c
on that rtc? I'm interested in the full output. It seems this RTC
working range is 2000 to 2079

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH] rtc: em3027: correct month value
  2019-10-31 10:27   ` Alexandre Belloni
@ 2019-10-31 12:07     ` Ilya Ledvich
  2019-10-31 12:16     ` Ilya Ledvich
  2019-11-01  9:54     ` [PATCH v2] " Ilya Ledvich
  2 siblings, 0 replies; 8+ messages in thread
From: Ilya Ledvich @ 2019-10-31 12:07 UTC (permalink / raw)
  To: Alexandre Belloni, Nobuhiro Iwamatsu; +Cc: linux-rtc

Hi,

On 10/31/19 12:27 PM, Alexandre Belloni wrote:
> On 31/10/2019 18:53:00+0900, Nobuhiro Iwamatsu wrote:
>> Hi,
>>
>> 2019年10月31日(木) 16:57 Ilya Ledvich <ilya@compulab.co.il>:
>>> The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
>>> This may result in the RTC not rolling over correctly.
>>>
>>> Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>
>>> ---
>>>   drivers/rtc/rtc-em3027.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
>>> index 77cca1392253..ef3792543f93 100644
>>> --- a/drivers/rtc/rtc-em3027.c
>>> +++ b/drivers/rtc/rtc-em3027.c
>>> @@ -71,7 +71,7 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
>>>          tm->tm_hour     = bcd2bin(buf[2]);
>>>          tm->tm_mday     = bcd2bin(buf[3]);
>>>          tm->tm_wday     = bcd2bin(buf[4]);
>>> -       tm->tm_mon      = bcd2bin(buf[5]);
>>> +       tm->tm_mon      = bcd2bin(buf[5]) - 1;
>>>          tm->tm_year     = bcd2bin(buf[6]) + 100;
>>>
>>>          return 0;
>>> @@ -94,7 +94,7 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
>>>          buf[3] = bin2bcd(tm->tm_hour);
>>>          buf[4] = bin2bcd(tm->tm_mday);
>>>          buf[5] = bin2bcd(tm->tm_wday);
>>> -       buf[6] = bin2bcd(tm->tm_mon);
>>> +       buf[6] = bin2bcd(tm->tm_mon) + 1;
>> I think '+'1 should be set in bin2bcd().
>>
> This is correct.
Thank you for the note. I'll fix it and send v2.
>
> Ilya, could you also run
> https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c
> on that rtc? I'm interested in the full output. It seems this RTC
> working range is 2000 to 2079

According to the data sheet its range is 2000 to 2079 indeed.

Please find the full output below.

Testing 2000-02-28 23:59:59.
OK

Testing 2038-01-19 03:14:07.
OK

Testing 2069-12-31 23:59:59.
OK

Testing 2099-12-31 23:59:59.
KO  Read back 2019-12-31 23:59:59.

Testing 2100-02-28 23:59:59.
KO  Read back 2000-02-28 23:59:59.

Testing 2106-02-07 06:28:15.
KO  Read back 2006-02-07 06:28:15.

Testing 2262-04-11 23:47:16.
KO  Read back 2062-04-11 23:47:16.


Kind regards,

Ilya


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

* Re: [PATCH] rtc: em3027: correct month value
  2019-10-31 10:27   ` Alexandre Belloni
  2019-10-31 12:07     ` Ilya Ledvich
@ 2019-10-31 12:16     ` Ilya Ledvich
  2019-11-01  9:54     ` [PATCH v2] " Ilya Ledvich
  2 siblings, 0 replies; 8+ messages in thread
From: Ilya Ledvich @ 2019-10-31 12:16 UTC (permalink / raw)
  To: Alexandre Belloni, Nobuhiro Iwamatsu; +Cc: linux-rtc

Hi,

On 10/31/19 12:27 PM, Alexandre Belloni wrote:
> On 31/10/2019 18:53:00+0900, Nobuhiro Iwamatsu wrote:
>> Hi,
>>
>> 2019年10月31日(木) 16:57 Ilya Ledvich <ilya@compulab.co.il>:
>>> The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
>>> This may result in the RTC not rolling over correctly.
>>>
>>> Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>
>>> ---
>>>   drivers/rtc/rtc-em3027.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
>>> index 77cca1392253..ef3792543f93 100644
>>> --- a/drivers/rtc/rtc-em3027.c
>>> +++ b/drivers/rtc/rtc-em3027.c
>>> @@ -71,7 +71,7 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
>>>          tm->tm_hour     = bcd2bin(buf[2]);
>>>          tm->tm_mday     = bcd2bin(buf[3]);
>>>          tm->tm_wday     = bcd2bin(buf[4]);
>>> -       tm->tm_mon      = bcd2bin(buf[5]);
>>> +       tm->tm_mon      = bcd2bin(buf[5]) - 1;
>>>          tm->tm_year     = bcd2bin(buf[6]) + 100;
>>>
>>>          return 0;
>>> @@ -94,7 +94,7 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
>>>          buf[3] = bin2bcd(tm->tm_hour);
>>>          buf[4] = bin2bcd(tm->tm_mday);
>>>          buf[5] = bin2bcd(tm->tm_wday);
>>> -       buf[6] = bin2bcd(tm->tm_mon);
>>> +       buf[6] = bin2bcd(tm->tm_mon) + 1;
>> I think '+'1 should be set in bin2bcd().
>>
> This is correct.
Thank you for the note. I'll fix it and send v2.
> Ilya, could you also run
> https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c
> on that rtc? I'm interested in the full output. It seems this RTC
> working range is 2000 to 2079
>
According to the data sheet its range is 2000 to 2079 indeed.
Please find the full output below.
---
Testing 2000-02-28 23:59:59.
OK

Testing 2038-01-19 03:14:07.
OK

Testing 2069-12-31 23:59:59.
OK

Testing 2099-12-31 23:59:59.
KO  Read back 2019-12-31 23:59:59.

Testing 2100-02-28 23:59:59.
KO  Read back 2000-02-28 23:59:59.

Testing 2106-02-07 06:28:15.
KO  Read back 2006-02-07 06:28:15.

Testing 2262-04-11 23:47:16.
KO  Read back 2062-04-11 23:47:16.

---

Kind regards,

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

* [PATCH v2] rtc: em3027: correct month value
  2019-10-31 10:27   ` Alexandre Belloni
  2019-10-31 12:07     ` Ilya Ledvich
  2019-10-31 12:16     ` Ilya Ledvich
@ 2019-11-01  9:54     ` Ilya Ledvich
  2019-11-04  1:10       ` Nobuhiro Iwamatsu
  2019-11-05 17:19       ` Alexandre Belloni
  2 siblings, 2 replies; 8+ messages in thread
From: Ilya Ledvich @ 2019-11-01  9:54 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Nobuhiro Iwamatsu, linux-rtc, Ilya Ledvich

The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
This may result in the RTC not rolling over correctly.

Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>
---
 drivers/rtc/rtc-em3027.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index 77cca1392253..9f176bce48ba 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -71,7 +71,7 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
 	tm->tm_hour	= bcd2bin(buf[2]);
 	tm->tm_mday	= bcd2bin(buf[3]);
 	tm->tm_wday	= bcd2bin(buf[4]);
-	tm->tm_mon	= bcd2bin(buf[5]);
+	tm->tm_mon	= bcd2bin(buf[5]) - 1;
 	tm->tm_year	= bcd2bin(buf[6]) + 100;
 
 	return 0;
@@ -94,7 +94,7 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
 	buf[3] = bin2bcd(tm->tm_hour);
 	buf[4] = bin2bcd(tm->tm_mday);
 	buf[5] = bin2bcd(tm->tm_wday);
-	buf[6] = bin2bcd(tm->tm_mon);
+	buf[6] = bin2bcd(tm->tm_mon + 1);
 	buf[7] = bin2bcd(tm->tm_year % 100);
 
 	/* write time/date registers */
-- 
2.20.1


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

* Re: [PATCH v2] rtc: em3027: correct month value
  2019-11-01  9:54     ` [PATCH v2] " Ilya Ledvich
@ 2019-11-04  1:10       ` Nobuhiro Iwamatsu
  2019-11-05 17:19       ` Alexandre Belloni
  1 sibling, 0 replies; 8+ messages in thread
From: Nobuhiro Iwamatsu @ 2019-11-04  1:10 UTC (permalink / raw)
  To: Ilya Ledvich; +Cc: Alexandre Belloni, linux-rtc

Hi,

2019年11月1日(金) 18:54 Ilya Ledvich <ilya@compulab.co.il>:
>
> The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
> This may result in the RTC not rolling over correctly.
>
> Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>

Reviewed-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

Best regards,
  Nobuhiro

> ---
>  drivers/rtc/rtc-em3027.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
> index 77cca1392253..9f176bce48ba 100644
> --- a/drivers/rtc/rtc-em3027.c
> +++ b/drivers/rtc/rtc-em3027.c
> @@ -71,7 +71,7 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
>         tm->tm_hour     = bcd2bin(buf[2]);
>         tm->tm_mday     = bcd2bin(buf[3]);
>         tm->tm_wday     = bcd2bin(buf[4]);
> -       tm->tm_mon      = bcd2bin(buf[5]);
> +       tm->tm_mon      = bcd2bin(buf[5]) - 1;
>         tm->tm_year     = bcd2bin(buf[6]) + 100;
>
>         return 0;
> @@ -94,7 +94,7 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
>         buf[3] = bin2bcd(tm->tm_hour);
>         buf[4] = bin2bcd(tm->tm_mday);
>         buf[5] = bin2bcd(tm->tm_wday);
> -       buf[6] = bin2bcd(tm->tm_mon);
> +       buf[6] = bin2bcd(tm->tm_mon + 1);
>         buf[7] = bin2bcd(tm->tm_year % 100);
>
>         /* write time/date registers */
> --
> 2.20.1
>


--
Nobuhiro Iwamatsu
   iwamatsu at {nigauri.org / debian.org}
   GPG ID: 40AD1FA6

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

* Re: [PATCH v2] rtc: em3027: correct month value
  2019-11-01  9:54     ` [PATCH v2] " Ilya Ledvich
  2019-11-04  1:10       ` Nobuhiro Iwamatsu
@ 2019-11-05 17:19       ` Alexandre Belloni
  1 sibling, 0 replies; 8+ messages in thread
From: Alexandre Belloni @ 2019-11-05 17:19 UTC (permalink / raw)
  To: Ilya Ledvich; +Cc: Nobuhiro Iwamatsu, linux-rtc

On 01/11/2019 11:54:22+0200, Ilya Ledvich wrote:
> The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed.
> This may result in the RTC not rolling over correctly.
> 
> Signed-off-by: Ilya Ledvich <ilya@compulab.co.il>
> ---
>  drivers/rtc/rtc-em3027.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2019-11-05 17:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31  7:36 [PATCH] rtc: em3027: correct month value Ilya Ledvich
2019-10-31  9:53 ` Nobuhiro Iwamatsu
2019-10-31 10:27   ` Alexandre Belloni
2019-10-31 12:07     ` Ilya Ledvich
2019-10-31 12:16     ` Ilya Ledvich
2019-11-01  9:54     ` [PATCH v2] " Ilya Ledvich
2019-11-04  1:10       ` Nobuhiro Iwamatsu
2019-11-05 17:19       ` Alexandre Belloni

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).