[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / sound / oss / emu10k1 / timer.c
blobd10d30739f41f49206b8e69b71dfafab8abd91bb
2 /*
3 **********************************************************************
4 * timer.c
5 * Copyright (C) 1999, 2000 Creative Labs, inc.
7 **********************************************************************
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
22 * USA.
24 **********************************************************************
27 /* 3/6/2000 Improved support for different timer delays Rui Sousa */
29 /* 4/3/2000 Implemented timer list using list.h Rui Sousa */
31 #include "hwaccess.h"
32 #include "8010.h"
33 #include "irqmgr.h"
34 #include "timer.h"
36 /* Try to schedule only once per fragment */
38 void emu10k1_timer_irqhandler(struct emu10k1_card *card)
40 struct emu_timer *t;
41 struct list_head *entry;
43 spin_lock(&card->timer_lock);
45 list_for_each(entry, &card->timers) {
46 t = list_entry(entry, struct emu_timer, list);
48 if (t->state & TIMER_STATE_ACTIVE) {
49 t->count++;
50 if (t->count == t->count_max) {
51 t->count = 0;
52 tasklet_hi_schedule(&t->tasklet);
57 spin_unlock(&card->timer_lock);
59 return;
62 void emu10k1_timer_install(struct emu10k1_card *card, struct emu_timer *timer, u16 delay)
64 struct emu_timer *t;
65 struct list_head *entry;
66 unsigned long flags;
68 if (delay < 5)
69 delay = 5;
71 timer->delay = delay;
72 timer->state = TIMER_STATE_INSTALLED;
74 spin_lock_irqsave(&card->timer_lock, flags);
76 timer->count_max = timer->delay / (card->timer_delay < 1024 ? card->timer_delay : 1024);
77 timer->count = timer->count_max - 1;
79 list_add(&timer->list, &card->timers);
81 if (card->timer_delay > delay) {
82 if (card->timer_delay == TIMER_STOPPED)
83 emu10k1_irq_enable(card, INTE_INTERVALTIMERENB);
85 card->timer_delay = delay;
86 delay = (delay < 1024 ? delay : 1024);
88 emu10k1_timer_set(card, delay);
90 list_for_each(entry, &card->timers) {
91 t = list_entry(entry, struct emu_timer, list);
93 t->count_max = t->delay / delay;
94 /* don't want to think much, just force scheduling
95 on the next interrupt */
96 t->count = t->count_max - 1;
99 DPD(2, "timer rate --> %u\n", delay);
102 spin_unlock_irqrestore(&card->timer_lock, flags);
104 return;
107 void emu10k1_timer_uninstall(struct emu10k1_card *card, struct emu_timer *timer)
109 struct emu_timer *t;
110 struct list_head *entry;
111 u16 delay = TIMER_STOPPED;
112 unsigned long flags;
114 if (timer->state == TIMER_STATE_UNINSTALLED)
115 return;
117 spin_lock_irqsave(&card->timer_lock, flags);
119 list_del(&timer->list);
121 list_for_each(entry, &card->timers) {
122 t = list_entry(entry, struct emu_timer, list);
124 if (t->delay < delay)
125 delay = t->delay;
128 if (card->timer_delay != delay) {
129 card->timer_delay = delay;
131 if (delay == TIMER_STOPPED)
132 emu10k1_irq_disable(card, INTE_INTERVALTIMERENB);
133 else {
134 delay = (delay < 1024 ? delay : 1024);
136 emu10k1_timer_set(card, delay);
138 list_for_each(entry, &card->timers) {
139 t = list_entry(entry, struct emu_timer, list);
141 t->count_max = t->delay / delay;
142 t->count = t->count_max - 1;
146 DPD(2, "timer rate --> %u\n", delay);
149 spin_unlock_irqrestore(&card->timer_lock, flags);
151 timer->state = TIMER_STATE_UNINSTALLED;
153 return;
156 void emu10k1_timer_enable(struct emu10k1_card *card, struct emu_timer *timer)
158 unsigned long flags;
160 spin_lock_irqsave(&card->timer_lock, flags);
161 timer->state |= TIMER_STATE_ACTIVE;
162 spin_unlock_irqrestore(&card->timer_lock, flags);
164 return;
167 void emu10k1_timer_disable(struct emu10k1_card *card, struct emu_timer *timer)
169 unsigned long flags;
171 spin_lock_irqsave(&card->timer_lock, flags);
172 timer->state &= ~TIMER_STATE_ACTIVE;
173 spin_unlock_irqrestore(&card->timer_lock, flags);
175 return;