diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2007-10-11 18:46:09 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2007-10-11 18:46:09 -0400 |
commit | 90b02340dcc6ce00bf22c48f4865915f5989e5e4 (patch) | |
tree | 763f07fe0025ac5cd54fa361ec5d77ad76b5547c /arch/mips/kernel/time.c | |
parent | 4b550488f894c899aa54dc935c8fee47bca2b7df (diff) |
[MIPS] Switch from to_tm to rtc_time_to_tm
This replaces the MIPS-specific to_tm function with the generic
rtc_time_to_tm function. The big difference between the two functions is
that rtc_time_to_tm uses epoch 70 while to_tm uses 1970, so the result of
rtc_time_to_tm needs to be fixed up.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/kernel/time.c')
-rw-r--r-- | arch/mips/kernel/time.c | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c index 9bbbd9b327fc..c48ebd4b495e 100644 --- a/arch/mips/kernel/time.c +++ b/arch/mips/kernel/time.c | |||
@@ -397,52 +397,3 @@ void __init time_init(void) | |||
397 | 397 | ||
398 | init_mips_clocksource(); | 398 | init_mips_clocksource(); |
399 | } | 399 | } |
400 | |||
401 | #define FEBRUARY 2 | ||
402 | #define STARTOFTIME 1970 | ||
403 | #define SECDAY 86400L | ||
404 | #define SECYR (SECDAY * 365) | ||
405 | #define leapyear(y) ((!((y) % 4) && ((y) % 100)) || !((y) % 400)) | ||
406 | #define days_in_year(y) (leapyear(y) ? 366 : 365) | ||
407 | #define days_in_month(m) (month_days[(m) - 1]) | ||
408 | |||
409 | static int month_days[12] = { | ||
410 | 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 | ||
411 | }; | ||
412 | |||
413 | void to_tm(unsigned long tim, struct rtc_time *tm) | ||
414 | { | ||
415 | long hms, day, gday; | ||
416 | int i; | ||
417 | |||
418 | gday = day = tim / SECDAY; | ||
419 | hms = tim % SECDAY; | ||
420 | |||
421 | /* Hours, minutes, seconds are easy */ | ||
422 | tm->tm_hour = hms / 3600; | ||
423 | tm->tm_min = (hms % 3600) / 60; | ||
424 | tm->tm_sec = (hms % 3600) % 60; | ||
425 | |||
426 | /* Number of years in days */ | ||
427 | for (i = STARTOFTIME; day >= days_in_year(i); i++) | ||
428 | day -= days_in_year(i); | ||
429 | tm->tm_year = i; | ||
430 | |||
431 | /* Number of months in days left */ | ||
432 | if (leapyear(tm->tm_year)) | ||
433 | days_in_month(FEBRUARY) = 29; | ||
434 | for (i = 1; day >= days_in_month(i); i++) | ||
435 | day -= days_in_month(i); | ||
436 | days_in_month(FEBRUARY) = 28; | ||
437 | tm->tm_mon = i - 1; /* tm_mon starts from 0 to 11 */ | ||
438 | |||
439 | /* Days are what is left over (+1) from all that. */ | ||
440 | tm->tm_mday = day + 1; | ||
441 | |||
442 | /* | ||
443 | * Determine the day of week | ||
444 | */ | ||
445 | tm->tm_wday = (gday + 4) % 7; /* 1970/1/1 was Thursday */ | ||
446 | } | ||
447 | |||
448 | EXPORT_SYMBOL(to_tm); | ||