sh: Hook up page fault events for software perf counters.
[safe/jmp/linux-2.6] / arch / arm / plat-orion / time.c
index 93c4ef9..715a301 100644 (file)
  */
 
 #include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/cnt32_to_63.h>
+#include <linux/timer.h>
 #include <linux/clockchips.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <asm/mach/time.h>
-#include <asm/arch/hardware.h>
+#include <mach/bridge-regs.h>
+#include <mach/hardware.h>
 
 /*
  * Number of timer ticks per jiffy.
@@ -39,9 +43,59 @@ static u32 ticks_per_jiffy;
 
 
 /*
+ * Orion's sched_clock implementation. It has a resolution of
+ * at least 7.5ns (133MHz TCLK) and a maximum value of 834 days.
+ *
+ * Because the hardware timer period is quite short (21 secs if
+ * 200MHz TCLK) and because cnt32_to_63() needs to be called at
+ * least once per half period to work properly, a kernel timer is
+ * set up to ensure this requirement is always met.
+ */
+#define TCLK2NS_SCALE_FACTOR 8
+
+static unsigned long tclk2ns_scale;
+
+unsigned long long sched_clock(void)
+{
+       unsigned long long v = cnt32_to_63(0xffffffff - readl(TIMER0_VAL));
+       return (v * tclk2ns_scale) >> TCLK2NS_SCALE_FACTOR;
+}
+
+static struct timer_list cnt32_to_63_keepwarm_timer;
+
+static void cnt32_to_63_keepwarm(unsigned long data)
+{
+       mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
+       (void) sched_clock();
+}
+
+static void __init setup_sched_clock(unsigned long tclk)
+{
+       unsigned long long v;
+       unsigned long data;
+
+       v = NSEC_PER_SEC;
+       v <<= TCLK2NS_SCALE_FACTOR;
+       v += tclk/2;
+       do_div(v, tclk);
+       /*
+        * We want an even value to automatically clear the top bit
+        * returned by cnt32_to_63() without an additional run time
+        * instruction. So if the LSB is 1 then round it up.
+        */
+       if (v & 1)
+               v++;
+       tclk2ns_scale = v;
+
+       data = (0xffffffffUL / tclk / 2 - 2) * HZ;
+       setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, data);
+       mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
+}
+
+/*
  * Clocksource handling.
  */
-static cycle_t orion_clksrc_read(void)
+static cycle_t orion_clksrc_read(struct clocksource *cs)
 {
        return 0xffffffff - readl(TIMER0_VAL);
 }
@@ -149,7 +203,6 @@ static struct clock_event_device orion_clkevt = {
        .features       = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC,
        .shift          = 32,
        .rating         = 300,
-       .cpumask        = CPU_MASK_CPU0,
        .set_next_event = orion_clkevt_next_event,
        .set_mode       = orion_clkevt_mode,
 };
@@ -177,6 +230,10 @@ void __init orion_time_init(unsigned int irq, unsigned int tclk)
 
        ticks_per_jiffy = (tclk + HZ/2) / HZ;
 
+       /*
+        * Set scale and timer for sched_clock
+        */
+       setup_sched_clock(tclk);
 
        /*
         * Setup free-running clocksource timer (interrupts
@@ -191,7 +248,6 @@ void __init orion_time_init(unsigned int irq, unsigned int tclk)
        orion_clksrc.mult = clocksource_hz2mult(tclk, orion_clksrc.shift);
        clocksource_register(&orion_clksrc);
 
-
        /*
         * Setup clockevent timer (interrupt-driven.)
         */
@@ -199,5 +255,6 @@ void __init orion_time_init(unsigned int irq, unsigned int tclk)
        orion_clkevt.mult = div_sc(tclk, NSEC_PER_SEC, orion_clkevt.shift);
        orion_clkevt.max_delta_ns = clockevent_delta2ns(0xfffffffe, &orion_clkevt);
        orion_clkevt.min_delta_ns = clockevent_delta2ns(1, &orion_clkevt);
+       orion_clkevt.cpumask = cpumask_of(0);
        clockevents_register_device(&orion_clkevt);
 }