]> git.sur5r.net Git - u-boot/blobdiff - arch/microblaze/cpu/timer.c
usb: hub: make minimum power-on delay configurable
[u-boot] / arch / microblaze / cpu / timer.c
index a91eabc64280a84f5219f14b11fae9f6b0bcdf53..1330401a93429bb5313f9233e72d33fa6554089c 100644 (file)
 #include <asm/microblaze_intc.h>
 
 volatile int timestamp = 0;
+microblaze_timer_t *tmr;
 
-void reset_timer (void)
+ulong get_timer (ulong base)
 {
-       timestamp = 0;
+       if (tmr)
+               return timestamp - base;
+       return timestamp++ - base;
 }
 
-#ifdef CONFIG_SYS_TIMER_0
-ulong get_timer (ulong base)
+void __udelay(unsigned long usec)
 {
-       return (timestamp - base);
+       u32 i;
+
+       if (tmr) {
+               i = get_timer(0);
+               while ((get_timer(0) - i) < (usec / 1000))
+                       ;
+       } else {
+               for (i = 0; i < (usec * XILINX_CLOCK_FREQ / 10000000); i++)
+                       ;
+       }
 }
-#else
-ulong get_timer (ulong base)
+
+static void timer_isr(void *arg)
 {
-       return (timestamp++ - base);
+       timestamp++;
+       tmr->control = tmr->control | TIMER_INTERRUPT;
 }
-#endif
 
-void set_timer (ulong t)
+int timer_init (void)
 {
-       timestamp = t;
-}
+       int irq = -1;
+       u32 preload = 0;
+       u32 ret = 0;
+
+#if defined(CONFIG_SYS_TIMER_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
+       preload = XILINX_CLOCK_FREQ / CONFIG_SYS_HZ;
+       irq = CONFIG_SYS_TIMER_0_IRQ;
+       tmr = (microblaze_timer_t *) (CONFIG_SYS_TIMER_0_ADDR);
+#endif
 
-#ifdef CONFIG_SYS_INTC_0
-#ifdef CONFIG_SYS_TIMER_0
-microblaze_timer_t *tmr = (microblaze_timer_t *) (CONFIG_SYS_TIMER_0_ADDR);
+       if (tmr && preload && irq >= 0) {
+               tmr->loadreg = preload;
+               tmr->control = TIMER_INTERRUPT | TIMER_RESET;
+               tmr->control = TIMER_ENABLE | TIMER_ENABLE_INTR |\
+                                       TIMER_RELOAD | TIMER_DOWN_COUNT;
+               timestamp = 0;
+               ret = install_interrupt_handler (irq, timer_isr, (void *)tmr);
+               if (ret)
+                       tmr = NULL;
+       }
 
-void timer_isr (void *arg)
+       /* No problem if timer is not found/initialized */
+       return 0;
+}
+
+/*
+ * This function is derived from PowerPC code (read timebase as long long).
+ * On Microblaze it just returns the timer value.
+ */
+unsigned long long get_ticks(void)
 {
-       timestamp++;
-       tmr->control = tmr->control | TIMER_INTERRUPT;
+       return get_timer(0);
 }
 
-void timer_init (void)
+/*
+ * This function is derived from PowerPC code (timebase clock frequency).
+ * On Microblaze it returns the number of timer ticks per second.
+ */
+ulong get_tbclk(void)
 {
-       tmr->loadreg = CONFIG_SYS_TIMER_0_PRELOAD;
-       tmr->control = TIMER_INTERRUPT | TIMER_RESET;
-       tmr->control =
-           TIMER_ENABLE | TIMER_ENABLE_INTR | TIMER_RELOAD | TIMER_DOWN_COUNT;
-       reset_timer ();
-       install_interrupt_handler (CONFIG_SYS_TIMER_0_IRQ, timer_isr, (void *)tmr);
+       return CONFIG_SYS_HZ;
 }
-#endif
-#endif