[PATCH] ppc64: consolidate calibrate_decr implementations
authorArnd Bergmann <arnd@arndb.de>
Wed, 22 Jun 2005 23:43:07 +0000 (09:43 +1000)
committerPaul Mackerras <paulus@samba.org>
Wed, 22 Jun 2005 23:43:07 +0000 (09:43 +1000)
pSeries and maple have almost the same code for calibrate_decr,
and BPA would need yet another copy. Instead, I'm moving the
code to arch/ppc64/kernel/time.c.

Some of the related declarations were missing from header
files, so I'm moving those as well.

It makes sense to merge this with the pmac function of the
same name, so we end up having just one implemetation for
iSeries and one for Open Firmware based machines.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/ppc64/kernel/iSeries_setup.c
arch/ppc64/kernel/maple_setup.c
arch/ppc64/kernel/maple_time.c
arch/ppc64/kernel/pSeries_setup.c
arch/ppc64/kernel/pmac_time.c
arch/ppc64/kernel/setup.c
arch/ppc64/kernel/time.c
include/asm-ppc64/time.h

index b319624..86966ce 100644 (file)
@@ -671,9 +671,6 @@ static void __init iSeries_bolt_kernel(unsigned long saddr, unsigned long eaddr)
        }
 }
 
-extern unsigned long ppc_proc_freq;
-extern unsigned long ppc_tb_freq;
-
 /*
  * Document me.
  */
@@ -772,8 +769,6 @@ static void iSeries_halt(void)
        mf_power_off();
 }
 
-extern void setup_default_decr(void);
-
 /*
  * void __init iSeries_calibrate_decr()
  *
index 8cf95a2..3dabedb 100644 (file)
@@ -235,6 +235,6 @@ struct machdep_calls __initdata maple_md = {
                .get_boot_time          = maple_get_boot_time,
                .set_rtc_time           = maple_set_rtc_time,
                .get_rtc_time           = maple_get_rtc_time,
-       .calibrate_decr         = maple_calibrate_decr,
+       .calibrate_decr         = generic_calibrate_decr,
        .progress               = maple_progress,
 };
index 07ce789..d65210a 100644 (file)
 #define DBG(x...)
 #endif
 
-extern void setup_default_decr(void);
 extern void GregorianDay(struct rtc_time * tm);
 
-extern unsigned long ppc_tb_freq;
-extern unsigned long ppc_proc_freq;
 static int maple_rtc_addr;
 
 static int maple_clock_read(int addr)
@@ -176,51 +173,3 @@ void __init maple_get_boot_time(struct rtc_time *tm)
        maple_get_rtc_time(tm);
 }
 
-/* XXX FIXME: Some sane defaults: 125 MHz timebase, 1GHz processor */
-#define DEFAULT_TB_FREQ                125000000UL
-#define DEFAULT_PROC_FREQ      (DEFAULT_TB_FREQ * 8)
-
-void __init maple_calibrate_decr(void)
-{
-       struct device_node *cpu;
-       struct div_result divres;
-       unsigned int *fp = NULL;
-
-       /*
-        * The cpu node should have a timebase-frequency property
-        * to tell us the rate at which the decrementer counts.
-        */
-       cpu = of_find_node_by_type(NULL, "cpu");
-
-       ppc_tb_freq = DEFAULT_TB_FREQ;
-       if (cpu != 0)
-               fp = (unsigned int *)get_property(cpu, "timebase-frequency", NULL);
-       if (fp != NULL)
-               ppc_tb_freq = *fp;
-       else
-               printk(KERN_ERR "WARNING: Estimating decrementer frequency (not found)\n");
-       fp = NULL;
-       ppc_proc_freq = DEFAULT_PROC_FREQ;
-       if (cpu != 0)
-               fp = (unsigned int *)get_property(cpu, "clock-frequency", NULL);
-       if (fp != NULL)
-               ppc_proc_freq = *fp;
-       else
-               printk(KERN_ERR "WARNING: Estimating processor frequency (not found)\n");
-
-       of_node_put(cpu);
-
-       printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
-              ppc_tb_freq/1000000, ppc_tb_freq%1000000);
-       printk(KERN_INFO "time_init: processor frequency   = %lu.%.6lu MHz\n",
-              ppc_proc_freq/1000000, ppc_proc_freq%1000000);
-
-       tb_ticks_per_jiffy = ppc_tb_freq / HZ;
-       tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
-       tb_ticks_per_usec = ppc_tb_freq / 1000000;
-       tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
-       div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
-       tb_to_xs = divres.result_low;
-
-       setup_default_decr();
-}
index 6c0d1d5..f9a310c 100644 (file)
@@ -84,9 +84,6 @@ extern void generic_find_legacy_serial_ports(u64 *physport,
 
 int fwnmi_active;  /* TRUE if an FWNMI handler is present */
 
-extern unsigned long ppc_proc_freq;
-extern unsigned long ppc_tb_freq;
-
 extern void pSeries_system_reset_exception(struct pt_regs *regs);
 extern int pSeries_machine_check_exception(struct pt_regs *regs);
 
@@ -482,70 +479,6 @@ static void pSeries_progress(char *s, unsigned short hex)
        spin_unlock(&progress_lock);
 }
 
-extern void setup_default_decr(void);
-
-/* Some sane defaults: 125 MHz timebase, 1GHz processor */
-#define DEFAULT_TB_FREQ                125000000UL
-#define DEFAULT_PROC_FREQ      (DEFAULT_TB_FREQ * 8)
-
-static void __init pSeries_calibrate_decr(void)
-{
-       struct device_node *cpu;
-       struct div_result divres;
-       unsigned int *fp;
-       int node_found;
-
-       /*
-        * The cpu node should have a timebase-frequency property
-        * to tell us the rate at which the decrementer counts.
-        */
-       cpu = of_find_node_by_type(NULL, "cpu");
-
-       ppc_tb_freq = DEFAULT_TB_FREQ;          /* hardcoded default */
-       node_found = 0;
-       if (cpu != 0) {
-               fp = (unsigned int *)get_property(cpu, "timebase-frequency",
-                                                 NULL);
-               if (fp != 0) {
-                       node_found = 1;
-                       ppc_tb_freq = *fp;
-               }
-       }
-       if (!node_found)
-               printk(KERN_ERR "WARNING: Estimating decrementer frequency "
-                               "(not found)\n");
-
-       ppc_proc_freq = DEFAULT_PROC_FREQ;
-       node_found = 0;
-       if (cpu != 0) {
-               fp = (unsigned int *)get_property(cpu, "clock-frequency",
-                                                 NULL);
-               if (fp != 0) {
-                       node_found = 1;
-                       ppc_proc_freq = *fp;
-               }
-       }
-       if (!node_found)
-               printk(KERN_ERR "WARNING: Estimating processor frequency "
-                               "(not found)\n");
-
-       of_node_put(cpu);
-
-       printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
-              ppc_tb_freq/1000000, ppc_tb_freq%1000000);
-       printk(KERN_INFO "time_init: processor frequency   = %lu.%.6lu MHz\n",
-              ppc_proc_freq/1000000, ppc_proc_freq%1000000);
-
-       tb_ticks_per_jiffy = ppc_tb_freq / HZ;
-       tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
-       tb_ticks_per_usec = ppc_tb_freq / 1000000;
-       tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
-       div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
-       tb_to_xs = divres.result_low;
-
-       setup_default_decr();
-}
-
 static int pSeries_check_legacy_ioport(unsigned int baseport)
 {
        struct device_node *np;
@@ -604,7 +537,7 @@ struct machdep_calls __initdata pSeries_md = {
        .get_boot_time          = pSeries_get_boot_time,
        .get_rtc_time           = pSeries_get_rtc_time,
        .set_rtc_time           = pSeries_set_rtc_time,
-       .calibrate_decr         = pSeries_calibrate_decr,
+       .calibrate_decr         = generic_calibrate_decr,
        .progress               = pSeries_progress,
        .check_legacy_ioport    = pSeries_check_legacy_ioport,
        .system_reset_exception = pSeries_system_reset_exception,
index f248275..3059edb 100644 (file)
 #define DBG(x...)
 #endif
 
-extern void setup_default_decr(void);
-
-extern unsigned long ppc_tb_freq;
-extern unsigned long ppc_proc_freq;
-
 /* Apparently the RTC stores seconds since 1 Jan 1904 */
 #define RTC_OFFSET     2082844800
 
@@ -161,8 +156,7 @@ void __init pmac_get_boot_time(struct rtc_time *tm)
 
 /*
  * Query the OF and get the decr frequency.
- * This was taken from the pmac time_init() when merging the prep/pmac
- * time functions.
+ * FIXME: merge this with generic_calibrate_decr
  */
 void __init pmac_calibrate_decr(void)
 {
index 8e439a8..93b0ee8 100644 (file)
@@ -701,9 +701,6 @@ void machine_halt(void)
 
 EXPORT_SYMBOL(machine_halt);
 
-unsigned long ppc_proc_freq;
-unsigned long ppc_tb_freq;
-
 static int ppc64_panic_event(struct notifier_block *this,
                              unsigned long event, void *ptr)
 {
@@ -1117,7 +1114,7 @@ void ppc64_dump_msg(unsigned int src, const char *msg)
 }
 
 /* This should only be called on processor 0 during calibrate decr */
-void setup_default_decr(void)
+void __init setup_default_decr(void)
 {
        struct paca_struct *lpaca = get_paca();
 
index 33364a7..2348a75 100644 (file)
@@ -107,6 +107,9 @@ void ppc_adjtimex(void);
 
 static unsigned adjusting_time = 0;
 
+unsigned long ppc_proc_freq;
+unsigned long ppc_tb_freq;
+
 static __inline__ void timer_check_rtc(void)
 {
         /*
@@ -472,6 +475,66 @@ int do_settimeofday(struct timespec *tv)
 
 EXPORT_SYMBOL(do_settimeofday);
 
+#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_MAPLE) || defined(CONFIG_PPC_BPA)
+void __init generic_calibrate_decr(void)
+{
+       struct device_node *cpu;
+       struct div_result divres;
+       unsigned int *fp;
+       int node_found;
+
+       /*
+        * The cpu node should have a timebase-frequency property
+        * to tell us the rate at which the decrementer counts.
+        */
+       cpu = of_find_node_by_type(NULL, "cpu");
+
+       ppc_tb_freq = DEFAULT_TB_FREQ;          /* hardcoded default */
+       node_found = 0;
+       if (cpu != 0) {
+               fp = (unsigned int *)get_property(cpu, "timebase-frequency",
+                                                 NULL);
+               if (fp != 0) {
+                       node_found = 1;
+                       ppc_tb_freq = *fp;
+               }
+       }
+       if (!node_found)
+               printk(KERN_ERR "WARNING: Estimating decrementer frequency "
+                               "(not found)\n");
+
+       ppc_proc_freq = DEFAULT_PROC_FREQ;
+       node_found = 0;
+       if (cpu != 0) {
+               fp = (unsigned int *)get_property(cpu, "clock-frequency",
+                                                 NULL);
+               if (fp != 0) {
+                       node_found = 1;
+                       ppc_proc_freq = *fp;
+               }
+       }
+       if (!node_found)
+               printk(KERN_ERR "WARNING: Estimating processor frequency "
+                               "(not found)\n");
+
+       of_node_put(cpu);
+
+       printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
+              ppc_tb_freq/1000000, ppc_tb_freq%1000000);
+       printk(KERN_INFO "time_init: processor frequency   = %lu.%.6lu MHz\n",
+              ppc_proc_freq/1000000, ppc_proc_freq%1000000);
+
+       tb_ticks_per_jiffy = ppc_tb_freq / HZ;
+       tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
+       tb_ticks_per_usec = ppc_tb_freq / 1000000;
+       tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
+       div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
+       tb_to_xs = divres.result_low;
+
+       setup_default_decr();
+}
+#endif
+
 void __init time_init(void)
 {
        /* This function is only called on the boot processor */
index 8d6e376..c6c762c 100644 (file)
@@ -34,6 +34,15 @@ struct rtc_time;
 extern void to_tm(int tim, struct rtc_time * tm);
 extern time_t last_rtc_update;
 
+void generic_calibrate_decr(void);
+void setup_default_decr(void);
+
+/* Some sane defaults: 125 MHz timebase, 1GHz processor */
+extern unsigned long ppc_proc_freq;
+#define DEFAULT_PROC_FREQ      (DEFAULT_TB_FREQ * 8)
+extern unsigned long ppc_tb_freq;
+#define DEFAULT_TB_FREQ                125000000UL
+
 /*
  * By putting all of this stuff into a single struct we 
  * reduce the number of cache lines touched by do_gettimeofday.