]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/media/video/cx88/cx88-alsa.c
[ALSA] Fix synchronize_irq() bugs, redundancies
[karo-tx-linux.git] / drivers / media / video / cx88 / cx88-alsa.c
index 90c36c5705c368bfdb98525af9faf3c7e62d15f9..03feb5b49e1b270428cdcb38ae938893324eb0d9 100644 (file)
@@ -7,7 +7,7 @@
  *    (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org>
  *    (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
  *    Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org>
- *    Based on dummy.c by Jaroslav Kysela <perex@suse.cz>
+ *    Based on dummy.c by Jaroslav Kysela <perex@perex.cz>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include <linux/pci.h>
 
 #include <asm/delay.h>
-#include <sound/driver.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/control.h>
 #include <sound/initval.h>
+#include <sound/tlv.h>
 
 #include "cx88.h"
 #include "cx88-reg.h"
@@ -82,6 +82,7 @@ typedef struct cx88_audio_dev snd_cx88_card_t;
 
 
 
+
 /****************************************************************************
                        Module global static vars
  ****************************************************************************/
@@ -415,7 +416,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
        buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC);
        buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
 
-       buf->vb.state = STATE_PREPARED;
+       buf->vb.state = VIDEOBUF_PREPARED;
 
        chip->buf = buf;
        chip->dma_risc = dma;
@@ -545,8 +546,8 @@ static int __devinit snd_cx88_pcm(snd_cx88_card_t *chip, int device, char *name)
 /****************************************************************************
                                CONTROL INTERFACE
  ****************************************************************************/
-static int snd_cx88_capture_volume_info(struct snd_kcontrol *kcontrol,
-                                       struct snd_ctl_elem_info *info)
+static int snd_cx88_volume_info(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *info)
 {
        info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        info->count = 2;
@@ -556,9 +557,8 @@ static int snd_cx88_capture_volume_info(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
-/* OK - TODO: test it */
-static int snd_cx88_capture_volume_get(struct snd_kcontrol *kcontrol,
-                                      struct snd_ctl_elem_value *value)
+static int snd_cx88_volume_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
 {
        snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
        struct cx88_core *core=chip->core;
@@ -573,8 +573,8 @@ static int snd_cx88_capture_volume_get(struct snd_kcontrol *kcontrol,
 }
 
 /* OK - TODO: test it */
-static int snd_cx88_capture_volume_put(struct snd_kcontrol *kcontrol,
-                                      struct snd_ctl_elem_value *value)
+static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
 {
        snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
        struct cx88_core *core=chip->core;
@@ -605,14 +605,67 @@ static int snd_cx88_capture_volume_put(struct snd_kcontrol *kcontrol,
        return changed;
 }
 
-static struct snd_kcontrol_new snd_cx88_capture_volume = {
+static const DECLARE_TLV_DB_SCALE(snd_cx88_db_scale, -6300, 100, 0);
+
+static struct snd_kcontrol_new snd_cx88_volume = {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "Capture Volume",
-       .info = snd_cx88_capture_volume_info,
-       .get = snd_cx88_capture_volume_get,
-       .put = snd_cx88_capture_volume_put,
+       .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
+       .name = "Playback Volume",
+       .info = snd_cx88_volume_info,
+       .get = snd_cx88_volume_get,
+       .put = snd_cx88_volume_put,
+       .tlv.p = snd_cx88_db_scale,
 };
 
+static int snd_cx88_switch_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
+{
+       snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
+       struct cx88_core *core = chip->core;
+       u32 bit = kcontrol->private_value;
+
+       value->value.integer.value[0] = !(cx_read(AUD_VOL_CTL) & bit);
+       return 0;
+}
+
+static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *value)
+{
+       snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
+       struct cx88_core *core = chip->core;
+       u32 bit = kcontrol->private_value;
+       int ret = 0;
+       u32 vol;
+
+       spin_lock_irq(&chip->reg_lock);
+       vol = cx_read(AUD_VOL_CTL);
+       if (value->value.integer.value[0] != !(vol & bit)) {
+               vol ^= bit;
+               cx_write(AUD_VOL_CTL, vol);
+               ret = 1;
+       }
+       spin_unlock_irq(&chip->reg_lock);
+       return ret;
+}
+
+static struct snd_kcontrol_new snd_cx88_dac_switch = {
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "Playback Switch",
+       .info = snd_ctl_boolean_mono_info,
+       .get = snd_cx88_switch_get,
+       .put = snd_cx88_switch_put,
+       .private_value = (1<<8),
+};
+
+static struct snd_kcontrol_new snd_cx88_source_switch = {
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "Capture Switch",
+       .info = snd_ctl_boolean_mono_info,
+       .get = snd_cx88_switch_get,
+       .put = snd_cx88_switch_put,
+       .private_value = (1<<6),
+};
 
 /****************************************************************************
                        Basic Flow for Sound Devices
@@ -637,10 +690,8 @@ MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
 static int snd_cx88_free(snd_cx88_card_t *chip)
 {
 
-       if (chip->irq >= 0){
-               synchronize_irq(chip->irq);
+       if (chip->irq >= 0)
                free_irq(chip->irq, chip);
-       }
 
        cx88_core_put(chip->core,chip->pci);
 
@@ -762,7 +813,13 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
        if (err < 0)
                goto error;
 
-       err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_capture_volume, chip));
+       err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_volume, chip));
+       if (err < 0)
+               goto error;
+       err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_dac_switch, chip));
+       if (err < 0)
+               goto error;
+       err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_source_switch, chip));
        if (err < 0)
                goto error;