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.
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", \
24 __FILE__, __func__, __LINE__);
27 #define BFIN_TIMER_NUM_GROUP (BFIN_TIMER_OCTET(MAX_BLACKFIN_GPTIMERS - 1) + 1)
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
,
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
,
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
,
73 static uint32_t const dis_mask
[MAX_BLACKFIN_GPTIMERS
] =
78 #if (MAX_BLACKFIN_GPTIMERS > 3)
85 #if (MAX_BLACKFIN_GPTIMERS > 8)
93 static uint32_t const irq_mask
[MAX_BLACKFIN_GPTIMERS
] =
98 #if (MAX_BLACKFIN_GPTIMERS > 3)
105 #if (MAX_BLACKFIN_GPTIMERS > 8)
108 TIMER_STATUS_TIMIL10
,
109 TIMER_STATUS_TIMIL11
,
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
;
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
;
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
;
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
;
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
)
197 tassert((mask
& ~BLACKFIN_GPTIMER_IDMASK
) == 0);
198 for (i
= 0; i
< BFIN_TIMER_NUM_GROUP
; ++i
) {
199 group_regs
[i
]->enable
= mask
& 0xFF;
204 EXPORT_SYMBOL(enable_gptimers
);
206 void disable_gptimers(uint16_t 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;
215 for (i
= 0; i
< MAX_BLACKFIN_GPTIMERS
; ++i
)
217 group_regs
[BFIN_TIMER_OCTET(i
)]->status
|= dis_mask
[i
];
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
;
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
;
236 EXPORT_SYMBOL(clear_gptimer_pulse_hi
);
238 uint16_t get_enabled_gptimers(void)
242 for (i
= 0; i
< BFIN_TIMER_NUM_GROUP
; ++i
)
243 result
|= (group_regs
[i
]->enable
<< (i
<< 3));
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");