2019-05-27 06:55:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-05-19 14:29:30 +00:00
|
|
|
/*
|
|
|
|
* hdac_i915.c - routines for sync between HD-A core and i915 display driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/hdaudio.h>
|
|
|
|
#include <sound/hda_i915.h>
|
2016-04-21 14:39:17 +00:00
|
|
|
#include <sound/hda_register.h>
|
2023-10-09 11:54:30 +00:00
|
|
|
#include <video/nomodeset.h>
|
|
|
|
|
|
|
|
static int gpu_bind = -1;
|
|
|
|
module_param(gpu_bind, int, 0644);
|
|
|
|
MODULE_PARM_DESC(gpu_bind, "Whether to bind sound component to GPU "
|
|
|
|
"(1=always, 0=never, -1=on nomodeset(default))");
|
2015-05-19 14:29:30 +00:00
|
|
|
|
2015-10-28 11:26:48 +00:00
|
|
|
/**
|
2016-04-21 14:39:17 +00:00
|
|
|
* snd_hdac_i915_set_bclk - Reprogram BCLK for HSW/BDW
|
2015-10-28 11:26:48 +00:00
|
|
|
* @bus: HDA core bus
|
|
|
|
*
|
2016-04-21 14:39:17 +00:00
|
|
|
* Intel HSW/BDW display HDA controller is in GPU. Both its power and link BCLK
|
|
|
|
* depends on GPU. Two Extended Mode registers EM4 (M value) and EM5 (N Value)
|
|
|
|
* are used to convert CDClk (Core Display Clock) to 24MHz BCLK:
|
|
|
|
* BCLK = CDCLK * M / N
|
|
|
|
* The values will be lost when the display power well is disabled and need to
|
|
|
|
* be restored to avoid abnormal playback speed.
|
2015-10-28 11:26:48 +00:00
|
|
|
*
|
2016-04-21 14:39:17 +00:00
|
|
|
* Call this function at initializing and changing power well, as well as
|
|
|
|
* at ELD notifier for the hotplug.
|
2015-10-28 11:26:48 +00:00
|
|
|
*/
|
2016-04-21 14:39:17 +00:00
|
|
|
void snd_hdac_i915_set_bclk(struct hdac_bus *bus)
|
2015-05-19 14:29:30 +00:00
|
|
|
{
|
2018-07-11 13:17:22 +00:00
|
|
|
struct drm_audio_component *acomp = bus->audio_component;
|
2016-04-21 14:39:17 +00:00
|
|
|
struct pci_dev *pci = to_pci_dev(bus->dev);
|
|
|
|
int cdclk_freq;
|
|
|
|
unsigned int bclk_m, bclk_n;
|
|
|
|
|
|
|
|
if (!acomp || !acomp->ops || !acomp->ops->get_cdclk_freq)
|
|
|
|
return; /* only for i915 binding */
|
2023-07-17 11:45:03 +00:00
|
|
|
if (!HDA_CONTROLLER_IS_HSW(pci))
|
2016-04-21 14:39:17 +00:00
|
|
|
return; /* only HSW/BDW */
|
|
|
|
|
|
|
|
cdclk_freq = acomp->ops->get_cdclk_freq(acomp->dev);
|
|
|
|
switch (cdclk_freq) {
|
|
|
|
case 337500:
|
|
|
|
bclk_m = 16;
|
|
|
|
bclk_n = 225;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 450000:
|
|
|
|
default: /* default CDCLK 450MHz */
|
|
|
|
bclk_m = 4;
|
|
|
|
bclk_n = 75;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 540000:
|
|
|
|
bclk_m = 4;
|
|
|
|
bclk_n = 90;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 675000:
|
|
|
|
bclk_m = 8;
|
|
|
|
bclk_n = 225;
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 14:29:30 +00:00
|
|
|
|
2016-04-21 14:39:17 +00:00
|
|
|
snd_hdac_chip_writew(bus, HSW_EM4, bclk_m);
|
|
|
|
snd_hdac_chip_writew(bus, HSW_EM5, bclk_n);
|
2015-05-19 14:29:30 +00:00
|
|
|
}
|
2016-04-21 14:39:17 +00:00
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_i915_set_bclk);
|
2015-05-19 14:29:30 +00:00
|
|
|
|
2020-09-24 16:10:27 +00:00
|
|
|
/* returns true if the devices can be connected for audio */
|
2020-09-21 14:17:40 +00:00
|
|
|
static bool connectivity_check(struct pci_dev *i915, struct pci_dev *hdac)
|
|
|
|
{
|
|
|
|
struct pci_bus *bus_a = i915->bus, *bus_b = hdac->bus;
|
|
|
|
|
|
|
|
/* directly connected on the same bus */
|
|
|
|
if (bus_a == bus_b)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
bus_a = bus_a->parent;
|
|
|
|
bus_b = bus_b->parent;
|
2023-08-02 15:01:05 +00:00
|
|
|
|
|
|
|
/* connected via parent bus (may be NULL!) */
|
|
|
|
if (bus_a == bus_b)
|
|
|
|
return true;
|
|
|
|
|
2020-09-21 14:17:40 +00:00
|
|
|
if (!bus_a || !bus_b)
|
|
|
|
return false;
|
2023-08-02 15:01:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* on i915 discrete GPUs with embedded HDA audio, the two
|
|
|
|
* devices are connected via 2nd level PCI bridge
|
|
|
|
*/
|
2020-09-21 14:17:40 +00:00
|
|
|
bus_a = bus_a->parent;
|
|
|
|
bus_b = bus_b->parent;
|
|
|
|
if (bus_a && bus_a == bus_b)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-07 23:27:59 +00:00
|
|
|
static int i915_component_master_match(struct device *dev, int subcomponent,
|
|
|
|
void *data)
|
2015-12-01 11:39:38 +00:00
|
|
|
{
|
2020-09-21 14:17:40 +00:00
|
|
|
struct pci_dev *hdac_pci, *i915_pci;
|
|
|
|
struct hdac_bus *bus = data;
|
|
|
|
|
|
|
|
if (!dev_is_pci(dev))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
hdac_pci = to_pci_dev(bus->dev);
|
|
|
|
i915_pci = to_pci_dev(dev);
|
|
|
|
|
2023-10-09 11:54:32 +00:00
|
|
|
if ((!strcmp(dev->driver->name, "i915") ||
|
|
|
|
!strcmp(dev->driver->name, "xe")) &&
|
2020-09-21 14:17:40 +00:00
|
|
|
subcomponent == I915_COMPONENT_AUDIO &&
|
|
|
|
connectivity_check(i915_pci, hdac_pci))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
2015-05-19 14:29:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 12:36:22 +00:00
|
|
|
/* check whether Intel graphics is present and reachable */
|
|
|
|
static int i915_gfx_present(struct pci_dev *hdac_pci)
|
2016-03-29 13:03:06 +00:00
|
|
|
{
|
2022-04-05 12:36:22 +00:00
|
|
|
struct pci_dev *display_dev = NULL;
|
|
|
|
|
2023-10-09 11:54:30 +00:00
|
|
|
if (!gpu_bind || (gpu_bind < 0 && video_firmware_drivers_only()))
|
|
|
|
return false;
|
|
|
|
|
2022-06-21 12:00:44 +00:00
|
|
|
for_each_pci_dev(display_dev) {
|
|
|
|
if (display_dev->vendor == PCI_VENDOR_ID_INTEL &&
|
|
|
|
(display_dev->class >> 16) == PCI_BASE_CLASS_DISPLAY &&
|
2022-04-16 06:44:18 +00:00
|
|
|
connectivity_check(display_dev, hdac_pci)) {
|
|
|
|
pci_dev_put(display_dev);
|
2022-06-21 12:00:44 +00:00
|
|
|
return true;
|
2022-04-16 06:44:18 +00:00
|
|
|
}
|
2022-06-21 12:00:44 +00:00
|
|
|
}
|
2022-04-05 12:36:22 +00:00
|
|
|
|
2022-06-21 12:00:44 +00:00
|
|
|
return false;
|
2016-03-29 13:03:06 +00:00
|
|
|
}
|
|
|
|
|
2015-10-28 11:26:48 +00:00
|
|
|
/**
|
|
|
|
* snd_hdac_i915_init - Initialize i915 audio component
|
|
|
|
* @bus: HDA core bus
|
|
|
|
*
|
|
|
|
* This function is supposed to be used only by a HD-audio controller
|
|
|
|
* driver that needs the interaction with i915 graphics.
|
|
|
|
*
|
|
|
|
* This function initializes and sets up the audio component to communicate
|
|
|
|
* with i915 graphics driver.
|
|
|
|
*
|
|
|
|
* Returns zero for success or a negative error code.
|
|
|
|
*/
|
2023-10-09 11:54:37 +00:00
|
|
|
int snd_hdac_i915_init(struct hdac_bus *bus)
|
2015-05-19 14:29:30 +00:00
|
|
|
{
|
2018-07-11 13:17:22 +00:00
|
|
|
struct drm_audio_component *acomp;
|
ALSA: hda: Make audio component support more generic
This is the final step for more generic support of DRM audio
component. The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively. The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.
Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively. All these are optional,
but used in i915 implementation and also other later implementations.
A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init(). The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error. Meanwhile the new function doesn't
synchronize but just leaves as is. It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.
v1->v2: Fix missing NULL check in master_bind/unbind
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-07-11 14:23:16 +00:00
|
|
|
int err;
|
2016-03-21 13:41:58 +00:00
|
|
|
|
2022-04-05 12:36:22 +00:00
|
|
|
if (!i915_gfx_present(to_pci_dev(bus->dev)))
|
2016-03-29 13:03:06 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2020-10-06 16:17:22 +00:00
|
|
|
err = snd_hdac_acomp_init(bus, NULL,
|
ALSA: hda: Make audio component support more generic
This is the final step for more generic support of DRM audio
component. The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively. The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.
Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively. All these are optional,
but used in i915 implementation and also other later implementations.
A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init(). The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error. Meanwhile the new function doesn't
synchronize but just leaves as is. It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.
v1->v2: Fix missing NULL check in master_bind/unbind
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-07-11 14:23:16 +00:00
|
|
|
i915_component_master_match,
|
|
|
|
sizeof(struct i915_audio_component) - sizeof(*acomp));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
acomp = bus->audio_component;
|
|
|
|
if (!acomp)
|
|
|
|
return -ENODEV;
|
2015-05-19 14:29:30 +00:00
|
|
|
if (!acomp->ops) {
|
ALSA: hda: Make audio component support more generic
This is the final step for more generic support of DRM audio
component. The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively. The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.
Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively. All these are optional,
but used in i915 implementation and also other later implementations.
A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init(). The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error. Meanwhile the new function doesn't
synchronize but just leaves as is. It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.
v1->v2: Fix missing NULL check in master_bind/unbind
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-07-11 14:23:16 +00:00
|
|
|
snd_hdac_acomp_exit(bus);
|
2023-10-09 11:54:37 +00:00
|
|
|
return dev_err_probe(bus->dev, -EPROBE_DEFER,
|
|
|
|
"couldn't bind with audio component\n");
|
2015-05-19 14:29:30 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_i915_init);
|