xref: /linux/sound/soc/amd/acp/acp-sdw-legacy-mach.c (revision 4982d3552a3bf94de503acf93433277d08421de6)
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2024 Advanced Micro Devices, Inc.
3 
4 /*
5  *  acp-sdw-legacy-mach - ASoC legacy Machine driver for AMD SoundWire platforms
6  */
7 
8 #include <linux/bitmap.h>
9 #include <linux/device.h>
10 #include <linux/dmi.h>
11 #include <linux/module.h>
12 #include <linux/soundwire/sdw.h>
13 #include <linux/soundwire/sdw_type.h>
14 #include <sound/soc.h>
15 #include <sound/soc-acpi.h>
16 #include "soc_amd_sdw_common.h"
17 #include "../../codecs/rt711.h"
18 
19 static unsigned long soc_sdw_quirk = RT711_JD1;
20 static int quirk_override = -1;
21 module_param_named(quirk, quirk_override, int, 0444);
22 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
23 
log_quirks(struct device * dev)24 static void log_quirks(struct device *dev)
25 {
26 	if (SOC_JACK_JDSRC(soc_sdw_quirk))
27 		dev_dbg(dev, "quirk realtek,jack-detect-source %ld\n",
28 			SOC_JACK_JDSRC(soc_sdw_quirk));
29 	if (soc_sdw_quirk & ASOC_SDW_ACP_DMIC)
30 		dev_dbg(dev, "quirk SOC_SDW_ACP_DMIC enabled\n");
31 	if (soc_sdw_quirk & ASOC_SDW_CODEC_SPKR)
32 		dev_dbg(dev, "quirk ASOC_SDW_CODEC_SPKR enabled\n");
33 }
34 
soc_sdw_quirk_cb(const struct dmi_system_id * id)35 static int soc_sdw_quirk_cb(const struct dmi_system_id *id)
36 {
37 	soc_sdw_quirk = (unsigned long)id->driver_data;
38 	return 1;
39 }
40 
41 static const struct dmi_system_id soc_sdw_quirk_table[] = {
42 	{
43 		.callback = soc_sdw_quirk_cb,
44 		.matches = {
45 			DMI_MATCH(DMI_SYS_VENDOR, "AMD"),
46 			DMI_MATCH(DMI_PRODUCT_NAME, "Birman-PHX"),
47 		},
48 		.driver_data = (void *)RT711_JD2,
49 	},
50 	{
51 		.callback = soc_sdw_quirk_cb,
52 		.matches = {
53 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
54 			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0D80"),
55 		},
56 		.driver_data = (void *)(ASOC_SDW_CODEC_SPKR),
57 	},
58 	{
59 		.callback = soc_sdw_quirk_cb,
60 		.matches = {
61 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
62 			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0D81"),
63 		},
64 		.driver_data = (void *)(ASOC_SDW_CODEC_SPKR),
65 	},
66 	{
67 		.callback = soc_sdw_quirk_cb,
68 		.matches = {
69 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
70 			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0D82"),
71 		},
72 		.driver_data = (void *)(ASOC_SDW_CODEC_SPKR),
73 	},
74 	{
75 		.callback = soc_sdw_quirk_cb,
76 		.matches = {
77 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
78 			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0D83"),
79 		},
80 		.driver_data = (void *)(ASOC_SDW_CODEC_SPKR),
81 	},
82 	{
83 		.callback = soc_sdw_quirk_cb,
84 		.matches = {
85 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
86 			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0DD3"),
87 		},
88 		.driver_data = (void *)(ASOC_SDW_CODEC_SPKR),
89 	},
90 	{
91 		.callback = soc_sdw_quirk_cb,
92 		.matches = {
93 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
94 			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0DD4"),
95 		},
96 		.driver_data = (void *)(ASOC_SDW_CODEC_SPKR),
97 	},
98 	{
99 		.callback = soc_sdw_quirk_cb,
100 		.matches = {
101 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
102 			DMI_MATCH(DMI_PRODUCT_SKU, "21YW"),
103 		},
104 		.driver_data = (void *)((ASOC_SDW_CODEC_SPKR) | (ASOC_SDW_ACP_DMIC)),
105 	},
106 	{
107 		.callback = soc_sdw_quirk_cb,
108 		.matches = {
109 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
110 			DMI_MATCH(DMI_PRODUCT_SKU, "21YX"),
111 		},
112 		.driver_data = (void *)((ASOC_SDW_CODEC_SPKR) | (ASOC_SDW_ACP_DMIC)),
113 	},
114 	{
115 		.callback = soc_sdw_quirk_cb,
116 		.matches = { /* Lenovo P16s G5 AMD */
117 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
118 			DMI_MATCH(DMI_PRODUCT_SKU, "21XG"),
119 		},
120 		.driver_data = (void *)(ASOC_SDW_ACP_DMIC),
121 	},
122 	{
123 		.callback = soc_sdw_quirk_cb,
124 		.matches = { /* Lenovo P16s G5 AMD */
125 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
126 			DMI_MATCH(DMI_PRODUCT_SKU, "21XH"),
127 		},
128 		.driver_data = (void *)(ASOC_SDW_ACP_DMIC),
129 	},
130 	{
131 		.callback = soc_sdw_quirk_cb,
132 		.matches = {
133 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."),
134 			DMI_MATCH(DMI_PRODUCT_NAME, "HN7306EA"),
135 		},
136 		.driver_data = (void *)(ASOC_SDW_ACP_DMIC),
137 	},
138 	{}
139 };
140 
141 static const struct snd_soc_ops sdw_ops = {
142 	.startup = asoc_sdw_startup,
143 	.prepare = asoc_sdw_prepare,
144 	.trigger = asoc_sdw_trigger,
145 	.hw_params = asoc_sdw_hw_params,
146 	.hw_free = asoc_sdw_hw_free,
147 	.shutdown = asoc_sdw_shutdown,
148 };
149 
150 static const char * const type_strings[] = {"SimpleJack", "SmartAmp", "SmartMic"};
151 
create_sdw_dailink(struct snd_soc_card * card,struct asoc_sdw_dailink * soc_dai,struct snd_soc_dai_link ** dai_links,int * be_id,struct snd_soc_codec_conf ** codec_conf,struct snd_soc_dai_link_component * sdw_platform_component)152 static int create_sdw_dailink(struct snd_soc_card *card,
153 			      struct asoc_sdw_dailink *soc_dai,
154 			      struct snd_soc_dai_link **dai_links,
155 			      int *be_id, struct snd_soc_codec_conf **codec_conf,
156 			      struct snd_soc_dai_link_component *sdw_platform_component)
157 {
158 	struct device *dev = card->dev;
159 	struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
160 	struct amd_mc_ctx *amd_ctx = (struct amd_mc_ctx *)ctx->private;
161 	struct asoc_sdw_endpoint *soc_end;
162 	int cpu_pin_id;
163 	int stream;
164 	int ret;
165 
166 	list_for_each_entry(soc_end, &soc_dai->endpoints, list) {
167 		if (soc_end->name_prefix) {
168 			(*codec_conf)->dlc.name = soc_end->codec_name;
169 			(*codec_conf)->name_prefix = soc_end->name_prefix;
170 			(*codec_conf)++;
171 		}
172 
173 		if (soc_end->include_sidecar) {
174 			ret = soc_end->codec_info->add_sidecar(card, dai_links, codec_conf);
175 			if (ret)
176 				return ret;
177 		}
178 	}
179 
180 	for_each_pcm_streams(stream) {
181 		static const char * const sdw_stream_name[] = {
182 			"SDW%d-PIN%d-PLAYBACK",
183 			"SDW%d-PIN%d-CAPTURE",
184 			"SDW%d-PIN%d-PLAYBACK-%s",
185 			"SDW%d-PIN%d-CAPTURE-%s",
186 		};
187 		struct snd_soc_dai_link_ch_map *codec_maps;
188 		struct snd_soc_dai_link_component *codecs;
189 		struct snd_soc_dai_link_component *cpus;
190 		int num_cpus = hweight32(soc_dai->link_mask[stream]);
191 		int num_codecs = soc_dai->num_devs[stream];
192 		int playback, capture;
193 		int j = 0;
194 		char *name;
195 
196 		if (!soc_dai->num_devs[stream])
197 			continue;
198 
199 		soc_end = list_first_entry(&soc_dai->endpoints,
200 					   struct asoc_sdw_endpoint, list);
201 
202 		*be_id = soc_end->dai_info->dailink[stream];
203 		if (*be_id < 0) {
204 			dev_err(dev, "Invalid dailink id %d\n", *be_id);
205 			return -EINVAL;
206 		}
207 
208 		if (!soc_end->link_mask) {
209 			dev_err(dev, "invalid zero link_mask\n");
210 			return -EINVAL;
211 		}
212 		if ((ffs(soc_end->link_mask) - 1) >= amd_ctx->max_sdw_links) {
213 			dev_err(dev, "link_id %d exceeds max_sdw_links %d\n",
214 				ffs(soc_end->link_mask) - 1, amd_ctx->max_sdw_links);
215 			return -EINVAL;
216 		}
217 
218 		switch (amd_ctx->acp_rev) {
219 		case ACP63_PCI_REV:
220 			ret = get_acp63_cpu_pin_id(ffs(soc_end->link_mask) - 1,
221 						   *be_id, &cpu_pin_id, dev);
222 			if (ret)
223 				return ret;
224 			break;
225 		case ACP70_PCI_REV:
226 		case ACP71_PCI_REV:
227 		case ACP72_PCI_REV:
228 			ret = get_acp70_cpu_pin_id(ffs(soc_end->link_mask) - 1,
229 						   *be_id, &cpu_pin_id, dev);
230 			if (ret)
231 				return ret;
232 			break;
233 		default:
234 			return -EINVAL;
235 		}
236 		/* create stream name according to first link id */
237 		if (ctx->append_dai_type) {
238 			name = devm_kasprintf(dev, GFP_KERNEL,
239 					      sdw_stream_name[stream + 2],
240 					      ffs(soc_end->link_mask) - 1,
241 					      cpu_pin_id,
242 					      type_strings[soc_end->dai_info->dai_type]);
243 		} else {
244 			name = devm_kasprintf(dev, GFP_KERNEL,
245 					      sdw_stream_name[stream],
246 					      ffs(soc_end->link_mask) - 1,
247 					      cpu_pin_id);
248 		}
249 		if (!name)
250 			return -ENOMEM;
251 
252 		cpus = devm_kcalloc(dev, num_cpus, sizeof(*cpus), GFP_KERNEL);
253 		if (!cpus)
254 			return -ENOMEM;
255 
256 		codecs = devm_kcalloc(dev, num_codecs, sizeof(*codecs), GFP_KERNEL);
257 		if (!codecs)
258 			return -ENOMEM;
259 
260 		codec_maps = devm_kcalloc(dev, num_codecs, sizeof(*codec_maps), GFP_KERNEL);
261 		if (!codec_maps)
262 			return -ENOMEM;
263 
264 		list_for_each_entry(soc_end, &soc_dai->endpoints, list) {
265 			if (!soc_end->dai_info->direction[stream])
266 				continue;
267 
268 			int link_num = ffs(soc_end->link_mask) - 1;
269 
270 			cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
271 							"SDW%d Pin%d",
272 							link_num, cpu_pin_id);
273 			if (!cpus->dai_name)
274 				return -ENOMEM;
275 			dev_dbg(dev, "cpu->dai_name:%s\n", cpus->dai_name);
276 
277 			codec_maps[j].cpu = 0;
278 			codec_maps[j].codec = j;
279 
280 			codecs[j].name = soc_end->codec_name;
281 			codecs[j].dai_name = soc_end->dai_info->dai_name;
282 			j++;
283 		}
284 
285 		WARN_ON(j != num_codecs);
286 
287 		playback = (stream == SNDRV_PCM_STREAM_PLAYBACK);
288 		capture = (stream == SNDRV_PCM_STREAM_CAPTURE);
289 
290 		asoc_sdw_init_dai_link(dev, *dai_links, be_id, name, playback, capture,
291 				       cpus, num_cpus, sdw_platform_component,
292 				       1, codecs, num_codecs,
293 				       0, asoc_sdw_rtd_init, &sdw_ops);
294 		/*
295 		 * SoundWire DAILINKs use 'stream' functions and Bank Switch operations
296 		 * based on wait_for_completion(), tag them as 'nonatomic'.
297 		 */
298 		(*dai_links)->nonatomic = true;
299 		(*dai_links)->ch_maps = codec_maps;
300 
301 		list_for_each_entry(soc_end, &soc_dai->endpoints, list) {
302 			if (soc_end->dai_info->init)
303 				soc_end->dai_info->init(card, *dai_links,
304 							soc_end->codec_info,
305 							playback);
306 		}
307 
308 		(*dai_links)++;
309 	}
310 
311 	return 0;
312 }
313 
create_sdw_dailinks(struct snd_soc_card * card,struct snd_soc_dai_link ** dai_links,int * be_id,struct asoc_sdw_dailink * soc_dais,int num_dais,struct snd_soc_codec_conf ** codec_conf)314 static int create_sdw_dailinks(struct snd_soc_card *card,
315 			       struct snd_soc_dai_link **dai_links, int *be_id,
316 			       struct asoc_sdw_dailink *soc_dais, int num_dais,
317 			       struct snd_soc_codec_conf **codec_conf)
318 {
319 	struct device *dev = card->dev;
320 	struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
321 	struct amd_mc_ctx *amd_ctx = (struct amd_mc_ctx *)ctx->private;
322 	struct snd_soc_dai_link_component *sdw_platform_component;
323 	int i;
324 	int ret;
325 
326 	sdw_platform_component = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component),
327 					      GFP_KERNEL);
328 	if (!sdw_platform_component)
329 		return -ENOMEM;
330 
331 	switch (amd_ctx->acp_rev) {
332 	case ACP63_PCI_REV:
333 	case ACP70_PCI_REV:
334 	case ACP71_PCI_REV:
335 	case ACP72_PCI_REV:
336 		sdw_platform_component->name = "amd_ps_sdw_dma.0";
337 		break;
338 	default:
339 		return -EINVAL;
340 	}
341 
342 	/* generate DAI links by each sdw link */
343 	for (i = 0; i < num_dais && soc_dais->initialised; i++) {
344 		int current_be_id = 0;
345 
346 		ret = create_sdw_dailink(card, soc_dais, dai_links,
347 					 &current_be_id, codec_conf, sdw_platform_component);
348 		if (ret)
349 			return ret;
350 
351 		/* Update the be_id to match the highest ID used for SDW link */
352 		if (*be_id < current_be_id)
353 			*be_id = current_be_id;
354 
355 		soc_dais++;
356 	}
357 
358 	return 0;
359 }
360 
create_dmic_dailinks(struct snd_soc_card * card,struct snd_soc_dai_link ** dai_links,int * be_id,int no_pcm)361 static int create_dmic_dailinks(struct snd_soc_card *card,
362 				struct snd_soc_dai_link **dai_links, int *be_id, int no_pcm)
363 {
364 	struct device *dev = card->dev;
365 	struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
366 	struct amd_mc_ctx *amd_ctx = (struct amd_mc_ctx *)ctx->private;
367 	struct snd_soc_dai_link_component *pdm_cpu;
368 	struct snd_soc_dai_link_component *pdm_platform;
369 	int ret;
370 
371 	pdm_cpu = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
372 	if (!pdm_cpu)
373 		return -ENOMEM;
374 
375 	pdm_platform = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
376 	if (!pdm_platform)
377 		return -ENOMEM;
378 
379 	switch (amd_ctx->acp_rev) {
380 	case ACP63_PCI_REV:
381 	case ACP70_PCI_REV:
382 	case ACP71_PCI_REV:
383 	case ACP72_PCI_REV:
384 		pdm_cpu->name = "acp_ps_pdm_dma.0";
385 		pdm_platform->name = "acp_ps_pdm_dma.0";
386 		break;
387 	default:
388 		return -EINVAL;
389 	}
390 
391 	*be_id = ACP_DMIC_BE_ID;
392 	ret = asoc_sdw_init_simple_dai_link(dev, *dai_links, be_id, "acp-dmic-codec",
393 					    0, 1, // DMIC only supports capture
394 					    pdm_cpu->name, pdm_platform->name,
395 					    "dmic-codec.0", "dmic-hifi", no_pcm,
396 					    asoc_sdw_dmic_init, NULL);
397 	if (ret)
398 		return ret;
399 
400 	(*dai_links)++;
401 
402 	return 0;
403 }
404 
soc_card_dai_links_create(struct snd_soc_card * card)405 static int soc_card_dai_links_create(struct snd_soc_card *card)
406 {
407 	struct device *dev = card->dev;
408 	int sdw_be_num = 0, dmic_num = 0;
409 	struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
410 	struct snd_soc_aux_dev *soc_aux;
411 	struct snd_soc_codec_conf *codec_conf;
412 	struct snd_soc_dai_link *dai_links;
413 	int num_devs = 0;
414 	int num_ends = 0;
415 	int num_aux = 0;
416 	int num_confs;
417 	int num_links;
418 	int be_id = 0;
419 	int ret;
420 
421 	ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux);
422 	if (ret < 0) {
423 		dev_err(dev, "failed to count devices/endpoints: %d\n", ret);
424 		return ret;
425 	}
426 
427 	num_confs = num_ends;
428 
429 	/* One per DAI link, worst case is a DAI link for every endpoint */
430 	struct asoc_sdw_dailink *soc_dais __free(kfree) =
431 		kzalloc_objs(*soc_dais, num_ends);
432 	if (!soc_dais)
433 		return -ENOMEM;
434 
435 	/* One per endpoint, ie. each DAI on each codec/amp */
436 	struct asoc_sdw_endpoint *soc_ends __free(kfree) =
437 		kzalloc_objs(*soc_ends, num_ends);
438 	if (!soc_ends)
439 		return -ENOMEM;
440 
441 	soc_aux = devm_kcalloc(dev, num_aux, sizeof(*soc_aux), GFP_KERNEL);
442 	if (!soc_aux)
443 		return -ENOMEM;
444 
445 	ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, soc_aux, soc_dais, soc_ends, &num_confs);
446 	if (ret < 0)
447 		return ret;
448 
449 	sdw_be_num = ret;
450 
451 	/* enable dmic */
452 	if (soc_sdw_quirk & ASOC_SDW_ACP_DMIC)
453 		dmic_num = 1;
454 
455 	dev_dbg(dev, "sdw %d, dmic %d", sdw_be_num, dmic_num);
456 
457 	codec_conf = devm_kcalloc(dev, num_confs, sizeof(*codec_conf), GFP_KERNEL);
458 	if (!codec_conf)
459 		return -ENOMEM;
460 
461 	/* allocate BE dailinks */
462 	num_links = sdw_be_num + dmic_num;
463 	dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL);
464 	if (!dai_links)
465 		return -ENOMEM;
466 
467 	card->codec_conf = codec_conf;
468 	card->num_configs = num_confs;
469 	card->dai_link = dai_links;
470 	card->num_links = num_links;
471 	card->aux_dev = soc_aux;
472 	card->num_aux_devs = num_aux;
473 
474 	/* SDW */
475 	if (sdw_be_num) {
476 		ret = create_sdw_dailinks(card, &dai_links, &be_id,
477 					  soc_dais, num_ends, &codec_conf);
478 		if (ret)
479 			return ret;
480 	}
481 
482 	/* dmic */
483 	if (dmic_num > 0) {
484 		if (ctx->ignore_internal_dmic) {
485 			dev_warn(dev, "Ignoring ACP DMIC\n");
486 		} else {
487 			ret = create_dmic_dailinks(card, &dai_links, &be_id, 0);
488 			if (ret)
489 				return ret;
490 		}
491 	}
492 
493 	WARN_ON(codec_conf != card->codec_conf + card->num_configs);
494 	WARN_ON(dai_links != card->dai_link + card->num_links);
495 
496 	return ret;
497 }
498 
mc_probe(struct platform_device * pdev)499 static int mc_probe(struct platform_device *pdev)
500 {
501 	struct snd_soc_acpi_mach *mach = dev_get_platdata(&pdev->dev);
502 	struct snd_soc_card *card;
503 	struct amd_mc_ctx *amd_ctx;
504 	struct asoc_sdw_mc_private *ctx;
505 	int amp_num = 0, i;
506 	int ret;
507 
508 	amd_ctx = devm_kzalloc(&pdev->dev, sizeof(*amd_ctx), GFP_KERNEL);
509 	if (!amd_ctx)
510 		return -ENOMEM;
511 
512 	amd_ctx->acp_rev = mach->mach_params.subsystem_rev;
513 	amd_ctx->max_sdw_links = ACP63_SDW_MAX_LINKS;
514 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
515 	if (!ctx)
516 		return -ENOMEM;
517 	ctx->codec_info_list_count = asoc_sdw_get_codec_info_list_count();
518 	ctx->private = amd_ctx;
519 	card = &ctx->card;
520 	card->dev = &pdev->dev;
521 	card->name = "amd-soundwire";
522 	card->owner = THIS_MODULE;
523 	card->late_probe = asoc_sdw_card_late_probe;
524 
525 	snd_soc_card_set_drvdata(card, ctx);
526 	if (mach->mach_params.subsystem_id_set)
527 		snd_soc_card_set_pci_ssid(card,
528 					  mach->mach_params.subsystem_vendor,
529 					  mach->mach_params.subsystem_device);
530 
531 	dmi_check_system(soc_sdw_quirk_table);
532 
533 	if (quirk_override != -1) {
534 		dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
535 			 soc_sdw_quirk, quirk_override);
536 		soc_sdw_quirk = quirk_override;
537 	}
538 
539 	log_quirks(&pdev->dev);
540 
541 	ctx->mc_quirk = soc_sdw_quirk;
542 	dev_dbg(&pdev->dev, "legacy quirk 0x%lx\n", ctx->mc_quirk);
543 	/* reset amp_num to ensure amp_num++ starts from 0 in each probe */
544 	for (i = 0; i < ctx->codec_info_list_count; i++)
545 		codec_info_list[i].amp_num = 0;
546 
547 	ret = soc_card_dai_links_create(card);
548 	if (ret < 0)
549 		return ret;
550 
551 	/*
552 	 * the default amp_num is zero for each codec and
553 	 * amp_num will only be increased for active amp
554 	 * codecs on used platform
555 	 */
556 	for (i = 0; i < ctx->codec_info_list_count; i++)
557 		amp_num += codec_info_list[i].amp_num;
558 
559 	card->components = devm_kasprintf(&pdev->dev, GFP_KERNEL,
560 					  " cfg-amp:%d", amp_num);
561 	if (!card->components)
562 		return -ENOMEM;
563 	if (soc_sdw_quirk & ASOC_SDW_ACP_DMIC) {
564 		card->components = devm_kasprintf(&pdev->dev, GFP_KERNEL,
565 						  "%s mic:acp-dmic cfg-mics:%d",
566 						  card->components,
567 						  1);
568 		if (!card->components)
569 			return -ENOMEM;
570 	}
571 
572 	/* Register the card */
573 	ret = devm_snd_soc_register_card(&pdev->dev, card);
574 	if (ret) {
575 		dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed %d\n", ret);
576 		asoc_sdw_mc_dailink_exit_loop(card);
577 		return ret;
578 	}
579 
580 	platform_set_drvdata(pdev, card);
581 
582 	return ret;
583 }
584 
mc_remove(struct platform_device * pdev)585 static void mc_remove(struct platform_device *pdev)
586 {
587 	struct snd_soc_card *card = platform_get_drvdata(pdev);
588 
589 	asoc_sdw_mc_dailink_exit_loop(card);
590 }
591 
592 static const struct platform_device_id mc_id_table[] = {
593 	{ .name = "amd_sdw" },
594 	{ }
595 };
596 MODULE_DEVICE_TABLE(platform, mc_id_table);
597 
598 static struct platform_driver soc_sdw_driver = {
599 	.driver = {
600 		.name = "amd_sdw",
601 		.pm = &snd_soc_pm_ops,
602 	},
603 	.probe = mc_probe,
604 	.remove = mc_remove,
605 	.id_table = mc_id_table,
606 };
607 
608 module_platform_driver(soc_sdw_driver);
609 
610 MODULE_DESCRIPTION("ASoC AMD SoundWire Legacy Generic Machine driver");
611 MODULE_AUTHOR("Vijendar Mukunda <Vijendar.Mukunda@amd.com>");
612 MODULE_LICENSE("GPL");
613 MODULE_IMPORT_NS("SND_SOC_SDW_UTILS");
614 MODULE_IMPORT_NS("SND_SOC_AMD_SDW_MACH");
615