2020-05-01 22:58:50 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-08-23 04:24:59 +08:00
|
|
|
// Copyright(c) 2015-18 Intel Corporation.
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Machine Driver for SKL+ platforms with DSP and iDisp, HDA Codecs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/jack.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
2018-11-02 05:34:49 +08:00
|
|
|
#include <sound/soc-acpi.h>
|
2018-08-23 04:24:59 +08:00
|
|
|
#include "../../codecs/hdac_hdmi.h"
|
|
|
|
#include "skl_hda_dsp_common.h"
|
|
|
|
|
2018-08-23 04:25:03 +08:00
|
|
|
static const struct snd_soc_dapm_widget skl_hda_widgets[] = {
|
|
|
|
SND_SOC_DAPM_HP("Analog Out", NULL),
|
|
|
|
SND_SOC_DAPM_MIC("Analog In", NULL),
|
|
|
|
SND_SOC_DAPM_HP("Alt Analog Out", NULL),
|
|
|
|
SND_SOC_DAPM_MIC("Alt Analog In", NULL),
|
|
|
|
SND_SOC_DAPM_SPK("Digital Out", NULL),
|
|
|
|
SND_SOC_DAPM_MIC("Digital In", NULL),
|
2019-08-10 07:22:36 +08:00
|
|
|
SND_SOC_DAPM_MIC("SoC DMIC", NULL),
|
2018-08-23 04:25:03 +08:00
|
|
|
};
|
|
|
|
|
2018-08-23 04:24:59 +08:00
|
|
|
static const struct snd_soc_dapm_route skl_hda_map[] = {
|
|
|
|
{ "hifi3", NULL, "iDisp3 Tx"},
|
|
|
|
{ "iDisp3 Tx", NULL, "iDisp3_out"},
|
|
|
|
{ "hifi2", NULL, "iDisp2 Tx"},
|
|
|
|
{ "iDisp2 Tx", NULL, "iDisp2_out"},
|
|
|
|
{ "hifi1", NULL, "iDisp1 Tx"},
|
|
|
|
{ "iDisp1 Tx", NULL, "iDisp1_out"},
|
2018-08-23 04:25:03 +08:00
|
|
|
|
|
|
|
{ "Analog Out", NULL, "Codec Output Pin1" },
|
|
|
|
{ "Digital Out", NULL, "Codec Output Pin2" },
|
|
|
|
{ "Alt Analog Out", NULL, "Codec Output Pin3" },
|
|
|
|
|
|
|
|
{ "Codec Input Pin1", NULL, "Analog In" },
|
|
|
|
{ "Codec Input Pin2", NULL, "Digital In" },
|
|
|
|
{ "Codec Input Pin3", NULL, "Alt Analog In" },
|
|
|
|
|
2019-08-10 07:22:36 +08:00
|
|
|
/* digital mics */
|
|
|
|
{"DMic", NULL, "SoC DMIC"},
|
|
|
|
|
2018-08-23 04:25:03 +08:00
|
|
|
/* CODEC BE connections */
|
|
|
|
{ "Analog Codec Playback", NULL, "Analog CPU Playback" },
|
|
|
|
{ "Analog CPU Playback", NULL, "codec0_out" },
|
|
|
|
{ "Digital Codec Playback", NULL, "Digital CPU Playback" },
|
|
|
|
{ "Digital CPU Playback", NULL, "codec1_out" },
|
|
|
|
{ "Alt Analog Codec Playback", NULL, "Alt Analog CPU Playback" },
|
|
|
|
{ "Alt Analog CPU Playback", NULL, "codec2_out" },
|
|
|
|
|
|
|
|
{ "codec0_in", NULL, "Analog CPU Capture" },
|
|
|
|
{ "Analog CPU Capture", NULL, "Analog Codec Capture" },
|
|
|
|
{ "codec1_in", NULL, "Digital CPU Capture" },
|
|
|
|
{ "Digital CPU Capture", NULL, "Digital Codec Capture" },
|
|
|
|
{ "codec2_in", NULL, "Alt Analog CPU Capture" },
|
|
|
|
{ "Alt Analog CPU Capture", NULL, "Alt Analog Codec Capture" },
|
2018-08-23 04:24:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int skl_hda_card_late_probe(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
return skl_hda_hdmi_jack_init(card);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
skl_hda_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *link)
|
|
|
|
{
|
|
|
|
struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
|
|
|
|
int ret = 0;
|
|
|
|
|
2022-06-17 05:53:50 +08:00
|
|
|
dev_dbg(card->dev, "dai link name - %s\n", link->name);
|
2019-06-06 12:22:04 +08:00
|
|
|
link->platforms->name = ctx->platform_name;
|
2018-08-23 04:24:59 +08:00
|
|
|
link->nonatomic = 1;
|
|
|
|
|
2020-07-14 21:28:04 +08:00
|
|
|
if (!ctx->idisp_codec)
|
|
|
|
return 0;
|
|
|
|
|
2018-08-23 04:24:59 +08:00
|
|
|
if (strstr(link->name, "HDMI")) {
|
|
|
|
ret = skl_hda_hdmi_add_pcm(card, ctx->pcm_count);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ctx->dai_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->pcm_count++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_soc_card hda_soc_card = {
|
2019-10-29 00:46:24 +08:00
|
|
|
.name = "hda-dsp",
|
2018-08-23 04:24:59 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.dai_link = skl_hda_be_dai_links,
|
2018-08-23 04:25:03 +08:00
|
|
|
.dapm_widgets = skl_hda_widgets,
|
2018-08-23 04:24:59 +08:00
|
|
|
.dapm_routes = skl_hda_map,
|
|
|
|
.add_dai_link = skl_hda_add_dai_link,
|
|
|
|
.fully_routed = true,
|
|
|
|
.late_probe = skl_hda_card_late_probe,
|
|
|
|
};
|
|
|
|
|
2019-12-05 05:15:44 +08:00
|
|
|
static char hda_soc_components[30];
|
|
|
|
|
2018-08-23 04:24:59 +08:00
|
|
|
#define IDISP_DAI_COUNT 3
|
2019-05-01 06:37:42 +08:00
|
|
|
#define HDAC_DAI_COUNT 2
|
|
|
|
#define DMIC_DAI_COUNT 2
|
|
|
|
|
2018-08-23 04:24:59 +08:00
|
|
|
/* there are two routes per iDisp output */
|
|
|
|
#define IDISP_ROUTE_COUNT (IDISP_DAI_COUNT * 2)
|
|
|
|
#define IDISP_CODEC_MASK 0x4
|
|
|
|
|
2020-04-10 02:58:16 +08:00
|
|
|
#define HDA_CODEC_AUTOSUSPEND_DELAY_MS 1000
|
|
|
|
|
2018-11-02 05:34:49 +08:00
|
|
|
static int skl_hda_fill_card_info(struct snd_soc_acpi_mach_params *mach_params)
|
2018-08-23 04:24:59 +08:00
|
|
|
{
|
|
|
|
struct snd_soc_card *card = &hda_soc_card;
|
2020-07-14 21:28:04 +08:00
|
|
|
struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
|
2018-09-18 09:28:49 +08:00
|
|
|
struct snd_soc_dai_link *dai_link;
|
2020-07-14 21:28:04 +08:00
|
|
|
u32 codec_count, codec_mask;
|
2018-08-23 04:24:59 +08:00
|
|
|
int i, num_links, num_route;
|
|
|
|
|
2018-11-02 05:34:49 +08:00
|
|
|
codec_mask = mach_params->codec_mask;
|
2018-08-23 04:24:59 +08:00
|
|
|
codec_count = hweight_long(codec_mask);
|
2020-07-14 21:28:04 +08:00
|
|
|
ctx->idisp_codec = !!(codec_mask & IDISP_CODEC_MASK);
|
2020-02-21 01:10:27 +08:00
|
|
|
|
|
|
|
if (!codec_count || codec_count > 2 ||
|
2020-07-14 21:28:04 +08:00
|
|
|
(codec_count == 2 && !ctx->idisp_codec))
|
2020-02-21 01:10:27 +08:00
|
|
|
return -EINVAL;
|
2018-08-23 04:24:59 +08:00
|
|
|
|
2020-07-14 21:28:04 +08:00
|
|
|
if (codec_mask == IDISP_CODEC_MASK) {
|
2020-02-21 01:10:27 +08:00
|
|
|
/* topology with iDisp as the only HDA codec */
|
2019-05-01 06:37:42 +08:00
|
|
|
num_links = IDISP_DAI_COUNT + DMIC_DAI_COUNT;
|
2018-08-23 04:24:59 +08:00
|
|
|
num_route = IDISP_ROUTE_COUNT;
|
2019-05-01 06:37:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rearrange the dai link array and make the
|
|
|
|
* dmic dai links follow idsp dai links for only
|
|
|
|
* num_links of dai links need to be registered
|
|
|
|
* to ASoC.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < DMIC_DAI_COUNT; i++) {
|
|
|
|
skl_hda_be_dai_links[IDISP_DAI_COUNT + i] =
|
|
|
|
skl_hda_be_dai_links[IDISP_DAI_COUNT +
|
|
|
|
HDAC_DAI_COUNT + i];
|
|
|
|
}
|
2020-02-21 01:10:27 +08:00
|
|
|
} else {
|
|
|
|
/* topology with external and iDisp HDA codecs */
|
2018-08-23 04:25:03 +08:00
|
|
|
num_links = ARRAY_SIZE(skl_hda_be_dai_links);
|
2019-05-01 06:37:43 +08:00
|
|
|
num_route = ARRAY_SIZE(skl_hda_map);
|
2018-08-23 04:25:03 +08:00
|
|
|
card->dapm_widgets = skl_hda_widgets;
|
|
|
|
card->num_dapm_widgets = ARRAY_SIZE(skl_hda_widgets);
|
2020-07-14 21:28:04 +08:00
|
|
|
if (!ctx->idisp_codec) {
|
2023-11-24 20:40:15 +08:00
|
|
|
card->dapm_routes = &skl_hda_map[IDISP_ROUTE_COUNT];
|
|
|
|
num_route -= IDISP_ROUTE_COUNT;
|
2020-02-21 01:10:27 +08:00
|
|
|
for (i = 0; i < IDISP_DAI_COUNT; i++) {
|
2023-09-26 14:24:24 +08:00
|
|
|
skl_hda_be_dai_links[i].codecs = &snd_soc_dummy_dlc;
|
2023-04-24 10:37:17 +08:00
|
|
|
skl_hda_be_dai_links[i].num_codecs = 1;
|
2020-02-21 01:10:27 +08:00
|
|
|
}
|
|
|
|
}
|
2018-08-23 04:24:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
card->num_links = num_links;
|
|
|
|
card->num_dapm_routes = num_route;
|
|
|
|
|
2018-09-18 09:28:49 +08:00
|
|
|
for_each_card_prelinks(card, i, dai_link)
|
2019-06-06 12:22:04 +08:00
|
|
|
dai_link->platforms->name = mach_params->platform;
|
2018-08-23 04:24:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:58:16 +08:00
|
|
|
static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card)
|
|
|
|
{
|
2020-04-21 04:54:31 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd;
|
2020-04-10 02:58:16 +08:00
|
|
|
struct hdac_hda_priv *hda_pvt;
|
2020-04-21 04:54:31 +08:00
|
|
|
struct snd_soc_dai *dai;
|
|
|
|
|
|
|
|
for_each_card_rtds(card, rtd) {
|
2020-07-23 01:35:24 +08:00
|
|
|
if (!strstr(rtd->dai_link->codecs->name, "ehdaudio0D0"))
|
2020-04-21 04:54:31 +08:00
|
|
|
continue;
|
2023-09-26 14:24:24 +08:00
|
|
|
dai = snd_soc_rtd_to_codec(rtd, 0);
|
2020-04-21 04:54:31 +08:00
|
|
|
hda_pvt = snd_soc_component_get_drvdata(dai->component);
|
|
|
|
if (hda_pvt) {
|
|
|
|
/*
|
|
|
|
* all codecs are on the same bus, so it's sufficient
|
|
|
|
* to look up only the first one
|
|
|
|
*/
|
2022-08-16 19:17:24 +08:00
|
|
|
snd_hda_set_power_save(hda_pvt->codec->bus,
|
2020-04-21 04:54:31 +08:00
|
|
|
HDA_CODEC_AUTOSUSPEND_DELAY_MS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 02:58:16 +08:00
|
|
|
}
|
|
|
|
|
2018-08-23 04:24:59 +08:00
|
|
|
static int skl_hda_audio_probe(struct platform_device *pdev)
|
|
|
|
{
|
2018-11-02 05:34:49 +08:00
|
|
|
struct snd_soc_acpi_mach *mach;
|
2018-08-23 04:24:59 +08:00
|
|
|
struct skl_hda_private *ctx;
|
|
|
|
int ret;
|
|
|
|
|
2022-06-17 05:53:50 +08:00
|
|
|
dev_dbg(&pdev->dev, "entry\n");
|
2018-08-23 04:24:59 +08:00
|
|
|
|
2018-11-02 05:34:52 +08:00
|
|
|
ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
|
2018-08-23 04:24:59 +08:00
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
|
|
|
|
|
2020-03-13 03:48:56 +08:00
|
|
|
mach = pdev->dev.platform_data;
|
2018-11-02 05:34:49 +08:00
|
|
|
if (!mach)
|
2018-08-23 04:24:59 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2020-07-14 21:28:04 +08:00
|
|
|
snd_soc_card_set_drvdata(&hda_soc_card, ctx);
|
|
|
|
|
2018-11-02 05:34:49 +08:00
|
|
|
ret = skl_hda_fill_card_info(&mach->mach_params);
|
2018-08-23 04:24:59 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev, "Unsupported HDAudio/iDisp configuration found\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->pcm_count = hda_soc_card.num_links;
|
|
|
|
ctx->dai_index = 1; /* hdmi codec dai name starts from index 1 */
|
2018-11-02 05:34:49 +08:00
|
|
|
ctx->platform_name = mach->mach_params.platform;
|
2019-10-29 21:40:11 +08:00
|
|
|
ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
|
2018-08-23 04:24:59 +08:00
|
|
|
|
|
|
|
hda_soc_card.dev = &pdev->dev;
|
|
|
|
|
2019-12-05 05:15:44 +08:00
|
|
|
if (mach->mach_params.dmic_num > 0) {
|
|
|
|
snprintf(hda_soc_components, sizeof(hda_soc_components),
|
|
|
|
"cfg-dmics:%d", mach->mach_params.dmic_num);
|
|
|
|
hda_soc_card.components = hda_soc_components;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:58:16 +08:00
|
|
|
ret = devm_snd_soc_register_card(&pdev->dev, &hda_soc_card);
|
|
|
|
if (!ret)
|
|
|
|
skl_set_hda_codec_autosuspend_delay(&hda_soc_card);
|
|
|
|
|
|
|
|
return ret;
|
2018-08-23 04:24:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver skl_hda_audio = {
|
|
|
|
.probe = skl_hda_audio_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "skl_hda_dsp_generic",
|
|
|
|
.pm = &snd_soc_pm_ops,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(skl_hda_audio)
|
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_DESCRIPTION("SKL/KBL/BXT/APL HDA Generic Machine driver");
|
|
|
|
MODULE_AUTHOR("Rakesh Ughreja <rakesh.a.ughreja@intel.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_ALIAS("platform:skl_hda_dsp_generic");
|
2021-05-06 00:36:57 +08:00
|
|
|
MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
|