]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/pci/cs46xx/cs46xx_lib.c
ALSA: Kill snd_assert() in sound/pci/*
[linux-2.6-omap-h63xx.git] / sound / pci / cs46xx / cs46xx_lib.c
index 2c7bfc9fef619646ae0a85ee3d1dc8321a2dd792..a10ab8283f9a003049b98d36572d3ef630b5949f 100644 (file)
@@ -8,7 +8,7 @@
  *    - Sometimes the SPDIF input DSP tasks get's unsynchronized
  *      and the SPDIF get somewhat "distorcionated", or/and left right channel
  *      are swapped. To get around this problem when it happens, mute and unmute 
- *      the SPDIF input mixer controll.
+ *      the SPDIF input mixer control.
  *    - On the Hercules Game Theater XP the amplifier are sometimes turned
  *      off on inadecuate moments which causes distorcions on sound.
  *
@@ -45,7 +45,6 @@
  *
  */
 
-#include <sound/driver.h>
 #include <linux/delay.h>
 #include <linux/pci.h>
 #include <linux/pm.h>
@@ -91,9 +90,10 @@ static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip,
        int count;
        unsigned short result,tmp;
        u32 offset = 0;
-       snd_assert ( (codec_index == CS46XX_PRIMARY_CODEC_INDEX) ||
-                    (codec_index == CS46XX_SECONDARY_CODEC_INDEX),
-                    return -EINVAL);
+
+       if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
+                      codec_index != CS46XX_SECONDARY_CODEC_INDEX))
+               return -EINVAL;
 
        chip->active_ctrl(chip, 1);
 
@@ -213,9 +213,9 @@ static unsigned short snd_cs46xx_ac97_read(struct snd_ac97 * ac97,
        unsigned short val;
        int codec_index = ac97->num;
 
-       snd_assert(codec_index == CS46XX_PRIMARY_CODEC_INDEX ||
-                  codec_index == CS46XX_SECONDARY_CODEC_INDEX,
-                  return 0xffff);
+       if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
+                      codec_index != CS46XX_SECONDARY_CODEC_INDEX))
+               return 0xffff;
 
        val = snd_cs46xx_codec_read(chip, reg, codec_index);
 
@@ -230,9 +230,9 @@ static void snd_cs46xx_codec_write(struct snd_cs46xx *chip,
 {
        int count;
 
-       snd_assert ((codec_index == CS46XX_PRIMARY_CODEC_INDEX) ||
-                   (codec_index == CS46XX_SECONDARY_CODEC_INDEX),
-                   return);
+       if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
+                      codec_index != CS46XX_SECONDARY_CODEC_INDEX))
+               return;
 
        chip->active_ctrl(chip, 1);
 
@@ -295,9 +295,9 @@ static void snd_cs46xx_ac97_write(struct snd_ac97 *ac97,
        struct snd_cs46xx *chip = ac97->private_data;
        int codec_index = ac97->num;
 
-       snd_assert(codec_index == CS46XX_PRIMARY_CODEC_INDEX ||
-                  codec_index == CS46XX_SECONDARY_CODEC_INDEX,
-                  return);
+       if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
+                      codec_index != CS46XX_SECONDARY_CODEC_INDEX))
+               return;
 
        snd_cs46xx_codec_write(chip, reg, val, codec_index);
 }
@@ -316,7 +316,8 @@ int snd_cs46xx_download(struct snd_cs46xx *chip,
        unsigned int bank = offset >> 16;
        offset = offset & 0xffff;
 
-       snd_assert(!(offset & 3) && !(len & 3), return -EINVAL);
+       if (snd_BUG_ON((offset & 3) || (len & 3)))
+               return -EINVAL;
        dst = chip->region.idx[bank+1].remap_addr + offset;
        len /= sizeof(u32);
 
@@ -344,7 +345,8 @@ int snd_cs46xx_clear_BA1(struct snd_cs46xx *chip,
        unsigned int bank = offset >> 16;
        offset = offset & 0xffff;
 
-       snd_assert(!(offset & 3) && !(len & 3), return -EINVAL);
+       if (snd_BUG_ON((offset & 3) || (len & 3)))
+               return -EINVAL;
        dst = chip->region.idx[bank+1].remap_addr + offset;
        len /= sizeof(u32);
 
@@ -723,7 +725,9 @@ static snd_pcm_uframes_t snd_cs46xx_playback_direct_pointer(struct snd_pcm_subst
        struct snd_cs46xx *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
        struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data;
-       snd_assert (cpcm->pcm_channel,return -ENXIO);
+
+       if (snd_BUG_ON(!cpcm->pcm_channel))
+               return -ENXIO;
 
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
        ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2);
@@ -741,7 +745,8 @@ static snd_pcm_uframes_t snd_cs46xx_playback_indirect_pointer(struct snd_pcm_sub
        struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data;
 
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
-       snd_assert (cpcm->pcm_channel,return -ENXIO);
+       if (snd_BUG_ON(!cpcm->pcm_channel))
+               return -ENXIO;
        ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2);
 #else
        ptr = snd_cs46xx_peek(chip, BA1_PBA);
@@ -909,7 +914,8 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
        cpcm = runtime->private_data;
 
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
-       snd_assert (sample_rate != 0, return -ENXIO);
+       if (snd_BUG_ON(!sample_rate))
+               return -ENXIO;
 
        mutex_lock(&chip->spos_mutex);
 
@@ -918,7 +924,7 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
                return -ENXIO;
        }
 
-       snd_assert (cpcm->pcm_channel != NULL);
+       snd_BUG_ON(!cpcm->pcm_channel);
        if (!cpcm->pcm_channel) {
                mutex_unlock(&chip->spos_mutex);
                return -ENXIO;
@@ -953,7 +959,7 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
                } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) {
                        substream->ops = &snd_cs46xx_playback_iec958_ops;
                } else {
-                       snd_assert(0);
+                       snd_BUG();
                }
 #else
                substream->ops = &snd_cs46xx_playback_ops;
@@ -982,7 +988,7 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
                } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) {
                        substream->ops = &snd_cs46xx_playback_indirect_iec958_ops;
                } else {
-                       snd_assert(0);
+                       snd_BUG();
                }
 #else
                substream->ops = &snd_cs46xx_playback_indirect_ops;
@@ -1030,7 +1036,8 @@ static int snd_cs46xx_playback_prepare(struct snd_pcm_substream *substream)
        cpcm = runtime->private_data;
 
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
-    snd_assert (cpcm->pcm_channel != NULL, return -ENXIO);
+       if (snd_BUG_ON(!cpcm->pcm_channel))
+               return -ENXIO;
 
        pfie = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 1) << 2 );
        pfie &= ~0x0000f03f;
@@ -1715,9 +1722,9 @@ static void snd_cs46xx_mixer_free_ac97(struct snd_ac97 *ac97)
 {
        struct snd_cs46xx *chip = ac97->private_data;
 
-       snd_assert ((ac97 == chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]) ||
-                   (ac97 == chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]),
-                   return);
+       if (snd_BUG_ON(ac97 != chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] &&
+                      ac97 != chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]))
+               return;
 
        if (ac97 == chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]) {
                chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] = NULL;
@@ -1865,7 +1872,7 @@ static int snd_cs46xx_iec958_put(struct snd_kcontrol *kcontrol,
                break;
        default:
                res = -EINVAL;
-               snd_assert(0, (void)0);
+               snd_BUG(); /* should never happen ... */
        }
 
        return res;
@@ -2084,71 +2091,6 @@ static int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol,
 #endif /* CONFIG_SND_CS46XX_NEW_DSP */
 
 
-#ifdef CONFIG_SND_CS46XX_DEBUG_GPIO
-static int snd_cs46xx_egpio_select_info(struct snd_kcontrol *kcontrol, 
-                                        struct snd_ctl_elem_info *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 8;
-       return 0;
-}
-
-static int snd_cs46xx_egpio_select_get(struct snd_kcontrol *kcontrol, 
-                                       struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol);
-       ucontrol->value.integer.value[0] = chip->current_gpio;
-
-       return 0;
-}
-
-static int snd_cs46xx_egpio_select_put(struct snd_kcontrol *kcontrol, 
-                                       struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol);
-       int change = (chip->current_gpio != ucontrol->value.integer.value[0]);
-       chip->current_gpio = ucontrol->value.integer.value[0];
-
-       return change;
-}
-
-
-static int snd_cs46xx_egpio_get(struct snd_kcontrol *kcontrol, 
-                                       struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol);
-       int reg = kcontrol->private_value;
-
-       snd_printdd ("put: reg = %04x, gpio %02x\n",reg,chip->current_gpio);
-       ucontrol->value.integer.value[0] = 
-               (snd_cs46xx_peekBA0(chip, reg) & (1 << chip->current_gpio)) ? 1 : 0;
-  
-       return 0;
-}
-
-static int snd_cs46xx_egpio_put(struct snd_kcontrol *kcontrol, 
-                                       struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol);
-       int reg = kcontrol->private_value;
-       int val = snd_cs46xx_peekBA0(chip, reg);
-       int oldval = val;
-       snd_printdd ("put: reg = %04x, gpio %02x\n",reg,chip->current_gpio);
-
-       if (ucontrol->value.integer.value[0])
-               val |= (1 << chip->current_gpio);
-       else
-               val &= ~(1 << chip->current_gpio);
-
-       snd_cs46xx_pokeBA0(chip, reg,val);
-       snd_printdd ("put: val %08x oldval %08x\n",val,oldval);
-
-       return (oldval != val);
-}
-#endif /* CONFIG_SND_CS46XX_DEBUG_GPIO */
-
 static struct snd_kcontrol_new snd_cs46xx_controls[] __devinitdata = {
 {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -2240,40 +2182,6 @@ static struct snd_kcontrol_new snd_cs46xx_controls[] __devinitdata = {
        .put =   snd_cs46xx_spdif_stream_put
 },
 
-#endif
-#ifdef CONFIG_SND_CS46XX_DEBUG_GPIO
-{
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "EGPIO select",
-       .info = snd_cs46xx_egpio_select_info,
-       .get = snd_cs46xx_egpio_select_get,
-       .put = snd_cs46xx_egpio_select_put,
-       .private_value = 0,
-},
-{
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "EGPIO Input/Output",
-       .info = snd_mixer_boolean_info,
-       .get = snd_cs46xx_egpio_get,
-       .put = snd_cs46xx_egpio_put,
-       .private_value = BA0_EGPIODR,
-},
-{
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "EGPIO CMOS/Open drain",
-       .info = snd_mixer_boolean_info,
-       .get = snd_cs46xx_egpio_get,
-       .put = snd_cs46xx_egpio_put,
-       .private_value = BA0_EGPIOPTR,
-},
-{
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "EGPIO On/Off",
-       .info = snd_mixer_boolean_info,
-       .get = snd_cs46xx_egpio_get,
-       .put = snd_cs46xx_egpio_put,
-       .private_value = BA0_EGPIOSR,
-},
 #endif
 };
 
@@ -2336,7 +2244,7 @@ static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97)
                snd_printdd("cs46xx: CODOEC2 mode %04x\n",0x3);
                snd_cs46xx_ac97_write(ac97,AC97_CSR_ACMODE,0x3);
        } else {
-               snd_assert(0); /* should never happen ... */
+               snd_BUG(); /* should never happen ... */
        }
 
        udelay(50);
@@ -2653,7 +2561,8 @@ static void snd_cs46xx_gameport_trigger(struct gameport *gameport)
 {
        struct snd_cs46xx *chip = gameport_get_port_data(gameport);
 
-       snd_assert(chip, return);
+       if (snd_BUG_ON(!chip))
+               return;
        snd_cs46xx_pokeBA0(chip, BA0_JSPT, 0xFF);  //outb(gameport->io, 0xFF);
 }
 
@@ -2661,7 +2570,8 @@ static unsigned char snd_cs46xx_gameport_read(struct gameport *gameport)
 {
        struct snd_cs46xx *chip = gameport_get_port_data(gameport);
 
-       snd_assert(chip, return 0);
+       if (snd_BUG_ON(!chip))
+               return 0;
        return snd_cs46xx_peekBA0(chip, BA0_JSPT); //inb(gameport->io);
 }
 
@@ -2670,7 +2580,8 @@ static int snd_cs46xx_gameport_cooked_read(struct gameport *gameport, int *axes,
        struct snd_cs46xx *chip = gameport_get_port_data(gameport);
        unsigned js1, js2, jst;
 
-       snd_assert(chip, return 0);
+       if (snd_BUG_ON(!chip))
+               return 0;
 
        js1 = snd_cs46xx_peekBA0(chip, BA0_JSC1);
        js2 = snd_cs46xx_peekBA0(chip, BA0_JSC2);
@@ -2854,7 +2765,8 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
 {
        int idx;
 
-       snd_assert(chip != NULL, return -EINVAL);
+       if (snd_BUG_ON(!chip))
+               return -EINVAL;
 
        if (chip->active_ctrl)
                chip->active_ctrl(chip, 1);
@@ -2872,6 +2784,9 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
        if (chip->irq >= 0)
                free_irq(chip->irq, chip);
 
+       if (chip->active_ctrl)
+               chip->active_ctrl(chip, -chip->amplifier);
+
        for (idx = 0; idx < 5; idx++) {
                struct snd_cs46xx_region *region = &chip->region.idx[idx];
                if (region->remap_addr)
@@ -2879,9 +2794,6 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
                release_and_free_resource(region->resource);
        }
 
-       if (chip->active_ctrl)
-               chip->active_ctrl(chip, -chip->amplifier);
-       
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
        if (chip->dsp_spos_instance) {
                cs46xx_dsp_spos_destroy(chip);