Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright(c) 2015-18 Intel Corporation.
  3
  4/*
  5 * Machine Driver for SKL+ platforms with DSP and iDisp, HDA Codecs
  6 */
  7
  8#include <linux/module.h>
  9#include <linux/platform_device.h>
 10#include <sound/core.h>
 11#include <sound/hda_codec.h>
 12#include <sound/jack.h>
 13#include <sound/pcm.h>
 14#include <sound/pcm_params.h>
 15#include <sound/soc.h>
 16#include <sound/soc-acpi.h>
 17#include "../../codecs/hdac_hda.h"
 18#include "../../sof/intel/hda.h"
 19#include "sof_board_helpers.h"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 20
 21static int skl_hda_card_late_probe(struct snd_soc_card *card)
 22{
 23	return sof_intel_board_card_late_probe(card);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 24}
 25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 26#define HDA_CODEC_AUTOSUSPEND_DELAY_MS 1000
 27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 28static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card)
 29{
 30	struct snd_soc_pcm_runtime *rtd;
 31	struct hdac_hda_priv *hda_pvt;
 32	struct snd_soc_dai *dai;
 33
 34	for_each_card_rtds(card, rtd) {
 35		if (!strstr(rtd->dai_link->codecs->name, "ehdaudio0D0"))
 36			continue;
 37		dai = snd_soc_rtd_to_codec(rtd, 0);
 38		hda_pvt = snd_soc_component_get_drvdata(dai->component);
 39		if (hda_pvt) {
 40			/*
 41			 * all codecs are on the same bus, so it's sufficient
 42			 * to look up only the first one
 43			 */
 44			snd_hda_set_power_save(hda_pvt->codec->bus,
 45					       HDA_CODEC_AUTOSUSPEND_DELAY_MS);
 46			break;
 47		}
 48	}
 49}
 50
 51#define IDISP_HDMI_BE_ID	1
 52#define HDA_BE_ID		4
 53#define DMIC01_BE_ID		6
 54#define DMIC16K_BE_ID		7
 55#define BT_OFFLOAD_BE_ID	8
 56
 57#define HDA_LINK_ORDER	SOF_LINK_ORDER(SOF_LINK_IDISP_HDMI,  \
 58				       SOF_LINK_HDA,        \
 59				       SOF_LINK_DMIC01,     \
 60				       SOF_LINK_DMIC16K,    \
 61				       SOF_LINK_BT_OFFLOAD, \
 62				       SOF_LINK_NONE,       \
 63				       SOF_LINK_NONE)
 64
 65#define HDA_LINK_IDS	SOF_LINK_ORDER(IDISP_HDMI_BE_ID,  \
 66				       HDA_BE_ID,        \
 67				       DMIC01_BE_ID,     \
 68				       DMIC16K_BE_ID,    \
 69				       BT_OFFLOAD_BE_ID, \
 70				       0,                \
 71				       0)
 72
 73static unsigned long
 74skl_hda_get_board_quirk(struct snd_soc_acpi_mach_params *mach_params)
 75{
 76	unsigned long board_quirk = 0;
 77	int ssp_bt;
 78
 79	if (hweight_long(mach_params->bt_link_mask) == 1) {
 80		ssp_bt = fls(mach_params->bt_link_mask) - 1;
 81		board_quirk |= SOF_SSP_PORT_BT_OFFLOAD(ssp_bt) |
 82				SOF_BT_OFFLOAD_PRESENT;
 83	}
 84
 85	return board_quirk;
 86}
 87
 88static int skl_hda_audio_probe(struct platform_device *pdev)
 89{
 90	struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
 91	struct sof_card_private *ctx;
 92	struct snd_soc_card *card;
 93	unsigned long board_quirk = skl_hda_get_board_quirk(&mach->mach_params);
 94	int ret;
 95
 96	card = devm_kzalloc(&pdev->dev, sizeof(struct snd_soc_card), GFP_KERNEL);
 97	if (!card)
 98		return -ENOMEM;
 99
100	card->name = "hda-dsp";
101	card->owner = THIS_MODULE;
102	card->fully_routed = true;
103	card->late_probe = skl_hda_card_late_probe;
104
105	dev_dbg(&pdev->dev, "board_quirk = %lx\n", board_quirk);
106
107	/* initialize ctx with board quirk */
108	ctx = sof_intel_board_get_ctx(&pdev->dev, board_quirk);
109	if (!ctx)
110		return -ENOMEM;
111
112	if (HDA_EXT_CODEC(mach->mach_params.codec_mask))
113		ctx->hda_codec_present = true;
114
115	if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
116		ctx->hdmi.idisp_codec = true;
 
117
118	ctx->link_order_overwrite = HDA_LINK_ORDER;
119	ctx->link_id_overwrite = HDA_LINK_IDS;
120
121	/* update dai_link */
122	ret = sof_intel_board_set_dai_link(&pdev->dev, card, ctx);
123	if (ret)
124		return ret;
 
 
 
 
 
 
125
126	card->dev = &pdev->dev;
127	if (!snd_soc_acpi_sof_parent(&pdev->dev))
128		card->disable_route_checks = true;
129
130	if (mach->mach_params.dmic_num > 0) {
131		card->components = devm_kasprintf(card->dev, GFP_KERNEL,
132						  "cfg-dmics:%d",
133						  mach->mach_params.dmic_num);
134		if (!card->components)
135			return -ENOMEM;
136	}
137
138	ret = snd_soc_fixup_dai_links_platform_name(card,
139						    mach->mach_params.platform);
140	if (ret)
141		return ret;
142
143	snd_soc_card_set_drvdata(card, ctx);
144
145	ret = devm_snd_soc_register_card(&pdev->dev, card);
146	if (!ret)
147		skl_set_hda_codec_autosuspend_delay(card);
148
149	return ret;
150}
151
152static struct platform_driver skl_hda_audio = {
153	.probe = skl_hda_audio_probe,
154	.driver = {
155		.name = "skl_hda_dsp_generic",
156		.pm = &snd_soc_pm_ops,
157	},
158};
159
160module_platform_driver(skl_hda_audio)
161
162/* Module information */
163MODULE_DESCRIPTION("SKL/KBL/BXT/APL HDA Generic Machine driver");
164MODULE_AUTHOR("Rakesh Ughreja <rakesh.a.ughreja@intel.com>");
165MODULE_LICENSE("GPL v2");
166MODULE_ALIAS("platform:skl_hda_dsp_generic");
167MODULE_IMPORT_NS("SND_SOC_INTEL_SOF_BOARD_HELPERS");
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright(c) 2015-18 Intel Corporation.
  3
  4/*
  5 * Machine Driver for SKL+ platforms with DSP and iDisp, HDA Codecs
  6 */
  7
  8#include <linux/module.h>
  9#include <linux/platform_device.h>
 10#include <sound/core.h>
 
 11#include <sound/jack.h>
 12#include <sound/pcm.h>
 13#include <sound/pcm_params.h>
 14#include <sound/soc.h>
 15#include <sound/soc-acpi.h>
 16#include "../../codecs/hdac_hdmi.h"
 17#include "skl_hda_dsp_common.h"
 18
 19static const struct snd_soc_dapm_widget skl_hda_widgets[] = {
 20	SND_SOC_DAPM_HP("Analog Out", NULL),
 21	SND_SOC_DAPM_MIC("Analog In", NULL),
 22	SND_SOC_DAPM_HP("Alt Analog Out", NULL),
 23	SND_SOC_DAPM_MIC("Alt Analog In", NULL),
 24	SND_SOC_DAPM_SPK("Digital Out", NULL),
 25	SND_SOC_DAPM_MIC("Digital In", NULL),
 26	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
 27};
 28
 29static const struct snd_soc_dapm_route skl_hda_map[] = {
 30	{ "hifi3", NULL, "iDisp3 Tx"},
 31	{ "iDisp3 Tx", NULL, "iDisp3_out"},
 32	{ "hifi2", NULL, "iDisp2 Tx"},
 33	{ "iDisp2 Tx", NULL, "iDisp2_out"},
 34	{ "hifi1", NULL, "iDisp1 Tx"},
 35	{ "iDisp1 Tx", NULL, "iDisp1_out"},
 36
 37	{ "Analog Out", NULL, "Codec Output Pin1" },
 38	{ "Digital Out", NULL, "Codec Output Pin2" },
 39	{ "Alt Analog Out", NULL, "Codec Output Pin3" },
 40
 41	{ "Codec Input Pin1", NULL, "Analog In" },
 42	{ "Codec Input Pin2", NULL, "Digital In" },
 43	{ "Codec Input Pin3", NULL, "Alt Analog In" },
 44
 45	/* digital mics */
 46	{"DMic", NULL, "SoC DMIC"},
 47
 48	/* CODEC BE connections */
 49	{ "Analog Codec Playback", NULL, "Analog CPU Playback" },
 50	{ "Analog CPU Playback", NULL, "codec0_out" },
 51	{ "Digital Codec Playback", NULL, "Digital CPU Playback" },
 52	{ "Digital CPU Playback", NULL, "codec1_out" },
 53	{ "Alt Analog Codec Playback", NULL, "Alt Analog CPU Playback" },
 54	{ "Alt Analog CPU Playback", NULL, "codec2_out" },
 55
 56	{ "codec0_in", NULL, "Analog CPU Capture" },
 57	{ "Analog CPU Capture", NULL, "Analog Codec Capture" },
 58	{ "codec1_in", NULL, "Digital CPU Capture" },
 59	{ "Digital CPU Capture", NULL, "Digital Codec Capture" },
 60	{ "codec2_in", NULL, "Alt Analog CPU Capture" },
 61	{ "Alt Analog CPU Capture", NULL, "Alt Analog Codec Capture" },
 62};
 63
 64static int skl_hda_card_late_probe(struct snd_soc_card *card)
 65{
 66	return skl_hda_hdmi_jack_init(card);
 67}
 68
 69static int
 70skl_hda_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *link)
 71{
 72	struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
 73	int ret = 0;
 74
 75	dev_dbg(card->dev, "dai link name - %s\n", link->name);
 76	link->platforms->name = ctx->platform_name;
 77	link->nonatomic = 1;
 78
 79	if (!ctx->idisp_codec)
 80		return 0;
 81
 82	if (strstr(link->name, "HDMI")) {
 83		ret = skl_hda_hdmi_add_pcm(card, ctx->pcm_count);
 84
 85		if (ret < 0)
 86			return ret;
 87
 88		ctx->dai_index++;
 89	}
 90
 91	ctx->pcm_count++;
 92	return ret;
 93}
 94
 95static struct snd_soc_card hda_soc_card = {
 96	.name = "hda-dsp",
 97	.owner = THIS_MODULE,
 98	.dai_link = skl_hda_be_dai_links,
 99	.dapm_widgets = skl_hda_widgets,
100	.dapm_routes = skl_hda_map,
101	.add_dai_link = skl_hda_add_dai_link,
102	.fully_routed = true,
103	.late_probe = skl_hda_card_late_probe,
104};
105
106static char hda_soc_components[30];
107
108#define IDISP_DAI_COUNT		3
109#define HDAC_DAI_COUNT		2
110#define DMIC_DAI_COUNT		2
111
112/* there are two routes per iDisp output */
113#define IDISP_ROUTE_COUNT	(IDISP_DAI_COUNT * 2)
114#define IDISP_CODEC_MASK	0x4
115
116#define HDA_CODEC_AUTOSUSPEND_DELAY_MS 1000
117
118static int skl_hda_fill_card_info(struct snd_soc_acpi_mach_params *mach_params)
119{
120	struct snd_soc_card *card = &hda_soc_card;
121	struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
122	struct snd_soc_dai_link *dai_link;
123	u32 codec_count, codec_mask;
124	int i, num_links, num_route;
125
126	codec_mask = mach_params->codec_mask;
127	codec_count = hweight_long(codec_mask);
128	ctx->idisp_codec = !!(codec_mask & IDISP_CODEC_MASK);
129
130	if (!codec_count || codec_count > 2 ||
131	    (codec_count == 2 && !ctx->idisp_codec))
132		return -EINVAL;
133
134	if (codec_mask == IDISP_CODEC_MASK) {
135		/* topology with iDisp as the only HDA codec */
136		num_links = IDISP_DAI_COUNT + DMIC_DAI_COUNT;
137		num_route = IDISP_ROUTE_COUNT;
138
139		/*
140		 * rearrange the dai link array and make the
141		 * dmic dai links follow idsp dai links for only
142		 * num_links of dai links need to be registered
143		 * to ASoC.
144		 */
145		for (i = 0; i < DMIC_DAI_COUNT; i++) {
146			skl_hda_be_dai_links[IDISP_DAI_COUNT + i] =
147				skl_hda_be_dai_links[IDISP_DAI_COUNT +
148					HDAC_DAI_COUNT + i];
149		}
150	} else {
151		/* topology with external and iDisp HDA codecs */
152		num_links = ARRAY_SIZE(skl_hda_be_dai_links);
153		num_route = ARRAY_SIZE(skl_hda_map);
154		card->dapm_widgets = skl_hda_widgets;
155		card->num_dapm_widgets = ARRAY_SIZE(skl_hda_widgets);
156		if (!ctx->idisp_codec) {
157			card->dapm_routes = &skl_hda_map[IDISP_ROUTE_COUNT];
158			num_route -= IDISP_ROUTE_COUNT;
159			for (i = 0; i < IDISP_DAI_COUNT; i++) {
160				skl_hda_be_dai_links[i].codecs = &snd_soc_dummy_dlc;
161				skl_hda_be_dai_links[i].num_codecs = 1;
162			}
163		}
164	}
165
166	card->num_links = num_links;
167	card->num_dapm_routes = num_route;
168
169	for_each_card_prelinks(card, i, dai_link)
170		dai_link->platforms->name = mach_params->platform;
171
172	return 0;
173}
174
175static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card)
176{
177	struct snd_soc_pcm_runtime *rtd;
178	struct hdac_hda_priv *hda_pvt;
179	struct snd_soc_dai *dai;
180
181	for_each_card_rtds(card, rtd) {
182		if (!strstr(rtd->dai_link->codecs->name, "ehdaudio0D0"))
183			continue;
184		dai = snd_soc_rtd_to_codec(rtd, 0);
185		hda_pvt = snd_soc_component_get_drvdata(dai->component);
186		if (hda_pvt) {
187			/*
188			 * all codecs are on the same bus, so it's sufficient
189			 * to look up only the first one
190			 */
191			snd_hda_set_power_save(hda_pvt->codec->bus,
192					       HDA_CODEC_AUTOSUSPEND_DELAY_MS);
193			break;
194		}
195	}
196}
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198static int skl_hda_audio_probe(struct platform_device *pdev)
199{
200	struct snd_soc_acpi_mach *mach;
201	struct skl_hda_private *ctx;
 
 
202	int ret;
203
204	dev_dbg(&pdev->dev, "entry\n");
 
 
 
 
 
 
 
 
 
205
206	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
 
207	if (!ctx)
208		return -ENOMEM;
209
210	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
 
211
212	mach = pdev->dev.platform_data;
213	if (!mach)
214		return -EINVAL;
215
216	snd_soc_card_set_drvdata(&hda_soc_card, ctx);
 
217
218	ret = skl_hda_fill_card_info(&mach->mach_params);
219	if (ret < 0) {
220		dev_err(&pdev->dev, "Unsupported HDAudio/iDisp configuration found\n");
221		return ret;
222	}
223
224	ctx->pcm_count = hda_soc_card.num_links;
225	ctx->dai_index = 1; /* hdmi codec dai name starts from index 1 */
226	ctx->platform_name = mach->mach_params.platform;
227	ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
228
229	hda_soc_card.dev = &pdev->dev;
 
 
230
231	if (mach->mach_params.dmic_num > 0) {
232		snprintf(hda_soc_components, sizeof(hda_soc_components),
233				"cfg-dmics:%d", mach->mach_params.dmic_num);
234		hda_soc_card.components = hda_soc_components;
 
 
235	}
236
237	ret = devm_snd_soc_register_card(&pdev->dev, &hda_soc_card);
 
 
 
 
 
 
 
238	if (!ret)
239		skl_set_hda_codec_autosuspend_delay(&hda_soc_card);
240
241	return ret;
242}
243
244static struct platform_driver skl_hda_audio = {
245	.probe = skl_hda_audio_probe,
246	.driver = {
247		.name = "skl_hda_dsp_generic",
248		.pm = &snd_soc_pm_ops,
249	},
250};
251
252module_platform_driver(skl_hda_audio)
253
254/* Module information */
255MODULE_DESCRIPTION("SKL/KBL/BXT/APL HDA Generic Machine driver");
256MODULE_AUTHOR("Rakesh Ughreja <rakesh.a.ughreja@intel.com>");
257MODULE_LICENSE("GPL v2");
258MODULE_ALIAS("platform:skl_hda_dsp_generic");
259MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);