2 * time.c Timer functions for cpe
5 #include <linux/time.h>
6 #include <linux/timex.h>
7 #include <linux/types.h>
8 #include <linux/sched.h>
9 #include <linux/interrupt.h>
10 #if 1 // add by Victor Yu. 05-25-2005
11 #include <linux/init.h>
12 #include <asm/mach/time.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/time.h>
17 #include <asm/arch/cpe/cpe.h>
18 #include <asm/arch/cpe_int.h>
22 cpe_time_reg_t
*TimerBase
[] ={ 0,
23 (cpe_time_reg_t
*)CPE_TIMER1_VA_BASE
,
24 (cpe_time_reg_t
*)CPE_TIMER2_VA_BASE
27 unsigned int cpe_timer_enable(unsigned int timer
)
29 cpe_time_ctrl_t
*t
=(cpe_time_ctrl_t
*)(CPE_TIMER1_VA_BASE
+TIMER_CR
);
31 if ((timer
== 0) || (timer
> MAX_TIMER
))
39 #if 1 // add by Victor Yu. 06-01-2005
40 t
->Tm1Clock
= 0; // use PCLK
46 #if 1 // add by Victor Yu. 06-01-2005
47 t
->Tm2Clock
= 0; // use PCLK
53 #if 1 // add by Victor Yu. 06-01-2005
54 t
->Tm3Clock
= 0; // use PCLK
65 /* This routine stops the specified timer hardware. */
66 unsigned int cpe_timer_disable(unsigned int timer
)
68 cpe_time_ctrl_t
*t
=(cpe_time_ctrl_t
*)(CPE_TIMER1_VA_BASE
+ TIMER_CR
);
70 if ((timer
== 0) || (timer
> MAX_TIMER
))
95 void cpe_timer_set_counter(unsigned int timer
, unsigned int value
)
97 volatile cpe_time_reg_t
*t
= TimerBase
[timer
];
98 t
->TimerValue
= value
;
101 void cpe_timer_set_reload(unsigned int timer
, unsigned int value
)
103 volatile cpe_time_reg_t
*t
= TimerBase
[timer
];
104 t
->TimerLoad
= value
;
107 // --------------------------------------------------------------------
110 // --------------------------------------------------------------------
111 unsigned int cpe_timer_get_counter(unsigned int timer
)
113 volatile cpe_time_reg_t
*t
= TimerBase
[timer
];
114 return t
->TimerValue
;
117 #define SET_COUNTER (APB_CLK / HZ)
119 unsigned long cpe_gettimeoffset (void)
121 #if 1 // add by Victor Yu. 02-26-2007
122 unsigned long volatile offsetticks
;
124 offsetticks
= cpe_timer_get_counter(USED_TIMER
);
125 offsetticks
= SET_COUNTER
- offsetticks
;
126 #if 0 // mask by Victor Yu. 01-31-2008
127 if ( (*(volatile unsigned int *)(CPE_IC_VA_BASE
+IRQ_STATUS_REG
) & IRQ_TIMER1
) ||
128 (*(volatile unsigned int *)(CPE_IC_VA_BASE
+IRQ_STATUS_REG
) & IRQ_TIMER1
) ) {
130 if ( *(volatile unsigned int *)(CPE_TIMER1_VA_BASE
+TIMER_INTR_STATE
) ) {
131 //printk("[has timer interrupt pending , %d !]\n", offsetticks);
133 offsetticks
= cpe_timer_get_counter(USED_TIMER
);
134 offsetticks
= SET_COUNTER
- offsetticks
;
135 offsetticks
+= SET_COUNTER
;
137 offsetticks
= offsetticks
/ (APB_CLK
/ 1000000); // tansfer ticks to usec
144 #if 1 // add by Victor Yu. 05-25-2005
145 static irqreturn_t
cpe_timer_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
147 //do_timer(regs); // mask by Victor Yu. 06-01-2005
148 timer_tick(regs
); // add by Victor Yu. 06-01-2005
149 *(volatile unsigned int *)(CPE_TIMER1_VA_BASE
+TIMER_INTR_STATE
) = 0;
154 static struct irqaction cpe_timer_irq
= {
155 .name
= "Moxa CPE timer interrupt",
156 .flags
= SA_INTERRUPT
,
157 .handler
= cpe_timer_interrupt
160 void __init
cpe_timer_init(void)
162 //printk("HZ:%d\n",HZ);
163 gettimeoffset
= cpe_gettimeoffset
;
164 #ifdef TIMER_INC_MODE
165 cpe_timer_set_reload(1, 0xffffffff - APB_CLK
/HZ
);
166 cpe_timer_set_counter(1, 0xffffffff - APB_CLK
/HZ
);
168 cpe_timer_set_reload(1, APB_CLK
/HZ
);
169 cpe_timer_set_counter(1, APB_CLK
/HZ
);
172 if( !cpe_timer_enable(1) ) {
173 panic("can not enable timer\n");
176 printk("IRQ timer at interrupt number 0x%x clock %d\r\n",IRQ_TIMER1
,APB_CLK
);
177 cpe_int_set_irq(IRQ_TIMER1
, EDGE
, L_ACTIVE
);
178 setup_irq(IRQ_TIMER1
, &cpe_timer_irq
);