Use dentry_path() to create full path to inode object
[pohmelfs.git] / arch / blackfin / kernel / gptimers.c
blob06459f4bf43a61371af9a1dcaf159edb35abd4bb
1 /*
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.
9 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/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", __FILE__, __func__, __LINE__);
24 #endif
26 #define BFIN_TIMER_NUM_GROUP (BFIN_TIMER_OCTET(MAX_BLACKFIN_GPTIMERS - 1) + 1)
28 static struct bfin_gptimer_regs * const timer_regs[MAX_BLACKFIN_GPTIMERS] =
30 (void *)TIMER0_CONFIG,
31 (void *)TIMER1_CONFIG,
32 (void *)TIMER2_CONFIG,
33 #if (MAX_BLACKFIN_GPTIMERS > 3)
34 (void *)TIMER3_CONFIG,
35 (void *)TIMER4_CONFIG,
36 (void *)TIMER5_CONFIG,
37 (void *)TIMER6_CONFIG,
38 (void *)TIMER7_CONFIG,
39 # if (MAX_BLACKFIN_GPTIMERS > 8)
40 (void *)TIMER8_CONFIG,
41 (void *)TIMER9_CONFIG,
42 (void *)TIMER10_CONFIG,
43 # if (MAX_BLACKFIN_GPTIMERS > 11)
44 (void *)TIMER11_CONFIG,
45 # endif
46 # endif
47 #endif
50 static struct bfin_gptimer_group_regs * const group_regs[BFIN_TIMER_NUM_GROUP] =
52 (void *)TIMER0_GROUP_REG,
53 #if (MAX_BLACKFIN_GPTIMERS > 8)
54 (void *)TIMER8_GROUP_REG,
55 #endif
58 static uint32_t const trun_mask[MAX_BLACKFIN_GPTIMERS] =
60 TIMER_STATUS_TRUN0,
61 TIMER_STATUS_TRUN1,
62 TIMER_STATUS_TRUN2,
63 #if (MAX_BLACKFIN_GPTIMERS > 3)
64 TIMER_STATUS_TRUN3,
65 TIMER_STATUS_TRUN4,
66 TIMER_STATUS_TRUN5,
67 TIMER_STATUS_TRUN6,
68 TIMER_STATUS_TRUN7,
69 # if (MAX_BLACKFIN_GPTIMERS > 8)
70 TIMER_STATUS_TRUN8,
71 TIMER_STATUS_TRUN9,
72 TIMER_STATUS_TRUN10,
73 # if (MAX_BLACKFIN_GPTIMERS > 11)
74 TIMER_STATUS_TRUN11,
75 # endif
76 # endif
77 #endif
80 static uint32_t const tovf_mask[MAX_BLACKFIN_GPTIMERS] =
82 TIMER_STATUS_TOVF0,
83 TIMER_STATUS_TOVF1,
84 TIMER_STATUS_TOVF2,
85 #if (MAX_BLACKFIN_GPTIMERS > 3)
86 TIMER_STATUS_TOVF3,
87 TIMER_STATUS_TOVF4,
88 TIMER_STATUS_TOVF5,
89 TIMER_STATUS_TOVF6,
90 TIMER_STATUS_TOVF7,
91 # if (MAX_BLACKFIN_GPTIMERS > 8)
92 TIMER_STATUS_TOVF8,
93 TIMER_STATUS_TOVF9,
94 TIMER_STATUS_TOVF10,
95 # if (MAX_BLACKFIN_GPTIMERS > 11)
96 TIMER_STATUS_TOVF11,
97 # endif
98 # endif
99 #endif
102 static uint32_t const timil_mask[MAX_BLACKFIN_GPTIMERS] =
104 TIMER_STATUS_TIMIL0,
105 TIMER_STATUS_TIMIL1,
106 TIMER_STATUS_TIMIL2,
107 #if (MAX_BLACKFIN_GPTIMERS > 3)
108 TIMER_STATUS_TIMIL3,
109 TIMER_STATUS_TIMIL4,
110 TIMER_STATUS_TIMIL5,
111 TIMER_STATUS_TIMIL6,
112 TIMER_STATUS_TIMIL7,
113 # if (MAX_BLACKFIN_GPTIMERS > 8)
114 TIMER_STATUS_TIMIL8,
115 TIMER_STATUS_TIMIL9,
116 TIMER_STATUS_TIMIL10,
117 # if (MAX_BLACKFIN_GPTIMERS > 11)
118 TIMER_STATUS_TIMIL11,
119 # endif
120 # endif
121 #endif
124 void set_gptimer_pwidth(unsigned int timer_id, uint32_t value)
126 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
127 bfin_write(&timer_regs[timer_id]->width, value);
128 SSYNC();
130 EXPORT_SYMBOL(set_gptimer_pwidth);
132 uint32_t get_gptimer_pwidth(unsigned int timer_id)
134 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
135 return bfin_read(&timer_regs[timer_id]->width);
137 EXPORT_SYMBOL(get_gptimer_pwidth);
139 void set_gptimer_period(unsigned int timer_id, uint32_t period)
141 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
142 bfin_write(&timer_regs[timer_id]->period, period);
143 SSYNC();
145 EXPORT_SYMBOL(set_gptimer_period);
147 uint32_t get_gptimer_period(unsigned int timer_id)
149 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
150 return bfin_read(&timer_regs[timer_id]->period);
152 EXPORT_SYMBOL(get_gptimer_period);
154 uint32_t get_gptimer_count(unsigned int timer_id)
156 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
157 return bfin_read(&timer_regs[timer_id]->counter);
159 EXPORT_SYMBOL(get_gptimer_count);
161 uint32_t get_gptimer_status(unsigned int group)
163 tassert(group < BFIN_TIMER_NUM_GROUP);
164 return bfin_read(&group_regs[group]->status);
166 EXPORT_SYMBOL(get_gptimer_status);
168 void set_gptimer_status(unsigned int group, uint32_t value)
170 tassert(group < BFIN_TIMER_NUM_GROUP);
171 bfin_write(&group_regs[group]->status, value);
172 SSYNC();
174 EXPORT_SYMBOL(set_gptimer_status);
176 static uint32_t read_gptimer_status(unsigned int timer_id)
178 return bfin_read(&group_regs[BFIN_TIMER_OCTET(timer_id)]->status);
181 int get_gptimer_intr(unsigned int timer_id)
183 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
184 return !!(read_gptimer_status(timer_id) & timil_mask[timer_id]);
186 EXPORT_SYMBOL(get_gptimer_intr);
188 void clear_gptimer_intr(unsigned int timer_id)
190 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
191 bfin_write(&group_regs[BFIN_TIMER_OCTET(timer_id)]->status, timil_mask[timer_id]);
193 EXPORT_SYMBOL(clear_gptimer_intr);
195 int get_gptimer_over(unsigned int timer_id)
197 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
198 return !!(read_gptimer_status(timer_id) & tovf_mask[timer_id]);
200 EXPORT_SYMBOL(get_gptimer_over);
202 void clear_gptimer_over(unsigned int timer_id)
204 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
205 bfin_write(&group_regs[BFIN_TIMER_OCTET(timer_id)]->status, tovf_mask[timer_id]);
207 EXPORT_SYMBOL(clear_gptimer_over);
209 int get_gptimer_run(unsigned int timer_id)
211 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
212 return !!(read_gptimer_status(timer_id) & trun_mask[timer_id]);
214 EXPORT_SYMBOL(get_gptimer_run);
216 void set_gptimer_config(unsigned int timer_id, uint16_t config)
218 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
219 bfin_write(&timer_regs[timer_id]->config, config);
220 SSYNC();
222 EXPORT_SYMBOL(set_gptimer_config);
224 uint16_t get_gptimer_config(unsigned int timer_id)
226 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
227 return bfin_read(&timer_regs[timer_id]->config);
229 EXPORT_SYMBOL(get_gptimer_config);
231 void enable_gptimers(uint16_t mask)
233 int i;
234 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0);
235 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) {
236 bfin_write(&group_regs[i]->enable, mask & 0xFF);
237 mask >>= 8;
239 SSYNC();
241 EXPORT_SYMBOL(enable_gptimers);
243 static void _disable_gptimers(uint16_t mask)
245 int i;
246 uint16_t m = mask;
247 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0);
248 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) {
249 bfin_write(&group_regs[i]->disable, m & 0xFF);
250 m >>= 8;
254 void disable_gptimers(uint16_t mask)
256 int i;
257 _disable_gptimers(mask);
258 for (i = 0; i < MAX_BLACKFIN_GPTIMERS; ++i)
259 if (mask & (1 << i))
260 bfin_write(&group_regs[BFIN_TIMER_OCTET(i)]->status, trun_mask[i]);
261 SSYNC();
263 EXPORT_SYMBOL(disable_gptimers);
265 void disable_gptimers_sync(uint16_t mask)
267 _disable_gptimers(mask);
268 SSYNC();
270 EXPORT_SYMBOL(disable_gptimers_sync);
272 void set_gptimer_pulse_hi(unsigned int timer_id)
274 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
275 bfin_write_or(&timer_regs[timer_id]->config, TIMER_PULSE_HI);
276 SSYNC();
278 EXPORT_SYMBOL(set_gptimer_pulse_hi);
280 void clear_gptimer_pulse_hi(unsigned int timer_id)
282 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
283 bfin_write_and(&timer_regs[timer_id]->config, ~TIMER_PULSE_HI);
284 SSYNC();
286 EXPORT_SYMBOL(clear_gptimer_pulse_hi);
288 uint16_t get_enabled_gptimers(void)
290 int i;
291 uint16_t result = 0;
292 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i)
293 result |= (bfin_read(&group_regs[i]->enable) << (i << 3));
294 return result;
296 EXPORT_SYMBOL(get_enabled_gptimers);
298 MODULE_AUTHOR("Axel Weiss (awe@aglaia-gmbh.de)");
299 MODULE_DESCRIPTION("Blackfin General Purpose Timers API");
300 MODULE_LICENSE("GPL");