Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-serial
[pandora-kernel.git] / arch / sparc / kernel / time.c
index 7dadcdb..e10dc83 100644 (file)
@@ -15,7 +15,6 @@
  * 1997-09-10  Updated NTP code according to technical memorandum Jan '96
  *             "A Kernel Model for Precision Timekeeping" by Dave Mills
  */
-#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/sched.h>
@@ -42,8 +41,7 @@
 #include <asm/sun4paddr.h>
 #include <asm/page.h>
 #include <asm/pcic.h>
-
-extern unsigned long wall_jiffies;
+#include <asm/of_device.h>
 
 DEFINE_SPINLOCK(rtc_lock);
 enum sparc_clock_type sp_clock_typ;
@@ -128,7 +126,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs * regs)
 #endif
        clear_clock_irq();
 
-       do_timer(regs);
+       do_timer(1);
 #ifndef CONFIG_SMP
        update_process_times(user_mode(regs));
 #endif
@@ -225,6 +223,32 @@ static __inline__ int has_low_battery(void)
        return (data1 == data2);        /* Was the write blocked? */
 }
 
+static void __init mostek_set_system_time(void)
+{
+       unsigned int year, mon, day, hour, min, sec;
+       struct mostek48t02 *mregs;
+
+       mregs = (struct mostek48t02 *)mstk48t02_regs;
+       if(!mregs) {
+               prom_printf("Something wrong, clock regs not mapped yet.\n");
+               prom_halt();
+       }               
+       spin_lock_irq(&mostek_lock);
+       mregs->creg |= MSTK_CREG_READ;
+       sec = MSTK_REG_SEC(mregs);
+       min = MSTK_REG_MIN(mregs);
+       hour = MSTK_REG_HOUR(mregs);
+       day = MSTK_REG_DOM(mregs);
+       mon = MSTK_REG_MONTH(mregs);
+       year = MSTK_CVT_YEAR( MSTK_REG_YEAR(mregs) );
+       xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
+       xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
+        set_normalized_timespec(&wall_to_monotonic,
+                                -xtime.tv_sec, -xtime.tv_nsec);
+       mregs->creg &= ~MSTK_CREG_READ;
+       spin_unlock_irq(&mostek_lock);
+}
+
 /* Probe for the real time clock chip on Sun4 */
 static __inline__ void sun4_clock_probe(void)
 {
@@ -273,83 +297,32 @@ static __inline__ void sun4_clock_probe(void)
 #endif
 }
 
-/* Probe for the mostek real time clock chip. */
-static __inline__ void clock_probe(void)
+#ifndef CONFIG_SUN4
+static int __devinit clock_probe(struct of_device *op, const struct of_device_id *match)
 {
-       struct linux_prom_registers clk_reg[2];
-       char model[128];
-       register int node, cpuunit, bootbus;
-       struct resource r;
-
-       cpuunit = bootbus = 0;
-       memset(&r, 0, sizeof(r));
-
-       /* Determine the correct starting PROM node for the probe. */
-       node = prom_getchild(prom_root_node);
-       switch (sparc_cpu_model) {
-       case sun4c:
-               break;
-       case sun4m:
-               node = prom_getchild(prom_searchsiblings(node, "obio"));
-               break;
-       case sun4d:
-               node = prom_getchild(bootbus = prom_searchsiblings(prom_getchild(cpuunit = prom_searchsiblings(node, "cpu-unit")), "bootbus"));
-               break;
-       default:
-               prom_printf("CLOCK: Unsupported architecture!\n");
-               prom_halt();
-       }
+       struct device_node *dp = op->node;
+       char *model = of_get_property(dp, "model", NULL);
 
-       /* Find the PROM node describing the real time clock. */
-       sp_clock_typ = MSTK_INVALID;
-       node = prom_searchsiblings(node,"eeprom");
-       if (!node) {
-               prom_printf("CLOCK: No clock found!\n");
-               prom_halt();
-       }
+       if (!model)
+               return -ENODEV;
 
-       /* Get the model name and setup everything up. */
-       model[0] = '\0';
-       prom_getstring(node, "model", model, sizeof(model));
-       if (strcmp(model, "mk48t02") == 0) {
+       if (!strcmp(model, "mk48t02")) {
                sp_clock_typ = MSTK48T02;
-               if (prom_getproperty(node, "reg", (char *) clk_reg, sizeof(clk_reg)) == -1) {
-                       prom_printf("clock_probe: FAILED!\n");
-                       prom_halt();
-               }
-               if (sparc_cpu_model == sun4d)
-                       prom_apply_generic_ranges (bootbus, cpuunit, clk_reg, 1);
-               else
-                       prom_apply_obio_ranges(clk_reg, 1);
+
                /* Map the clock register io area read-only */
-               r.flags = clk_reg[0].which_io;
-               r.start = clk_reg[0].phys_addr;
-               mstk48t02_regs = sbus_ioremap(&r, 0,
-                   sizeof(struct mostek48t02), "mk48t02");
+               mstk48t02_regs = of_ioremap(&op->resource[0], 0,
+                                           sizeof(struct mostek48t02),
+                                           "mk48t02");
                mstk48t08_regs = NULL;  /* To catch weirdness */
-       } else if (strcmp(model, "mk48t08") == 0) {
+       } else if (!strcmp(model, "mk48t08")) {
                sp_clock_typ = MSTK48T08;
-               if(prom_getproperty(node, "reg", (char *) clk_reg,
-                                   sizeof(clk_reg)) == -1) {
-                       prom_printf("clock_probe: FAILED!\n");
-                       prom_halt();
-               }
-               if (sparc_cpu_model == sun4d)
-                       prom_apply_generic_ranges (bootbus, cpuunit, clk_reg, 1);
-               else
-                       prom_apply_obio_ranges(clk_reg, 1);
-               /* Map the clock register io area read-only */
-               /* XXX r/o attribute is somewhere in r.flags */
-               r.flags = clk_reg[0].which_io;
-               r.start = clk_reg[0].phys_addr;
-               mstk48t08_regs = sbus_ioremap(&r, 0,
-                   sizeof(struct mostek48t08), "mk48t08");
+               mstk48t08_regs = of_ioremap(&op->resource[0], 0,
+                                           sizeof(struct mostek48t08),
+                                           "mk48t08");
 
                mstk48t02_regs = &mstk48t08_regs->regs;
-       } else {
-               prom_printf("CLOCK: Unknown model name '%s'\n",model);
-               prom_halt();
-       }
+       } else
+               return -ENODEV;
 
        /* Report a low battery voltage condition. */
        if (has_low_battery())
@@ -358,53 +331,58 @@ static __inline__ void clock_probe(void)
        /* Kick start the clock if it is completely stopped. */
        if (mostek_read(mstk48t02_regs + MOSTEK_SEC) & MSTK_STOP)
                kick_start_clock();
+
+       mostek_set_system_time();
+
+       return 0;
 }
 
-void __init sbus_time_init(void)
+static struct of_device_id clock_match[] = {
+       {
+               .name = "eeprom",
+       },
+       {},
+};
+
+static struct of_platform_driver clock_driver = {
+       .name           = "clock",
+       .match_table    = clock_match,
+       .probe          = clock_probe,
+};
+
+
+/* Probe for the mostek real time clock chip. */
+static int __init clock_init(void)
 {
-       unsigned int year, mon, day, hour, min, sec;
-       struct mostek48t02 *mregs;
+       return of_register_driver(&clock_driver, &of_bus_type);
+}
 
-#ifdef CONFIG_SUN4
-       int temp;
-       struct intersil *iregs;
-#endif
+/* Must be after subsys_initcall() so that busses are probed.  Must
+ * be before device_initcall() because things like the RTC driver
+ * need to see the clock registers.
+ */
+fs_initcall(clock_init);
+#endif /* !CONFIG_SUN4 */
+
+void __init sbus_time_init(void)
+{
 
        BTFIXUPSET_CALL(bus_do_settimeofday, sbus_do_settimeofday, BTFIXUPCALL_NORM);
        btfixup();
 
        if (ARCH_SUN4)
                sun4_clock_probe();
-       else
-               clock_probe();
 
        sparc_init_timers(timer_interrupt);
        
 #ifdef CONFIG_SUN4
        if(idprom->id_machtype == (SM_SUN4 | SM_4_330)) {
-#endif
-       mregs = (struct mostek48t02 *)mstk48t02_regs;
-       if(!mregs) {
-               prom_printf("Something wrong, clock regs not mapped yet.\n");
-               prom_halt();
-       }               
-       spin_lock_irq(&mostek_lock);
-       mregs->creg |= MSTK_CREG_READ;
-       sec = MSTK_REG_SEC(mregs);
-       min = MSTK_REG_MIN(mregs);
-       hour = MSTK_REG_HOUR(mregs);
-       day = MSTK_REG_DOM(mregs);
-       mon = MSTK_REG_MONTH(mregs);
-       year = MSTK_CVT_YEAR( MSTK_REG_YEAR(mregs) );
-       xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
-        set_normalized_timespec(&wall_to_monotonic,
-                                -xtime.tv_sec, -xtime.tv_nsec);
-       mregs->creg &= ~MSTK_CREG_READ;
-       spin_unlock_irq(&mostek_lock);
-#ifdef CONFIG_SUN4
+               mostek_set_system_time();
        } else if(idprom->id_machtype == (SM_SUN4 | SM_4_260) ) {
                /* initialise the intersil on sun4 */
+               unsigned int year, mon, day, hour, min, sec;
+               int temp;
+               struct intersil *iregs;
 
                iregs=intersil_clock;
                if(!iregs) {
@@ -469,7 +447,7 @@ unsigned long long sched_clock(void)
 
 /* Ok, my cute asm atomicity trick doesn't work anymore.
  * There are just too many variables that need to be protected
- * now (both members of xtime, wall_jiffies, et al.)
+ * now (both members of xtime, et al.)
  */
 void do_gettimeofday(struct timeval *tv)
 {
@@ -479,26 +457,17 @@ void do_gettimeofday(struct timeval *tv)
        unsigned long max_ntp_tick = tick_usec - tickadj;
 
        do {
-               unsigned long lost;
-
                seq = read_seqbegin_irqsave(&xtime_lock, flags);
                usec = do_gettimeoffset();
-               lost = jiffies - wall_jiffies;
 
                /*
                 * If time_adjust is negative then NTP is slowing the clock
                 * so make sure not to go into next possible interval.
                 * Better to lose some accuracy than have time go backwards..
                 */
-               if (unlikely(time_adjust < 0)) {
+               if (unlikely(time_adjust < 0))
                        usec = min(usec, max_ntp_tick);
 
-                       if (lost)
-                               usec += lost * max_ntp_tick;
-               }
-               else if (unlikely(lost))
-                       usec += lost * tick_usec;
-
                sec = xtime.tv_sec;
                usec += (xtime.tv_nsec / 1000);
        } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
@@ -541,8 +510,7 @@ static int sbus_do_settimeofday(struct timespec *tv)
         * wall time.  Discover what correction gettimeofday() would have
         * made, and then undo it!
         */
-       nsec -= 1000 * (do_gettimeoffset() +
-                       (jiffies - wall_jiffies) * (USEC_PER_SEC / HZ));
+       nsec -= 1000 * do_gettimeoffset();
 
        wtm_sec  = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
        wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);