Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-clps711x/time.c |
| 3 | * |
| 4 | * Copyright (C) 2001 Deep Blue Solutions Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #include <linux/timex.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/interrupt.h> |
Thomas Gleixner | 6f77dde | 2006-07-01 22:32:37 +0100 | [diff] [blame] | 22 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/sched.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/irq.h> |
| 28 | #include <asm/leds.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/hardware/clps7111.h> |
| 30 | |
| 31 | #include <asm/mach/time.h> |
| 32 | |
| 33 | |
| 34 | /* |
| 35 | * gettimeoffset() returns time since last timer tick, in usecs. |
| 36 | * |
| 37 | * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy. |
| 38 | * 'tick' is usecs per jiffy. |
| 39 | */ |
| 40 | static unsigned long clps711x_gettimeoffset(void) |
| 41 | { |
| 42 | unsigned long hwticks; |
| 43 | hwticks = LATCH - (clps_readl(TC2D) & 0xffff); /* since last underflow */ |
| 44 | return (hwticks * (tick_nsec / 1000)) / LATCH; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * IRQ handler for the timer |
| 49 | */ |
| 50 | static irqreturn_t |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 51 | p720t_timer_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 53 | timer_tick(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | return IRQ_HANDLED; |
| 55 | } |
| 56 | |
| 57 | static struct irqaction clps711x_timer_irq = { |
| 58 | .name = "CLPS711x Timer Tick", |
Bernhard Walle | b30faba | 2007-05-08 00:35:39 -0700 | [diff] [blame] | 59 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
Russell King | 09b8b5f | 2005-06-26 17:06:36 +0100 | [diff] [blame] | 60 | .handler = p720t_timer_interrupt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static void __init clps711x_timer_init(void) |
| 64 | { |
| 65 | struct timespec tv; |
| 66 | unsigned int syscon; |
| 67 | |
| 68 | syscon = clps_readl(SYSCON1); |
| 69 | syscon |= SYSCON1_TC2S | SYSCON1_TC2M; |
| 70 | clps_writel(syscon, SYSCON1); |
| 71 | |
| 72 | clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */ |
| 73 | |
| 74 | setup_irq(IRQ_TC2OI, &clps711x_timer_irq); |
| 75 | |
| 76 | tv.tv_nsec = 0; |
| 77 | tv.tv_sec = clps_readl(RTCDR); |
| 78 | do_settimeofday(&tv); |
| 79 | } |
| 80 | |
| 81 | struct sys_timer clps711x_timer = { |
| 82 | .init = clps711x_timer_init, |
| 83 | .offset = clps711x_gettimeoffset, |
| 84 | }; |