2015-02-17 14:25:37 +00:00
|
|
|
/*
|
|
|
|
* HD-audio codec driver binding
|
|
|
|
* Copyright (c) Takashi Iwai <tiwai@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/export.h>
|
2015-02-18 14:39:59 +00:00
|
|
|
#include <linux/pm.h>
|
2015-03-05 16:21:32 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2015-02-17 14:25:37 +00:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include "hda_codec.h"
|
|
|
|
#include "hda_local.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find a matching codec preset
|
|
|
|
*/
|
2015-02-17 20:46:37 +00:00
|
|
|
static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
|
2015-02-17 14:25:37 +00:00
|
|
|
{
|
2015-02-17 20:46:37 +00:00
|
|
|
struct hda_codec *codec = container_of(dev, struct hda_codec, core);
|
2015-02-17 14:25:37 +00:00
|
|
|
struct hda_codec_driver *driver =
|
2015-02-17 20:46:37 +00:00
|
|
|
container_of(drv, struct hda_codec_driver, core);
|
2015-02-17 14:25:37 +00:00
|
|
|
const struct hda_codec_preset *preset;
|
|
|
|
/* check probe_id instead of vendor_id if set */
|
2015-03-03 09:07:24 +00:00
|
|
|
u32 id = codec->probe_id ? codec->probe_id : codec->core.vendor_id;
|
2015-02-17 14:25:37 +00:00
|
|
|
|
|
|
|
for (preset = driver->preset; preset->id; preset++) {
|
|
|
|
u32 mask = preset->mask;
|
|
|
|
|
2015-03-03 09:07:24 +00:00
|
|
|
if (preset->afg && preset->afg != codec->core.afg)
|
2015-02-17 14:25:37 +00:00
|
|
|
continue;
|
2015-03-03 09:07:24 +00:00
|
|
|
if (preset->mfg && preset->mfg != codec->core.mfg)
|
2015-02-17 14:25:37 +00:00
|
|
|
continue;
|
|
|
|
if (!mask)
|
|
|
|
mask = ~0;
|
|
|
|
if (preset->id == (id & mask) &&
|
2015-03-03 09:07:24 +00:00
|
|
|
(!preset->rev || preset->rev == codec->core.revision_id)) {
|
2015-02-17 14:25:37 +00:00
|
|
|
codec->preset = preset;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-02 22:22:59 +00:00
|
|
|
/* process an unsolicited event */
|
|
|
|
static void hda_codec_unsol_event(struct hdac_device *dev, unsigned int ev)
|
|
|
|
{
|
|
|
|
struct hda_codec *codec = container_of(dev, struct hda_codec, core);
|
|
|
|
|
|
|
|
if (codec->patch_ops.unsol_event)
|
|
|
|
codec->patch_ops.unsol_event(codec, ev);
|
|
|
|
}
|
|
|
|
|
2015-02-17 14:25:37 +00:00
|
|
|
/* reset the codec name from the preset */
|
|
|
|
static int codec_refresh_name(struct hda_codec *codec, const char *name)
|
|
|
|
{
|
2015-03-03 09:07:24 +00:00
|
|
|
if (name) {
|
|
|
|
kfree(codec->core.chip_name);
|
|
|
|
codec->core.chip_name = kstrdup(name, GFP_KERNEL);
|
2015-02-17 14:25:37 +00:00
|
|
|
}
|
2015-03-03 09:07:24 +00:00
|
|
|
return codec->core.chip_name ? 0 : -ENOMEM;
|
2015-02-17 14:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hda_codec_driver_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
struct hda_codec *codec = dev_to_hda_codec(dev);
|
|
|
|
struct module *owner = dev->driver->owner;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (WARN_ON(!codec->preset))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = codec_refresh_name(codec, codec->preset->name);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!try_module_get(owner)) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = codec->preset->patch(codec);
|
2015-02-27 19:44:54 +00:00
|
|
|
if (err < 0)
|
|
|
|
goto error_module;
|
|
|
|
|
|
|
|
err = snd_hda_codec_build_pcms(codec);
|
|
|
|
if (err < 0)
|
|
|
|
goto error_module;
|
|
|
|
err = snd_hda_codec_build_controls(codec);
|
|
|
|
if (err < 0)
|
|
|
|
goto error_module;
|
|
|
|
if (codec->card->registered) {
|
|
|
|
err = snd_card_register(codec->card);
|
|
|
|
if (err < 0)
|
|
|
|
goto error_module;
|
2015-03-03 16:22:12 +00:00
|
|
|
snd_hda_codec_register(codec);
|
2015-02-17 14:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2015-02-27 19:44:54 +00:00
|
|
|
error_module:
|
|
|
|
module_put(owner);
|
|
|
|
|
2015-02-17 14:25:37 +00:00
|
|
|
error:
|
2015-02-27 19:44:54 +00:00
|
|
|
snd_hda_codec_cleanup_for_unbind(codec);
|
2015-02-17 14:25:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hda_codec_driver_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct hda_codec *codec = dev_to_hda_codec(dev);
|
|
|
|
|
|
|
|
if (codec->patch_ops.free)
|
|
|
|
codec->patch_ops.free(codec);
|
2015-02-27 17:17:28 +00:00
|
|
|
snd_hda_codec_cleanup_for_unbind(codec);
|
2015-02-17 14:25:37 +00:00
|
|
|
module_put(dev->driver->owner);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-05 16:21:32 +00:00
|
|
|
static void hda_codec_driver_shutdown(struct device *dev)
|
|
|
|
{
|
|
|
|
struct hda_codec *codec = dev_to_hda_codec(dev);
|
|
|
|
|
|
|
|
if (!pm_runtime_suspended(dev) && codec->patch_ops.reboot_notify)
|
|
|
|
codec->patch_ops.reboot_notify(codec);
|
|
|
|
}
|
|
|
|
|
2015-02-17 14:25:37 +00:00
|
|
|
int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
|
|
|
|
struct module *owner)
|
|
|
|
{
|
2015-02-17 20:46:37 +00:00
|
|
|
drv->core.driver.name = name;
|
|
|
|
drv->core.driver.owner = owner;
|
|
|
|
drv->core.driver.bus = &snd_hda_bus_type;
|
|
|
|
drv->core.driver.probe = hda_codec_driver_probe;
|
|
|
|
drv->core.driver.remove = hda_codec_driver_remove;
|
|
|
|
drv->core.driver.shutdown = hda_codec_driver_shutdown;
|
|
|
|
drv->core.driver.pm = &hda_codec_driver_pm;
|
|
|
|
drv->core.type = HDA_DEV_LEGACY;
|
|
|
|
drv->core.match = hda_codec_match;
|
2015-03-02 22:22:59 +00:00
|
|
|
drv->core.unsol_event = hda_codec_unsol_event;
|
2015-02-17 20:46:37 +00:00
|
|
|
return driver_register(&drv->core.driver);
|
2015-02-17 14:25:37 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__hda_codec_driver_register);
|
|
|
|
|
|
|
|
void hda_codec_driver_unregister(struct hda_codec_driver *drv)
|
|
|
|
{
|
2015-02-17 20:46:37 +00:00
|
|
|
driver_unregister(&drv->core.driver);
|
2015-02-17 14:25:37 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(hda_codec_driver_unregister);
|
|
|
|
|
|
|
|
static inline bool codec_probed(struct hda_codec *codec)
|
|
|
|
{
|
|
|
|
return device_attach(hda_codec_dev(codec)) > 0 && codec->preset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to auto-load and bind the codec module */
|
|
|
|
static void codec_bind_module(struct hda_codec *codec)
|
|
|
|
{
|
|
|
|
#ifdef MODULE
|
2015-03-03 09:07:24 +00:00
|
|
|
request_module("snd-hda-codec-id:%08x", codec->core.vendor_id);
|
2015-02-17 14:25:37 +00:00
|
|
|
if (codec_probed(codec))
|
|
|
|
return;
|
|
|
|
request_module("snd-hda-codec-id:%04x*",
|
2015-03-03 09:07:24 +00:00
|
|
|
(codec->core.vendor_id >> 16) & 0xffff);
|
2015-02-17 14:25:37 +00:00
|
|
|
if (codec_probed(codec))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
|
|
|
|
/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */
|
|
|
|
static bool is_likely_hdmi_codec(struct hda_codec *codec)
|
|
|
|
{
|
2015-03-03 09:07:24 +00:00
|
|
|
hda_nid_t nid;
|
2015-02-17 14:25:37 +00:00
|
|
|
|
2015-03-03 09:07:24 +00:00
|
|
|
for_each_hda_codec_node(nid, codec) {
|
2015-02-17 14:25:37 +00:00
|
|
|
unsigned int wcaps = get_wcaps(codec, nid);
|
|
|
|
switch (get_wcaps_type(wcaps)) {
|
|
|
|
case AC_WID_AUD_IN:
|
|
|
|
return false; /* HDMI parser supports only HDMI out */
|
|
|
|
case AC_WID_AUD_OUT:
|
|
|
|
if (!(wcaps & AC_WCAP_DIGITAL))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* no HDMI codec parser support */
|
|
|
|
#define is_likely_hdmi_codec(codec) false
|
|
|
|
#endif /* CONFIG_SND_HDA_CODEC_HDMI */
|
|
|
|
|
|
|
|
static int codec_bind_generic(struct hda_codec *codec)
|
|
|
|
{
|
|
|
|
if (codec->probe_id)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (is_likely_hdmi_codec(codec)) {
|
|
|
|
codec->probe_id = HDA_CODEC_ID_GENERIC_HDMI;
|
|
|
|
#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI)
|
|
|
|
request_module("snd-hda-codec-hdmi");
|
|
|
|
#endif
|
|
|
|
if (codec_probed(codec))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
codec->probe_id = HDA_CODEC_ID_GENERIC;
|
|
|
|
#if IS_MODULE(CONFIG_SND_HDA_GENERIC)
|
|
|
|
request_module("snd-hda-codec-generic");
|
|
|
|
#endif
|
|
|
|
if (codec_probed(codec))
|
|
|
|
return 0;
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_SND_HDA_GENERIC)
|
|
|
|
#define is_generic_config(codec) \
|
|
|
|
(codec->modelname && !strcmp(codec->modelname, "generic"))
|
|
|
|
#else
|
|
|
|
#define is_generic_config(codec) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hda_codec_configure - (Re-)configure the HD-audio codec
|
|
|
|
* @codec: the HDA codec
|
|
|
|
*
|
|
|
|
* Start parsing of the given codec tree and (re-)initialize the whole
|
|
|
|
* patch instance.
|
|
|
|
*
|
|
|
|
* Returns 0 if successful or a negative error code.
|
|
|
|
*/
|
|
|
|
int snd_hda_codec_configure(struct hda_codec *codec)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (is_generic_config(codec))
|
|
|
|
codec->probe_id = HDA_CODEC_ID_GENERIC;
|
|
|
|
else
|
|
|
|
codec->probe_id = 0;
|
|
|
|
|
ALSA: hda - Add widget sysfs tree
This patch changes the sysfs files assigned to the codec device on the
bus which were formerly identical with hwdep sysfs files. Now it
shows only a few core parameter, vendor_id, subsystem_id, revision_id,
afg, mfg, vendor_name and chip_name.
In addition, now a widget tree is added to the bus device sysfs
directory for showing the widget topology and attributes. It's just a
flat tree consisting of subdirectories named as the widget NID
including various attributes like widget capability bits. The AFG
(usually NID 0x01) is always found there, and it contains always
amp_in_caps, amp_out_caps and power_caps files. Each of these
attributes show a single value. The rest are the widget nodes
belonging to that AFG. Note that the child node might not start from
0x02 but from another value like 0x0a.
Each child node may contain caps, pin_caps, amp_in_caps, amp_out_caps,
power_caps and connections files. The caps (representing the widget
capability bits) always contain a value. The rest may contain
value(s) if the attribute exists on the node. Only connections file
show multiple values while other attributes have zero or one single
value.
An example of ls -R output is like below:
% ls -R /sys/bus/hdaudio/devices/hdaudioC0D0/
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/:
01/ 04/ 07/ 0a/ 0d/ 10/ 13/ 16/ 19/ 1c/ 1f/ 22/
02/ 05/ 08/ 0b/ 0e/ 11/ 14/ 17/ 1a/ 1d/ 20/ 23/
03/ 06/ 09/ 0c/ 0f/ 12/ 15/ 18/ 1b/ 1e/ 21/
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/01:
amp_in_caps amp_out_caps power_caps
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/02:
amp_in_caps amp_out_caps caps connections pin_caps pin_cfg
power_caps
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/03:
.....
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-24 13:59:42 +00:00
|
|
|
err = snd_hdac_device_register(&codec->core);
|
2015-02-17 14:25:37 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!codec->preset)
|
|
|
|
codec_bind_module(codec);
|
|
|
|
if (!codec->preset) {
|
|
|
|
err = codec_bind_generic(codec);
|
|
|
|
if (err < 0) {
|
|
|
|
codec_err(codec, "Unable to bind the codec\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* audio codec should override the mixer name */
|
2015-03-03 09:07:24 +00:00
|
|
|
if (codec->core.afg || !*codec->card->mixername)
|
2015-02-27 15:09:22 +00:00
|
|
|
snprintf(codec->card->mixername,
|
2015-03-03 09:07:24 +00:00
|
|
|
sizeof(codec->card->mixername), "%s %s",
|
|
|
|
codec->core.vendor_name, codec->core.chip_name);
|
2015-02-17 14:25:37 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
ALSA: hda - Add widget sysfs tree
This patch changes the sysfs files assigned to the codec device on the
bus which were formerly identical with hwdep sysfs files. Now it
shows only a few core parameter, vendor_id, subsystem_id, revision_id,
afg, mfg, vendor_name and chip_name.
In addition, now a widget tree is added to the bus device sysfs
directory for showing the widget topology and attributes. It's just a
flat tree consisting of subdirectories named as the widget NID
including various attributes like widget capability bits. The AFG
(usually NID 0x01) is always found there, and it contains always
amp_in_caps, amp_out_caps and power_caps files. Each of these
attributes show a single value. The rest are the widget nodes
belonging to that AFG. Note that the child node might not start from
0x02 but from another value like 0x0a.
Each child node may contain caps, pin_caps, amp_in_caps, amp_out_caps,
power_caps and connections files. The caps (representing the widget
capability bits) always contain a value. The rest may contain
value(s) if the attribute exists on the node. Only connections file
show multiple values while other attributes have zero or one single
value.
An example of ls -R output is like below:
% ls -R /sys/bus/hdaudio/devices/hdaudioC0D0/
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/:
01/ 04/ 07/ 0a/ 0d/ 10/ 13/ 16/ 19/ 1c/ 1f/ 22/
02/ 05/ 08/ 0b/ 0e/ 11/ 14/ 17/ 1a/ 1d/ 20/ 23/
03/ 06/ 09/ 0c/ 0f/ 12/ 15/ 18/ 1b/ 1e/ 21/
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/01:
amp_in_caps amp_out_caps power_caps
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/02:
amp_in_caps amp_out_caps caps connections pin_caps pin_cfg
power_caps
/sys/bus/hdaudio/devices/hdaudioC0D0/widgets/03:
.....
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-24 13:59:42 +00:00
|
|
|
snd_hdac_device_unregister(&codec->core);
|
2015-02-17 14:25:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hda_codec_configure);
|