Skip to content

Commit d6f471a

Browse files
AngeloGioacchino Del Regnoalexandrebelloni
authored andcommitted
rtc: mt6359: Use RTC_TC_DOW hardware register for wday
Instead of calculating the number of full days since Sunday with (days + 4) % 7, read (and write) that to the RTC Day-of-week Time Counter register (RTC_TC_DOW). Some transformation (addition and subtraction for set/get) is still done, as this register's range is [1..7], while the tm_wday in struct tm's range is [0..6]. Please note that this was added only to set_time() and read_time() callbacks because set_alarm() and read_alarm() are setting a bit in RTC_AL_MASK to ignore DOW for RTC HW alarms for unknown reasons. Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 34bbdc1 commit d6f471a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

drivers/rtc/rtc-mt6397.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static int __mtk_rtc_read_time(struct mt6397_rtc *rtc,
7575
tm->tm_min = data[RTC_OFFSET_MIN];
7676
tm->tm_hour = data[RTC_OFFSET_HOUR];
7777
tm->tm_mday = data[RTC_OFFSET_DOM];
78+
tm->tm_wday = data[RTC_OFFSET_DOW];
7879
tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_TC_MTH_MASK;
7980
tm->tm_year = data[RTC_OFFSET_YEAR];
8081

@@ -86,25 +87,18 @@ static int __mtk_rtc_read_time(struct mt6397_rtc *rtc,
8687

8788
static int mtk_rtc_read_time(struct device *dev, struct rtc_time *tm)
8889
{
89-
time64_t time;
9090
struct mt6397_rtc *rtc = dev_get_drvdata(dev);
91-
int days, sec, ret;
91+
int sec, ret;
9292

9393
do {
9494
ret = __mtk_rtc_read_time(rtc, tm, &sec);
9595
if (ret < 0)
9696
goto exit;
9797
} while (sec < tm->tm_sec);
9898

99-
/* HW register start mon from one, but tm_mon start from zero. */
99+
/* HW register start mon/wday from one, but tm_mon/tm_wday start from zero. */
100100
tm->tm_mon--;
101-
time = rtc_tm_to_time64(tm);
102-
103-
/* rtc_tm_to_time64 covert Gregorian date to seconds since
104-
* 01-01-1970 00:00:00, and this date is Thursday.
105-
*/
106-
days = div_s64(time, 86400);
107-
tm->tm_wday = (days + 4) % 7;
101+
tm->tm_wday--;
108102

109103
exit:
110104
return ret;
@@ -117,11 +111,13 @@ static int mtk_rtc_set_time(struct device *dev, struct rtc_time *tm)
117111
u16 data[RTC_OFFSET_COUNT];
118112

119113
tm->tm_mon++;
114+
tm->tm_wday++;
120115

121116
data[RTC_OFFSET_SEC] = tm->tm_sec;
122117
data[RTC_OFFSET_MIN] = tm->tm_min;
123118
data[RTC_OFFSET_HOUR] = tm->tm_hour;
124119
data[RTC_OFFSET_DOM] = tm->tm_mday;
120+
data[RTC_OFFSET_DOW] = tm->tm_wday;
125121
data[RTC_OFFSET_MTH] = tm->tm_mon;
126122
data[RTC_OFFSET_YEAR] = tm->tm_year;
127123

0 commit comments

Comments
 (0)