Skip to contentSkip to conversation

rtc: fsl-ftm-alarm: allow COMPILE_TEST

PATCH Superseded Alexandre Belloni 1 participant 4 messages Oct 16, 2019 Real time clock (RTC)

lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/4 rtc: fsl-ftm-alarm: allow COMPILE_TEST

Allow building building the driver with COMPILE_TEST.

---
 drivers/rtc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/Kconfig +1 -1
index f28aee483c55..4185b0d27021 100644
@@ -1325,7 +1325,7 @@ config RTC_DRV_IMXDI
 
 config RTC_DRV_FSL_FTM_ALARM
 	tristate "Freescale FlexTimer alarm timer"
-	depends on ARCH_LAYERSCAPE || SOC_LS1021A
+	depends on ARCH_LAYERSCAPE || SOC_LS1021A || COMPILE_TEST
 	select FSL_RCPM
 	default y
 	help
Signature · 1 line
2.21.0
author maintainer
#3 lore raw

PATCH 4/4 rtc: fsl-ftm-alarm: avoid struct rtc_time conversions

Directly call ktime_get_real_seconds instead of converting the result to a struct rtc_time and then back to a time64_t.

---
 drivers/rtc/rtc-fsl-ftm-alarm.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/rtc/rtc-fsl-ftm-alarm.c +2 -5
index 039bd2f1a7ee..9e6e994cce99 100644
@@ -203,17 +203,14 @@ static int ftm_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
  */
 static int ftm_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
 {
-	struct rtc_time tm;
-	time64_t now, alm_time;
+	time64_t alm_time;
 	unsigned long long cycle;
 	struct ftm_rtc *rtc = dev_get_drvdata(dev);
 
-	ftm_rtc_read_time(dev, &tm);
-	now = rtc_tm_to_time64(&tm);
 	alm_time = rtc_tm_to_time64(&alm->time);
 
 	ftm_clean_alarm(rtc);
-	cycle = (alm_time - now) * rtc->alarm_freq;
+	cycle = (alm_time - ktime_get_real_seconds()) * rtc->alarm_freq;
 	if (cycle > MAX_COUNT_VAL) {
 		pr_err("Out of alarm range {0~262} seconds.\n");
 		return -ERANGE;
Signature · 1 line
2.21.0
author maintainer
#2 lore raw

PATCH 3/4 rtc: fsl-ftm-alarm: switch to rtc_time64_to_tm/rtc_tm_to_time64

In reply to Alexandre Belloni

Call the 64bit versions of rtc_tm time conversion to avoid the y2038 issue.

---
 drivers/rtc/rtc-fsl-ftm-alarm.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/rtc/rtc-fsl-ftm-alarm.c +5 -4
index e954c51bf39b..039bd2f1a7ee 100644
@@ -180,7 +180,7 @@ static int ftm_rtc_alarm_irq_enable(struct device *dev,
  */
 static int ftm_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-	rtc_time_to_tm(ktime_get_real_seconds(), tm);
+	rtc_time64_to_tm(ktime_get_real_seconds(), tm);
 
 	return 0;
 }
@@ -204,12 +204,13 @@ static int ftm_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
 static int ftm_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
 {
 	struct rtc_time tm;
-	unsigned long now, alm_time, cycle;
+	time64_t now, alm_time;
+	unsigned long long cycle;
 	struct ftm_rtc *rtc = dev_get_drvdata(dev);
 
 	ftm_rtc_read_time(dev, &tm);
-	rtc_tm_to_time(&tm, &now);
-	rtc_tm_to_time(&alm->time, &alm_time);
+	now = rtc_tm_to_time64(&tm);
+	alm_time = rtc_tm_to_time64(&alm->time);
 
 	ftm_clean_alarm(rtc);
 	cycle = (alm_time - now) * rtc->alarm_freq;
Signature · 1 line
2.21.0
author maintainer
#1 lore raw

PATCH 2/4 rtc: fsl-ftm-alarm: switch to ktime_get_real_seconds

In reply to Alexandre Belloni

The driver drops the nanoseconds part of the timespec64, there is no need to call ktime_get_real_ts64.

---
 drivers/rtc/rtc-fsl-ftm-alarm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/rtc/rtc-fsl-ftm-alarm.c +1 -4
index b83f7afa8311..e954c51bf39b 100644
@@ -180,10 +180,7 @@ static int ftm_rtc_alarm_irq_enable(struct device *dev,
  */
 static int ftm_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-	struct timespec64 ts64;
-
-	ktime_get_real_ts64(&ts64);
-	rtc_time_to_tm(ts64.tv_sec, tm);
+	rtc_time_to_tm(ktime_get_real_seconds(), tm);
 
 	return 0;
 }
Signature · 1 line
2.21.0