via82cxxx_audio.c
来自「linux 内核源代码」· C语言 代码 · 共 2,515 行 · 第 1/5 页
C
2,515 行
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); DPRINTK ("EXIT, pcm_fmt = 0x%02X, reg = 0x%02X\n", chan->pcm_fmt, inb (chan->iobase + VIA_PCM_TYPE));}/** * via_chan_clear - Stop DMA channel operation, and reset pointers * @card: the chip to accessed * @chan: Channel to be cleared * * Call via_chan_stop to halt DMA operations, and then resets * all software pointers which track DMA operation. */static void via_chan_clear (struct via_info *card, struct via_channel *chan){ DPRINTK ("ENTER\n"); via_chan_stop (chan->iobase); via_chan_buffer_free(card, chan); chan->is_active = 0; chan->is_mapped = 0; chan->is_enabled = 1; chan->slop_len = 0; chan->sw_ptr = 0; chan->n_irqs = 0; atomic_set (&chan->hw_ptr, 0); DPRINTK ("EXIT\n");}/** * via_chan_set_speed - Set PCM sample rate for given channel * @card: Private info for specified board * @chan: Channel whose sample rate will be adjusted * @val: New sample rate, in Khz * * Helper function for the %SNDCTL_DSP_SPEED ioctl. OSS semantics * demand that all audio operations halt (if they are not already * halted) when the %SNDCTL_DSP_SPEED is given. * * This function halts all audio operations for the given channel * @chan, and then calls via_set_rate to set the audio hardware * to the new rate. */static int via_chan_set_speed (struct via_info *card, struct via_channel *chan, int val){ DPRINTK ("ENTER, requested rate = %d\n", val); via_chan_clear (card, chan); val = via_set_rate (card->ac97, chan, val); DPRINTK ("EXIT, returning %d\n", val); return val;}/** * via_chan_set_fmt - Set PCM sample size for given channel * @card: Private info for specified board * @chan: Channel whose sample size will be adjusted * @val: New sample size, use the %AFMT_xxx constants * * Helper function for the %SNDCTL_DSP_SETFMT ioctl. OSS semantics * demand that all audio operations halt (if they are not already * halted) when the %SNDCTL_DSP_SETFMT is given. * * This function halts all audio operations for the given channel * @chan, and then calls via_chan_pcm_fmt to set the audio hardware * to the new sample size, either 8-bit or 16-bit. */static int via_chan_set_fmt (struct via_info *card, struct via_channel *chan, int val){ DPRINTK ("ENTER, val=%s\n", val == AFMT_U8 ? "AFMT_U8" : val == AFMT_S16_LE ? "AFMT_S16_LE" : "unknown"); via_chan_clear (card, chan); assert (val != AFMT_QUERY); /* this case is handled elsewhere */ switch (val) { case AFMT_S16_LE: if ((chan->pcm_fmt & VIA_PCM_FMT_16BIT) == 0) { chan->pcm_fmt |= VIA_PCM_FMT_16BIT; via_chan_pcm_fmt (chan, 0); } break; case AFMT_U8: if (chan->pcm_fmt & VIA_PCM_FMT_16BIT) { chan->pcm_fmt &= ~VIA_PCM_FMT_16BIT; via_chan_pcm_fmt (chan, 0); } break; default: DPRINTK ("unknown AFMT: 0x%X\n", val); val = AFMT_S16_LE; } DPRINTK ("EXIT\n"); return val;}/** * via_chan_set_stereo - Enable or disable stereo for a DMA channel * @card: Private info for specified board * @chan: Channel whose stereo setting will be adjusted * @val: New sample size, use the %AFMT_xxx constants * * Helper function for the %SNDCTL_DSP_CHANNELS and %SNDCTL_DSP_STEREO ioctls. OSS semantics * demand that all audio operations halt (if they are not already * halted) when %SNDCTL_DSP_CHANNELS or SNDCTL_DSP_STEREO is given. * * This function halts all audio operations for the given channel * @chan, and then calls via_chan_pcm_fmt to set the audio hardware * to enable or disable stereo. */static int via_chan_set_stereo (struct via_info *card, struct via_channel *chan, int val){ DPRINTK ("ENTER, channels = %d\n", val); via_chan_clear (card, chan); switch (val) { /* 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: val = -EINVAL; break; } DPRINTK ("EXIT, returning %d\n", val); return val;}static int via_chan_set_buffering (struct via_info *card, struct via_channel *chan, int val){ int shift; DPRINTK ("ENTER\n"); /* in both cases the buffer cannot be changed */ if (chan->is_active || chan->is_mapped) { DPRINTK ("EXIT\n"); return -EINVAL; } /* called outside SETFRAGMENT */ /* set defaults or do nothing */ if (val < 0) { if (chan->frag_size && chan->frag_number) goto out; DPRINTK ("\n"); 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) { chan->frag_size >>= 1; shift++; } chan->frag_size = 1 << shift; chan->frag_number = (VIA_DEFAULT_BUFFER_TIME / VIA_DEFAULT_FRAG_TIME); DPRINTK ("setting default values %d %d\n", chan->frag_size, chan->frag_number); } else { chan->frag_size = 1 << (val & 0xFFFF); chan->frag_number = (val >> 16) & 0xFFFF; DPRINTK ("using user values %d %d\n", chan->frag_size, chan->frag_number); } /* quake3 wants frag_number to be a power of two */ shift = 0; while (chan->frag_number) { chan->frag_number >>= 1; shift++; } chan->frag_number = 1 << shift; if (chan->frag_size > VIA_MAX_FRAG_SIZE) chan->frag_size = VIA_MAX_FRAG_SIZE; else if (chan->frag_size < VIA_MIN_FRAG_SIZE) chan->frag_size = VIA_MIN_FRAG_SIZE; if (chan->frag_number < VIA_MIN_FRAG_NUMBER) chan->frag_number = VIA_MIN_FRAG_NUMBER; if (chan->frag_number > VIA_MAX_FRAG_NUMBER) chan->frag_number = VIA_MAX_FRAG_NUMBER; if ((chan->frag_number * chan->frag_size) / PAGE_SIZE > VIA_MAX_BUFFER_DMA_PAGES) chan->frag_number = (VIA_MAX_BUFFER_DMA_PAGES * PAGE_SIZE) / chan->frag_size;out: if (chan->is_record) atomic_set (&chan->n_frags, 0); else atomic_set (&chan->n_frags, chan->frag_number); DPRINTK ("EXIT\n"); return 0;}#ifdef VIA_CHAN_DUMP_BUFS/** * via_chan_dump_bufs - Display DMA table contents * @chan: Channel whose DMA table will be displayed * * Debugging function which displays the contents of the * scatter-gather DMA table for the given channel @chan. */static void via_chan_dump_bufs (struct via_channel *chan){ int i; for (i = 0; i < chan->frag_number; i++) { DPRINTK ("#%02d: addr=%x, count=%u, flag=%d, eol=%d\n", i, chan->sgtable[i].addr, chan->sgtable[i].count & 0x00FFFFFF, chan->sgtable[i].count & VIA_FLAG ? 1 : 0, chan->sgtable[i].count & VIA_EOL ? 1 : 0); } DPRINTK ("buf_in_use = %d, nextbuf = %d\n", atomic_read (&chan->buf_in_use), atomic_read (&chan->sw_ptr));}#endif /* VIA_CHAN_DUMP_BUFS *//** * via_chan_flush_frag - Flush partially-full playback buffer to hardware * @chan: Channel whose DMA table will be flushed * * Flushes partially-full playback buffer to hardware. */static void via_chan_flush_frag (struct via_channel *chan){ DPRINTK ("ENTER\n"); assert (chan->slop_len > 0); if (chan->sw_ptr == (chan->frag_number - 1)) chan->sw_ptr = 0; else chan->sw_ptr++; chan->slop_len = 0; assert (atomic_read (&chan->n_frags) > 0); atomic_dec (&chan->n_frags); DPRINTK ("EXIT\n");}/** * via_chan_maybe_start - Initiate audio hardware DMA operation * @chan: Channel whose DMA is to be started * * Initiate DMA operation, if the DMA engine for the given * channel @chan is not already active. */static inline void via_chan_maybe_start (struct via_channel *chan){ assert (chan->is_active == sg_active(chan->iobase)); DPRINTK ("MAYBE START %s\n", chan->name); if (!chan->is_active && chan->is_enabled) { chan->is_active = 1; sg_begin (chan); DPRINTK ("starting channel %s\n", chan->name); }}/**************************************************************** * * Interface to ac97-codec module * * *//** * via_ac97_wait_idle - Wait until AC97 codec is not busy * @card: Private info for specified board * * Sleep until the AC97 codec is no longer busy. * Returns the final value read from the SGD * register being polled. */static u8 via_ac97_wait_idle (struct via_info *card){ u8 tmp8; int counter = VIA_COUNTER_LIMIT; DPRINTK ("ENTER/EXIT\n"); assert (card != NULL); assert (card->pdev != NULL); do { udelay (15); tmp8 = inb (card->baseaddr + 0x83); } while ((tmp8 & VIA_CR83_BUSY) && (counter-- > 0)); if (tmp8 & VIA_CR83_BUSY) printk (KERN_WARNING PFX "timeout waiting on AC97 codec\n"); return tmp8;}/** * via_ac97_read_reg - Read AC97 standard register * @codec: Pointer to generic AC97 codec info * @reg: Index of AC97 register to be read * * Read the value of a single AC97 codec register, * as defined by the Intel AC97 specification. * * Defines the standard AC97 read-register operation * required by the kernel's ac97_codec interface. * * Returns the 16-bit value stored in the specified * register. */static u16 via_ac97_read_reg (struct ac97_codec *codec, u8 reg){ unsigned long data; struct via_info *card; int counter; DPRINTK ("ENTER\n"); assert (codec != NULL); assert (codec->private_data != NULL); card = codec->private_data; spin_lock(&card->ac97_lock); /* Every time we write to register 80 we cause a transaction. The only safe way to clear the valid bit is to write it at the same time as the command */ data = (reg << 16) | VIA_CR80_READ | VIA_CR80_VALID; outl (data, card->baseaddr + VIA_BASE0_AC97_CTRL); udelay (20); for (counter = VIA_COUNTER_LIMIT; counter > 0; counter--) { udelay (1); if ((((data = inl(card->baseaddr + VIA_BASE0_AC97_CTRL)) & (VIA_CR80_VALID|VIA_CR80_BUSY)) == VIA_CR80_VALID)) goto out; } printk (KERN_WARNING PFX "timeout while reading AC97 codec (0x%lX)\n", data); goto err_out;out: /* Once the valid bit has become set, we must wait a complete AC97 frame before the data has settled. */ udelay(25); data = (unsigned long) inl (card->baseaddr + VIA_BASE0_AC97_CTRL); outb (0x02, card->baseaddr + 0x83); if (((data & 0x007F0000) >> 16) == reg) { DPRINTK ("EXIT, success, data=0x%lx, retval=0x%lx\n", data, data & 0x0000FFFF); spin_unlock(&card->ac97_lock); return data & 0x0000FFFF; } printk (KERN_WARNING "via82cxxx_audio: not our index: reg=0x%x, newreg=0x%lx\n", reg, ((data & 0x007F0000) >> 16));err_out: spin_unlock(&card->ac97_lock); DPRINTK ("EXIT, returning 0\n"); return 0;}/** * via_ac97_write_reg - Write AC97 standard register * @codec: Pointer to generic AC97 codec info * @reg: Index of AC97 register to be written * @value: Value to be written to AC97 register * * Write the value of a single AC97 codec register, * as defined by the Intel AC97 specification. * * Defines the standard AC97 write-register operation * required by the kernel's ac97_codec interface. */static void via_ac97_write_reg (struct ac97_codec *codec, u8 reg, u16 value){ u32 data; struct via_info *card;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?