xref: /linux/sound/soc/intel/boards/skl_hda_dsp_generic.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1e149ca29SPierre-Louis Bossart // SPDX-License-Identifier: GPL-2.0-only
27c33b5f1SRakesh Ughreja // Copyright(c) 2015-18 Intel Corporation.
37c33b5f1SRakesh Ughreja 
47c33b5f1SRakesh Ughreja /*
57c33b5f1SRakesh Ughreja  * Machine Driver for SKL+ platforms with DSP and iDisp, HDA Codecs
67c33b5f1SRakesh Ughreja  */
77c33b5f1SRakesh Ughreja 
87c33b5f1SRakesh Ughreja #include <linux/module.h>
97c33b5f1SRakesh Ughreja #include <linux/platform_device.h>
107c33b5f1SRakesh Ughreja #include <sound/core.h>
11*b28b23deSBrent Lu #include <sound/hda_codec.h>
127c33b5f1SRakesh Ughreja #include <sound/jack.h>
137c33b5f1SRakesh Ughreja #include <sound/pcm.h>
147c33b5f1SRakesh Ughreja #include <sound/pcm_params.h>
157c33b5f1SRakesh Ughreja #include <sound/soc.h>
16842bb513SPierre-Louis Bossart #include <sound/soc-acpi.h>
17*b28b23deSBrent Lu #include "../../codecs/hdac_hda.h"
18*b28b23deSBrent Lu #include "../../sof/intel/hda.h"
19*b28b23deSBrent Lu #include "sof_board_helpers.h"
207c33b5f1SRakesh Ughreja 
skl_hda_card_late_probe(struct snd_soc_card * card)217c33b5f1SRakesh Ughreja static int skl_hda_card_late_probe(struct snd_soc_card *card)
227c33b5f1SRakesh Ughreja {
23*b28b23deSBrent Lu 	return sof_intel_board_card_late_probe(card);
247c33b5f1SRakesh Ughreja }
257c33b5f1SRakesh Ughreja 
263a24f135SHui Wang #define HDA_CODEC_AUTOSUSPEND_DELAY_MS 1000
273a24f135SHui Wang 
skl_set_hda_codec_autosuspend_delay(struct snd_soc_card * card)283a24f135SHui Wang static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card)
293a24f135SHui Wang {
305bf73b1bSKai Vehmanen 	struct snd_soc_pcm_runtime *rtd;
313a24f135SHui Wang 	struct hdac_hda_priv *hda_pvt;
325bf73b1bSKai Vehmanen 	struct snd_soc_dai *dai;
333a24f135SHui Wang 
345bf73b1bSKai Vehmanen 	for_each_card_rtds(card, rtd) {
355610921aSMateusz Gorski 		if (!strstr(rtd->dai_link->codecs->name, "ehdaudio0D0"))
365bf73b1bSKai Vehmanen 			continue;
37a2c1125eSKuninori Morimoto 		dai = snd_soc_rtd_to_codec(rtd, 0);
385bf73b1bSKai Vehmanen 		hda_pvt = snd_soc_component_get_drvdata(dai->component);
395bf73b1bSKai Vehmanen 		if (hda_pvt) {
403a24f135SHui Wang 			/*
413a24f135SHui Wang 			 * all codecs are on the same bus, so it's sufficient
425bf73b1bSKai Vehmanen 			 * to look up only the first one
433a24f135SHui Wang 			 */
443fd63658SCezary Rojewski 			snd_hda_set_power_save(hda_pvt->codec->bus,
453a24f135SHui Wang 					       HDA_CODEC_AUTOSUSPEND_DELAY_MS);
465bf73b1bSKai Vehmanen 			break;
475bf73b1bSKai Vehmanen 		}
485bf73b1bSKai Vehmanen 	}
493a24f135SHui Wang }
503a24f135SHui Wang 
51*b28b23deSBrent Lu #define IDISP_HDMI_BE_ID	1
52*b28b23deSBrent Lu #define HDA_BE_ID		4
53*b28b23deSBrent Lu #define DMIC01_BE_ID		6
54*b28b23deSBrent Lu #define DMIC16K_BE_ID		7
55*b28b23deSBrent Lu #define BT_OFFLOAD_BE_ID	8
56*b28b23deSBrent Lu 
57*b28b23deSBrent Lu #define HDA_LINK_ORDER	SOF_LINK_ORDER(SOF_LINK_IDISP_HDMI,  \
58*b28b23deSBrent Lu 				       SOF_LINK_HDA,        \
59*b28b23deSBrent Lu 				       SOF_LINK_DMIC01,     \
60*b28b23deSBrent Lu 				       SOF_LINK_DMIC16K,    \
61*b28b23deSBrent Lu 				       SOF_LINK_BT_OFFLOAD, \
62*b28b23deSBrent Lu 				       SOF_LINK_NONE,       \
63*b28b23deSBrent Lu 				       SOF_LINK_NONE)
64*b28b23deSBrent Lu 
65*b28b23deSBrent Lu #define HDA_LINK_IDS	SOF_LINK_ORDER(IDISP_HDMI_BE_ID,  \
66*b28b23deSBrent Lu 				       HDA_BE_ID,        \
67*b28b23deSBrent Lu 				       DMIC01_BE_ID,     \
68*b28b23deSBrent Lu 				       DMIC16K_BE_ID,    \
69*b28b23deSBrent Lu 				       BT_OFFLOAD_BE_ID, \
70*b28b23deSBrent Lu 				       0,                \
71*b28b23deSBrent Lu 				       0)
72*b28b23deSBrent Lu 
73*b28b23deSBrent Lu static unsigned long
skl_hda_get_board_quirk(struct snd_soc_acpi_mach_params * mach_params)74*b28b23deSBrent Lu skl_hda_get_board_quirk(struct snd_soc_acpi_mach_params *mach_params)
75*b28b23deSBrent Lu {
76*b28b23deSBrent Lu 	unsigned long board_quirk = 0;
77*b28b23deSBrent Lu 	int ssp_bt;
78*b28b23deSBrent Lu 
79*b28b23deSBrent Lu 	if (hweight_long(mach_params->bt_link_mask) == 1) {
80*b28b23deSBrent Lu 		ssp_bt = fls(mach_params->bt_link_mask) - 1;
81*b28b23deSBrent Lu 		board_quirk |= SOF_SSP_PORT_BT_OFFLOAD(ssp_bt) |
82*b28b23deSBrent Lu 				SOF_BT_OFFLOAD_PRESENT;
83*b28b23deSBrent Lu 	}
84*b28b23deSBrent Lu 
85*b28b23deSBrent Lu 	return board_quirk;
86*b28b23deSBrent Lu }
87*b28b23deSBrent Lu 
skl_hda_audio_probe(struct platform_device * pdev)887c33b5f1SRakesh Ughreja static int skl_hda_audio_probe(struct platform_device *pdev)
897c33b5f1SRakesh Ughreja {
90a2a0312aSBrent Lu 	struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
91*b28b23deSBrent Lu 	struct sof_card_private *ctx;
9233e59e50SPeter Ujfalusi 	struct snd_soc_card *card;
93*b28b23deSBrent Lu 	unsigned long board_quirk = skl_hda_get_board_quirk(&mach->mach_params);
947c33b5f1SRakesh Ughreja 	int ret;
957c33b5f1SRakesh Ughreja 
96*b28b23deSBrent Lu 	card = devm_kzalloc(&pdev->dev, sizeof(struct snd_soc_card), GFP_KERNEL);
97*b28b23deSBrent Lu 	if (!card)
987c33b5f1SRakesh Ughreja 		return -ENOMEM;
997c33b5f1SRakesh Ughreja 
100813751eaSChen Ni 	card->name = "hda-dsp";
101813751eaSChen Ni 	card->owner = THIS_MODULE;
102813751eaSChen Ni 	card->fully_routed = true;
103813751eaSChen Ni 	card->late_probe = skl_hda_card_late_probe;
104ffc6d45dSKai Vehmanen 
105*b28b23deSBrent Lu 	dev_dbg(&pdev->dev, "board_quirk = %lx\n", board_quirk);
106*b28b23deSBrent Lu 
107*b28b23deSBrent Lu 	/* initialize ctx with board quirk */
108*b28b23deSBrent Lu 	ctx = sof_intel_board_get_ctx(&pdev->dev, board_quirk);
109*b28b23deSBrent Lu 	if (!ctx)
110*b28b23deSBrent Lu 		return -ENOMEM;
111*b28b23deSBrent Lu 
112*b28b23deSBrent Lu 	if (HDA_EXT_CODEC(mach->mach_params.codec_mask))
113*b28b23deSBrent Lu 		ctx->hda_codec_present = true;
11433e59e50SPeter Ujfalusi 
115690640efSBrent Lu 	if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
116690640efSBrent Lu 		ctx->hdmi.idisp_codec = true;
117690640efSBrent Lu 
118*b28b23deSBrent Lu 	ctx->link_order_overwrite = HDA_LINK_ORDER;
119*b28b23deSBrent Lu 	ctx->link_id_overwrite = HDA_LINK_IDS;
1200752ba42SBrent Lu 
121*b28b23deSBrent Lu 	/* update dai_link */
122*b28b23deSBrent Lu 	ret = sof_intel_board_set_dai_link(&pdev->dev, card, ctx);
123*b28b23deSBrent Lu 	if (ret)
1247c33b5f1SRakesh Ughreja 		return ret;
1257c33b5f1SRakesh Ughreja 
12633e59e50SPeter Ujfalusi 	card->dev = &pdev->dev;
1270cb3b7fdSCezary Rojewski 	if (!snd_soc_acpi_sof_parent(&pdev->dev))
12833e59e50SPeter Ujfalusi 		card->disable_route_checks = true;
1297c33b5f1SRakesh Ughreja 
1308cd9956fSJaroslav Kysela 	if (mach->mach_params.dmic_num > 0) {
13169d0f88bSPeter Ujfalusi 		card->components = devm_kasprintf(card->dev, GFP_KERNEL,
13269d0f88bSPeter Ujfalusi 						  "cfg-dmics:%d",
13369d0f88bSPeter Ujfalusi 						  mach->mach_params.dmic_num);
13469d0f88bSPeter Ujfalusi 		if (!card->components)
13569d0f88bSPeter Ujfalusi 			return -ENOMEM;
1368cd9956fSJaroslav Kysela 	}
1378cd9956fSJaroslav Kysela 
138*b28b23deSBrent Lu 	ret = snd_soc_fixup_dai_links_platform_name(card,
139*b28b23deSBrent Lu 						    mach->mach_params.platform);
140*b28b23deSBrent Lu 	if (ret)
141*b28b23deSBrent Lu 		return ret;
142*b28b23deSBrent Lu 
143*b28b23deSBrent Lu 	snd_soc_card_set_drvdata(card, ctx);
144*b28b23deSBrent Lu 
14533e59e50SPeter Ujfalusi 	ret = devm_snd_soc_register_card(&pdev->dev, card);
1463a24f135SHui Wang 	if (!ret)
14733e59e50SPeter Ujfalusi 		skl_set_hda_codec_autosuspend_delay(card);
1483a24f135SHui Wang 
1493a24f135SHui Wang 	return ret;
1507c33b5f1SRakesh Ughreja }
1517c33b5f1SRakesh Ughreja 
1527c33b5f1SRakesh Ughreja static struct platform_driver skl_hda_audio = {
1537c33b5f1SRakesh Ughreja 	.probe = skl_hda_audio_probe,
1547c33b5f1SRakesh Ughreja 	.driver = {
1557c33b5f1SRakesh Ughreja 		.name = "skl_hda_dsp_generic",
1567c33b5f1SRakesh Ughreja 		.pm = &snd_soc_pm_ops,
1577c33b5f1SRakesh Ughreja 	},
1587c33b5f1SRakesh Ughreja };
1597c33b5f1SRakesh Ughreja 
1607c33b5f1SRakesh Ughreja module_platform_driver(skl_hda_audio)
1617c33b5f1SRakesh Ughreja 
1627c33b5f1SRakesh Ughreja /* Module information */
1637c33b5f1SRakesh Ughreja MODULE_DESCRIPTION("SKL/KBL/BXT/APL HDA Generic Machine driver");
1647c33b5f1SRakesh Ughreja MODULE_AUTHOR("Rakesh Ughreja <rakesh.a.ughreja@intel.com>");
1657c33b5f1SRakesh Ughreja MODULE_LICENSE("GPL v2");
1667c33b5f1SRakesh Ughreja MODULE_ALIAS("platform:skl_hda_dsp_generic");
167*b28b23deSBrent Lu MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_BOARD_HELPERS);
168