cs46xx.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:160k
- }
- return -ENODEV;
- case SNDCTL_DSP_GETISPACE:
- if (!(file->f_mode & FMODE_READ))
- return -EINVAL;
- state = (struct cs_state *)card->states[0];
- if(state)
- {
- dmabuf = &state->dmabuf;
- spin_lock_irqsave(&state->card->lock, flags);
- cs_update_ptr(card, CS_TRUE);
- abinfo.fragsize = dmabuf->fragsize/dmabuf->divisor;
- abinfo.bytes = dmabuf->count/dmabuf->divisor;
- abinfo.fragstotal = dmabuf->numfrag;
- abinfo.fragments = abinfo.bytes >> dmabuf->fragshift;
- spin_unlock_irqrestore(&state->card->lock, flags);
- return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
- }
- return -ENODEV;
- case SNDCTL_DSP_NONBLOCK:
- file->f_flags |= O_NONBLOCK;
- return 0;
- case SNDCTL_DSP_GETCAPS:
- return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP,
- (int *)arg);
- case SNDCTL_DSP_GETTRIGGER:
- val = 0;
- CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()+n") );
- if (file->f_mode & FMODE_WRITE)
- {
- state = (struct cs_state *)card->states[1];
- if(state)
- {
- dmabuf = &state->dmabuf;
- if(dmabuf->enable & DAC_RUNNING)
- val |= PCM_ENABLE_INPUT;
- }
- }
- if (file->f_mode & FMODE_READ)
- {
- if(state)
- {
- state = (struct cs_state *)card->states[0];
- dmabuf = &state->dmabuf;
- if(dmabuf->enable & ADC_RUNNING)
- val |= PCM_ENABLE_OUTPUT;
- }
- }
- CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()- val=0x%xn",val) );
- return put_user(val, (int *)arg);
- case SNDCTL_DSP_SETTRIGGER:
- if (get_user(val, (int *)arg))
- return -EFAULT;
- if (file->f_mode & FMODE_READ) {
- state = (struct cs_state *)card->states[0];
- if(state)
- {
- dmabuf = &state->dmabuf;
- if (val & PCM_ENABLE_INPUT) {
- if (!dmabuf->ready && (ret = prog_dmabuf(state)))
- return ret;
- start_adc(state);
- } else
- stop_adc(state);
- }
- }
- if (file->f_mode & FMODE_WRITE) {
- state = (struct cs_state *)card->states[1];
- if(state)
- {
- dmabuf = &state->dmabuf;
- if (val & PCM_ENABLE_OUTPUT) {
- if (!dmabuf->ready && (ret = prog_dmabuf(state)))
- return ret;
- start_dac(state);
- } else
- stop_dac(state);
- }
- }
- return 0;
- case SNDCTL_DSP_GETIPTR:
- if (!(file->f_mode & FMODE_READ))
- return -EINVAL;
- state = (struct cs_state *)card->states[0];
- if(state)
- {
- dmabuf = &state->dmabuf;
- spin_lock_irqsave(&state->card->lock, flags);
- cs_update_ptr(card, CS_TRUE);
- cinfo.bytes = dmabuf->total_bytes/dmabuf->divisor;
- cinfo.blocks = dmabuf->count/dmabuf->divisor >> dmabuf->fragshift;
- cinfo.ptr = dmabuf->hwptr/dmabuf->divisor;
- spin_unlock_irqrestore(&state->card->lock, flags);
- return copy_to_user((void *)arg, &cinfo, sizeof(cinfo));
- }
- return -ENODEV;
- case SNDCTL_DSP_GETOPTR:
- if (!(file->f_mode & FMODE_WRITE))
- return -EINVAL;
- state = (struct cs_state *)card->states[1];
- if(state)
- {
- dmabuf = &state->dmabuf;
- spin_lock_irqsave(&state->card->lock, flags);
- cs_update_ptr(card, CS_TRUE);
- cinfo.bytes = dmabuf->total_bytes;
- if (dmabuf->mapped)
- {
- cinfo.blocks = (cinfo.bytes >> dmabuf->fragshift)
- - dmabuf->blocks;
- CS_DBGOUT(CS_PARMS, 8,
- printk("total_bytes=%d blocks=%d dmabuf->blocks=%dn",
- cinfo.bytes,cinfo.blocks,dmabuf->blocks) );
- dmabuf->blocks = cinfo.bytes >> dmabuf->fragshift;
- }
- else
- {
- cinfo.blocks = dmabuf->count >> dmabuf->fragshift;
- }
- cinfo.ptr = dmabuf->hwptr;
- CS_DBGOUT(CS_PARMS, 4, printk(
- "cs46xx: GETOPTR bytes=%d blocks=%d ptr=%dn",
- cinfo.bytes,cinfo.blocks,cinfo.ptr) );
- spin_unlock_irqrestore(&state->card->lock, flags);
- return copy_to_user((void *)arg, &cinfo, sizeof(cinfo));
- }
- return -ENODEV;
- case SNDCTL_DSP_SETDUPLEX:
- return 0;
- case SNDCTL_DSP_GETODELAY:
- if (!(file->f_mode & FMODE_WRITE))
- return -EINVAL;
- state = (struct cs_state *)card->states[1];
- if(state)
- {
- dmabuf = &state->dmabuf;
- spin_lock_irqsave(&state->card->lock, flags);
- cs_update_ptr(card, CS_TRUE);
- val = dmabuf->count;
- spin_unlock_irqrestore(&state->card->lock, flags);
- }
- else
- val = 0;
- return put_user(val, (int *)arg);
- case SOUND_PCM_READ_RATE:
- if(file->f_mode & FMODE_READ)
- state = (struct cs_state *)card->states[0];
- else
- state = (struct cs_state *)card->states[1];
- if(state)
- {
- dmabuf = &state->dmabuf;
- return put_user(dmabuf->rate, (int *)arg);
- }
- return put_user(0, (int *)arg);
-
- case SOUND_PCM_READ_CHANNELS:
- if(file->f_mode & FMODE_READ)
- state = (struct cs_state *)card->states[0];
- else
- state = (struct cs_state *)card->states[1];
- if(state)
- {
- dmabuf = &state->dmabuf;
- return put_user((dmabuf->fmt & CS_FMT_STEREO) ? 2 : 1,
- (int *)arg);
- }
- return put_user(0, (int *)arg);
- case SOUND_PCM_READ_BITS:
- if(file->f_mode & FMODE_READ)
- state = (struct cs_state *)card->states[0];
- else
- state = (struct cs_state *)card->states[1];
- if(state)
- {
- dmabuf = &state->dmabuf;
- return put_user((dmabuf->fmt & CS_FMT_16BIT) ?
- AFMT_S16_LE : AFMT_U8, (int *)arg);
- }
- return put_user(0, (int *)arg);
- case SNDCTL_DSP_MAPINBUF:
- case SNDCTL_DSP_MAPOUTBUF:
- case SNDCTL_DSP_SETSYNCRO:
- case SOUND_PCM_WRITE_FILTER:
- case SOUND_PCM_READ_FILTER:
- return -EINVAL;
- }
- return -EINVAL;
- }
- /*
- * AMP control - null AMP
- */
-
- static void amp_none(struct cs_card *card, int change)
- {
- }
- /*
- * Crystal EAPD mode
- */
-
- static void amp_voyetra(struct cs_card *card, int change)
- {
- /* Manage the EAPD bit on the Crystal 4297
- and the Analog AD1885 */
-
- int old=card->amplifier;
-
- card->amplifier+=change;
- if(card->amplifier && !old)
- {
- /* Turn the EAPD amp on */
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL,
- cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) |
- 0x8000);
- }
- else if(old && !card->amplifier)
- {
- /* Turn the EAPD amp off */
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL,
- cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- ~0x8000);
- }
- }
-
- /*
- * Game Theatre XP card - EGPIO[2] is used to enable the external amp.
- */
-
- static void amp_hercules(struct cs_card *card, int change)
- {
- int old=card->amplifier;
- if(!card)
- {
- CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
- "cs46xx: amp_hercules() called before initialized.n"));
- return;
- }
- card->amplifier+=change;
- if( (card->amplifier && !old) && !(hercules_egpio_disable))
- {
- CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO
- "cs46xx: amp_hercules() external amp enabledn"));
- cs461x_pokeBA0(card, BA0_EGPIODR,
- EGPIODR_GPOE2); /* enable EGPIO2 output */
- cs461x_pokeBA0(card, BA0_EGPIOPTR,
- EGPIOPTR_GPPT2); /* open-drain on output */
- }
- else if(old && !card->amplifier)
- {
- CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO
- "cs46xx: amp_hercules() external amp disabledn"));
- cs461x_pokeBA0(card, BA0_EGPIODR, 0); /* disable */
- cs461x_pokeBA0(card, BA0_EGPIOPTR, 0); /* disable */
- }
- }
- /*
- * Handle the CLKRUN on a thinkpad. We must disable CLKRUN support
- * whenever we need to beat on the chip.
- *
- * The original idea and code for this hack comes from David Kaiser at
- * Linuxcare. Perhaps one day Crystal will document their chips well
- * enough to make them useful.
- */
-
- static void clkrun_hack(struct cs_card *card, int change)
- {
- struct pci_dev *acpi_dev;
- u16 control;
- u8 pp;
- unsigned long port;
- int old=card->active;
-
- card->active+=change;
-
- acpi_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
- if(acpi_dev == NULL)
- return; /* Not a thinkpad thats for sure */
- /* Find the control port */
- pci_read_config_byte(acpi_dev, 0x41, &pp);
- port=pp<<8;
- /* Read ACPI port */
- control=inw(port+0x10);
- /* Flip CLKRUN off while running */
- if(!card->active && old)
- {
- CS_DBGOUT(CS_PARMS , 9, printk( KERN_INFO
- "cs46xx: clkrun() enable clkrun - change=%d active=%dn",
- change,card->active));
- outw(control|0x2000, port+0x10);
- }
- else
- {
- /*
- * sometimes on a resume the bit is set, so always reset the bit.
- */
- CS_DBGOUT(CS_PARMS , 9, printk( KERN_INFO
- "cs46xx: clkrun() disable clkrun - change=%d active=%dn",
- change,card->active));
- outw(control&~0x2000, port+0x10);
- }
- }
-
- static int cs_open(struct inode *inode, struct file *file)
- {
- struct cs_card *card = (struct cs_card *)file->private_data;
- struct cs_state *state = NULL;
- struct dmabuf *dmabuf = NULL;
- struct list_head *entry;
- int minor = MINOR(inode->i_rdev);
- int ret=0;
- unsigned int tmp;
- CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()+ file=0x%x %s %sn",
- (unsigned)file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "",
- file->f_mode & FMODE_READ ? "FMODE_READ" : "") );
- list_for_each(entry, &cs46xx_devs)
- {
- card = list_entry(entry, struct cs_card, list);
- if (!((card->dev_audio ^ minor) & ~0xf))
- break;
- }
- if (entry == &cs46xx_devs)
- return -ENODEV;
- if (!card) {
- CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
- "cs46xx: cs_open(): Error - unable to find audio card structn"));
- return -ENODEV;
- }
- /*
- * hardcode state[0] for capture, [1] for playback
- */
- if(file->f_mode & FMODE_READ)
- {
- CS_DBGOUT(CS_WAVE_READ, 2, printk("cs46xx: cs_open() FMODE_READn") );
- if (card->states[0] == NULL) {
- state = card->states[0] = (struct cs_state *)
- kmalloc(sizeof(struct cs_state), GFP_KERNEL);
- if (state == NULL)
- return -ENOMEM;
- memset(state, 0, sizeof(struct cs_state));
- init_MUTEX(&state->sem);
- dmabuf = &state->dmabuf;
- dmabuf->pbuf = (void *)get_free_page(GFP_KERNEL | GFP_DMA);
- if(dmabuf->pbuf==NULL)
- {
- kfree(state);
- card->states[0]=NULL;
- return -ENOMEM;
- }
- }
- else
- {
- state = card->states[0];
- if(state->open_mode & FMODE_READ)
- return -EBUSY;
- }
- dmabuf->channel = card->alloc_rec_pcm_channel(card);
-
- if (dmabuf->channel == NULL) {
- kfree (card->states[0]);
- card->states[0] = NULL;;
- return -ENODEV;
- }
- /* Now turn on external AMP if needed */
- state->card = card;
- state->card->active_ctrl(state->card,1);
- state->card->amplifier_ctrl(state->card,1);
-
- if( (tmp = cs46xx_powerup(card, CS_POWER_ADC)) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs46xx_powerup of ADC failed (0x%x)n",tmp) );
- return -EIO;
- }
- dmabuf->channel->state = state;
- /* initialize the virtual channel */
- state->virt = 0;
- state->magic = CS_STATE_MAGIC;
- init_waitqueue_head(&dmabuf->wait);
- init_MUTEX(&state->open_sem);
- file->private_data = card;
- down(&state->open_sem);
- /* set default sample format. According to OSS Programmer's Guide /dev/dsp
- should be default to unsigned 8-bits, mono, with sample rate 8kHz and
- /dev/dspW will accept 16-bits sample */
- /* Default input is 8bit mono */
- dmabuf->fmt &= ~CS_FMT_MASK;
- dmabuf->type = CS_TYPE_ADC;
- dmabuf->ossfragshift = 0;
- dmabuf->ossmaxfrags = 0;
- dmabuf->subdivision = 0;
- cs_set_adc_rate(state, 8000);
- cs_set_divisor(dmabuf);
- state->open_mode |= FMODE_READ;
- up(&state->open_sem);
- }
- if(file->f_mode & FMODE_WRITE)
- {
- CS_DBGOUT(CS_OPEN, 2, printk("cs46xx: cs_open() FMODE_WRITEn") );
- if (card->states[1] == NULL) {
- state = card->states[1] = (struct cs_state *)
- kmalloc(sizeof(struct cs_state), GFP_KERNEL);
- if (state == NULL)
- return -ENOMEM;
- memset(state, 0, sizeof(struct cs_state));
- init_MUTEX(&state->sem);
- dmabuf = &state->dmabuf;
- dmabuf->pbuf = (void *)get_free_page(GFP_KERNEL | GFP_DMA);
- if(dmabuf->pbuf==NULL)
- {
- kfree(state);
- card->states[1]=NULL;
- return -ENOMEM;
- }
- }
- else
- {
- state = card->states[1];
- if(state->open_mode & FMODE_WRITE)
- return -EBUSY;
- }
- dmabuf->channel = card->alloc_pcm_channel(card);
-
- if (dmabuf->channel == NULL) {
- kfree (card->states[1]);
- card->states[1] = NULL;;
- return -ENODEV;
- }
- /* Now turn on external AMP if needed */
- state->card = card;
- state->card->active_ctrl(state->card,1);
- state->card->amplifier_ctrl(state->card,1);
- if( (tmp = cs46xx_powerup(card, CS_POWER_DAC)) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs46xx_powerup of DAC failed (0x%x)n",tmp) );
- return -EIO;
- }
-
- dmabuf->channel->state = state;
- /* initialize the virtual channel */
- state->virt = 1;
- state->magic = CS_STATE_MAGIC;
- init_waitqueue_head(&dmabuf->wait);
- init_MUTEX(&state->open_sem);
- file->private_data = card;
- down(&state->open_sem);
- /* set default sample format. According to OSS Programmer's Guide /dev/dsp
- should be default to unsigned 8-bits, mono, with sample rate 8kHz and
- /dev/dspW will accept 16-bits sample */
- /* Default output is 8bit mono. */
- dmabuf->fmt &= ~CS_FMT_MASK;
- dmabuf->type = CS_TYPE_DAC;
- dmabuf->ossfragshift = 0;
- dmabuf->ossmaxfrags = 0;
- dmabuf->subdivision = 0;
- cs_set_dac_rate(state, 8000);
- cs_set_divisor(dmabuf);
- state->open_mode |= FMODE_WRITE;
- up(&state->open_sem);
- if((ret = prog_dmabuf(state)))
- return ret;
- }
- MOD_INC_USE_COUNT; /* for 2.2 */
- CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()- 0n") );
- return 0;
- }
- static int cs_release(struct inode *inode, struct file *file)
- {
- struct cs_card *card = (struct cs_card *)file->private_data;
- struct dmabuf *dmabuf;
- struct cs_state *state;
- unsigned int tmp;
- CS_DBGOUT(CS_RELEASE | CS_FUNCTION, 2, printk("cs46xx: cs_release()+ file=0x%x %s %sn",
- (unsigned)file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "",
- file->f_mode & FMODE_READ ? "FMODE_READ" : "") );
- if (!(file->f_mode & (FMODE_WRITE | FMODE_READ)))
- {
- return -EINVAL;
- }
- state = card->states[1];
- if(state)
- {
- if ( (state->open_mode & FMODE_WRITE) & (file->f_mode & FMODE_WRITE) )
- {
- CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_WRITEn") );
- dmabuf = &state->dmabuf;
- cs_clear_tail(state);
- drain_dac(state, file->f_flags & O_NONBLOCK);
- /* stop DMA state machine and free DMA buffers/channels */
- down(&state->open_sem);
- stop_dac(state);
- dealloc_dmabuf(state);
- state->card->free_pcm_channel(state->card, dmabuf->channel->num);
- free_page((unsigned long)state->dmabuf.pbuf);
- /* we're covered by the open_sem */
- up(&state->open_sem);
- state->card->states[state->virt] = NULL;
- state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
- if( (tmp = cs461x_powerdown(card, CS_POWER_DAC, CS_FALSE )) )
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
- "cs46xx: cs_release_mixdev() powerdown DAC failure (0x%x)n",tmp) );
- }
- /* Now turn off external AMP if needed */
- state->card->amplifier_ctrl(state->card, -1);
- state->card->active_ctrl(state->card, -1);
- kfree(state);
- }
- }
- state = card->states[0];
- if(state)
- {
- if ( (state->open_mode & FMODE_READ) & (file->f_mode & FMODE_READ) )
- {
- CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_READn") );
- dmabuf = &state->dmabuf;
- down(&state->open_sem);
- stop_adc(state);
- dealloc_dmabuf(state);
- state->card->free_pcm_channel(state->card, dmabuf->channel->num);
- free_page((unsigned long)state->dmabuf.pbuf);
- /* we're covered by the open_sem */
- up(&state->open_sem);
- state->card->states[state->virt] = NULL;
- state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
- if( (tmp = cs461x_powerdown(card, CS_POWER_ADC, CS_FALSE )) )
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
- "cs46xx: cs_release_mixdev() powerdown ADC failure (0x%x)n",tmp) );
- }
- /* Now turn off external AMP if needed */
- state->card->amplifier_ctrl(state->card, -1);
- state->card->active_ctrl(state->card, -1);
- kfree(state);
- }
- }
- CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk("cs46xx: cs_release()- 0n") );
- MOD_DEC_USE_COUNT; /* For 2.2 */
- return 0;
- }
- static void printpm(struct cs_card *s)
- {
- CS_DBGOUT(CS_PM, 9, printk("pm struct:n"));
- CS_DBGOUT(CS_PM, 9, printk("flags:0x%x u32CLKCR1_SAVE: 0%x u32SSPMValue: 0x%xn",
- (unsigned)s->pm.flags,s->pm.u32CLKCR1_SAVE,s->pm.u32SSPMValue));
- CS_DBGOUT(CS_PM, 9, printk("u32PPLVCvalue: 0x%x u32PPRVCvalue: 0x%xn",
- s->pm.u32PPLVCvalue,s->pm.u32PPRVCvalue));
- CS_DBGOUT(CS_PM, 9, printk("u32FMLVCvalue: 0x%x u32FMRVCvalue: 0x%xn",
- s->pm.u32FMLVCvalue,s->pm.u32FMRVCvalue));
- CS_DBGOUT(CS_PM, 9, printk("u32GPIORvalue: 0x%x u32JSCTLvalue: 0x%xn",
- s->pm.u32GPIORvalue,s->pm.u32JSCTLvalue));
- CS_DBGOUT(CS_PM, 9, printk("u32SSCR: 0x%x u32SRCSA: 0x%xn",
- s->pm.u32SSCR,s->pm.u32SRCSA));
- CS_DBGOUT(CS_PM, 9, printk("u32DacASR: 0x%x u32AdcASR: 0x%xn",
- s->pm.u32DacASR,s->pm.u32AdcASR));
- CS_DBGOUT(CS_PM, 9, printk("u32DacSR: 0x%x u32AdcSR: 0x%xn",
- s->pm.u32DacSR,s->pm.u32AdcSR));
- CS_DBGOUT(CS_PM, 9, printk("u32MIDCR_Save: 0x%xn",
- s->pm.u32MIDCR_Save));
- CS_DBGOUT(CS_PM, 9, printk("u32AC97_powerdown: 0x%x _general_purpose 0x%xn",
- s->pm.u32AC97_powerdown,s->pm.u32AC97_general_purpose));
- CS_DBGOUT(CS_PM, 9, printk("u32AC97_master_volume: 0x%xn",
- s->pm.u32AC97_master_volume));
- CS_DBGOUT(CS_PM, 9, printk("u32AC97_headphone_volume: 0x%xn",
- s->pm.u32AC97_headphone_volume));
- CS_DBGOUT(CS_PM, 9, printk("u32AC97_master_volume_mono: 0x%xn",
- s->pm.u32AC97_master_volume_mono));
- CS_DBGOUT(CS_PM, 9, printk("u32AC97_pcm_out_volume: 0x%xn",
- s->pm.u32AC97_pcm_out_volume));
- CS_DBGOUT(CS_PM, 9, printk("dmabuf_swptr_play: 0x%x dmabuf_count_play: %dn",
- s->pm.dmabuf_swptr_play,s->pm.dmabuf_count_play));
- CS_DBGOUT(CS_PM, 9, printk("dmabuf_swptr_capture: 0x%x dmabuf_count_capture: %dn",
- s->pm.dmabuf_swptr_capture,s->pm.dmabuf_count_capture));
- }
- /****************************************************************************
- *
- * Suspend - save the ac97 regs, mute the outputs and power down the part.
- *
- ****************************************************************************/
- void cs46xx_ac97_suspend(struct cs_card *card)
- {
- int Count,i;
- struct ac97_codec *dev=card->ac97_codec[0];
- unsigned int tmp;
- CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()+n"));
- if(card->states[1])
- {
- stop_dac(card->states[1]);
- resync_dma_ptrs(card->states[1]);
- }
- if(card->states[0])
- {
- stop_adc(card->states[0]);
- resync_dma_ptrs(card->states[0]);
- }
- for(Count = 0x2, i=0; (Count <= CS46XX_AC97_HIGHESTREGTORESTORE)
- && (i < CS46XX_AC97_NUMBER_RESTORE_REGS);
- Count += 2, i++)
- {
- card->pm.ac97[i] = cs_ac97_get(dev, BA0_AC97_RESET + Count);
- }
- /*
- * Save the ac97 volume registers as well as the current powerdown state.
- * Now, mute the all the outputs (master, headphone, and mono), as well
- * as the PCM volume, in preparation for powering down the entire part.
- card->pm.u32AC97_master_volume = (u32)cs_ac97_get( dev,
- (u8)BA0_AC97_MASTER_VOLUME);
- card->pm.u32AC97_headphone_volume = (u32)cs_ac97_get(dev,
- (u8)BA0_AC97_HEADPHONE_VOLUME);
- card->pm.u32AC97_master_volume_mono = (u32)cs_ac97_get(dev,
- (u8)BA0_AC97_MASTER_VOLUME_MONO);
- card->pm.u32AC97_pcm_out_volume = (u32)cs_ac97_get(dev,
- (u8)BA0_AC97_PCM_OUT_VOLUME);
- */
- /*
- * mute the outputs
- */
- cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME, 0x8000);
- 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);
- /*
- * save the registers that cause pops
- */
- card->pm.u32AC97_powerdown = (u32)cs_ac97_get(dev, (u8)AC97_POWER_CONTROL);
- card->pm.u32AC97_general_purpose = (u32)cs_ac97_get(dev, (u8)BA0_AC97_GENERAL_PURPOSE);
- /*
- * And power down everything on the AC97 codec.
- * well, for now, only power down the DAC/ADC and MIXER VREFON components.
- * trouble with removing VREF.
- */
- if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
- CS_POWER_MIXVON, CS_TRUE )) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs46xx_ac97_suspend() failure (0x%x)n",tmp) );
- }
- CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()-n"));
- }
- /****************************************************************************
- *
- * Resume - power up the part and restore its registers..
- *
- ****************************************************************************/
- void cs46xx_ac97_resume(struct cs_card *card)
- {
- int Count,i;
- struct ac97_codec *dev=card->ac97_codec[0];
- CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_resume()+n"));
- /*
- * First, we restore the state of the general purpose register. This
- * contains the mic select (mic1 or mic2) and if we restore this after
- * we restore the mic volume/boost state and mic2 was selected at
- * suspend time, we will end up with a brief period of time where mic1
- * is selected with the volume/boost settings for mic2, causing
- * acoustic feedback. So we restore the general purpose register
- * first, thereby getting the correct mic selected before we restore
- * the mic volume/boost.
- */
- cs_ac97_set(dev, (u8)BA0_AC97_GENERAL_PURPOSE,
- (u16)card->pm.u32AC97_general_purpose);
- /*
- * Now, while the outputs are still muted, restore the state of power
- * on the AC97 part.
- */
- cs_ac97_set(dev, (u8)BA0_AC97_POWERDOWN, (u16)card->pm.u32AC97_powerdown);
- mdelay(5 * cs_laptop_wait);
- /*
- * Restore just the first set of registers, from register number
- * 0x02 to the register number that ulHighestRegToRestore specifies.
- */
- for( Count = 0x2, i=0;
- (Count <= CS46XX_AC97_HIGHESTREGTORESTORE)
- && (i < CS46XX_AC97_NUMBER_RESTORE_REGS);
- Count += 2, i++)
- {
- cs_ac97_set(dev, (u8)(BA0_AC97_RESET + Count), (u16)card->pm.ac97[i]);
- }
- /* Check if we have to init the amplifier */
- if(card->amp_init)
- card->amp_init(card);
-
- CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_resume()-n"));
- }
- static int cs46xx_restart_part(struct cs_card *card)
- {
- struct dmabuf *dmabuf;
- CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
- printk( "cs46xx: cs46xx_restart_part()+n"));
- if(card->states[1])
- {
- dmabuf = &card->states[1]->dmabuf;
- dmabuf->ready = 0;
- resync_dma_ptrs(card->states[1]);
- cs_set_divisor(dmabuf);
- if(__prog_dmabuf(card->states[1]))
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 1,
- printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() dac errorn"));
- return -1;
- }
- cs_set_dac_rate(card->states[1], dmabuf->rate);
- }
- if(card->states[0])
- {
- dmabuf = &card->states[0]->dmabuf;
- dmabuf->ready = 0;
- resync_dma_ptrs(card->states[0]);
- cs_set_divisor(dmabuf);
- if(__prog_dmabuf(card->states[0]))
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 1,
- printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() adc errorn"));
- return -1;
- }
- cs_set_adc_rate(card->states[0], dmabuf->rate);
- }
- card->pm.flags |= CS46XX_PM_RESUMED;
- if(card->states[0])
- start_adc(card->states[0]);
- if(card->states[1])
- start_dac(card->states[1]);
- card->pm.flags |= CS46XX_PM_IDLE;
- card->pm.flags &= ~(CS46XX_PM_SUSPENDING | CS46XX_PM_SUSPENDED
- | CS46XX_PM_RESUMING | CS46XX_PM_RESUMED);
- if(card->states[0])
- wake_up(&card->states[0]->dmabuf.wait);
- if(card->states[1])
- wake_up(&card->states[1]->dmabuf.wait);
- CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
- printk( "cs46xx: cs46xx_restart_part()-n"));
- return 0;
- }
- static void cs461x_reset(struct cs_card *card);
- static void cs461x_proc_stop(struct cs_card *card);
- static int cs46xx_suspend(struct cs_card *card, u32 state)
- {
- unsigned int tmp;
- CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
- printk("cs46xx: cs46xx_suspend()+ flags=0x%x s=0x%xn",
- (unsigned)card->pm.flags,(unsigned)card));
- /*
- * check the current state, only suspend if IDLE
- */
- if(!(card->pm.flags & CS46XX_PM_IDLE))
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 2,
- printk("cs46xx: cs46xx_suspend() unable to suspend, not IDLEn"));
- return 1;
- }
- card->pm.flags &= ~CS46XX_PM_IDLE;
- card->pm.flags |= CS46XX_PM_SUSPENDING;
- card->active_ctrl(card,1);
-
- tmp = cs461x_peek(card, BA1_PFIE);
- tmp &= ~0x0000f03f;
- tmp |= 0x00000010;
- cs461x_poke(card, BA1_PFIE, tmp); /* playback interrupt disable */
- tmp = cs461x_peek(card, BA1_CIE);
- tmp &= ~0x0000003f;
- tmp |= 0x00000011;
- cs461x_poke(card, BA1_CIE, tmp); /* capture interrupt disable */
- /*
- * Stop playback DMA.
- */
- tmp = cs461x_peek(card, BA1_PCTL);
- cs461x_poke(card, BA1_PCTL, tmp & 0x0000ffff);
- /*
- * Stop capture DMA.
- */
- tmp = cs461x_peek(card, BA1_CCTL);
- cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
- if(card->states[1])
- {
- card->pm.dmabuf_swptr_play = card->states[1]->dmabuf.swptr;
- card->pm.dmabuf_count_play = card->states[1]->dmabuf.count;
- }
- if(card->states[0])
- {
- card->pm.dmabuf_swptr_capture = card->states[0]->dmabuf.swptr;
- card->pm.dmabuf_count_capture = card->states[0]->dmabuf.count;
- }
- cs46xx_ac97_suspend(card);
- /*
- * Reset the processor.
- */
- cs461x_reset(card);
- cs461x_proc_stop(card);
- /*
- * Power down the DAC and ADC. For now leave the other areas on.
- */
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, 0x0300);
- /*
- * Power down the PLL.
- */
- cs461x_pokeBA0(card, BA0_CLKCR1, 0);
- /*
- * Turn off the Processor by turning off the software clock enable flag in
- * the clock control register.
- */
- tmp = cs461x_peekBA0(card, BA0_CLKCR1) & ~CLKCR1_SWCE;
- cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
- card->active_ctrl(card,-1);
- card->pm.flags &= ~CS46XX_PM_SUSPENDING;
- card->pm.flags |= CS46XX_PM_SUSPENDED;
- printpm(card);
- CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
- printk("cs46xx: cs46xx_suspend()- flags=0x%xn",
- (unsigned)card->pm.flags));
- return 0;
- }
- static int cs46xx_resume(struct cs_card *card)
- {
- int i;
- CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
- printk( "cs46xx: cs46xx_resume()+ flags=0x%xn",
- (unsigned)card->pm.flags));
- if(!(card->pm.flags & CS46XX_PM_SUSPENDED))
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 2,
- printk("cs46xx: cs46xx_resume() unable to resume, not SUSPENDEDn"));
- return 1;
- }
- card->pm.flags |= CS46XX_PM_RESUMING;
- card->pm.flags &= ~CS46XX_PM_SUSPENDED;
- printpm(card);
- card->active_ctrl(card, 1);
- for(i=0;i<5;i++)
- {
- if (cs_hardware_init(card) != 0)
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 4, printk(
- "cs46xx: cs46xx_resume()- ERROR in cs_hardware_init()n"));
- mdelay(10 * cs_laptop_wait);
- cs461x_reset(card);
- continue;
- }
- break;
- }
- if(i>=4)
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 1, printk(
- "cs46xx: cs46xx_resume()- cs_hardware_init() failed, retried %d times.n",i));
- return 0;
- }
- if(cs46xx_restart_part(card))
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 4, printk(
- "cs46xx: cs46xx_resume(): cs46xx_restart_part() returned errorn"));
- }
- card->active_ctrl(card, -1);
- CS_DBGOUT(CS_PM | CS_FUNCTION, 4, printk("cs46xx: cs46xx_resume()- flags=0x%xn",
- (unsigned)card->pm.flags));
- return 0;
- }
- static /*const*/ struct file_operations cs461x_fops = {
- CS_OWNER CS_THIS_MODULE
- llseek: no_llseek,
- read: cs_read,
- write: cs_write,
- poll: cs_poll,
- ioctl: cs_ioctl,
- mmap: cs_mmap,
- open: cs_open,
- release: cs_release,
- };
- /* Write AC97 codec registers */
- static u16 cs_ac97_get(struct ac97_codec *dev, u8 reg)
- {
- struct cs_card *card = dev->private_data;
- int count,loopcnt;
- unsigned int tmp;
-
- /*
- * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
- * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97
- * 3. Write ACCTL = Control Register = 460h for initiating the write
- * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 17h
- * 5. if DCV not cleared, break and return error
- * 6. Read ACSTS = Status Register = 464h, check VSTS bit
- */
- cs461x_peekBA0(card, BA0_ACSDA);
- /*
- * Setup the AC97 control registers on the CS461x to send the
- * appropriate command to the AC97 to perform the read.
- * ACCAD = Command Address Register = 46Ch
- * ACCDA = Command Data Register = 470h
- * ACCTL = Control Register = 460h
- * set DCV - will clear when process completed
- * set CRW - Read command
- * set VFRM - valid frame enabled
- * set ESYN - ASYNC generation enabled
- * set RSTN - ARST# inactive, AC97 codec not reset
- */
- cs461x_pokeBA0(card, BA0_ACCAD, reg);
- cs461x_pokeBA0(card, BA0_ACCDA, 0);
- cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_DCV | ACCTL_CRW |
- ACCTL_VFRM | ACCTL_ESYN |
- ACCTL_RSTN);
- /*
- * Wait for the read to occur.
- */
- if(!(card->pm.flags & CS46XX_PM_IDLE))
- loopcnt = 2000;
- else
- loopcnt = 500 * cs_laptop_wait;
- loopcnt *= cs_laptop_wait;
- for (count = 0; count < loopcnt; count++) {
- /*
- * First, we want to wait for a short time.
- */
- udelay(10 * cs_laptop_wait);
- /*
- * Now, check to see if the read has completed.
- * ACCTL = 460h, DCV should be reset by now and 460h = 17h
- */
- if (!(cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV))
- break;
- }
- /*
- * Make sure the read completed.
- */
- if (cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV) {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: AC'97 read problem (ACCTL_DCV), reg = 0x%x returning 0xffffn", reg));
- return 0xffff;
- }
- /*
- * Wait for the valid status bit to go active.
- */
- if(!(card->pm.flags & CS46XX_PM_IDLE))
- loopcnt = 2000;
- else
- loopcnt = 1000;
- loopcnt *= cs_laptop_wait;
- for (count = 0; count < loopcnt; count++) {
- /*
- * Read the AC97 status register.
- * ACSTS = Status Register = 464h
- * VSTS - Valid Status
- */
- if (cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_VSTS)
- break;
- udelay(10 * cs_laptop_wait);
- }
-
- /*
- * Make sure we got valid status.
- */
- if (!( (tmp=cs461x_peekBA0(card, BA0_ACSTS)) & ACSTS_VSTS)) {
- CS_DBGOUT(CS_ERROR, 2, printk(KERN_WARNING
- "cs46xx: AC'97 read problem (ACSTS_VSTS), reg = 0x%x val=0x%x 0xffff n",
- reg, tmp));
- return 0xffff;
- }
- /*
- * Read the data returned from the AC97 register.
- * ACSDA = Status Data Register = 474h
- */
- CS_DBGOUT(CS_FUNCTION, 9, printk(KERN_INFO
- "cs46xx: cs_ac97_get() reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%xn",
- reg, cs461x_peekBA0(card, BA0_ACSDA),
- cs461x_peekBA0(card, BA0_ACCAD)));
- return(cs461x_peekBA0(card, BA0_ACSDA));
- }
- static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 val)
- {
- struct cs_card *card = dev->private_data;
- int count;
- int val2 = 0;
-
- if(reg == AC97_CD_VOL)
- {
- val2 = cs_ac97_get(dev, AC97_CD_VOL);
- }
-
- /*
- * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
- * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97
- * 3. Write ACCTL = Control Register = 460h for initiating the write
- * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 07h
- * 5. if DCV not cleared, break and return error
- */
- /*
- * Setup the AC97 control registers on the CS461x to send the
- * appropriate command to the AC97 to perform the read.
- * ACCAD = Command Address Register = 46Ch
- * ACCDA = Command Data Register = 470h
- * ACCTL = Control Register = 460h
- * set DCV - will clear when process completed
- * reset CRW - Write command
- * set VFRM - valid frame enabled
- * set ESYN - ASYNC generation enabled
- * set RSTN - ARST# inactive, AC97 codec not reset
- */
- cs461x_pokeBA0(card, BA0_ACCAD, reg);
- cs461x_pokeBA0(card, BA0_ACCDA, val);
- cs461x_peekBA0(card, BA0_ACCTL);
- cs461x_pokeBA0(card, BA0_ACCTL, 0 | ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN);
- cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_DCV | ACCTL_VFRM |
- ACCTL_ESYN | ACCTL_RSTN);
- for (count = 0; count < 1000; count++) {
- /*
- * First, we want to wait for a short time.
- */
- udelay(10 * cs_laptop_wait);
- /*
- * Now, check to see if the write has completed.
- * ACCTL = 460h, DCV should be reset by now and 460h = 07h
- */
- if (!(cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV))
- break;
- }
- /*
- * Make sure the write completed.
- */
- if (cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV)
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: AC'97 write problem, reg = 0x%x, val = 0x%xn", reg, val));
- }
- /*
- * Adjust power if the mixer is selected/deselected according
- * to the CD.
- *
- * IF the CD is a valid input source (mixer or direct) AND
- * the CD is not muted THEN power is needed
- *
- * We do two things. When record select changes the input to
- * add/remove the CD we adjust the power count if the CD is
- * unmuted.
- *
- * When the CD mute changes we adjust the power level if the
- * CD was a valid input.
- *
- * We also check for CD volume != 0, as the CD mute isn't
- * normally tweaked from userspace.
- */
-
- /* CD mute change ? */
-
- if(reg==AC97_CD_VOL)
- {
- /* Mute bit change ? */
- if((val2^val)&0x8000 || ((val2 == 0x1f1f || val == 0x1f1f) && val2 != val))
- {
- /* This is a hack but its cleaner than the alternatives.
- Right now card->ac97_codec[0] might be NULL as we are
- still doing codec setup. This does an early assignment
- to avoid the problem if it occurs */
-
- if(card->ac97_codec[0]==NULL)
- card->ac97_codec[0]=dev;
-
- /* Mute on */
- if(val&0x8000 || val == 0x1f1f)
- card->amplifier_ctrl(card, -1);
- else /* Mute off power on */
- {
- if(card->amp_init)
- card->amp_init(card);
- card->amplifier_ctrl(card, 1);
- }
- }
- }
- }
- /* OSS /dev/mixer file operation methods */
- static int cs_open_mixdev(struct inode *inode, struct file *file)
- {
- int i=0;
- int minor = MINOR(inode->i_rdev);
- struct cs_card *card=NULL;
- struct list_head *entry;
- unsigned int tmp;
- CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
- printk(KERN_INFO "cs46xx: cs_open_mixdev()+n"));
- list_for_each(entry, &cs46xx_devs)
- {
- card = list_entry(entry, struct cs_card, list);
- for (i = 0; i < NR_AC97; i++)
- if (card->ac97_codec[i] != NULL &&
- card->ac97_codec[i]->dev_mixer == minor)
- goto match;
- }
- if (!card)
- {
- CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
- printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEVn"));
- return -ENODEV;
- }
- match:
- if(!card->ac97_codec[i])
- return -ENODEV;
- file->private_data = card->ac97_codec[i];
- card->active_ctrl(card,1);
- if(!CS_IN_USE(&card->mixer_use_cnt))
- {
- if( (tmp = cs46xx_powerup(card, CS_POWER_MIXVON )) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs_open_mixdev() powerup failure (0x%x)n",tmp) );
- return -EIO;
- }
- }
- card->amplifier_ctrl(card, 1);
- CS_INC_USE_COUNT(&card->mixer_use_cnt);
- MOD_INC_USE_COUNT; /* for 2.2 */
- CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
- printk(KERN_INFO "cs46xx: cs_open_mixdev()- 0n"));
- return 0;
- }
- static int cs_release_mixdev(struct inode *inode, struct file *file)
- {
- int minor = MINOR(inode->i_rdev);
- struct cs_card *card=NULL;
- struct list_head *entry;
- int i;
- unsigned int tmp;
- CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4,
- printk(KERN_INFO "cs46xx: cs_release_mixdev()+n"));
- list_for_each(entry, &cs46xx_devs)
- {
- card = list_entry(entry, struct cs_card, list);
- for (i = 0; i < NR_AC97; i++)
- if (card->ac97_codec[i] != NULL &&
- card->ac97_codec[i]->dev_mixer == minor)
- goto match;
- }
- if (!card)
- {
- CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
- printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEVn"));
- return -ENODEV;
- }
- match:
- MOD_DEC_USE_COUNT; /* for 2.2 */
- if(!CS_DEC_AND_TEST(&card->mixer_use_cnt))
- {
- CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4,
- printk(KERN_INFO "cs46xx: cs_release_mixdev()- no powerdown, usecnt>0n"));
- card->active_ctrl(card, -1);
- card->amplifier_ctrl(card, -1);
- return 0;
- }
- /*
- * ok, no outstanding mixer opens, so powerdown.
- */
- if( (tmp = cs461x_powerdown(card, CS_POWER_MIXVON, CS_FALSE )) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs_release_mixdev() powerdown MIXVON failure (0x%x)n",tmp) );
- card->active_ctrl(card, -1);
- card->amplifier_ctrl(card, -1);
- return -EIO;
- }
- card->active_ctrl(card, -1);
- card->amplifier_ctrl(card, -1);
- CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4,
- printk(KERN_INFO "cs46xx: cs_release_mixdev()- 0n"));
- return 0;
- }
- void __exit cs46xx_cleanup_module(void);
- static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
- unsigned long arg)
- {
- struct ac97_codec *codec = (struct ac97_codec *)file->private_data;
- struct cs_card *card=NULL;
- struct list_head *entry;
- #if CSDEBUG_INTERFACE
- int val;
- if( (cmd == SOUND_MIXER_CS_GETDBGMASK) ||
- (cmd == SOUND_MIXER_CS_SETDBGMASK) ||
- (cmd == SOUND_MIXER_CS_GETDBGLEVEL) ||
- (cmd == SOUND_MIXER_CS_SETDBGLEVEL) ||
- (cmd == SOUND_MIXER_CS_APM))
- {
- switch(cmd)
- {
- case SOUND_MIXER_CS_GETDBGMASK:
- return put_user(cs_debugmask, (unsigned long *)arg);
-
- case SOUND_MIXER_CS_GETDBGLEVEL:
- return put_user(cs_debuglevel, (unsigned long *)arg);
- case SOUND_MIXER_CS_SETDBGMASK:
- if (get_user(val, (unsigned long *)arg))
- return -EFAULT;
- cs_debugmask = val;
- return 0;
- case SOUND_MIXER_CS_SETDBGLEVEL:
- if (get_user(val, (unsigned long *)arg))
- return -EFAULT;
- cs_debuglevel = val;
- return 0;
- case SOUND_MIXER_CS_APM:
- if (get_user(val, (unsigned long *) arg))
- return -EFAULT;
- if(val == CS_IOCTL_CMD_SUSPEND)
- {
- list_for_each(entry, &cs46xx_devs)
- {
- card = list_entry(entry, struct cs_card, list);
- cs46xx_suspend(card, 0);
- }
- }
- else if(val == CS_IOCTL_CMD_RESUME)
- {
- list_for_each(entry, &cs46xx_devs)
- {
- card = list_entry(entry, struct cs_card, list);
- cs46xx_resume(card);
- }
- }
- else
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
- "cs46xx: mixer_ioctl(): invalid APM cmd (%d)n",
- val));
- }
- return 0;
- default:
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
- "cs46xx: mixer_ioctl(): ERROR unknown debug cmdn") );
- return 0;
- }
- }
- #endif
- return codec->mixer_ioctl(codec, cmd, arg);
- }
- static /*const*/ struct file_operations cs_mixer_fops = {
- CS_OWNER CS_THIS_MODULE
- llseek: no_llseek,
- ioctl: cs_ioctl_mixdev,
- open: cs_open_mixdev,
- release: cs_release_mixdev,
- };
- /* AC97 codec initialisation. */
- static int __init cs_ac97_init(struct cs_card *card)
- {
- int num_ac97 = 0;
- int ready_2nd = 0;
- struct ac97_codec *codec;
- u16 eid;
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
- "cs46xx: cs_ac97_init()+n") );
- for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
- if ((codec = kmalloc(sizeof(struct ac97_codec), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(codec, 0, sizeof(struct ac97_codec));
- /* initialize some basic codec information, other fields will be filled
- in ac97_probe_codec */
- codec->private_data = card;
- codec->id = num_ac97;
- codec->codec_read = cs_ac97_get;
- codec->codec_write = cs_ac97_set;
-
- if (ac97_probe_codec(codec) == 0)
- {
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
- "cs46xx: cs_ac97_init()- codec number %d not foundn",
- num_ac97) );
- card->ac97_codec[num_ac97] = 0;
- break;
- }
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
- "cs46xx: cs_ac97_init() found codec %dn",num_ac97) );
- eid = cs_ac97_get(codec, AC97_EXTENDED_ID);
-
- if(eid==0xFFFFFF)
- {
- printk(KERN_WARNING "cs46xx: codec %d not presentn",num_ac97);
- kfree(codec);
- break;
- }
-
- card->ac97_features = eid;
-
- if ((codec->dev_mixer = register_sound_mixer(&cs_mixer_fops, -1)) < 0) {
- printk(KERN_ERR "cs46xx: couldn't register mixer!n");
- kfree(codec);
- break;
- }
- card->ac97_codec[num_ac97] = codec;
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
- "cs46xx: cs_ac97_init() ac97_codec[%d] set to 0x%xn",
- (unsigned int)num_ac97,
- (unsigned int)codec));
- /* if there is no secondary codec at all, don't probe any more */
- if (!ready_2nd)
- {
- num_ac97 += 1;
- break;
- }
- }
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
- "cs46xx: cs_ac97_init()- %dn", (unsigned int)num_ac97));
- return num_ac97;
- }
- /*
- * load the static image into the DSP
- */
- #include "cs461x_image.h"
- static void cs461x_download_image(struct cs_card *card)
- {
- unsigned i, j, temp1, temp2, offset, count;
- unsigned char *pBA1 = ioremap(card->ba1_addr, 0x40000);
- for( i=0; i < CLEAR__COUNT; i++)
- {
- offset = ClrStat[i].BA1__DestByteOffset;
- count = ClrStat[i].BA1__SourceSize;
- for( temp1 = offset; temp1<(offset+count); temp1+=4 );
- writel(0, pBA1+temp1);
- }
- for(i=0; i<FILL__COUNT; i++)
- {
- temp2 = FillStat[i].Offset;
- for(j=0; j<(FillStat[i].Size)/4; j++)
- {
- temp1 = (FillStat[i]).pFill[j];
- writel(temp1, pBA1+temp2+j*4);
- }
- }
- iounmap(pBA1);
- }
- /*
- * Chip reset
- */
- static void cs461x_reset(struct cs_card *card)
- {
- int idx;
- /*
- * Write the reset bit of the SP control register.
- */
- cs461x_poke(card, BA1_SPCR, SPCR_RSTSP);
- /*
- * Write the control register.
- */
- cs461x_poke(card, BA1_SPCR, SPCR_DRQEN);
- /*
- * Clear the trap registers.
- */
- for (idx = 0; idx < 8; idx++) {
- cs461x_poke(card, BA1_DREG, DREG_REGID_TRAP_SELECT + idx);
- cs461x_poke(card, BA1_TWPR, 0xFFFF);
- }
- cs461x_poke(card, BA1_DREG, 0);
- /*
- * Set the frame timer to reflect the number of cycles per frame.
- */
- cs461x_poke(card, BA1_FRMT, 0xadf);
- }
- static void cs461x_clear_serial_FIFOs(struct cs_card *card, int type)
- {
- int idx, loop, startfifo=0, endfifo=0, powerdown1 = 0;
- unsigned int tmp;
- /*
- * See if the devices are powered down. If so, we must power them up first
- * or they will not respond.
- */
- if (!((tmp = cs461x_peekBA0(card, BA0_CLKCR1)) & CLKCR1_SWCE)) {
- cs461x_pokeBA0(card, BA0_CLKCR1, tmp | CLKCR1_SWCE);
- powerdown1 = 1;
- }
- /*
- * We want to clear out the serial port FIFOs so we don't end up playing
- * whatever random garbage happens to be in them. We fill the sample FIFOS
- * with zero (silence).
- */
- cs461x_pokeBA0(card, BA0_SERBWP, 0);
- /*
- * Check for which FIFO locations to clear, if we are currently
- * playing or capturing then we don't want to put in 128 bytes of
- * "noise".
- */
- if(type & CS_TYPE_DAC)
- {
- startfifo = 128;
- endfifo = 256;
- }
- if(type & CS_TYPE_ADC)
- {
- startfifo = 0;
- if(!endfifo)
- endfifo = 128;
- }
- /*
- * Fill sample FIFO locations (256 locations total).
- */
- for (idx = startfifo; idx < endfifo; idx++) {
- /*
- * Make sure the previous FIFO write operation has completed.
- */
- for (loop = 0; loop < 5; loop++) {
- udelay(50);
- if (!(cs461x_peekBA0(card, BA0_SERBST) & SERBST_WBSY))
- break;
- }
- if (cs461x_peekBA0(card, BA0_SERBST) & SERBST_WBSY) {
- if (powerdown1)
- cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
- }
- /*
- * Write the serial port FIFO index.
- */
- cs461x_pokeBA0(card, BA0_SERBAD, idx);
- /*
- * Tell the serial port to load the new value into the FIFO location.
- */
- cs461x_pokeBA0(card, BA0_SERBCM, SERBCM_WRC);
- }
- /*
- * Now, if we powered up the devices, then power them back down again.
- * This is kinda ugly, but should never happen.
- */
- if (powerdown1)
- cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
- }
- static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspendflag)
- {
- int count;
- unsigned int tmp=0,muted=0;
- CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
- "cs46xx: cs461x_powerdown()+ type=0x%xn",type));
- if(!cs_powerdown && !suspendflag)
- {
- CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
- "cs46xx: cs461x_powerdown() DISABLED exitingn"));
- return 0;
- }
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
- "cs46xx: cs461x_powerdown() powerdown reg=0x%xn",tmp));
- /*
- * if powering down only the VREF, and not powering down the DAC/ADC,
- * then do not power down the VREF, UNLESS both the DAC and ADC are not
- * currently powered down. If powering down DAC and ADC, then
- * it is possible to power down the VREF (ON).
- */
- if ( ((type & CS_POWER_MIXVON) &&
- (!(type & CS_POWER_ADC) || (!(type & CS_POWER_DAC))) )
- &&
- ((tmp & CS_AC97_POWER_CONTROL_ADC_ON) ||
- (tmp & CS_AC97_POWER_CONTROL_DAC_ON) ) )
- {
- CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
- "cs46xx: cs461x_powerdown()- 0 unable to powerdown. tmp=0x%xn",tmp));
- return 0;
- }
- /*
- * for now, always keep power to the mixer block.
- * not sure why it's a problem but it seems to be if we power off.
- */
- type &= ~CS_POWER_MIXVON;
- type &= ~CS_POWER_MIXVOFF;
- /*
- * Power down indicated areas.
- */
- if(type & CS_POWER_MIXVOFF)
- {
- CS_DBGOUT(CS_FUNCTION, 4,
- printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVOFFn"));
- /*
- * Power down the MIXER (VREF ON) on the AC97 card.
- */
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON)
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp |= CS_AC97_POWER_CONTROL_MIXVOFF;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVOFF_ON))
- break;
- }
-
- /*
- * Check the status..
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVOFF_ON)
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerdown MIXVOFF failedn"));
- return 1;
- }
- }
- }
- if(type & CS_POWER_MIXVON)
- {
- CS_DBGOUT(CS_FUNCTION, 4,
- printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVONn"));
- /*
- * Power down the MIXER (VREF ON) on the AC97 card.
- */
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (tmp & CS_AC97_POWER_CONTROL_MIXVON_ON)
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp |= CS_AC97_POWER_CONTROL_MIXVON;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVON_ON))
- break;
- }
-
- /*
- * Check the status..
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVON_ON)
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerdown MIXVON failedn"));
- return 1;
- }
- }
- }
- if(type & CS_POWER_ADC)
- {
- /*
- * Power down the ADC on the AC97 card.
- */
- CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs461x_powerdown()+ ADCn"));
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (tmp & CS_AC97_POWER_CONTROL_ADC_ON)
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp |= CS_AC97_POWER_CONTROL_ADC;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_ADC_ON))
- break;
- }
- /*
- * Check the status..
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_ADC_ON)
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerdown ADC failedn"));
- return 1;
- }
- }
- }
- if(type & CS_POWER_DAC)
- {
- /*
- * Power down the DAC on the AC97 card.
- */
- CS_DBGOUT(CS_FUNCTION, 4,
- printk(KERN_INFO "cs46xx: cs461x_powerdown()+ DACn"));
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (tmp & CS_AC97_POWER_CONTROL_DAC_ON)
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp |= CS_AC97_POWER_CONTROL_DAC;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_DAC_ON))
- break;
- }
-
- /*
- * Check the status..
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_DAC_ON)
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerdown DAC failedn"));
- return 1;
- }
- }
- }
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if(muted)
- cs_mute(card, CS_FALSE);
- CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
- "cs46xx: cs461x_powerdown()- 0 tmp=0x%xn",tmp));
- return 0;
- }
- static int cs46xx_powerup(struct cs_card *card, unsigned int type)
- {
- int count;
- unsigned int tmp=0,muted=0;
- CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
- "cs46xx: cs46xx_powerup()+ type=0x%xn",type));
- /*
- * check for VREF and powerup if need to.
- */
- if(type & CS_POWER_MIXVON)
- type |= CS_POWER_MIXVOFF;
- if(type & (CS_POWER_DAC | CS_POWER_ADC))
- type |= CS_POWER_MIXVON | CS_POWER_MIXVOFF;
- /*
- * Power up indicated areas.
- */
- if(type & CS_POWER_MIXVOFF)
- {
- CS_DBGOUT(CS_FUNCTION, 4,
- printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVOFFn"));
- /*
- * Power up the MIXER (VREF ON) on the AC97 card.
- */
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (!(tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON))
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp &= ~CS_AC97_POWER_CONTROL_MIXVOFF;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVOFF_ON)
- break;
- }
-
- /*
- * Check the status..
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVOFF_ON))
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerup MIXVOFF failedn"));
- return 1;
- }
- }
- }
- if(type & CS_POWER_MIXVON)
- {
- CS_DBGOUT(CS_FUNCTION, 4,
- printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVONn"));
- /*
- * Power up the MIXER (VREF ON) on the AC97 card.
- */
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (!(tmp & CS_AC97_POWER_CONTROL_MIXVON_ON))
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp &= ~CS_AC97_POWER_CONTROL_MIXVON;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVON_ON)
- break;
- }
-
- /*
- * Check the status..
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_MIXVON_ON))
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerup MIXVON failedn"));
- return 1;
- }
- }
- }
- if(type & CS_POWER_ADC)
- {
- /*
- * Power up the ADC on the AC97 card.
- */
- CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs46xx_powerup()+ ADCn"));
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (!(tmp & CS_AC97_POWER_CONTROL_ADC_ON))
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp &= ~CS_AC97_POWER_CONTROL_ADC;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_ADC_ON)
- break;
- }
- /*
- * Check the status..
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_ADC_ON))
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerup ADC failedn"));
- return 1;
- }
- }
- }
- if(type & CS_POWER_DAC)
- {
- /*
- * Power up the DAC on the AC97 card.
- */
- CS_DBGOUT(CS_FUNCTION, 4,
- printk(KERN_INFO "cs46xx: cs46xx_powerup()+ DACn"));
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if (!(tmp & CS_AC97_POWER_CONTROL_DAC_ON))
- {
- if(!muted)
- {
- cs_mute(card, CS_TRUE);
- muted=1;
- }
- tmp &= ~CS_AC97_POWER_CONTROL_DAC;
- cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
- /*
- * Now, we wait until we sample a ready state.
- */
- for (count = 0; count < 32; count++) {
- /*
- * First, lets wait a short while to let things settle out a
- * bit, and to prevent retrying the read too quickly.
- */
- udelay(500);
- /*
- * Read the current state of the power control register.
- */
- if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_DAC_ON)
- break;
- }
-
- /*
- * Check the status..
- */
- if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
- CS_AC97_POWER_CONTROL_DAC_ON))
- {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
- "cs46xx: powerup DAC failedn"));
- return 1;
- }
- }
- }
- tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
- if(muted)
- cs_mute(card, CS_FALSE);
- CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
- "cs46xx: cs46xx_powerup()- 0 tmp=0x%xn",tmp));
- return 0;
- }
- static void cs461x_proc_start(struct cs_card *card)
- {
- int cnt;
- /*
- * Set the frame timer to reflect the number of cycles per frame.
- */
- cs461x_poke(card, BA1_FRMT, 0xadf);
- /*
- * Turn on the run, run at frame, and DMA enable bits in the local copy of
- * the SP control register.
- */
- cs461x_poke(card, BA1_SPCR, SPCR_RUN | SPCR_RUNFR | SPCR_DRQEN);
- /*
- * Wait until the run at frame bit resets itself in the SP control
- * register.
- */
- for (cnt = 0; cnt < 25; cnt++) {
- udelay(50);
- if (!(cs461x_peek(card, BA1_SPCR) & SPCR_RUNFR))
- break;
- }
- if (cs461x_peek(card, BA1_SPCR) & SPCR_RUNFR)
- printk(KERN_WARNING "cs46xx: SPCR_RUNFR never resetn");
- }
- static void cs461x_proc_stop(struct cs_card *card)
- {
- /*
- * Turn off the run, run at frame, and DMA enable bits in the local copy of
- * the SP control register.
- */
- cs461x_poke(card, BA1_SPCR, 0);
- }
- static int cs_hardware_init(struct cs_card *card)
- {
- unsigned long end_time;
- unsigned int tmp,count;
-
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
- "cs46xx: cs_hardware_init()+n") );
- /*
- * First, blast the clock control register to zero so that the PLL starts
- * out in a known state, and blast the master serial port control register
- * to zero so that the serial ports also start out in a known state.
- */
- cs461x_pokeBA0(card, BA0_CLKCR1, 0);
- cs461x_pokeBA0(card, BA0_SERMC1, 0);
- /*
- * If we are in AC97 mode, then we must set the part to a host controlled
- * AC-link. Otherwise, we won't be able to bring up the link.
- */
- cs461x_pokeBA0(card, BA0_SERACC, SERACC_HSP | SERACC_CODEC_TYPE_1_03); /* 1.03 card */
- /* cs461x_pokeBA0(card, BA0_SERACC, SERACC_HSP | SERACC_CODEC_TYPE_2_0); */ /* 2.00 card */
- /*
- * Drive the ARST# pin low for a minimum of 1uS (as defined in the AC97
- * spec) and then drive it high. This is done for non AC97 modes since
- * there might be logic external to the CS461x that uses the ARST# line
- * for a reset.
- */
- cs461x_pokeBA0(card, BA0_ACCTL, 1);
- udelay(50);
- cs461x_pokeBA0(card, BA0_ACCTL, 0);
- udelay(50);
- cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_RSTN);
- /*
- * The first thing we do here is to enable sync generation. As soon
- * as we start receiving bit clock, we'll start producing the SYNC
- * signal.
- */
- cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_ESYN | ACCTL_RSTN);
- /*
- * Now wait for a short while to allow the AC97 part to start
- * generating bit clock (so we don't try to start the PLL without an
- * input clock).
- */
- mdelay(5 * cs_laptop_wait); /* 1 should be enough ?? (and pigs might fly) */
- /*
- * Set the serial port timing configuration, so that
- * the clock control circuit gets its clock from the correct place.
- */
- cs461x_pokeBA0(card, BA0_SERMC1, SERMC1_PTC_AC97);
- /*
- * The part seems to not be ready for a while after a resume.
- * so, if we are resuming, then wait for 700 mils. Note that 600 mils
- * is not enough for some platforms! tested on an IBM Thinkpads and
- * reference cards.
- */
- if(!(card->pm.flags & CS46XX_PM_IDLE))
- mdelay(initdelay);
- /*
- * Write the selected clock control setup to the hardware. Do not turn on
- * SWCE yet (if requested), so that the devices clocked by the output of
- * PLL are not clocked until the PLL is stable.
- */
- cs461x_pokeBA0(card, BA0_PLLCC, PLLCC_LPF_1050_2780_KHZ | PLLCC_CDR_73_104_MHZ);
- cs461x_pokeBA0(card, BA0_PLLM, 0x3a);
- cs461x_pokeBA0(card, BA0_CLKCR2, CLKCR2_PDIVS_8);
- /*
- * Power up the PLL.
- */
- cs461x_pokeBA0(card, BA0_CLKCR1, CLKCR1_PLLP);
- /*
- * Wait until the PLL has stabilized.
- */
- mdelay(5 * cs_laptop_wait); /* Again 1 should be enough ?? */
- /*
- * Turn on clocking of the core so that we can setup the serial ports.
- */
- tmp = cs461x_peekBA0(card, BA0_CLKCR1) | CLKCR1_SWCE;
- cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
- /*
- * Fill the serial port FIFOs with silence.
- */
- cs461x_clear_serial_FIFOs(card,CS_TYPE_DAC | CS_TYPE_ADC);
- /*
- * Set the serial port FIFO pointer to the first sample in the FIFO.
- */
- /* cs461x_pokeBA0(card, BA0_SERBSP, 0); */
- /*
- * Write the serial port configuration to the part. The master
- * enable bit is not set until all other values have been written.
- */
- cs461x_pokeBA0(card, BA0_SERC1, SERC1_SO1F_AC97 | SERC1_SO1EN);
- cs461x_pokeBA0(card, BA0_SERC2, SERC2_SI1F_AC97 | SERC1_SO1EN);
- cs461x_pokeBA0(card, BA0_SERMC1, SERMC1_PTC_AC97 | SERMC1_MSPE);
- mdelay(5 * cs_laptop_wait); /* Shouldnt be needed ?? */
-
- /*
- * If we are resuming under 2.2.x then we can not schedule a timeout.
- * so, just spin the CPU.
- */
- if(card->pm.flags & CS46XX_PM_IDLE)
- {
- /*
- * Wait for the card ready signal from the AC97 card.
- */
- end_time = jiffies + 3 * (HZ >> 2);
- do {
- /*
- * Read the AC97 status register to see if we've seen a CODEC READY
- * signal from the AC97 card.
- */
- if (cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_CRDY)
- break;
- current->state = TASK_UNINTERRUPTIBLE;
- schedule_timeout(1);
- } while (time_before(jiffies, end_time));
- }
- else
- {
- for (count = 0; count < 100; count++) {
- // First, we want to wait for a short time.
- udelay(25 * cs_laptop_wait);
- if (cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_CRDY)
- break;
- }
- }
- /*
- * Make sure CODEC is READY.
- */
- if (!(cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_CRDY)) {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_WARNING
- "cs46xx: create - never read card ready from AC'97n"));
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_WARNING
- "cs46xx: probably not a bug, try using the CS4232 driver,n"));
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_WARNING
- "cs46xx: or turn off any automatic Power Management support in the BIOS.n"));
- return -EIO;
- }
- /*
- * Assert the vaid frame signal so that we can start sending commands
- * to the AC97 card.
- */
- cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN);
- if(card->pm.flags & CS46XX_PM_IDLE)
- {
- /*
- * Wait until we've sampled input slots 3 and 4 as valid, meaning that
- * the card is pumping ADC data across the AC-link.
- */
- end_time = jiffies + 3 * (HZ >> 2);
- do {
- /*
- * Read the input slot valid register and see if input slots 3 and
- * 4 are valid yet.
- */
- if ((cs461x_peekBA0(card, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4))
- break;
- current->state = TASK_UNINTERRUPTIBLE;
- schedule_timeout(1);
- } while (time_before(jiffies, end_time));
- }
- else
- {
- for (count = 0; count < 100; count++) {
- // First, we want to wait for a short time.
- udelay(25 * cs_laptop_wait);
- if ((cs461x_peekBA0(card, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4))
- break;
- }
- }
- /*
- * Make sure input slots 3 and 4 are valid. If not, then return
- * an error.
- */
- if ((cs461x_peekBA0(card, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) != (ACISV_ISV3 | ACISV_ISV4)) {
- printk(KERN_WARNING "cs46xx: create - never read ISV3 & ISV4 from AC'97n");
- return -EIO;
- }
- /*
- * Now, assert valid frame and the slot 3 and 4 valid bits. This will
- * commense the transfer of digital audio data to the AC97 card.
- */
- cs461x_pokeBA0(card, BA0_ACOSV, ACOSV_SLV3 | ACOSV_SLV4);
- /*
- * Turn off the Processor by turning off the software clock enable flag in
- * the clock control register.
- */
- /* tmp = cs461x_peekBA0(card, BA0_CLKCR1) & ~CLKCR1_SWCE; */
- /* cs461x_pokeBA0(card, BA0_CLKCR1, tmp); */
- /*
- * Reset the processor.
- */
- cs461x_reset(card);
- /*
- * Download the image to the processor.
- */
-
- cs461x_download_image(card);
- /*
- * Stop playback DMA.
- */
- tmp = cs461x_peek(card, BA1_PCTL);
- card->pctl = tmp & 0xffff0000;
- cs461x_poke(card, BA1_PCTL, tmp & 0x0000ffff);
- /*
- * Stop capture DMA.
- */
- tmp = cs461x_peek(card, BA1_CCTL);
- card->cctl = tmp & 0x0000ffff;
- cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
- /* initialize AC97 codec and register /dev/mixer */
- if(card->pm.flags & CS46XX_PM_IDLE)
- {
- if (cs_ac97_init(card) <= 0)
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs_ac97_init() failuren") );
- return -EIO;
- }
- }
- else
- {
- cs46xx_ac97_resume(card);
- }
-
- cs461x_proc_start(card);
- /*
- * Enable interrupts on the part.
- */
- cs461x_pokeBA0(card, BA0_HICR, HICR_IEV | HICR_CHGM);
- tmp = cs461x_peek(card, BA1_PFIE);
- tmp &= ~0x0000f03f;
- cs461x_poke(card, BA1_PFIE, tmp); /* playback interrupt enable */
- tmp = cs461x_peek(card, BA1_CIE);
- tmp &= ~0x0000003f;
- tmp |= 0x00000001;
- cs461x_poke(card, BA1_CIE, tmp); /* capture interrupt enable */
- /*
- * If IDLE then Power down the part. We will power components up
- * when we need them.
- */
- if(card->pm.flags & CS46XX_PM_IDLE)
- {
- if(!cs_powerdown)
- {
- if( (tmp = cs46xx_powerup(card, CS_POWER_DAC | CS_POWER_ADC |
- CS_POWER_MIXVON )) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs461x_powerup() failure (0x%x)n",tmp) );
- return -EIO;
- }
- }
- else
- {
- if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
- CS_POWER_MIXVON, CS_FALSE )) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs461x_powerdown() failure (0x%x)n",tmp) );
- return -EIO;
- }
- }
- }
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
- "cs46xx: cs_hardware_init()- 0n"));
- return 0;
- }
- /* install the driver, we do not allocate hardware channel nor DMA buffer now, they are defered
- until "ACCESS" time (in prog_dmabuf called by open/read/write/ioctl/mmap) */
-
- /*
- * Card subid table
- */
-
- struct cs_card_type
- {
- u16 vendor;
- u16 id;
- char *name;
- void (*amp)(struct cs_card *, int);
- void (*amp_init)(struct cs_card *);
- void (*active)(struct cs_card *, int);
- };
- static struct cs_card_type cards[]={
- {0x1489, 0x7001, "Genius Soundmaker 128 value", amp_none, NULL, NULL},
- {0x5053, 0x3357, "Voyetra", amp_voyetra, NULL, NULL},
- {0x1071, 0x6003, "Mitac MI6020/21", amp_voyetra, NULL, NULL},
- {0x14AF, 0x0050, "Hercules Game Theatre XP", amp_hercules, NULL, NULL},
- {0x1681, 0x0050, "Hercules Game Theatre XP", amp_hercules, NULL, NULL},
- {0x1681, 0x0051, "Hercules Game Theatre XP", amp_hercules, NULL, NULL},
- {0x1681, 0x0052, "Hercules Game Theatre XP", amp_hercules, NULL, NULL},
- {0x1681, 0x0053, "Hercules Game Theatre XP", amp_hercules, NULL, NULL},
- {0x1681, 0x0054, "Hercules Game Theatre XP", amp_hercules, NULL, NULL},
- {0x1681, 0xa010, "Hercules Fortissimo II", amp_none, NULL, NULL},
-
- /* Not sure if the 570 needs the clkrun hack */
- {PCI_VENDOR_ID_IBM, 0x0132, "Thinkpad 570", amp_none, NULL, clkrun_hack},
- {PCI_VENDOR_ID_IBM, 0x0153, "Thinkpad 600X/A20/T20", amp_none, NULL, clkrun_hack},
- {PCI_VENDOR_ID_IBM, 0x1010, "Thinkpad 600E (unsupported)", NULL, NULL, NULL},
- {0, 0, "Card without SSID set", NULL, NULL, NULL },
- {0, 0, NULL, NULL, NULL}
- };
- MODULE_AUTHOR("Alan Cox <alan@redhat.com>, Jaroslav Kysela, <pcaudio@crystal.cirrus.com>");
- MODULE_DESCRIPTION("Crystal SoundFusion Audio Support");
- MODULE_LICENSE("GPL");
- static const char cs46xx_banner[] = KERN_INFO "Crystal 4280/46xx + AC97 Audio, version " CS46XX_MAJOR_VERSION "." CS46XX_MINOR_VERSION "." CS46XX_ARCH ", " __TIME__ " " __DATE__ "n";
- static const char fndmsg[] = KERN_INFO "cs46xx: Found %d audio device(s).n";
- static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
- const struct pci_device_id *pciid)
- {
- struct pm_dev *pmdev;
- int i,j;
- u16 ss_card, ss_vendor;
- struct cs_card *card;
- dma_addr_t dma_mask;
- struct cs_card_type *cp = &cards[0];
- CS_DBGOUT(CS_FUNCTION | CS_INIT, 2,
- printk(KERN_INFO "cs46xx: probe()+n"));
- dma_mask = 0xffffffff; /* this enables playback and recording */
- if (pci_enable_device(pci_dev)) {
- CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
- "cs46xx: pci_enable_device() failedn"));
- return -1;
- }
- if (!RSRCISMEMORYREGION(pci_dev, 0) ||
- !RSRCISMEMORYREGION(pci_dev, 1)) {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
- "cs46xx: probe()- Memory region not assignedn"));
- return -1;
- }
- if (pci_dev->irq == 0) {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
- "cs46xx: probe() IRQ not assignedn"));
- return -1;
- }
- if (!pci_dma_supported(pci_dev, 0xffffffff)) {
- CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
- "cs46xx: probe() architecture does not support 32bit PCI busmaster DMAn"));
- return -1;
- }
- pci_read_config_word(pci_dev, PCI_SUBSYSTEM_VENDOR_ID, &ss_vendor);
- pci_read_config_word(pci_dev, PCI_SUBSYSTEM_ID, &ss_card);
- if ((card = kmalloc(sizeof(struct cs_card), GFP_KERNEL)) == NULL) {
- printk(KERN_ERR "cs46xx: out of memoryn");
- return -ENOMEM;
- }
- memset(card, 0, sizeof(*card));
- card->ba0_addr = RSRCADDRESS(pci_dev, 0);
- card->ba1_addr = RSRCADDRESS(pci_dev, 1);
- card->pci_dev = pci_dev;
- card->irq = pci_dev->irq;
- card->magic = CS_CARD_MAGIC;
- spin_lock_init(&card->lock);
- pci_set_master(pci_dev);
- printk(cs46xx_banner);
- printk(KERN_INFO "cs46xx: Card found at 0x%08lx and 0x%08lx, IRQ %dn",
- card->ba0_addr, card->ba1_addr, card->irq);
- card->alloc_pcm_channel = cs_alloc_pcm_channel;
- card->alloc_rec_pcm_channel = cs_alloc_rec_pcm_channel;
- card->free_pcm_channel = cs_free_pcm_channel;
- card->amplifier_ctrl = amp_none;
- card->active_ctrl = amp_none;
- while (cp->name)
- {
- if(cp->vendor == ss_vendor && cp->id == ss_card)
- {
- card->amplifier_ctrl = cp->amp;
- if(cp->active)
- card->active_ctrl = cp->active;
- if(cp->amp_init)
- card->amp_init = cp->amp_init;
- break;
- }
- cp++;
- }
- if (cp->name==NULL)
- {
- printk(KERN_INFO "cs46xx: Unknown card (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %dn",
- ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq);
- }
- else
- {
- printk(KERN_INFO "cs46xx: %s (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %dn",
- cp->name, ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq);
- }
-
- if (card->amplifier_ctrl==NULL)
- {
- card->amplifier_ctrl = amp_none;
- card->active_ctrl = clkrun_hack;
- }
- if (external_amp == 1)
- {
- printk(KERN_INFO "cs46xx: Crystal EAPD support forced on.n");
- card->amplifier_ctrl = amp_voyetra;
- }
- if (thinkpad == 1)
- {
- printk(KERN_INFO "cs46xx: Activating CLKRUN hack for Thinkpad.n");
- card->active_ctrl = clkrun_hack;
- }
- /*
- * The thinkpads don't work well without runtime updating on their kernel
- * delay values (or any laptop with variable CPU speeds really).
- * so, just to be safe set the init delay to 2100. Eliminates
- * failures on T21 Thinkpads. remove this code when the udelay
- * and mdelay kernel code is replaced by a pm timer, or the delays
- * work well for battery and/or AC power both.
- */
- if(card->active_ctrl == clkrun_hack)
- {
- initdelay = 2100;
- cs_laptop_wait = 5;
- }
- if((card->active_ctrl == clkrun_hack) && !(powerdown == 1))
- {
- /*
- * for some currently unknown reason, powering down the DAC and ADC component
- * blocks on thinkpads causes some funky behavior... distoorrrtion and ac97
- * codec access problems. probably the serial clock becomes unsynced.
- * added code to sync the chips back up, but only helped about 70% the time.
- */
- cs_powerdown = 0;
- }
- if(powerdown == 0)
- cs_powerdown = 0;
- card->active_ctrl(card, 1);
- /* claim our iospace and irq */
-
- card->ba0 = ioremap_nocache(card->ba0_addr, CS461X_BA0_SIZE);
- card->ba1.name.data0 = ioremap_nocache(card->ba1_addr + BA1_SP_DMEM0, CS461X_BA1_DATA0_SIZE);
- card->ba1.name.data1 = ioremap_nocache(card->ba1_addr + BA1_SP_DMEM1, CS461X_BA1_DATA1_SIZE);
- card->ba1.name.pmem = ioremap_nocache(card->ba1_addr + BA1_SP_PMEM, CS461X_BA1_PRG_SIZE);
- card->ba1.name.reg = ioremap_nocache(card->ba1_addr + BA1_SP_REG, CS461X_BA1_REG_SIZE);
-
- CS_DBGOUT(CS_INIT, 4, printk(KERN_INFO
- "cs46xx: card=0x%x card->ba0=0x%.08xn",(unsigned)card,(unsigned)card->ba0) );
- CS_DBGOUT(CS_INIT, 4, printk(KERN_INFO
- "cs46xx: card->ba1=0x%.08x 0x%.08x 0x%.08x 0x%.08xn",
- (unsigned)card->ba1.name.data0,
- (unsigned)card->ba1.name.data1,
- (unsigned)card->ba1.name.pmem,
- (unsigned)card->ba1.name.reg) );
- if(card->ba0 == 0 || card->ba1.name.data0 == 0 ||
- card->ba1.name.data1 == 0 || card->ba1.name.pmem == 0 ||
- card->ba1.name.reg == 0)
- goto fail2;
-
- if (request_irq(card->irq, &cs_interrupt, SA_SHIRQ, "cs46xx", card)) {
- printk(KERN_ERR "cs46xx: unable to allocate irq %dn", card->irq);
- goto fail2;
- }
- /* register /dev/dsp */
- if ((card->dev_audio = register_sound_dsp(&cs461x_fops, -1)) < 0) {
- printk(KERN_ERR "cs46xx: unable to register dspn");
- goto fail;
- }
- /* register /dev/midi */
- if((card->dev_midi = register_sound_midi(&cs_midi_fops, -1)) < 0)
- printk(KERN_ERR "cs46xx: unable to register midin");
-
- card->pm.flags |= CS46XX_PM_IDLE;
- for(i=0;i<5;i++)
- {
- if (cs_hardware_init(card) != 0)
- {
- CS_DBGOUT(CS_ERROR, 4, printk(
- "cs46xx: ERROR in cs_hardware_init()... retryingn"));
- for (j = 0; j < NR_AC97; j++)
- if (card->ac97_codec[j] != NULL) {
- unregister_sound_mixer(card->ac97_codec[j]->dev_mixer);
- kfree (card->ac97_codec[j]);
- }
- mdelay(10 * cs_laptop_wait);
- continue;
- }
- break;
- }
- if(i>=4)
- {
- CS_DBGOUT(CS_PM | CS_ERROR, 1, printk(
- "cs46xx: cs46xx_probe()- cs_hardware_init() failed, retried %d times.n",i));
- unregister_sound_dsp(card->dev_audio);
- if(card->dev_midi)
- unregister_sound_midi(card->dev_midi);
- goto fail;
- }
- init_waitqueue_head(&card->midi.open_wait);
- init_MUTEX(&card->midi.open_sem);
- init_waitqueue_head(&card->midi.iwait);
- init_waitqueue_head(&card->midi.owait);
- cs461x_pokeBA0(card, BA0_MIDCR, MIDCR_MRST);
- cs461x_pokeBA0(card, BA0_MIDCR, 0);
- /*
- * Check if we have to init the amplifier, but probably already done
- * since the CD logic in the ac97 init code will turn on the ext amp.
- */
- if(cp->amp_init)
- cp->amp_init(card);
- card->active_ctrl(card, -1);
- PCI_SET_DRIVER_DATA(pci_dev, card);
- PCI_SET_DMA_MASK(pci_dev, dma_mask);
- list_add(&card->list, &cs46xx_devs);
- pmdev = cs_pm_register(PM_PCI_DEV, PM_PCI_ID(pci_dev), cs46xx_pm_callback);
- if (pmdev)
- {
- CS_DBGOUT(CS_INIT | CS_PM, 4, printk(KERN_INFO
- "cs46xx: probe() pm_register() succeeded (0x%x).n",
- (unsigned)pmdev));
- pmdev->data = card;
- }
- else
- {
- CS_DBGOUT(CS_INIT | CS_PM | CS_ERROR, 2, printk(KERN_INFO
- "cs46xx: probe() pm_register() failed (0x%x).n",
- (unsigned)pmdev));
- card->pm.flags |= CS46XX_PM_NOT_REGISTERED;
- }
- CS_DBGOUT(CS_PM, 9, printk(KERN_INFO "cs46xx: pm.flags=0x%x card=0x%xn",
- (unsigned)card->pm.flags,(unsigned)card));
- CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
- "cs46xx: probe()- device allocated successfullyn"));
- return 0;
- fail:
- free_irq(card->irq, card);
- fail2:
- if(card->ba0)
- iounmap(card->ba0);
- if(card->ba1.name.data0)
- iounmap(card->ba1.name.data0);
- if(card->ba1.name.data1)
- iounmap(card->ba1.name.data1);
- if(card->ba1.name.pmem)
- iounmap(card->ba1.name.pmem);
- if(card->ba1.name.reg)
- iounmap(card->ba1.name.reg);
- kfree(card);
- CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_INFO
- "cs46xx: probe()- no device allocatedn"));
- return -ENODEV;
- } // probe_cs46xx
- // ---------------------------------------------------------------------
- static void __devinit cs46xx_remove(struct pci_dev *pci_dev)
- {
- struct cs_card *card = PCI_GET_DRIVER_DATA(pci_dev);
- int i;
- unsigned int tmp;
-
- CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
- "cs46xx: cs46xx_remove()+n"));
- card->active_ctrl(card,1);
-
- tmp = cs461x_peek(card, BA1_PFIE);
- tmp &= ~0x0000f03f;
- tmp |= 0x00000010;
- cs461x_poke(card, BA1_PFIE, tmp); /* playback interrupt disable */
- tmp = cs461x_peek(card, BA1_CIE);
- tmp &= ~0x0000003f;
- tmp |= 0x00000011;
- cs461x_poke(card, BA1_CIE, tmp); /* capture interrupt disable */
- /*
- * Stop playback DMA.
- */
- tmp = cs461x_peek(card, BA1_PCTL);
- cs461x_poke(card, BA1_PCTL, tmp & 0x0000ffff);
- /*
- * Stop capture DMA.
- */
- tmp = cs461x_peek(card, BA1_CCTL);
- cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
- /*
- * Reset the processor.
- */
- cs461x_reset(card);
- cs461x_proc_stop(card);
- /*
- * Power down the DAC and ADC. We will power them up (if) when we need
- * them.
- */
- if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
- CS_POWER_MIXVON, CS_TRUE )) )
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
- "cs46xx: cs461x_powerdown() failure (0x%x)n",tmp) );
- }
- /*
- * Power down the PLL.
- */
- cs461x_pokeBA0(card, BA0_CLKCR1, 0);
- /*
- * Turn off the Processor by turning off the software clock enable flag in
- * the clock control register.
- */
- tmp = cs461x_peekBA0(card, BA0_CLKCR1) & ~CLKCR1_SWCE;
- cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
- card->active_ctrl(card,-1);
- /* free hardware resources */
- free_irq(card->irq, card);
- iounmap(card->ba0);
- iounmap(card->ba1.name.data0);
- iounmap(card->ba1.name.data1);
- iounmap(card->ba1.name.pmem);
- iounmap(card->ba1.name.reg);
-
- /* unregister audio devices */
- for (i = 0; i < NR_AC97; i++)
- if (card->ac97_codec[i] != NULL) {
- unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
- kfree (card->ac97_codec[i]);
- }
- unregister_sound_dsp(card->dev_audio);
- if(card->dev_midi)
- unregister_sound_midi(card->dev_midi);
- list_del(&card->list);
- kfree(card);
- PCI_SET_DRIVER_DATA(pci_dev,NULL);
- CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
- "cs46xx: cs46xx_remove()-: remove successfuln"));
- }
- enum {
- CS46XX_4610 = 0,
- CS46XX_4612, /* same as 4630 */
- CS46XX_4615, /* same as 4624 */
- };
- static struct pci_device_id cs46xx_pci_tbl[] __devinitdata = {
-
- {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_4610, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CS46XX_4610},
- {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_4612, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CS46XX_4612},
- {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_4615, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CS46XX_4615},
- {0,}
- };
- MODULE_DEVICE_TABLE(pci, cs46xx_pci_tbl);
- struct pci_driver cs46xx_pci_driver = {
- name:"cs46xx",
- id_table:cs46xx_pci_tbl,
- probe:cs46xx_probe,
- remove:cs46xx_remove,
- suspend:CS46XX_SUSPEND_TBL,
- resume:CS46XX_RESUME_TBL,
- };
- int __init cs46xx_init_module(void)
- {
- int rtn = 0;
- CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
- "cs46xx: cs46xx_init_module()+ n"));
- if (!pci_present()) { /* No PCI bus in this machine! */
- CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
- "cs46xx: cs46xx_init_module()- no pci bus foundn"));
- return -ENODEV;
- }
- rtn = pci_module_init(&cs46xx_pci_driver);
- if(rtn == -ENODEV)
- {
- CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(
- "cs46xx: Unable to detect valid cs46xx devicen"));
- }
- CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
- printk(KERN_INFO "cs46xx: cs46xx_init_module()- (%d)n",rtn));
- return rtn;
- }
- void __exit cs46xx_cleanup_module(void)
- {
- pci_unregister_driver(&cs46xx_pci_driver);
- cs_pm_unregister_all(cs46xx_pm_callback);
- CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
- printk(KERN_INFO "cs46xx: cleanup_cs46xx() finishedn"));
- }
- module_init(cs46xx_init_module);
- module_exit(cs46xx_cleanup_module);
- int cs46xx_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
- {
- struct cs_card *card;
- CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
- "cs46xx: cs46xx_pm_callback dev=0x%x rqst=0x%x card=%dn",
- (unsigned)dev,(unsigned)rqst,(unsigned)data));
- card = (struct cs_card *) dev->data;
- if (card) {
- switch(rqst) {
- case PM_SUSPEND:
- CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
- "cs46xx: PM suspend requestn"));
- if(cs46xx_suspend(card, 0))
- {
- CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
- "cs46xx: PM suspend request refusedn"));
- return 1;
- }
- break;
- case PM_RESUME:
- CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
- "cs46xx: PM resume requestn"));
- if(cs46xx_resume(card))
- {
- CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
- "cs46xx: PM resume request refusedn"));
- return 1;
- }
- break;
- }
- }
- return 0;
- }
- #if CS46XX_ACPI_SUPPORT
- static int cs46xx_suspend_tbl(struct pci_dev *pcidev, u32 state)
- {
- struct cs_card *s = PCI_GET_DRIVER_DATA(pcidev);
- CS_DBGOUT(CS_PM | CS_FUNCTION, 2,
- printk(KERN_INFO "cs46xx: cs46xx_suspend_tbl requestn"));
- cs46xx_suspend(s, 0);
- return 0;
- }
- static int cs46xx_resume_tbl(struct pci_dev *pcidev)
- {
- struct cs_card *s = PCI_GET_DRIVER_DATA(pcidev);
- CS_DBGOUT(CS_PM | CS_FUNCTION, 2,
- printk(KERN_INFO "cs46xx: cs46xx_resume_tbl requestn"));
- cs46xx_resume(s);
- return 0;
- }
- #endif