ASoC: Fix dB scales for WM8990
[safe/jmp/linux-2.6] / sound / pci / atiixp.c
index 5ead666..49d572a 100644 (file)
@@ -19,7 +19,6 @@
  *
  */
 
-#include <sound/driver.h>
 #include <asm/io.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -27,6 +26,7 @@
 #include <linux/pci.h>
 #include <linux/slab.h>
 #include <linux/moduleparam.h>
+#include <linux/mutex.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
 MODULE_DESCRIPTION("ATI IXP AC97 controller");
 MODULE_LICENSE("GPL");
-MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400}}");
+MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400/600}}");
 
 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
 static char *id = SNDRV_DEFAULT_STR1;  /* ID for this card */
 static int ac97_clock = 48000;
 static char *ac97_quirk;
 static int spdif_aclink = 1;
+static int ac97_codec = -1;
 
 module_param(index, int, 0444);
 MODULE_PARM_DESC(index, "Index value for ATI IXP controller.");
@@ -53,6 +54,8 @@ module_param(ac97_clock, int, 0444);
 MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
 module_param(ac97_quirk, charp, 0444);
 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
+module_param(ac97_codec, int, 0444);
+MODULE_PARM_DESC(ac97_codec, "Specify codec instead of probing.");
 module_param(spdif_aclink, bool, 0444);
 MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
 
@@ -277,21 +280,27 @@ struct atiixp {
        unsigned int codec_not_ready_bits;      /* for codec detection */
 
        int spdif_over_aclink;          /* passed from the module option */
-       struct semaphore open_mutex;    /* playback open mutex */
+       struct mutex open_mutex;        /* playback open mutex */
 };
 
 
 /*
  */
-static struct pci_device_id snd_atiixp_ids[] = {
-       { 0x1002, 0x4341, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */
-       { 0x1002, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB300 */
-       { 0x1002, 0x4370, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */
+static DEFINE_PCI_DEVICE_TABLE(snd_atiixp_ids) = {
+       { PCI_VDEVICE(ATI, 0x4341), 0 }, /* SB200 */
+       { PCI_VDEVICE(ATI, 0x4361), 0 }, /* SB300 */
+       { PCI_VDEVICE(ATI, 0x4370), 0 }, /* SB400 */
+       { PCI_VDEVICE(ATI, 0x4382), 0 }, /* SB600 */
        { 0, }
 };
 
 MODULE_DEVICE_TABLE(pci, snd_atiixp_ids);
 
+static struct snd_pci_quirk atiixp_quirks[] __devinitdata = {
+       SND_PCI_QUIRK(0x105b, 0x0c81, "Foxconn RC4107MA-RS2", 0),
+       SND_PCI_QUIRK(0x15bd, 0x3100, "DFI RS482", 0),
+       { } /* terminator */
+};
 
 /*
  * lowlevel functions
@@ -552,11 +561,33 @@ static int snd_atiixp_aclink_down(struct atiixp *chip)
             ATI_REG_ISR_CODEC2_NOT_READY)
 #define CODEC_CHECK_BITS (ALL_CODEC_NOT_READY|ATI_REG_ISR_NEW_FRAME)
 
-static int snd_atiixp_codec_detect(struct atiixp *chip)
+static int __devinit ac97_probing_bugs(struct pci_dev *pci)
+{
+       const struct snd_pci_quirk *q;
+
+       q = snd_pci_quirk_lookup(pci, atiixp_quirks);
+       if (q) {
+               snd_printdd(KERN_INFO "Atiixp quirk for %s.  "
+                           "Forcing codec %d\n", q->name, q->value);
+               return q->value;
+       }
+       /* this hardware doesn't need workarounds.  Probe for codec */
+       return -1;
+}
+
+static int __devinit snd_atiixp_codec_detect(struct atiixp *chip)
 {
        int timeout;
 
        chip->codec_not_ready_bits = 0;
+       if (ac97_codec == -1)
+               ac97_codec = ac97_probing_bugs(chip->pci);
+       if (ac97_codec >= 0) {
+               chip->codec_not_ready_bits |= 
+                       CODEC_CHECK_BITS ^ (1 << (ac97_codec + 10));
+               return 0;
+       }
+
        atiixp_write(chip, IER, CODEC_CHECK_BITS);
        /* wait for the interrupts */
        timeout = 50;
@@ -693,7 +724,9 @@ static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        struct atiixp_dma *dma = substream->runtime->private_data;
        int err = 0;
 
-       snd_assert(dma->ops->enable_transfer && dma->ops->flush_dma, return -EINVAL);
+       if (snd_BUG_ON(!dma->ops->enable_transfer ||
+                      !dma->ops->flush_dma))
+               return -EINVAL;
 
        spin_lock(&chip->reg_lock);
        switch (cmd) {
@@ -1003,7 +1036,8 @@ static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream,
        struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
-       snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL);
+       if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
+               return -EINVAL;
 
        if (dma->opened)
                return -EBUSY;
@@ -1035,7 +1069,8 @@ static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,
 {
        struct atiixp *chip = snd_pcm_substream_chip(substream);
        /* disable DMA bits */
-       snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL);
+       if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
+               return -EINVAL;
        spin_lock_irq(&chip->reg_lock);
        dma->ops->enable_dma(chip, 0);
        spin_unlock_irq(&chip->reg_lock);
@@ -1051,9 +1086,9 @@ static int snd_atiixp_playback_open(struct snd_pcm_substream *substream)
        struct atiixp *chip = snd_pcm_substream_chip(substream);
        int err;
 
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 0);
-       up(&chip->open_mutex);
+       mutex_unlock(&chip->open_mutex);
        if (err < 0)
                return err;
        substream->runtime->hw.channels_max = chip->max_channels;
@@ -1068,9 +1103,9 @@ static int snd_atiixp_playback_close(struct snd_pcm_substream *substream)
 {
        struct atiixp *chip = snd_pcm_substream_chip(substream);
        int err;
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]);
-       up(&chip->open_mutex);
+       mutex_unlock(&chip->open_mutex);
        return err;
 }
 
@@ -1090,12 +1125,12 @@ static int snd_atiixp_spdif_open(struct snd_pcm_substream *substream)
 {
        struct atiixp *chip = snd_pcm_substream_chip(substream);
        int err;
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        if (chip->spdif_over_aclink) /* share DMA_PLAYBACK */
                err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 2);
        else
                err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_SPDIF], -1);
-       up(&chip->open_mutex);
+       mutex_unlock(&chip->open_mutex);
        return err;
 }
 
@@ -1103,12 +1138,12 @@ static int snd_atiixp_spdif_close(struct snd_pcm_substream *substream)
 {
        struct atiixp *chip = snd_pcm_substream_chip(substream);
        int err;
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        if (chip->spdif_over_aclink)
                err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]);
        else
                err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_SPDIF]);
-       up(&chip->open_mutex);
+       mutex_unlock(&chip->open_mutex);
        return err;
 }
 
@@ -1299,7 +1334,7 @@ static int __devinit snd_atiixp_pcm_new(struct atiixp *chip)
 /*
  * interrupt handler
  */
-static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id)
 {
        struct atiixp *chip = dev_id;
        unsigned int status;
@@ -1353,6 +1388,18 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
                .name = "HP Pavilion ZV5030US",
                .type = AC97_TUNE_MUTE_LED
        },
+       {
+               .subvendor = 0x103c,
+               .subdevice = 0x308b,
+               .name = "HP nx6125",
+               .type = AC97_TUNE_MUTE_LED
+       },
+       {
+               .subvendor = 0x103c,
+               .subdevice = 0x3091,
+               .name = "unknown HP",
+               .type = AC97_TUNE_MUTE_LED
+       },
        { } /* terminator */
 };
 
@@ -1389,7 +1436,7 @@ static int __devinit snd_atiixp_mixer_new(struct atiixp *chip, int clock,
                ac97.private_data = chip;
                ac97.pci = chip->pci;
                ac97.num = i;
-               ac97.scaps = AC97_SCAP_SKIP_MODEM;
+               ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
                if (! chip->spdif_over_aclink)
                        ac97.scaps |= AC97_SCAP_NO_SPDIF;
                if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
@@ -1415,11 +1462,13 @@ static int __devinit snd_atiixp_mixer_new(struct atiixp *chip, int clock,
 /*
  * power management
  */
-static int snd_atiixp_suspend(struct snd_card *card, pm_message_t state)
+static int snd_atiixp_suspend(struct pci_dev *pci, pm_message_t state)
 {
-       struct atiixp *chip = card->pm_private_data;
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct atiixp *chip = card->private_data;
        int i;
 
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
        for (i = 0; i < NUM_ATI_PCMDEVS; i++)
                if (chip->pcmdevs[i]) {
                        struct atiixp_dma *dma = &chip->dmas[i];
@@ -1429,31 +1478,37 @@ static int snd_atiixp_suspend(struct snd_card *card, pm_message_t state)
                        snd_pcm_suspend_all(chip->pcmdevs[i]);
                }
        for (i = 0; i < NUM_ATI_CODECS; i++)
-               if (chip->ac97[i])
-                       snd_ac97_suspend(chip->ac97[i]);
+               snd_ac97_suspend(chip->ac97[i]);
        snd_atiixp_aclink_down(chip);
        snd_atiixp_chip_stop(chip);
 
-       pci_set_power_state(chip->pci, PCI_D3hot);
-       pci_disable_device(chip->pci);
+       pci_disable_device(pci);
+       pci_save_state(pci);
+       pci_set_power_state(pci, pci_choose_state(pci, state));
        return 0;
 }
 
-static int snd_atiixp_resume(struct snd_card *card)
+static int snd_atiixp_resume(struct pci_dev *pci)
 {
-       struct atiixp *chip = card->pm_private_data;
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct atiixp *chip = card->private_data;
        int i;
 
-       pci_enable_device(chip->pci);
-       pci_set_power_state(chip->pci, PCI_D0);
-       pci_set_master(chip->pci);
+       pci_set_power_state(pci, PCI_D0);
+       pci_restore_state(pci);
+       if (pci_enable_device(pci) < 0) {
+               printk(KERN_ERR "atiixp: pci_enable_device failed, "
+                      "disabling device\n");
+               snd_card_disconnect(card);
+               return -EIO;
+       }
+       pci_set_master(pci);
 
        snd_atiixp_aclink_reset(chip);
        snd_atiixp_chip_start(chip);
 
        for (i = 0; i < NUM_ATI_CODECS; i++)
-               if (chip->ac97[i])
-                       snd_ac97_resume(chip->ac97[i]);
+               snd_ac97_resume(chip->ac97[i]);
 
        for (i = 0; i < NUM_ATI_PCMDEVS; i++)
                if (chip->pcmdevs[i]) {
@@ -1468,11 +1523,13 @@ static int snd_atiixp_resume(struct snd_card *card)
                        }
                }
 
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
        return 0;
 }
 #endif /* CONFIG_PM */
 
 
+#ifdef CONFIG_PROC_FS
 /*
  * proc interface for register dump
  */
@@ -1492,9 +1549,11 @@ static void __devinit snd_atiixp_proc_init(struct atiixp *chip)
        struct snd_info_entry *entry;
 
        if (! snd_card_proc_new(chip->card, "atiixp", &entry))
-               snd_info_set_text_ops(entry, chip, 1024, snd_atiixp_proc_read);
+               snd_info_set_text_ops(entry, chip, snd_atiixp_proc_read);
 }
-
+#else /* !CONFIG_PROC_FS */
+#define snd_atiixp_proc_init(chip)
+#endif
 
 
 /*
@@ -1506,7 +1565,7 @@ static int snd_atiixp_free(struct atiixp *chip)
        if (chip->irq < 0)
                goto __hw_end;
        snd_atiixp_chip_stop(chip);
-       synchronize_irq(chip->irq);
+
       __hw_end:
        if (chip->irq >= 0)
                free_irq(chip->irq, chip);
@@ -1547,7 +1606,7 @@ static int __devinit snd_atiixp_create(struct snd_card *card,
        }
 
        spin_lock_init(&chip->reg_lock);
-       init_MUTEX(&chip->open_mutex);
+       mutex_init(&chip->open_mutex);
        chip->card = card;
        chip->pci = pci;
        chip->irq = -1;
@@ -1557,14 +1616,14 @@ static int __devinit snd_atiixp_create(struct snd_card *card,
                return err;
        }
        chip->addr = pci_resource_start(pci, 0);
-       chip->remap_addr = ioremap_nocache(chip->addr, pci_resource_len(pci, 0));
+       chip->remap_addr = pci_ioremap_bar(pci, 0);
        if (chip->remap_addr == NULL) {
                snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
                snd_atiixp_free(chip);
                return -EIO;
        }
 
-       if (request_irq(pci->irq, snd_atiixp_interrupt, SA_INTERRUPT|SA_SHIRQ,
+       if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED,
                        card->shortname, chip)) {
                snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
                snd_atiixp_free(chip);
@@ -1591,19 +1650,17 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
 {
        struct snd_card *card;
        struct atiixp *chip;
-       unsigned char revision;
        int err;
 
-       card = snd_card_new(index, id, THIS_MODULE, 0);
-       if (card == NULL)
-               return -ENOMEM;
-
-       pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
+       err = snd_card_create(index, id, THIS_MODULE, 0, &card);
+       if (err < 0)
+               return err;
 
        strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA");
        strcpy(card->shortname, "ATI IXP");
        if ((err = snd_atiixp_create(card, pci, &chip)) < 0)
                goto __error;
+       card->private_data = chip;
 
        if ((err = snd_atiixp_aclink_reset(chip)) < 0)
                goto __error;
@@ -1621,12 +1678,11 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
        snd_atiixp_chip_start(chip);
 
        snprintf(card->longname, sizeof(card->longname),
-                "%s rev %x with %s at %#lx, irq %i", card->shortname, revision,
+                "%s rev %x with %s at %#lx, irq %i", card->shortname,
+                pci->revision,
                 chip->ac97[0] ? snd_ac97_get_short_name(chip->ac97[0]) : "?",
                 chip->addr, chip->irq);
 
-       snd_card_set_pm_callback(card, snd_atiixp_suspend, snd_atiixp_resume, chip);
-
        if ((err = snd_card_register(card)) < 0)
                goto __error;
 
@@ -1649,7 +1705,10 @@ static struct pci_driver driver = {
        .id_table = snd_atiixp_ids,
        .probe = snd_atiixp_probe,
        .remove = __devexit_p(snd_atiixp_remove),
-       SND_PCI_PM_CALLBACKS
+#ifdef CONFIG_PM
+       .suspend = snd_atiixp_suspend,
+       .resume = snd_atiixp_resume,
+#endif
 };