]> git.pld-linux.org Git - packages/kernel.git/blame - linux-2.4.20-i810_audio.patch
- blah, not needed on HEAD
[packages/kernel.git] / linux-2.4.20-i810_audio.patch
CommitLineData
c9e2ee61 1diff -u linux/drivers/sound/i810_audio.c linux/drivers/sound/i810_audio.c
2--- linux/drivers/sound/i810_audio.c.alan Thu Aug 8 16:05:48 2002
3+++ linux/drivers/sound/i810_audio.c Thu Aug 8 16:08:23 2002
4@@ -213,7 +213,7 @@
5 #define INT_MASK (INT_SEC|INT_PRI|INT_MC|INT_PO|INT_PI|INT_MO|INT_NI|INT_GPI)
6
7
8-#define DRIVER_VERSION "0.21"
9+#define DRIVER_VERSION "0.22"
10
11 /* magic numbers to protect our data structures */
12 #define I810_CARD_MAGIC 0x5072696E /* "Prin" */
13@@ -354,7 +354,6 @@
14
15
16 struct i810_card {
17- struct i810_channel channel[3];
18 unsigned int magic;
19
20 /* We keep i810 cards in a linked list */
21@@ -378,6 +377,8 @@
22 /* structures for abstraction of hardware facilities, codecs, banks and channels*/
23 struct ac97_codec *ac97_codec[NR_AC97];
24 struct i810_state *states[NR_HW_CH];
25+ struct i810_channel *channel; /* 1:1 to states[] but diff. lifetime */
26+ dma_addr_t chandma;
27
28 u16 ac97_features;
29 u16 ac97_status;
30@@ -732,6 +733,8 @@
31 outb(0, card->iobase + PI_CR);
32 // wait for the card to acknowledge shutdown
33 while( inb(card->iobase + PI_CR) != 0 ) ;
34+ // reset the dma engine now
35+ outb(0x02, card->iobase + PI_CR);
36 // now clear any latent interrupt bits (like the halt bit)
37 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
38 outb( inb(card->iobase + PI_PICB), card->iobase + PI_PICB );
39@@ -757,7 +760,8 @@
40 if (dmabuf->count < dmabuf->dmasize && dmabuf->ready && !dmabuf->enable &&
41 (dmabuf->trigger & PCM_ENABLE_INPUT)) {
42 dmabuf->enable |= ADC_RUNNING;
43- outb((1<<4) | (1<<2) | 1, state->card->iobase + PI_CR);
44+ // Interrupt enable, LVI enable, DMA enable
45+ outb(0x10 | 0x04 | 0x01, state->card->iobase + PI_CR);
46 }
47 }
48
49@@ -781,6 +785,8 @@
50 outb(0, card->iobase + PO_CR);
51 // wait for the card to acknowledge shutdown
52 while( inb(card->iobase + PO_CR) != 0 ) ;
53+ // reset the dma engine now
54+ outb(0x02, card->iobase + PO_CR);
55 // now clear any latent interrupt bits (like the halt bit)
56 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
57 outb( inb(card->iobase + PO_PICB), card->iobase + PO_PICB );
58@@ -806,7 +812,8 @@
59 if (dmabuf->count > 0 && dmabuf->ready && !dmabuf->enable &&
60 (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
61 dmabuf->enable |= DAC_RUNNING;
62- outb((1<<4) | (1<<2) | 1, state->card->iobase + PO_CR);
63+ // Interrupt enable, LVI enable, DMA enable
64+ outb(0x10 | 0x04 | 0x01, state->card->iobase + PO_CR);
65 }
66 }
67 static void start_dac(struct i810_state *state)
68@@ -958,7 +965,7 @@
69
70 for(i=0;i<dmabuf->numfrag;i++)
71 {
72- sg->busaddr=virt_to_bus(dmabuf->rawbuf+dmabuf->fragsize*i);
73+ sg->busaddr=(u32)dmabuf->dma_handle+dmabuf->fragsize*i;
74 // the card will always be doing 16bit stereo
75 sg->control=dmabuf->fragsamples;
76 if(state->card->pci_id == PCI_DEVICE_ID_SI_7012)
77@@ -973,7 +980,9 @@
78 }
79 spin_lock_irqsave(&state->card->lock, flags);
80 outb(2, state->card->iobase+c->port+OFF_CR); /* reset DMA machine */
81- outl(virt_to_bus(&c->sg[0]), state->card->iobase+c->port+OFF_BDBAR);
82+ outl((u32)state->card->chandma +
83+ c->num*sizeof(struct i810_channel),
84+ state->card->iobase+c->port+OFF_BDBAR);
85 outb(0, state->card->iobase+c->port+OFF_CIV);
86 outb(0, state->card->iobase+c->port+OFF_LVI);
87
88@@ -1295,7 +1304,6 @@
89 if (dmabuf->enable & ADC_RUNNING)
90 __stop_adc(state);
91 dmabuf->enable = 0;
92- wake_up(&dmabuf->wait);
93 #ifdef DEBUG_INTERRUPTS
94 printk(" STOP ");
95 #endif
96@@ -1741,7 +1749,9 @@
97 }
98 if (c != NULL) {
99 outb(2, state->card->iobase+c->port+OFF_CR); /* reset DMA machine */
100- outl(virt_to_bus(&c->sg[0]), state->card->iobase+c->port+OFF_BDBAR);
101+ outl((u32)state->card->chandma +
102+ c->num*sizeof(struct i810_channel),
103+ state->card->iobase+c->port+OFF_BDBAR);
104 outb(0, state->card->iobase+c->port+OFF_CIV);
105 outb(0, state->card->iobase+c->port+OFF_LVI);
106 }
107@@ -1884,12 +1894,14 @@
108
109 switch ( val ) {
110 case 2: /* 2 channels is always supported */
111- outl(state->card->iobase + GLOB_CNT, (i_glob_cnt & 0xcfffff));
112+ outl(i_glob_cnt & 0xcfffff,
113+ state->card->iobase + GLOB_CNT);
114 /* Do we need to change mixer settings???? */
115 break;
116 case 4: /* Supported on some chipsets, better check first */
117 if ( state->card->channels >= 4 ) {
118- outl(state->card->iobase + GLOB_CNT, ((i_glob_cnt & 0xcfffff) | 0x0100000));
119+ outl((i_glob_cnt & 0xcfffff) | 0x100000,
120+ state->card->iobase + GLOB_CNT);
121 /* Do we need to change mixer settings??? */
122 } else {
123 val = ret;
124@@ -1897,7 +1909,8 @@
125 break;
126 case 6: /* Supported on some chipsets, better check first */
127 if ( state->card->channels >= 6 ) {
128- outl(state->card->iobase + GLOB_CNT, ((i_glob_cnt & 0xcfffff) | 0x0200000));
129+ outl((i_glob_cnt & 0xcfffff) | 0x200000,
130+ state->card->iobase + GLOB_CNT);
131 /* Do we need to change mixer settings??? */
132 } else {
133 val = ret;
134@@ -2415,6 +2428,9 @@
135 i810_set_spdif_output(state, AC97_EA_SPSA_3_4, spdif_locked);
136 } else {
137 i810_set_dac_rate(state, 8000);
138+ /* Put the ACLink in 2 channel mode by default */
139+ i = inl(card->iobase + GLOB_CNT);
140+ outl(i & 0xffcfffff, card->iobase + GLOB_CNT);
141 }
142 }
143
144@@ -2674,7 +2690,10 @@
145 card->channels = 6;
146 else if ( reg & 0x0100000 )
147 card->channels = 4;
148- printk("i810_audio: Audio Controller supports %d channels.\n", card->channels);
149+ printk(KERN_INFO "i810_audio: Audio Controller supports %d channels.\n", card->channels);
150+ printk(KERN_INFO "i810_audio: Defaulting to base 2 channel mode.\n");
151+ reg = inl(card->iobase + GLOB_CNT);
152+ outl(reg & 0xffcfffff, card->iobase + GLOB_CNT);
153
154 inw(card->ac97base);
155
156@@ -2707,7 +2726,7 @@
157 codec->codec_write = i810_ac97_set;
158
159 if(!i810_ac97_probe_and_powerup(card,codec)) {
160- printk("i810_audio: timed out waiting for codec %d analog ready.\n", num_ac97);
161+ printk(KERN_ERR "i810_audio: timed out waiting for codec %d analog ready.\n", num_ac97);
162 kfree(codec);
163 break; /* it didn't work */
164 }
165@@ -2716,7 +2735,7 @@
166
167 /* Don't attempt to get eid until powerup is complete */
168 eid = i810_ac97_get(codec, AC97_EXTENDED_ID);
169-
170+
171 if(eid==0xFFFFFF)
172 {
173 printk(KERN_WARNING "i810_audio: no codec attached ?\n");
174@@ -2855,6 +2874,8 @@
175 init_MUTEX(&state->open_sem);
176 dmabuf->fmt = I810_FMT_STEREO | I810_FMT_16BIT;
177 dmabuf->trigger = PCM_ENABLE_OUTPUT;
178+ i810_set_spdif_output(state, -1, 0);
179+ i810_set_dac_channels(state, 2);
180 i810_set_dac_rate(state, 48000);
181 if(prog_dmabuf(state, 0) != 0) {
182 goto config_out_nodmabuf;
183@@ -2863,6 +2884,8 @@
184 goto config_out;
185 }
186 dmabuf->count = dmabuf->dmasize;
187+ stop_dac(state);
188+ outb(0,card->iobase+dmabuf->write_channel->port+OFF_CIV);
189 outb(31,card->iobase+dmabuf->write_channel->port+OFF_LVI);
190 save_flags(flags);
191 cli();
192@@ -2871,10 +2894,9 @@
193 mdelay(50);
194 new_offset = i810_get_dma_addr(state, 0);
195 stop_dac(state);
196- outb(2,card->iobase+dmabuf->write_channel->port+OFF_CR);
197 restore_flags(flags);
198 i = new_offset - offset;
199-#ifdef DEBUG
200+#ifdef DEBUG_INTERRUPTS
201 printk("i810_audio: %d bytes in 50 milliseconds\n", i);
202 #endif
203 if(i == 0)
204@@ -2939,15 +2961,26 @@
205 card->alloc_rec_pcm_channel = i810_alloc_rec_pcm_channel;
206 card->alloc_rec_mic_channel = i810_alloc_rec_mic_channel;
207 card->free_pcm_channel = i810_free_pcm_channel;
208- card->channel[0].offset = 0;
209- card->channel[0].port = 0x00;
210- card->channel[0].num=0;
211- card->channel[1].offset = 0;
212- card->channel[1].port = 0x10;
213- card->channel[1].num=1;
214- card->channel[2].offset = 0;
215- card->channel[2].port = 0x20;
216- card->channel[2].num=2;
217+
218+ if ((card->channel = pci_alloc_consistent(pci_dev,
219+ sizeof(struct i810_channel)*NR_HW_CH, &card->chandma)) == NULL) {
220+ printk(KERN_ERR "i810: cannot allocate channel DMA memory\n");
221+ goto out_mem;
222+ }
223+
224+ { /* We may dispose of this altogether some time soon, so... */
225+ struct i810_channel *cp = card->channel;
226+
227+ cp[0].offset = 0;
228+ cp[0].port = 0x00;
229+ cp[0].num = 0;
230+ cp[1].offset = 0;
231+ cp[1].port = 0x10;
232+ cp[1].num = 1;
233+ cp[2].offset = 0;
234+ cp[2].port = 0x20;
235+ cp[2].num = 2;
236+ }
237
238 /* claim our iospace and irq */
239 request_region(card->iobase, 64, card_names[pci_id->driver_data]);
240@@ -2958,8 +2991,7 @@
241 printk(KERN_ERR "i810_audio: unable to allocate irq %d\n", card->irq);
242 release_region(card->iobase, 64);
243 release_region(card->ac97base, 256);
244- kfree(card);
245- return -ENODEV;
246+ goto out_chan;
247 }
248
249 /* initialize AC97 codec and register /dev/mixer */
250@@ -2967,8 +2999,7 @@
251 release_region(card->iobase, 64);
252 release_region(card->ac97base, 256);
253 free_irq(card->irq, card);
254- kfree(card);
255- return -ENODEV;
256+ goto out_chan;
257 }
258 pci_set_drvdata(pci_dev, card);
259
260@@ -2989,11 +3020,17 @@
261 unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
262 kfree (card->ac97_codec[i]);
263 }
264- kfree(card);
265- return -ENODEV;
266+ goto out_chan;
267 }
268 card->initializing = 0;
269 return 0;
270+
271+ out_chan:
272+ pci_free_consistent(pci_dev, sizeof(struct i810_channel)*NR_HW_CH,
273+ card->channel, card->chandma);
274+ out_mem:
275+ kfree(card);
276+ return -ENODEV;
277 }
278
279 static void __devexit i810_remove(struct pci_dev *pci_dev)
280diff -u linux/drivers/sound.org/i810_audio.c linux/drivers/sound/i810_audio.c
281--- linux/drivers/sound.org/i810_audio.c 2002-09-03 12:24:46.000000000 +0200
282+++ linux/drivers/sound/i810_audio.c 2002-09-03 13:22:18.000000000 +0200
283@@ -1,3 +1,4 @@
284+
285 /*
286 * Intel i810 and friends ICH driver for Linux
287 * Alan Cox <alan@redhat.com>
288@@ -116,6 +117,9 @@
289 #ifndef PCI_DEVICE_ID_AMD_768_AUDIO
290 #define PCI_DEVICE_ID_AMD_768_AUDIO 0x7445
291 #endif
292+#ifndef PCI_DEVICE_ID_AMD_8111_AC97
293+#define PCI_DEVICE_ID_AMD_8111_AC97 0x746d
294+#endif
295
296 static int ftsodell=0;
297 static int strict_clocking=0;
298@@ -728,8 +736,6 @@
299 outb(0, card->iobase + PI_CR);
300 // wait for the card to acknowledge shutdown
301 while( inb(card->iobase + PI_CR) != 0 ) ;
302- // reset the dma engine now
303- outb(0x02, card->iobase + PI_CR);
304 // now clear any latent interrupt bits (like the halt bit)
305 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
306 outb( inb(card->iobase + PI_PICB), card->iobase + PI_PICB );
307@@ -780,8 +786,6 @@
308 outb(0, card->iobase + PO_CR);
309 // wait for the card to acknowledge shutdown
310 while( inb(card->iobase + PO_CR) != 0 ) ;
311- // reset the dma engine now
312- outb(0x02, card->iobase + PO_CR);
313 // now clear any latent interrupt bits (like the halt bit)
314 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
315 outb( inb(card->iobase + PO_PICB), card->iobase + PO_PICB );
316@@ -978,8 +982,9 @@
317 outl((u32)state->card->chandma +
318 c->num*sizeof(struct i810_channel),
319 state->card->iobase+c->port+OFF_BDBAR);
320- outb(0, state->card->iobase+c->port+OFF_CIV);
321- outb(0, state->card->iobase+c->port+OFF_LVI);
322+ // The next two lines aren't needed, the reset clears these to 0
323+ // outb(0, state->card->iobase+c->port+OFF_CIV);
324+ // outb(0, state->card->iobase+c->port+OFF_LVI);
325
326 spin_unlock_irqrestore(&state->card->lock, flags);
327
328@@ -1747,8 +1752,10 @@
329 outl((u32)state->card->chandma +
330 c->num*sizeof(struct i810_channel),
331 state->card->iobase+c->port+OFF_BDBAR);
332- outb(0, state->card->iobase+c->port+OFF_CIV);
333- outb(0, state->card->iobase+c->port+OFF_LVI);
334+ // The next two lines aren't needed since the DMA
335+ // reset clears out these registers
336+ // outb(0, state->card->iobase+c->port+OFF_CIV);
337+ // outb(0, state->card->iobase+c->port+OFF_LVI);
338 }
339
340 spin_unlock_irqrestore(&state->card->lock, flags);
341@@ -1889,13 +1896,13 @@
342
343 switch ( val ) {
344 case 2: /* 2 channels is always supported */
345- outl(i_glob_cnt & 0xcfffff,
346+ outl(i_glob_cnt & 0xffcfffff,
347 state->card->iobase + GLOB_CNT);
348 /* Do we need to change mixer settings???? */
349 break;
350 case 4: /* Supported on some chipsets, better check first */
351 if ( state->card->channels >= 4 ) {
352- outl((i_glob_cnt & 0xcfffff) | 0x100000,
353+ outl((i_glob_cnt & 0xffcfffff) | 0x100000,
354 state->card->iobase + GLOB_CNT);
355 /* Do we need to change mixer settings??? */
356 } else {
357@@ -1904,7 +1911,7 @@
358 break;
359 case 6: /* Supported on some chipsets, better check first */
360 if ( state->card->channels >= 6 ) {
361- outl((i_glob_cnt & 0xcfffff) | 0x200000,
362+ outl((i_glob_cnt & 0xffcfffff) | 0x200000,
363 state->card->iobase + GLOB_CNT);
364 /* Do we need to change mixer settings??? */
365 } else {
366@@ -2590,9 +2597,7 @@
367 i810_ac97_set(codec, AC97_POWER_CONTROL,
368 i810_ac97_get(codec, AC97_POWER_CONTROL) & ~0x7f00);
369 /* wait for analog ready */
370- for (i=10;
371- i && ((i810_ac97_get(codec, AC97_POWER_CONTROL) & 0xf) != 0xf);
372- i--)
373+ for (i=10; i && ((i810_ac97_get(codec, AC97_POWER_CONTROL) & 0xf) != 0xf); i--)
374 {
375 set_current_state(TASK_UNINTERRUPTIBLE);
376 schedule_timeout(HZ/20);
377@@ -2600,8 +2605,14 @@
378 return i;
379 }
380
381-/* if I knew what this did, I'd give it a better name */
382-static int i810_ac97_random_init_stuff(struct i810_card *card)
383+/**
384+ * i810_ac97_power_up_bus - bring up AC97 link
385+ * @card : ICH audio device to power up
386+ *
387+ * Bring up the ACLink AC97 codec bus
388+ */
389+
390+static int i810_ac97_power_up_bus(struct i810_card *card)
391 {
392 u32 reg = inl(card->iobase + GLOB_CNT);
393 int i;
394@@ -2612,8 +2623,13 @@
395 reg|=4; /* Warm */
396
397 reg&=~8; /* ACLink on */
398- outl(reg , card->iobase + GLOB_CNT);
399
400+ /* At this point we deassert AC_RESET # */
401+ outl(reg , card->iobase + GLOB_CNT);
402+
403+ /* We must now allow time for the Codec initialisation.
404+ 600mS is the specified time */
405+
406 for(i=0;i<10;i++)
407 {
408 if((inl(card->iobase+GLOB_CNT)&4)==0)
409@@ -2630,7 +2646,24 @@
410
411 set_current_state(TASK_UNINTERRUPTIBLE);
412 schedule_timeout(HZ/2);
413+
414+ /*
415+ * See if the primary codec comes ready. This must happen
416+ * before we start doing DMA stuff
417+ */
418+
419 reg = inl(card->iobase + GLOB_STA);
420+ if(!(reg & 0x100))
421+ {
422+ printk(KERN_INFO "i810_audio: Codec not ready.. wait.. ");
423+ set_current_state(TASK_UNINTERRUPTIBLE);
424+ schedule_timeout(HZ); /* actually 600mS by the spec */
425+ reg = inl(card->iobase + GLOB_STA);
426+ if(reg & 0x100)
427+ printk("OK\n");
428+ else
429+ printk("no response.\n");
430+ }
431 inw(card->ac97base);
432 return 1;
433 }
434@@ -2643,7 +2676,7 @@
435 u16 eid;
436 u32 reg;
437
438- if(!i810_ac97_random_init_stuff(card)) return 0;
439+ if(!i810_ac97_power_up_bus(card)) return 0;
440
441 /* Number of channels supported */
442 /* What about the codec? Just because the ICH supports */
443@@ -2721,7 +2754,7 @@
444 }
445
446 card->ac97_features = eid;
447-
448+
449 /* Now check the codec for useful features to make up for
450 the dumbness of the 810 hardware engine */
451
452@@ -2735,6 +2768,11 @@
453 }
454 }
455
456+ /* Turn on the amplifier */
457+
458+ codec->codec_write(codec, AC97_POWER_CONTROL,
459+ codec->codec_read(codec, AC97_POWER_CONTROL) & ~0x8000);
460+
461 /* Determine how many channels the codec(s) support */
462 /* - The primary codec always supports 2 */
463 /* - If the codec supports AMAP, surround DACs will */
464@@ -2849,7 +2887,10 @@
465 }
466 dmabuf->count = dmabuf->dmasize;
467 stop_dac(state);
468- outb(0,card->iobase+dmabuf->write_channel->port+OFF_CIV);
469+ // OFF_CIV is a readonly register on some chipsets. But, we
470+ // know it will be 0 anyway because prog_dmabuf() resets the
471+ // DMA hardware, which 0's out all the DMA registers
472+ // outb(0,card->iobase+dmabuf->write_channel->port+OFF_CIV);
473 outb(31,card->iobase+dmabuf->write_channel->port+OFF_LVI);
474 save_flags(flags);
475 cli();
476@@ -2860,7 +2901,7 @@
477 stop_dac(state);
478 restore_flags(flags);
479 i = new_offset - offset;
480-#ifdef DEBUG_INTERRUPTS
481+#ifdef DEBUG
482 printk("i810_audio: %d bytes in 50 milliseconds\n", i);
483 #endif
484 if(i == 0)
485@@ -3087,7 +3128,7 @@
486 hardware has to be more or less completely reinitialized from
487 scratch after an apm suspend. Works For Me. -dan */
488
489- i810_ac97_random_init_stuff(card);
490+ i810_ac97_power_up_bus(card);
491
492 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
493 struct ac97_codec *codec = card->ac97_codec[num_ac97];
This page took 0.208882 seconds and 4 git commands to generate.