[U-Boot] [PATCH v1 0/5] 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(-)

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().
Signed-off-by: Chris Packham judge.packham@gmail.com ---
drivers/rtc/ds1307.c | 33 --------------------------------- 1 file changed, 33 deletions(-)
diff --git a/drivers/rtc/ds1307.c b/drivers/rtc/ds1307.c index 5df15c7fd6c6..5e74b93b72bc 100644 --- a/drivers/rtc/ds1307.c +++ b/drivers/rtc/ds1307.c @@ -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; }

On 20 March 2018 at 20:40, Chris Packham judge.packham@gmail.com wrote:
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().
Signed-off-by: Chris Packham judge.packham@gmail.com
drivers/rtc/ds1307.c | 33 --------------------------------- 1 file changed, 33 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Mar 21, 2018 at 03:40:33PM +1300, Chris Packham wrote:
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().
Signed-off-by: Chris Packham judge.packham@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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().
Signed-off-by: Chris Packham judge.packham@gmail.com ---
drivers/rtc/ds1374.c | 15 --------------- 1 file changed, 15 deletions(-)
diff --git a/drivers/rtc/ds1374.c b/drivers/rtc/ds1374.c index 78473570b9df..9e440d845766 100644 --- a/drivers/rtc/ds1374.c +++ b/drivers/rtc/ds1374.c @@ -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);

On Wed, Mar 21, 2018 at 03:40:34PM +1300, Chris Packham wrote:
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().
Signed-off-by: Chris Packham judge.packham@gmail.com
Applied to u-boot/master, thanks!

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.
Signed-off-by: Chris Packham judge.packham@gmail.com ---
drivers/rtc/mx27rtc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/rtc/mx27rtc.c b/drivers/rtc/mx27rtc.c index 29ccdf17301b..b42770e05bd9 100644 --- a/drivers/rtc/mx27rtc.c +++ b/drivers/rtc/mx27rtc.c @@ -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 */ }

On Wed, Mar 21, 2018 at 03:40:35PM +1300, Chris Packham wrote:
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.
Signed-off-by: Chris Packham judge.packham@gmail.com
Applied to u-boot/master, thanks!

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().
Signed-off-by: Chris Packham judge.packham@gmail.com ---
drivers/rtc/rs5c372.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-)
diff --git a/drivers/rtc/rs5c372.c b/drivers/rtc/rs5c372.c index 65f45ea5e3c3..c815c915d5c0 100644 --- a/drivers/rtc/rs5c372.c +++ b/drivers/rtc/rs5c372.c @@ -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

On Wed, Mar 21, 2018 at 03:40:36PM +1300, Chris Packham wrote:
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().
Signed-off-by: Chris Packham judge.packham@gmail.com
Applied to u-boot/master, thanks!

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().
Signed-off-by: Chris Packham judge.packham@gmail.com ---
drivers/rtc/rx8025.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
diff --git a/drivers/rtc/rx8025.c b/drivers/rtc/rx8025.c index b4a149b73808..c43966a50d76 100644 --- a/drivers/rtc/rx8025.c +++ b/drivers/rtc/rx8025.c @@ -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; }
/*

On Wed, Mar 21, 2018 at 03:40:37PM +1300, Chris Packham wrote:
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().
Signed-off-by: Chris Packham judge.packham@gmail.com
Applied to u-boot/master, thanks!
participants (3)
-
Chris Packham
-
Simon Glass
-
Tom Rini