fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / pci / pcxhr / pcxhr_mixer.c
index 760e733..b133ad9 100644 (file)
 #include <linux/time.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
+#include <linux/mutex.h>
 #include <sound/core.h>
 #include "pcxhr.h"
 #include "pcxhr_hwdep.h"
 #include "pcxhr_core.h"
 #include <sound/control.h>
+#include <sound/tlv.h>
 #include <sound/asoundef.h>
 #include "pcxhr_mixer.h"
 
@@ -42,6 +44,9 @@
 #define PCXHR_ANALOG_PLAYBACK_LEVEL_MAX  128   /*    0.0 dB */
 #define PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL 104   /*  -24.0 dB ( 0.0 dB - fix level +24.0 dB ) */
 
+static DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -9600, 50, 0);
+static DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -12800, 100, 0);
+
 static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip, int is_capture, int channel)
 {
        int err, vol;
@@ -92,7 +97,7 @@ static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
                                struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        if (kcontrol->private_value == 0) {     /* playback */
                ucontrol->value.integer.value[0] = chip->analog_playback_volume[0];
                ucontrol->value.integer.value[1] = chip->analog_playback_volume[1];
@@ -100,7 +105,7 @@ static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
                ucontrol->value.integer.value[0] = chip->analog_capture_volume[0];
                ucontrol->value.integer.value[1] = chip->analog_capture_volume[1];
        }
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return 0;
 }
 
@@ -111,7 +116,7 @@ static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
        int changed = 0;
        int is_capture, i;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        is_capture = (kcontrol->private_value != 0);
        for (i = 0; i < 2; i++) {
                int  new_volume = ucontrol->value.integer.value[i];
@@ -123,16 +128,19 @@ static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
                        pcxhr_update_analog_audio_level(chip, is_capture, i);
                }
        }
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return changed;
 }
 
 static struct snd_kcontrol_new pcxhr_control_analog_level = {
        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
+       .access =       (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                        SNDRV_CTL_ELEM_ACCESS_TLV_READ),
        /* name will be filled later */
        .info =         pcxhr_analog_vol_info,
        .get =          pcxhr_analog_vol_get,
        .put =          pcxhr_analog_vol_put,
+       /* tlv will be filled later */
 };
 
 /* shared */
@@ -150,10 +158,10 @@ static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol,
 {
        struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->analog_playback_active[0];
        ucontrol->value.integer.value[1] = chip->analog_playback_active[1];
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return 0;
 }
 
@@ -162,7 +170,7 @@ static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
 {
        struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
        int i, changed = 0;
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        for(i = 0; i < 2; i++) {
                if (chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) {
                        chip->analog_playback_active[i] = ucontrol->value.integer.value[i];
@@ -170,7 +178,7 @@ static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
                        pcxhr_update_analog_audio_level(chip, 0, i);    /* update playback levels */
                }
        }
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return changed;
 }
 
@@ -187,6 +195,7 @@ static struct snd_kcontrol_new pcxhr_control_output_switch = {
 #define PCXHR_DIGITAL_LEVEL_MAX                0x1ff   /* +18 dB */
 #define PCXHR_DIGITAL_ZERO_LEVEL       0x1b7   /*  0 dB */
 
+static DECLARE_TLV_DB_SCALE(db_scale_digital, -10950, 50, 0);
 
 #define MORE_THAN_ONE_STREAM_LEVEL     0x000001
 #define VALID_STREAM_PAN_LEVEL_MASK    0x800000
@@ -299,14 +308,14 @@ static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol,
        int *stored_volume;
        int is_capture = kcontrol->private_value;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        if (is_capture)
                stored_volume = chip->digital_capture_volume;           /* digital capture */
        else
                stored_volume = chip->digital_playback_volume[idx];     /* digital playback */
        ucontrol->value.integer.value[0] = stored_volume[0];
        ucontrol->value.integer.value[1] = stored_volume[1];
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return 0;
 }
 
@@ -320,7 +329,7 @@ static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
        int *stored_volume;
        int i;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        if (is_capture)
                stored_volume = chip->digital_capture_volume;           /* digital capture */
        else
@@ -335,18 +344,21 @@ static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
        }
        if (! is_capture && changed)
                pcxhr_update_playback_stream_level(chip, idx);  /* update playback volume */
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return changed;
 }
 
 static struct snd_kcontrol_new snd_pcxhr_pcm_vol =
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
+       .access =       (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                        SNDRV_CTL_ELEM_ACCESS_TLV_READ),
        /* name will be filled later */
        /* count will be filled later */
        .info =         pcxhr_digital_vol_info,         /* shared */
        .get =          pcxhr_pcm_vol_get,
        .put =          pcxhr_pcm_vol_put,
+       .tlv = { .p = db_scale_digital },
 };
 
 
@@ -356,10 +368,10 @@ static int pcxhr_pcm_sw_get(struct snd_kcontrol *kcontrol,
        struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0];
        ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1];
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return 0;
 }
 
@@ -370,7 +382,7 @@ static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
        int i, j;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        j = idx;
        for (i = 0; i < 2; i++) {
                if (chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) {
@@ -380,7 +392,7 @@ static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
        }
        if (changed)
                pcxhr_update_playback_stream_level(chip, idx);
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return changed;
 }
 
@@ -402,10 +414,10 @@ static int pcxhr_monitor_vol_get(struct snd_kcontrol *kcontrol,
                                 struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->monitoring_volume[0];
        ucontrol->value.integer.value[1] = chip->monitoring_volume[1];
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return 0;
 }
 
@@ -416,7 +428,7 @@ static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
        int changed = 0;
        int i;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        for (i = 0; i < 2; i++) {
                if (chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) {
                        chip->monitoring_volume[i] = ucontrol->value.integer.value[i];
@@ -426,16 +438,19 @@ static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
                        changed = 1;
                }
        }
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return changed;
 }
 
 static struct snd_kcontrol_new pcxhr_control_monitor_vol = {
        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
+       .access =       (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                        SNDRV_CTL_ELEM_ACCESS_TLV_READ),
        .name =         "Monitoring Volume",
        .info =         pcxhr_digital_vol_info,         /* shared */
        .get =          pcxhr_monitor_vol_get,
        .put =          pcxhr_monitor_vol_put,
+       .tlv = { .p = db_scale_digital },
 };
 
 /*
@@ -446,10 +461,10 @@ static int pcxhr_monitor_sw_get(struct snd_kcontrol *kcontrol,
                                struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->monitoring_active[0];
        ucontrol->value.integer.value[1] = chip->monitoring_active[1];
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return 0;
 }
 
@@ -460,7 +475,7 @@ static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
        int changed = 0;
        int i;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        for (i = 0; i < 2; i++) {
                if (chip->monitoring_active[i] != ucontrol->value.integer.value[i]) {
                        chip->monitoring_active[i] = ucontrol->value.integer.value[i];
@@ -474,7 +489,7 @@ static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
                /* update right monitoring volume and mute */
                pcxhr_update_audio_pipe_level(chip, 0, 1);
 
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return (changed != 0);
 }
 
@@ -571,13 +586,13 @@ static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
        struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
        int ret = 0;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
                chip->audio_capture_source = ucontrol->value.enumerated.item[0];
                pcxhr_set_audio_source(chip);
                ret = 1;
        }
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return ret;
 }
 
@@ -636,9 +651,9 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
        struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
        int rate, ret = 0;
 
-       down(&mgr->mixer_mutex);
+       mutex_lock(&mgr->mixer_mutex);
        if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
-               down(&mgr->setup_mutex);
+               mutex_lock(&mgr->setup_mutex);
                mgr->use_clock_type = ucontrol->value.enumerated.item[0];
                if (mgr->use_clock_type)
                        pcxhr_get_external_clock(mgr, mgr->use_clock_type, &rate);
@@ -649,10 +664,10 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
                        if (mgr->sample_rate)
                                mgr->sample_rate = rate;
                }
-               up(&mgr->setup_mutex);
+               mutex_unlock(&mgr->setup_mutex);
                ret = 1;        /* return 1 even if the set was not done. ok ? */
        }
-       up(&mgr->mixer_mutex);
+       mutex_unlock(&mgr->mixer_mutex);
        return ret;
 }
 
@@ -685,7 +700,7 @@ static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
        struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
        int i, err, rate;
 
-       down(&mgr->mixer_mutex);
+       mutex_lock(&mgr->mixer_mutex);
        for(i = 0; i < 3 + mgr->capture_chips; i++) {
                if (i == PCXHR_CLOCK_TYPE_INTERNAL)
                        rate = mgr->sample_rate_real;
@@ -696,7 +711,7 @@ static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
                }
                ucontrol->value.integer.value[i] = rate;
        }
-       up(&mgr->mixer_mutex);
+       mutex_unlock(&mgr->mixer_mutex);
        return 0;
 }
 
@@ -765,7 +780,7 @@ static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
        unsigned char aes_bits;
        int i, err;
 
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        for(i = 0; i < 5; i++) {
                if (kcontrol->private_value == 0)       /* playback */
                        aes_bits = chip->aes_bits[i];
@@ -776,7 +791,7 @@ static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
                }
                ucontrol->value.iec958.status[i] = aes_bits;
        }
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
         return 0;
 }
 
@@ -828,14 +843,14 @@ static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
        int i, changed = 0;
 
        /* playback */
-       down(&chip->mgr->mixer_mutex);
+       mutex_lock(&chip->mgr->mixer_mutex);
        for (i = 0; i < 5; i++) {
                if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
                        pcxhr_iec958_update_byte(chip, i, ucontrol->value.iec958.status[i]);
                        changed = 1;
                }
        }
-       up(&chip->mgr->mixer_mutex);
+       mutex_unlock(&chip->mgr->mixer_mutex);
        return changed;
 }
 
@@ -916,7 +931,7 @@ int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
        struct snd_pcxhr *chip;
        int err, i;
 
-       init_MUTEX(&mgr->mixer_mutex); /* can be in another place */
+       mutex_init(&mgr->mixer_mutex); /* can be in another place */
 
        for (i = 0; i < mgr->num_cards; i++) {
                struct snd_kcontrol_new temp;
@@ -927,6 +942,7 @@ int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
                        temp = pcxhr_control_analog_level;
                        temp.name = "Master Playback Volume";
                        temp.private_value = 0; /* playback */
+                       temp.tlv.p = db_scale_analog_playback;
                        if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
                                return err;
                        /* output mute controls */
@@ -962,6 +978,7 @@ int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
                        temp = pcxhr_control_analog_level;
                        temp.name = "Master Capture Volume";
                        temp.private_value = 1; /* capture */
+                       temp.tlv.p = db_scale_analog_capture;
                        if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
                                return err;