diff options
author | Ricardo Cerqueira <devnull@localhost> | 2006-01-05 01:45:00 +0000 |
---|---|---|
committer | Ricardo Cerqueira <devnull@localhost> | 2006-01-05 01:45:00 +0000 |
commit | 0cc31265cf7c304af6c1c95e5ea88a9ab0fba55c (patch) | |
tree | 6188262c246fedc861cca25e8d9b4fdd594edc8f /linux/drivers/media/video | |
parent | a2d5e8c9749f3879aeb871992113bef4e5005a3d (diff) | |
download | mediapointer-dvb-s2-0cc31265cf7c304af6c1c95e5ea88a9ab0fba55c.tar.gz mediapointer-dvb-s2-0cc31265cf7c304af6c1c95e5ea88a9ab0fba55c.tar.bz2 |
Cleanup old code and debug from cx88-alsa
From: Ricardo Cerqueira <v4l@cerqueira.org>
Cleaned up some code and excessive debug left behind during development
Signed-off-by:
Diffstat (limited to 'linux/drivers/media/video')
-rw-r--r-- | linux/drivers/media/video/cx88/cx88-alsa.c | 249 |
1 files changed, 57 insertions, 192 deletions
diff --git a/linux/drivers/media/video/cx88/cx88-alsa.c b/linux/drivers/media/video/cx88/cx88-alsa.c index 145afd07c..020d49166 100644 --- a/linux/drivers/media/video/cx88/cx88-alsa.c +++ b/linux/drivers/media/video/cx88/cx88-alsa.c @@ -1,13 +1,12 @@ /* - * $Id: cx88-alsa.c,v 1.24 2006/01/04 03:15:34 rmcc Exp $ + * $Id: cx88-alsa.c,v 1.25 2006/01/05 01:45:00 rmcc Exp $ * * Support for audio capture * PCI function #1 of the cx2388x. * - * (c) 2006 Ricardo Cerqueira <v4l@cerqueira.org> + * (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org> * (c) 2005 Mauro Carvalho Chehab <mchehab@brturbo.com.br> * Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org> - * Based on bt87x.c by Clemens Ladisch <clemens@ladisch.de> * Based on dummy.c by Jaroslav Kysela <perex@suse.cz> * * This program is free software; you can redistribute it and/or modify @@ -52,39 +51,19 @@ Data type declarations - Can be moded to a header file later ****************************************************************************/ -#if 1 -#define ANALOG_CLOCK 1792000 -#define CLOCK_DIV_MIN 4 -#define CLOCK_DIV_MAX 15 -#define MAX_PCM_DEVICES 4 -#define MAX_PCM_SUBSTREAMS 16 -#endif - -enum { DEVICE_DIGITAL, DEVICE_ANALOG }; - /* These can be replaced after done */ #define MIXER_ADDR_LAST MAX_CX88_INPUT -struct cx8801_fh { - struct cx88_audio_dev *dev; - struct videobuf_queue vb_q; - - int size; -}; - struct cx88_audio_dev { struct cx88_core *core; struct cx88_dmaqueue q; - struct cx8801_fh *fh; - /* pci i/o */ struct pci_dev *pci; unsigned char pci_rev,pci_lat; /* audio controls */ int irq; - int dig_rate; /* Digital sampling rate */ snd_card_t *card; @@ -93,34 +72,23 @@ struct cx88_audio_dev { unsigned int dma_size; unsigned int period_size; unsigned int num_periods; - unsigned int current_period; struct videobuf_dmabuf dma_risc; - struct snd_dma_buffer alsa_risc; int mixer_volume[MIXER_ADDR_LAST+1][2]; int capture_source[MIXER_ADDR_LAST+1][2]; - long int bufsize; long int read_count; long int read_offset; + struct cx88_buffer *buf; - u32 __iomem *mmio; long opened; snd_pcm_substream_t *substream; }; typedef struct cx88_audio_dev snd_cx88_card_t; -typedef struct snd_card_cx88_pcm { - struct cx88_dev *dev; - - spinlock_t lock; - - snd_pcm_substream_t *substream; -} snd_card_cx88_pcm_t; - #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,8) #define chip_t snd_cx88_card_t @@ -133,11 +101,6 @@ typedef struct snd_card_cx88_pcm { static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1}; -#if 0 -static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; -static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; -static snd_cx88_card_t *snd_dummy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; -#endif static snd_card_t *snd_cx88_cards[SNDRV_CARDS]; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) @@ -148,6 +111,14 @@ module_param_array(enable, bool, NULL, 0444); #endif MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled."); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) +module_param_array(index, int, dummy, 0444); +#else +module_param_array(index, int, NULL, 0444); +#endif +MODULE_PARM_DESC(index, "Index value for cx88x capture interface(s)."); + + /**************************************************************************** Module macros ****************************************************************************/ @@ -179,12 +150,8 @@ int _cx88_start_audio_dma(snd_cx88_card_t *chip) dprintk(1, "Starting audio DMA for %i bpl and %i (%i) lines at ptr2 %08x\n",buf->bpl, chip->num_periods, audio_ch->fifo_size / buf->bpl, audio_ch->fifo_start); - //dprintk(1, "Starting audio DMA at RISC %08lx for %i bpl\n",(unsigned long)buf->risc.dma,buf->bpl); /* setup fifo + format - out channel */ - //cx88_sram_channel_setup(chip->core, audio_ch, buf->bpl, 0); - - //snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), audio_ch->fifo_size, &chip->alsa_risc); cx88_sram_channel_setup(chip->core, &cx88_sram_channels[SRAM_CH25], buf->bpl, buf->risc.dma); @@ -192,37 +159,24 @@ int _cx88_start_audio_dma(snd_cx88_card_t *chip) cx_write(MO_AUDD_LNGTH, buf->bpl); /* reset counter */ - //cx_write(MO_AUDD_GPCNTRL,GP_COUNT_CONTROL_RESET); + cx_write(MO_AUDD_GPCNTRL,GP_COUNT_CONTROL_RESET); dprintk(1,"Enabling IRQ, setting mask from 0x%x to 0x%x\n",chip->core->pci_irqmask,(chip->core->pci_irqmask | 0x02)); /* enable irqs */ - cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | 0x02); + cx_set(MO_PCI_INTMSK, 0x02); /* Enables corresponding bits at AUD_INT_STAT */ -#if 1 /*keep*/ - /* Maybe necessary to enable other errors */ - //cx_set(MO_AUD_INTMSK, (1<<21)||(1<<19)||(1<<16)||1); - cx_set(MO_AUD_INTMSK, - (1<<21)| - (1<<20)| - (1<<19)| - (1<<18)| - (1<<17)| + cx_write(MO_AUD_INTMSK, (1<<16)| (1<<12)| (1<<4)| (1<<0) ); -#endif - - //dprintk(2, "Is queue reading? A: %x\n",chip->fh->vb_q.reading); /* start dma */ cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */ - cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */ - - chip->current_period = 0; + cx_write(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */ if (debug) cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]); @@ -237,12 +191,13 @@ int _cx88_stop_audio_dma(snd_cx88_card_t *chip) { struct cx88_core *core=chip->core; dprintk(1, "Stopping audio DMA\n"); + /* stop dma */ cx_clear(MO_AUD_DMACNTRL, 0x11); /* disable irqs */ - cx_clear(MO_PCI_INTMSK, 0x000002); - cx_set(MO_AUD_INTMSK, 0); + cx_clear(MO_PCI_INTMSK, 0x02); + cx_write(MO_AUD_INTMSK, 0); if (debug) cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]); @@ -284,7 +239,7 @@ static void cx8801_aud_irq(snd_cx88_card_t *chip) return; } cx_write(MO_AUD_INTSTAT, status); - if (debug || (status & mask & ~0xff)) + if (debug > 1 || (status & mask & ~0xff)) cx88_print_irqbits(core->name, "irq aud", cx88_aud_irqs, status, mask); /* risc op code error */ @@ -296,25 +251,21 @@ static void cx8801_aud_irq(snd_cx88_card_t *chip) /* risc1 downstream */ if (status & 0x01) { - printk("AUDIO DATA!\n"); spin_lock(&chip->reg_lock); count = cx_read(MO_AUDD_GPCNT); -// cx88_wakeup(core, &chip->q, count); spin_unlock(&chip->reg_lock); - chip->read_count += chip->dma_size; - chip->current_period = (chip->current_period + 1) % chip->num_periods; - snd_pcm_period_elapsed(chip->substream); + if (chip->read_count == 0) + chip->read_count += chip->dma_size; } - printk("Still kicking...\n"); if (chip->read_count >= chip->period_size) { - printk("Elapsing?\n"); + dprintk(2, "Elapsing period\n"); spin_lock(&chip->reg_lock); - //snd_pcm_period_elapsed(chip->substream); + snd_pcm_period_elapsed(chip->substream); spin_unlock(&chip->reg_lock); } - printk("Leaving audio IRQ handler...\n"); + dprintk(3,"Leaving audio IRQ handler...\n"); /* FIXME: Any other status should deserve a special handling? */ } @@ -333,15 +284,15 @@ static irqreturn_t cx8801_irq(int irq, void *dev_id, struct pt_regs *regs) status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x02); if (0 == status) goto out; - //dprintk( 3, "cx8801_irq\n" ); - //dprintk( 3, " loop: %d/%d\n", loop, MAX_IRQ_LOOP ); - //dprintk( 3, " status: %d\n", status ); + dprintk( 3, "cx8801_irq\n" ); + dprintk( 3, " loop: %d/%d\n", loop, MAX_IRQ_LOOP ); + dprintk( 3, " status: %d\n", status ); handled = 1; cx_write(MO_PCI_INTSTAT, status); if (status & 0x02) { - dprintk( 1, " ALSA IRQ handling\n" ); + dprintk( 2, " ALSA IRQ handling\n" ); cx8801_aud_irq(chip); } }; @@ -350,7 +301,7 @@ static irqreturn_t cx8801_irq(int irq, void *dev_id, struct pt_regs *regs) dprintk( 0, "clearing mask\n" ); dprintk(1,"%s/0: irq loop -- clearing mask\n", core->name); - cx_write(MO_PCI_INTMSK,0); + cx_clear(MO_PCI_INTMSK,0x02); } out: @@ -362,7 +313,11 @@ static int dsp_buffer_free(snd_cx88_card_t *chip) { BUG_ON(!chip->dma_size); -// videobuf_dma_free(&chip->dma_risc); + dprintk(2,"Freeing buffer\n"); + videobuf_dma_pci_unmap(chip->pci, &chip->dma_risc); + videobuf_dma_free(&chip->dma_risc); + btcx_riscmem_free(chip->pci,&chip->buf->risc); + kfree(chip->buf); chip->dma_size = 0; @@ -383,10 +338,10 @@ static snd_pcm_hardware_t snd_cx88_digital_hw = { SNDRV_PCM_INFO_MMAP_VALID, .formats = SNDRV_PCM_FMTBIT_S16_LE, - .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000, - .rate_min = 32000, - .rate_max = 96000, - .channels_min = 1, + .rates = SNDRV_PCM_RATE_48000, + .rate_min = 48000, + .rate_max = 48000, + .channels_min = 2, .channels_max = 2, .buffer_bytes_max = (4*1024), .period_bytes_min = 1024, @@ -400,9 +355,6 @@ static snd_pcm_hardware_t snd_cx88_digital_hw = { */ static void snd_card_cx88_runtime_free(snd_pcm_runtime_t *runtime) { - snd_pcm_hardware_t *pcm = runtime->private_data; - - kfree(pcm); } /* * audio pcm capture open callback @@ -411,10 +363,8 @@ static int snd_cx88_pcm_open(snd_pcm_substream_t *substream) { snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; - snd_card_cx88_pcm_t *pcm; int err; - dprintk(1,"Opening PCM!\n"); if (test_and_set_bit(0, &chip->opened)) return -EBUSY; @@ -427,20 +377,9 @@ static int snd_cx88_pcm_open(snd_pcm_substream_t *substream) chip->read_count = 0; chip->read_offset = 0; - pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); - if (pcm == NULL) { - err=-ENOMEM; - goto _error; - } - - spin_lock_init(&pcm->lock); - - pcm->substream = substream; - runtime->private_data = pcm; runtime->private_free = snd_card_cx88_runtime_free; runtime->hw = snd_cx88_digital_hw; - dprintk(1,"Opened PCM!\n"); return 0; _error: dprintk(1,"Error opening PCM!\n"); @@ -456,11 +395,9 @@ static int snd_cx88_close(snd_pcm_substream_t *substream) { snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); - - dprintk(2,"PCM close\n"); clear_bit(0, &chip->opened); smp_mb__after_clear_bit(); - dprintk(2,"Returning from PCM close\n"); + return 0; } @@ -473,13 +410,8 @@ static int snd_cx88_hw_params(snd_pcm_substream_t * substream, snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); struct cx88_buffer *buf; - printk("ALSA HW_params\n"); - - - if (substream->runtime->dma_area) { - //videobuf_read_stop(&chip->fh->vb_q); - //videobuf_dma_pci_unmap(chip->pci, &chip->dma_risc); - //dsp_buffer_free(chip); + if (substream->runtime->dma_area) { + dsp_buffer_free(chip); substream->runtime->dma_area = NULL; } @@ -492,9 +424,6 @@ static int snd_cx88_hw_params(snd_pcm_substream_t * substream, dprintk(1,"Setting buffer\n"); - - //dsp_buffer_init(chip); - buf = kmalloc(sizeof(*buf),GFP_KERNEL); if (NULL == buf) return -ENOMEM; @@ -517,13 +446,6 @@ static int snd_cx88_hw_params(snd_pcm_substream_t * substream, cx88_risc_databuffer(chip->pci, &buf->risc, buf->vb.dma.sglist, buf->vb.width, buf->vb.height); -#if 0 - cx88_risc_buffer(chip->pci, &buf->risc, - buf->vb.dma.sglist, - 0, buf->vb.width * buf->vb.height, - buf->vb.width, 0, - buf->vb.height); -#endif buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); @@ -547,17 +469,11 @@ static int snd_cx88_hw_free(snd_pcm_substream_t * substream) snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); - dprintk(2,"HW free\n"); if (substream->runtime->dma_area) { - dprintk(2,"Freeing buffer\n"); - videobuf_dma_pci_unmap(chip->pci, &chip->dma_risc); - videobuf_dma_free(&chip->dma_risc); - btcx_riscmem_free(chip->pci,&chip->buf->risc); - kfree(chip->buf); dsp_buffer_free(chip); substream->runtime->dma_area = NULL; } - dprintk(2,"Returning from HW free\n"); + return 0; } @@ -566,14 +482,6 @@ static int snd_cx88_hw_free(snd_pcm_substream_t * substream) */ static int snd_cx88_prepare(snd_pcm_substream_t *substream) { - //snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); - - printk("ALSA Prepare\n"); - //spin_lock_irq(&chip->reg_lock); - - //err = dsp_buffer_init(chip); - -// spin_unlock_irq(&chip->reg_lock); return 0; } @@ -584,21 +492,15 @@ static int snd_cx88_prepare(snd_pcm_substream_t *substream) static int snd_cx88_card_trigger(snd_pcm_substream_t *substream, int cmd) { snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); - //struct cx8801_fh *fh = chip->fh; int err; - dprintk(2,"PCM Trigger cmd=%d\n",cmd); spin_lock(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: - dprintk(1,"start stream\n"); - //err=videobuf_streamon(&fh->vb_q); err=_cx88_start_audio_dma(chip); break; case SNDRV_PCM_TRIGGER_STOP: - dprintk(1,"stop stream\n"); - //err=videobuf_streamoff(&fh->vb_q); err=_cx88_stop_audio_dma(chip); break; default: @@ -608,7 +510,6 @@ static int snd_cx88_card_trigger(snd_pcm_substream_t *substream, int cmd) spin_unlock(&chip->reg_lock); - dprintk(2,"Leaving PCM Trigger\n"); return err; } @@ -619,19 +520,17 @@ static snd_pcm_uframes_t snd_cx88_pointer(snd_pcm_substream_t *substream) { snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; - //struct cx88_core *core = chip->core; if (chip->read_count) { - chip->read_count -= snd_pcm_lib_period_bytes(substream); - chip->read_offset += snd_pcm_lib_period_bytes(substream); - if (chip->read_offset == chip->dma_size) - chip->read_offset = 0; + chip->read_count -= snd_pcm_lib_period_bytes(substream); + chip->read_offset += snd_pcm_lib_period_bytes(substream); + if (chip->read_offset == chip->dma_size) + chip->read_offset = 0; } - printk("Pointer time, will return %li, read %li\n",chip->read_offset,chip->read_count); + + dprintk(2, "Pointer time, will return %li, read %li\n",chip->read_offset,chip->read_count); return bytes_to_frames(runtime, chip->read_offset); -// printk("Pointer time, will return %li\n",chip->current_period * chip->period_size); -// return (snd_pcm_uframes_t)bytes_to_frames(runtime, chip->current_period * chip->period_size); } /* @@ -646,7 +545,6 @@ static snd_pcm_ops_t snd_cx88_pcm_ops = { .prepare = snd_cx88_prepare, .trigger = snd_cx88_card_trigger, .pointer = snd_cx88_pointer, - //.page = snd_pcm_sgbuf_ops_page, }; /* @@ -739,14 +637,12 @@ MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl); static int snd_cx88_free(snd_cx88_card_t *chip) { - dprintk(1,"cx88 free\n"); if (chip->irq >= 0){ synchronize_irq(chip->irq); free_irq(chip->irq, chip); } - //btcx_riscmem_free(chip->pci,&chip->q.stopper); cx88_core_put(chip->core,chip->pci); pci_disable_device(chip->pci); @@ -760,7 +656,6 @@ static void snd_cx88_dev_free(snd_card_t * card) { snd_cx88_card_t *chip = card->private_data; - dprintk(1,"cx88 dev free\n"); snd_cx88_free(chip); } @@ -782,16 +677,20 @@ static int __devinit snd_cx88_create(snd_card_t *card, struct pci_dev *pci, err = pci_enable_device(pci); if (err < 0) return err; + pci_set_master(pci); + chip = (snd_cx88_card_t *) card->private_data; + + core = cx88_core_get(pci); + if (!pci_dma_supported(pci,0xffffffff)) { dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n",core->name); err = -EIO; + cx88_core_put(core,pci); return err; } - chip = (snd_cx88_card_t *) card->private_data; - /* pci init */ chip->card = card; @@ -799,7 +698,6 @@ static int __devinit snd_cx88_create(snd_card_t *card, struct pci_dev *pci, chip->irq = -1; spin_lock_init(&chip->reg_lock); - core = cx88_core_get(chip->pci); cx88_reset(core); if (NULL == core) { err = -EINVAL; @@ -808,13 +706,6 @@ static int __devinit snd_cx88_create(snd_card_t *card, struct pci_dev *pci, } chip->core = core; - -#if 1 /* Should be tested if it is right */ - chip->dig_rate=48000; -#endif - -#if 1 /* From cx88-mpeg.c */ - /* get irq */ err = request_irq(chip->pci->irq, cx8801_irq, SA_SHIRQ | SA_INTERRUPT, chip->core->name, chip); @@ -823,8 +714,6 @@ static int __devinit snd_cx88_create(snd_card_t *card, struct pci_dev *pci, chip->core->name, chip->pci->irq); return err; } - cx_set(MO_PCI_INTMSK, core->pci_irqmask); -#endif /* print pci info */ pci_read_config_byte(pci, PCI_CLASS_REVISION, &chip->pci_rev); @@ -870,8 +759,8 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci, if (err < 0) return (err); - //err = snd_cx88_pcm(chip, DEVICE_DIGITAL, "CX88 Digital"); err = snd_cx88_pcm(chip, 0, "CX88 Digital"); + if (err < 0) { snd_card_free(card); return (err); @@ -883,13 +772,13 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci, return (err); } - strcpy (card->driver, "CX88_ALSA"); + strcpy (card->driver, "CX88x"); sprintf(card->shortname, "Conexant CX%x", pci->device); sprintf(card->longname, "%s at %#lx", card->shortname, pci_resource_start(pci, 0)); strcpy (card->mixername, "CX88"); - dprintk (0, "%s/%i: Alsa support for cx2388x boards\n", + dprintk (0, "%s/%i: ALSA support for cx2388x boards\n", card->driver,devno); err = snd_card_register(card); @@ -910,25 +799,9 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci, static void __devexit cx88_audio_finidev(struct pci_dev *pci) { struct cx88_audio_dev *card = pci_get_drvdata(pci); - //struct cx88_core *core = card->core; - - //_cx88_stop_audio_dma(card); - -// pci_disable_device(pci); - - /* unregister stuff */ - -// free_irq(pci->irq, card); - - /* free memory */ - -// btcx_riscmem_free(card->pci,&card->q.stopper); - //cx88_core_put(core,card->pci); snd_card_free((void *)card); - //kfree(card); - pci_set_drvdata(pci, NULL); devno--; @@ -976,14 +849,6 @@ static int cx88_audio_init(void) static void cx88_audio_fini(void) { -/* - int idx; - printk(KERN_INFO "cx88 fini\n"); - for (idx = 0; idx < SNDRV_CARDS; idx++) { - snd_card_free(snd_cx88_cards[idx]); - snd_cx88_cards[idx] = NULL; - }*/ - pci_unregister_driver(&cx88_audio_pci_driver); } |