]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - sound/pci/hda/hda_intel.c
ALSA: hda - Revert DSP detection on legacy HD-audio driver
[linux.git] / sound / pci / hda / hda_intel.c
index 76f03abd15ab766190c4d5739f707d81aa0e2d70..e784130ea4e0eb2d7fec5357fb86872fb44292fc 100644 (file)
@@ -310,31 +310,28 @@ enum {
 #define AZX_DCAPS_INTEL_HASWELL \
        (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_COUNT_LPIB_DELAY |\
         AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_COMPONENT |\
-        AZX_DCAPS_I915_POWERWELL | AZX_DCAPS_SNOOP_TYPE(SCH))
+        AZX_DCAPS_SNOOP_TYPE(SCH))
 
 /* Broadwell HDMI can't use position buffer reliably, force to use LPIB */
 #define AZX_DCAPS_INTEL_BROADWELL \
        (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_POSFIX_LPIB |\
         AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_COMPONENT |\
-        AZX_DCAPS_I915_POWERWELL | AZX_DCAPS_SNOOP_TYPE(SCH))
+        AZX_DCAPS_SNOOP_TYPE(SCH))
 
 #define AZX_DCAPS_INTEL_BAYTRAIL \
-       (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_I915_COMPONENT |\
-        AZX_DCAPS_I915_POWERWELL)
+       (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_I915_COMPONENT)
 
 #define AZX_DCAPS_INTEL_BRASWELL \
        (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
-        AZX_DCAPS_I915_COMPONENT | AZX_DCAPS_I915_POWERWELL)
+        AZX_DCAPS_I915_COMPONENT)
 
 #define AZX_DCAPS_INTEL_SKYLAKE \
        (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
-        AZX_DCAPS_SEPARATE_STREAM_TAG | AZX_DCAPS_I915_COMPONENT |\
-        AZX_DCAPS_I915_POWERWELL)
+        AZX_DCAPS_SEPARATE_STREAM_TAG | AZX_DCAPS_I915_COMPONENT)
 
 #define AZX_DCAPS_INTEL_BROXTON \
        (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
-        AZX_DCAPS_SEPARATE_STREAM_TAG | AZX_DCAPS_I915_COMPONENT |\
-        AZX_DCAPS_I915_POWERWELL)
+        AZX_DCAPS_SEPARATE_STREAM_TAG | AZX_DCAPS_I915_COMPONENT)
 
 /* quirks for ATI SB / AMD Hudson */
 #define AZX_DCAPS_PRESET_ATI_SB \
@@ -591,8 +588,7 @@ static void hda_intel_init_chip(struct azx *chip, bool full_reset)
        struct pci_dev *pci = chip->pci;
        u32 val;
 
-       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
-               snd_hdac_set_codec_wakeup(bus, true);
+       snd_hdac_set_codec_wakeup(bus, true);
        if (chip->driver_type == AZX_DRIVER_SKL) {
                pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
                val = val & ~INTEL_HDA_CGCTL_MISCBDCGE;
@@ -604,8 +600,8 @@ static void hda_intel_init_chip(struct azx *chip, bool full_reset)
                val = val | INTEL_HDA_CGCTL_MISCBDCGE;
                pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
        }
-       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
-               snd_hdac_set_codec_wakeup(bus, false);
+
+       snd_hdac_set_codec_wakeup(bus, false);
 
        /* reduce dma latency to avoid noise */
        if (IS_BXT(pci))
@@ -667,13 +663,8 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
        return 0;
 }
 
-/* Enable/disable i915 display power for the link */
-static int azx_intel_link_power(struct azx *chip, bool enable)
-{
-       struct hdac_bus *bus = azx_bus(chip);
-
-       return snd_hdac_display_power(bus, enable);
-}
+#define display_power(chip, enable) \
+       snd_hdac_display_power(azx_bus(chip), HDA_CODEC_IDX_CONTROLLER, enable)
 
 /*
  * Check whether the current DMA position is acceptable for updating
@@ -930,35 +921,75 @@ static int param_set_xint(const char *val, const struct kernel_param *kp)
        mutex_unlock(&card_list_lock);
        return 0;
 }
-#else
-#define azx_add_card_list(chip) /* NOP */
-#define azx_del_card_list(chip) /* NOP */
-#endif /* CONFIG_PM */
 
-#ifdef CONFIG_PM_SLEEP
 /*
  * power management
  */
-static int azx_suspend(struct device *dev)
+static bool azx_is_pm_ready(struct snd_card *card)
 {
-       struct snd_card *card = dev_get_drvdata(dev);
        struct azx *chip;
        struct hda_intel *hda;
-       struct hdac_bus *bus;
 
        if (!card)
-               return 0;
-
+               return false;
        chip = card->private_data;
        hda = container_of(chip, struct hda_intel, chip);
        if (chip->disabled || hda->init_failed || !chip->running)
+               return false;
+       return true;
+}
+
+static void __azx_runtime_suspend(struct azx *chip)
+{
+       azx_stop_chip(chip);
+       azx_enter_link_reset(chip);
+       azx_clear_irq_pending(chip);
+       display_power(chip, false);
+}
+
+static void __azx_runtime_resume(struct azx *chip)
+{
+       struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
+       struct hdac_bus *bus = azx_bus(chip);
+       struct hda_codec *codec;
+       int status;
+
+       display_power(chip, true);
+       if (hda->need_i915_power)
+               snd_hdac_i915_set_bclk(bus);
+
+       /* Read STATESTS before controller reset */
+       status = azx_readw(chip, STATESTS);
+
+       azx_init_pci(chip);
+       hda_intel_init_chip(chip, true);
+
+       if (status) {
+               list_for_each_codec(codec, &chip->bus)
+                       if (status & (1 << codec->addr))
+                               schedule_delayed_work(&codec->jackpoll_work,
+                                                     codec->jackpoll_interval);
+       }
+
+       /* power down again for link-controlled chips */
+       if (!hda->need_i915_power)
+               display_power(chip, false);
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int azx_suspend(struct device *dev)
+{
+       struct snd_card *card = dev_get_drvdata(dev);
+       struct azx *chip;
+       struct hdac_bus *bus;
+
+       if (!azx_is_pm_ready(card))
                return 0;
 
+       chip = card->private_data;
        bus = azx_bus(chip);
        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       azx_clear_irq_pending(chip);
-       azx_stop_chip(chip);
-       azx_enter_link_reset(chip);
+       __azx_runtime_suspend(chip);
        if (bus->irq >= 0) {
                free_irq(bus->irq, chip);
                bus->irq = -1;
@@ -966,9 +997,6 @@ static int azx_suspend(struct device *dev)
 
        if (chip->msi)
                pci_disable_msi(chip->pci);
-       if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
-               && hda->need_i915_power)
-               snd_hdac_display_power(bus, false);
 
        trace_azx_suspend(chip);
        return 0;
@@ -976,41 +1004,19 @@ static int azx_suspend(struct device *dev)
 
 static int azx_resume(struct device *dev)
 {
-       struct pci_dev *pci = to_pci_dev(dev);
        struct snd_card *card = dev_get_drvdata(dev);
        struct azx *chip;
-       struct hda_intel *hda;
-       struct hdac_bus *bus;
 
-       if (!card)
+       if (!azx_is_pm_ready(card))
                return 0;
 
        chip = card->private_data;
-       hda = container_of(chip, struct hda_intel, chip);
-       bus = azx_bus(chip);
-       if (chip->disabled || hda->init_failed || !chip->running)
-               return 0;
-
-       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
-               snd_hdac_display_power(bus, true);
-               if (hda->need_i915_power)
-                       snd_hdac_i915_set_bclk(bus);
-       }
-
        if (chip->msi)
-               if (pci_enable_msi(pci) < 0)
+               if (pci_enable_msi(chip->pci) < 0)
                        chip->msi = 0;
        if (azx_acquire_irq(chip, 1) < 0)
                return -EIO;
-       azx_init_pci(chip);
-
-       hda_intel_init_chip(chip, true);
-
-       /* power down again for link-controlled chips */
-       if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
-           !hda->need_i915_power)
-               snd_hdac_display_power(bus, false);
-
+       __azx_runtime_resume(chip);
        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
 
        trace_azx_resume(chip);
@@ -1045,21 +1051,14 @@ static int azx_thaw_noirq(struct device *dev)
 }
 #endif /* CONFIG_PM_SLEEP */
 
-#ifdef CONFIG_PM
 static int azx_runtime_suspend(struct device *dev)
 {
        struct snd_card *card = dev_get_drvdata(dev);
        struct azx *chip;
-       struct hda_intel *hda;
 
-       if (!card)
+       if (!azx_is_pm_ready(card))
                return 0;
-
        chip = card->private_data;
-       hda = container_of(chip, struct hda_intel, chip);
-       if (chip->disabled || hda->init_failed)
-               return 0;
-
        if (!azx_has_pm_runtime(chip))
                return 0;
 
@@ -1067,13 +1066,7 @@ static int azx_runtime_suspend(struct device *dev)
        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->need_i915_power)
-               snd_hdac_display_power(azx_bus(chip), false);
-
+       __azx_runtime_suspend(chip);
        trace_azx_runtime_suspend(chip);
        return 0;
 }
@@ -1082,51 +1075,18 @@ static int azx_runtime_resume(struct device *dev)
 {
        struct snd_card *card = dev_get_drvdata(dev);
        struct azx *chip;
-       struct hda_intel *hda;
-       struct hdac_bus *bus;
-       struct hda_codec *codec;
-       int status;
 
-       if (!card)
+       if (!azx_is_pm_ready(card))
                return 0;
-
        chip = card->private_data;
-       hda = container_of(chip, struct hda_intel, chip);
-       bus = azx_bus(chip);
-       if (chip->disabled || hda->init_failed)
-               return 0;
-
        if (!azx_has_pm_runtime(chip))
                return 0;
-
-       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
-               snd_hdac_display_power(bus, true);
-               if (hda->need_i915_power)
-                       snd_hdac_i915_set_bclk(bus);
-       }
-
-       /* Read STATESTS before controller reset */
-       status = azx_readw(chip, STATESTS);
-
-       azx_init_pci(chip);
-       hda_intel_init_chip(chip, true);
-
-       if (status) {
-               list_for_each_codec(codec, &chip->bus)
-                       if (status & (1 << codec->addr))
-                               schedule_delayed_work(&codec->jackpoll_work,
-                                                     codec->jackpoll_interval);
-       }
+       __azx_runtime_resume(chip);
 
        /* disable controller Wake Up event*/
        azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
                        ~STATESTS_INT_MASK);
 
-       /* power down again for link-controlled chips */
-       if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
-           !hda->need_i915_power)
-               snd_hdac_display_power(bus, false);
-
        trace_azx_runtime_resume(chip);
        return 0;
 }
@@ -1167,6 +1127,8 @@ static const struct dev_pm_ops azx_pm = {
 
 #define AZX_PM_OPS     &azx_pm
 #else
+#define azx_add_card_list(chip) /* NOP */
+#define azx_del_card_list(chip) /* NOP */
 #define AZX_PM_OPS     NULL
 #endif /* CONFIG_PM */
 
@@ -1374,11 +1336,8 @@ static int azx_free(struct azx *chip)
 #ifdef CONFIG_SND_HDA_PATCH_LOADER
        release_firmware(chip->fw);
 #endif
+       display_power(chip, false);
 
-       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
-               if (hda->need_i915_power)
-                       snd_hdac_display_power(bus, false);
-       }
        if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT)
                snd_hdac_i915_exit(bus);
        kfree(hda);
@@ -1935,8 +1894,7 @@ static int azx_first_init(struct azx *chip)
        /* initialize chip */
        azx_init_pci(chip);
 
-       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
-               snd_hdac_i915_set_bclk(bus);
+       snd_hdac_i915_set_bclk(bus);
 
        hda_intel_init_chip(chip, (probe_only[dev] & 2) == 0);
 
@@ -2078,7 +2036,6 @@ static const struct hda_controller_ops pci_hda_ops = {
        .disable_msi_reset_irq = disable_msi_reset_irq,
        .pcm_mmap_prepare = pcm_mmap_prepare,
        .position_check = azx_position_check,
-       .link_power = azx_intel_link_power,
 };
 
 static int azx_probe(struct pci_dev *pci,
@@ -2245,10 +2202,13 @@ static int azx_probe_continue(struct azx *chip)
                                goto out_free;
                        } else {
                                /* don't bother any longer */
-                               chip->driver_caps &=
-                                       ~(AZX_DCAPS_I915_COMPONENT | AZX_DCAPS_I915_POWERWELL);
+                               chip->driver_caps &= ~AZX_DCAPS_I915_COMPONENT;
                        }
                }
+
+               /* HSW/BDW controllers need this power */
+               if (CONTROLLER_IN_GPU(pci))
+                       hda->need_i915_power = 1;
        }
 
        /* Request display power well for the HDA controller or codec. For
@@ -2256,18 +2216,7 @@ static int azx_probe_continue(struct azx *chip)
         * this power. For other platforms, like Baytrail/Braswell, only the
         * display codec needs the power and it can be released after probe.
         */
-       if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
-               /* HSW/BDW controllers need this power */
-               if (CONTROLLER_IN_GPU(pci))
-                       hda->need_i915_power = 1;
-
-               err = snd_hdac_display_power(bus, true);
-               if (err < 0) {
-                       dev_err(chip->card->dev,
-                               "Cannot turn on display power on i915\n");
-                       goto i915_power_fail;
-               }
-       }
+       display_power(chip, true);
 
        err = azx_first_init(chip);
        if (err < 0)
@@ -2315,11 +2264,8 @@ static int azx_probe_continue(struct azx *chip)
                pm_runtime_put_autosuspend(&pci->dev);
 
 out_free:
-       if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
-               && !hda->need_i915_power)
-               snd_hdac_display_power(bus, false);
-
-i915_power_fail:
+       if (err < 0 || !hda->need_i915_power)
+               display_power(chip, false);
        if (err < 0)
                hda->init_failed = 1;
        complete_all(&hda->probe_wait);