Commit d5ee43af authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Linus Torvalds

[PATCH] v4l: 975: apply saa7134-alsa fixes

Merged parts of a patch from Takashi Iwai for an older version of the module.

This patch was adapted and tested by Ricardo Cerqueira.
Signed-off-by: default avatarRicardo Cerqueira <v4l@cerqueira.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@brturbo.com.br>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c01ee851
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <sound/core.h> #include <sound/core.h>
#include <sound/control.h> #include <sound/control.h>
#include <sound/pcm.h> #include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/initval.h> #include <sound/initval.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -168,8 +169,9 @@ void saa7134_irq_alsa_done(struct saa7134_dev *dev, unsigned long status) ...@@ -168,8 +169,9 @@ void saa7134_irq_alsa_done(struct saa7134_dev *dev, unsigned long status)
if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) { if (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, dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->dmasound.read_count,
dev->dmasound.bufsize, dev->dmasound.blocks); dev->dmasound.bufsize, dev->dmasound.blocks);
spin_unlock(&dev->slock);
snd_pcm_stop(dev->dmasound.substream,SNDRV_PCM_STATE_XRUN); snd_pcm_stop(dev->dmasound.substream,SNDRV_PCM_STATE_XRUN);
goto done; return;
} }
/* next block addr */ /* next block addr */
...@@ -252,7 +254,7 @@ static int snd_card_saa7134_capture_trigger(snd_pcm_substream_t * substream, ...@@ -252,7 +254,7 @@ static int snd_card_saa7134_capture_trigger(snd_pcm_substream_t * substream,
struct saa7134_dev *dev=pcm->dev; struct saa7134_dev *dev=pcm->dev;
int err = 0; int err = 0;
spin_lock_irq(&dev->slock); spin_lock(&dev->slock);
if (cmd == SNDRV_PCM_TRIGGER_START) { if (cmd == SNDRV_PCM_TRIGGER_START) {
/* start dma */ /* start dma */
saa7134_dma_start(dev); saa7134_dma_start(dev);
...@@ -262,44 +264,11 @@ static int snd_card_saa7134_capture_trigger(snd_pcm_substream_t * substream, ...@@ -262,44 +264,11 @@ static int snd_card_saa7134_capture_trigger(snd_pcm_substream_t * substream,
} else { } else {
err = -EINVAL; err = -EINVAL;
} }
spin_unlock_irq(&dev->slock); spin_unlock(&dev->slock);
return err; 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 * DMA buffer initialization
* *
...@@ -325,6 +294,28 @@ static int dsp_buffer_init(struct saa7134_dev *dev) ...@@ -325,6 +294,28 @@ static int dsp_buffer_init(struct saa7134_dev *dev)
return 0; 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();
videobuf_dma_free(&dev->dmasound.dma);
dev->dmasound.blocks = 0;
dev->dmasound.blksize = 0;
dev->dmasound.bufsize = 0;
return 0;
}
/* /*
* ALSA PCM preparation * ALSA PCM preparation
* *
...@@ -340,74 +331,30 @@ static int dsp_buffer_init(struct saa7134_dev *dev) ...@@ -340,74 +331,30 @@ static int dsp_buffer_init(struct saa7134_dev *dev)
static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream) static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream)
{ {
snd_pcm_runtime_t *runtime = substream->runtime; snd_pcm_runtime_t *runtime = substream->runtime;
int err, bswap, sign; int bswap, sign;
u32 fmt, control; u32 fmt, control;
snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
struct saa7134_dev *dev; struct saa7134_dev *dev;
snd_card_saa7134_pcm_t *pcm = runtime->private_data; snd_card_saa7134_pcm_t *pcm = runtime->private_data;
unsigned long size;
unsigned count;
size = snd_pcm_lib_buffer_bytes(substream);
count = snd_pcm_lib_period_bytes(substream);
pcm->dev->dmasound.substream = substream; pcm->dev->dmasound.substream = substream;
dev=saa7134->dev; dev = saa7134->dev;
dsp_buffer_conf(dev,count,(size/count));
err = dsp_buffer_init(dev);
if (0 != err)
return err;
/* 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) { if (snd_pcm_format_width(runtime->format) == 8)
case SNDRV_PCM_FORMAT_U8:
case SNDRV_PCM_FORMAT_S8:
fmt = 0x00; fmt = 0x00;
break; else
case SNDRV_PCM_FORMAT_U16_LE:
case SNDRV_PCM_FORMAT_U16_BE:
case SNDRV_PCM_FORMAT_S16_LE:
case SNDRV_PCM_FORMAT_S16_BE:
fmt = 0x01; fmt = 0x01;
break;
default:
err = -EINVAL;
return 1;
}
switch (runtime->format) { if (snd_pcm_format_signed(runtime->format))
case SNDRV_PCM_FORMAT_S8:
case SNDRV_PCM_FORMAT_S16_LE:
case SNDRV_PCM_FORMAT_S16_BE:
sign = 1; sign = 1;
break; else
default:
sign = 0; sign = 0;
break;
}
switch (runtime->format) { if (snd_pcm_format_big_endian(runtime->format))
case SNDRV_PCM_FORMAT_U16_BE: bswap = 1;
case SNDRV_PCM_FORMAT_S16_BE: else
bswap = 1; break; bswap = 0;
default:
bswap = 0; break;
}
switch (dev->pci->device) { switch (dev->pci->device) {
case PCI_DEVICE_ID_PHILIPS_SAA7134: case PCI_DEVICE_ID_PHILIPS_SAA7134:
...@@ -448,12 +395,6 @@ static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream) ...@@ -448,12 +395,6 @@ static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream)
if (bswap) if (bswap)
control |= SAA7134_RS_CONTROL_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_BA1(6),0);
saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize); saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize);
saa_writel(SAA7134_RS_PITCH(6),0); saa_writel(SAA7134_RS_PITCH(6),0);
...@@ -462,12 +403,6 @@ static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream) ...@@ -462,12 +403,6 @@ static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream)
dev->dmasound.rate = runtime->rate; dev->dmasound.rate = runtime->rate;
return 0; return 0;
fail2:
saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
fail1:
videobuf_dma_pci_unmap(dev->pci,&dev->dmasound.dma);
return err;
} }
...@@ -539,15 +474,76 @@ static void snd_card_saa7134_runtime_free(snd_pcm_runtime_t *runtime) ...@@ -539,15 +474,76 @@ static void snd_card_saa7134_runtime_free(snd_pcm_runtime_t *runtime)
* - One of the ALSA capture callbacks. * - One of the ALSA capture callbacks.
* *
* Called on initialization, right before the PCM preparation * 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, 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->dev;
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;
} }
...@@ -557,33 +553,23 @@ static int snd_card_saa7134_hw_params(snd_pcm_substream_t * substream, ...@@ -557,33 +553,23 @@ static int snd_card_saa7134_hw_params(snd_pcm_substream_t * substream,
* - One of the ALSA capture callbacks. * - One of the ALSA capture callbacks.
* *
* Called after closing the device, but before snd_card_saa7134_capture_close * 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 * It stops the DMA audio and releases the buffers.
* ALSA DMA it does nothing
* *
*/ */
static int snd_card_saa7134_hw_free(snd_pcm_substream_t * substream) static int snd_card_saa7134_hw_free(snd_pcm_substream_t * substream)
{ {
return 0; snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
} struct saa7134_dev *dev;
/*
* 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 = saa7134->dev;
dev->dmasound.blocks = 0; if (substream->runtime->dma_area) {
dev->dmasound.blksize = 0; saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
dev->dmasound.bufsize = 0; videobuf_dma_pci_unmap(dev->pci, &dev->dmasound.dma);
dsp_buffer_free(dev);
substream->runtime->dma_area = NULL;
}
return 0; return 0;
} }
...@@ -593,21 +579,12 @@ static int dsp_buffer_free(struct saa7134_dev *dev) ...@@ -593,21 +579,12 @@ static int dsp_buffer_free(struct saa7134_dev *dev)
* *
* - One of the ALSA capture callbacks. * - One of the ALSA capture callbacks.
* *
* Called after closing the device. It stops the DMA audio and releases * Called after closing the device.
* the buffers
* *
*/ */
static int snd_card_saa7134_capture_close(snd_pcm_substream_t * substream) 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->dev;
/* 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; return 0;
} }
...@@ -720,7 +697,6 @@ static int snd_saa7134_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ ...@@ -720,7 +697,6 @@ static int snd_saa7134_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_
static int snd_saa7134_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) static int snd_saa7134_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
{ {
snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
unsigned long flags;
int change, addr = kcontrol->private_value; int change, addr = kcontrol->private_value;
int left, right; int left, right;
...@@ -734,12 +710,12 @@ static int snd_saa7134_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_ ...@@ -734,12 +710,12 @@ static int snd_saa7134_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_
right = 0; right = 0;
if (right > 20) if (right > 20)
right = 20; right = 20;
spin_lock_irqsave(&chip->mixer_lock, flags); spin_lock_irq(&chip->mixer_lock);
change = chip->mixer_volume[addr][0] != left || change = chip->mixer_volume[addr][0] != left ||
chip->mixer_volume[addr][1] != right; chip->mixer_volume[addr][1] != right;
chip->mixer_volume[addr][0] = left; chip->mixer_volume[addr][0] = left;
chip->mixer_volume[addr][1] = right; chip->mixer_volume[addr][1] = right;
spin_unlock_irqrestore(&chip->mixer_lock, flags); spin_unlock_irq(&chip->mixer_lock);
return change; return change;
} }
...@@ -761,13 +737,12 @@ static int snd_saa7134_capsrc_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_ ...@@ -761,13 +737,12 @@ static int snd_saa7134_capsrc_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_
static int snd_saa7134_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) static int snd_saa7134_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
{ {
snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
unsigned long flags;
int addr = kcontrol->private_value; 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[0] = chip->capture_source[addr][0];
ucontrol->value.integer.value[1] = chip->capture_source[addr][1]; 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; return 0;
} }
...@@ -884,15 +859,10 @@ static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip) ...@@ -884,15 +859,10 @@ static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip)
static void snd_saa7134_free(snd_card_t * card) static void snd_saa7134_free(snd_card_t * card)
{ {
return; snd_card_saa7134_t *chip = card->private_data;
}
static int snd_saa7134_dev_free(snd_device_t *device)
{
snd_card_saa7134_t *chip = device->device_data;
if (chip->dev->dmasound.priv_data == NULL) if (chip->dev->dmasound.priv_data == NULL)
return 0; return;
if (chip->irq >= 0) { if (chip->irq >= 0) {
synchronize_irq(chip->irq); synchronize_irq(chip->irq);
...@@ -901,7 +871,6 @@ static int snd_saa7134_dev_free(snd_device_t *device) ...@@ -901,7 +871,6 @@ static int snd_saa7134_dev_free(snd_device_t *device)
chip->dev->dmasound.priv_data = NULL; chip->dev->dmasound.priv_data = NULL;
return 0;
} }
/* /*
...@@ -918,9 +887,6 @@ int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum) ...@@ -918,9 +887,6 @@ int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
snd_card_t *card; snd_card_t *card;
snd_card_saa7134_t *chip; snd_card_saa7134_t *chip;
int err; int err;
static snd_device_ops_t ops = {
.dev_free = snd_saa7134_dev_free,
};
if (devnum >= SNDRV_CARDS) if (devnum >= SNDRV_CARDS)
...@@ -948,7 +914,6 @@ int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum) ...@@ -948,7 +914,6 @@ int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
chip->card = card; chip->card = card;
chip->pci = dev->pci; chip->pci = dev->pci;
chip->irq = dev->pci->irq;
chip->iobase = pci_resource_start(dev->pci, 0); chip->iobase = pci_resource_start(dev->pci, 0);
...@@ -962,11 +927,9 @@ int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum) ...@@ -962,11 +927,9 @@ int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
goto __nodev; goto __nodev;
} }
init_MUTEX(&dev->dmasound.lock); chip->irq = dev->pci->irq;
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { init_MUTEX(&dev->dmasound.lock);
goto __nodev;
}
if ((err = snd_card_saa7134_new_mixer(chip)) < 0) if ((err = snd_card_saa7134_new_mixer(chip)) < 0)
goto __nodev; goto __nodev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment