add port definition for mcf UART driver
[linux-2.6/next.git] / arch / blackfin / kernel / gptimers.c
blobcb7ba9bfc79ca55be3d6127a49d1090d98db647c
1 /*
2 * bfin_gptimers.c - derived from bf53x_timers.c
3 * Driver for General Purpose Timer functions on the Blackfin processor
5 * Copyright (C) 2005 John DeHority
6 * Copyright (C) 2006 Hella Aglaia GmbH (awe@aglaia-gmbh.de)
8 * Licensed under the GPLv2.
9 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <asm/io.h>
15 #include <asm/blackfin.h>
16 #include <asm/gptimers.h>
18 #ifdef DEBUG
19 # define tassert(expr)
20 #else
21 # define tassert(expr) \
22 if (!(expr)) \
23 printk(KERN_DEBUG "%s:%s:%i: Assertion failed: " #expr "\n", \
24 __FILE__, __func__, __LINE__);
25 #endif
27 #define BFIN_TIMER_NUM_GROUP (BFIN_TIMER_OCTET(MAX_BLACKFIN_GPTIMERS - 1) + 1)
29 typedef struct {
30 uint16_t config;
31 uint16_t __pad;
32 uint32_t counter;
33 uint32_t period;
34 uint32_t width;
35 } GPTIMER_timer_regs;
37 typedef struct {
38 uint16_t enable;
39 uint16_t __pad0;
40 uint16_t disable;
41 uint16_t __pad1;
42 uint32_t status;
43 } GPTIMER_group_regs;
45 static volatile GPTIMER_timer_regs *const timer_regs[MAX_BLACKFIN_GPTIMERS] =
47 (GPTIMER_timer_regs *)TIMER0_CONFIG,
48 (GPTIMER_timer_regs *)TIMER1_CONFIG,
49 (GPTIMER_timer_regs *)TIMER2_CONFIG,
50 #if (MAX_BLACKFIN_GPTIMERS > 3)
51 (GPTIMER_timer_regs *)TIMER3_CONFIG,
52 (GPTIMER_timer_regs *)TIMER4_CONFIG,
53 (GPTIMER_timer_regs *)TIMER5_CONFIG,
54 (GPTIMER_timer_regs *)TIMER6_CONFIG,
55 (GPTIMER_timer_regs *)TIMER7_CONFIG,
56 #endif
57 #if (MAX_BLACKFIN_GPTIMERS > 8)
58 (GPTIMER_timer_regs *)TIMER8_CONFIG,
59 (GPTIMER_timer_regs *)TIMER9_CONFIG,
60 (GPTIMER_timer_regs *)TIMER10_CONFIG,
61 (GPTIMER_timer_regs *)TIMER11_CONFIG,
62 #endif
65 static volatile GPTIMER_group_regs *const group_regs[BFIN_TIMER_NUM_GROUP] =
67 (GPTIMER_group_regs *)TIMER0_GROUP_REG,
68 #if (MAX_BLACKFIN_GPTIMERS > 8)
69 (GPTIMER_group_regs *)TIMER8_GROUP_REG,
70 #endif
73 static uint32_t const dis_mask[MAX_BLACKFIN_GPTIMERS] =
75 TIMER_STATUS_TRUN0,
76 TIMER_STATUS_TRUN1,
77 TIMER_STATUS_TRUN2,
78 #if (MAX_BLACKFIN_GPTIMERS > 3)
79 TIMER_STATUS_TRUN3,
80 TIMER_STATUS_TRUN4,
81 TIMER_STATUS_TRUN5,
82 TIMER_STATUS_TRUN6,
83 TIMER_STATUS_TRUN7,
84 #endif
85 #if (MAX_BLACKFIN_GPTIMERS > 8)
86 TIMER_STATUS_TRUN8,
87 TIMER_STATUS_TRUN9,
88 TIMER_STATUS_TRUN10,
89 TIMER_STATUS_TRUN11,
90 #endif
93 static uint32_t const irq_mask[MAX_BLACKFIN_GPTIMERS] =
95 TIMER_STATUS_TIMIL0,
96 TIMER_STATUS_TIMIL1,
97 TIMER_STATUS_TIMIL2,
98 #if (MAX_BLACKFIN_GPTIMERS > 3)
99 TIMER_STATUS_TIMIL3,
100 TIMER_STATUS_TIMIL4,
101 TIMER_STATUS_TIMIL5,
102 TIMER_STATUS_TIMIL6,
103 TIMER_STATUS_TIMIL7,
104 #endif
105 #if (MAX_BLACKFIN_GPTIMERS > 8)
106 TIMER_STATUS_TIMIL8,
107 TIMER_STATUS_TIMIL9,
108 TIMER_STATUS_TIMIL10,
109 TIMER_STATUS_TIMIL11,
110 #endif
113 void set_gptimer_pwidth(int timer_id, uint32_t value)
115 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
116 timer_regs[timer_id]->width = value;
117 SSYNC();
119 EXPORT_SYMBOL(set_gptimer_pwidth);
121 uint32_t get_gptimer_pwidth(int timer_id)
123 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
124 return timer_regs[timer_id]->width;
126 EXPORT_SYMBOL(get_gptimer_pwidth);
128 void set_gptimer_period(int timer_id, uint32_t period)
130 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
131 timer_regs[timer_id]->period = period;
132 SSYNC();
134 EXPORT_SYMBOL(set_gptimer_period);
136 uint32_t get_gptimer_period(int timer_id)
138 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
139 return timer_regs[timer_id]->period;
141 EXPORT_SYMBOL(get_gptimer_period);
143 uint32_t get_gptimer_count(int timer_id)
145 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
146 return timer_regs[timer_id]->counter;
148 EXPORT_SYMBOL(get_gptimer_count);
150 uint32_t get_gptimer_status(int group)
152 tassert(group < BFIN_TIMER_NUM_GROUP);
153 return group_regs[group]->status;
155 EXPORT_SYMBOL(get_gptimer_status);
157 void set_gptimer_status(int group, uint32_t value)
159 tassert(group < BFIN_TIMER_NUM_GROUP);
160 group_regs[group]->status = value;
161 SSYNC();
163 EXPORT_SYMBOL(set_gptimer_status);
165 uint16_t get_gptimer_intr(int timer_id)
167 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
168 return (group_regs[BFIN_TIMER_OCTET(timer_id)]->status & irq_mask[timer_id]) ? 1 : 0;
170 EXPORT_SYMBOL(get_gptimer_intr);
172 void clear_gptimer_intr(int timer_id)
174 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
175 group_regs[BFIN_TIMER_OCTET(timer_id)]->status = irq_mask[timer_id];
177 EXPORT_SYMBOL(clear_gptimer_intr);
179 void set_gptimer_config(int timer_id, uint16_t config)
181 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
182 timer_regs[timer_id]->config = config;
183 SSYNC();
185 EXPORT_SYMBOL(set_gptimer_config);
187 uint16_t get_gptimer_config(int timer_id)
189 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
190 return timer_regs[timer_id]->config;
192 EXPORT_SYMBOL(get_gptimer_config);
194 void enable_gptimers(uint16_t mask)
196 int i;
197 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0);
198 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) {
199 group_regs[i]->enable = mask & 0xFF;
200 mask >>= 8;
202 SSYNC();
204 EXPORT_SYMBOL(enable_gptimers);
206 void disable_gptimers(uint16_t mask)
208 int i;
209 uint16_t m = mask;
210 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0);
211 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) {
212 group_regs[i]->disable = m & 0xFF;
213 m >>= 8;
215 for (i = 0; i < MAX_BLACKFIN_GPTIMERS; ++i)
216 if (mask & (1 << i))
217 group_regs[BFIN_TIMER_OCTET(i)]->status |= dis_mask[i];
218 SSYNC();
220 EXPORT_SYMBOL(disable_gptimers);
222 void set_gptimer_pulse_hi(int timer_id)
224 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
225 timer_regs[timer_id]->config |= TIMER_PULSE_HI;
226 SSYNC();
228 EXPORT_SYMBOL(set_gptimer_pulse_hi);
230 void clear_gptimer_pulse_hi(int timer_id)
232 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
233 timer_regs[timer_id]->config &= ~TIMER_PULSE_HI;
234 SSYNC();
236 EXPORT_SYMBOL(clear_gptimer_pulse_hi);
238 uint16_t get_enabled_gptimers(void)
240 int i;
241 uint16_t result = 0;
242 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i)
243 result |= (group_regs[i]->enable << (i << 3));
244 return result;
246 EXPORT_SYMBOL(get_enabled_gptimers);
248 MODULE_AUTHOR("Axel Weiss (awe@aglaia-gmbh.de)");
249 MODULE_DESCRIPTION("Blackfin General Purpose Timers API");
250 MODULE_LICENSE("GPL");