diff options
author | Alessandro Zummo <a.zummo@towertech.it> | 2006-03-27 04:16:35 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-27 11:44:50 -0500 |
commit | 12b824fb15a37cdcdfa3e92c9e912a07cc6f7a24 (patch) | |
tree | 85fb2cc63219078022a98471531ec8286eb2272d /arch | |
parent | c58411e95d7f5062dedd1a3064af4d359da1e633 (diff) |
[PATCH] RTC subsystem: ARM cleanup
This patch removes from the ARM subsytem some of the rtc-related functions
that have been included in the RTC subsystem. It also fixes some naming
collisions.
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/Kconfig | 3 | ||||
-rw-r--r-- | arch/arm/common/rtctime.c | 108 |
2 files changed, 16 insertions, 95 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index bf2e72698d02..9731b3f826ab 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -8,6 +8,7 @@ mainmenu "Linux Kernel Configuration" | |||
8 | config ARM | 8 | config ARM |
9 | bool | 9 | bool |
10 | default y | 10 | default y |
11 | select RTC_LIB | ||
11 | help | 12 | help |
12 | The ARM series is a line of low-power-consumption RISC chip designs | 13 | The ARM series is a line of low-power-consumption RISC chip designs |
13 | licensed by ARM Ltd and targeted at embedded applications and | 14 | licensed by ARM Ltd and targeted at embedded applications and |
@@ -839,6 +840,8 @@ source "drivers/usb/Kconfig" | |||
839 | 840 | ||
840 | source "drivers/mmc/Kconfig" | 841 | source "drivers/mmc/Kconfig" |
841 | 842 | ||
843 | source "drivers/rtc/Kconfig" | ||
844 | |||
842 | endmenu | 845 | endmenu |
843 | 846 | ||
844 | source "fs/Kconfig" | 847 | source "fs/Kconfig" |
diff --git a/arch/arm/common/rtctime.c b/arch/arm/common/rtctime.c index e851d86c212c..35c9a64ac14c 100644 --- a/arch/arm/common/rtctime.c +++ b/arch/arm/common/rtctime.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/capability.h> | 20 | #include <linux/capability.h> |
21 | #include <linux/device.h> | 21 | #include <linux/device.h> |
22 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
23 | #include <linux/rtc.h> | ||
23 | 24 | ||
24 | #include <asm/rtc.h> | 25 | #include <asm/rtc.h> |
25 | #include <asm/semaphore.h> | 26 | #include <asm/semaphore.h> |
@@ -42,89 +43,6 @@ static struct rtc_ops *rtc_ops; | |||
42 | 43 | ||
43 | #define rtc_epoch 1900UL | 44 | #define rtc_epoch 1900UL |
44 | 45 | ||
45 | static const unsigned char days_in_month[] = { | ||
46 | 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 | ||
47 | }; | ||
48 | |||
49 | #define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) | ||
50 | #define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400)) | ||
51 | |||
52 | static int month_days(unsigned int month, unsigned int year) | ||
53 | { | ||
54 | return days_in_month[month] + (LEAP_YEAR(year) && month == 1); | ||
55 | } | ||
56 | |||
57 | /* | ||
58 | * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. | ||
59 | */ | ||
60 | void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) | ||
61 | { | ||
62 | int days, month, year; | ||
63 | |||
64 | days = time / 86400; | ||
65 | time -= days * 86400; | ||
66 | |||
67 | tm->tm_wday = (days + 4) % 7; | ||
68 | |||
69 | year = 1970 + days / 365; | ||
70 | days -= (year - 1970) * 365 | ||
71 | + LEAPS_THRU_END_OF(year - 1) | ||
72 | - LEAPS_THRU_END_OF(1970 - 1); | ||
73 | if (days < 0) { | ||
74 | year -= 1; | ||
75 | days += 365 + LEAP_YEAR(year); | ||
76 | } | ||
77 | tm->tm_year = year - 1900; | ||
78 | tm->tm_yday = days + 1; | ||
79 | |||
80 | for (month = 0; month < 11; month++) { | ||
81 | int newdays; | ||
82 | |||
83 | newdays = days - month_days(month, year); | ||
84 | if (newdays < 0) | ||
85 | break; | ||
86 | days = newdays; | ||
87 | } | ||
88 | tm->tm_mon = month; | ||
89 | tm->tm_mday = days + 1; | ||
90 | |||
91 | tm->tm_hour = time / 3600; | ||
92 | time -= tm->tm_hour * 3600; | ||
93 | tm->tm_min = time / 60; | ||
94 | tm->tm_sec = time - tm->tm_min * 60; | ||
95 | } | ||
96 | EXPORT_SYMBOL(rtc_time_to_tm); | ||
97 | |||
98 | /* | ||
99 | * Does the rtc_time represent a valid date/time? | ||
100 | */ | ||
101 | int rtc_valid_tm(struct rtc_time *tm) | ||
102 | { | ||
103 | if (tm->tm_year < 70 || | ||
104 | tm->tm_mon >= 12 || | ||
105 | tm->tm_mday < 1 || | ||
106 | tm->tm_mday > month_days(tm->tm_mon, tm->tm_year + 1900) || | ||
107 | tm->tm_hour >= 24 || | ||
108 | tm->tm_min >= 60 || | ||
109 | tm->tm_sec >= 60) | ||
110 | return -EINVAL; | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | EXPORT_SYMBOL(rtc_valid_tm); | ||
115 | |||
116 | /* | ||
117 | * Convert Gregorian date to seconds since 01-01-1970 00:00:00. | ||
118 | */ | ||
119 | int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) | ||
120 | { | ||
121 | *time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | ||
122 | tm->tm_hour, tm->tm_min, tm->tm_sec); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | EXPORT_SYMBOL(rtc_tm_to_time); | ||
127 | |||
128 | /* | 46 | /* |
129 | * Calculate the next alarm time given the requested alarm time mask | 47 | * Calculate the next alarm time given the requested alarm time mask |
130 | * and the current time. | 48 | * and the current time. |
@@ -151,13 +69,13 @@ void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, struct rtc | |||
151 | } | 69 | } |
152 | } | 70 | } |
153 | 71 | ||
154 | static inline int rtc_read_time(struct rtc_ops *ops, struct rtc_time *tm) | 72 | static inline int rtc_arm_read_time(struct rtc_ops *ops, struct rtc_time *tm) |
155 | { | 73 | { |
156 | memset(tm, 0, sizeof(struct rtc_time)); | 74 | memset(tm, 0, sizeof(struct rtc_time)); |
157 | return ops->read_time(tm); | 75 | return ops->read_time(tm); |
158 | } | 76 | } |
159 | 77 | ||
160 | static inline int rtc_set_time(struct rtc_ops *ops, struct rtc_time *tm) | 78 | static inline int rtc_arm_set_time(struct rtc_ops *ops, struct rtc_time *tm) |
161 | { | 79 | { |
162 | int ret; | 80 | int ret; |
163 | 81 | ||
@@ -168,7 +86,7 @@ static inline int rtc_set_time(struct rtc_ops *ops, struct rtc_time *tm) | |||
168 | return ret; | 86 | return ret; |
169 | } | 87 | } |
170 | 88 | ||
171 | static inline int rtc_read_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm) | 89 | static inline int rtc_arm_read_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm) |
172 | { | 90 | { |
173 | int ret = -EINVAL; | 91 | int ret = -EINVAL; |
174 | if (ops->read_alarm) { | 92 | if (ops->read_alarm) { |
@@ -178,7 +96,7 @@ static inline int rtc_read_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm) | |||
178 | return ret; | 96 | return ret; |
179 | } | 97 | } |
180 | 98 | ||
181 | static inline int rtc_set_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm) | 99 | static inline int rtc_arm_set_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm) |
182 | { | 100 | { |
183 | int ret = -EINVAL; | 101 | int ret = -EINVAL; |
184 | if (ops->set_alarm) | 102 | if (ops->set_alarm) |
@@ -266,7 +184,7 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
266 | 184 | ||
267 | switch (cmd) { | 185 | switch (cmd) { |
268 | case RTC_ALM_READ: | 186 | case RTC_ALM_READ: |
269 | ret = rtc_read_alarm(ops, &alrm); | 187 | ret = rtc_arm_read_alarm(ops, &alrm); |
270 | if (ret) | 188 | if (ret) |
271 | break; | 189 | break; |
272 | ret = copy_to_user(uarg, &alrm.time, sizeof(tm)); | 190 | ret = copy_to_user(uarg, &alrm.time, sizeof(tm)); |
@@ -288,11 +206,11 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
288 | alrm.time.tm_wday = -1; | 206 | alrm.time.tm_wday = -1; |
289 | alrm.time.tm_yday = -1; | 207 | alrm.time.tm_yday = -1; |
290 | alrm.time.tm_isdst = -1; | 208 | alrm.time.tm_isdst = -1; |
291 | ret = rtc_set_alarm(ops, &alrm); | 209 | ret = rtc_arm_set_alarm(ops, &alrm); |
292 | break; | 210 | break; |
293 | 211 | ||
294 | case RTC_RD_TIME: | 212 | case RTC_RD_TIME: |
295 | ret = rtc_read_time(ops, &tm); | 213 | ret = rtc_arm_read_time(ops, &tm); |
296 | if (ret) | 214 | if (ret) |
297 | break; | 215 | break; |
298 | ret = copy_to_user(uarg, &tm, sizeof(tm)); | 216 | ret = copy_to_user(uarg, &tm, sizeof(tm)); |
@@ -310,7 +228,7 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
310 | ret = -EFAULT; | 228 | ret = -EFAULT; |
311 | break; | 229 | break; |
312 | } | 230 | } |
313 | ret = rtc_set_time(ops, &tm); | 231 | ret = rtc_arm_set_time(ops, &tm); |
314 | break; | 232 | break; |
315 | 233 | ||
316 | case RTC_EPOCH_SET: | 234 | case RTC_EPOCH_SET: |
@@ -341,11 +259,11 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
341 | ret = -EFAULT; | 259 | ret = -EFAULT; |
342 | break; | 260 | break; |
343 | } | 261 | } |
344 | ret = rtc_set_alarm(ops, &alrm); | 262 | ret = rtc_arm_set_alarm(ops, &alrm); |
345 | break; | 263 | break; |
346 | 264 | ||
347 | case RTC_WKALM_RD: | 265 | case RTC_WKALM_RD: |
348 | ret = rtc_read_alarm(ops, &alrm); | 266 | ret = rtc_arm_read_alarm(ops, &alrm); |
349 | if (ret) | 267 | if (ret) |
350 | break; | 268 | break; |
351 | ret = copy_to_user(uarg, &alrm, sizeof(alrm)); | 269 | ret = copy_to_user(uarg, &alrm, sizeof(alrm)); |
@@ -435,7 +353,7 @@ static int rtc_read_proc(char *page, char **start, off_t off, int count, int *eo | |||
435 | struct rtc_time tm; | 353 | struct rtc_time tm; |
436 | char *p = page; | 354 | char *p = page; |
437 | 355 | ||
438 | if (rtc_read_time(ops, &tm) == 0) { | 356 | if (rtc_arm_read_time(ops, &tm) == 0) { |
439 | p += sprintf(p, | 357 | p += sprintf(p, |
440 | "rtc_time\t: %02d:%02d:%02d\n" | 358 | "rtc_time\t: %02d:%02d:%02d\n" |
441 | "rtc_date\t: %04d-%02d-%02d\n" | 359 | "rtc_date\t: %04d-%02d-%02d\n" |
@@ -445,7 +363,7 @@ static int rtc_read_proc(char *page, char **start, off_t off, int count, int *eo | |||
445 | rtc_epoch); | 363 | rtc_epoch); |
446 | } | 364 | } |
447 | 365 | ||
448 | if (rtc_read_alarm(ops, &alrm) == 0) { | 366 | if (rtc_arm_read_alarm(ops, &alrm) == 0) { |
449 | p += sprintf(p, "alrm_time\t: "); | 367 | p += sprintf(p, "alrm_time\t: "); |
450 | if ((unsigned int)alrm.time.tm_hour <= 24) | 368 | if ((unsigned int)alrm.time.tm_hour <= 24) |
451 | p += sprintf(p, "%02d:", alrm.time.tm_hour); | 369 | p += sprintf(p, "%02d:", alrm.time.tm_hour); |