[media] snd_tea575x: Add a cannot_mute flag
[linux-3.10.git] / sound / i2c / other / ak4117.c
index d51b51dd86d6dda11178e571aadb892e327b753b..b4b2a51fc117a98b667e10de335a86c5e2c1ce00 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  Routines for control of the AK4117 via 4-wire serial interface
  *  IEC958 (S/PDIF) receiver by Asahi Kasei
- *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  *
  *
  *   This program is free software; you can redistribute it and/or modify
  *
  */
 
-#include <sound/driver.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/module.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/pcm.h>
 #include <sound/ak4117.h>
 #include <sound/asoundef.h>
 
-MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 MODULE_DESCRIPTION("AK4117 IEC958 (S/PDIF) receiver by Asahi Kasei");
 MODULE_LICENSE("GPL");
 
@@ -37,49 +37,49 @@ MODULE_LICENSE("GPL");
 
 static void snd_ak4117_timer(unsigned long data);
 
-static void reg_write(ak4117_t *ak4117, unsigned char reg, unsigned char val)
+static void reg_write(struct ak4117 *ak4117, unsigned char reg, unsigned char val)
 {
        ak4117->write(ak4117->private_data, reg, val);
        if (reg < sizeof(ak4117->regmap))
                ak4117->regmap[reg] = val;
 }
 
-static inline unsigned char reg_read(ak4117_t *ak4117, unsigned char reg)
+static inline unsigned char reg_read(struct ak4117 *ak4117, unsigned char reg)
 {
        return ak4117->read(ak4117->private_data, reg);
 }
 
 #if 0
-static void reg_dump(ak4117_t *ak4117)
+static void reg_dump(struct ak4117 *ak4117)
 {
        int i;
 
-       printk("AK4117 REG DUMP:\n");
+       printk(KERN_DEBUG "AK4117 REG DUMP:\n");
        for (i = 0; i < 0x1b; i++)
-               printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4117, i), i < sizeof(ak4117->regmap) ? ak4117->regmap[i] : 0);
+               printk(KERN_DEBUG "reg[%02x] = %02x (%02x)\n", i, reg_read(ak4117, i), i < sizeof(ak4117->regmap) ? ak4117->regmap[i] : 0);
 }
 #endif
 
-static void snd_ak4117_free(ak4117_t *chip)
+static void snd_ak4117_free(struct ak4117 *chip)
 {
        del_timer(&chip->timer);
        kfree(chip);
 }
 
-static int snd_ak4117_dev_free(snd_device_t *device)
+static int snd_ak4117_dev_free(struct snd_device *device)
 {
-       ak4117_t *chip = device->device_data;
+       struct ak4117 *chip = device->device_data;
        snd_ak4117_free(chip);
        return 0;
 }
 
-int snd_ak4117_create(snd_card_t *card, ak4117_read_t *read, ak4117_write_t *write,
-                     unsigned char pgm[5], void *private_data, ak4117_t **r_ak4117)
+int snd_ak4117_create(struct snd_card *card, ak4117_read_t *read, ak4117_write_t *write,
+                     const unsigned char pgm[5], void *private_data, struct ak4117 **r_ak4117)
 {
-       ak4117_t *chip;
+       struct ak4117 *chip;
        int err = 0;
        unsigned char reg;
-       static snd_device_ops_t ops = {
+       static struct snd_device_ops ops = {
                .dev_free =     snd_ak4117_dev_free,
        };
 
@@ -115,14 +115,14 @@ int snd_ak4117_create(snd_card_t *card, ak4117_read_t *read, ak4117_write_t *wri
        return err < 0 ? err : -EIO;
 }
 
-void snd_ak4117_reg_write(ak4117_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
+void snd_ak4117_reg_write(struct ak4117 *chip, unsigned char reg, unsigned char mask, unsigned char val)
 {
        if (reg >= 5)
                return;
        reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val);
 }
 
-void snd_ak4117_reinit(ak4117_t *chip)
+void snd_ak4117_reinit(struct ak4117 *chip)
 {
        unsigned char old = chip->regmap[AK4117_REG_PWRDN], reg;
 
@@ -157,8 +157,8 @@ static unsigned int external_rate(unsigned char rcs1)
        }
 }
 
-static int snd_ak4117_in_error_info(snd_kcontrol_t *kcontrol,
-                                   snd_ctl_elem_info_t *uinfo)
+static int snd_ak4117_in_error_info(struct snd_kcontrol *kcontrol,
+                                   struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 1;
@@ -167,10 +167,10 @@ static int snd_ak4117_in_error_info(snd_kcontrol_t *kcontrol,
        return 0;
 }
 
-static int snd_ak4117_in_error_get(snd_kcontrol_t *kcontrol,
-                                  snd_ctl_elem_value_t *ucontrol)
+static int snd_ak4117_in_error_get(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
        long *ptr;
 
        spin_lock_irq(&chip->lock);
@@ -181,20 +181,12 @@ static int snd_ak4117_in_error_get(snd_kcontrol_t *kcontrol,
        return 0;
 }
 
-static int snd_ak4117_in_bit_info(snd_kcontrol_t *kcontrol,
-                                 snd_ctl_elem_info_t *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
+#define snd_ak4117_in_bit_info         snd_ctl_boolean_mono_info
 
-static int snd_ak4117_in_bit_get(snd_kcontrol_t *kcontrol,
-                                snd_ctl_elem_value_t *ucontrol)
+static int snd_ak4117_in_bit_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
        unsigned char reg = kcontrol->private_value & 0xff;
        unsigned char bit = (kcontrol->private_value >> 8) & 0xff;
        unsigned char inv = (kcontrol->private_value >> 31) & 1;
@@ -203,8 +195,8 @@ static int snd_ak4117_in_bit_get(snd_kcontrol_t *kcontrol,
        return 0;
 }
 
-static int snd_ak4117_rx_info(snd_kcontrol_t *kcontrol,
-                             snd_ctl_elem_info_t *uinfo)
+static int snd_ak4117_rx_info(struct snd_kcontrol *kcontrol,
+                             struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 1;
@@ -213,19 +205,19 @@ static int snd_ak4117_rx_info(snd_kcontrol_t *kcontrol,
        return 0;
 }
 
-static int snd_ak4117_rx_get(snd_kcontrol_t *kcontrol,
-                            snd_ctl_elem_value_t *ucontrol)
+static int snd_ak4117_rx_get(struct snd_kcontrol *kcontrol,
+                            struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
 
        ucontrol->value.integer.value[0] = (chip->regmap[AK4117_REG_IO] & AK4117_IPS) ? 1 : 0;
        return 0;
 }
 
-static int snd_ak4117_rx_put(snd_kcontrol_t *kcontrol,
-                            snd_ctl_elem_value_t *ucontrol)
+static int snd_ak4117_rx_put(struct snd_kcontrol *kcontrol,
+                            struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
        int change;
        u8 old_val;
        
@@ -238,8 +230,8 @@ static int snd_ak4117_rx_put(snd_kcontrol_t *kcontrol,
        return change;
 }
 
-static int snd_ak4117_rate_info(snd_kcontrol_t *kcontrol,
-                               snd_ctl_elem_info_t *uinfo)
+static int snd_ak4117_rate_info(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 1;
@@ -248,26 +240,26 @@ static int snd_ak4117_rate_info(snd_kcontrol_t *kcontrol,
        return 0;
 }
 
-static int snd_ak4117_rate_get(snd_kcontrol_t *kcontrol,
-                              snd_ctl_elem_value_t *ucontrol)
+static int snd_ak4117_rate_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
 
        ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4117_REG_RCS1));
        return 0;
 }
 
-static int snd_ak4117_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ak4117_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
        uinfo->count = 1;
        return 0;
 }
 
-static int snd_ak4117_spdif_get(snd_kcontrol_t * kcontrol,
-                               snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4117_spdif_get(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
        unsigned i;
 
        for (i = 0; i < AK4117_REG_RXCSB_SIZE; i++)
@@ -275,21 +267,21 @@ static int snd_ak4117_spdif_get(snd_kcontrol_t * kcontrol,
        return 0;
 }
 
-static int snd_ak4117_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ak4117_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
        uinfo->count = 1;
        return 0;
 }
 
-static int snd_ak4117_spdif_mask_get(snd_kcontrol_t * kcontrol,
-                                     snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4117_spdif_mask_get(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_value *ucontrol)
 {
        memset(ucontrol->value.iec958.status, 0xff, AK4117_REG_RXCSB_SIZE);
        return 0;
 }
 
-static int snd_ak4117_spdif_pinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ak4117_spdif_pinfo(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->value.integer.min = 0;
@@ -298,10 +290,10 @@ static int snd_ak4117_spdif_pinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
        return 0;
 }
 
-static int snd_ak4117_spdif_pget(snd_kcontrol_t * kcontrol,
-                                snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4117_spdif_pget(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
        unsigned short tmp;
 
        ucontrol->value.integer.value[0] = 0xf8f2;
@@ -313,17 +305,17 @@ static int snd_ak4117_spdif_pget(snd_kcontrol_t * kcontrol,
        return 0;
 }
 
-static int snd_ak4117_spdif_qinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ak4117_spdif_qinfo(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
        uinfo->count = AK4117_REG_QSUB_SIZE;
        return 0;
 }
 
-static int snd_ak4117_spdif_qget(snd_kcontrol_t * kcontrol,
-                                snd_ctl_elem_value_t * ucontrol)
+static int snd_ak4117_spdif_qget(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
 {
-       ak4117_t *chip = snd_kcontrol_chip(kcontrol);
+       struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
        unsigned i;
 
        for (i = 0; i < AK4117_REG_QSUB_SIZE; i++)
@@ -332,14 +324,14 @@ static int snd_ak4117_spdif_qget(snd_kcontrol_t * kcontrol,
 }
 
 /* Don't forget to change AK4117_CONTROLS define!!! */
-static snd_kcontrol_new_t snd_ak4117_iec958_controls[] = {
+static struct snd_kcontrol_new snd_ak4117_iec958_controls[] = {
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
        .name =         "IEC958 Parity Errors",
        .access =       SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
        .info =         snd_ak4117_in_error_info,
        .get =          snd_ak4117_in_error_get,
-       .private_value = offsetof(ak4117_t, parity_errors),
+       .private_value = offsetof(struct ak4117, parity_errors),
 },
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
@@ -347,7 +339,7 @@ static snd_kcontrol_new_t snd_ak4117_iec958_controls[] = {
        .access =       SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
        .info =         snd_ak4117_in_error_info,
        .get =          snd_ak4117_in_error_get,
-       .private_value = offsetof(ak4117_t, v_bit_errors),
+       .private_value = offsetof(struct ak4117, v_bit_errors),
 },
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
@@ -355,7 +347,7 @@ static snd_kcontrol_new_t snd_ak4117_iec958_controls[] = {
        .access =       SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
        .info =         snd_ak4117_in_error_info,
        .get =          snd_ak4117_in_error_get,
-       .private_value = offsetof(ak4117_t, ccrc_errors),
+       .private_value = offsetof(struct ak4117, ccrc_errors),
 },
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
@@ -363,7 +355,7 @@ static snd_kcontrol_new_t snd_ak4117_iec958_controls[] = {
        .access =       SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
        .info =         snd_ak4117_in_error_info,
        .get =          snd_ak4117_in_error_get,
-       .private_value = offsetof(ak4117_t, qcrc_errors),
+       .private_value = offsetof(struct ak4117, qcrc_errors),
 },
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
@@ -434,13 +426,14 @@ static snd_kcontrol_new_t snd_ak4117_iec958_controls[] = {
 }
 };
 
-int snd_ak4117_build(ak4117_t *ak4117, snd_pcm_substream_t *cap_substream)
+int snd_ak4117_build(struct ak4117 *ak4117, struct snd_pcm_substream *cap_substream)
 {
-       snd_kcontrol_t *kctl;
+       struct snd_kcontrol *kctl;
        unsigned int idx;
        int err;
 
-       snd_assert(cap_substream, return -EINVAL);
+       if (snd_BUG_ON(!cap_substream))
+               return -EINVAL;
        ak4117->substream = cap_substream;
        for (idx = 0; idx < AK4117_CONTROLS; idx++) {
                kctl = snd_ctl_new1(&snd_ak4117_iec958_controls[idx], ak4117);
@@ -456,7 +449,7 @@ int snd_ak4117_build(ak4117_t *ak4117, snd_pcm_substream_t *cap_substream)
        return 0;
 }
 
-int snd_ak4117_external_rate(ak4117_t *ak4117)
+int snd_ak4117_external_rate(struct ak4117 *ak4117)
 {
        unsigned char rcs1;
 
@@ -464,9 +457,9 @@ int snd_ak4117_external_rate(ak4117_t *ak4117)
        return external_rate(rcs1);
 }
 
-int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags)
+int snd_ak4117_check_rate_and_errors(struct ak4117 *ak4117, unsigned int flags)
 {
-       snd_pcm_runtime_t *runtime = ak4117->substream ? ak4117->substream->runtime : NULL;
+       struct snd_pcm_runtime *runtime = ak4117->substream ? ak4117->substream->runtime : NULL;
        unsigned long _flags;
        int res = 0;
        unsigned char rcs0, rcs1, rcs2;
@@ -477,7 +470,7 @@ int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags)
                goto __rate;
        rcs0 = reg_read(ak4117, AK4117_REG_RCS0);
        rcs2 = reg_read(ak4117, AK4117_REG_RCS2);
-       // printk("AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2);
+       // printk(KERN_DEBUG "AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2);
        spin_lock_irqsave(&ak4117->lock, _flags);
        if (rcs0 & AK4117_PAR)
                ak4117->parity_errors++;
@@ -530,7 +523,7 @@ int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags)
        if (!(flags & AK4117_CHECK_NO_RATE) && runtime && runtime->rate != res) {
                snd_pcm_stream_lock_irqsave(ak4117->substream, _flags);
                if (snd_pcm_running(ak4117->substream)) {
-                       // printk("rate changed (%i <- %i)\n", runtime->rate, res);
+                       // printk(KERN_DEBUG "rate changed (%i <- %i)\n", runtime->rate, res);
                        snd_pcm_stop(ak4117->substream, SNDRV_PCM_STATE_DRAINING);
                        wake_up(&runtime->sleep);
                        res = 1;
@@ -542,7 +535,7 @@ int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags)
 
 static void snd_ak4117_timer(unsigned long data)
 {
-       ak4117_t *chip = (ak4117_t *)data;
+       struct ak4117 *chip = (struct ak4117 *)data;
 
        if (chip->init)
                return;