V4L (951) Make saa7134-oss as a stand-alone module
PATCH 13/20 V4L (951) Make saa7134-oss as a stand-alone module
From: Ricardo Cerqueira <[email protected]>
- saa7134-oss is now a standalone module as well
- remaining DMA sound code has been removed from core the module
- Lots of small cleanups and variable renames to get more consistency between the OSS and ALSA drivers
- Fixed saa7134-alsa spinlock bug
- Added missing #include in saa7134-oss
-----------------
drivers/media/video/saa7134/Makefile | 7 - drivers/media/video/saa7134/saa7134-alsa.c | 130 +++++++++++------------ drivers/media/video/saa7134/saa7134-core.c | 118 +++++--------------- drivers/media/video/saa7134/saa7134-oss.c | 163 ++++++++++++++++++++++++++--- drivers/media/video/saa7134/saa7134.h | 1 5 files changed, 251 insertions(+), 168 deletions(-)
drivers/media/video/saa7134/Makefile +4 -3
@@ -1,10 +1,11 @@ saa7134-objs := saa7134-cards.o saa7134-core.o saa7134-i2c.o \ - saa7134-oss.o saa7134-ts.o saa7134-tvaudio.o \ - saa7134-vbi.o saa7134-video.o saa7134-input.o + saa7134-ts.o saa7134-tvaudio.o saa7134-vbi.o \ + saa7134-video.o saa7134-input.o obj-$(CONFIG_VIDEO_SAA7134) += saa7134.o saa7134-empress.o \ - saa6752hs.o saa7134-alsa.o + saa6752hs.o saa7134-alsa.o \ + saa7134-oss.o obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o EXTRA_CFLAGS += -I$(src)/..
drivers/media/video/saa7134/saa7134-alsa.c +66 -64
307 lines not on this page · raw message
drivers/media/video/saa7134/saa7134-core.c +30 -88
224 lines not on this page · raw message
drivers/media/video/saa7134/saa7134.h +1 -0
@@ -383,6 +383,7 @@ struct saa7134_dmasound {unsigned int dma_blk;unsigned int read_offset;unsigned int read_count; +void * priv_data;snd_pcm_substream_t *substream; };
drivers/media/video/saa7134/saa7134-oss.c +150 -13
221 lines not on this page · raw message
_______________________________________________________
Yahoo! Acesso Gr�tis: Internet r�pida e gr�tis.
Instale o discador agora!
http://br.acesso.yahoo.com/
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
At Thu, 10 Nov 2005 18:50:02 -0200,
Quoted 10 lines · [email protected] wrote:
From: Ricardo Cerqueira <[email protected]>
- saa7134-oss is now a standalone module as well
- remaining DMA sound code has been removed from core the module
- Lots of small cleanups and variable renames to get more consistency between the OSS and ALSA drivers
- Fixed saa7134-alsa spinlock bug
- Added missing #include in saa7134-oss
Quoted 2 lines
Signed-off-by Ricardo Cerqueira <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>
This version still looks including a couple of bugs.
The below is a fix patch (untested, sorry) for the previous version. Please check it for the next fix.
Takashi
---
saa7134-alsa.c renamed from saa7134-alsa.c-dist +118 -174
@@ -104,9 +104,6 @@ typedef struct snd_card_saa7134_pcm {struct saa7134_dev *saadev;spinlock_t lock; -unsigned int pcm_size;/* buffer size */ -unsigned int pcm_count;/* bytes per period */ -unsigned int pcm_bps;/* bytes per second */ snd_pcm_substream_t *substream; } snd_card_saa7134_pcm_t;
@@ -185,8 +182,9 @@ void saa7134_irq_alsa_done(struct saa713if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2 )) {dprintk ("irq: overrun [full=%d/%d] - Blocks in %d\n" ,dev->dmasound.read_count, dev->dmasound.bufsize, dev->dmasound.blocks); +spin_unlock (&dev->slock);snd_pcm_stop (dev->dmasound.substream,SNDRV_PCM_STATE_XRUN ); - goto done; +return ; }/* next block addr */
@@ -267,7 +265,7 @@ static int snd_card_saa7134_capture_trigstruct saa7134_dev *dev=saapcm->saadev;int err =0 ; -spin_lock_irq (&dev->slock); +spin_lock (&dev->slock);if (cmd ==SNDRV_PCM_TRIGGER_START ) {/* start dma */ saa7134_dma_start (dev);
@@ -277,45 +275,12 @@ static int snd_card_saa7134_capture_trig }else { err = -EINVAL ; } -spin_unlock_irq (&dev->slock); +spin_unlock (&dev->slock);return err; }/* -* DMA buffer config -* -* Sets the values that will later be used as the size of the buffer, -* size of the fragments, and total number of fragments. -* Must be called during the preparation stage, before memory is -* allocated -* -* - Copied verbatim from saa7134-oss. -* -*/ - -static int dsp_buffer_conf (struct saa7134_dev *dev,int blksize,int blocks) -{ -if (blksize <0x100 ) - blksize =0x100 ; -if (blksize >0x10000 ) - blksize =0x10000 ; - -if (blocks <2 ) - blocks =2 ; -if ((blksize * blocks) >1024 *1024 ) - blocks =1024 *1024 / blksize; - - dev->dmasound.blocks = blocks; - dev->dmasound.blksize = blksize; - dev->dmasound.bufsize = blksize * blocks; - -dprintk ("buffer config: %d blocks / %d bytes, %d kB total\n" , - blocks,blksize,blksize * blocks /1024 ); -return 0 ; -} - -/* * DMA buffer initialization * * Uses V4L functions to initialize the DMA. Shouldn't be necessary in
@@ -341,6 +306,27 @@ static int dsp_buffer_init(struct saa713 }/* +* DMA buffer release +* +* Called after closing the device, during snd_card_saa7134_capture_close +* +*/ + +static int dsp_buffer_free (struct saa7134_dev *dev) +{ +if (!dev->dmasound.blksize) +BUG (); + +videobuf_dma_free (&dev->dmasound.dma); + + dev->dmasound.blocks =0 ; + dev->dmasound.blksize =0 ; + dev->dmasound.bufsize =0 ; + +return 0 ; +} + +/* * ALSA PCM preparation * * - One of the ALSA capture callbacks.
@@ -360,79 +346,24 @@ static int snd_card_saa7134_capture_prepsnd_card_saa7134_t *saa7134 =snd_pcm_substream_chip (substream);struct saa7134_dev *dev;snd_card_saa7134_pcm_t *saapcm = runtime->private_data; -unsigned int bps; -unsigned long size; -unsigned count; - - size =snd_pcm_lib_buffer_bytes (substream); - count =snd_pcm_lib_period_bytes (substream); saapcm->saadev->dmasound.substream = substream; - bps = runtime->rate * runtime->channels; - bps *=snd_pcm_format_width (runtime->format); - bps /=8 ; -if (bps <=0 ) -return -EINVAL ; - saapcm->pcm_bps = bps; - saapcm->pcm_size =snd_pcm_lib_buffer_bytes (substream); - saapcm->pcm_count =snd_pcm_lib_period_bytes (substream); - - - dev=saa7134->saadev; - -dsp_buffer_conf (dev,saapcm->pcm_count,(saapcm->pcm_size/saapcm->pcm_count)); - - err =dsp_buffer_init (dev); -if (0 != err) -return err; + dev = saa7134->saadev; -/* prepare buffer */ -if (0 != (err =videobuf_dma_pci_map (dev->pci,&dev->dmasound.dma))) -return err; -if (0 != (err =saa7134_pgtable_alloc (dev->pci,&dev->dmasound.pt))) - goto fail1; -if (0 != (err =saa7134_pgtable_build (dev->pci,&dev->dmasound.pt, - dev->dmasound.dma.sglist, - dev->dmasound.dma.sglen, -0 ))) - goto fail2; - - - -switch (runtime->format) { -case SNDRV_PCM_FORMAT_U8 : -case SNDRV_PCM_FORMAT_S8 : +if (snd_pcm_format_width (runtime->format) ==8 ) fmt =0x00 ; -break ; -case SNDRV_PCM_FORMAT_U16_LE : -case SNDRV_PCM_FORMAT_U16_BE : -case SNDRV_PCM_FORMAT_S16_LE : -case SNDRV_PCM_FORMAT_S16_BE : +else fmt =0x01 ; -break ; -default : - err = -EINVAL ; -return 1 ; - } -switch (runtime->format) { -case SNDRV_PCM_FORMAT_S8 : -case SNDRV_PCM_FORMAT_S16_LE : -case SNDRV_PCM_FORMAT_S16_BE : +if (snd_pcm_format_signed (runtime->format)) sign =1 ; -break ; -default : +else sign =0 ; -break ; - } -switch (runtime->format) { -case SNDRV_PCM_FORMAT_U16_BE : -case SNDRV_PCM_FORMAT_S16_BE : - bswap =1 ;break ; -default : - bswap =0 ;break ; - } +if (snd_pcm_format_big_endian (runtime->format)) + bswap =1 ; +else + bswap =0 ;switch (dev->pci->device) {case PCI_DEVICE_ID_PHILIPS_SAA7134 :
@@ -474,12 +405,6 @@ static int snd_card_saa7134_capture_prepif (bswap) control |=SAA7134_RS_CONTROL_BSWAP ; -/* I should be able to use runtime->dma_addr in the control -byte, but it doesn't work. So I allocate the DMA using the -V4L functions, and force ALSA to use that as the DMA area */ - - runtime->dma_area = dev->dmasound.dma.vmalloc; -saa_writel (SAA7134_RS_BA1 (6 ),0 );saa_writel (SAA7134_RS_BA2 (6 ),dev->dmasound.blksize);saa_writel (SAA7134_RS_PITCH (6 ),0 );
@@ -488,13 +413,6 @@ static int snd_card_saa7134_capture_prep dev->dmasound.rate = runtime->rate;return 0 ; - fail2: -saa7134_pgtable_free (dev->pci,&dev->dmasound.pt); - fail1: -videobuf_dma_pci_unmap (dev->pci,&dev->dmasound.dma); -return err; - - }/*
@@ -567,16 +485,77 @@ static void snd_card_saa7134_runtime_fre* - One of the ALSA capture callbacks. * * Called on initialization, right before the PCM preparation -* Usually used in ALSA to allocate the DMA, but since we don't use the -* ALSA DMA it does nothing * */ static int snd_card_saa7134_hw_params (snd_pcm_substream_t * substream, -snd_pcm_hw_params_t * hw_params) +snd_pcm_hw_params_t * hw_params) { -return 0 ; +snd_card_saa7134_t *saa7134 =snd_pcm_substream_chip (substream); +struct saa7134_dev *dev; +unsigned int period_size, periods; +int err; + + period_size =params_period_bytes (hw_params); + periods =params_periods (hw_params); + +snd_assert (period_size >=0x100 && period_size <=0x10000 , + return -EINVAL ); +snd_assert (periods >=2 , return -EINVAL ); +snd_assert (period_size * periods <=1024 *1024 , return -EINVAL ); + + dev = saa7134->saadev; + +if (dev->dmasound.blocks == periods && + dev->dmasound.blksize == period_size) +return 0 ; + +/* release the old buffer */ +if (substream->runtime->dma_area) { +saa7134_pgtable_free (dev->pci, &dev->dmasound.pt); +videobuf_dma_pci_unmap (dev->pci, &dev->dmasound.dma); +dsp_buffer_free (dev); + substream->runtime->dma_area =NULL ; + } + dev->dmasound.blocks = periods; + dev->dmasound.blksize = period_size; + dev->dmasound.bufsize = period_size * periods; + + err =dsp_buffer_init (dev); +if (0 != err) { + dev->dmasound.blocks =0 ; + dev->dmasound.blksize =0 ; + dev->dmasound.bufsize =0 ; +return err; + } + +if (0 != (err =videobuf_dma_pci_map (dev->pci, &dev->dmasound.dma))) { +dsp_buffer_free (dev); +return err; + } +if (0 != (err =saa7134_pgtable_alloc (dev->pci,&dev->dmasound.pt))) { +videobuf_dma_pci_unmap (dev->pci, &dev->dmasound.dma); +dsp_buffer_free (dev); +return err; + } +if (0 != (err =saa7134_pgtable_build (dev->pci,&dev->dmasound.pt, + dev->dmasound.dma.sglist, + dev->dmasound.dma.sglen, +0 ))) { +saa7134_pgtable_free (dev->pci, &dev->dmasound.pt); +videobuf_dma_pci_unmap (dev->pci, &dev->dmasound.dma); +dsp_buffer_free (dev); +return err; + } + +/* I should be able to use runtime->dma_addr in the control +byte, but it doesn't work. So I allocate the DMA using the +V4L functions, and force ALSA to use that as the DMA area */ + + substream->runtime->dma_area = dev->dmasound.dma.vmalloc; + +return 1 ; }/*
@@ -585,33 +564,23 @@ static int snd_card_saa7134_hw_params(sn* - One of the ALSA capture callbacks. * * Called after closing the device, but before snd_card_saa7134_capture_close -* Usually used in ALSA to free the DMA, but since we don't use the -* ALSA DMA I'm almost sure this isn't necessary. +* It stops the DMA audio and releases the buffers. * */ static int snd_card_saa7134_hw_free (snd_pcm_substream_t * substream) { -return 0 ; -} - -/* -* DMA buffer release -* -* Called after closing the device, during snd_card_saa7134_capture_close -* -*/ - -static int dsp_buffer_free (struct saa7134_dev *dev) -{ -if (!dev->dmasound.blksize) -BUG (); +snd_card_saa7134_t *saa7134 =snd_pcm_substream_chip (substream); +struct saa7134_dev *dev; -videobuf_dma_free (&dev->dmasound.dma); + dev = saa7134->saadev; - dev->dmasound.blocks =0 ; - dev->dmasound.blksize =0 ; - dev->dmasound.bufsize =0 ; +if (substream->runtime->dma_area) { +saa7134_pgtable_free (dev->pci, &dev->dmasound.pt); +videobuf_dma_pci_unmap (dev->pci, &dev->dmasound.dma); +dsp_buffer_free (dev); + substream->runtime->dma_area =NULL ; + }return 0 ; }
@@ -621,21 +590,12 @@ static int dsp_buffer_free(struct saa713* * - One of the ALSA capture callbacks. * -* Called after closing the device. It stops the DMA audio and releases -* the buffers +* Called after closing the device. * */ static int snd_card_saa7134_capture_close (snd_pcm_substream_t * substream) { -snd_card_saa7134_t *chip =snd_pcm_substream_chip (substream); -struct saa7134_dev *dev = chip->saadev; - -/* unlock buffer */ -saa7134_pgtable_free (dev->pci,&dev->dmasound.pt); -videobuf_dma_pci_unmap (dev->pci,&dev->dmasound.dma); - -dsp_buffer_free (dev);return 0 ; }
@@ -749,7 +709,6 @@ static int snd_saa7134_volume_get(snd_kcstatic int snd_saa7134_volume_put (snd_kcontrol_t * kcontrol,snd_ctl_elem_value_t * ucontrol) {snd_card_saa7134_t *chip =snd_kcontrol_chip (kcontrol); -unsigned long flags;int change, addr = kcontrol->private_value;int left, right;
@@ -763,12 +722,12 @@ static int snd_saa7134_volume_put(snd_kc right =0 ;if (right >20 ) right =20 ; -spin_lock_irqsave (&chip->mixer_lock, flags); +spin_lock_irq (&chip->mixer_lock); change = chip->mixer_volume[addr][0 ] != left || chip->mixer_volume[addr][1 ] != right; chip->mixer_volume[addr][0 ] = left; chip->mixer_volume[addr][1 ] = right; -spin_unlock_irqrestore (&chip->mixer_lock, flags); +spin_unlock_irq (&chip->mixer_lock);return change; }
@@ -790,13 +749,12 @@ static int snd_saa7134_capsrc_info(snd_kstatic int snd_saa7134_capsrc_get (snd_kcontrol_t * kcontrol,snd_ctl_elem_value_t * ucontrol) {snd_card_saa7134_t *chip =snd_kcontrol_chip (kcontrol); -unsigned long flags;int addr = kcontrol->private_value; -spin_lock_irqsave (&chip->mixer_lock, flags); +spin_lock_irq (&chip->mixer_lock); ucontrol->value.integer.value[0 ] = chip->capture_source[addr][0 ]; ucontrol->value.integer.value[1 ] = chip->capture_source[addr][1 ]; -spin_unlock_irqrestore (&chip->mixer_lock, flags); +spin_unlock_irq (&chip->mixer_lock);return 0 ; }
@@ -912,21 +870,15 @@ static int snd_card_saa7134_new_mixer(snstatic void snd_saa7134_free (snd_card_t * card) { -return ; -} - -static int snd_saa7134_dev_free (snd_device_t *device) -{ -snd_card_saa7134_t *chip = device->device_data; +snd_card_saa7134_t *chip = card->private_data;if (chip->irq >=0 ) {synchronize_irq (chip->irq);free_irq (chip->irq, (void *) chip); } - -return 0 ; } +/* * ALSA initialization *
@@ -941,10 +893,6 @@ int alsa_card_saa7134_create(struct saa7snd_card_t *card;snd_card_saa7134_t *chip;int err; -static snd_device_ops_t ops = { - .dev_free = snd_saa7134_dev_free, - }; -if (dev >=SNDRV_CARDS )return -ENODEV ;
@@ -971,7 +919,6 @@ int alsa_card_saa7134_create(struct saa7 chip->card = card; chip->pci = saadev->pci; - chip->irq = saadev->pci->irq; chip->iobase =pci_resource_start (saadev->pci,0 ); err = request_irq(saadev->pci->irq, saa7134_alsa_irq,
@@ -979,13 +926,10 @@ int alsa_card_saa7134_create(struct saa7if (err <0 ) {printk (KERN_ERR "%s: can't get IRQ %d for ALSA\n" , - saadev->name, saadev->pci->irq); - goto __nodev; - } - -if ((err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , chip, &ops)) <0 ) { + saadev->name, chip->irq); goto __nodev; } + chip->irq = saadev->pci->irq;if ((err =snd_card_saa7134_new_mixer (chip)) <0 ) goto __nodev;