Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20240923100010.97470-4-angelogioacchino.delregno@collabora.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

AngeloGioacchino Del Regno and committed by
Alexandre Belloni
d6f471a7 34bbdc12

+6 -10
+6 -10
drivers/rtc/rtc-mt6397.c
··· 75 75 tm->tm_min = data[RTC_OFFSET_MIN]; 76 76 tm->tm_hour = data[RTC_OFFSET_HOUR]; 77 77 tm->tm_mday = data[RTC_OFFSET_DOM]; 78 + tm->tm_wday = data[RTC_OFFSET_DOW]; 78 79 tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_TC_MTH_MASK; 79 80 tm->tm_year = data[RTC_OFFSET_YEAR]; 80 81 ··· 87 86 88 87 static int mtk_rtc_read_time(struct device *dev, struct rtc_time *tm) 89 88 { 90 - time64_t time; 91 89 struct mt6397_rtc *rtc = dev_get_drvdata(dev); 92 - int days, sec, ret; 90 + int sec, ret; 93 91 94 92 do { 95 93 ret = __mtk_rtc_read_time(rtc, tm, &sec); ··· 96 96 goto exit; 97 97 } while (sec < tm->tm_sec); 98 98 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. */ 100 100 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--; 108 102 109 103 exit: 110 104 return ret; ··· 111 117 u16 data[RTC_OFFSET_COUNT]; 112 118 113 119 tm->tm_mon++; 120 + tm->tm_wday++; 114 121 115 122 data[RTC_OFFSET_SEC] = tm->tm_sec; 116 123 data[RTC_OFFSET_MIN] = tm->tm_min; 117 124 data[RTC_OFFSET_HOUR] = tm->tm_hour; 118 125 data[RTC_OFFSET_DOM] = tm->tm_mday; 126 + data[RTC_OFFSET_DOW] = tm->tm_wday; 119 127 data[RTC_OFFSET_MTH] = tm->tm_mon; 120 128 data[RTC_OFFSET_YEAR] = tm->tm_year; 121 129