On Fri, Jan 10, 2003 at 09:03:11AM +0100, Björn Fischer wrote: >... > 00:11.5 Multimedia audio controller: VIA Technologies, Inc. VT8233 AC97 Audio >Controller (rev 50) >...
Das Modul heisst via82cxxx_audio, du brauchst aber entweder Kernel 2.4.21-pre3 oder 2.4.20 mit dem untenstehenden Patch. Gruss Adrian --- linux-2.4.20/drivers/sound/via82cxxx_audio.c 2002-08-03 00:39:44.000000000 +0000 +++ linux-2.4.21-pre3/drivers/sound/via82cxxx_audio.c 2003-01-06 21:18:24.000000000 ++0000 @@ -2,17 +2,20 @@ * Support for VIA 82Cxxx Audio Codecs * Copyright 1999,2000 Jeff Garzik * + * Updated to support the VIA 8233/8235 audio subsystem + * Alan Cox <[EMAIL PROTECTED]> (C) Copyright 2002 Red Hat Inc + * * Distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2. * See the "COPYING" file distributed with this software for more info. + * NO WARRANTY * * For a list of known bugs (errata) and documentation, * see via-audio.pdf in linux/Documentation/DocBook. * If this documentation does not exist, run "make pdfdocs". - * */ -#define VIA_VERSION "1.9.1" +#define VIA_VERSION "1.9.1-ac2" #include <linux/config.h> @@ -117,7 +120,10 @@ #define VIA_PCM_STATUS 0x00 #define VIA_PCM_CONTROL 0x01 #define VIA_PCM_TYPE 0x02 +#define VIA_PCM_LEFTVOL 0x02 +#define VIA_PCM_RIGHTVOL 0x03 #define VIA_PCM_TABLE_ADDR 0x04 +#define VIA_PCM_STOPRATE 0x08 /* 8233+ */ #define VIA_PCM_BLOCK_COUNT 0x0C /* XXX unused DMA channel for FM PCM data */ @@ -126,6 +132,12 @@ #define VIA_BASE0_FM_OUT_CHAN_CTRL 0x21 #define VIA_BASE0_FM_OUT_CHAN_TYPE 0x22 +/* Six channel audio output on 8233 */ +#define VIA_BASE0_MULTI_OUT_CHAN 0x40 +#define VIA_BASE0_MULTI_OUT_CHAN_STATUS 0x40 +#define VIA_BASE0_MULTI_OUT_CHAN_CTRL 0x41 +#define VIA_BASE0_MULTI_OUT_CHAN_TYPE 0x42 + #define VIA_BASE0_AC97_CTRL 0x80 #define VIA_BASE0_SGD_STATUS_SHADOW 0x84 #define VIA_BASE0_GPI_INT_ENABLE 0x8C @@ -251,11 +263,15 @@ unsigned is_record : 1; unsigned is_mapped : 1; unsigned is_enabled : 1; + unsigned is_multi: 1; /* 8233 6 channel */ u8 pcm_fmt; /* VIA_PCM_FMT_xxx */ + u8 channels; /* Channel count */ unsigned rate; /* sample rate */ unsigned int frag_size; unsigned int frag_number; + + unsigned char intmask; volatile struct via_sgd_table *sgtable; dma_addr_t sgt_handle; @@ -281,6 +297,9 @@ int dev_dsp; /* /dev/dsp index from register_sound_dsp() */ unsigned rev_h : 1; + unsigned legacy: 1; /* Has legacy ports */ + unsigned intmask: 1; /* Needs int bits */ + unsigned sixchannel: 1; /* 8233/35 with 6 channel support */ int locked_rate : 1; @@ -353,7 +372,9 @@ static struct pci_device_id via_pci_tbl[] __initdata = { { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, - PCI_ANY_ID, PCI_ANY_ID, }, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, { 0, } }; MODULE_DEVICE_TABLE(pci,via_pci_tbl); @@ -427,7 +448,13 @@ static inline void sg_begin (struct via_channel *chan) { - outb (VIA_SGD_START, chan->iobase + VIA_PCM_CONTROL); + DPRINTK("Start with intmask %d\n", chan->intmask); + DPRINTK("About to start from %d to %d\n", + inl(chan->iobase + VIA_PCM_BLOCK_COUNT), + inb(chan->iobase + VIA_PCM_STOPRATE + 3)); + outb (VIA_SGD_START|chan->intmask, chan->iobase + VIA_PCM_CONTROL); + DPRINTK("Status is now %02X\n", inb(chan->iobase + VIA_PCM_STATUS)); + DPRINTK("Control is now %02X\n", inb(chan->iobase + VIA_PCM_CONTROL)); } @@ -443,6 +470,10 @@ return 0; } +static int via_sg_offset(struct via_channel *chan) +{ + return inl (chan->iobase + VIA_PCM_BLOCK_COUNT) & 0x00FFFFFF; +} /**************************************************************** * @@ -506,6 +537,8 @@ via_chan_stop (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN); via_chan_stop (card->baseaddr + VIA_BASE0_PCM_IN_CHAN); via_chan_stop (card->baseaddr + VIA_BASE0_FM_OUT_CHAN); + if(card->sixchannel) + via_chan_stop (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN); /* * clear any existing stops / flags (sanity check mainly) @@ -513,6 +546,8 @@ via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN); via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_IN_CHAN); via_chan_status_clear (card->baseaddr + VIA_BASE0_FM_OUT_CHAN); + if(card->sixchannel) + via_chan_status_clear (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN); /* * clear any enabled interrupt bits @@ -532,6 +567,14 @@ if (tmp != new_tmp) outb (0, card->baseaddr + VIA_BASE0_FM_OUT_CHAN_TYPE); + if(card->sixchannel) + { + tmp = inb (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN_TYPE); + new_tmp = tmp & +~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL); + if (tmp != new_tmp) + outb (0, card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN_TYPE); + } + udelay(10); /* @@ -627,9 +670,19 @@ { memset (chan, 0, sizeof (*chan)); + if(card->intmask) + chan->intmask = 0x23; /* Turn on the IRQ bits */ + if (chan == &card->ch_out) { chan->name = "PCM-OUT"; - chan->iobase = card->baseaddr + VIA_BASE0_PCM_OUT_CHAN; + if(card->sixchannel) + { + chan->iobase = card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN; + chan->is_multi = 1; + DPRINTK("Using multichannel for pcm out\n"); + } + else + chan->iobase = card->baseaddr + VIA_BASE0_PCM_OUT_CHAN; } else if (chan == &card->ch_in) { chan->name = "PCM-IN"; chan->iobase = card->baseaddr + VIA_BASE0_PCM_IN_CHAN; @@ -708,6 +761,11 @@ DPRINTK ("ENTER\n"); + + chan->intmask = 0; + if(card->intmask) + chan->intmask = 0x23; /* Turn on the IRQ bits */ + if (chan->sgtable != NULL) { DPRINTK ("EXIT\n"); return 0; @@ -778,6 +836,16 @@ outl (chan->sgt_handle, chan->iobase + VIA_PCM_TABLE_ADDR); udelay (20); via_ac97_wait_idle (card); + /* load no rate adaption, stereo 16bit, set up ring slots */ + if(card->sixchannel) + { + if(!chan->is_multi) + { + outl (0xFFFFF | (0x3 << 20) | (chan->frag_number << 24), +chan->iobase + VIA_PCM_STOPRATE); + udelay (20); + via_ac97_wait_idle (card); + } + } DPRINTK ("inl (0x%lX) = %x\n", chan->iobase + VIA_PCM_TABLE_ADDR, @@ -881,8 +949,11 @@ assert (chan != NULL); if (reset) + { /* reset to 8-bit mono mode */ chan->pcm_fmt = 0; + chan->channels = 1; + } /* enable interrupts on FLAG and EOL */ chan->pcm_fmt |= VIA_CHAN_TYPE_MASK; @@ -893,8 +964,83 @@ /* set interrupt select bits where applicable (PCM in & out channels) */ if (!chan->is_record) chan->pcm_fmt |= VIA_CHAN_TYPE_INT_SELECT; + + DPRINTK("SET FMT - %02x %02x\n", chan->intmask , chan->is_multi); + + if(chan->intmask) + { + u32 m; + + /* + * Channel 0x4 is up to 6 x 16bit and has to be + * programmed differently + */ + + if(chan->is_multi) + { + u8 c = 0; + + /* + * Load the type bit for num channels + * and 8/16bit + */ + + if(chan->pcm_fmt & VIA_PCM_FMT_16BIT) + c = 1 << 7; + if(chan->pcm_fmt & VIA_PCM_FMT_STEREO) + c |= (2<<4); + else + c |= (1<<4); + + outb(c, chan->iobase + VIA_PCM_TYPE); + + /* + * Set the channel steering + * Mono + * Channel 0 to slot 3 + * Channel 0 to slot 4 + * Stereo + * Channel 0 to slot 3 + * Channel 1 to slot 4 + */ + + switch(chan->channels) + { + case 1: + outl(0xFF000000 | (1<<0) | (1<<4) , +chan->iobase + VIA_PCM_STOPRATE); + break; + case 2: + outl(0xFF000000 | (1<<0) | (2<<4) , +chan->iobase + VIA_PCM_STOPRATE); + break; + case 4: + outl(0xFF000000 | (1<<0) | (2<<4) | (3<<8) | +(4<<12), chan->iobase + VIA_PCM_STOPRATE); + break; + case 6: + outl(0xFF000000 | (1<<0) | (2<<4) | (5<<8) | +(6<<12) | (3<<16) | (4<<20), chan->iobase + VIA_PCM_STOPRATE); + break; + } + } + else + { + /* + * New style, turn off channel volume + * control, set bits in the right register + */ + outb(0x0, chan->iobase + VIA_PCM_LEFTVOL); + outb(0x0, chan->iobase + VIA_PCM_RIGHTVOL); + + m = inl(chan->iobase + VIA_PCM_STOPRATE); + m &= ~(3<<20); + if(chan->pcm_fmt & VIA_PCM_FMT_STEREO) + m |= (1 << 20); + if(chan->pcm_fmt & VIA_PCM_FMT_16BIT) + m |= (1 << 21); + outl(m, chan->iobase + VIA_PCM_STOPRATE); + } + } + else + outb (chan->pcm_fmt, chan->iobase + VIA_PCM_TYPE); - outb (chan->pcm_fmt, chan->iobase + VIA_PCM_TYPE); DPRINTK ("EXIT, pcm_fmt = 0x%02X, reg = 0x%02X\n", chan->pcm_fmt, @@ -1035,15 +1181,25 @@ /* mono */ case 1: chan->pcm_fmt &= ~VIA_PCM_FMT_STEREO; + chan->channels = 1; via_chan_pcm_fmt (chan, 0); break; /* stereo */ case 2: chan->pcm_fmt |= VIA_PCM_FMT_STEREO; + chan->channels = 2; via_chan_pcm_fmt (chan, 0); break; + case 4: + case 6: + if(chan->is_multi) + { + chan->pcm_fmt |= VIA_PCM_FMT_STEREO; + chan->channels = val; + break; + } /* unknown */ default: printk (KERN_WARNING PFX "unknown number of channels\n"); @@ -1077,9 +1233,8 @@ DPRINTK ("\n"); - chan->frag_size = (VIA_DEFAULT_FRAG_TIME * chan->rate * - ((chan->pcm_fmt & VIA_PCM_FMT_STEREO) ? 2 : 1) * - ((chan->pcm_fmt & VIA_PCM_FMT_16BIT) ? 2 : 1)) / 1000 - 1; + chan->frag_size = (VIA_DEFAULT_FRAG_TIME * chan->rate * chan->channels + * ((chan->pcm_fmt & VIA_PCM_FMT_16BIT) ? 2 : 1)) / +1000 - 1; shift = 0; while (chan->frag_size) { @@ -1494,16 +1649,19 @@ udelay (100); } + if(card->legacy) + { #if 0 /* this breaks on K7M */ - /* disable legacy stuff */ - pci_write_config_byte (pdev, 0x42, 0x00); - udelay(10); + /* disable legacy stuff */ + pci_write_config_byte (pdev, 0x42, 0x00); + udelay(10); #endif - /* route FM trap to IRQ, disable FM trap */ - pci_write_config_byte (pdev, 0x48, 0x05); - udelay(10); - + /* route FM trap to IRQ, disable FM trap */ + pci_write_config_byte (pdev, 0x48, 0x05); + udelay(10); + } + /* disable all codec GPI interrupts */ outl (0, pci_resource_start (pdev, 0) + 0x8C); @@ -1553,7 +1711,9 @@ printk (KERN_ERR PFX "unable to reset AC97 codec, aborting\n"); goto err_out; } - + + mdelay(10); + if (ac97_probe_codec (&card->ac97) == 0) { printk (KERN_ERR PFX "unable to probe AC97 codec, aborting\n"); rc = -EIO; @@ -1730,6 +1890,22 @@ spin_unlock (&card->lock); } +static void via_new_interrupt(int irq, void *dev_id, struct pt_regs *regs) +{ + struct via_info *card = dev_id; + + /* + * goes away completely on UP + */ + spin_lock (&card->lock); + + via_intr_channel (&card->ch_out); + via_intr_channel (&card->ch_in); + via_intr_channel (&card->ch_fm); + + spin_unlock (&card->lock); +} + /** * via_interrupt_init - Initialize interrupt handling @@ -1757,18 +1933,32 @@ return -EIO; } - /* make sure FM irq is not routed to us */ - pci_read_config_byte (card->pdev, VIA_FM_NMI_CTRL, &tmp8); - if ((tmp8 & VIA_CR48_FM_TRAP_TO_NMI) == 0) { - tmp8 |= VIA_CR48_FM_TRAP_TO_NMI; - pci_write_config_byte (card->pdev, VIA_FM_NMI_CTRL, tmp8); + /* VIA requires this is done */ + pci_write_config_byte(card->pdev, PCI_INTERRUPT_LINE, card->pdev->irq); + + if(card->legacy) + { + /* make sure FM irq is not routed to us */ + pci_read_config_byte (card->pdev, VIA_FM_NMI_CTRL, &tmp8); + if ((tmp8 & VIA_CR48_FM_TRAP_TO_NMI) == 0) { + tmp8 |= VIA_CR48_FM_TRAP_TO_NMI; + pci_write_config_byte (card->pdev, VIA_FM_NMI_CTRL, tmp8); + } + if (request_irq (card->pdev->irq, via_interrupt, SA_SHIRQ, +VIA_MODULE_NAME, card)) { + printk (KERN_ERR PFX "unable to obtain IRQ %d, aborting\n", + card->pdev->irq); + DPRINTK ("EXIT, returning -EBUSY\n"); + return -EBUSY; + } } - - if (request_irq (card->pdev->irq, via_interrupt, SA_SHIRQ, VIA_MODULE_NAME, card)) { - printk (KERN_ERR PFX "unable to obtain IRQ %d, aborting\n", - card->pdev->irq); - DPRINTK ("EXIT, returning -EBUSY\n"); - return -EBUSY; + else + { + if (request_irq (card->pdev->irq, via_new_interrupt, SA_SHIRQ, +VIA_MODULE_NAME, card)) { + printk (KERN_ERR PFX "unable to obtain IRQ %d, aborting\n", + card->pdev->irq); + DPRINTK ("EXIT, returning -EBUSY\n"); + return -EBUSY; + } } DPRINTK ("EXIT, returning 0\n"); @@ -1803,11 +1993,14 @@ assert (card != NULL); - /* turn off legacy features, if not already */ - pci_read_config_byte (card->pdev, VIA_FUNC_ENABLE, &tmp8); - if (tmp8 & (VIA_CR42_SB_ENABLE | VIA_CR42_FM_ENABLE)) { - tmp8 &= ~(VIA_CR42_SB_ENABLE | VIA_CR42_FM_ENABLE); - pci_write_config_byte (card->pdev, VIA_FUNC_ENABLE, tmp8); + if(card->legacy) + { + /* turn off legacy features, if not already */ + pci_read_config_byte (card->pdev, VIA_FUNC_ENABLE, &tmp8); + if (tmp8 & (VIA_CR42_SB_ENABLE | VIA_CR42_FM_ENABLE)) { + tmp8 &= ~(VIA_CR42_SB_ENABLE | VIA_CR42_FM_ENABLE); + pci_write_config_byte (card->pdev, VIA_FUNC_ENABLE, tmp8); + } } via_stop_everything (card); @@ -2120,7 +2313,6 @@ file, buffer, count, ppos ? ((unsigned long)*ppos) : 0); assert (file != NULL); - assert (buffer != NULL); card = file->private_data; assert (card != NULL); @@ -2278,11 +2470,12 @@ DPRINTK ("Flushed block %u, sw_ptr now %u, n_frags now %d\n", n, chan->sw_ptr, atomic_read (&chan->n_frags)); - DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n", + DPRINTK ("regs==S=%02X C=%02X TP=%02X BP=%08X RT=%08X SG=%08X CC=%08X +SS=%08X\n", inb (card->baseaddr + 0x00), inb (card->baseaddr + 0x01), inb (card->baseaddr + 0x02), inl (card->baseaddr + 0x04), + inl (card->baseaddr + 0x08), inl (card->baseaddr + 0x0C), inl (card->baseaddr + 0x80), inl (card->baseaddr + 0x84)); @@ -2305,7 +2498,6 @@ file, buffer, count, ppos ? ((unsigned long)*ppos) : 0); assert (file != NULL); - assert (buffer != NULL); card = file->private_data; assert (card != NULL); @@ -2558,7 +2750,7 @@ if (chan->is_active) { unsigned long extra; info.ptr = atomic_read (&chan->hw_ptr) * chan->frag_size; - extra = chan->frag_size - inl (chan->iobase + VIA_PCM_BLOCK_COUNT); + extra = chan->frag_size - via_sg_offset(chan); info.ptr += extra; info.bytes += extra; } else { @@ -2679,7 +2871,7 @@ rc = put_user (val, (int *)arg); break; - /* query or set number of channels (1=mono, 2=stereo) */ + /* query or set number of channels (1=mono, 2=stereo, 4/6 for multichannel) */ case SNDCTL_DSP_CHANNELS: if (get_user(val, (int *)arg)) { rc = -EFAULT; @@ -2700,11 +2892,10 @@ val = rc; } else { - if ((rd && (card->ch_in.pcm_fmt & VIA_PCM_FMT_STEREO)) || - (wr && (card->ch_out.pcm_fmt & VIA_PCM_FMT_STEREO))) - val = 2; + if (rd) + val = card->ch_in.channels; else - val = 1; + val = card->ch_out.channels; } DPRINTK ("CHANNELS EXIT, returning %d\n", val); rc = put_user (val, (int *)arg); @@ -2864,10 +3055,11 @@ val = chan->frag_number - atomic_read (&chan->n_frags); + assert(val >= 0); + if (val > 0) { val *= chan->frag_size; - val -= chan->frag_size - - inl (chan->iobase + VIA_PCM_BLOCK_COUNT); + val -= chan->frag_size - via_sg_offset(chan); } val += chan->slop_len % chan->frag_size; } else @@ -3029,7 +3221,9 @@ /* why is this forced to 16-bit stereo in all drivers? */ chan->pcm_fmt = VIA_PCM_FMT_16BIT | VIA_PCM_FMT_STEREO; + chan->channels = 2; + // TO DO - use FIFO: via_capture_fifo(card, 1); via_chan_pcm_fmt (chan, 0); via_set_rate (&card->ac97, chan, 44100); } @@ -3044,6 +3238,7 @@ /* if in duplex mode make the recording and playback channels have the same settings */ chan->pcm_fmt = VIA_PCM_FMT_16BIT | VIA_PCM_FMT_STEREO; + chan->channels = 2; via_chan_pcm_fmt (chan, 0); via_set_rate (&card->ac97, chan, 44100); } else { @@ -3083,7 +3278,7 @@ if (file->f_mode & FMODE_WRITE) { rc = via_dsp_drain_playback (card, &card->ch_out, nonblock); - if (rc) + if (rc && rc != ERESTARTSYS) /* Nobody needs to know about ^C */ printk (KERN_DEBUG "via_audio: ignoring drain playback error %d\n", rc); via_chan_free (card, &card->ch_out); @@ -3122,11 +3317,12 @@ DPRINTK ("ENTER\n"); if (printed_version++ == 0) - printk (KERN_INFO "Via 686a audio driver " VIA_VERSION "\n"); + printk (KERN_INFO "Via 686a/8233/8235 audio driver " VIA_VERSION "\n"); rc = pci_enable_device (pdev); if (rc) goto err_out; + rc = pci_request_regions (pdev, "via82cxxx_audio"); if (rc) @@ -3158,7 +3354,15 @@ * which means it has a few extra features */ if (pci_resource_start (pdev, 2) > 0) card->rev_h = 1; - + + /* Overkill for now, but more flexible done right */ + + card->intmask = id->driver_data; + card->legacy = !card->intmask; + card->sixchannel = id->driver_data; + + if(card->sixchannel) + printk(KERN_INFO PFX "Six channel audio available\n"); if (pdev->irq < 1) { printk (KERN_ERR PFX "invalid PCI IRQ %d, aborting\n", pdev->irq); rc = -ENODEV; @@ -3171,6 +3375,8 @@ goto err_out_kfree; } + pci_set_master(pdev); + /* * init AC97 mixer and codec */ @@ -3214,26 +3420,29 @@ /* Disable by default */ card->midi_info.io_base = 0; - pci_read_config_byte (pdev, 0x42, &r42); - /* Disable MIDI interrupt */ - pci_write_config_byte (pdev, 0x42, r42 | VIA_CR42_MIDI_IRQMASK); - if (r42 & VIA_CR42_MIDI_ENABLE) + if(card->legacy) { - if (r42 & VIA_CR42_MIDI_PNP) /* Address selected by iobase 2 - not tested */ - card->midi_info.io_base = pci_resource_start (pdev, 2); - else /* Address selected by byte 0x43 */ + pci_read_config_byte (pdev, 0x42, &r42); + /* Disable MIDI interrupt */ + pci_write_config_byte (pdev, 0x42, r42 | VIA_CR42_MIDI_IRQMASK); + if (r42 & VIA_CR42_MIDI_ENABLE) { - u8 r43; - pci_read_config_byte (pdev, 0x43, &r43); - card->midi_info.io_base = 0x300 + ((r43 & 0x0c) << 2); - } + if (r42 & VIA_CR42_MIDI_PNP) /* Address selected by iobase 2 - +not tested */ + card->midi_info.io_base = pci_resource_start (pdev, 2); + else /* Address selected by byte 0x43 */ + { + u8 r43; + pci_read_config_byte (pdev, 0x43, &r43); + card->midi_info.io_base = 0x300 + ((r43 & 0x0c) << 2); + } - card->midi_info.irq = -pdev->irq; - if (probe_uart401(& card->midi_info, THIS_MODULE)) - { - card->midi_devc=midi_devs[card->midi_info.slots[4]]->devc; - pci_write_config_byte(pdev, 0x42, r42 & ~VIA_CR42_MIDI_IRQMASK); - printk("Enabled Via MIDI\n"); + card->midi_info.irq = -pdev->irq; + if (probe_uart401(& card->midi_info, THIS_MODULE)) + { + +card->midi_devc=midi_devs[card->midi_info.slots[4]]->devc; + pci_write_config_byte(pdev, 0x42, r42 & +~VIA_CR42_MIDI_IRQMASK); + printk("Enabled Via MIDI\n"); + } } } #endif -- Häufig gestellte Fragen und Antworten (FAQ): http://www.de.debian.org/debian-user-german-FAQ/ Zum AUSTRAGEN schicken Sie eine Mail an [EMAIL PROTECTED] mit dem Subject "unsubscribe". Probleme? Mail an [EMAIL PROTECTED] (engl)