aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-lib.c')
-rw-r--r--drivers/rtc/rtc-lib.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index c4cf05731118..e6bfb9c42a10 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -45,16 +45,20 @@ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
45} 45}
46EXPORT_SYMBOL(rtc_year_days); 46EXPORT_SYMBOL(rtc_year_days);
47 47
48
48/* 49/*
50 * rtc_time_to_tm64 - Converts time64_t to rtc_time.
49 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. 51 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
50 */ 52 */
51void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) 53void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
52{ 54{
53 unsigned int month, year; 55 unsigned int month, year;
56 unsigned long secs;
54 int days; 57 int days;
55 58
56 days = time / 86400; 59 /* time must be positive */
57 time -= (unsigned int) days * 86400; 60 days = div_s64(time, 86400);
61 secs = time - (unsigned int) days * 86400;
58 62
59 /* day of the week, 1970-01-01 was a Thursday */ 63 /* day of the week, 1970-01-01 was a Thursday */
60 tm->tm_wday = (days + 4) % 7; 64 tm->tm_wday = (days + 4) % 7;
@@ -81,14 +85,14 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
81 tm->tm_mon = month; 85 tm->tm_mon = month;
82 tm->tm_mday = days + 1; 86 tm->tm_mday = days + 1;
83 87
84 tm->tm_hour = time / 3600; 88 tm->tm_hour = secs / 3600;
85 time -= tm->tm_hour * 3600; 89 secs -= tm->tm_hour * 3600;
86 tm->tm_min = time / 60; 90 tm->tm_min = secs / 60;
87 tm->tm_sec = time - tm->tm_min * 60; 91 tm->tm_sec = secs - tm->tm_min * 60;
88 92
89 tm->tm_isdst = 0; 93 tm->tm_isdst = 0;
90} 94}
91EXPORT_SYMBOL(rtc_time_to_tm); 95EXPORT_SYMBOL(rtc_time64_to_tm);
92 96
93/* 97/*
94 * Does the rtc_time represent a valid date/time? 98 * Does the rtc_time represent a valid date/time?
@@ -109,24 +113,22 @@ int rtc_valid_tm(struct rtc_time *tm)
109EXPORT_SYMBOL(rtc_valid_tm); 113EXPORT_SYMBOL(rtc_valid_tm);
110 114
111/* 115/*
116 * rtc_tm_to_time64 - Converts rtc_time to time64_t.
112 * Convert Gregorian date to seconds since 01-01-1970 00:00:00. 117 * Convert Gregorian date to seconds since 01-01-1970 00:00:00.
113 */ 118 */
114int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) 119time64_t rtc_tm_to_time64(struct rtc_time *tm)
115{ 120{
116 *time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 121 return mktime64(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
117 tm->tm_hour, tm->tm_min, tm->tm_sec); 122 tm->tm_hour, tm->tm_min, tm->tm_sec);
118 return 0;
119} 123}
120EXPORT_SYMBOL(rtc_tm_to_time); 124EXPORT_SYMBOL(rtc_tm_to_time64);
121 125
122/* 126/*
123 * Convert rtc_time to ktime 127 * Convert rtc_time to ktime
124 */ 128 */
125ktime_t rtc_tm_to_ktime(struct rtc_time tm) 129ktime_t rtc_tm_to_ktime(struct rtc_time tm)
126{ 130{
127 time_t time; 131 return ktime_set(rtc_tm_to_time64(&tm), 0);
128 rtc_tm_to_time(&tm, &time);
129 return ktime_set(time, 0);
130} 132}
131EXPORT_SYMBOL_GPL(rtc_tm_to_ktime); 133EXPORT_SYMBOL_GPL(rtc_tm_to_ktime);
132 134
@@ -135,14 +137,14 @@ EXPORT_SYMBOL_GPL(rtc_tm_to_ktime);
135 */ 137 */
136struct rtc_time rtc_ktime_to_tm(ktime_t kt) 138struct rtc_time rtc_ktime_to_tm(ktime_t kt)
137{ 139{
138 struct timespec ts; 140 struct timespec64 ts;
139 struct rtc_time ret; 141 struct rtc_time ret;
140 142
141 ts = ktime_to_timespec(kt); 143 ts = ktime_to_timespec64(kt);
142 /* Round up any ns */ 144 /* Round up any ns */
143 if (ts.tv_nsec) 145 if (ts.tv_nsec)
144 ts.tv_sec++; 146 ts.tv_sec++;
145 rtc_time_to_tm(ts.tv_sec, &ret); 147 rtc_time64_to_tm(ts.tv_sec, &ret);
146 return ret; 148 return ret;
147} 149}
148EXPORT_SYMBOL_GPL(rtc_ktime_to_tm); 150EXPORT_SYMBOL_GPL(rtc_ktime_to_tm);