MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / arm / mach-atmel / time.c
blob182f38e3b46e077ac6c773524f96983faee433dc
1 /*
2 * linux/arch/armnommu/mach-atmel/time.c
4 * Copyright (C) SAMSUNG ELECTRONICS
5 * Hyok S. Choi <hyok.choi@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <asm/system.h>
26 #include <asm/leds.h>
27 #include <asm/mach-types.h>
29 #include <asm/io.h>
30 #include <asm/irq.h>
31 #include <asm/mach/time.h>
32 #include <asm/arch/time.h>
34 unsigned long atmel_gettimeoffset (void)
36 volatile struct at91_timers* tt = (struct at91_timers*) (AT91_TC_BASE);
37 volatile struct at91_timer_channel* tc = &tt->chans[KERNEL_TIMER].ch;
38 return tc->cv * (1000*1000)/(ARM_CLK/128);
41 static irqreturn_t
42 atmel_timer_interrupt(int irq, void *dev_id)
44 /* Clear the timer status interrupt. */
45 volatile struct at91_timers* tt = (struct at91_timers*) (AT91_TC_BASE);
46 volatile struct at91_timer_channel* tc = &tt->chans[KERNEL_TIMER].ch;
47 (void)tc->sr;
49 timer_tick();
50 return IRQ_HANDLED;
53 static struct irqaction atmel_timer_irq = {
54 .name = "ATMEL Timer Tick",
55 .flags = IRQF_DISABLED | IRQF_TIMER,
56 .handler = atmel_timer_interrupt
60 * Set up timer interrupt, and return the current time in seconds.
63 void __init atmel_time_init (void)
65 register volatile struct at91_timers* tt = (struct at91_timers*) (AT91_TC_BASE);
66 register volatile struct at91_timer_channel* tc = &tt->chans[KERNEL_TIMER].ch;
67 unsigned long v;
69 /* enable Kernel timer */
70 HW_AT91_TIMER_INIT(KERNEL_TIMER)
72 /* No SYNC */
73 tt->bcr = 0;
74 /* program NO signal on XC1 */
75 v = tt->bmr;
76 v &= ~TCNXCNS(KERNEL_TIMER,3);
77 v |= TCNXCNS(KERNEL_TIMER,1);
78 tt->bmr = v;
80 tc->ccr = 2; /* disable the channel */
82 /* select ACLK/128 as inupt frequency for TC1 and enable CPCTRG */
83 tc->cmr = 3 | (1 << 14);
85 tc->idr = ~0ul; /* disable all interrupt */
86 tc->rc = ((ARM_CLK/128)/HZ - 1); /* load the count limit into the CR register */
87 tc->ier = TC_CPCS; /* enable CPCS interrupt */
90 * @todo do those really need to be function pointers ?
92 atmel_timer_irq.handler = atmel_timer_interrupt;
94 /* set up the interrupt */
95 setup_irq(KERNEL_TIMER_IRQ_NUM, &atmel_timer_irq);
97 /* enable the channel */
98 tc->ccr = TC_SWTRG|TC_CLKEN;
101 struct sys_timer atmel_timer = {
102 .init = atmel_time_init,
103 .offset = atmel_gettimeoffset,