powerpc/iseries: Initialise on-stack completion
[safe/jmp/linux-2.6] / arch / mips / sgi-ip27 / ip27-timer.c
index 08d4536..d6802d6 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/kernel_stat.h>
 #include <linux/param.h>
+#include <linux/smp.h>
 #include <linux/time.h>
 #include <linux/timex.h>
 #include <linux/mm.h>
+#include <linux/platform_device.h>
 
 #include <asm/time.h>
 #include <asm/pgtable.h>
 #include <asm/sgialib.h>
 #include <asm/sn/ioc3.h>
-#include <asm/m48t35.h>
 #include <asm/sn/klconfig.h>
 #include <asm/sn/arch.h>
 #include <asm/sn/addrs.h>
 
 #define TICK_SIZE (tick_nsec / 1000)
 
-#if 0
-static int set_rtc_mmss(unsigned long nowtime)
-{
-       int retval = 0;
-       int real_seconds, real_minutes, cmos_minutes;
-       struct m48t35_rtc *rtc;
-       nasid_t nid;
-
-       nid = get_nasid();
-       rtc = (struct m48t35_rtc *)(KL_CONFIG_CH_CONS_INFO(nid)->memory_base +
-                                                       IOC3_BYTEBUS_DEV0);
-
-       rtc->control |= M48T35_RTC_READ;
-       cmos_minutes = BCD2BIN(rtc->min);
-       rtc->control &= ~M48T35_RTC_READ;
-
-       /*
-        * Since we're only adjusting minutes and seconds, don't interfere with
-        * hour overflow. This avoids messing with unknown time zones but
-        * requires your RTC not to be off by more than 15 minutes
-        */
-       real_seconds = nowtime % 60;
-       real_minutes = nowtime / 60;
-       if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
-               real_minutes += 30;     /* correct for half hour time zone */
-       real_minutes %= 60;
-
-       if (abs(real_minutes - cmos_minutes) < 30) {
-               real_seconds = BIN2BCD(real_seconds);
-               real_minutes = BIN2BCD(real_minutes);
-               rtc->control |= M48T35_RTC_SET;
-               rtc->sec = real_seconds;
-               rtc->min = real_minutes;
-               rtc->control &= ~M48T35_RTC_SET;
-       } else {
-               printk(KERN_WARNING
-                      "set_rtc_mmss: can't update from %d to %d\n",
-                      cmos_minutes, real_minutes);
-               retval = -1;
-       }
-
-       return retval;
-}
-#endif
-
 /* Includes for ioc3_init().  */
 #include <asm/sn/types.h>
 #include <asm/sn/sn0/addrs.h>
@@ -80,37 +36,6 @@ static int set_rtc_mmss(unsigned long nowtime)
 #include <asm/sn/sn0/hubio.h>
 #include <asm/pci/bridge.h>
 
-unsigned long read_persistent_clock(void)
-{
-        unsigned int year, month, date, hour, min, sec;
-       struct m48t35_rtc *rtc;
-       nasid_t nid;
-
-       nid = get_nasid();
-       rtc = (struct m48t35_rtc *)(KL_CONFIG_CH_CONS_INFO(nid)->memory_base +
-                                                       IOC3_BYTEBUS_DEV0);
-
-       rtc->control |= M48T35_RTC_READ;
-       sec = rtc->sec;
-       min = rtc->min;
-       hour = rtc->hour;
-       date = rtc->date;
-       month = rtc->month;
-       year = rtc->year;
-       rtc->control &= ~M48T35_RTC_READ;
-
-        sec = BCD2BIN(sec);
-        min = BCD2BIN(min);
-        hour = BCD2BIN(hour);
-        date = BCD2BIN(date);
-        month = BCD2BIN(month);
-        year = BCD2BIN(year);
-
-        year += 1970;
-
-        return mktime(year, month, date, hour, min, sec);
-}
-
 static void enable_rt_irq(unsigned int irq)
 {
 }
@@ -158,12 +83,15 @@ static void rt_set_mode(enum clock_event_mode mode,
        }
 }
 
-unsigned int rt_timer_irq;
+int rt_timer_irq;
+
+static DEFINE_PER_CPU(struct clock_event_device, hub_rt_clockevent);
+static DEFINE_PER_CPU(char [11], hub_rt_name);
 
 static irqreturn_t hub_rt_counter_handler(int irq, void *dev_id)
 {
-       struct clock_event_device *cd = dev_id;
        unsigned int cpu = smp_processor_id();
+       struct clock_event_device *cd = &per_cpu(hub_rt_clockevent, cpu);
        int slice = cputoslice(cpu);
 
        /*
@@ -177,7 +105,7 @@ static irqreturn_t hub_rt_counter_handler(int irq, void *dev_id)
 
 struct irqaction hub_rt_irqaction = {
        .handler        = hub_rt_counter_handler,
-       .flags          = IRQF_DISABLED | IRQF_PERCPU,
+       .flags          = IRQF_DISABLED | IRQF_PERCPU | IRQF_TIMER,
        .name           = "hub-rt",
 };
 
@@ -192,10 +120,7 @@ struct irqaction hub_rt_irqaction = {
 #define NSEC_PER_CYCLE         800
 #define CYCLES_PER_SEC         (NSEC_PER_SEC / NSEC_PER_CYCLE)
 
-static DEFINE_PER_CPU(struct clock_event_device, hub_rt_clockevent);
-static DEFINE_PER_CPU(char [11], hub_rt_name);
-
-static void __cpuinit hub_rt_clock_event_init(void)
+void __cpuinit hub_rt_clock_event_init(void)
 {
        unsigned int cpu = smp_processor_id();
        struct clock_event_device *cd = &per_cpu(hub_rt_clockevent, cpu);
@@ -203,23 +128,22 @@ static void __cpuinit hub_rt_clock_event_init(void)
        int irq = rt_timer_irq;
 
        sprintf(name, "hub-rt %d", cpu);
-       cd->name                = "HUB-RT",
-       cd->features            = CLOCK_EVT_FEAT_ONESHOT,
+       cd->name                = name;
+       cd->features            = CLOCK_EVT_FEAT_ONESHOT;
        clockevent_set_clock(cd, CYCLES_PER_SEC);
        cd->max_delta_ns        = clockevent_delta2ns(0xfffffffffffff, cd);
        cd->min_delta_ns        = clockevent_delta2ns(0x300, cd);
-       cd->rating              = 200,
-       cd->irq                 = irq,
-       cd->cpumask             = cpumask_of_cpu(cpu),
-       cd->rating              = 300,
-       cd->set_next_event      = rt_next_event,
-       cd->set_mode            = rt_set_mode,
+       cd->rating              = 200;
+       cd->irq                 = irq;
+       cd->cpumask             = cpumask_of(cpu);
+       cd->set_next_event      = rt_next_event;
+       cd->set_mode            = rt_set_mode;
        clockevents_register_device(cd);
 }
 
 static void __init hub_rt_clock_event_global_init(void)
 {
-       unsigned int irq;
+       int irq;
 
        do {
                smp_wmb();
@@ -236,7 +160,7 @@ static void __init hub_rt_clock_event_global_init(void)
        setup_irq(irq, &hub_rt_irqaction);
 }
 
-static cycle_t hub_rt_read(void)
+static cycle_t hub_rt_read(struct clocksource *cs)
 {
        return REMOTE_HUB_L(cputonasid(0), PI_RT_COUNT);
 }
@@ -261,6 +185,7 @@ void __init plat_time_init(void)
 {
        hub_rt_clocksource_init();
        hub_rt_clock_event_global_init();
+       hub_rt_clock_event_init();
 }
 
 void __cpuinit cpu_time_init(void)
@@ -281,12 +206,12 @@ void __cpuinit cpu_time_init(void)
 
        printk("CPU %d clock is %dMHz.\n", smp_processor_id(), cpu->cpu_speed);
 
-       hub_rt_clock_event_init();
        set_c0_status(SRB_TIMOCLK);
 }
 
-void __init hub_rtc_init(cnodeid_t cnode)
+void __cpuinit hub_rtc_init(cnodeid_t cnode)
 {
+
        /*
         * We only need to initialize the current node.
         * If this is not the current node then it is a cpuless
@@ -302,3 +227,23 @@ void __init hub_rtc_init(cnodeid_t cnode)
                LOCAL_HUB_S(PI_RT_PEND_B, 0);
        }
 }
+
+static int __init sgi_ip27_rtc_devinit(void)
+{
+       struct resource res;
+
+       memset(&res, 0, sizeof(res));
+       res.start = XPHYSADDR(KL_CONFIG_CH_CONS_INFO(master_nasid)->memory_base +
+                             IOC3_BYTEBUS_DEV0);
+       res.end = res.start + 32767;
+       res.flags = IORESOURCE_MEM;
+
+       return IS_ERR(platform_device_register_simple("rtc-m48t35", -1,
+                                                     &res, 1));
+}
+
+/*
+ * kludge make this a device_initcall after ioc3 resource conflicts
+ * are resolved
+ */
+late_initcall(sgi_ip27_rtc_devinit);