1 diff -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
5 #define INT_MASK (INT_SEC|INT_PRI|INT_MC|INT_PO|INT_PI|INT_MO|INT_NI|INT_GPI)
8 -#define DRIVER_VERSION "0.21"
9 +#define DRIVER_VERSION "0.22"
11 /* magic numbers to protect our data structures */
12 #define I810_CARD_MAGIC 0x5072696E /* "Prin" */
17 - struct i810_channel channel[3];
20 /* We keep i810 cards in a linked list */
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 */
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 );
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);
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 );
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);
67 static void start_dac(struct i810_state *state)
70 for(i=0;i<dmabuf->numfrag;i++)
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)
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);
89 if (dmabuf->enable & ADC_RUNNING)
92 - wake_up(&dmabuf->wait);
93 #ifdef DEBUG_INTERRUPTS
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);
107 @@ -1884,12 +1894,14 @@
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???? */
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??? */
124 @@ -1897,7 +1909,8 @@
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??? */
134 @@ -2415,6 +2428,9 @@
135 i810_set_spdif_output(state, AC97_EA_SPSA_3_4, spdif_locked);
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);
144 @@ -2674,7 +2690,10 @@
146 else if ( reg & 0x0100000 )
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);
156 @@ -2707,7 +2726,7 @@
157 codec->codec_write = i810_ac97_set;
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);
163 break; /* it didn't work */
165 @@ -2716,7 +2735,7 @@
167 /* Don't attempt to get eid until powerup is complete */
168 eid = i810_ac97_get(codec, AC97_EXTENDED_ID);
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 @@
186 dmabuf->count = dmabuf->dmasize;
188 + outb(0,card->iobase+dmabuf->write_channel->port+OFF_CIV);
189 outb(31,card->iobase+dmabuf->write_channel->port+OFF_LVI);
192 @@ -2871,10 +2894,9 @@
194 new_offset = i810_get_dma_addr(state, 0);
196 - outb(2,card->iobase+dmabuf->write_channel->port+OFF_CR);
197 restore_flags(flags);
198 i = new_offset - offset;
200 +#ifdef DEBUG_INTERRUPTS
201 printk("i810_audio: %d bytes in 50 milliseconds\n", i);
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;
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");
224 + { /* We may dispose of this altogether some time soon, so... */
225 + struct i810_channel *cp = card->channel;
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);
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);
258 pci_set_drvdata(pci_dev, card);
260 @@ -2989,11 +3020,17 @@
261 unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
262 kfree (card->ac97_codec[i]);
268 card->initializing = 0;
272 + pci_free_consistent(pci_dev, sizeof(struct i810_channel)*NR_HW_CH,
273 + card->channel, card->chandma);
279 static void __devexit i810_remove(struct pci_dev *pci_dev)
280 diff -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
286 * Intel i810 and friends ICH driver for Linux
287 * Alan Cox <alan@redhat.com>
289 #ifndef PCI_DEVICE_ID_AMD_768_AUDIO
290 #define PCI_DEVICE_ID_AMD_768_AUDIO 0x7445
292 +#ifndef PCI_DEVICE_ID_AMD_8111_AC97
293 +#define PCI_DEVICE_ID_AMD_8111_AC97 0x746d
296 static int ftsodell=0;
297 static int strict_clocking=0;
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 );
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 );
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);
326 spin_unlock_irqrestore(&state->card->lock, flags);
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);
340 spin_unlock_irqrestore(&state->card->lock, flags);
341 @@ -1889,13 +1896,13 @@
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???? */
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??? */
357 @@ -1904,7 +1911,7 @@
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??? */
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 */
371 - i && ((i810_ac97_get(codec, AC97_POWER_CONTROL) & 0xf) != 0xf);
373 + for (i=10; i && ((i810_ac97_get(codec, AC97_POWER_CONTROL) & 0xf) != 0xf); i--)
375 set_current_state(TASK_UNINTERRUPTIBLE);
376 schedule_timeout(HZ/20);
377 @@ -2600,8 +2605,14 @@
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)
384 + * i810_ac97_power_up_bus - bring up AC97 link
385 + * @card : ICH audio device to power up
387 + * Bring up the ACLink AC97 codec bus
390 +static int i810_ac97_power_up_bus(struct i810_card *card)
392 u32 reg = inl(card->iobase + GLOB_CNT);
394 @@ -2612,8 +2623,13 @@
397 reg&=~8; /* ACLink on */
398 - outl(reg , card->iobase + GLOB_CNT);
400 + /* At this point we deassert AC_RESET # */
401 + outl(reg , card->iobase + GLOB_CNT);
403 + /* We must now allow time for the Codec initialisation.
404 + 600mS is the specified time */
408 if((inl(card->iobase+GLOB_CNT)&4)==0)
409 @@ -2630,7 +2646,24 @@
411 set_current_state(TASK_UNINTERRUPTIBLE);
412 schedule_timeout(HZ/2);
415 + * See if the primary codec comes ready. This must happen
416 + * before we start doing DMA stuff
419 reg = inl(card->iobase + GLOB_STA);
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);
429 + printk("no response.\n");
434 @@ -2643,7 +2676,7 @@
438 - if(!i810_ac97_random_init_stuff(card)) return 0;
439 + if(!i810_ac97_power_up_bus(card)) return 0;
441 /* Number of channels supported */
442 /* What about the codec? Just because the ICH supports */
443 @@ -2721,7 +2754,7 @@
446 card->ac97_features = eid;
449 /* Now check the codec for useful features to make up for
450 the dumbness of the 810 hardware engine */
452 @@ -2735,6 +2768,11 @@
456 + /* Turn on the amplifier */
458 + codec->codec_write(codec, AC97_POWER_CONTROL,
459 + codec->codec_read(codec, AC97_POWER_CONTROL) & ~0x8000);
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 @@
466 dmabuf->count = dmabuf->dmasize;
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);
476 @@ -2860,7 +2901,7 @@
478 restore_flags(flags);
479 i = new_offset - offset;
480 -#ifdef DEBUG_INTERRUPTS
482 printk("i810_audio: %d bytes in 50 milliseconds\n", i);
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 */
489 - i810_ac97_random_init_stuff(card);
490 + i810_ac97_power_up_bus(card);
492 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
493 struct ac97_codec *codec = card->ac97_codec[num_ac97];