fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / pci / ice1712 / pontis.c
index 0dccd77..6c74c2d 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/mutex.h>
+
 #include <sound/core.h>
 #include <sound/info.h>
+#include <sound/tlv.h>
 
 #include "ice1712.h"
 #include "envy24ht.h"
@@ -124,13 +127,13 @@ static int wm_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
        unsigned short val;
        int i;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        for (i = 0; i < 2; i++) {
                val = wm_get(ice, WM_DAC_ATTEN_L + i) & 0xff;
                val = val > DAC_MIN ? (val - DAC_MIN) : 0;
                ucontrol->value.integer.value[i] = val;
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -140,7 +143,7 @@ static int wm_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
        unsigned short oval, nval;
        int i, idx, change = 0;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        for (i = 0; i < 2; i++) {
                nval = ucontrol->value.integer.value[i];
                nval = (nval ? (nval + DAC_MIN) : 0) & 0xff;
@@ -152,7 +155,7 @@ static int wm_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
                        change = 1;
                }
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return change;
 }
 
@@ -179,13 +182,13 @@ static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
        unsigned short val;
        int i;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        for (i = 0; i < 2; i++) {
                val = wm_get(ice, WM_ADC_ATTEN_L + i) & 0xff;
                val = val > ADC_MIN ? (val - ADC_MIN) : 0;
                ucontrol->value.integer.value[i] = val;
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -195,7 +198,7 @@ static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
        unsigned short ovol, nvol;
        int i, idx, change = 0;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        for (i = 0; i < 2; i++) {
                nvol = ucontrol->value.integer.value[i];
                nvol = nvol ? (nvol + ADC_MIN) : 0;
@@ -206,7 +209,7 @@ static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
                        change = 1;
                }
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return change;
 }
 
@@ -227,9 +230,9 @@ static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
        int bit = kcontrol->private_value;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        ucontrol->value.integer.value[0] = (wm_get(ice, WM_ADC_MUX) & (1 << bit)) ? 1 : 0;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -240,7 +243,7 @@ static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
        unsigned short oval, nval;
        int change;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        nval = oval = wm_get(ice, WM_ADC_MUX);
        if (ucontrol->value.integer.value[0])
                nval |= (1 << bit);
@@ -250,7 +253,7 @@ static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
        if (change) {
                wm_put(ice, WM_ADC_MUX, nval);
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -270,9 +273,9 @@ static int wm_bypass_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
 {
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        ucontrol->value.integer.value[0] = (wm_get(ice, WM_OUT_MUX) & 0x04) ? 1 : 0;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -282,7 +285,7 @@ static int wm_bypass_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
        unsigned short val, oval;
        int change = 0;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        val = oval = wm_get(ice, WM_OUT_MUX);
        if (ucontrol->value.integer.value[0])
                val |= 0x04;
@@ -292,7 +295,7 @@ static int wm_bypass_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
                wm_put(ice, WM_OUT_MUX, val);
                change = 1;
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return change;
 }
 
@@ -312,9 +315,9 @@ static int wm_chswap_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
 {
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL1) & 0xf0) != 0x90;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -324,7 +327,7 @@ static int wm_chswap_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
        unsigned short val, oval;
        int change = 0;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        oval = wm_get(ice, WM_DAC_CTRL1);
        val = oval & 0x0f;
        if (ucontrol->value.integer.value[0])
@@ -336,7 +339,7 @@ static int wm_chswap_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
                wm_put_nocache(ice, WM_DAC_CTRL1, val);
                change = 1;
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return change;
 }
 
@@ -449,9 +452,9 @@ static int cs_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
 {
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        ucontrol->value.enumerated.item[0] = ice->gpio.saved[0];
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -461,14 +464,14 @@ static int cs_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
        unsigned char val;
        int change = 0;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        if (ucontrol->value.enumerated.item[0] != ice->gpio.saved[0]) {
                ice->gpio.saved[0] = ucontrol->value.enumerated.item[0] & 3;
                val = 0x80 | (ice->gpio.saved[0] << 3);
                spi_write(ice, CS_DEV, 0x04, val);
                change = 1;
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -488,10 +491,10 @@ static int pontis_gpio_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_e
 static int pontis_gpio_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        /* 4-7 reserved */
        ucontrol->value.integer.value[0] = (~ice->gpio.write_mask & 0xffff) | 0x00f0;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
        
@@ -500,22 +503,22 @@ static int pontis_gpio_mask_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
        unsigned int val;
        int changed;
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        /* 4-7 reserved */
        val = (~ucontrol->value.integer.value[0] & 0xffff) | 0x00f0;
        changed = val != ice->gpio.write_mask;
        ice->gpio.write_mask = val;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return changed;
 }
 
 static int pontis_gpio_dir_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        /* 4-7 reserved */
        ucontrol->value.integer.value[0] = ice->gpio.direction & 0xff0f;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
        
@@ -524,23 +527,23 @@ static int pontis_gpio_dir_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
        unsigned int val;
        int changed;
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        /* 4-7 reserved */
        val = ucontrol->value.integer.value[0] & 0xff0f;
        changed = (val != ice->gpio.direction);
        ice->gpio.direction = val;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return changed;
 }
 
 static int pontis_gpio_data_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
        snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
        ucontrol->value.integer.value[0] = snd_ice1712_gpio_read(ice) & 0xffff;
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return 0;
 }
 
@@ -549,7 +552,7 @@ static int pontis_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
        unsigned int val, nval;
        int changed = 0;
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
        snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
        val = snd_ice1712_gpio_read(ice) & 0xffff;
@@ -558,10 +561,12 @@ static int pontis_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
                snd_ice1712_gpio_write(ice, nval);
                changed = 1;
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
        return changed;
 }
 
+static DECLARE_TLV_DB_SCALE(db_scale_volume, -6400, 50, 1);
+
 /*
  * mixers
  */
@@ -569,17 +574,23 @@ static int pontis_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
 static struct snd_kcontrol_new pontis_controls[] __devinitdata = {
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                          SNDRV_CTL_ELEM_ACCESS_TLV_READ),
                .name = "PCM Playback Volume",
                .info = wm_dac_vol_info,
                .get = wm_dac_vol_get,
                .put = wm_dac_vol_put,
+               .tlv = { .p = db_scale_volume },
        },
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                          SNDRV_CTL_ELEM_ACCESS_TLV_READ),
                .name = "Capture Volume",
                .info = wm_adc_vol_info,
                .get = wm_adc_vol_get,
                .put = wm_adc_vol_put,
+               .tlv = { .p = db_scale_volume },
        },
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -651,14 +662,14 @@ static void wm_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buf
        struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
        char line[64];
        unsigned int reg, val;
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        while (!snd_info_get_line(buffer, line, sizeof(line))) {
                if (sscanf(line, "%x %x", &reg, &val) != 2)
                        continue;
                if (reg <= 0x17 && val <= 0xffff)
                        wm_put(ice, reg, val);
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
 }
 
 static void wm_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
@@ -666,21 +677,20 @@ static void wm_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buff
        struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
        int reg, val;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        for (reg = 0; reg <= 0x17; reg++) {
                val = wm_get(ice, reg);
                snd_iprintf(buffer, "%02x = %04x\n", reg, val);
        }
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
 }
 
 static void wm_proc_init(struct snd_ice1712 *ice)
 {
        struct snd_info_entry *entry;
        if (! snd_card_proc_new(ice->card, "wm_codec", &entry)) {
-               snd_info_set_text_ops(entry, ice, 1024, wm_proc_regs_read);
+               snd_info_set_text_ops(entry, ice, wm_proc_regs_read);
                entry->mode |= S_IWUSR;
-               entry->c.text.write_size = 1024;
                entry->c.text.write = wm_proc_regs_write;
        }
 }
@@ -690,22 +700,21 @@ static void cs_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buff
        struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
        int reg, val;
 
-       down(&ice->gpio_mutex);
+       mutex_lock(&ice->gpio_mutex);
        for (reg = 0; reg <= 0x26; reg++) {
                val = spi_read(ice, CS_DEV, reg);
                snd_iprintf(buffer, "%02x = %02x\n", reg, val);
        }
        val = spi_read(ice, CS_DEV, 0x7f);
        snd_iprintf(buffer, "%02x = %02x\n", 0x7f, val);
-       up(&ice->gpio_mutex);
+       mutex_unlock(&ice->gpio_mutex);
 }
 
 static void cs_proc_init(struct snd_ice1712 *ice)
 {
        struct snd_info_entry *entry;
-       if (! snd_card_proc_new(ice->card, "cs_codec", &entry)) {
-               snd_info_set_text_ops(entry, ice, 1024, cs_proc_regs_read);
-       }
+       if (! snd_card_proc_new(ice->card, "cs_codec", &entry))
+               snd_info_set_text_ops(entry, ice, cs_proc_regs_read);
 }