]> err.no Git - linux-2.6/blobdiff - drivers/media/video/cx88/cx88-alsa.c
Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-backlight
[linux-2.6] / drivers / media / video / cx88 / cx88-alsa.c
index 33dd4cb5e8779bf0af66dbe8211a21f4ca5147ff..90c36c5705c368bfdb98525af9faf3c7e62d15f9 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/interrupt.h>
+#include <linux/vmalloc.h>
 #include <linux/dma-mapping.h>
 #include <linux/pci.h>
 
        Data type declarations - Can be moded to a header file later
  ****************************************************************************/
 
-/* These can be replaced after done */
-#define MIXER_ADDR_LAST MAX_CX88_INPUT
-
 struct cx88_audio_dev {
        struct cx88_core           *core;
        struct cx88_dmaqueue       q;
-       u64 starttime;
 
        /* pci i/o */
        struct pci_dev             *pci;
@@ -75,10 +72,7 @@ struct cx88_audio_dev {
        unsigned int               period_size;
        unsigned int               num_periods;
 
-       struct videobuf_dmabuf     dma_risc;
-
-       int                        mixer_volume[MIXER_ADDR_LAST+1][2];
-       int                        capture_source[MIXER_ADDR_LAST+1][2];
+       struct videobuf_dmabuf     *dma_risc;
 
        struct cx88_buffer         *buf;
 
@@ -95,7 +89,6 @@ typedef struct cx88_audio_dev snd_cx88_card_t;
 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};
-static struct snd_card *snd_cx88_cards[SNDRV_CARDS];
 
 module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled.");
@@ -289,11 +282,12 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
        BUG_ON(!chip->dma_size);
 
        dprintk(2,"Freeing buffer\n");
-       videobuf_pci_dma_unmap(chip->pci, &chip->dma_risc);
-       videobuf_dma_free(&chip->dma_risc);
+       videobuf_pci_dma_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_risc = NULL;
        chip->dma_size = 0;
 
        return 0;
@@ -373,6 +367,8 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
                              struct snd_pcm_hw_params * hw_params)
 {
        snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
+       struct videobuf_dmabuf *dma;
+
        struct cx88_buffer *buf;
        int ret;
 
@@ -388,7 +384,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
        BUG_ON(!chip->dma_size);
        BUG_ON(chip->num_periods & (chip->num_periods-1));
 
-       buf = kzalloc(sizeof(*buf), GFP_KERNEL);
+       buf = videobuf_pci_alloc(sizeof(*buf));
        if (NULL == buf)
                return -ENOMEM;
 
@@ -399,17 +395,18 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
        buf->vb.height = chip->num_periods;
        buf->vb.size   = chip->dma_size;
 
-       videobuf_dma_init(&buf->vb.dma);
-       ret = videobuf_dma_init_kernel(&buf->vb.dma, PCI_DMA_FROMDEVICE,
+       dma=videobuf_to_dma(&buf->vb);
+       videobuf_dma_init(dma);
+       ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
                        (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT));
        if (ret < 0)
                goto error;
 
-       ret = videobuf_pci_dma_map(chip->pci,&buf->vb.dma);
+       ret = videobuf_pci_dma_map(chip->pci,dma);
        if (ret < 0)
                goto error;
 
-       ret = cx88_risc_databuffer(chip->pci, &buf->risc, buf->vb.dma.sglist,
+       ret = cx88_risc_databuffer(chip->pci, &buf->risc, dma->sglist,
                                   buf->vb.width, buf->vb.height, 1);
        if (ret < 0)
                goto error;
@@ -421,9 +418,11 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
        buf->vb.state = STATE_PREPARED;
 
        chip->buf = buf;
-       chip->dma_risc = buf->vb.dma;
+       chip->dma_risc = dma;
 
-       substream->runtime->dma_area = chip->dma_risc.vmalloc;
+       substream->runtime->dma_area = chip->dma_risc->vmalloc;
+       substream->runtime->dma_bytes = chip->dma_size;
+       substream->runtime->dma_addr = 0;
        return 0;
 
 error:
@@ -500,6 +499,16 @@ static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
        return runtime->period_size * (count & (runtime->periods-1));
 }
 
+/*
+ * page callback (needed for mmap)
+ */
+static struct page *snd_cx88_page(struct snd_pcm_substream *substream,
+                               unsigned long offset)
+{
+       void *pageptr = substream->runtime->dma_area + offset;
+       return vmalloc_to_page(pageptr);
+}
+
 /*
  * operators
  */
@@ -512,6 +521,7 @@ static struct snd_pcm_ops snd_cx88_pcm_ops = {
        .prepare = snd_cx88_prepare,
        .trigger = snd_cx88_card_trigger,
        .pointer = snd_cx88_pointer,
+       .page = snd_cx88_page,
 };
 
 /*
@@ -539,7 +549,7 @@ static int snd_cx88_capture_volume_info(struct snd_kcontrol *kcontrol,
                                        struct snd_ctl_elem_info *info)
 {
        info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
-       info->count = 1;
+       info->count = 2;
        info->value.integer.min = 0;
        info->value.integer.max = 0x3f;
 
@@ -552,8 +562,12 @@ static int snd_cx88_capture_volume_get(struct snd_kcontrol *kcontrol,
 {
        snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
        struct cx88_core *core=chip->core;
+       int vol = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f),
+           bal = cx_read(AUD_BAL_CTL);
 
-       value->value.integer.value[0] = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f);
+       value->value.integer.value[(bal & 0x40) ? 0 : 1] = vol;
+       vol -= (bal & 0x3f);
+       value->value.integer.value[(bal & 0x40) ? 1 : 0] = vol < 0 ? 0 : vol;
 
        return 0;
 }
@@ -564,19 +578,31 @@ static int snd_cx88_capture_volume_put(struct snd_kcontrol *kcontrol,
 {
        snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
        struct cx88_core *core=chip->core;
-       int v;
-       u32 old_control;
-
+       int v, b;
+       int changed = 0;
+       u32 old;
+
+       b = value->value.integer.value[1] - value->value.integer.value[0];
+       if (b < 0) {
+           v = 0x3f - value->value.integer.value[0];
+           b = (-b) | 0x40;
+       } else {
+           v = 0x3f - value->value.integer.value[1];
+       }
        /* Do we really know this will always be called with IRQs on? */
        spin_lock_irq(&chip->reg_lock);
-
-       old_control = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f);
-       v = 0x3f - (value->value.integer.value[0] & 0x3f);
-       cx_andor(AUD_VOL_CTL, 0x3f, v);
-
+       old = cx_read(AUD_VOL_CTL);
+       if (v != (old & 0x3f)) {
+           cx_write(AUD_VOL_CTL, (old & ~0x3f) | v);
+           changed = 1;
+       }
+       if (cx_read(AUD_BAL_CTL) != b) {
+           cx_write(AUD_BAL_CTL, b);
+           changed = 1;
+       }
        spin_unlock_irq(&chip->reg_lock);
 
-       return v != old_control;
+       return changed;
 }
 
 static struct snd_kcontrol_new snd_cx88_capture_volume = {
@@ -733,17 +759,12 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
                return (err);
 
        err = snd_cx88_pcm(chip, 0, "CX88 Digital");
-
-       if (err < 0) {
-               snd_card_free(card);
-               return (err);
-       }
+       if (err < 0)
+               goto error;
 
        err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_capture_volume, chip));
-       if (err < 0) {
-               snd_card_free(card);
-               return (err);
-       }
+       if (err < 0)
+               goto error;
 
        strcpy (card->driver, "CX88x");
        sprintf(card->shortname, "Conexant CX%x", pci->device);
@@ -755,16 +776,16 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
               card->driver,devno);
 
        err = snd_card_register(card);
-       if (err < 0) {
-               snd_card_free(card);
-               return (err);
-       }
-       snd_cx88_cards[devno] = card;
-
+       if (err < 0)
+               goto error;
        pci_set_drvdata(pci,card);
 
        devno++;
        return 0;
+
+error:
+       snd_card_free(card);
+       return err;
 }
 /*
  * ALSA destructor