2015-05-19 16:29:30 +02:00
|
|
|
/*
|
|
|
|
* hdac_i915.c - routines for sync between HD-A core and i915 display driver
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 16:39:17 +02:00
|
|
|
#include <sound/hda_register.h>
|
2015-05-19 16:29:30 +02:00
|
|
|
|
2018-07-11 15:05:06 +02:00
|
|
|
static struct completion bind_complete;
|
|
|
|
|
2016-04-21 16:39:17 +02:00
|
|
|
#define CONTROLLER_IN_GPU(pci) (((pci)->device == 0x0a0c) || \
|
|
|
|
((pci)->device == 0x0c0c) || \
|
|
|
|
((pci)->device == 0x0d0c) || \
|
|
|
|
((pci)->device == 0x160c))
|
|
|
|
|
2015-10-28 12:26:48 +01:00
|
|
|
/**
|
2016-04-21 16:39:17 +02:00
|
|
|
* snd_hdac_i915_set_bclk - Reprogram BCLK for HSW/BDW
|
2015-10-28 12:26:48 +01:00
|
|
|
* @bus: HDA core bus
|
|
|
|
*
|
2016-04-21 16:39:17 +02: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 12:26:48 +01:00
|
|
|
*
|
2016-04-21 16:39:17 +02:00
|
|
|
* Call this function at initializing and changing power well, as well as
|
|
|
|
* at ELD notifier for the hotplug.
|
2015-10-28 12:26:48 +01:00
|
|
|
*/
|
2016-04-21 16:39:17 +02:00
|
|
|
void snd_hdac_i915_set_bclk(struct hdac_bus *bus)
|
2015-05-19 16:29:30 +02:00
|
|
|
{
|
2018-07-11 15:17:22 +02:00
|
|
|
struct drm_audio_component *acomp = bus->audio_component;
|
2016-04-21 16:39:17 +02: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 */
|
|
|
|
if (!CONTROLLER_IN_GPU(pci))
|
|
|
|
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 16:29:30 +02:00
|
|
|
|
2016-04-21 16:39:17 +02:00
|
|
|
snd_hdac_chip_writew(bus, HSW_EM4, bclk_m);
|
|
|
|
snd_hdac_chip_writew(bus, HSW_EM5, bclk_n);
|
2015-05-19 16:29:30 +02:00
|
|
|
}
|
2016-04-21 16:39:17 +02:00
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_i915_set_bclk);
|
2015-05-19 16:29:30 +02:00
|
|
|
|
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 16:23:16 +02:00
|
|
|
static int i915_component_master_match(struct device *dev, void *data)
|
2015-12-01 12:39:38 +01:00
|
|
|
{
|
2015-05-19 16:29:30 +02:00
|
|
|
return !strcmp(dev->driver->name, "i915");
|
|
|
|
}
|
|
|
|
|
2016-03-29 15:03:06 +02:00
|
|
|
/* check whether intel graphics is present */
|
|
|
|
static bool i915_gfx_present(void)
|
|
|
|
{
|
2017-07-18 19:05:06 +02:00
|
|
|
static const struct pci_device_id ids[] = {
|
2016-03-29 15:03:06 +02:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
|
|
|
|
.class = PCI_BASE_CLASS_DISPLAY << 16,
|
|
|
|
.class_mask = 0xff << 16 },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
return pci_dev_present(ids);
|
|
|
|
}
|
|
|
|
|
2018-07-11 15:05:06 +02:00
|
|
|
static int i915_master_bind(struct device *dev,
|
|
|
|
struct drm_audio_component *acomp)
|
|
|
|
{
|
|
|
|
complete_all(&bind_complete);
|
|
|
|
/* clear audio_ops here as it was needed only for completion call */
|
|
|
|
acomp->audio_ops = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_audio_component_audio_ops i915_init_ops = {
|
|
|
|
.master_bind = i915_master_bind
|
|
|
|
};
|
|
|
|
|
2015-10-28 12:26:48 +01: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.
|
|
|
|
*/
|
2015-05-19 16:29:30 +02:00
|
|
|
int snd_hdac_i915_init(struct hdac_bus *bus)
|
|
|
|
{
|
2018-07-11 15:17:22 +02: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 16:23:16 +02:00
|
|
|
int err;
|
2016-03-21 14:41:58 +01:00
|
|
|
|
2016-03-29 15:03:06 +02:00
|
|
|
if (!i915_gfx_present())
|
|
|
|
return -ENODEV;
|
|
|
|
|
2018-07-11 15:05:06 +02:00
|
|
|
init_completion(&bind_complete);
|
|
|
|
|
|
|
|
err = snd_hdac_acomp_init(bus, &i915_init_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 16:23:16 +02: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;
|
2018-07-11 15:05:06 +02: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 16:23:16 +02:00
|
|
|
request_module("i915");
|
2018-07-11 15:05:06 +02:00
|
|
|
/* 10s timeout */
|
|
|
|
wait_for_completion_timeout(&bind_complete, 10 * 1000);
|
|
|
|
}
|
2015-05-19 16:29:30 +02: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 16:23:16 +02:00
|
|
|
snd_hdac_acomp_exit(bus);
|
|
|
|
return -ENODEV;
|
2015-05-19 16:29:30 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_i915_init);
|