2 * gptimers.c - Blackfin General Purpose Timer core API
4 * Copyright (c) 2005-2008 Analog Devices Inc.
5 * Copyright (C) 2005 John DeHority
6 * Copyright (C) 2006 Hella Aglaia GmbH (awe@aglaia-gmbh.de)
8 * Licensed under the GPLv2.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
15 #include <asm/blackfin.h>
16 #include <asm/gptimers.h>
19 # define tassert(expr)
21 # define tassert(expr) \
23 printk(KERN_DEBUG "%s:%s:%i: Assertion failed: " #expr "\n", __FILE__, __func__, __LINE__);
26 #define BFIN_TIMER_NUM_GROUP (BFIN_TIMER_OCTET(MAX_BLACKFIN_GPTIMERS - 1) + 1)
44 static volatile GPTIMER_timer_regs
*const timer_regs
[MAX_BLACKFIN_GPTIMERS
] =
46 (GPTIMER_timer_regs
*)TIMER0_CONFIG
,
47 (GPTIMER_timer_regs
*)TIMER1_CONFIG
,
48 (GPTIMER_timer_regs
*)TIMER2_CONFIG
,
49 #if (MAX_BLACKFIN_GPTIMERS > 3)
50 (GPTIMER_timer_regs
*)TIMER3_CONFIG
,
51 (GPTIMER_timer_regs
*)TIMER4_CONFIG
,
52 (GPTIMER_timer_regs
*)TIMER5_CONFIG
,
53 (GPTIMER_timer_regs
*)TIMER6_CONFIG
,
54 (GPTIMER_timer_regs
*)TIMER7_CONFIG
,
55 # if (MAX_BLACKFIN_GPTIMERS > 8)
56 (GPTIMER_timer_regs
*)TIMER8_CONFIG
,
57 (GPTIMER_timer_regs
*)TIMER9_CONFIG
,
58 (GPTIMER_timer_regs
*)TIMER10_CONFIG
,
59 # if (MAX_BLACKFIN_GPTIMERS > 11)
60 (GPTIMER_timer_regs
*)TIMER11_CONFIG
,
66 static volatile GPTIMER_group_regs
*const group_regs
[BFIN_TIMER_NUM_GROUP
] =
68 (GPTIMER_group_regs
*)TIMER0_GROUP_REG
,
69 #if (MAX_BLACKFIN_GPTIMERS > 8)
70 (GPTIMER_group_regs
*)TIMER8_GROUP_REG
,
74 static uint32_t const trun_mask
[MAX_BLACKFIN_GPTIMERS
] =
79 #if (MAX_BLACKFIN_GPTIMERS > 3)
85 # if (MAX_BLACKFIN_GPTIMERS > 8)
89 # if (MAX_BLACKFIN_GPTIMERS > 11)
96 static uint32_t const tovf_mask
[MAX_BLACKFIN_GPTIMERS
] =
101 #if (MAX_BLACKFIN_GPTIMERS > 3)
107 # if (MAX_BLACKFIN_GPTIMERS > 8)
111 # if (MAX_BLACKFIN_GPTIMERS > 11)
118 static uint32_t const timil_mask
[MAX_BLACKFIN_GPTIMERS
] =
123 #if (MAX_BLACKFIN_GPTIMERS > 3)
129 # if (MAX_BLACKFIN_GPTIMERS > 8)
132 TIMER_STATUS_TIMIL10
,
133 # if (MAX_BLACKFIN_GPTIMERS > 11)
134 TIMER_STATUS_TIMIL11
,
140 void set_gptimer_pwidth(int timer_id
, uint32_t value
)
142 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
143 timer_regs
[timer_id
]->width
= value
;
146 EXPORT_SYMBOL(set_gptimer_pwidth
);
148 uint32_t get_gptimer_pwidth(int timer_id
)
150 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
151 return timer_regs
[timer_id
]->width
;
153 EXPORT_SYMBOL(get_gptimer_pwidth
);
155 void set_gptimer_period(int timer_id
, uint32_t period
)
157 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
158 timer_regs
[timer_id
]->period
= period
;
161 EXPORT_SYMBOL(set_gptimer_period
);
163 uint32_t get_gptimer_period(int timer_id
)
165 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
166 return timer_regs
[timer_id
]->period
;
168 EXPORT_SYMBOL(get_gptimer_period
);
170 uint32_t get_gptimer_count(int timer_id
)
172 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
173 return timer_regs
[timer_id
]->counter
;
175 EXPORT_SYMBOL(get_gptimer_count
);
177 uint32_t get_gptimer_status(int group
)
179 tassert(group
< BFIN_TIMER_NUM_GROUP
);
180 return group_regs
[group
]->status
;
182 EXPORT_SYMBOL(get_gptimer_status
);
184 void set_gptimer_status(int group
, uint32_t value
)
186 tassert(group
< BFIN_TIMER_NUM_GROUP
);
187 group_regs
[group
]->status
= value
;
190 EXPORT_SYMBOL(set_gptimer_status
);
192 uint16_t get_gptimer_intr(int timer_id
)
194 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
195 return (group_regs
[BFIN_TIMER_OCTET(timer_id
)]->status
& timil_mask
[timer_id
]) ? 1 : 0;
197 EXPORT_SYMBOL(get_gptimer_intr
);
199 void clear_gptimer_intr(int timer_id
)
201 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
202 group_regs
[BFIN_TIMER_OCTET(timer_id
)]->status
= timil_mask
[timer_id
];
204 EXPORT_SYMBOL(clear_gptimer_intr
);
206 uint16_t get_gptimer_over(int timer_id
)
208 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
209 return (group_regs
[BFIN_TIMER_OCTET(timer_id
)]->status
& tovf_mask
[timer_id
]) ? 1 : 0;
211 EXPORT_SYMBOL(get_gptimer_over
);
213 void clear_gptimer_over(int timer_id
)
215 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
216 group_regs
[BFIN_TIMER_OCTET(timer_id
)]->status
= tovf_mask
[timer_id
];
218 EXPORT_SYMBOL(clear_gptimer_over
);
220 void set_gptimer_config(int timer_id
, uint16_t config
)
222 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
223 timer_regs
[timer_id
]->config
= config
;
226 EXPORT_SYMBOL(set_gptimer_config
);
228 uint16_t get_gptimer_config(int timer_id
)
230 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
231 return timer_regs
[timer_id
]->config
;
233 EXPORT_SYMBOL(get_gptimer_config
);
235 void enable_gptimers(uint16_t mask
)
238 tassert((mask
& ~BLACKFIN_GPTIMER_IDMASK
) == 0);
239 for (i
= 0; i
< BFIN_TIMER_NUM_GROUP
; ++i
) {
240 group_regs
[i
]->enable
= mask
& 0xFF;
245 EXPORT_SYMBOL(enable_gptimers
);
247 void disable_gptimers(uint16_t mask
)
251 tassert((mask
& ~BLACKFIN_GPTIMER_IDMASK
) == 0);
252 for (i
= 0; i
< BFIN_TIMER_NUM_GROUP
; ++i
) {
253 group_regs
[i
]->disable
= m
& 0xFF;
256 for (i
= 0; i
< MAX_BLACKFIN_GPTIMERS
; ++i
)
258 group_regs
[BFIN_TIMER_OCTET(i
)]->status
|= trun_mask
[i
];
261 EXPORT_SYMBOL(disable_gptimers
);
263 void set_gptimer_pulse_hi(int timer_id
)
265 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
266 timer_regs
[timer_id
]->config
|= TIMER_PULSE_HI
;
269 EXPORT_SYMBOL(set_gptimer_pulse_hi
);
271 void clear_gptimer_pulse_hi(int timer_id
)
273 tassert(timer_id
< MAX_BLACKFIN_GPTIMERS
);
274 timer_regs
[timer_id
]->config
&= ~TIMER_PULSE_HI
;
277 EXPORT_SYMBOL(clear_gptimer_pulse_hi
);
279 uint16_t get_enabled_gptimers(void)
283 for (i
= 0; i
< BFIN_TIMER_NUM_GROUP
; ++i
)
284 result
|= (group_regs
[i
]->enable
<< (i
<< 3));
287 EXPORT_SYMBOL(get_enabled_gptimers
);
289 MODULE_AUTHOR("Axel Weiss (awe@aglaia-gmbh.de)");
290 MODULE_DESCRIPTION("Blackfin General Purpose Timers API");
291 MODULE_LICENSE("GPL");