fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / pci / ac97 / ak4531_codec.c
index b0c6214..c153cb7 100644 (file)
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/mutex.h>
+
 #include <sound/core.h>
 #include <sound/ak4531_codec.h>
+#include <sound/tlv.h>
 
 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
 MODULE_DESCRIPTION("Universal routines for AK4531 codec");
 MODULE_LICENSE("GPL");
 
-#define chip_t ak4531_t
-
-static void snd_ak4531_proc_init(snd_card_t * card, ak4531_t * ak4531);
+#ifdef CONFIG_PROC_FS
+static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531);
+#else
+#define snd_ak4531_proc_init(card,ak)
+#endif
 
 /*
  *
@@ -40,7 +45,7 @@ static void snd_ak4531_proc_init(snd_card_t * card, ak4531_t * ak4531);
  
 #if 0
 
-static void snd_ak4531_dump(ak4531_t *ak4531)
+static void snd_ak4531_dump(struct snd_ak4531 *ak4531)
 {
        int idx;
        
@@ -59,8 +64,16 @@ static void snd_ak4531_dump(ak4531_t *ak4531)
   .info = snd_ak4531_info_single, \
   .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
   .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) }
+#define AK4531_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv)    \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
+  .name = xname, .index = xindex, \
+  .info = snd_ak4531_info_single, \
+  .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
+  .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22), \
+  .tlv = { .p = (xtlv) } }
 
-static int snd_ak4531_info_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 24) & 0xff;
 
@@ -71,30 +84,28 @@ static int snd_ak4531_info_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t
        return 0;
 }
  
-static int snd_ak4531_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 16) & 0x07;
        int mask = (kcontrol->private_value >> 24) & 0xff;
        int invert = (kcontrol->private_value >> 22) & 1;
        int val;
 
-       spin_lock_irqsave(&ak4531->reg_lock, flags);
+       mutex_lock(&ak4531->reg_mutex);
        val = (ak4531->regs[reg] >> shift) & mask;
-       spin_unlock_irqrestore(&ak4531->reg_lock, flags);
+       mutex_unlock(&ak4531->reg_mutex);
        if (invert) {
                val = mask - val;
        }
        ucontrol->value.integer.value[0] = val;
        return 0;
-}                                                                                                                                                                                                                                                                                                            
+}
 
-static int snd_ak4531_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 16) & 0x07;
        int mask = (kcontrol->private_value >> 24) & 0xff;
@@ -107,21 +118,29 @@ static int snd_ak4531_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                val = mask - val;
        }
        val <<= shift;
-       spin_lock_irqsave(&ak4531->reg_lock, flags);
+       mutex_lock(&ak4531->reg_mutex);
        val = (ak4531->regs[reg] & ~(mask << shift)) | val;
        change = val != ak4531->regs[reg];
        ak4531->write(ak4531, reg, ak4531->regs[reg] = val);
-       spin_unlock_irqrestore(&ak4531->reg_lock, flags);
+       mutex_unlock(&ak4531->reg_mutex);
        return change;
-}                                                                                                                                                                                                                                                                                                            
+}
 
 #define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
   .info = snd_ak4531_info_double, \
   .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
   .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) }
+#define AK4531_DOUBLE_TLV(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert, xtlv) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
+  .name = xname, .index = xindex, \
+  .info = snd_ak4531_info_double, \
+  .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
+  .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22), \
+  .tlv = { .p = (xtlv) } }
 
-static int snd_ak4531_info_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 24) & 0xff;
 
@@ -132,10 +151,9 @@ static int snd_ak4531_info_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t
        return 0;
 }
  
-static int snd_ak4531_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
        int left_reg = kcontrol->private_value & 0xff;
        int right_reg = (kcontrol->private_value >> 8) & 0xff;
        int left_shift = (kcontrol->private_value >> 16) & 0x07;
@@ -144,10 +162,10 @@ static int snd_ak4531_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        int invert = (kcontrol->private_value >> 22) & 1;
        int left, right;
 
-       spin_lock_irqsave(&ak4531->reg_lock, flags);
+       mutex_lock(&ak4531->reg_mutex);
        left = (ak4531->regs[left_reg] >> left_shift) & mask;
        right = (ak4531->regs[right_reg] >> right_shift) & mask;
-       spin_unlock_irqrestore(&ak4531->reg_lock, flags);
+       mutex_unlock(&ak4531->reg_mutex);
        if (invert) {
                left = mask - left;
                right = mask - right;
@@ -155,12 +173,11 @@ static int snd_ak4531_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        ucontrol->value.integer.value[0] = left;
        ucontrol->value.integer.value[1] = right;
        return 0;
-}                                                                                                                                                                                                                                                                                                            
+}
 
-static int snd_ak4531_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
        int left_reg = kcontrol->private_value & 0xff;
        int right_reg = (kcontrol->private_value >> 8) & 0xff;
        int left_shift = (kcontrol->private_value >> 16) & 0x07;
@@ -178,7 +195,7 @@ static int snd_ak4531_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        }
        left <<= left_shift;
        right <<= right_shift;
-       spin_lock_irqsave(&ak4531->reg_lock, flags);
+       mutex_lock(&ak4531->reg_mutex);
        if (left_reg == right_reg) {
                left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right;
                change = left != ak4531->regs[left_reg];
@@ -190,9 +207,9 @@ static int snd_ak4531_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
                ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right);
        }
-       spin_unlock_irqrestore(&ak4531->reg_lock, flags);
+       mutex_unlock(&ak4531->reg_mutex);
        return change;
-}                                                                                                                                                                                                                                                                                                            
+}
 
 #define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
@@ -200,7 +217,7 @@ static int snd_ak4531_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
   .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \
   .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) }
 
-static int snd_ak4531_info_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
        uinfo->count = 4;
@@ -209,28 +226,26 @@ static int snd_ak4531_info_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_info
        return 0;
 }
  
-static int snd_ak4531_get_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
        int reg1 = kcontrol->private_value & 0xff;
        int reg2 = (kcontrol->private_value >> 8) & 0xff;
        int left_shift = (kcontrol->private_value >> 16) & 0x0f;
        int right_shift = (kcontrol->private_value >> 24) & 0x0f;
 
-       spin_lock_irqsave(&ak4531->reg_lock, flags);
+       mutex_lock(&ak4531->reg_mutex);
        ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1;
        ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1;
        ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1;
        ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1;
-       spin_unlock_irqrestore(&ak4531->reg_lock, flags);
+       mutex_unlock(&ak4531->reg_mutex);
        return 0;
-}                                                                                                                                                                                                                                                                                                            
+}
 
-static int snd_ak4531_put_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
        int reg1 = kcontrol->private_value & 0xff;
        int reg2 = (kcontrol->private_value >> 8) & 0xff;
        int left_shift = (kcontrol->private_value >> 16) & 0x0f;
@@ -238,7 +253,7 @@ static int snd_ak4531_put_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
        int change;
        int val1, val2;
 
-       spin_lock_irqsave(&ak4531->reg_lock, flags);
+       mutex_lock(&ak4531->reg_mutex);
        val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift));
        val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift));
        val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift;
@@ -248,56 +263,66 @@ static int snd_ak4531_put_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
        change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2];
        ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1);
        ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2);
-       spin_unlock_irqrestore(&ak4531->reg_lock, flags);
+       mutex_unlock(&ak4531->reg_mutex);
        return change;
-}                                                                                                                                                                                                                                                                                                            
+}
 
-#define AK4531_CONTROLS (sizeof(snd_ak4531_controls)/sizeof(snd_kcontrol_new_t))
+static DECLARE_TLV_DB_SCALE(db_scale_master, -6200, 200, 0);
+static DECLARE_TLV_DB_SCALE(db_scale_mono, -2800, 400, 0);
+static DECLARE_TLV_DB_SCALE(db_scale_input, -5000, 200, 0);
 
-static snd_kcontrol_new_t snd_ak4531_controls[] = {
+static struct snd_kcontrol_new snd_ak4531_controls[] = {
 
-AK4531_DOUBLE("Master Playback Switch", 0, AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1),
+AK4531_DOUBLE_TLV("Master Playback Switch", 0,
+                 AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1,
+                 db_scale_master),
 AK4531_DOUBLE("Master Playback Volume", 0, AK4531_LMASTER, AK4531_RMASTER, 0, 0, 0x1f, 1),
 
-AK4531_SINGLE("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1),
+AK4531_SINGLE_TLV("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1,
+                 db_scale_mono),
 AK4531_SINGLE("Master Mono Playback Volume", 0, AK4531_MONO_OUT, 0, 0x07, 1),
 
 AK4531_DOUBLE("PCM Switch", 0, AK4531_LVOICE, AK4531_RVOICE, 7, 7, 1, 1),
-AK4531_DOUBLE("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1),
+AK4531_DOUBLE_TLV("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1,
+                 db_scale_input),
 AK4531_DOUBLE("PCM Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 3, 2, 1, 0),
 AK4531_DOUBLE("PCM Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 2, 2, 1, 0),
 
 AK4531_DOUBLE("PCM Switch", 1, AK4531_LFM, AK4531_RFM, 7, 7, 1, 1),
-AK4531_DOUBLE("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1),
+AK4531_DOUBLE_TLV("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1,
+                 db_scale_input),
 AK4531_DOUBLE("PCM Playback Switch", 1, AK4531_OUT_SW1, AK4531_OUT_SW1, 6, 5, 1, 0),
 AK4531_INPUT_SW("PCM Capture Route", 1, AK4531_LIN_SW1, AK4531_RIN_SW1, 6, 5),
 
 AK4531_DOUBLE("CD Switch", 0, AK4531_LCD, AK4531_RCD, 7, 7, 1, 1),
-AK4531_DOUBLE("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1),
+AK4531_DOUBLE_TLV("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1,
+                 db_scale_input),
 AK4531_DOUBLE("CD Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 2, 1, 1, 0),
 AK4531_INPUT_SW("CD Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 2, 1),
 
 AK4531_DOUBLE("Line Switch", 0, AK4531_LLINE, AK4531_RLINE, 7, 7, 1, 1),
-AK4531_DOUBLE("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1),
+AK4531_DOUBLE_TLV("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1,
+                 db_scale_input),
 AK4531_DOUBLE("Line Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 4, 3, 1, 0),
 AK4531_INPUT_SW("Line Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 4, 3),
 
 AK4531_DOUBLE("Aux Switch", 0, AK4531_LAUXA, AK4531_RAUXA, 7, 7, 1, 1),
-AK4531_DOUBLE("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1),
+AK4531_DOUBLE_TLV("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1,
+                 db_scale_input),
 AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0),
 AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3),
 
 AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1),
-AK4531_SINGLE("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1),
+AK4531_SINGLE_TLV("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1, db_scale_input),
 AK4531_SINGLE("Mono Playback Switch", 0, AK4531_OUT_SW2, 0, 1, 0),
 AK4531_DOUBLE("Mono Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 0, 0, 1, 0),
 
 AK4531_SINGLE("Mono Switch", 1, AK4531_MONO2, 7, 1, 1),
-AK4531_SINGLE("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1),
+AK4531_SINGLE_TLV("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1, db_scale_input),
 AK4531_SINGLE("Mono Playback Switch", 1, AK4531_OUT_SW2, 1, 1, 0),
 AK4531_DOUBLE("Mono Capture Switch", 1, AK4531_LIN_SW2, AK4531_RIN_SW2, 1, 1, 1, 0),
 
-AK4531_SINGLE("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1),
+AK4531_SINGLE_TLV("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1, db_scale_input),
 AK4531_SINGLE("Mic Switch", 0, AK4531_MIC, 7, 1, 1),
 AK4531_SINGLE("Mic Playback Switch", 0, AK4531_OUT_SW1, 0, 1, 0),
 AK4531_DOUBLE("Mic Capture Switch", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 0, 0, 1, 0),
@@ -310,19 +335,19 @@ AK4531_SINGLE("AD Input Select", 0, AK4531_AD_IN, 0, 1, 0),
 AK4531_SINGLE("Mic Boost (+30dB)", 0, AK4531_MIC_GAIN, 0, 1, 0)
 };
 
-static int snd_ak4531_free(ak4531_t *ak4531)
+static int snd_ak4531_free(struct snd_ak4531 *ak4531)
 {
        if (ak4531) {
                if (ak4531->private_free)
                        ak4531->private_free(ak4531);
-               snd_magic_kfree(ak4531);
+               kfree(ak4531);
        }
        return 0;
 }
 
-static int snd_ak4531_dev_free(snd_device_t *device)
+static int snd_ak4531_dev_free(struct snd_device *device)
 {
-       ak4531_t *ak4531 = snd_magic_cast(ak4531_t, device->device_data, return -ENXIO);
+       struct snd_ak4531 *ak4531 = device->device_data;
        return snd_ak4531_free(ak4531);
 }
 
@@ -355,23 +380,24 @@ static u8 snd_ak4531_initial_map[0x19 + 1] = {
        0x01            /* 19: Mic Amp Setup */
 };
 
-int snd_ak4531_mixer(snd_card_t * card, ak4531_t * _ak4531, ak4531_t ** rak4531)
+int snd_ak4531_mixer(struct snd_card *card, struct snd_ak4531 *_ak4531,
+                    struct snd_ak4531 **rak4531)
 {
        unsigned int idx;
        int err;
-       ak4531_t * ak4531;
-       static snd_device_ops_t ops = {
+       struct snd_ak4531 *ak4531;
+       static struct snd_device_ops ops = {
                .dev_free =     snd_ak4531_dev_free,
        };
 
        snd_assert(rak4531 != NULL, return -EINVAL);
        *rak4531 = NULL;
        snd_assert(card != NULL && _ak4531 != NULL, return -EINVAL);
-       ak4531 = snd_magic_kcalloc(ak4531_t, 0, GFP_KERNEL);
+       ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL);
        if (ak4531 == NULL)
                return -ENOMEM;
        *ak4531 = *_ak4531;
-       spin_lock_init(&ak4531->reg_lock);
+       mutex_init(&ak4531->reg_mutex);
        if ((err = snd_component_add(card, "AK4531")) < 0) {
                snd_ak4531_free(ak4531);
                return err;
@@ -380,19 +406,19 @@ int snd_ak4531_mixer(snd_card_t * card, ak4531_t * _ak4531, ak4531_t ** rak4531)
        ak4531->write(ak4531, AK4531_RESET, 0x03);      /* no RST, PD */
        udelay(100);
        ak4531->write(ak4531, AK4531_CLOCK, 0x00);      /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */
-       for (idx = 0; idx < 0x19; idx++) {
+       for (idx = 0; idx <= 0x19; idx++) {
                if (idx == AK4531_RESET || idx == AK4531_CLOCK)
                        continue;
                ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]);    /* recording source is mixer */
        }
-       for (idx = 0; idx < AK4531_CONTROLS; idx++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) {
                if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) {
                        snd_ak4531_free(ak4531);
                        return err;
                }
        }
        snd_ak4531_proc_init(card, ak4531);
-       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ak4531, &ops)) < 0) {
+       if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) {
                snd_ak4531_free(ak4531);
                return err;
        }
@@ -405,13 +431,44 @@ int snd_ak4531_mixer(snd_card_t * card, ak4531_t * _ak4531, ak4531_t ** rak4531)
 }
 
 /*
+ * power management
+ */
+#ifdef CONFIG_PM
+void snd_ak4531_suspend(struct snd_ak4531 *ak4531)
+{
+       /* mute */
+       ak4531->write(ak4531, AK4531_LMASTER, 0x9f);
+       ak4531->write(ak4531, AK4531_RMASTER, 0x9f);
+       /* powerdown */
+       ak4531->write(ak4531, AK4531_RESET, 0x01);
+}
+
+void snd_ak4531_resume(struct snd_ak4531 *ak4531)
+{
+       int idx;
+
+       /* initialize */
+       ak4531->write(ak4531, AK4531_RESET, 0x03);
+       udelay(100);
+       ak4531->write(ak4531, AK4531_CLOCK, 0x00);
+       /* restore mixer registers */
+       for (idx = 0; idx <= 0x19; idx++) {
+               if (idx == AK4531_RESET || idx == AK4531_CLOCK)
+                       continue;
+               ak4531->write(ak4531, idx, ak4531->regs[idx]);
+       }
+}
+#endif
 
+#ifdef CONFIG_PROC_FS
+/*
+ * /proc interface
  */
 
-static void snd_ak4531_proc_read(snd_info_entry_t *entry, 
-                                snd_info_buffer_t * buffer)
+static void snd_ak4531_proc_read(struct snd_info_entry *entry, 
+                                struct snd_info_buffer *buffer)
 {
-       ak4531_t *ak4531 = snd_magic_cast(ak4531_t, entry->private_data, return);
+       struct snd_ak4531 *ak4531 = entry->private_data;
 
        snd_iprintf(buffer, "Asahi Kasei AK4531\n\n");
        snd_iprintf(buffer, "Recording source   : %s\n"
@@ -420,15 +477,20 @@ static void snd_ak4531_proc_read(snd_info_entry_t *entry,
                    ak4531->regs[AK4531_MIC_GAIN] & 1 ? "+30dB" : "+0dB");
 }
 
-static void snd_ak4531_proc_init(snd_card_t * card, ak4531_t * ak4531)
+static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531)
 {
-       snd_info_entry_t *entry;
+       struct snd_info_entry *entry;
 
        if (! snd_card_proc_new(card, "ak4531", &entry))
-               snd_info_set_text_ops(entry, ak4531, 1024, snd_ak4531_proc_read);
+               snd_info_set_text_ops(entry, ak4531, snd_ak4531_proc_read);
 }
+#endif
 
 EXPORT_SYMBOL(snd_ak4531_mixer);
+#ifdef CONFIG_PM
+EXPORT_SYMBOL(snd_ak4531_suspend);
+EXPORT_SYMBOL(snd_ak4531_resume);
+#endif
 
 /*
  *  INIT part