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 | |
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')
-rw-r--r-- | arch/mips/Kconfig | 1 | ||||
-rw-r--r-- | arch/mips/kernel/time.c | 49 | ||||
-rw-r--r-- | arch/mips/pmc-sierra/yosemite/setup.c | 8 | ||||
-rw-r--r-- | arch/mips/sgi-ip22/ip22-time.c | 6 | ||||
-rw-r--r-- | arch/mips/sibyte/swarm/rtc_m41t81.c | 3 | ||||
-rw-r--r-- | arch/mips/sibyte/swarm/rtc_xicor1241.c | 3 |
6 files changed, 14 insertions, 56 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index c024113ce280..0cd0f835b13d 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig | |||
@@ -3,6 +3,7 @@ config MIPS | |||
3 | default y | 3 | default y |
4 | # Horrible source of confusion. Die, die, die ... | 4 | # Horrible source of confusion. Die, die, die ... |
5 | select EMBEDDED | 5 | select EMBEDDED |
6 | select RTC_LIB | ||
6 | 7 | ||
7 | mainmenu "Linux/MIPS Kernel Configuration" | 8 | mainmenu "Linux/MIPS Kernel Configuration" |
8 | 9 | ||
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); | ||
diff --git a/arch/mips/pmc-sierra/yosemite/setup.c b/arch/mips/pmc-sierra/yosemite/setup.c index 56bf69595da8..015fcc363dc0 100644 --- a/arch/mips/pmc-sierra/yosemite/setup.c +++ b/arch/mips/pmc-sierra/yosemite/setup.c | |||
@@ -100,8 +100,12 @@ int rtc_mips_set_time(unsigned long tim) | |||
100 | struct rtc_time tm; | 100 | struct rtc_time tm; |
101 | unsigned long flags; | 101 | unsigned long flags; |
102 | 102 | ||
103 | /* convert to a more useful format -- note months count from 0 */ | 103 | /* |
104 | to_tm(sec, &tm); | 104 | * Convert to a more useful format -- note months count from 0 |
105 | * and years from 1900 | ||
106 | */ | ||
107 | rtc_time_to_tm(tim, &tm); | ||
108 | tm.tm_year += 1900; | ||
105 | tm.tm_mon += 1; | 109 | tm.tm_mon += 1; |
106 | 110 | ||
107 | spin_lock_irqsave(&rtc_lock, flags); | 111 | spin_lock_irqsave(&rtc_lock, flags); |
diff --git a/arch/mips/sgi-ip22/ip22-time.c b/arch/mips/sgi-ip22/ip22-time.c index 0387c385b4b2..c49418067f93 100644 --- a/arch/mips/sgi-ip22/ip22-time.c +++ b/arch/mips/sgi-ip22/ip22-time.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #include <asm/sgi/ip22.h> | 29 | #include <asm/sgi/ip22.h> |
30 | 30 | ||
31 | /* | 31 | /* |
32 | * note that mktime uses month from 1 to 12 while to_tm | 32 | * Note that mktime uses month from 1 to 12 while rtc_time_to_tm |
33 | * uses 0 to 11. | 33 | * uses 0 to 11. |
34 | */ | 34 | */ |
35 | unsigned long read_persistent_clock(void) | 35 | unsigned long read_persistent_clock(void) |
@@ -66,10 +66,10 @@ int rtc_mips_set_time(unsigned long tim) | |||
66 | unsigned int save_control; | 66 | unsigned int save_control; |
67 | unsigned long flags; | 67 | unsigned long flags; |
68 | 68 | ||
69 | to_tm(tim, &tm); | 69 | rtc_time_to_tm(tim, &tm); |
70 | 70 | ||
71 | tm.tm_mon += 1; /* tm_mon starts at zero */ | 71 | tm.tm_mon += 1; /* tm_mon starts at zero */ |
72 | tm.tm_year -= 1940; | 72 | tm.tm_year -= 40; |
73 | if (tm.tm_year >= 100) | 73 | if (tm.tm_year >= 100) |
74 | tm.tm_year -= 100; | 74 | tm.tm_year -= 100; |
75 | 75 | ||
diff --git a/arch/mips/sibyte/swarm/rtc_m41t81.c b/arch/mips/sibyte/swarm/rtc_m41t81.c index c13914bdda59..26fbff4c15b1 100644 --- a/arch/mips/sibyte/swarm/rtc_m41t81.c +++ b/arch/mips/sibyte/swarm/rtc_m41t81.c | |||
@@ -146,7 +146,8 @@ int m41t81_set_time(unsigned long t) | |||
146 | struct rtc_time tm; | 146 | struct rtc_time tm; |
147 | unsigned long flags; | 147 | unsigned long flags; |
148 | 148 | ||
149 | to_tm(t, &tm); | 149 | /* Note we don't care about the century */ |
150 | rtc_time_to_tm(t, &tm); | ||
150 | 151 | ||
151 | /* | 152 | /* |
152 | * Note the write order matters as it ensures the correctness. | 153 | * Note the write order matters as it ensures the correctness. |
diff --git a/arch/mips/sibyte/swarm/rtc_xicor1241.c b/arch/mips/sibyte/swarm/rtc_xicor1241.c index f4a178836415..ff3e5dabb348 100644 --- a/arch/mips/sibyte/swarm/rtc_xicor1241.c +++ b/arch/mips/sibyte/swarm/rtc_xicor1241.c | |||
@@ -115,7 +115,8 @@ int xicor_set_time(unsigned long t) | |||
115 | int tmp; | 115 | int tmp; |
116 | unsigned long flags; | 116 | unsigned long flags; |
117 | 117 | ||
118 | to_tm(t, &tm); | 118 | rtc_time_to_tm(t, &tm); |
119 | tm.tm_year += 1900; | ||
119 | 120 | ||
120 | spin_lock_irqsave(&rtc_lock, flags); | 121 | spin_lock_irqsave(&rtc_lock, flags); |
121 | /* unlock writes to the CCR */ | 122 | /* unlock writes to the CCR */ |