9 #include <linux/slab.h>
18 static bool use_system_timer;
66 static void ct_systimer_callback(
unsigned long data)
77 position = substream->
ops->pointer(substream);
78 dist = (position + buffer_size - ti->
position) % buffer_size;
79 if (dist >= period_size ||
80 position / period_size != ti->
position / period_size) {
86 interval = ((period_size - (position % period_size))
87 *
HZ + (runtime->
rate - 1)) / runtime->
rate +
HZ * 5 / 1000;
91 spin_unlock_irqrestore(&ti->
lock, flags);
109 (runtime->
rate - 1)) / runtime->
rate);
110 spin_unlock_irqrestore(&ti->
lock, flags);
120 spin_unlock_irqrestore(&ti->
lock, flags);
125 ct_systimer_stop(ti);
129 #define ct_systimer_free ct_systimer_prepare
132 .init = ct_systimer_init,
134 .prepare = ct_systimer_prepare,
135 .start = ct_systimer_start,
136 .stop = ct_systimer_stop,
144 #define CT_TIMER_FREQ 48000
146 #define MAX_TICKS ((1 << 13) - 1)
148 static void ct_xfitimer_irq_rearm(
struct ct_timer *atimer,
int ticks)
150 struct hw *
hw = atimer->
atc->hw;
159 static void ct_xfitimer_irq_stop(
struct ct_timer *atimer)
162 struct hw *
hw = atimer->
atc->hw;
169 static inline unsigned int ct_xfitimer_get_wc(
struct ct_timer *atimer)
171 struct hw *hw = atimer->
atc->hw;
183 static int ct_xfitimer_reprogram(
struct ct_timer *atimer,
int can_update)
186 unsigned int min_intr = (
unsigned int)-1;
188 unsigned int wc, diff;
191 ct_xfitimer_irq_stop(atimer);
196 wc = ct_xfitimer_get_wc(atimer);
197 diff = wc - atimer->
wc;
204 unsigned int period_size,
rate;
206 period_size = ti->
substream->runtime->period_size;
209 if (pos / period_size != ti->
position / period_size) {
215 pos = period_size -
pos;
227 ct_xfitimer_irq_rearm(atimer, min_intr);
233 static void ct_xfitimer_check_period(
struct ct_timer *atimer)
245 spin_unlock_irqrestore(&atimer->
list_lock, flags);
249 static void ct_xfitimer_callback(
struct ct_timer *atimer)
257 update = ct_xfitimer_reprogram(atimer, 1);
258 spin_unlock(&atimer->
lock);
260 ct_xfitimer_check_period(atimer);
261 spin_lock(&atimer->
lock);
264 spin_unlock_irqrestore(&atimer->
lock, flags);
276 static void ct_xfitimer_update(
struct ct_timer *atimer)
284 spin_unlock_irqrestore(&atimer->
lock, flags);
288 ct_xfitimer_irq_stop(atimer);
289 ct_xfitimer_reprogram(atimer, 0);
290 spin_unlock_irqrestore(&atimer->
lock, flags);
300 atimer->
wc = ct_xfitimer_get_wc(atimer);
304 spin_unlock_irqrestore(&atimer->
lock, flags);
305 ct_xfitimer_update(atimer);
316 spin_unlock_irqrestore(&atimer->
lock, flags);
317 ct_xfitimer_update(atimer);
320 static void ct_xfitimer_free_global(
struct ct_timer *atimer)
322 ct_xfitimer_irq_stop(atimer);
326 .prepare = ct_xfitimer_prepare,
327 .start = ct_xfitimer_start,
328 .stop = ct_xfitimer_stop,
329 .interrupt = ct_xfitimer_callback,
330 .free_global = ct_xfitimer_free_global,
351 if (atimer->
ops->init)
352 atimer->
ops->init(ti);
372 atimer->
ops->start(ti);
378 atimer->
ops->stop(ti);
385 atimer->
ops->stop(ti);
386 if (atimer->
ops->free_instance)
387 atimer->
ops->free_instance(ti);
400 static void ct_timer_interrupt(
void *data,
unsigned int status)
405 if ((status &
IT_INT) && timer->
ops->interrupt)
406 timer->
ops->interrupt(timer);
414 atimer = kzalloc(
sizeof(*atimer),
GFP_KERNEL);
425 atimer->
ops = &ct_xfitimer_ops;
430 atimer->
ops = &ct_systimer_ops;
437 struct hw *hw = atimer->
atc->hw;
439 if (atimer->
ops->free_global)
440 atimer->
ops->free_global(atimer);