aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/powerpc/Kconfig3
-rw-r--r--arch/powerpc/kernel/time.c85
-rw-r--r--arch/powerpc/sysdev/Makefile5
-rw-r--r--arch/powerpc/sysdev/timer.c81
4 files changed, 29 insertions, 145 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 45e86c751f11..6468cd9d72e4 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -26,6 +26,9 @@ config MMU
26 bool 26 bool
27 default y 27 default y
28 28
29config GENERIC_CMOS_UPDATE
30 def_bool y
31
29config GENERIC_HARDIRQS 32config GENERIC_HARDIRQS
30 bool 33 bool
31 default y 34 default y
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index d95e68c0a6b3..b94e4dffba19 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -73,16 +73,11 @@
73#include <asm/iseries/hv_call_xm.h> 73#include <asm/iseries/hv_call_xm.h>
74#endif 74#endif
75 75
76/* keep track of when we need to update the rtc */
77time_t last_rtc_update;
78#ifdef CONFIG_PPC_ISERIES 76#ifdef CONFIG_PPC_ISERIES
79static unsigned long __initdata iSeries_recal_titan; 77static unsigned long __initdata iSeries_recal_titan;
80static signed long __initdata iSeries_recal_tb; 78static signed long __initdata iSeries_recal_tb;
81#endif 79#endif
82 80
83/* The decrementer counts down by 128 every 128ns on a 601. */
84#define DECREMENTER_COUNT_601 (1000000000 / HZ)
85
86#define XSEC_PER_SEC (1024*1024) 81#define XSEC_PER_SEC (1024*1024)
87 82
88#ifdef CONFIG_PPC64 83#ifdef CONFIG_PPC64
@@ -348,39 +343,6 @@ void udelay(unsigned long usecs)
348} 343}
349EXPORT_SYMBOL(udelay); 344EXPORT_SYMBOL(udelay);
350 345
351static __inline__ void timer_check_rtc(void)
352{
353 /*
354 * update the rtc when needed, this should be performed on the
355 * right fraction of a second. Half or full second ?
356 * Full second works on mk48t59 clocks, others need testing.
357 * Note that this update is basically only used through
358 * the adjtimex system calls. Setting the HW clock in
359 * any other way is a /dev/rtc and userland business.
360 * This is still wrong by -0.5/+1.5 jiffies because of the
361 * timer interrupt resolution and possible delay, but here we
362 * hit a quantization limit which can only be solved by higher
363 * resolution timers and decoupling time management from timer
364 * interrupts. This is also wrong on the clocks
365 * which require being written at the half second boundary.
366 * We should have an rtc call that only sets the minutes and
367 * seconds like on Intel to avoid problems with non UTC clocks.
368 */
369 if (ppc_md.set_rtc_time && ntp_synced() &&
370 xtime.tv_sec - last_rtc_update >= 659 &&
371 abs((xtime.tv_nsec/1000) - (1000000-1000000/HZ)) < 500000/HZ) {
372 struct rtc_time tm;
373 to_tm(xtime.tv_sec + 1 + timezone_offset, &tm);
374 tm.tm_year -= 1900;
375 tm.tm_mon -= 1;
376 if (ppc_md.set_rtc_time(&tm) == 0)
377 last_rtc_update = xtime.tv_sec + 1;
378 else
379 /* Try again one minute later */
380 last_rtc_update += 60;
381 }
382}
383
384/* 346/*
385 * This version of gettimeofday has microsecond resolution. 347 * This version of gettimeofday has microsecond resolution.
386 */ 348 */
@@ -689,7 +651,6 @@ void timer_interrupt(struct pt_regs * regs)
689 tb_last_jiffy = tb_next_jiffy; 651 tb_last_jiffy = tb_next_jiffy;
690 do_timer(1); 652 do_timer(1);
691 timer_recalc_offset(tb_last_jiffy); 653 timer_recalc_offset(tb_last_jiffy);
692 timer_check_rtc();
693 } 654 }
694 write_sequnlock(&xtime_lock); 655 write_sequnlock(&xtime_lock);
695 } 656 }
@@ -801,11 +762,6 @@ int do_settimeofday(struct timespec *tv)
801 set_normalized_timespec(&xtime, new_sec, new_nsec); 762 set_normalized_timespec(&xtime, new_sec, new_nsec);
802 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 763 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
803 764
804 /* In case of a large backwards jump in time with NTP, we want the
805 * clock to be updated as soon as the PLL is again in lock.
806 */
807 last_rtc_update = new_sec - 658;
808
809 ntp_clear(); 765 ntp_clear();
810 766
811 new_xsec = xtime.tv_nsec; 767 new_xsec = xtime.tv_nsec;
@@ -881,12 +837,35 @@ void __init generic_calibrate_decr(void)
881#endif 837#endif
882} 838}
883 839
884unsigned long get_boot_time(void) 840int update_persistent_clock(struct timespec now)
841{
842 struct rtc_time tm;
843
844 if (!ppc_md.set_rtc_time)
845 return 0;
846
847 to_tm(now.tv_sec + 1 + timezone_offset, &tm);
848 tm.tm_year -= 1900;
849 tm.tm_mon -= 1;
850
851 return ppc_md.set_rtc_time(&tm);
852}
853
854unsigned long read_persistent_clock(void)
885{ 855{
886 struct rtc_time tm; 856 struct rtc_time tm;
857 static int first = 1;
858
859 /* XXX this is a litle fragile but will work okay in the short term */
860 if (first) {
861 first = 0;
862 if (ppc_md.time_init)
863 timezone_offset = ppc_md.time_init();
887 864
888 if (ppc_md.get_boot_time) 865 /* get_boot_time() isn't guaranteed to be safe to call late */
889 return ppc_md.get_boot_time(); 866 if (ppc_md.get_boot_time)
867 return ppc_md.get_boot_time() -timezone_offset;
868 }
890 if (!ppc_md.get_rtc_time) 869 if (!ppc_md.get_rtc_time)
891 return 0; 870 return 0;
892 ppc_md.get_rtc_time(&tm); 871 ppc_md.get_rtc_time(&tm);
@@ -898,14 +877,10 @@ unsigned long get_boot_time(void)
898void __init time_init(void) 877void __init time_init(void)
899{ 878{
900 unsigned long flags; 879 unsigned long flags;
901 unsigned long tm = 0;
902 struct div_result res; 880 struct div_result res;
903 u64 scale, x; 881 u64 scale, x;
904 unsigned shift; 882 unsigned shift;
905 883
906 if (ppc_md.time_init != NULL)
907 timezone_offset = ppc_md.time_init();
908
909 if (__USE_RTC()) { 884 if (__USE_RTC()) {
910 /* 601 processor: dec counts down by 128 every 128ns */ 885 /* 601 processor: dec counts down by 128 every 128ns */
911 ppc_tb_freq = 1000000000; 886 ppc_tb_freq = 1000000000;
@@ -980,19 +955,14 @@ void __init time_init(void)
980 /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */ 955 /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
981 boot_tb = get_tb_or_rtc(); 956 boot_tb = get_tb_or_rtc();
982 957
983 tm = get_boot_time();
984
985 write_seqlock_irqsave(&xtime_lock, flags); 958 write_seqlock_irqsave(&xtime_lock, flags);
986 959
987 /* If platform provided a timezone (pmac), we correct the time */ 960 /* If platform provided a timezone (pmac), we correct the time */
988 if (timezone_offset) { 961 if (timezone_offset) {
989 sys_tz.tz_minuteswest = -timezone_offset / 60; 962 sys_tz.tz_minuteswest = -timezone_offset / 60;
990 sys_tz.tz_dsttime = 0; 963 sys_tz.tz_dsttime = 0;
991 tm -= timezone_offset;
992 } 964 }
993 965
994 xtime.tv_sec = tm;
995 xtime.tv_nsec = 0;
996 do_gtod.varp = &do_gtod.vars[0]; 966 do_gtod.varp = &do_gtod.vars[0];
997 do_gtod.var_idx = 0; 967 do_gtod.var_idx = 0;
998 do_gtod.varp->tb_orig_stamp = tb_last_jiffy; 968 do_gtod.varp->tb_orig_stamp = tb_last_jiffy;
@@ -1010,9 +980,6 @@ void __init time_init(void)
1010 980
1011 time_freq = 0; 981 time_freq = 0;
1012 982
1013 last_rtc_update = xtime.tv_sec;
1014 set_normalized_timespec(&wall_to_monotonic,
1015 -xtime.tv_sec, -xtime.tv_nsec);
1016 write_sequnlock_irqrestore(&xtime_lock, flags); 983 write_sequnlock_irqrestore(&xtime_lock, flags);
1017 984
1018 /* Not exact, but the timer interrupt takes care of this */ 985 /* Not exact, but the timer interrupt takes care of this */
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index ed41dc0a310f..b0ea8e9495e8 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -21,11 +21,6 @@ obj-$(CONFIG_MV64X60) += $(mv64x60-y) mv64x60_pic.o mv64x60_dev.o \
21obj-$(CONFIG_RTC_DRV_CMOS) += rtc_cmos_setup.o 21obj-$(CONFIG_RTC_DRV_CMOS) += rtc_cmos_setup.o
22obj-$(CONFIG_AXON_RAM) += axonram.o 22obj-$(CONFIG_AXON_RAM) += axonram.o
23 23
24# contains only the suspend handler for time
25ifeq ($(CONFIG_RTC_CLASS),)
26obj-$(CONFIG_PM) += timer.o
27endif
28
29ifeq ($(CONFIG_PPC_MERGE),y) 24ifeq ($(CONFIG_PPC_MERGE),y)
30obj-$(CONFIG_PPC_INDIRECT_PCI) += indirect_pci.o 25obj-$(CONFIG_PPC_INDIRECT_PCI) += indirect_pci.o
31obj-$(CONFIG_PPC_I8259) += i8259.o 26obj-$(CONFIG_PPC_I8259) += i8259.o
diff --git a/arch/powerpc/sysdev/timer.c b/arch/powerpc/sysdev/timer.c
deleted file mode 100644
index e81e7ec2e799..000000000000
--- a/arch/powerpc/sysdev/timer.c
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 * Common code to keep time when machine suspends.
3 *
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * GPLv2
7 */
8
9#include <linux/time.h>
10#include <linux/sysdev.h>
11#include <asm/rtc.h>
12
13static unsigned long suspend_rtc_time;
14
15/*
16 * Reset the time after a sleep.
17 */
18static int timer_resume(struct sys_device *dev)
19{
20 struct timeval tv;
21 struct timespec ts;
22 struct rtc_time cur_rtc_tm;
23 unsigned long cur_rtc_time, diff;
24
25 /* get current RTC time and convert to seconds */
26 get_rtc_time(&cur_rtc_tm);
27 cur_rtc_time = mktime(cur_rtc_tm.tm_year + 1900,
28 cur_rtc_tm.tm_mon + 1,
29 cur_rtc_tm.tm_mday,
30 cur_rtc_tm.tm_hour,
31 cur_rtc_tm.tm_min,
32 cur_rtc_tm.tm_sec);
33
34 diff = cur_rtc_time - suspend_rtc_time;
35
36 /* adjust time of day by seconds that elapsed while
37 * we were suspended */
38 do_gettimeofday(&tv);
39 ts.tv_sec = tv.tv_sec + diff;
40 ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
41 do_settimeofday(&ts);
42
43 return 0;
44}
45
46static int timer_suspend(struct sys_device *dev, pm_message_t state)
47{
48 struct rtc_time suspend_rtc_tm;
49 WARN_ON(!ppc_md.get_rtc_time);
50
51 get_rtc_time(&suspend_rtc_tm);
52 suspend_rtc_time = mktime(suspend_rtc_tm.tm_year + 1900,
53 suspend_rtc_tm.tm_mon + 1,
54 suspend_rtc_tm.tm_mday,
55 suspend_rtc_tm.tm_hour,
56 suspend_rtc_tm.tm_min,
57 suspend_rtc_tm.tm_sec);
58
59 return 0;
60}
61
62static struct sysdev_class timer_sysclass = {
63 .resume = timer_resume,
64 .suspend = timer_suspend,
65 set_kset_name("timer"),
66};
67
68static struct sys_device device_timer = {
69 .id = 0,
70 .cls = &timer_sysclass,
71};
72
73static int time_init_device(void)
74{
75 int error = sysdev_class_register(&timer_sysclass);
76 if (!error)
77 error = sysdev_register(&device_timer);
78 return error;
79}
80
81device_initcall(time_init_device);