1
0
Fork 0
alistair23-linux/include/sound
Lukas Wunner 07f4f97d7b vga_switcheroo: Use device link for HDA controller
Back in 2013, runtime PM for GPUs with integrated HDA controller was
introduced with commits 0d69704ae3 ("gpu/vga_switcheroo: add driver
control power feature. (v3)") and 246efa4a07 ("snd/hda: add runtime
suspend/resume on optimus support (v4)").

Briefly, the idea was that the HDA controller is forced on and off in
unison with the GPU.

The original code is mostly still in place even though it was never a
100% perfect solution:  E.g. on access to the HDA controller, the GPU
is powered up via vga_switcheroo_runtime_resume_hdmi_audio() but there
are no provisions to keep it resumed until access to the HDA controller
has ceased:  The GPU autosuspends after 5 seconds, rendering the HDA
controller inaccessible.

Additionally, a kludge is required when hda_intel.c probes:  It has to
check whether the GPU is powered down (check_hdmi_disabled()) and defer
probing if so.

However in the meantime (in v4.10) the driver core has gained a feature
called device links which promises to solve such issues in a clean way:
It allows us to declare a dependency from the HDA controller (consumer)
to the GPU (supplier).  The PM core then automagically ensures that the
GPU is runtime resumed as long as the HDA controller's ->probe hook is
executed and whenever the HDA controller is accessed.

By default, the HDA controller has a dependency on its parent, a PCIe
Root Port.  Adding a device link creates another dependency on its
sibling:

                            PCIe Root Port
                             ^          ^
                             |          |
                             |          |
                            HDA  ===>  GPU

The device link is not only used for runtime PM, it also guarantees that
on system sleep, the HDA controller suspends before the GPU and resumes
after the GPU, and on system shutdown the HDA controller's ->shutdown
hook is executed before the one of the GPU.  It is a complete solution.

Using this functionality is as simple as calling device_link_add(),
which results in a dmesg entry like this:

        pci 0000:01:00.1: Linked as a consumer to 0000:01:00.0

The code for the GPU-governed audio power management can thus be removed
(except where it's still needed for legacy manual power control).

The device link is added in a PCI quirk rather than in hda_intel.c.
It is therefore legal for the GPU to runtime suspend to D3cold even if
the HDA controller is not bound to a driver or if CONFIG_SND_HDA_INTEL
is not enabled, for accesses to the HDA controller will cause the GPU to
wake up regardless if they're occurring outside of hda_intel.c (think
config space readout via sysfs).

Contrary to the previous implementation, the HDA controller's power
state is now self-governed, rather than GPU-governed, whereas the GPU's
power state is no longer fully self-governed.  (The HDA controller needs
to runtime suspend before the GPU can.)

It is thus crucial that runtime PM is always activated on the HDA
controller even if CONFIG_SND_HDA_POWER_SAVE_DEFAULT is set to 0 (which
is the default), lest the GPU stays awake.  This is achieved by setting
the auto_runtime_pm flag on every codec and the AZX_DCAPS_PM_RUNTIME
flag on the HDA controller.

A side effect is that power consumption might be reduced if the GPU is
in use but the HDA controller is not, because the HDA controller is now
allowed to go to D3hot.  Before, it was forced to stay in D0 as long as
the GPU was in use.  (There is no reduction in power consumption on my
Nvidia GK107, but there might be on other chips.)

The code paths for legacy manual power control are adjusted such that
runtime PM is disabled during power off, thereby preventing the PM core
from resuming the HDA controller.

Note that the device link is not only added on vga_switcheroo capable
systems, but for *any* GPU with integrated HDA controller.  The idea is
that the HDA controller streams audio via connectors located on the GPU,
so the GPU needs to be on for the HDA controller to do anything useful.

This commit implicitly fixes an unbalanced runtime PM ref upon unbind of
hda_intel.c:  On ->probe, a runtime PM ref was previously released under
the condition "azx_has_pm_runtime(chip) || hda->use_vga_switcheroo", but
on ->remove a runtime PM ref was only acquired under the first of those
conditions.  Thus, binding and unbinding the driver twice on a
vga_switcheroo capable system caused the runtime PM refcount to drop
below zero.  The issue is resolved because the AZX_DCAPS_PM_RUNTIME flag
is now always set if use_vga_switcheroo is true.

For more information on device links please refer to:
https://www.kernel.org/doc/html/latest/driver-api/device_link.html
Documentation/driver-api/device_link.rst

Cc: Dave Airlie <airlied@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Kai Heng Feng <kai.heng.feng@canonical.com> # AMD PowerXpress
Tested-by: Mike Lothian <mike@fireburn.co.uk>          # AMD PowerXpress
Tested-by: Denis Lisov <dennis.lissov@gmail.com>       # Nvidia Optimus
Tested-by: Peter Wu <peter@lekensteyn.nl>              # Nvidia Optimus
Tested-by: Lukas Wunner <lukas@wunner.de>              # MacBook Pro
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: https://patchwork.freedesktop.org/patch/msgid/51bd38360ff502a8c42b1ebf4405ee1d3f27118d.1520068884.git.lukas@wunner.de
2018-03-13 22:58:09 +01:00
..
ac97 ALSA: ac97: add an ac97 bus 2017-09-04 18:24:56 +01:00
ac97_codec.h ALSA: ac97: split out the generic ac97 registers 2017-09-04 18:24:56 +01:00
aci.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ad1816a.h ALSA: ad1816a: Remove always NULL parameters 2015-01-02 16:26:20 +01:00
ad1843.h
adau1373.h ASoC: Add ADAU1373 codec support 2011-08-17 00:53:54 +09:00
aess.h ASoC: TI AESS: add autogating-enable function, callable from architecture code 2013-02-10 11:22:23 -07:00
ak4xxx-adda.h
ak4113.h ALSA: ak411x: Use array instead of offsetof() 2017-05-17 07:13:03 +02:00
ak4114.h ALSA: ak411x: Use array instead of offsetof() 2017-05-17 07:13:03 +02:00
ak4117.h ALSA: ak411x: Use array instead of offsetof() 2017-05-17 07:13:03 +02:00
ak4531_codec.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
ak4641.h ASoC: Asahi Kasei AK4641 codec driver 2011-05-19 14:10:45 -07:00
alc5623.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
asequencer.h UAPI: (Scripted) Disintegrate include/sound 2012-10-09 09:49:13 +01:00
asound.h UAPI: (Scripted) Disintegrate include/sound 2012-10-09 09:49:13 +01:00
asoundef.h ALSA: Add definitions for CEA-861 Audio InfoFrames 2012-04-18 08:00:36 +02:00
compress_driver.h ALSA: compress: Fix kernel-doc warnings 2016-11-15 07:28:15 +01:00
control.h ALSA: hda - Fix yet remaining issue with vmaster 0dB initialization 2017-11-22 12:34:56 +01:00
core.h ALSA: add snd_card_disconnect_sync() 2017-10-11 15:06:10 +02:00
cs35l33.h ASoC: cs35l33: Initial commit of the cs35l33 CODEC driver. 2016-06-27 17:39:06 +01:00
cs35l34.h ASoC: cs35l34: Initial commit of the cs35l34 CODEC driver. 2016-10-21 12:02:44 +01:00
cs35l35.h ASoC: cs35l35: Add Boost Inductor Calculation 2017-05-19 17:31:34 +01:00
cs42l52.h ASoC: cs42l52: Make MICA/B mixer dependent on mic config 2013-11-28 10:20:51 +00:00
cs42l56.h ASoC: Add support for CS42L56 CODEC 2014-05-05 18:20:22 -07:00
cs42l73.h ASoC: cs42l73: Add platform data support for cs42l73 codec 2013-10-18 00:37:29 +01:00
cs4231-regs.h
cs4271.h ALSA: ASoC: cs4271: add optional soft reset workaround 2012-12-24 15:53:28 +00:00
cs8403.h
cs8427.h ALSA: cs8427: separate HW initialization 2014-04-03 14:59:48 +02:00
da7213.h ASoC: da7213: Add support to handle mclk data provided to driver 2015-10-07 15:11:34 +01:00
da7218.h ASoC: da7218: Add da7218 codec driver 2015-11-30 12:24:12 +00:00
da7219-aad.h ASoC: codecs: Add da7219 codec driver 2015-10-02 18:11:27 +01:00
da7219.h ASoC: da7219: Disable AAD if codec is not a wake-up source 2016-09-26 09:39:50 -07:00
da9055.h ASoC: codecs: Add DA9055 codec driver 2012-09-28 14:21:54 +01:00
designware_i2s.h ASoC: dwc: Added a quirk DW_I2S_QUIRK_16BIT_IDX_OVERRIDE to dwc driver 2017-06-28 19:01:12 +01:00
dmaengine_pcm.h ASoC: Revert "Drop SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME flag" 2017-01-23 18:16:33 +00:00
emu10k1.h ALSA: emu10k1: Use workqueue instead of kthread for emu1010 fw polling 2016-11-15 08:21:19 +01:00
emu10k1_synth.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
emu8000.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
emu8000_reg.h
emux_legacy.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
emux_synth.h ALSA: seq: Allow the tristate build of OSS emulation 2017-06-09 22:09:45 +02:00
es1688.h ALSA: es1688: Remove almost always NULL parameter 2015-01-02 16:27:03 +01:00
gus.h ALSA: Include linux/io.h instead of asm/io.h 2015-01-28 16:49:33 +01:00
hda_chmap.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hda_hwdep.h
hda_i915.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hda_register.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hda_regmap.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hda_verbs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hdaudio.h vga_switcheroo: Use device link for HDA controller 2018-03-13 22:58:09 +01:00
hdaudio_ext.h ASoC: hdac_hdmi: clean up hdac_device variable names 2017-12-01 12:48:16 +00:00
hdmi-codec.h ASoC: hdmi-codec: add .get_dai_id support 2017-05-24 18:45:29 +01:00
hwdep.h ->poll() methods should return __poll_t 2017-11-27 16:19:52 -05:00
i2c.h ALSA: i2c: constify snd_i2c_ops structures 2015-11-30 11:40:08 +01:00
info.h ->poll() methods should return __poll_t 2017-11-27 16:19:52 -05:00
initval.h ALSA: isa: Move snd_legacy_find_free_ioport to initval.h 2012-08-03 12:57:44 +02:00
jack.h ALSA: jack: Allow building the jack layer without input device 2016-02-23 09:03:07 +01:00
l3.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
max9768.h ASoC: max9768: add driver for max9768 amplifier 2012-01-30 21:50:55 +00:00
max98088.h
max98090.h ASoC:: max98090: Remove executable bit 2013-03-20 10:54:12 +01:00
max98095.h ASoC: max98095: Single bit bitfields should be unsigned 2012-05-13 23:33:53 +01:00
memalloc.h ALSA: Remove memory reservation code from memalloc helper 2014-01-09 07:32:10 +01:00
minors.h ALSA: core: add support for compressed devices 2011-12-23 10:07:46 +01:00
mixer_oss.h ALSA: Use IS_ENABLED() in common headers 2017-05-17 07:13:04 +02:00
mpu401.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
omap-hdmi-audio.h drm: omapdrm: hdmi: Pass HDMI core version as integer to HDMI audio 2017-08-16 12:52:41 +03:00
omap-pcm.h ASoC: omap-pcm: Move omap-pcm under include/sound 2014-05-26 15:32:32 +01:00
opl3.h ALSA: seq: Allow the tristate build of OSS emulation 2017-06-09 22:09:45 +02:00
opl4.h
pcm-indirect.h ALSA: pcm: Fix negative appl_ptr handling in pcm-indirect helpers 2017-05-25 23:34:45 +02:00
pcm.h ALSA: pcm: add SNDRV_PCM_FORMAT_{S,U}20 2017-11-29 09:26:33 +01:00
pcm_drm_eld.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pcm_iec958.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pcm_oss.h
pcm_params.h ALSA: Add params_set_format helper 2015-02-24 00:43:18 +09:00
pt2258.h
pxa2xx-lib.h Merge remote-tracking branches 'asoc/topic/ac97', 'asoc/topic/ac97-mfd', 'asoc/topic/amd' and 'asoc/topic/arizona-mfd' into asoc-next 2017-11-10 21:31:02 +00:00
rawmidi.h ALSA: Use IS_ENABLED() in common headers 2017-05-17 07:13:04 +02:00
rt286.h ASoC: add RT286 CODEC driver 2014-07-04 18:50:51 +01:00
rt298.h ASoC: add rt298 codec driver 2015-07-09 12:00:11 +01:00
rt5514.h ASoC: rt5514: The DSP clock can be calibrated by the other clock source 2017-11-07 11:23:36 +01:00
rt5640.h ASoC: rt5640: Fill up the IN3's support 2015-10-22 13:33:00 +01:00
rt5645.h ASoC: rt5645: Set card long_name for GPD win / pocket 2017-12-12 10:41:56 +00:00
rt5651.h ASoC: rt5651: Enable jack detection on JD* pins 2017-10-26 16:15:02 +02:00
rt5659.h ASoC: rt5659: add rt5659 codec driver 2015-11-18 12:55:25 +00:00
rt5660.h ASoC: rt5660: add rt5660 codec driver 2016-09-24 19:51:57 +01:00
rt5663.h ASoC: rt5663: Add the function of impedance sensing 2017-09-19 12:57:59 +01:00
rt5665.h treewide: Remove remaining executable attributes from source files 2017-02-25 12:12:50 -08:00
rt5670.h ASoC: rt5670: Add IRQ function 2015-03-11 12:08:20 +00:00
s3c24xx_uda134x.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sb.h ALSA: Include linux/io.h instead of asm/io.h 2015-01-28 16:49:33 +01:00
sb16_csp.h UAPI: (Scripted) Disintegrate include/sound 2012-10-09 09:49:13 +01:00
seq_device.h ALSA: seq: Define driver object in each driver 2015-02-12 14:15:54 +01:00
seq_kernel.h ALSA: seq: Avoid invalid lockdep class warning 2017-11-06 20:25:31 +01:00
seq_midi_emul.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
seq_midi_event.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
seq_oss.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
seq_oss_legacy.h
seq_virmidi.h ALSA: seq: Fix copy_from_user() call inside lock 2017-10-09 14:10:13 +02:00
sh_dac_audio.h
sh_fsi.h ASoC: fsi: cleanup sh_fsi.h 2012-12-24 15:57:20 +00:00
simple_card.h ASoC: simple-card: use asoc_simple_card_parse_daifmt() 2016-07-01 17:34:02 +02:00
simple_card_utils.h ASoC: make clock direction configurable in asoc-simple 2017-09-01 11:34:23 +01:00
snd_wavefront.h ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
soc-acpi-intel-match.h ASoC: acpi: add missing includes for non-ACPI platforms 2018-01-08 15:56:34 +00:00
soc-acpi.h ASoC: Intel - Convert to use acpi_dev_get_first_match_name() 2018-01-12 21:20:29 +00:00
soc-dai.h Merge remote-tracking branches 'asoc/topic/stm32', 'asoc/topic/sun4i-i2s', 'asoc/topic/sunxi', 'asoc/topic/symmetry' and 'asoc/topic/tas5720' into asoc-next 2018-01-18 11:56:17 +00:00
soc-dapm.h ASoC: dapm: Add new widget type for constructing DAPM graphs on DSPs. 2017-06-30 11:55:20 +01:00
soc-dpcm.h ASoC: Make soc_dpcm_debugfs_add() non-fatal 2015-04-09 11:32:29 +01:00
soc-topology.h ASoC: topology: Allow bespoke configuration post widget creation 2017-06-09 18:46:08 +01:00
soc.h Merge remote-tracking branches 'asoc/topic/max98373', 'asoc/topic/mtk', 'asoc/topic/pcm', 'asoc/topic/rockchip' and 'asoc/topic/sam9g20_wm8731' into asoc-next 2018-02-07 11:25:44 +00:00
soundfont.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
spear_dma.h ASoC: Update email-id of Rajeev Kumar 2015-04-28 16:31:01 +01:00
spear_spdif.h ASoC: SPEAr spdif_in: Add spdif IN support 2012-06-23 11:58:10 +01:00
sta32x.h ASoC: sta32x: add device tree binding. 2015-01-27 17:13:25 +00:00
sta350.h ASoC: sta350: add support for bits in miscellaneous registers 2014-05-05 12:52:59 -07:00
tas2552-plat.h ASoC: tas2552: Support TI TAS2552 Amplifier 2014-07-17 17:57:05 +01:00
tas5086.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tea6330t.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
timer.h ALSA: timer: Limit max instances per timer 2017-11-06 10:41:24 +01:00
tlv.h ALSA: control: cage TLV_DB_RANGE_HEAD in kernel land because it was obsoleted 2016-09-25 22:16:49 +02:00
tlv320aic3x.h ASoC: tlv320aic3x: Convert mic bias to a supply widget 2013-02-04 18:35:19 +00:00
tlv320aic32x4.h ASoC: tlv320aic32x4: Add gpio configuration to the codec 2017-07-17 16:22:28 +01:00
tlv320dac33-plat.h ASoC: tlv320dac33: Update e-mail address 2011-05-11 16:12:35 +01:00
tpa6130a2-plat.h ASoC: tpa6130a2: Remove model_id from platform data 2011-09-21 16:07:45 +01:00
uda134x.h ASoC: uda134x: Remove is_powered_on_standby from platform data 2014-11-24 18:04:49 +00:00
uda1380.h
util_mem.h
vx_core.h ALSA: vx: Use nonatomic PCM ops 2014-09-15 15:52:03 +02:00
wavefront.h
wm0010.h ASoC: wm0010: Add initial wm0010 DSP driver 2012-08-23 16:12:12 +01:00
wm1250-ev1.h ASoC: Add platform data for WM1250 EV1 GPIOs 2011-09-23 17:05:38 +01:00
wm2000.h ASoC: wm2000: Use clock API integration to configure MCLK divisor 2012-12-24 15:42:35 +00:00
wm2200.h ASoC: wm2200: Provide platform data for MICBIAS configuration 2013-02-05 15:53:07 +00:00
wm5100.h ASoC: Add WM5100 driver 2011-09-20 16:02:16 +01:00
wm8903.h ASoC: WM8903: Fix platform data gpio_cfg confusion 2011-12-06 10:29:22 +00:00
wm8904.h ASoC: wm8904: Correct number of EQ registers 2015-10-20 15:46:09 +01:00
wm8955.h
wm8960.h ASoC: wm8960: remove 'dres' field from platform data structure 2012-09-21 08:35:06 -04:00
wm8962.h ASoC: wm8962: Let CODEC driver enable and disable its own MCLK 2014-07-31 20:51:26 +01:00
wm8993.h ASoC: wm_hubs: Allow configuration of MICBIAS power up delay via pdata 2012-08-22 19:00:37 +01:00
wm8996.h ASoC: Rename WM8915 to WM8996 2011-08-08 14:30:37 +09:00
wm9081.h
wm9090.h
wss.h ALSA: wss: Remove (almost) always NULL parameters 2015-01-02 16:30:08 +01:00