diff options
Diffstat (limited to 'sound/oss/cs46xx.c')
-rw-r--r-- | sound/oss/cs46xx.c | 1272 |
1 files changed, 489 insertions, 783 deletions
diff --git a/sound/oss/cs46xx.c b/sound/oss/cs46xx.c index 53881bc91bb..994c71e986e 100644 --- a/sound/oss/cs46xx.c +++ b/sound/oss/cs46xx.c @@ -147,7 +147,7 @@ * that should be printed on any released driver. */ #if CSDEBUG -#define CS_DBGOUT(mask,level,x) if((cs_debuglevel >= (level)) && ((mask) & cs_debugmask)) {x;} +#define CS_DBGOUT(mask,level,x) if ((cs_debuglevel >= (level)) && ((mask) & cs_debugmask)) {x;} #else #define CS_DBGOUT(mask,level,x) #endif @@ -175,19 +175,19 @@ #define CS_IOCTL_CMD_RESUME 0x2 // resume #if CSDEBUG -static unsigned long cs_debuglevel=1; /* levels range from 1-9 */ +static unsigned long cs_debuglevel = 1; /* levels range from 1-9 */ module_param(cs_debuglevel, ulong, 0644); -static unsigned long cs_debugmask=CS_INIT | CS_ERROR; /* use CS_DBGOUT with various mask values */ +static unsigned long cs_debugmask = CS_INIT | CS_ERROR; /* use CS_DBGOUT with various mask values */ module_param(cs_debugmask, ulong, 0644); #endif static unsigned long hercules_egpio_disable; /* if non-zero set all EGPIO to 0 */ module_param(hercules_egpio_disable, ulong, 0); -static unsigned long initdelay=700; /* PM delay in millisecs */ +static unsigned long initdelay = 700; /* PM delay in millisecs */ module_param(initdelay, ulong, 0); -static unsigned long powerdown=-1; /* turn on/off powerdown processing in driver */ +static unsigned long powerdown = -1; /* turn on/off powerdown processing in driver */ module_param(powerdown, ulong, 0); #define DMABUF_DEFAULTORDER 3 -static unsigned long defaultorder=DMABUF_DEFAULTORDER; +static unsigned long defaultorder = DMABUF_DEFAULTORDER; module_param(defaultorder, ulong, 0); static int external_amp; @@ -200,8 +200,8 @@ module_param(thinkpad, bool, 0); * powerdown. also set thinkpad to 1 to disable powerdown, * but also to enable the clkrun functionality. */ -static unsigned cs_powerdown=1; -static unsigned cs_laptop_wait=1; +static unsigned cs_powerdown = 1; +static unsigned cs_laptop_wait = 1; /* An instance of the 4610 channel */ struct cs_channel @@ -319,7 +319,7 @@ struct cs_card { atomic_t mixer_use_cnt; /* PCI device stuff */ - struct pci_dev * pci_dev; + struct pci_dev *pci_dev; struct list_head list; unsigned int pctl, cctl; /* Hardware DMA flag sets */ @@ -384,7 +384,7 @@ struct cs_card { static int cs_open_mixdev(struct inode *inode, struct file *file); static int cs_release_mixdev(struct inode *inode, struct file *file); static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, - unsigned long arg); + unsigned long arg); static int cs_hardware_init(struct cs_card *card); static int cs46xx_powerup(struct cs_card *card, unsigned int type); static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspendflag); @@ -423,8 +423,7 @@ static void printioctl(unsigned int x) [SOUND_MIXER_VOLUME] = 9 /* Master Volume */ }; - switch(x) - { + switch (x) { case SOUND_MIXER_CS_GETDBGMASK: CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CS_GETDBGMASK: ") ); break; @@ -521,7 +520,6 @@ static void printioctl(unsigned int x) case SOUND_PCM_READ_FILTER: CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER: ") ); break; - case SOUND_MIXER_PRIVATE1: CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1: ") ); break; @@ -543,10 +541,8 @@ static void printioctl(unsigned int x) case SOUND_OLD_MIXER_INFO: CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO: ") ); break; - default: - switch (_IOC_NR(x)) - { + switch (_IOC_NR(x)) { case SOUND_MIXER_VOLUME: CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_VOLUME: ") ); break; @@ -579,14 +575,11 @@ static void printioctl(unsigned int x) break; default: i = _IOC_NR(x); - if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i])) - { + if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i])) { CS_DBGOUT(CS_IOCTL, 4, printk("UNKNOWN IOCTL: 0x%.8x NR=%d ",x,i) ); - } - else - { + } else { CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d ", - x,i) ); + x,i)); } break; } @@ -601,22 +594,22 @@ static void printioctl(unsigned int x) static void cs461x_poke(struct cs_card *codec, unsigned long reg, unsigned int val) { - writel(val, codec->ba1.idx[(reg >> 16) & 3]+(reg&0xffff)); + writel(val, codec->ba1.idx[(reg >> 16) & 3] + (reg & 0xffff)); } static unsigned int cs461x_peek(struct cs_card *codec, unsigned long reg) { - return readl(codec->ba1.idx[(reg >> 16) & 3]+(reg&0xffff)); + return readl(codec->ba1.idx[(reg >> 16) & 3] + (reg & 0xffff)); } static void cs461x_pokeBA0(struct cs_card *codec, unsigned long reg, unsigned int val) { - writel(val, codec->ba0+reg); + writel(val, codec->ba0 + reg); } static unsigned int cs461x_peekBA0(struct cs_card *codec, unsigned long reg) { - return readl(codec->ba0+reg); + return readl(codec->ba0 + reg); } @@ -625,26 +618,26 @@ static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 data); static struct cs_channel *cs_alloc_pcm_channel(struct cs_card *card) { - if(card->channel[1].used==1) + if (card->channel[1].used == 1) return NULL; - card->channel[1].used=1; - card->channel[1].num=1; + card->channel[1].used = 1; + card->channel[1].num = 1; return &card->channel[1]; } static struct cs_channel *cs_alloc_rec_pcm_channel(struct cs_card *card) { - if(card->channel[0].used==1) + if (card->channel[0].used == 1) return NULL; - card->channel[0].used=1; - card->channel[0].num=0; + card->channel[0].used = 1; + card->channel[0].num = 0; return &card->channel[0]; } static void cs_free_pcm_channel(struct cs_card *card, int channel) { card->channel[channel].state = NULL; - card->channel[channel].used=0; + card->channel[channel].used = 0; } /* @@ -655,15 +648,15 @@ static void cs_free_pcm_channel(struct cs_card *card, int channel) */ static void cs_set_divisor(struct dmabuf *dmabuf) { - if(dmabuf->type == CS_TYPE_DAC) + if (dmabuf->type == CS_TYPE_DAC) dmabuf->divisor = 1; - else if( !(dmabuf->fmt & CS_FMT_STEREO) && + else if (!(dmabuf->fmt & CS_FMT_STEREO) && (dmabuf->fmt & CS_FMT_16BIT)) dmabuf->divisor = 2; - else if( (dmabuf->fmt & CS_FMT_STEREO) && + else if ((dmabuf->fmt & CS_FMT_STEREO) && !(dmabuf->fmt & CS_FMT_16BIT)) dmabuf->divisor = 2; - else if( !(dmabuf->fmt & CS_FMT_STEREO) && + else if (!(dmabuf->fmt & CS_FMT_STEREO) && !(dmabuf->fmt & CS_FMT_16BIT)) dmabuf->divisor = 4; else @@ -680,13 +673,12 @@ static void cs_set_divisor(struct dmabuf *dmabuf) */ static void cs_mute(struct cs_card *card, int state) { - struct ac97_codec *dev=card->ac97_codec[0]; + struct ac97_codec *dev = card->ac97_codec[0]; CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: cs_mute()+ %s\n", - (state == CS_TRUE) ? "Muting" : "UnMuting") ); + (state == CS_TRUE) ? "Muting" : "UnMuting")); - if(state == CS_TRUE) - { + if (state == CS_TRUE) { /* * fix pops when powering up on thinkpads */ @@ -703,9 +695,7 @@ static void cs_mute(struct cs_card *card, int state) cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, 0x8000); cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, 0x8000); cs_ac97_set(dev, (u8)BA0_AC97_PCM_OUT_VOLUME, 0x8000); - } - else - { + } else { cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME, card->pm.u32AC97_master_volume); cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, card->pm.u32AC97_headphone_volume); cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, card->pm.u32AC97_master_volume_mono); @@ -757,7 +747,6 @@ static unsigned int cs_set_dac_rate(struct cs_state * state, unsigned int rate) /* * Fill in the SampleRateConverter control block. */ - spin_lock_irqsave(&state->card->lock, flags); cs461x_poke(state->card, BA1_PSRC, ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); @@ -770,7 +759,7 @@ static unsigned int cs_set_dac_rate(struct cs_state * state, unsigned int rate) } /* set recording sample rate */ -static unsigned int cs_set_adc_rate(struct cs_state * state, unsigned int rate) +static unsigned int cs_set_adc_rate(struct cs_state *state, unsigned int rate) { struct dmabuf *dmabuf = &state->dmabuf; struct cs_card *card = state->card; @@ -815,7 +804,6 @@ static unsigned int cs_set_adc_rate(struct cs_state * state, unsigned int rate) * dividend:remainder(ulOther / GOF_PER_SEC) * initialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out) */ - tmp1 = rate << 16; coeffIncr = tmp1 / 48000; tmp1 -= coeffIncr * 48000; @@ -891,7 +879,7 @@ static void cs_play_setup(struct cs_state *state) CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()+\n") ); cs461x_poke(card, BA1_PVOL, 0x80008000); - if(!dmabuf->SGok) + if (!dmabuf->SGok) cs461x_poke(card, BA1_PBA, virt_to_bus(dmabuf->pbuf)); Count = 4; @@ -899,16 +887,14 @@ static void cs_play_setup(struct cs_state *state) if ((dmabuf->fmt & CS_FMT_STEREO)) { playFormat &= ~DMA_RQ_C2_AC_MONO_TO_STEREO; Count *= 2; - } - else + } else playFormat |= DMA_RQ_C2_AC_MONO_TO_STEREO; if ((dmabuf->fmt & CS_FMT_16BIT)) { playFormat &= ~(DMA_RQ_C2_AC_8_TO_16_BIT | DMA_RQ_C2_AC_SIGNED_CONVERT); Count *= 2; - } - else + } else playFormat |= (DMA_RQ_C2_AC_8_TO_16_BIT | DMA_RQ_C2_AC_SIGNED_CONVERT); @@ -919,7 +905,6 @@ static void cs_play_setup(struct cs_state *state) cs461x_poke(card, BA1_PDTC, tmp | --Count); CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()-\n") ); - } static struct InitStruct @@ -944,8 +929,7 @@ static void SetCaptureSPValues(struct cs_card *card) { unsigned i, offset; CS_DBGOUT(CS_FUNCTION, 8, printk("cs46xx: SetCaptureSPValues()+\n") ); - for(i=0; i<sizeof(InitArray)/sizeof(struct InitStruct); i++) - { + for (i = 0; i < sizeof(InitArray) / sizeof(struct InitStruct); i++) { offset = InitArray[i].off*4; /* 8bit to 32bit offset value */ cs461x_poke(card, offset, InitArray[i].val ); } @@ -957,8 +941,8 @@ static void cs_rec_setup(struct cs_state *state) { struct cs_card *card = state->card; struct dmabuf *dmabuf = &state->dmabuf; - CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_rec_setup()+\n") ); + CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_rec_setup()+\n")); SetCaptureSPValues(card); /* @@ -994,14 +978,11 @@ static inline unsigned cs_get_dma_addr(struct cs_state *state) /* * granularity is byte boundary, good part. */ - if(dmabuf->enable & DAC_RUNNING) - { + if (dmabuf->enable & DAC_RUNNING) offset = cs461x_peek(state->card, BA1_PBA); - } else /* ADC_RUNNING must be set */ - { offset = cs461x_peek(state->card, BA1_CBA); - } + CS_DBGOUT(CS_PARMS | CS_FUNCTION, 9, printk("cs46xx: cs_get_dma_addr() %d\n",offset) ); offset = (u32)bus_to_virt((unsigned long)offset) - (u32)dmabuf->rawbuf; @@ -1015,8 +996,7 @@ static void resync_dma_ptrs(struct cs_state *state) struct dmabuf *dmabuf; CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: resync_dma_ptrs()+ \n") ); - if(state) - { + if (state) { dmabuf = &state->dmabuf; dmabuf->hwptr=dmabuf->swptr = 0; dmabuf->pringbuf = 0; @@ -1149,13 +1129,13 @@ static int alloc_dmabuf(struct cs_state *state) /* * check for order within limits, but do not overwrite value. */ - if((defaultorder > 1) && (defaultorder < 12)) + if ((defaultorder > 1) && (defaultorder < 12)) df = defaultorder; else df = 2; for (order = df; order >= DMABUF_MINORDER; order--) - if ( (rawbuf = (void *) pci_alloc_consistent( + if ((rawbuf = (void *)pci_alloc_consistent( card->pci_dev, PAGE_SIZE << order, &dmabuf->dmaaddr))) break; if (!rawbuf) { @@ -1181,8 +1161,7 @@ static int alloc_dmabuf(struct cs_state *state) /* * only allocate the conversion buffer for the ADC */ - if(dmabuf->type == CS_TYPE_DAC) - { + if (dmabuf->type == CS_TYPE_DAC) { dmabuf->tmpbuff = NULL; dmabuf->buforder_tmpbuff = 0; return 0; @@ -1258,8 +1237,7 @@ static int __prog_dmabuf(struct cs_state *state) /* * check for CAPTURE and use only non-sg for initial release */ - if(dmabuf->type == CS_TYPE_ADC) - { + if (dmabuf->type == CS_TYPE_ADC) { CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf() ADC\n")); /* * add in non-sg support for capture. @@ -1313,9 +1291,7 @@ static int __prog_dmabuf(struct cs_state *state) CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- 0 \n")); return 0; - } - else if (dmabuf->type == CS_TYPE_DAC) - { + } else if (dmabuf->type == CS_TYPE_DAC) { /* * Must be DAC */ @@ -1337,8 +1313,7 @@ static int __prog_dmabuf(struct cs_state *state) allocated_pages = 1 << dmabuf->buforder; allocated_bytes = allocated_pages*PAGE_SIZE; - if(allocated_pages < 2) - { + if (allocated_pages < 2) { CS_DBGOUT(CS_FUNCTION, 4, printk( "cs46xx: prog_dmabuf() Error: allocated_pages too small (%d)\n", (unsigned)allocated_pages)); @@ -1353,14 +1328,14 @@ static int __prog_dmabuf(struct cs_state *state) /* Set up S/G variables. */ *ptmp = virt_to_bus(dmabuf->rawbuf); - *(ptmp+1) = 0x00000008; - for(tmp1= 1; tmp1 < nSGpages; tmp1++) { - *(ptmp+2*tmp1) = virt_to_bus( (dmabuf->rawbuf)+4096*tmp1); - if( tmp1 == nSGpages-1) + *(ptmp + 1) = 0x00000008; + for (tmp1 = 1; tmp1 < nSGpages; tmp1++) { + *(ptmp + 2 * tmp1) = virt_to_bus((dmabuf->rawbuf) + 4096 * tmp1); + if (tmp1 == nSGpages - 1) tmp2 = 0xbfff0000; else - tmp2 = 0x80000000+8*(tmp1+1); - *(ptmp+2*tmp1+1) = tmp2; + tmp2 = 0x80000000 + 8 * (tmp1 + 1); + *(ptmp + 2 * tmp1 + 1) = tmp2; } SGarray[0] = 0x82c0200d; SGarray[1] = 0xffff0000; @@ -1368,18 +1343,17 @@ static int __prog_dmabuf(struct cs_state *state) SGarray[3] = 0x00010600; SGarray[4] = *(ptmp+2); SGarray[5] = 0x80000010; - SGarray[6] = *ptmp; - SGarray[7] = *(ptmp+2); - SGarray[8] = (virt_to_bus(dmabuf->pbuf) & 0xffff000) | 0x10; - - if (dmabuf->SGok) { - dmabuf->numfrag = nSGpages; - dmabuf->fragsize = 4096; - dmabuf->fragsamples = 4096 >> sample_shift[dmabuf->fmt]; - dmabuf->fragshift = 12; - dmabuf->dmasize = dmabuf->numfrag*4096; - } - else { + SGarray[6] = *ptmp; + SGarray[7] = *(ptmp+2); + SGarray[8] = (virt_to_bus(dmabuf->pbuf) & 0xffff000) | 0x10; + + if (dmabuf->SGok) { + dmabuf->numfrag = nSGpages; + dmabuf->fragsize = 4096; + dmabuf->fragsamples = 4096 >> sample_shift[dmabuf->fmt]; + dmabuf->fragshift = 12; + dmabuf->dmasize = dmabuf->numfrag * 4096; + } else { SGarray[0] = 0xf2c0000f; SGarray[1] = 0x00000200; SGarray[2] = 0; @@ -1391,8 +1365,8 @@ static int __prog_dmabuf(struct cs_state *state) dmabuf->dmasize = 4096; dmabuf->fragshift = 11; } - for(tmp1 = 0; tmp1 < sizeof(SGarray)/4; tmp1++) - cs461x_poke( state->card, BA1_PDTC+tmp1*4, SGarray[tmp1]); + for (tmp1 = 0; tmp1 < sizeof(SGarray) / 4; tmp1++) + cs461x_poke(state->card, BA1_PDTC+tmp1 * 4, SGarray[tmp1]); memset(dmabuf->rawbuf, (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, dmabuf->dmasize); @@ -1416,9 +1390,7 @@ static int __prog_dmabuf(struct cs_state *state) CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- \n")); return 0; - } - else - { + } else { CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- Invalid Type %d\n", dmabuf->type)); } @@ -1489,8 +1461,7 @@ static int drain_dac(struct cs_state *state, int nonblock) } remove_wait_queue(&dmabuf->wait, &wait); current->state = TASK_RUNNING; - if (signal_pending(current)) - { + if (signal_pending(current)) { CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: drain_dac()- -ERESTARTSYS\n")); /* * set to silence and let that clear the fifos. @@ -1514,8 +1485,7 @@ static void cs_update_ptr(struct cs_card *card, int wake) /* error handling and process wake up for ADC */ state = card->states[0]; - if(state) - { + if (state) { dmabuf = &state->dmabuf; if (dmabuf->enable & ADC_RUNNING) { /* update hardware pointer */ @@ -1531,12 +1501,10 @@ static void cs_update_ptr(struct cs_card *card, int wake) if (dmabuf->count > dmabuf->dmasize) dmabuf->count = dmabuf->dmasize; - if(dmabuf->mapped) - { + if (dmabuf->mapped) { if (wake && dmabuf->count >= (signed)dmabuf->fragsize) wake_up(&dmabuf->wait); - } else - { + } else { if (wake && dmabuf->count > 0) wake_up(&dmabuf->wait); } @@ -1547,8 +1515,7 @@ static void cs_update_ptr(struct cs_card *card, int wake) * Now the DAC */ state = card->states[1]; - if(state) - { + if (state) { dmabuf = &state->dmabuf; /* error handling and process wake up for DAC */ if (dmabuf->enable & DAC_RUNNING) { @@ -1570,7 +1537,7 @@ static void cs_update_ptr(struct cs_card *card, int wake) * in that, since dmasize is the buffer asked for * via mmap. */ - if( dmabuf->count > dmabuf->dmasize) + if (dmabuf->count > dmabuf->dmasize) dmabuf->count &= dmabuf->dmasize-1; } else { dmabuf->count -= diff; @@ -1578,13 +1545,10 @@ static void cs_update_ptr(struct cs_card *card, int wake) * backfill with silence and clear out the last * "diff" number of bytes. */ - if(hwptr >= diff) - { + if (hwptr >= diff) { memset(dmabuf->rawbuf + hwptr - diff, (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, diff); - } - else - { + } else { memset(dmabuf->rawbuf, (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, (unsigned)hwptr); @@ -1602,12 +1566,12 @@ static void cs_update_ptr(struct cs_card *card, int wake) * buffer underrun or buffer overrun, reset the * count of bytes written back to 0. */ - if(dmabuf->count < 0) - dmabuf->underrun=1; + if (dmabuf->count < 0) + dmabuf->underrun = 1; dmabuf->count = 0; dmabuf->error++; } - if (wake && dmabuf->count < (signed)dmabuf->dmasize/2) + if (wake && dmabuf->count < (signed)dmabuf->dmasize / 2) wake_up(&dmabuf->wait); } } @@ -1661,8 +1625,7 @@ static irqreturn_t cs_interrupt(int irq, void *dev_id, struct pt_regs *regs) status = cs461x_peekBA0(card, BA0_HISR); - if ((status & 0x7fffffff) == 0) - { + if ((status & 0x7fffffff) == 0) { cs461x_pokeBA0(card, BA0_HICR, HICR_CHGM|HICR_IEV); spin_unlock(&card->lock); return IRQ_HANDLED; /* Might be IRQ_NONE.. */ @@ -1671,15 +1634,14 @@ static irqreturn_t cs_interrupt(int irq, void *dev_id, struct pt_regs *regs) /* * check for playback or capture interrupt only */ - if( ((status & HISR_VC0) && playstate && playstate->dmabuf.ready) || - (((status & HISR_VC1) && recstate && recstate->dmabuf.ready)) ) - { + if (((status & HISR_VC0) && playstate && playstate->dmabuf.ready) || + (((status & HISR_VC1) && recstate && recstate->dmabuf.ready))) { CS_DBGOUT(CS_INTERRUPT, 8, printk( "cs46xx: cs_interrupt() interrupt bit(s) set (0x%x)\n",status)); cs_update_ptr(card, CS_TRUE); } - if( status & HISR_MIDI ) + if (status & HISR_MIDI) cs_handle_midi(card); /* clear 'em */ @@ -1694,7 +1656,7 @@ static irqreturn_t cs_interrupt(int irq, void *dev_id, struct pt_regs *regs) static ssize_t cs_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { - struct cs_card *card = (struct cs_card *)file->private_data; + struct cs_card *card = file->private_data; ssize_t ret; unsigned long flags; unsigned ptr; @@ -1737,7 +1699,7 @@ static ssize_t cs_midi_read(struct file *file, char __user *buffer, size_t count static ssize_t cs_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) { - struct cs_card *card = (struct cs_card *)file->private_data; + struct cs_card *card = file->private_data; ssize_t ret; unsigned long flags; unsigned ptr; @@ -1785,7 +1747,7 @@ static ssize_t cs_midi_write(struct file *file, const char __user *buffer, size_ static unsigned int cs_midi_poll(struct file *file, struct poll_table_struct *wait) { - struct cs_card *card = (struct cs_card *)file->private_data; + struct cs_card *card = file->private_data; unsigned long flags; unsigned int mask = 0; @@ -1810,12 +1772,11 @@ static unsigned int cs_midi_poll(struct file *file, struct poll_table_struct *wa static int cs_midi_open(struct inode *inode, struct file *file) { unsigned int minor = iminor(inode); - struct cs_card *card=NULL; + struct cs_card *card = NULL; unsigned long flags; struct list_head *entry; - list_for_each(entry, &cs46xx_devs) - { + list_for_each(entry, &cs46xx_devs) { card = list_entry(entry, struct cs_card, list); if (card->dev_midi == minor) break; @@ -1823,8 +1784,7 @@ static int cs_midi_open(struct inode *inode, struct file *file) if (entry == &cs46xx_devs) return -ENODEV; - if (!card) - { + if (!card) { CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO "cs46xx: cs46xx_midi_open(): Error - unable to find card struct\n")); return -ENODEV; @@ -1852,12 +1812,10 @@ static int cs_midi_open(struct inode *inode, struct file *file) cs461x_pokeBA0(card, BA0_MIDCR, 0x0000000f); /* Enable xmit, rcv. */ cs461x_pokeBA0(card, BA0_HICR, HICR_IEV | HICR_CHGM); /* Enable interrupts */ } - if (file->f_mode & FMODE_READ) { + if (file->f_mode & FMODE_READ) card->midi.ird = card->midi.iwr = card->midi.icnt = 0; - } - if (file->f_mode & FMODE_WRITE) { + if (file->f_mode & FMODE_WRITE) card->midi.ord = card->midi.owr = card->midi.ocnt = 0; - } spin_unlock_irqrestore(&card->midi.lock, flags); card->midi.open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE)); mutex_unlock(&card->midi.open_mutex); @@ -1867,7 +1825,7 @@ static int cs_midi_open(struct inode *inode, struct file *file) static int cs_midi_release(struct inode *inode, struct file *file) { - struct cs_card *card = (struct cs_card *)file->private_data; + struct cs_card *card = file->private_data; DECLARE_WAITQUEUE(wait, current); unsigned long flags; unsigned count, tmo; @@ -1933,11 +1891,10 @@ static /*const*/ struct file_operations cs_midi_fops = { static void CopySamples(char *dst, char *src, int count, unsigned fmt, struct dmabuf *dmabuf) { - s32 s32AudioSample; - s16 *psSrc=(s16 *)src; - s16 *psDst=(s16 *)dst; - u8 *pucDst=(u8 *)dst; + s16 *psSrc = (s16 *)src; + s16 *psDst = (s16 *)dst; + u8 *pucDst = (u8 *)dst; CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: CopySamples()+ ") ); CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO @@ -1947,34 +1904,29 @@ static void CopySamples(char *dst, char *src, int count, unsigned fmt, /* * See if the data should be output as 8-bit unsigned stereo. */ - if((fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) - { + if ((fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) { /* * Convert each 16-bit signed stereo sample to 8-bit unsigned * stereo using rounding. */ psSrc = (s16 *)src; - count = count/2; - while(count--) - { + count = count / 2; + while (count--) *(pucDst++) = (u8)(((s16)(*psSrc++) + (s16)0x8000) >> 8); - } } /* * See if the data should be output at 8-bit unsigned mono. */ - else if(!(fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) - { + else if (!(fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) { /* * Convert each 16-bit signed stereo sample to 8-bit unsigned * mono using averaging and rounding. */ psSrc = (s16 *)src; - count = count/2; - while(count--) - { - s32AudioSample = ((*psSrc)+(*(psSrc + 1)))/2 + (s32)0x80; - if(s32AudioSample > 0x7fff) + count = count / 2; + while (count--) { + s32AudioSample = ((*psSrc) + (*(psSrc + 1))) / 2 + (s32)0x80; + if (s32AudioSample > 0x7fff) s32AudioSample = 0x7fff; *(pucDst++) = (u8)(((s16)s32AudioSample + (s16)0x8000) >> 8); psSrc += 2; @@ -1983,17 +1935,15 @@ static void CopySamples(char *dst, char *src, int count, unsigned fmt, /* * See if the data should be output at 16-bit signed mono. */ - else if(!(fmt & CS_FMT_STEREO) && (fmt & CS_FMT_16BIT)) - { + else if (!(fmt & CS_FMT_STEREO) && (fmt & CS_FMT_16BIT)) { /* * Convert each 16-bit signed stereo sample to 16-bit signed * mono using averaging. */ psSrc = (s16 *)src; - count = count/2; - while(count--) - { - *(psDst++) = (s16)((*psSrc)+(*(psSrc + 1)))/2; + count = count / 2; + while (count--) { + *(psDst++) = (s16)((*psSrc) + (*(psSrc + 1))) / 2; psSrc += 2; } } @@ -2020,20 +1970,15 @@ static unsigned cs_copy_to_user( "cs_copy_to_user()+ fmt=0x%x cnt=%d dest=%p\n", dmabuf->fmt,(unsigned)cnt,dest) ); - if(cnt > dmabuf->dmasize) - { + if (cnt > dmabuf->dmasize) cnt = dmabuf->dmasize; - } - if(!cnt) - { + if (!cnt) { *copied = 0; return 0; } - if(dmabuf->divisor != 1) - { - if(!dmabuf->tmpbuff) - { - *copied = cnt/dmabuf->divisor; + if (dmabuf->divisor != 1) { + if (!dmabuf->tmpbuff) { + *copied = cnt / dmabuf->divisor; return 0; } @@ -2042,17 +1987,16 @@ static unsigned cs_copy_to_user( src = dmabuf->tmpbuff; cnt = cnt/dmabuf->divisor; } - if (copy_to_user(dest, src, cnt)) - { + if (copy_to_user(dest, src, cnt)) { CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_ERR "cs46xx: cs_copy_to_user()- fault dest=%p src=%p cnt=%d\n", - dest,src,cnt) ); + dest,src,cnt)); *copied = 0; return -EFAULT; } *copied = cnt; CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO - "cs46xx: cs_copy_to_user()- copied bytes is %d \n",cnt) ); + "cs46xx: cs_copy_to_user()- copied bytes is %d \n",cnt)); return 0; } @@ -2060,7 +2004,7 @@ static unsigned cs_copy_to_user( the user's buffer. it is filled by the dma machine and drained by this loop. */ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { - struct cs_card *card = (struct cs_card *) file->private_data; + struct cs_card *card = file->private_data; struct cs_state *state; DECLARE_WAITQUEUE(wait, current); struct dmabuf *dmabuf; @@ -2068,12 +2012,12 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof unsigned long flags; unsigned swptr; int cnt; - unsigned copied=0; + unsigned copied = 0; CS_DBGOUT(CS_WAVE_READ | CS_FUNCTION, 4, printk("cs46xx: cs_read()+ %zd\n",count) ); - state = (struct cs_state *)card->states[0]; - if(!state) + state = card->states[0]; + if (!state) return -ENODEV; dmabuf = &state->dmabuf; @@ -2088,11 +2032,11 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof add_wait_queue(&state->dmabuf.wait, &wait); while (count > 0) { - while(!(card->pm.flags & CS46XX_PM_IDLE)) - { + while (!(card->pm.flags & CS46XX_PM_IDLE)) { schedule(); if (signal_pending(current)) { - if(!ret) ret = -ERESTARTSYS; + if (!ret) + ret = -ERESTARTSYS; goto out; } } @@ -2112,19 +2056,20 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof recorded */ start_adc(state); if (file->f_flags & O_NONBLOCK) { - if (!ret) ret = -EAGAIN; + if (!ret) + ret = -EAGAIN; goto out; } mutex_unlock(&state->sem); schedule(); if (signal_pending(current)) { - if(!ret) ret = -ERESTARTSYS; + if (!ret) + ret = -ERESTARTSYS; goto out; } mutex_lock(&state->sem); - if (dmabuf->mapped) - { - if(!ret) + if (dmabuf->mapped) { + if (!ret) ret = -ENXIO; goto out; } @@ -2135,12 +2080,12 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof "_read() copy_to cnt=%d count=%zd ", cnt,count) ); CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO " .dmasize=%d .count=%d buffer=%p ret=%zd\n", - dmabuf->dmasize,dmabuf->count,buffer,ret) ); + dmabuf->dmasize,dmabuf->count,buffer,ret)); if (cs_copy_to_user(state, buffer, - (char *)dmabuf->rawbuf + swptr, cnt, &copied)) - { - if (!ret) ret = -EFAULT; + (char *)dmabuf->rawbuf + swptr, cnt, &copied)) { + if (!ret) + ret = -EFAULT; goto out; } swptr = (swptr + cnt) % dmabuf->dmasize; @@ -2167,7 +2112,7 @@ out2: the soundcard. it is drained by the dma machine and filled by this loop. */ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) { - struct cs_card *card = (struct cs_card *) file->private_data; + struct cs_card *card = file->private_data; struct cs_state *state; DECLARE_WAITQUEUE(wait, current); struct dmabuf *dmabuf; @@ -2178,16 +2123,15 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 4, printk("cs46xx: cs_write called, count = %zd\n", count) ); - state = (struct cs_state *)card->states[1]; - if(!state) + state = card->states[1]; + if (!state) return -ENODEV; if (!access_ok(VERIFY_READ, buffer, count)) return -EFAULT; dmabuf = &state->dmabuf; mutex_lock(&state->sem); - if (dmabuf->mapped) - { + if (dmabuf->mapped) { ret = -ENXIO; goto out; } @@ -2201,11 +2145,11 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou * check for PM events and underrun/overrun in the loop. */ while (count > 0) { - while(!(card->pm.flags & CS46XX_PM_IDLE)) - { + while (!(card->pm.flags & CS46XX_PM_IDLE)) { schedule(); if (signal_pending(current)) { - if(!ret) ret = -ERESTARTSYS; + if (!ret) + ret = -ERESTARTSYS; goto out; } } @@ -2216,8 +2160,7 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou dmabuf->count = 0; dmabuf->swptr = dmabuf->hwptr; } - if (dmabuf->underrun) - { + if (dmabuf->underrun) { dmabuf->underrun = 0; dmabuf->hwptr = cs_get_dma_addr(state); dmabuf->swptr = dmabuf->hwptr; @@ -2238,34 +2181,35 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou played */ start_dac(state); if (file->f_flags & O_NONBLOCK) { - if (!ret) ret = -EAGAIN; + if (!ret) + ret = -EAGAIN; goto out; } mutex_unlock(&state->sem); schedule(); if (signal_pending(current)) { - if(!ret) ret = -ERESTARTSYS; + if (!ret) + ret = -ERESTARTSYS; goto out; } mutex_lock(&state->sem); - if (dmabuf->mapped) - { - if(!ret) + if (dmabuf->mapped) { + if (!ret) ret = -ENXIO; goto out; } continue; } if (copy_from_user(dmabuf->rawbuf + swptr, buffer, cnt)) { - if (!ret) ret = -EFAULT; + if (!ret) + ret = -EFAULT; goto out; } spin_lock_irqsave(&state->card->lock, flags); swptr = (swptr + cnt) % dmabuf->dmasize; dmabuf->swptr = swptr; dmabuf->count += cnt; - if(dmabuf->count > dmabuf->dmasize) - { + if (dmabuf->count > dmabuf->dmasize) { CS_DBGOUT(CS_WAVE_WRITE | CS_ERROR, 2, printk( "cs46xx: cs_write() d->count > dmasize - resetting\n")); dmabuf->count = dmabuf->dmasize; @@ -2284,38 +2228,32 @@ out: set_current_state(TASK_RUNNING); CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 2, - printk("cs46xx: cs_write()- ret=%zd\n", ret) ); + printk("cs46xx: cs_write()- ret=%zd\n", ret)); return ret; } static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait) { - struct cs_card *card = (struct cs_card *)file->private_data; + struct cs_card *card = file->private_data; struct dmabuf *dmabuf; struct cs_state *state; - unsigned long flags; unsigned int mask = 0; CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_poll()+ \n")); - if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) - { + if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) { return -EINVAL; } - if (file->f_mode & FMODE_WRITE) - { + if (file->f_mode & FMODE_WRITE) { state = card->states[1]; - if(state) - { + if (state) { dmabuf = &state->dmabuf; poll_wait(file, &dmabuf->wait, wait); } } - if (file->f_mode & FMODE_READ) - { + if (file->f_mode & FMODE_READ) { state = card->states[0]; - if(state) - { + if (state) { dmabuf = &state->dmabuf; poll_wait(file, &dmabuf->wait, wait); } @@ -2325,8 +2263,7 @@ static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait) cs_update_ptr(card, CS_FALSE); if (file->f_mode & FMODE_READ) { state = card->states[0]; - if(state) - { + if (state) { dmabuf = &state->dmabuf; if (dmabuf->count >= (signed)dmabuf->fragsize) mask |= POLLIN | POLLRDNORM; @@ -2334,8 +2271,7 @@ static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait) } if (file->f_mode & FMODE_WRITE) { state = card->states[1]; - if(state) - { + if (state) { dmabuf = &state->dmabuf; if (dmabuf->mapped) { if (dmabuf->count >= (signed)dmabuf->fragsize) @@ -2364,7 +2300,7 @@ static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait) static int cs_mmap( |