ALSA: hda - Add Toshiba Satellite C870 to MSI blacklist
[pandora-kernel.git] / sound / pci / hda / hda_intel.c
index de18722..7f88dd6 100644 (file)
@@ -62,6 +62,7 @@
 #include <linux/vga_switcheroo.h>
 #include <linux/firmware.h>
 #include "hda_codec.h"
+#include "hda_i915.h"
 
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
@@ -541,6 +542,10 @@ struct azx {
        /* for pending irqs */
        struct work_struct irq_pending_work;
 
+#ifdef CONFIG_SND_HDA_I915
+       struct work_struct probe_work;
+#endif
+
        /* reboot notifier (for mysterious hangup problem at power-down) */
        struct notifier_block reboot_notifier;
 
@@ -594,6 +599,7 @@ enum {
 #define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23)   /* BDLE in 4k boundary */
 #define AZX_DCAPS_COUNT_LPIB_DELAY  (1 << 25)  /* Take LPIB as delay */
 #define AZX_DCAPS_PM_RUNTIME   (1 << 26)       /* runtime PM support */
+#define AZX_DCAPS_I915_POWERWELL (1 << 27)     /* HSW i915 power well support */
 
 /* quirks for Intel PCH */
 #define AZX_DCAPS_INTEL_PCH_NOPM \
@@ -942,6 +948,9 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
                }
        }
 
+       if (!bus->no_response_fallback)
+               return -1;
+
        if (!chip->polling_mode && chip->poll_count < 2) {
                snd_printdd(SFX "%s: azx_get_response timeout, "
                           "polling the codec once: last cmd=0x%08x\n",
@@ -1117,37 +1126,52 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
                                 struct snd_dma_buffer *dmab);
 #endif
 
-/* reset codec link */
-static int azx_reset(struct azx *chip, int full_reset)
+/* enter link reset */
+static void azx_enter_link_reset(struct azx *chip)
 {
        unsigned long timeout;
 
-       if (!full_reset)
-               goto __skip;
-
-       /* clear STATESTS */
-       azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
-
        /* reset controller */
        azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
 
        timeout = jiffies + msecs_to_jiffies(100);
-       while (azx_readb(chip, GCTL) &&
+       while ((azx_readb(chip, GCTL) & ICH6_GCTL_RESET) &&
                        time_before(jiffies, timeout))
                usleep_range(500, 1000);
+}
 
-       /* delay for >= 100us for codec PLL to settle per spec
-        * Rev 0.9 section 5.5.1
-        */
-       usleep_range(500, 1000);
+/* exit link reset */
+static void azx_exit_link_reset(struct azx *chip)
+{
+       unsigned long timeout;
 
-       /* Bring controller out of reset */
        azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
 
        timeout = jiffies + msecs_to_jiffies(100);
        while (!azx_readb(chip, GCTL) &&
                        time_before(jiffies, timeout))
                usleep_range(500, 1000);
+}
+
+/* reset codec link */
+static int azx_reset(struct azx *chip, int full_reset)
+{
+       if (!full_reset)
+               goto __skip;
+
+       /* clear STATESTS */
+       azx_writew(chip, STATESTS, STATESTS_INT_MASK);
+
+       /* reset controller */
+       azx_enter_link_reset(chip);
+
+       /* delay for >= 100us for codec PLL to settle per spec
+        * Rev 0.9 section 5.5.1
+        */
+       usleep_range(500, 1000);
+
+       /* Bring controller out of reset */
+       azx_exit_link_reset(chip);
 
        /* Brent Chartrand said to wait >= 540us for codecs to initialize */
        usleep_range(1000, 1200);
@@ -1218,7 +1242,7 @@ static void azx_int_clear(struct azx *chip)
        }
 
        /* clear STATESTS */
-       azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
+       azx_writew(chip, STATESTS, STATESTS_INT_MASK);
 
        /* clear rirb status */
        azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
@@ -1427,8 +1451,8 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
 
 #if 0
        /* clear state status int */
-       if (azx_readb(chip, STATESTS) & 0x04)
-               azx_writeb(chip, STATESTS, 0x04);
+       if (azx_readw(chip, STATESTS) & 0x04)
+               azx_writew(chip, STATESTS, 0x04);
 #endif
        spin_unlock(&chip->reg_lock);
        
@@ -2891,6 +2915,7 @@ static int azx_suspend(struct device *dev)
        if (chip->initialized)
                snd_hda_suspend(chip->bus);
        azx_stop_chip(chip);
+       azx_enter_link_reset(chip);
        if (chip->irq >= 0) {
                free_irq(chip->irq, chip);
                chip->irq = -1;
@@ -2900,6 +2925,8 @@ static int azx_suspend(struct device *dev)
        pci_disable_device(pci);
        pci_save_state(pci);
        pci_set_power_state(pci, PCI_D3hot);
+       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+               hda_display_power(false);
        return 0;
 }
 
@@ -2912,6 +2939,8 @@ static int azx_resume(struct device *dev)
        if (chip->disabled)
                return 0;
 
+       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+               hda_display_power(true);
        pci_set_power_state(pci, PCI_D0);
        pci_restore_state(pci);
        if (pci_enable_device(pci) < 0) {
@@ -2942,8 +2971,15 @@ static int azx_runtime_suspend(struct device *dev)
        struct snd_card *card = dev_get_drvdata(dev);
        struct azx *chip = card->private_data;
 
+       /* enable controller wake up event */
+       azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
+                 STATESTS_INT_MASK);
+
        azx_stop_chip(chip);
+       azx_enter_link_reset(chip);
        azx_clear_irq_pending(chip);
+       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+               hda_display_power(false);
        return 0;
 }
 
@@ -2951,9 +2987,31 @@ static int azx_runtime_resume(struct device *dev)
 {
        struct snd_card *card = dev_get_drvdata(dev);
        struct azx *chip = card->private_data;
+       struct hda_bus *bus;
+       struct hda_codec *codec;
+       int status;
+
+       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+               hda_display_power(true);
+
+       /* Read STATESTS before controller reset */
+       status = azx_readw(chip, STATESTS);
 
        azx_init_pci(chip);
        azx_init_chip(chip, 1);
+
+       bus = chip->bus;
+       if (status && bus) {
+               list_for_each_entry(codec, &bus->codec_list, list)
+                       if (status & (1 << codec->addr))
+                               queue_delayed_work(codec->bus->workq,
+                                                  &codec->jackpoll_work, codec->jackpoll_interval);
+       }
+
+       /* disable controller Wake Up event*/
+       azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
+                       ~STATESTS_INT_MASK);
+
        return 0;
 }
 
@@ -3006,7 +3064,6 @@ static void azx_notifier_unregister(struct azx *chip)
                unregister_reboot_notifier(&chip->reboot_notifier);
 }
 
-static int azx_first_init(struct azx *chip);
 static int azx_probe_continue(struct azx *chip);
 
 #ifdef SUPPORT_VGA_SWITCHEROO
@@ -3033,8 +3090,7 @@ static void azx_vs_set_state(struct pci_dev *pci,
                        snd_printk(KERN_INFO SFX
                                   "%s: Start delayed initialization\n",
                                   pci_name(chip->pci));
-                       if (azx_first_init(chip) < 0 ||
-                           azx_probe_continue(chip) < 0) {
+                       if (azx_probe_continue(chip) < 0) {
                                snd_printk(KERN_ERR SFX
                                           "%s: initialization error\n",
                                           pci_name(chip->pci));
@@ -3120,8 +3176,13 @@ static int register_vga_switcheroo(struct azx *chip)
  */
 static int azx_free(struct azx *chip)
 {
+       struct pci_dev *pci = chip->pci;
        int i;
 
+       if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
+                       && chip->running)
+               pm_runtime_get_noresume(&pci->dev);
+
        azx_del_card_list(chip);
 
        azx_notifier_unregister(chip);
@@ -3173,6 +3234,10 @@ static int azx_free(struct azx *chip)
        if (chip->fw)
                release_firmware(chip->fw);
 #endif
+       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
+               hda_display_power(false);
+               hda_i915_exit();
+       }
        kfree(chip);
 
        return 0;
@@ -3335,6 +3400,7 @@ static struct snd_pci_quirk msi_black_list[] = {
        SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
        SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
        SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
+       SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
        SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
        SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
        {}
@@ -3398,6 +3464,13 @@ static void azx_check_snoop_available(struct azx *chip)
        }
 }
 
+#ifdef CONFIG_SND_HDA_I915
+static void azx_probe_work(struct work_struct *work)
+{
+       azx_probe_continue(container_of(work, struct azx, probe_work));
+}
+#endif
+
 /*
  * constructor
  */
@@ -3473,7 +3546,13 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
                return err;
        }
 
+#ifdef CONFIG_SND_HDA_I915
+       /* continue probing in work context as may trigger request module */
+       INIT_WORK(&chip->probe_work, azx_probe_work);
+#endif
+
        *rchip = chip;
+
        return 0;
 }
 
@@ -3730,11 +3809,6 @@ static int azx_probe(struct pci_dev *pci,
        }
 
        probe_now = !chip->disabled;
-       if (probe_now) {
-               err = azx_first_init(chip);
-               if (err < 0)
-                       goto out_free;
-       }
 
 #ifdef CONFIG_SND_HDA_PATCH_LOADER
        if (patch[dev] && *patch[dev]) {
@@ -3749,30 +3823,53 @@ static int azx_probe(struct pci_dev *pci,
        }
 #endif /* CONFIG_SND_HDA_PATCH_LOADER */
 
+       /* continue probing in work context, avoid request_module deadlock */
+       if (probe_now && (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)) {
+#ifdef CONFIG_SND_HDA_I915
+               probe_now = false;
+               schedule_work(&chip->probe_work);
+#else
+               snd_printk(KERN_ERR SFX "Haswell must build in CONFIG_SND_HDA_I915\n");
+#endif
+       }
+
        if (probe_now) {
                err = azx_probe_continue(chip);
                if (err < 0)
                        goto out_free;
        }
 
-       if (pci_dev_run_wake(pci))
-               pm_runtime_put_noidle(&pci->dev);
-
        dev++;
        complete_all(&chip->probe_wait);
        return 0;
 
 out_free:
        snd_card_free(card);
-       pci_set_drvdata(pci, NULL);
        return err;
 }
 
 static int azx_probe_continue(struct azx *chip)
 {
+       struct pci_dev *pci = chip->pci;
        int dev = chip->dev_index;
        int err;
 
+       /* Request power well for Haswell HDA controller and codec */
+       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
+#ifdef CONFIG_SND_HDA_I915
+               err = hda_i915_init();
+               if (err < 0) {
+                       snd_printk(KERN_ERR SFX "Error request power-well from i915\n");
+                       goto out_free;
+               }
+#endif
+               hda_display_power(true);
+       }
+
+       err = azx_first_init(chip);
+       if (err < 0)
+               goto out_free;
+
 #ifdef CONFIG_SND_HDA_INPUT_BEEP
        chip->beep_mode = beep_mode[dev];
 #endif
@@ -3817,6 +3914,8 @@ static int azx_probe_continue(struct azx *chip)
        power_down_all_codecs(chip);
        azx_notifier_register(chip);
        azx_add_card_list(chip);
+       if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
+               pm_runtime_put_noidle(&pci->dev);
 
        return 0;
 
@@ -3829,12 +3928,8 @@ static void azx_remove(struct pci_dev *pci)
 {
        struct snd_card *card = pci_get_drvdata(pci);
 
-       if (pci_dev_run_wake(pci))
-               pm_runtime_get_noresume(&pci->dev);
-
        if (card)
                snd_card_free(card);
-       pci_set_drvdata(pci, NULL);
 }
 
 /* PCI IDs */
@@ -3864,11 +3959,14 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
          .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
        /* Haswell */
        { PCI_DEVICE(0x8086, 0x0a0c),
-         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
+         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH |
+         AZX_DCAPS_I915_POWERWELL },
        { PCI_DEVICE(0x8086, 0x0c0c),
-         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
+         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH |
+         AZX_DCAPS_I915_POWERWELL },
        { PCI_DEVICE(0x8086, 0x0d0c),
-         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
+         .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH |
+         AZX_DCAPS_I915_POWERWELL },
        /* 5 Series/3400 */
        { PCI_DEVICE(0x8086, 0x3b56),
          .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
@@ -3878,6 +3976,9 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
        /* Oaktrail */
        { PCI_DEVICE(0x8086, 0x080a),
          .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
+       /* BayTrail */
+       { PCI_DEVICE(0x8086, 0x0f04),
+         .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
        /* ICH */
        { PCI_DEVICE(0x8086, 0x2668),
          .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |