diff mbox series

[RFC,1/2] rtc: rzn1: drop superfluous wday calculation

Message ID 20241122101448.4374-2-wsa+renesas@sang-engineering.com (mailing list archive)
State New
Delegated to: Geert Uytterhoeven
Headers show
Series rtc: rzn1: simplify driver | expand

Commit Message

Wolfram Sang Nov. 22, 2024, 10:14 a.m. UTC
The week register simply counts from 0 to 6 where the numbers do not
even represent a specific weekday. So we can adopt 'tm_wday' numbering
of the RTC core without converting it.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/rtc/rtc-rzn1.c | 15 ---------------
 1 file changed, 15 deletions(-)

Comments

Alexandre Belloni Nov. 22, 2024, 11:26 p.m. UTC | #1
On 22/11/2024 11:14:47+0100, Wolfram Sang wrote:
> The week register simply counts from 0 to 6 where the numbers do not
> even represent a specific weekday. So we can adopt 'tm_wday' numbering
> of the RTC core without converting it.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/rtc/rtc-rzn1.c | 15 ---------------
>  1 file changed, 15 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-rzn1.c b/drivers/rtc/rtc-rzn1.c
> index b0ea2847e982..4ae6e349faa0 100644
> --- a/drivers/rtc/rtc-rzn1.c
> +++ b/drivers/rtc/rtc-rzn1.c
> @@ -75,19 +75,6 @@ static void rzn1_rtc_get_time_snapshot(struct rzn1_rtc *rtc, struct rtc_time *tm
>  	tm->tm_year = readl(rtc->base + RZN1_RTC_YEARC);
>  }
>  
> -static unsigned int rzn1_rtc_tm_to_wday(struct rtc_time *tm)
> -{
> -	time64_t time;
> -	unsigned int days;
> -	u32 secs;
> -
> -	time = rtc_tm_to_time64(tm);
> -	days = div_s64_rem(time, 86400, &secs);
> -
> -	/* day of the week, 1970-01-01 was a Thursday */
> -	return (days + 4) % 7;
> -}
> -
>  static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  {
>  	struct rzn1_rtc *rtc = dev_get_drvdata(dev);
> @@ -109,7 +96,6 @@ static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  	tm->tm_sec = bcd2bin(tm->tm_sec);
>  	tm->tm_min = bcd2bin(tm->tm_min);
>  	tm->tm_hour = bcd2bin(tm->tm_hour);
> -	tm->tm_wday = bcd2bin(tm->tm_wday);

With this, you're not even using wday anymore. This is fine as there are
probably no userspace users of the value but the commit message claims
it is now using it without conversion.

>  	tm->tm_mday = bcd2bin(tm->tm_mday);
>  	tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
>  	tm->tm_year = bcd2bin(tm->tm_year) + 100;
> @@ -126,7 +112,6 @@ static int rzn1_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  	tm->tm_sec = bin2bcd(tm->tm_sec);
>  	tm->tm_min = bin2bcd(tm->tm_min);
>  	tm->tm_hour = bin2bcd(tm->tm_hour);
> -	tm->tm_wday = bin2bcd(rzn1_rtc_tm_to_wday(tm));
>  	tm->tm_mday = bin2bcd(tm->tm_mday);
>  	tm->tm_mon = bin2bcd(tm->tm_mon + 1);
>  	tm->tm_year = bin2bcd(tm->tm_year - 100);
> -- 
> 2.39.2
>
Wolfram Sang Nov. 23, 2024, 8:01 a.m. UTC | #2
> >  	struct rzn1_rtc *rtc = dev_get_drvdata(dev);
> > @@ -109,7 +96,6 @@ static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
> >  	tm->tm_sec = bcd2bin(tm->tm_sec);
> >  	tm->tm_min = bcd2bin(tm->tm_min);
> >  	tm->tm_hour = bcd2bin(tm->tm_hour);
> > -	tm->tm_wday = bcd2bin(tm->tm_wday);
> 
> With this, you're not even using wday anymore. This is fine as there are
> probably no userspace users of the value but the commit message claims
> it is now using it without conversion.

But it is still read form and written to the register. And the values of
the register go from 0 to 6, same as tm_wday. So not even BCD conversion
is necessary. So, I think it is still used. Am I missing something?
Alexandre Belloni Nov. 23, 2024, 10:25 a.m. UTC | #3
On 23/11/2024 09:01:19+0100, Wolfram Sang wrote:
> 
> > >  	struct rzn1_rtc *rtc = dev_get_drvdata(dev);
> > > @@ -109,7 +96,6 @@ static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
> > >  	tm->tm_sec = bcd2bin(tm->tm_sec);
> > >  	tm->tm_min = bcd2bin(tm->tm_min);
> > >  	tm->tm_hour = bcd2bin(tm->tm_hour);
> > > -	tm->tm_wday = bcd2bin(tm->tm_wday);
> > 
> > With this, you're not even using wday anymore. This is fine as there are
> > probably no userspace users of the value but the commit message claims
> > it is now using it without conversion.
> 
> But it is still read form and written to the register. And the values of
> the register go from 0 to 6, same as tm_wday. So not even BCD conversion
> is necessary. So, I think it is still used. Am I missing something?
> 

You didn't, I misread the diff.
Wolfram Sang Nov. 24, 2024, 3:51 p.m. UTC | #4
> > is necessary. So, I think it is still used. Am I missing something?
> 
> You didn't, I misread the diff.

Ah, good. This kind of justifies my change in patch 2 to put
BCD-conversion and register access in one place, it seems :)
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-rzn1.c b/drivers/rtc/rtc-rzn1.c
index b0ea2847e982..4ae6e349faa0 100644
--- a/drivers/rtc/rtc-rzn1.c
+++ b/drivers/rtc/rtc-rzn1.c
@@ -75,19 +75,6 @@  static void rzn1_rtc_get_time_snapshot(struct rzn1_rtc *rtc, struct rtc_time *tm
 	tm->tm_year = readl(rtc->base + RZN1_RTC_YEARC);
 }
 
-static unsigned int rzn1_rtc_tm_to_wday(struct rtc_time *tm)
-{
-	time64_t time;
-	unsigned int days;
-	u32 secs;
-
-	time = rtc_tm_to_time64(tm);
-	days = div_s64_rem(time, 86400, &secs);
-
-	/* day of the week, 1970-01-01 was a Thursday */
-	return (days + 4) % 7;
-}
-
 static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
 	struct rzn1_rtc *rtc = dev_get_drvdata(dev);
@@ -109,7 +96,6 @@  static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
 	tm->tm_sec = bcd2bin(tm->tm_sec);
 	tm->tm_min = bcd2bin(tm->tm_min);
 	tm->tm_hour = bcd2bin(tm->tm_hour);
-	tm->tm_wday = bcd2bin(tm->tm_wday);
 	tm->tm_mday = bcd2bin(tm->tm_mday);
 	tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
 	tm->tm_year = bcd2bin(tm->tm_year) + 100;
@@ -126,7 +112,6 @@  static int rzn1_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	tm->tm_sec = bin2bcd(tm->tm_sec);
 	tm->tm_min = bin2bcd(tm->tm_min);
 	tm->tm_hour = bin2bcd(tm->tm_hour);
-	tm->tm_wday = bin2bcd(rzn1_rtc_tm_to_wday(tm));
 	tm->tm_mday = bin2bcd(tm->tm_mday);
 	tm->tm_mon = bin2bcd(tm->tm_mon + 1);
 	tm->tm_year = bin2bcd(tm->tm_year - 100);