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

rtc: mt6359: Add RTC hardware range and add support for start-year

Add the RTC hardware range parameters to enable the possibility
of using the `start-year` devicetree property which, if present,
will set the start_secs parameter by overriding the defaults
that this driver is setting;

To keep compatibility with (hence have the same date/time reading
as) the old behavior, set:
- range_min to 1900-01-01 00:00:00
- range_max to 2027-12-31 23:59:59 (HW year max range is 0-127)
- start_secs defaulting to 1968-01-02 00:00:00

Please note that the oddness of starting from January 2nd is not
a hardware quirk and it's done only to get the same date/time
reading as an RTC which time was set before this commit.

Also remove the RTC_MIN_YEAR_OFFSET addition and subtraction in
callbacks set_time() and read_time() respectively, as now this
is already done by the API.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Macpaul Lin <macpaul.lin@mediatek.com>
Link: https://lore.kernel.org/r/20240923100010.97470-3-angelogioacchino.delregno@collabora.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

AngeloGioacchino Del Regno and committed by
Alexandre Belloni
34bbdc12 9beeecbd

+4 -9
+4 -9
drivers/rtc/rtc-mt6397.c
··· 96 96 goto exit; 97 97 } while (sec < tm->tm_sec); 98 98 99 - /* HW register use 7 bits to store year data, minus 100 - * RTC_MIN_YEAR_OFFSET before write year data to register, and plus 101 - * RTC_MIN_YEAR_OFFSET back after read year from register 102 - */ 103 - tm->tm_year += RTC_MIN_YEAR_OFFSET; 104 - 105 99 /* HW register start mon from one, but tm_mon start from zero. */ 106 100 tm->tm_mon--; 107 101 time = rtc_tm_to_time64(tm); ··· 116 122 int ret; 117 123 u16 data[RTC_OFFSET_COUNT]; 118 124 119 - tm->tm_year -= RTC_MIN_YEAR_OFFSET; 120 125 tm->tm_mon++; 121 126 122 127 data[RTC_OFFSET_SEC] = tm->tm_sec; ··· 171 178 tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_AL_MTH_MASK; 172 179 tm->tm_year = data[RTC_OFFSET_YEAR] & RTC_AL_YEA_MASK; 173 180 174 - tm->tm_year += RTC_MIN_YEAR_OFFSET; 175 181 tm->tm_mon--; 176 182 177 183 return 0; ··· 186 194 int ret; 187 195 u16 data[RTC_OFFSET_COUNT]; 188 196 189 - tm->tm_year -= RTC_MIN_YEAR_OFFSET; 190 197 tm->tm_mon++; 191 198 192 199 mutex_lock(&rtc->lock); ··· 293 302 device_init_wakeup(&pdev->dev, 1); 294 303 295 304 rtc->rtc_dev->ops = &mtk_rtc_ops; 305 + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; 306 + rtc->rtc_dev->range_max = mktime64(2027, 12, 31, 23, 59, 59); 307 + rtc->rtc_dev->start_secs = mktime64(1968, 1, 2, 0, 0, 0); 308 + rtc->rtc_dev->set_start_time = true; 296 309 297 310 return devm_rtc_register_device(rtc->rtc_dev); 298 311 }