Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/plat-iop/time.c |
| 3 | * |
| 4 | * Timer code for IOP32x and IOP33x based systems |
| 5 | * |
| 6 | * Author: Deepak Saxena <dsaxena@mvista.com> |
| 7 | * |
| 8 | * Copyright 2002-2003 MontaVista Software Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/time.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/timex.h> |
| 21 | #include <asm/hardware.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <asm/irq.h> |
| 24 | #include <asm/uaccess.h> |
| 25 | #include <asm/mach/irq.h> |
| 26 | #include <asm/mach/time.h> |
| 27 | |
| 28 | #ifdef CONFIG_ARCH_IOP32X |
Lennert Buytenhek | c852ac8 | 2006-09-18 23:26:25 +0100 | [diff] [blame] | 29 | #define IRQ_IOP3XX_TIMER0 IRQ_IOP32X_TIMER0 |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 30 | #else |
| 31 | #ifdef CONFIG_ARCH_IOP33X |
Lennert Buytenhek | c852ac8 | 2006-09-18 23:26:25 +0100 | [diff] [blame] | 32 | #define IRQ_IOP3XX_TIMER0 IRQ_IOP33X_TIMER0 |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 33 | #endif |
| 34 | #endif |
| 35 | |
| 36 | static unsigned long ticks_per_jiffy; |
| 37 | static unsigned long ticks_per_usec; |
| 38 | static unsigned long next_jiffy_time; |
| 39 | |
| 40 | unsigned long iop3xx_gettimeoffset(void) |
| 41 | { |
| 42 | unsigned long offset; |
| 43 | |
| 44 | offset = next_jiffy_time - *IOP3XX_TU_TCR1; |
| 45 | |
| 46 | return offset / ticks_per_usec; |
| 47 | } |
| 48 | |
| 49 | static irqreturn_t |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame^] | 50 | iop3xx_timer_interrupt(int irq, void *dev_id) |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 51 | { |
| 52 | write_seqlock(&xtime_lock); |
| 53 | |
Lennert Buytenhek | 38ce73e | 2006-09-18 23:21:38 +0100 | [diff] [blame] | 54 | iop3xx_cp6_enable(); |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 55 | asm volatile("mcr p6, 0, %0, c6, c1, 0" : : "r" (1)); |
Lennert Buytenhek | 38ce73e | 2006-09-18 23:21:38 +0100 | [diff] [blame] | 56 | iop3xx_cp6_disable(); |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 57 | |
| 58 | while ((signed long)(next_jiffy_time - *IOP3XX_TU_TCR1) |
| 59 | >= ticks_per_jiffy) { |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame^] | 60 | timer_tick(); |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 61 | next_jiffy_time -= ticks_per_jiffy; |
| 62 | } |
| 63 | |
| 64 | write_sequnlock(&xtime_lock); |
| 65 | |
| 66 | return IRQ_HANDLED; |
| 67 | } |
| 68 | |
| 69 | static struct irqaction iop3xx_timer_irq = { |
| 70 | .name = "IOP3XX Timer Tick", |
| 71 | .handler = iop3xx_timer_interrupt, |
| 72 | .flags = IRQF_DISABLED | IRQF_TIMER, |
| 73 | }; |
| 74 | |
| 75 | void __init iop3xx_init_time(unsigned long tick_rate) |
| 76 | { |
| 77 | u32 timer_ctl; |
| 78 | |
| 79 | ticks_per_jiffy = (tick_rate + HZ/2) / HZ; |
| 80 | ticks_per_usec = tick_rate / 1000000; |
| 81 | next_jiffy_time = 0xffffffff; |
| 82 | |
| 83 | timer_ctl = IOP3XX_TMR_EN | IOP3XX_TMR_PRIVILEGED | |
| 84 | IOP3XX_TMR_RELOAD | IOP3XX_TMR_RATIO_1_1; |
| 85 | |
| 86 | /* |
| 87 | * We use timer 0 for our timer interrupt, and timer 1 as |
| 88 | * monotonic counter for tracking missed jiffies. |
| 89 | */ |
Lennert Buytenhek | 38ce73e | 2006-09-18 23:21:38 +0100 | [diff] [blame] | 90 | iop3xx_cp6_enable(); |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 91 | asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (ticks_per_jiffy - 1)); |
| 92 | asm volatile("mcr p6, 0, %0, c0, c1, 0" : : "r" (timer_ctl)); |
| 93 | asm volatile("mcr p6, 0, %0, c5, c1, 0" : : "r" (0xffffffff)); |
| 94 | asm volatile("mcr p6, 0, %0, c1, c1, 0" : : "r" (timer_ctl)); |
Lennert Buytenhek | 38ce73e | 2006-09-18 23:21:38 +0100 | [diff] [blame] | 95 | iop3xx_cp6_disable(); |
Lennert Buytenhek | 48388b2 | 2006-09-18 23:18:16 +0100 | [diff] [blame] | 96 | |
| 97 | setup_irq(IRQ_IOP3XX_TIMER0, &iop3xx_timer_irq); |
| 98 | } |