1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/time.h>
25#include <sound/core.h>
26#include <sound/gus.h>
27
28
29
30
31
32static int snd_gf1_timer1_start(struct snd_timer * timer)
33{
34 unsigned long flags;
35 unsigned char tmp;
36 unsigned int ticks;
37 struct snd_gus_card *gus;
38
39 gus = snd_timer_chip(timer);
40 spin_lock_irqsave(&gus->reg_lock, flags);
41 ticks = timer->sticks;
42 tmp = (gus->gf1.timer_enabled |= 4);
43 snd_gf1_write8(gus, SNDRV_GF1_GB_ADLIB_TIMER_1, 256 - ticks);
44 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp);
45 snd_gf1_adlib_write(gus, 0x04, tmp >> 2);
46 spin_unlock_irqrestore(&gus->reg_lock, flags);
47 return 0;
48}
49
50static int snd_gf1_timer1_stop(struct snd_timer * timer)
51{
52 unsigned long flags;
53 unsigned char tmp;
54 struct snd_gus_card *gus;
55
56 gus = snd_timer_chip(timer);
57 spin_lock_irqsave(&gus->reg_lock, flags);
58 tmp = (gus->gf1.timer_enabled &= ~4);
59 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp);
60 spin_unlock_irqrestore(&gus->reg_lock, flags);
61 return 0;
62}
63
64
65
66
67
68static int snd_gf1_timer2_start(struct snd_timer * timer)
69{
70 unsigned long flags;
71 unsigned char tmp;
72 unsigned int ticks;
73 struct snd_gus_card *gus;
74
75 gus = snd_timer_chip(timer);
76 spin_lock_irqsave(&gus->reg_lock, flags);
77 ticks = timer->sticks;
78 tmp = (gus->gf1.timer_enabled |= 8);
79 snd_gf1_write8(gus, SNDRV_GF1_GB_ADLIB_TIMER_2, 256 - ticks);
80 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp);
81 snd_gf1_adlib_write(gus, 0x04, tmp >> 2);
82 spin_unlock_irqrestore(&gus->reg_lock, flags);
83 return 0;
84}
85
86static int snd_gf1_timer2_stop(struct snd_timer * timer)
87{
88 unsigned long flags;
89 unsigned char tmp;
90 struct snd_gus_card *gus;
91
92 gus = snd_timer_chip(timer);
93 spin_lock_irqsave(&gus->reg_lock, flags);
94 tmp = (gus->gf1.timer_enabled &= ~8);
95 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp);
96 spin_unlock_irqrestore(&gus->reg_lock, flags);
97 return 0;
98}
99
100
101
102
103
104static void snd_gf1_interrupt_timer1(struct snd_gus_card * gus)
105{
106 struct snd_timer *timer = gus->gf1.timer1;
107
108 if (timer == NULL)
109 return;
110 snd_timer_interrupt(timer, timer->sticks);
111}
112
113static void snd_gf1_interrupt_timer2(struct snd_gus_card * gus)
114{
115 struct snd_timer *timer = gus->gf1.timer2;
116
117 if (timer == NULL)
118 return;
119 snd_timer_interrupt(timer, timer->sticks);
120}
121
122
123
124
125
126static struct snd_timer_hardware snd_gf1_timer1 =
127{
128 .flags = SNDRV_TIMER_HW_STOP,
129 .resolution = 80000,
130 .ticks = 256,
131 .start = snd_gf1_timer1_start,
132 .stop = snd_gf1_timer1_stop,
133};
134
135static struct snd_timer_hardware snd_gf1_timer2 =
136{
137 .flags = SNDRV_TIMER_HW_STOP,
138 .resolution = 320000,
139 .ticks = 256,
140 .start = snd_gf1_timer2_start,
141 .stop = snd_gf1_timer2_stop,
142};
143
144static void snd_gf1_timer1_free(struct snd_timer *timer)
145{
146 struct snd_gus_card *gus = timer->private_data;
147 gus->gf1.timer1 = NULL;
148}
149
150static void snd_gf1_timer2_free(struct snd_timer *timer)
151{
152 struct snd_gus_card *gus = timer->private_data;
153 gus->gf1.timer2 = NULL;
154}
155
156void snd_gf1_timers_init(struct snd_gus_card * gus)
157{
158 struct snd_timer *timer;
159 struct snd_timer_id tid;
160
161 if (gus->gf1.timer1 != NULL || gus->gf1.timer2 != NULL)
162 return;
163
164 gus->gf1.interrupt_handler_timer1 = snd_gf1_interrupt_timer1;
165 gus->gf1.interrupt_handler_timer2 = snd_gf1_interrupt_timer2;
166
167 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
168 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
169 tid.card = gus->card->number;
170 tid.device = gus->timer_dev;
171 tid.subdevice = 0;
172
173 if (snd_timer_new(gus->card, "GF1 timer", &tid, &timer) >= 0) {
174 strcpy(timer->name, "GF1 timer #1");
175 timer->private_data = gus;
176 timer->private_free = snd_gf1_timer1_free;
177 timer->hw = snd_gf1_timer1;
178 }
179 gus->gf1.timer1 = timer;
180
181 tid.device++;
182
183 if (snd_timer_new(gus->card, "GF1 timer", &tid, &timer) >= 0) {
184 strcpy(timer->name, "GF1 timer #2");
185 timer->private_data = gus;
186 timer->private_free = snd_gf1_timer2_free;
187 timer->hw = snd_gf1_timer2;
188 }
189 gus->gf1.timer2 = timer;
190}
191
192void snd_gf1_timers_done(struct snd_gus_card * gus)
193{
194 snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_TIMER1 | SNDRV_GF1_HANDLER_TIMER2);
195 if (gus->gf1.timer1) {
196 snd_device_free(gus->card, gus->gf1.timer1);
197 gus->gf1.timer1 = NULL;
198 }
199 if (gus->gf1.timer2) {
200 snd_device_free(gus->card, gus->gf1.timer2);
201 gus->gf1.timer2 = NULL;
202 }
203}
204