Skip to content

Commit 34bbdc1

Browse files
AngeloGioacchino Del Regnoalexandrebelloni
authored andcommitted
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 <[email protected]> Reviewed-by: Macpaul Lin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 9beeecb commit 34bbdc1

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

drivers/rtc/rtc-mt6397.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ static int mtk_rtc_read_time(struct device *dev, struct rtc_time *tm)
9696
goto exit;
9797
} while (sec < tm->tm_sec);
9898

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-
10599
/* HW register start mon from one, but tm_mon start from zero. */
106100
tm->tm_mon--;
107101
time = rtc_tm_to_time64(tm);
@@ -122,7 +116,6 @@ static int mtk_rtc_set_time(struct device *dev, struct rtc_time *tm)
122116
int ret;
123117
u16 data[RTC_OFFSET_COUNT];
124118

125-
tm->tm_year -= RTC_MIN_YEAR_OFFSET;
126119
tm->tm_mon++;
127120

128121
data[RTC_OFFSET_SEC] = tm->tm_sec;
@@ -178,7 +171,6 @@ static int mtk_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
178171
tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_AL_MTH_MASK;
179172
tm->tm_year = data[RTC_OFFSET_YEAR] & RTC_AL_YEA_MASK;
180173

181-
tm->tm_year += RTC_MIN_YEAR_OFFSET;
182174
tm->tm_mon--;
183175

184176
return 0;
@@ -194,7 +186,6 @@ static int mtk_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
194186
int ret;
195187
u16 data[RTC_OFFSET_COUNT];
196188

197-
tm->tm_year -= RTC_MIN_YEAR_OFFSET;
198189
tm->tm_mon++;
199190

200191
mutex_lock(&rtc->lock);
@@ -302,6 +293,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)
302293
device_init_wakeup(&pdev->dev, 1);
303294

304295
rtc->rtc_dev->ops = &mtk_rtc_ops;
296+
rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
297+
rtc->rtc_dev->range_max = mktime64(2027, 12, 31, 23, 59, 59);
298+
rtc->rtc_dev->start_secs = mktime64(1968, 1, 2, 0, 0, 0);
299+
rtc->rtc_dev->set_start_time = true;
305300

306301
return devm_rtc_register_device(rtc->rtc_dev);
307302
}

0 commit comments

Comments
 (0)