Skip to contentSkip to conversation

rtc: remove redundant code in rtc_reset

PATCH New Chris Packham 3 participants 12 messages Mar 21, 2018 – Apr 7, 2018 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

cover rtc: remove redundant code in rtc_reset

Someone at $dayjob pointed out some inconsistent behaviour between the ds1307 and the ds1337 rtc drivers for an old version of u-boot. Basically with ds1307 "date reset" changed the time whereas for the ds1337 it did not.

I was about to send a patch to add code to ds1337 when I noticed Marek's commit 1a1fa2406689 ("rtc: Set valid date after reset"). This meant that newer versions of u-boot did indeed have consistent behaviour for "date reset" regardless of the rtc driver but now there were a handful of drivers that had redundant code to do something that is now handled in the generic layers.

This series removes the now redundant code from the affected drivers. I've compile tested these changes but I only have access to hardware with ds1307/ds1337 (or variants thereof) so I haven't been able to test the last 4 patches on actual hardware.

Chris Packham (5):
rtc: ds1307: remove redundant code in rtc_reset
rtc: ds1374: remove redundant code in rtc_reset
rtc: mx27rtc: remove redundant code in rtc_reset
rtc: rs5c372: remove redundant code in rtc_reset
rtc: rx8025: remove redundant code in rtc_reset

 drivers/rtc/ds1307.c  | 33 ---------------------------------
 drivers/rtc/ds1374.c  | 15 ---------------
 drivers/rtc/mx27rtc.c |  6 +-----
 drivers/rtc/rs5c372.c | 24 +-----------------------
 drivers/rtc/rx8025.c  | 18 +-----------------
 5 files changed, 3 insertions(+), 93 deletions(-)
Signature · 1 line
2.16.2
#1 lore raw

PATCH 1/5 rtc: ds1307: remove redundant code in rtc_reset

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the ds1307 implementation of rtc_reset() doesn't need to call rtc_set().

---

 drivers/rtc/ds1307.c | 33 ---------------------------------
 1 file changed, 33 deletions(-)
drivers/rtc/ds1307.c +0 -33
index 5df15c7fd6c6..5e74b93b72bc 100644
@@ -184,25 +184,8 @@ int rtc_set (struct rtc_time *tmp)
  */
 void rtc_reset (void)
 {
-	struct rtc_time tmp;
-
 	rtc_write (RTC_SEC_REG_ADDR, 0x00);	/* clearing Clock Halt	*/
 	rtc_write (RTC_CTL_REG_ADDR, RTC_CTL_BIT_SQWE | RTC_CTL_BIT_RS1 | RTC_CTL_BIT_RS0);
-
-	tmp.tm_year = 1970;
-	tmp.tm_mon = 1;
-	tmp.tm_mday= 1;
-	tmp.tm_hour = 0;
-	tmp.tm_min = 0;
-	tmp.tm_sec = 0;
-
-	rtc_set(&tmp);
-
-	printf ( "RTC:   %4d-%02d-%02d %2d:%02d:%02d UTC\n",
-		tmp.tm_year, tmp.tm_mon, tmp.tm_mday,
-		tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
-
-	return;
 }
 
 
@@ -321,14 +304,6 @@ read_rtc:
 static int ds1307_rtc_reset(struct udevice *dev)
 {
 	int ret;
-	struct rtc_time tmp = {
-		.tm_year = 1970,
-		.tm_mon = 1,
-		.tm_mday = 1,
-		.tm_hour = 0,
-		.tm_min = 0,
-		.tm_sec = 0,
-	};
 
 	/* clear Clock Halt */
 	ret = dm_i2c_reg_write(dev, RTC_SEC_REG_ADDR, 0x00);
@@ -340,14 +315,6 @@ static int ds1307_rtc_reset(struct udevice *dev)
 	if (ret < 0)
 		return ret;
 
-	ret = ds1307_rtc_set(dev, &tmp);
-	if (ret < 0)
-		return ret;
-
-	debug("RTC:   %4d-%02d-%02d %2d:%02d:%02d UTC\n",
-	      tmp.tm_year, tmp.tm_mon, tmp.tm_mday,
-	      tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
-
 	return 0;
 }
 
Signature · 1 line
2.16.2
#2 lore raw

PATCH 1/5 rtc: ds1307: remove redundant code in rtc_reset

Quoted 10 lines · Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the ds1307 implementation of rtc_reset() doesn't need to call rtc_set().

---

 drivers/rtc/ds1307.c | 33 ---------------------------------
 1 file changed, 33 deletions(-)
#3 lore raw

PATCH 1/5 rtc: ds1307: remove redundant code in rtc_reset

In reply to Chris Packham
Quoted 7 lines · Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the ds1307 implementation of rtc_reset() doesn't need to call rtc_set().

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180407/b5c74b8c/attachment.sig>
#4 lore raw

PATCH 2/5 rtc: ds1374: remove redundant code in rtc_reset

In reply to Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the ds1374 implementation of rtc_reset() doesn't need to call rtc_set().

---

 drivers/rtc/ds1374.c | 15 ---------------
 1 file changed, 15 deletions(-)
drivers/rtc/ds1374.c +0 -15
index 78473570b9df..9e440d845766 100644
@@ -172,8 +172,6 @@ int rtc_set (struct rtc_time *tmp){
  */
 void rtc_reset (void){
 
-	struct rtc_time tmp;
-
 	/* clear status flags */
 	rtc_write(RTC_SR_ADDR, (RTC_SR_BIT_AF|RTC_SR_BIT_OSF), false); /* clearing OSF and AF */
 
@@ -189,19 +187,6 @@ void rtc_reset (void){
 				|RTC_CTL_BIT_BBSQW), true);/* disable WD/ALM, WDSTR set to INT-pin,
 							      set BBSQW and SQW to 32k
 							      - set to 1 */
-	tmp.tm_year = 1970;
-	tmp.tm_mon = 1;
-	tmp.tm_mday= 1;
-	tmp.tm_hour = 0;
-	tmp.tm_min = 0;
-	tmp.tm_sec = 0;
-
-	rtc_set(&tmp);
-
-	printf("RTC:   %4d-%02d-%02d %2d:%02d:%02d UTC\n",
-		tmp.tm_year, tmp.tm_mon, tmp.tm_mday,
-		tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
-
 	rtc_write(RTC_WD_ALM_CNT_BYTE2_ADDR, 0xAC, true);
 	rtc_write(RTC_WD_ALM_CNT_BYTE1_ADDR, 0xDE, true);
 	rtc_write(RTC_WD_ALM_CNT_BYTE2_ADDR, 0xAD, true);
Signature · 1 line
2.16.2
#5 lore raw

PATCH 2/5 rtc: ds1374: remove redundant code in rtc_reset

Quoted 6 lines · Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the ds1374 implementation of rtc_reset() doesn't need to call rtc_set().

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180407/c5e96c25/attachment.sig>
#6 lore raw

PATCH 3/5 rtc: mx27rtc: remove redundant code in rtc_reset

In reply to Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the mx27rtc implementation of rtc_reset() can be an empty stub function.

---

 drivers/rtc/mx27rtc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/rtc/mx27rtc.c +1 -5
index 29ccdf17301b..b42770e05bd9 100644
@@ -61,9 +61,5 @@ int rtc_set(struct rtc_time *time)
 
 void rtc_reset(void)
 {
-	struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
-
-	writel(0, &rtc_regs->dayr);
-	writel(0, &rtc_regs->hourmin);
-	writel(0, &rtc_regs->seconds);
+	/* nothing to do */
 }
Signature · 1 line
2.16.2
#7 lore raw

PATCH 3/5 rtc: mx27rtc: remove redundant code in rtc_reset

Quoted 6 lines · Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the mx27rtc implementation of rtc_reset() can be an empty stub function.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180407/74beb6cb/attachment.sig>
#8 lore raw

PATCH 4/5 rtc: rs5c372: remove redundant code in rtc_reset

In reply to Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the rs5c372 implementation of rtc_reset() does not need to call rtc_set().

---

 drivers/rtc/rs5c372.c | 24 +-----------------------
 1 file changed, 1 insertion(+), 23 deletions(-)
drivers/rtc/rs5c372.c +1 -23
index 65f45ea5e3c3..c815c915d5c0 100644
@@ -247,35 +247,13 @@ int rtc_set (struct rtc_time *tmp)
 }
 
 /*
- * Reset the RTC. We set the date back to 1970-01-01.
+ * Reset the RTC.
  */
 void
 rtc_reset (void)
 {
-	struct rtc_time tmp;
-
 	if (!setup_done)
 		rs5c372_enable();
-
-	if (!setup_done)
-		return;
-
-	tmp.tm_year = 1970;
-	tmp.tm_mon = 1;
-	/* Jan. 1, 1970 was a Thursday */
-	tmp.tm_wday= 4;
-	tmp.tm_mday= 1;
-	tmp.tm_hour = 0;
-	tmp.tm_min = 0;
-	tmp.tm_sec = 0;
-
-	rtc_set(&tmp);
-
-	printf ("RTC:	%4d-%02d-%02d %2d:%02d:%02d UTC\n",
-		tmp.tm_year, tmp.tm_mon, tmp.tm_mday,
-		tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
-
-	return;
 }
 
 #endif
Signature · 1 line
2.16.2
#9 lore raw

PATCH 4/5 rtc: rs5c372: remove redundant code in rtc_reset

Quoted 6 lines · Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the rs5c372 implementation of rtc_reset() does not need to call rtc_set().

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180407/72b17494/attachment.sig>
#10 lore raw

PATCH 5/5 rtc: rx8025: remove redundant code in rtc_reset

In reply to Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the rx8025 implementation of rtc_reset() does not need to call rtc_set().

---

 drivers/rtc/rx8025.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)
drivers/rtc/rx8025.c +1 -17
index b4a149b73808..c43966a50d76 100644
@@ -163,11 +163,10 @@ int rtc_set (struct rtc_time *tmp)
 }
 
 /*
- * Reset the RTC. We setting the date back to 1970-01-01.
+ * Reset the RTC
  */
 void rtc_reset (void)
 {
-	struct rtc_time tmp;
 	uchar buf[16];
 	uchar ctl2;
 
@@ -178,21 +177,6 @@ void rtc_reset (void)
 	ctl2 &= ~(RTC_CTL2_BIT_PON | RTC_CTL2_BIT_VDET);
 	ctl2 |= RTC_CTL2_BIT_XST | RTC_CTL2_BIT_VDSL;
 	rtc_write (RTC_CTL2_REG_ADDR, ctl2);
-
-	tmp.tm_year = 1970;
-	tmp.tm_mon = 1;
-	tmp.tm_mday= 1;
-	tmp.tm_hour = 0;
-	tmp.tm_min = 0;
-	tmp.tm_sec = 0;
-
-	rtc_set(&tmp);
-
-	printf ( "RTC:   %4d-%02d-%02d %2d:%02d:%02d UTC\n",
-		tmp.tm_year, tmp.tm_mon, tmp.tm_mday,
-		tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
-
-	return;
 }
 
 /*
Signature · 1 line
2.16.2
#11 lore raw

PATCH 5/5 rtc: rx8025: remove redundant code in rtc_reset

Quoted 6 lines · Chris Packham

As of commit 1a1fa2406689 ("rtc: Set valid date after reset") the command "date reset" will set the date/time to 2000-01-01 0:00:00 after calling rtc_reset(). This means that the rx8025 implementation of rtc_reset() does not need to call rtc_set().

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180407/f41dcd0a/attachment.sig>