allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / sound / isa / gus / gus_timer.c
bloba43b662f17c776dd12103a91b6f74f4fd24c3733
1 /*
2 * Routines for Gravis UltraSound soundcards - Timers
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
5 * GUS have similar timers as AdLib (OPL2/OPL3 chips).
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sound/driver.h>
25 #include <linux/time.h>
26 #include <sound/core.h>
27 #include <sound/gus.h>
30 * Timer 1 - 80us
33 static int snd_gf1_timer1_start(struct snd_timer * timer)
35 unsigned long flags;
36 unsigned char tmp;
37 unsigned int ticks;
38 struct snd_gus_card *gus;
40 gus = snd_timer_chip(timer);
41 spin_lock_irqsave(&gus->reg_lock, flags);
42 ticks = timer->sticks;
43 tmp = (gus->gf1.timer_enabled |= 4);
44 snd_gf1_write8(gus, SNDRV_GF1_GB_ADLIB_TIMER_1, 256 - ticks); /* timer 1 count */
45 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* enable timer 1 IRQ */
46 snd_gf1_adlib_write(gus, 0x04, tmp >> 2); /* timer 2 start */
47 spin_unlock_irqrestore(&gus->reg_lock, flags);
48 return 0;
51 static int snd_gf1_timer1_stop(struct snd_timer * timer)
53 unsigned long flags;
54 unsigned char tmp;
55 struct snd_gus_card *gus;
57 gus = snd_timer_chip(timer);
58 spin_lock_irqsave(&gus->reg_lock, flags);
59 tmp = (gus->gf1.timer_enabled &= ~4);
60 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* disable timer #1 */
61 spin_unlock_irqrestore(&gus->reg_lock, flags);
62 return 0;
66 * Timer 2 - 320us
69 static int snd_gf1_timer2_start(struct snd_timer * timer)
71 unsigned long flags;
72 unsigned char tmp;
73 unsigned int ticks;
74 struct snd_gus_card *gus;
76 gus = snd_timer_chip(timer);
77 spin_lock_irqsave(&gus->reg_lock, flags);
78 ticks = timer->sticks;
79 tmp = (gus->gf1.timer_enabled |= 8);
80 snd_gf1_write8(gus, SNDRV_GF1_GB_ADLIB_TIMER_2, 256 - ticks); /* timer 2 count */
81 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* enable timer 2 IRQ */
82 snd_gf1_adlib_write(gus, 0x04, tmp >> 2); /* timer 2 start */
83 spin_unlock_irqrestore(&gus->reg_lock, flags);
84 return 0;
87 static int snd_gf1_timer2_stop(struct snd_timer * timer)
89 unsigned long flags;
90 unsigned char tmp;
91 struct snd_gus_card *gus;
93 gus = snd_timer_chip(timer);
94 spin_lock_irqsave(&gus->reg_lock, flags);
95 tmp = (gus->gf1.timer_enabled &= ~8);
96 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* disable timer #1 */
97 spin_unlock_irqrestore(&gus->reg_lock, flags);
98 return 0;
105 static void snd_gf1_interrupt_timer1(struct snd_gus_card * gus)
107 struct snd_timer *timer = gus->gf1.timer1;
109 if (timer == NULL)
110 return;
111 snd_timer_interrupt(timer, timer->sticks);
114 static void snd_gf1_interrupt_timer2(struct snd_gus_card * gus)
116 struct snd_timer *timer = gus->gf1.timer2;
118 if (timer == NULL)
119 return;
120 snd_timer_interrupt(timer, timer->sticks);
127 static struct snd_timer_hardware snd_gf1_timer1 =
129 .flags = SNDRV_TIMER_HW_STOP,
130 .resolution = 80000,
131 .ticks = 256,
132 .start = snd_gf1_timer1_start,
133 .stop = snd_gf1_timer1_stop,
136 static struct snd_timer_hardware snd_gf1_timer2 =
138 .flags = SNDRV_TIMER_HW_STOP,
139 .resolution = 320000,
140 .ticks = 256,
141 .start = snd_gf1_timer2_start,
142 .stop = snd_gf1_timer2_stop,
145 static void snd_gf1_timer1_free(struct snd_timer *timer)
147 struct snd_gus_card *gus = timer->private_data;
148 gus->gf1.timer1 = NULL;
151 static void snd_gf1_timer2_free(struct snd_timer *timer)
153 struct snd_gus_card *gus = timer->private_data;
154 gus->gf1.timer2 = NULL;
157 void snd_gf1_timers_init(struct snd_gus_card * gus)
159 struct snd_timer *timer;
160 struct snd_timer_id tid;
162 if (gus->gf1.timer1 != NULL || gus->gf1.timer2 != NULL)
163 return;
165 gus->gf1.interrupt_handler_timer1 = snd_gf1_interrupt_timer1;
166 gus->gf1.interrupt_handler_timer2 = snd_gf1_interrupt_timer2;
168 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
169 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
170 tid.card = gus->card->number;
171 tid.device = gus->timer_dev;
172 tid.subdevice = 0;
174 if (snd_timer_new(gus->card, "GF1 timer", &tid, &timer) >= 0) {
175 strcpy(timer->name, "GF1 timer #1");
176 timer->private_data = gus;
177 timer->private_free = snd_gf1_timer1_free;
178 timer->hw = snd_gf1_timer1;
180 gus->gf1.timer1 = timer;
182 tid.device++;
184 if (snd_timer_new(gus->card, "GF1 timer", &tid, &timer) >= 0) {
185 strcpy(timer->name, "GF1 timer #2");
186 timer->private_data = gus;
187 timer->private_free = snd_gf1_timer2_free;
188 timer->hw = snd_gf1_timer2;
190 gus->gf1.timer2 = timer;
193 void snd_gf1_timers_done(struct snd_gus_card * gus)
195 snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_TIMER1 | SNDRV_GF1_HANDLER_TIMER2);
196 if (gus->gf1.timer1) {
197 snd_device_free(gus->card, gus->gf1.timer1);
198 gus->gf1.timer1 = NULL;
200 if (gus->gf1.timer2) {
201 snd_device_free(gus->card, gus->gf1.timer2);
202 gus->gf1.timer2 = NULL;