• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // Copyright(c) 2021-2022 Intel Corporation
4 //
5 // Authors: Cezary Rojewski <cezary.rojewski@intel.com>
6 //          Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
7 //
8 
9 #include <linux/debugfs.h>
10 #include <linux/device.h>
11 #include <sound/hda_register.h>
12 #include <sound/hdaudio_ext.h>
13 #include <sound/pcm_params.h>
14 #include <sound/soc-acpi.h>
15 #include <sound/soc-acpi-intel-match.h>
16 #include <sound/soc-component.h>
17 #include "avs.h"
18 #include "path.h"
19 #include "pcm.h"
20 #include "topology.h"
21 #include "../../codecs/hda.h"
22 
23 struct avs_dma_data {
24 	struct avs_tplg_path_template *template;
25 	struct avs_path *path;
26 	struct avs_dev *adev;
27 
28 	/* LINK-stream utilized in BE operations while HOST in FE ones. */
29 	union {
30 		struct hdac_ext_stream *link_stream;
31 		struct hdac_ext_stream *host_stream;
32 	};
33 
34 	struct work_struct period_elapsed_work;
35 	struct snd_pcm_substream *substream;
36 };
37 
38 static struct avs_tplg_path_template *
avs_dai_find_path_template(struct snd_soc_dai * dai,bool is_fe,int direction)39 avs_dai_find_path_template(struct snd_soc_dai *dai, bool is_fe, int direction)
40 {
41 	struct snd_soc_dapm_widget *dw = snd_soc_dai_get_widget(dai, direction);
42 	struct snd_soc_dapm_path *dp;
43 	enum snd_soc_dapm_direction dir;
44 
45 	if (direction == SNDRV_PCM_STREAM_CAPTURE) {
46 		dir = is_fe ? SND_SOC_DAPM_DIR_OUT : SND_SOC_DAPM_DIR_IN;
47 	} else {
48 		dir = is_fe ? SND_SOC_DAPM_DIR_IN : SND_SOC_DAPM_DIR_OUT;
49 	}
50 
51 	dp = list_first_entry_or_null(&dw->edges[dir], typeof(*dp), list_node[dir]);
52 	if (!dp)
53 		return NULL;
54 
55 	/* Get the other widget, with actual path template data */
56 	dw = (dp->source == dw) ? dp->sink : dp->source;
57 
58 	return dw->priv;
59 }
60 
avs_period_elapsed_work(struct work_struct * work)61 static void avs_period_elapsed_work(struct work_struct *work)
62 {
63 	struct avs_dma_data *data = container_of(work, struct avs_dma_data, period_elapsed_work);
64 
65 	snd_pcm_period_elapsed(data->substream);
66 }
67 
avs_period_elapsed(struct snd_pcm_substream * substream)68 void avs_period_elapsed(struct snd_pcm_substream *substream)
69 {
70 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
71 	struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
72 	struct avs_dma_data *data = snd_soc_dai_get_dma_data(dai, substream);
73 
74 	schedule_work(&data->period_elapsed_work);
75 }
76 
avs_dai_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)77 static int avs_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
78 {
79 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
80 	struct avs_dev *adev = to_avs_dev(dai->component->dev);
81 	struct avs_tplg_path_template *template;
82 	struct avs_dma_data *data;
83 
84 	template = avs_dai_find_path_template(dai, !rtd->dai_link->no_pcm, substream->stream);
85 	if (!template) {
86 		dev_err(dai->dev, "no %s path for dai %s, invalid tplg?\n",
87 			snd_pcm_stream_str(substream), dai->name);
88 		return -EINVAL;
89 	}
90 
91 	data = kzalloc(sizeof(*data), GFP_KERNEL);
92 	if (!data)
93 		return -ENOMEM;
94 
95 	data->substream = substream;
96 	data->template = template;
97 	data->adev = adev;
98 	INIT_WORK(&data->period_elapsed_work, avs_period_elapsed_work);
99 	snd_soc_dai_set_dma_data(dai, substream, data);
100 
101 	if (rtd->dai_link->ignore_suspend)
102 		adev->num_lp_paths++;
103 
104 	return 0;
105 }
106 
avs_dai_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)107 static void avs_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
108 {
109 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
110 	struct avs_dma_data *data;
111 
112 	data = snd_soc_dai_get_dma_data(dai, substream);
113 
114 	if (rtd->dai_link->ignore_suspend)
115 		data->adev->num_lp_paths--;
116 
117 	snd_soc_dai_set_dma_data(dai, substream, NULL);
118 	kfree(data);
119 }
120 
avs_dai_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * fe_hw_params,struct snd_pcm_hw_params * be_hw_params,struct snd_soc_dai * dai,int dma_id)121 static int avs_dai_hw_params(struct snd_pcm_substream *substream,
122 			     struct snd_pcm_hw_params *fe_hw_params,
123 			     struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai,
124 			     int dma_id)
125 {
126 	struct avs_dma_data *data;
127 	struct avs_path *path;
128 	int ret;
129 
130 	data = snd_soc_dai_get_dma_data(dai, substream);
131 
132 	dev_dbg(dai->dev, "%s FE hw_params str %p rtd %p",
133 		__func__, substream, substream->runtime);
134 	dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n",
135 		params_rate(fe_hw_params), params_channels(fe_hw_params),
136 		params_width(fe_hw_params), params_physical_width(fe_hw_params));
137 
138 	dev_dbg(dai->dev, "%s BE hw_params str %p rtd %p",
139 		__func__, substream, substream->runtime);
140 	dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n",
141 		params_rate(be_hw_params), params_channels(be_hw_params),
142 		params_width(be_hw_params), params_physical_width(be_hw_params));
143 
144 	path = avs_path_create(data->adev, dma_id, data->template, fe_hw_params, be_hw_params);
145 	if (IS_ERR(path)) {
146 		ret = PTR_ERR(path);
147 		dev_err(dai->dev, "create path failed: %d\n", ret);
148 		return ret;
149 	}
150 
151 	data->path = path;
152 	return 0;
153 }
154 
avs_dai_be_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * be_hw_params,struct snd_soc_dai * dai,int dma_id)155 static int avs_dai_be_hw_params(struct snd_pcm_substream *substream,
156 				struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai,
157 				int dma_id)
158 {
159 	struct snd_pcm_hw_params *fe_hw_params = NULL;
160 	struct snd_soc_pcm_runtime *fe, *be;
161 	struct snd_soc_dpcm *dpcm;
162 
163 	be = snd_soc_substream_to_rtd(substream);
164 	for_each_dpcm_fe(be, substream->stream, dpcm) {
165 		fe = dpcm->fe;
166 		fe_hw_params = &fe->dpcm[substream->stream].hw_params;
167 	}
168 
169 	return avs_dai_hw_params(substream, fe_hw_params, be_hw_params, dai, dma_id);
170 }
171 
avs_dai_prepare(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)172 static int avs_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
173 {
174 	struct avs_dma_data *data;
175 	int ret;
176 
177 	data = snd_soc_dai_get_dma_data(dai, substream);
178 	if (!data->path)
179 		return 0;
180 
181 	ret = avs_path_reset(data->path);
182 	if (ret < 0) {
183 		dev_err(dai->dev, "reset path failed: %d\n", ret);
184 		return ret;
185 	}
186 
187 	ret = avs_path_pause(data->path);
188 	if (ret < 0)
189 		dev_err(dai->dev, "pause path failed: %d\n", ret);
190 	return ret;
191 }
192 
avs_dai_nonhda_be_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * hw_params,struct snd_soc_dai * dai)193 static int avs_dai_nonhda_be_hw_params(struct snd_pcm_substream *substream,
194 				       struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai)
195 {
196 	struct avs_dma_data *data;
197 
198 	data = snd_soc_dai_get_dma_data(dai, substream);
199 	if (data->path)
200 		return 0;
201 
202 	/* Actual port-id comes from topology. */
203 	return avs_dai_be_hw_params(substream, hw_params, dai, 0);
204 }
205 
avs_dai_nonhda_be_hw_free(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)206 static int avs_dai_nonhda_be_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
207 {
208 	struct avs_dma_data *data;
209 
210 	dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
211 
212 	data = snd_soc_dai_get_dma_data(dai, substream);
213 	if (data->path) {
214 		avs_path_free(data->path);
215 		data->path = NULL;
216 	}
217 
218 	return 0;
219 }
220 
avs_dai_nonhda_be_trigger(struct snd_pcm_substream * substream,int cmd,struct snd_soc_dai * dai)221 static int avs_dai_nonhda_be_trigger(struct snd_pcm_substream *substream, int cmd,
222 				     struct snd_soc_dai *dai)
223 {
224 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
225 	struct avs_dma_data *data;
226 	int ret = 0;
227 
228 	data = snd_soc_dai_get_dma_data(dai, substream);
229 
230 	switch (cmd) {
231 	case SNDRV_PCM_TRIGGER_RESUME:
232 		if (rtd->dai_link->ignore_suspend)
233 			break;
234 		fallthrough;
235 	case SNDRV_PCM_TRIGGER_START:
236 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
237 		ret = avs_path_pause(data->path);
238 		if (ret < 0) {
239 			dev_err(dai->dev, "pause BE path failed: %d\n", ret);
240 			break;
241 		}
242 
243 		ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO);
244 		if (ret < 0)
245 			dev_err(dai->dev, "run BE path failed: %d\n", ret);
246 		break;
247 
248 	case SNDRV_PCM_TRIGGER_SUSPEND:
249 		if (rtd->dai_link->ignore_suspend)
250 			break;
251 		fallthrough;
252 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
253 	case SNDRV_PCM_TRIGGER_STOP:
254 		ret = avs_path_pause(data->path);
255 		if (ret < 0)
256 			dev_err(dai->dev, "pause BE path failed: %d\n", ret);
257 
258 		ret = avs_path_reset(data->path);
259 		if (ret < 0)
260 			dev_err(dai->dev, "reset BE path failed: %d\n", ret);
261 		break;
262 
263 	default:
264 		ret = -EINVAL;
265 		break;
266 	}
267 
268 	return ret;
269 }
270 
271 static const struct snd_soc_dai_ops avs_dai_nonhda_be_ops = {
272 	.startup = avs_dai_startup,
273 	.shutdown = avs_dai_shutdown,
274 	.hw_params = avs_dai_nonhda_be_hw_params,
275 	.hw_free = avs_dai_nonhda_be_hw_free,
276 	.prepare = avs_dai_prepare,
277 	.trigger = avs_dai_nonhda_be_trigger,
278 };
279 
avs_dai_hda_be_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)280 static int avs_dai_hda_be_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
281 {
282 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
283 	struct hdac_ext_stream *link_stream;
284 	struct avs_dma_data *data;
285 	struct hda_codec *codec;
286 	int ret;
287 
288 	ret = avs_dai_startup(substream, dai);
289 	if (ret)
290 		return ret;
291 
292 	codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
293 	link_stream = snd_hdac_ext_stream_assign(&codec->bus->core, substream,
294 						 HDAC_EXT_STREAM_TYPE_LINK);
295 	if (!link_stream) {
296 		avs_dai_shutdown(substream, dai);
297 		return -EBUSY;
298 	}
299 
300 	data = snd_soc_dai_get_dma_data(dai, substream);
301 	data->link_stream = link_stream;
302 	substream->runtime->private_data = link_stream;
303 	return 0;
304 }
305 
avs_dai_hda_be_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)306 static void avs_dai_hda_be_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
307 {
308 	struct avs_dma_data *data = snd_soc_dai_get_dma_data(dai, substream);
309 
310 	snd_hdac_ext_stream_release(data->link_stream, HDAC_EXT_STREAM_TYPE_LINK);
311 	substream->runtime->private_data = NULL;
312 	avs_dai_shutdown(substream, dai);
313 }
314 
avs_dai_hda_be_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * hw_params,struct snd_soc_dai * dai)315 static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream,
316 				    struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai)
317 {
318 	struct avs_dma_data *data;
319 
320 	data = snd_soc_dai_get_dma_data(dai, substream);
321 	if (data->path)
322 		return 0;
323 
324 	return avs_dai_be_hw_params(substream, hw_params, dai,
325 				    hdac_stream(data->link_stream)->stream_tag - 1);
326 }
327 
avs_dai_hda_be_hw_free(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)328 static int avs_dai_hda_be_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
329 {
330 	struct avs_dma_data *data;
331 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
332 	struct hdac_ext_stream *link_stream;
333 	struct hdac_ext_link *link;
334 	struct hda_codec *codec;
335 
336 	dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
337 
338 	data = snd_soc_dai_get_dma_data(dai, substream);
339 	if (!data->path)
340 		return 0;
341 
342 	link_stream = data->link_stream;
343 	link_stream->link_prepared = false;
344 	avs_path_free(data->path);
345 	data->path = NULL;
346 
347 	/* clear link <-> stream mapping */
348 	codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
349 	link = snd_hdac_ext_bus_get_hlink_by_addr(&codec->bus->core, codec->core.addr);
350 	if (!link)
351 		return -EINVAL;
352 
353 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
354 		snd_hdac_ext_bus_link_clear_stream_id(link, hdac_stream(link_stream)->stream_tag);
355 
356 	return 0;
357 }
358 
avs_dai_hda_be_prepare(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)359 static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
360 {
361 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
362 	struct snd_pcm_runtime *runtime = substream->runtime;
363 	const struct snd_soc_pcm_stream *stream_info;
364 	struct hdac_ext_stream *link_stream;
365 	struct hdac_ext_link *link;
366 	struct avs_dma_data *data;
367 	struct hda_codec *codec;
368 	struct hdac_bus *bus;
369 	unsigned int format_val;
370 	unsigned int bits;
371 	int ret;
372 
373 	data = snd_soc_dai_get_dma_data(dai, substream);
374 	link_stream = data->link_stream;
375 
376 	if (link_stream->link_prepared)
377 		return 0;
378 
379 	codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
380 	bus = &codec->bus->core;
381 	stream_info = snd_soc_dai_get_pcm_stream(dai, substream->stream);
382 	bits = snd_hdac_stream_format_bits(runtime->format, runtime->subformat,
383 					   stream_info->sig_bits);
384 	format_val = snd_hdac_stream_format(runtime->channels, bits, runtime->rate);
385 
386 	snd_hdac_ext_stream_decouple(bus, link_stream, true);
387 	snd_hdac_ext_stream_reset(link_stream);
388 	snd_hdac_ext_stream_setup(link_stream, format_val);
389 
390 	link = snd_hdac_ext_bus_get_hlink_by_addr(bus, codec->core.addr);
391 	if (!link)
392 		return -EINVAL;
393 
394 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
395 		snd_hdac_ext_bus_link_set_stream_id(link, hdac_stream(link_stream)->stream_tag);
396 
397 	ret = avs_dai_prepare(substream, dai);
398 	if (ret)
399 		return ret;
400 
401 	link_stream->link_prepared = true;
402 	return 0;
403 }
404 
avs_dai_hda_be_trigger(struct snd_pcm_substream * substream,int cmd,struct snd_soc_dai * dai)405 static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd,
406 				  struct snd_soc_dai *dai)
407 {
408 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
409 	struct avs_dma_data *data;
410 	int ret = 0;
411 
412 	dev_dbg(dai->dev, "entry %s cmd=%d\n", __func__, cmd);
413 
414 	data = snd_soc_dai_get_dma_data(dai, substream);
415 
416 	switch (cmd) {
417 	case SNDRV_PCM_TRIGGER_RESUME:
418 		if (rtd->dai_link->ignore_suspend)
419 			break;
420 		fallthrough;
421 	case SNDRV_PCM_TRIGGER_START:
422 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
423 		snd_hdac_ext_stream_start(data->link_stream);
424 
425 		ret = avs_path_pause(data->path);
426 		if (ret < 0) {
427 			dev_err(dai->dev, "pause BE path failed: %d\n", ret);
428 			break;
429 		}
430 
431 		ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO);
432 		if (ret < 0)
433 			dev_err(dai->dev, "run BE path failed: %d\n", ret);
434 		break;
435 
436 	case SNDRV_PCM_TRIGGER_SUSPEND:
437 		if (rtd->dai_link->ignore_suspend)
438 			break;
439 		fallthrough;
440 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
441 	case SNDRV_PCM_TRIGGER_STOP:
442 		ret = avs_path_pause(data->path);
443 		if (ret < 0)
444 			dev_err(dai->dev, "pause BE path failed: %d\n", ret);
445 
446 		snd_hdac_ext_stream_clear(data->link_stream);
447 
448 		ret = avs_path_reset(data->path);
449 		if (ret < 0)
450 			dev_err(dai->dev, "reset BE path failed: %d\n", ret);
451 		break;
452 
453 	default:
454 		ret = -EINVAL;
455 		break;
456 	}
457 
458 	return ret;
459 }
460 
461 static const struct snd_soc_dai_ops avs_dai_hda_be_ops = {
462 	.startup = avs_dai_hda_be_startup,
463 	.shutdown = avs_dai_hda_be_shutdown,
464 	.hw_params = avs_dai_hda_be_hw_params,
465 	.hw_free = avs_dai_hda_be_hw_free,
466 	.prepare = avs_dai_hda_be_prepare,
467 	.trigger = avs_dai_hda_be_trigger,
468 };
469 
hw_rule_param_size(struct snd_pcm_hw_params * params,struct snd_pcm_hw_rule * rule)470 static int hw_rule_param_size(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
471 {
472 	struct snd_interval *interval = hw_param_interval(params, rule->var);
473 	struct snd_interval to;
474 
475 	snd_interval_any(&to);
476 	to.integer = interval->integer;
477 	to.max = interval->max;
478 	/*
479 	 * Commonly 2ms buffer size is used in HDA scenarios whereas 4ms is used
480 	 * when streaming through GPDMA. Align to the latter to account for both.
481 	 */
482 	to.min = params_rate(params) / 1000 * 4;
483 
484 	if (rule->var == SNDRV_PCM_HW_PARAM_PERIOD_SIZE)
485 		to.min /= params_periods(params);
486 
487 	return snd_interval_refine(interval, &to);
488 }
489 
avs_pcm_hw_constraints_init(struct snd_pcm_substream * substream)490 static int avs_pcm_hw_constraints_init(struct snd_pcm_substream *substream)
491 {
492 	struct snd_pcm_runtime *runtime = substream->runtime;
493 	int ret;
494 
495 	ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
496 	if (ret < 0)
497 		return ret;
498 
499 	/* Avoid wrap-around with wall-clock. */
500 	ret = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME, 20, 178000000);
501 	if (ret < 0)
502 		return ret;
503 
504 	/* Adjust buffer and period size based on the audio format. */
505 	snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, hw_rule_param_size, NULL,
506 			    SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
507 			    SNDRV_PCM_HW_PARAM_RATE, -1);
508 	snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, hw_rule_param_size, NULL,
509 			    SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
510 			    SNDRV_PCM_HW_PARAM_RATE, -1);
511 
512 	return 0;
513 }
514 
avs_dai_fe_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)515 static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
516 {
517 	struct hdac_ext_stream *host_stream;
518 	struct avs_dma_data *data;
519 	struct hdac_bus *bus;
520 	int ret;
521 
522 	ret = avs_pcm_hw_constraints_init(substream);
523 	if (ret)
524 		return ret;
525 
526 	ret = avs_dai_startup(substream, dai);
527 	if (ret)
528 		return ret;
529 
530 	data = snd_soc_dai_get_dma_data(dai, substream);
531 	bus = &data->adev->base.core;
532 
533 	host_stream = snd_hdac_ext_stream_assign(bus, substream, HDAC_EXT_STREAM_TYPE_HOST);
534 	if (!host_stream) {
535 		avs_dai_shutdown(substream, dai);
536 		return -EBUSY;
537 	}
538 
539 	data->host_stream = host_stream;
540 	snd_pcm_set_sync(substream);
541 
542 	dev_dbg(dai->dev, "%s fe STARTUP tag %d str %p",
543 		__func__, hdac_stream(host_stream)->stream_tag, substream);
544 
545 	return 0;
546 }
547 
avs_dai_fe_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)548 static void avs_dai_fe_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
549 {
550 	struct avs_dma_data *data;
551 
552 	data = snd_soc_dai_get_dma_data(dai, substream);
553 
554 	snd_hdac_ext_stream_release(data->host_stream, HDAC_EXT_STREAM_TYPE_HOST);
555 	avs_dai_shutdown(substream, dai);
556 }
557 
avs_dai_fe_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * hw_params,struct snd_soc_dai * dai)558 static int avs_dai_fe_hw_params(struct snd_pcm_substream *substream,
559 				struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai)
560 {
561 	struct snd_pcm_hw_params *be_hw_params = NULL;
562 	struct snd_soc_pcm_runtime *fe, *be;
563 	struct snd_soc_dpcm *dpcm;
564 	struct avs_dma_data *data;
565 	struct hdac_ext_stream *host_stream;
566 	int ret;
567 
568 	data = snd_soc_dai_get_dma_data(dai, substream);
569 	if (data->path)
570 		return 0;
571 
572 	host_stream = data->host_stream;
573 
574 	hdac_stream(host_stream)->bufsize = 0;
575 	hdac_stream(host_stream)->period_bytes = 0;
576 	hdac_stream(host_stream)->format_val = 0;
577 
578 	fe = snd_soc_substream_to_rtd(substream);
579 	for_each_dpcm_be(fe, substream->stream, dpcm) {
580 		be = dpcm->be;
581 		be_hw_params = &be->dpcm[substream->stream].hw_params;
582 	}
583 
584 	ret = avs_dai_hw_params(substream, hw_params, be_hw_params, dai,
585 				hdac_stream(host_stream)->stream_tag - 1);
586 	if (ret)
587 		goto create_err;
588 
589 	ret = avs_path_bind(data->path);
590 	if (ret < 0) {
591 		dev_err(dai->dev, "bind FE <-> BE failed: %d\n", ret);
592 		goto bind_err;
593 	}
594 
595 	return 0;
596 
597 bind_err:
598 	avs_path_free(data->path);
599 	data->path = NULL;
600 create_err:
601 	snd_pcm_lib_free_pages(substream);
602 	return ret;
603 }
604 
__avs_dai_fe_hw_free(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)605 static int __avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
606 {
607 	struct avs_dma_data *data;
608 	struct hdac_ext_stream *host_stream;
609 	int ret;
610 
611 	dev_dbg(dai->dev, "%s fe HW_FREE str %p rtd %p",
612 		__func__, substream, substream->runtime);
613 
614 	data = snd_soc_dai_get_dma_data(dai, substream);
615 	if (!data->path)
616 		return 0;
617 
618 	host_stream = data->host_stream;
619 
620 	ret = avs_path_unbind(data->path);
621 	if (ret < 0)
622 		dev_err(dai->dev, "unbind FE <-> BE failed: %d\n", ret);
623 
624 	avs_path_free(data->path);
625 	data->path = NULL;
626 	snd_hdac_stream_cleanup(hdac_stream(host_stream));
627 	hdac_stream(host_stream)->prepared = false;
628 
629 	return ret;
630 }
631 
avs_dai_fe_hw_free(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)632 static int avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
633 {
634 	int ret;
635 
636 	ret = __avs_dai_fe_hw_free(substream, dai);
637 	snd_pcm_lib_free_pages(substream);
638 
639 	return ret;
640 }
641 
avs_dai_fe_prepare(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)642 static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
643 {
644 	struct snd_pcm_runtime *runtime = substream->runtime;
645 	const struct snd_soc_pcm_stream *stream_info;
646 	struct avs_dma_data *data;
647 	struct hdac_ext_stream *host_stream;
648 	unsigned int format_val;
649 	struct hdac_bus *bus;
650 	unsigned int bits;
651 	int ret;
652 
653 	data = snd_soc_dai_get_dma_data(dai, substream);
654 	host_stream = data->host_stream;
655 
656 	if (hdac_stream(host_stream)->prepared)
657 		return 0;
658 
659 	bus = hdac_stream(host_stream)->bus;
660 	snd_hdac_ext_stream_decouple(bus, data->host_stream, true);
661 	snd_hdac_stream_reset(hdac_stream(host_stream));
662 
663 	stream_info = snd_soc_dai_get_pcm_stream(dai, substream->stream);
664 	bits = snd_hdac_stream_format_bits(runtime->format, runtime->subformat,
665 					   stream_info->sig_bits);
666 	format_val = snd_hdac_stream_format(runtime->channels, bits, runtime->rate);
667 
668 	ret = snd_hdac_stream_set_params(hdac_stream(host_stream), format_val);
669 	if (ret < 0)
670 		return ret;
671 
672 	ret = snd_hdac_ext_host_stream_setup(host_stream, false);
673 	if (ret < 0)
674 		return ret;
675 
676 	ret = avs_dai_prepare(substream, dai);
677 	if (ret)
678 		return ret;
679 
680 	hdac_stream(host_stream)->prepared = true;
681 	return 0;
682 }
683 
avs_hda_stream_start(struct hdac_bus * bus,struct hdac_ext_stream * host_stream)684 static void avs_hda_stream_start(struct hdac_bus *bus, struct hdac_ext_stream *host_stream)
685 {
686 	struct hdac_stream *first_running = NULL;
687 	struct hdac_stream *pos;
688 	struct avs_dev *adev = hdac_to_avs(bus);
689 
690 	list_for_each_entry(pos, &bus->stream_list, list) {
691 		if (pos->running) {
692 			if (first_running)
693 				break; /* more than one running */
694 			first_running = pos;
695 		}
696 	}
697 
698 	/*
699 	 * If host_stream is a CAPTURE stream and will be the only one running,
700 	 * disable L1SEN to avoid sound clipping.
701 	 */
702 	if (!first_running) {
703 		if (hdac_stream(host_stream)->direction == SNDRV_PCM_STREAM_CAPTURE)
704 			avs_hda_l1sen_enable(adev, false);
705 		snd_hdac_stream_start(hdac_stream(host_stream));
706 		return;
707 	}
708 
709 	snd_hdac_stream_start(hdac_stream(host_stream));
710 	/*
711 	 * If host_stream is the first stream to break the rule above,
712 	 * re-enable L1SEN.
713 	 */
714 	if (list_entry_is_head(pos, &bus->stream_list, list) &&
715 	    first_running->direction == SNDRV_PCM_STREAM_CAPTURE)
716 		avs_hda_l1sen_enable(adev, true);
717 }
718 
avs_hda_stream_stop(struct hdac_bus * bus,struct hdac_ext_stream * host_stream)719 static void avs_hda_stream_stop(struct hdac_bus *bus, struct hdac_ext_stream *host_stream)
720 {
721 	struct hdac_stream *first_running = NULL;
722 	struct hdac_stream *pos;
723 	struct avs_dev *adev = hdac_to_avs(bus);
724 
725 	list_for_each_entry(pos, &bus->stream_list, list) {
726 		if (pos == hdac_stream(host_stream))
727 			continue; /* ignore stream that is about to be stopped */
728 		if (pos->running) {
729 			if (first_running)
730 				break; /* more than one running */
731 			first_running = pos;
732 		}
733 	}
734 
735 	/*
736 	 * If host_stream is a CAPTURE stream and is the only one running,
737 	 * re-enable L1SEN.
738 	 */
739 	if (!first_running) {
740 		snd_hdac_stream_stop(hdac_stream(host_stream));
741 		if (hdac_stream(host_stream)->direction == SNDRV_PCM_STREAM_CAPTURE)
742 			avs_hda_l1sen_enable(adev, true);
743 		return;
744 	}
745 
746 	/*
747 	 * If by stopping host_stream there is only a single, CAPTURE stream running
748 	 * left, disable L1SEN to avoid sound clipping.
749 	 */
750 	if (list_entry_is_head(pos, &bus->stream_list, list) &&
751 	    first_running->direction == SNDRV_PCM_STREAM_CAPTURE)
752 		avs_hda_l1sen_enable(adev, false);
753 
754 	snd_hdac_stream_stop(hdac_stream(host_stream));
755 }
756 
avs_dai_fe_trigger(struct snd_pcm_substream * substream,int cmd,struct snd_soc_dai * dai)757 static int avs_dai_fe_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai)
758 {
759 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
760 	struct avs_dma_data *data;
761 	struct hdac_ext_stream *host_stream;
762 	struct hdac_bus *bus;
763 	unsigned long flags;
764 	int ret = 0;
765 
766 	data = snd_soc_dai_get_dma_data(dai, substream);
767 	host_stream = data->host_stream;
768 	bus = hdac_stream(host_stream)->bus;
769 
770 	switch (cmd) {
771 	case SNDRV_PCM_TRIGGER_RESUME:
772 		if (rtd->dai_link->ignore_suspend)
773 			break;
774 		fallthrough;
775 	case SNDRV_PCM_TRIGGER_START:
776 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
777 		spin_lock_irqsave(&bus->reg_lock, flags);
778 		avs_hda_stream_start(bus, host_stream);
779 		spin_unlock_irqrestore(&bus->reg_lock, flags);
780 
781 		/* Timeout on DRSM poll shall not stop the resume so ignore the result. */
782 		if (cmd == SNDRV_PCM_TRIGGER_RESUME)
783 			snd_hdac_stream_wait_drsm(hdac_stream(host_stream));
784 
785 		ret = avs_path_pause(data->path);
786 		if (ret < 0) {
787 			dev_err(dai->dev, "pause FE path failed: %d\n", ret);
788 			break;
789 		}
790 
791 		ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO);
792 		if (ret < 0)
793 			dev_err(dai->dev, "run FE path failed: %d\n", ret);
794 
795 		break;
796 
797 	case SNDRV_PCM_TRIGGER_SUSPEND:
798 		if (rtd->dai_link->ignore_suspend)
799 			break;
800 		fallthrough;
801 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
802 	case SNDRV_PCM_TRIGGER_STOP:
803 		ret = avs_path_pause(data->path);
804 		if (ret < 0)
805 			dev_err(dai->dev, "pause FE path failed: %d\n", ret);
806 
807 		spin_lock_irqsave(&bus->reg_lock, flags);
808 		avs_hda_stream_stop(bus, host_stream);
809 		spin_unlock_irqrestore(&bus->reg_lock, flags);
810 
811 		ret = avs_path_reset(data->path);
812 		if (ret < 0)
813 			dev_err(dai->dev, "reset FE path failed: %d\n", ret);
814 		break;
815 
816 	default:
817 		ret = -EINVAL;
818 		break;
819 	}
820 
821 	return ret;
822 }
823 
824 const struct snd_soc_dai_ops avs_dai_fe_ops = {
825 	.startup = avs_dai_fe_startup,
826 	.shutdown = avs_dai_fe_shutdown,
827 	.hw_params = avs_dai_fe_hw_params,
828 	.hw_free = avs_dai_fe_hw_free,
829 	.prepare = avs_dai_fe_prepare,
830 	.trigger = avs_dai_fe_trigger,
831 };
832 
topology_name_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)833 static ssize_t topology_name_read(struct file *file, char __user *user_buf, size_t count,
834 				  loff_t *ppos)
835 {
836 	struct snd_soc_component *component = file->private_data;
837 	struct snd_soc_card *card = component->card;
838 	struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev);
839 	char buf[64];
840 	size_t len;
841 
842 	len = scnprintf(buf, sizeof(buf), "%s/%s\n", component->driver->topology_name_prefix,
843 			mach->tplg_filename);
844 
845 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
846 }
847 
848 static const struct file_operations topology_name_fops = {
849 	.open = simple_open,
850 	.read = topology_name_read,
851 	.llseek = default_llseek,
852 };
853 
avs_component_load_libraries(struct avs_soc_component * acomp)854 static int avs_component_load_libraries(struct avs_soc_component *acomp)
855 {
856 	struct avs_tplg *tplg = acomp->tplg;
857 	struct avs_dev *adev = to_avs_dev(acomp->base.dev);
858 	int ret;
859 
860 	if (!tplg->num_libs)
861 		return 0;
862 
863 	/* Parent device may be asleep and library loading involves IPCs. */
864 	ret = pm_runtime_resume_and_get(adev->dev);
865 	if (ret < 0)
866 		return ret;
867 
868 	avs_hda_power_gating_enable(adev, false);
869 	avs_hda_clock_gating_enable(adev, false);
870 	avs_hda_l1sen_enable(adev, false);
871 
872 	ret = avs_dsp_load_libraries(adev, tplg->libs, tplg->num_libs);
873 
874 	avs_hda_l1sen_enable(adev, true);
875 	avs_hda_clock_gating_enable(adev, true);
876 	avs_hda_power_gating_enable(adev, true);
877 
878 	if (!ret)
879 		ret = avs_module_info_init(adev, false);
880 
881 	pm_runtime_mark_last_busy(adev->dev);
882 	pm_runtime_put_autosuspend(adev->dev);
883 
884 	return ret;
885 }
886 
avs_component_probe(struct snd_soc_component * component)887 static int avs_component_probe(struct snd_soc_component *component)
888 {
889 	struct snd_soc_card *card = component->card;
890 	struct snd_soc_acpi_mach *mach;
891 	struct avs_soc_component *acomp;
892 	struct avs_dev *adev;
893 	char *filename;
894 	int ret;
895 
896 	dev_dbg(card->dev, "probing %s card %s\n", component->name, card->name);
897 	mach = dev_get_platdata(card->dev);
898 	acomp = to_avs_soc_component(component);
899 	adev = to_avs_dev(component->dev);
900 
901 	acomp->tplg = avs_tplg_new(component);
902 	if (!acomp->tplg)
903 		return -ENOMEM;
904 
905 	if (!mach->tplg_filename)
906 		goto finalize;
907 
908 	/* Load specified topology and create debugfs for it. */
909 	filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
910 			     mach->tplg_filename);
911 	if (!filename)
912 		return -ENOMEM;
913 
914 	ret = avs_load_topology(component, filename);
915 	kfree(filename);
916 	if (ret == -ENOENT && !strncmp(mach->tplg_filename, "hda-", 4)) {
917 		unsigned int vendor_id;
918 
919 		if (sscanf(mach->tplg_filename, "hda-%08x-tplg.bin", &vendor_id) != 1)
920 			return ret;
921 
922 		if (((vendor_id >> 16) & 0xFFFF) == 0x8086)
923 			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
924 							     "hda-8086-generic-tplg.bin");
925 		else
926 			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
927 							     "hda-generic-tplg.bin");
928 		if (!mach->tplg_filename)
929 			return -ENOMEM;
930 		filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
931 				     mach->tplg_filename);
932 		if (!filename)
933 			return -ENOMEM;
934 
935 		dev_info(card->dev, "trying to load fallback topology %s\n", mach->tplg_filename);
936 		ret = avs_load_topology(component, filename);
937 		kfree(filename);
938 	}
939 	if (ret < 0)
940 		return ret;
941 
942 	ret = avs_component_load_libraries(acomp);
943 	if (ret < 0) {
944 		dev_err(card->dev, "libraries loading failed: %d\n", ret);
945 		goto err_load_libs;
946 	}
947 
948 finalize:
949 	debugfs_create_file("topology_name", 0444, component->debugfs_root, component,
950 			    &topology_name_fops);
951 
952 	mutex_lock(&adev->comp_list_mutex);
953 	list_add_tail(&acomp->node, &adev->comp_list);
954 	mutex_unlock(&adev->comp_list_mutex);
955 
956 	return 0;
957 
958 err_load_libs:
959 	avs_remove_topology(component);
960 	return ret;
961 }
962 
avs_component_remove(struct snd_soc_component * component)963 static void avs_component_remove(struct snd_soc_component *component)
964 {
965 	struct avs_soc_component *acomp = to_avs_soc_component(component);
966 	struct snd_soc_acpi_mach *mach;
967 	struct avs_dev *adev = to_avs_dev(component->dev);
968 	int ret;
969 
970 	mach = dev_get_platdata(component->card->dev);
971 
972 	mutex_lock(&adev->comp_list_mutex);
973 	list_del(&acomp->node);
974 	mutex_unlock(&adev->comp_list_mutex);
975 
976 	if (mach->tplg_filename) {
977 		ret = avs_remove_topology(component);
978 		if (ret < 0)
979 			dev_err(component->dev, "unload topology failed: %d\n", ret);
980 	}
981 }
982 
avs_dai_resume_hw_params(struct snd_soc_dai * dai,struct avs_dma_data * data)983 static int avs_dai_resume_hw_params(struct snd_soc_dai *dai, struct avs_dma_data *data)
984 {
985 	struct snd_pcm_substream *substream;
986 	struct snd_soc_pcm_runtime *rtd;
987 	int ret;
988 
989 	substream = data->substream;
990 	rtd = snd_soc_substream_to_rtd(substream);
991 
992 	ret = dai->driver->ops->hw_params(substream, &rtd->dpcm[substream->stream].hw_params, dai);
993 	if (ret)
994 		dev_err(dai->dev, "hw_params on resume failed: %d\n", ret);
995 
996 	return ret;
997 }
998 
avs_dai_resume_fe_prepare(struct snd_soc_dai * dai,struct avs_dma_data * data)999 static int avs_dai_resume_fe_prepare(struct snd_soc_dai *dai, struct avs_dma_data *data)
1000 {
1001 	struct hdac_ext_stream *host_stream;
1002 	struct hdac_stream *hstream;
1003 	struct hdac_bus *bus;
1004 	int ret;
1005 
1006 	host_stream = data->host_stream;
1007 	hstream = hdac_stream(host_stream);
1008 	bus = hdac_stream(host_stream)->bus;
1009 
1010 	/* Set DRSM before programming stream and position registers. */
1011 	snd_hdac_stream_drsm_enable(bus, true, hstream->index);
1012 
1013 	ret = dai->driver->ops->prepare(data->substream, dai);
1014 	if (ret) {
1015 		dev_err(dai->dev, "prepare FE on resume failed: %d\n", ret);
1016 		return ret;
1017 	}
1018 
1019 	writel(host_stream->pphcllpl, host_stream->pphc_addr + AZX_REG_PPHCLLPL);
1020 	writel(host_stream->pphcllpu, host_stream->pphc_addr + AZX_REG_PPHCLLPU);
1021 	writel(host_stream->pphcldpl, host_stream->pphc_addr + AZX_REG_PPHCLDPL);
1022 	writel(host_stream->pphcldpu, host_stream->pphc_addr + AZX_REG_PPHCLDPU);
1023 
1024 	/* As per HW spec recommendation, program LPIB and DPIB to the same value. */
1025 	snd_hdac_stream_set_lpib(hstream, hstream->lpib);
1026 	snd_hdac_stream_set_dpibr(bus, hstream, hstream->lpib);
1027 
1028 	return 0;
1029 }
1030 
avs_dai_resume_be_prepare(struct snd_soc_dai * dai,struct avs_dma_data * data)1031 static int avs_dai_resume_be_prepare(struct snd_soc_dai *dai, struct avs_dma_data *data)
1032 {
1033 	int ret;
1034 
1035 	ret = dai->driver->ops->prepare(data->substream, dai);
1036 	if (ret)
1037 		dev_err(dai->dev, "prepare BE on resume failed: %d\n", ret);
1038 
1039 	return ret;
1040 }
1041 
avs_dai_suspend_fe_hw_free(struct snd_soc_dai * dai,struct avs_dma_data * data)1042 static int avs_dai_suspend_fe_hw_free(struct snd_soc_dai *dai, struct avs_dma_data *data)
1043 {
1044 	struct hdac_ext_stream *host_stream;
1045 	int ret;
1046 
1047 	host_stream = data->host_stream;
1048 
1049 	/* Store position addresses so we can resume from them later on. */
1050 	hdac_stream(host_stream)->lpib = snd_hdac_stream_get_pos_lpib(hdac_stream(host_stream));
1051 	host_stream->pphcllpl = readl(host_stream->pphc_addr + AZX_REG_PPHCLLPL);
1052 	host_stream->pphcllpu = readl(host_stream->pphc_addr + AZX_REG_PPHCLLPU);
1053 	host_stream->pphcldpl = readl(host_stream->pphc_addr + AZX_REG_PPHCLDPL);
1054 	host_stream->pphcldpu = readl(host_stream->pphc_addr + AZX_REG_PPHCLDPU);
1055 
1056 	ret = __avs_dai_fe_hw_free(data->substream, dai);
1057 	if (ret < 0)
1058 		dev_err(dai->dev, "hw_free FE on suspend failed: %d\n", ret);
1059 
1060 	return ret;
1061 }
1062 
avs_dai_suspend_be_hw_free(struct snd_soc_dai * dai,struct avs_dma_data * data)1063 static int avs_dai_suspend_be_hw_free(struct snd_soc_dai *dai, struct avs_dma_data *data)
1064 {
1065 	int ret;
1066 
1067 	ret = dai->driver->ops->hw_free(data->substream, dai);
1068 	if (ret < 0)
1069 		dev_err(dai->dev, "hw_free BE on suspend failed: %d\n", ret);
1070 
1071 	return ret;
1072 }
1073 
avs_component_pm_op(struct snd_soc_component * component,bool be,int (* op)(struct snd_soc_dai *,struct avs_dma_data *))1074 static int avs_component_pm_op(struct snd_soc_component *component, bool be,
1075 			       int (*op)(struct snd_soc_dai *, struct avs_dma_data *))
1076 {
1077 	struct snd_soc_pcm_runtime *rtd;
1078 	struct avs_dma_data *data;
1079 	struct snd_soc_dai *dai;
1080 	int ret;
1081 
1082 	for_each_component_dais(component, dai) {
1083 		data = snd_soc_dai_dma_data_get_playback(dai);
1084 		if (data) {
1085 			rtd = snd_soc_substream_to_rtd(data->substream);
1086 			if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) {
1087 				ret = op(dai, data);
1088 				if (ret < 0) {
1089 					__snd_pcm_set_state(data->substream->runtime,
1090 							    SNDRV_PCM_STATE_DISCONNECTED);
1091 					return ret;
1092 				}
1093 			}
1094 		}
1095 
1096 		data = snd_soc_dai_dma_data_get_capture(dai);
1097 		if (data) {
1098 			rtd = snd_soc_substream_to_rtd(data->substream);
1099 			if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) {
1100 				ret = op(dai, data);
1101 				if (ret < 0) {
1102 					__snd_pcm_set_state(data->substream->runtime,
1103 							    SNDRV_PCM_STATE_DISCONNECTED);
1104 					return ret;
1105 				}
1106 			}
1107 		}
1108 	}
1109 
1110 	return 0;
1111 }
1112 
avs_component_resume_hw_params(struct snd_soc_component * component,bool be)1113 static int avs_component_resume_hw_params(struct snd_soc_component *component, bool be)
1114 {
1115 	return avs_component_pm_op(component, be, &avs_dai_resume_hw_params);
1116 }
1117 
avs_component_resume_prepare(struct snd_soc_component * component,bool be)1118 static int avs_component_resume_prepare(struct snd_soc_component *component, bool be)
1119 {
1120 	int (*prepare_cb)(struct snd_soc_dai *dai, struct avs_dma_data *data);
1121 
1122 	if (be)
1123 		prepare_cb = &avs_dai_resume_be_prepare;
1124 	else
1125 		prepare_cb = &avs_dai_resume_fe_prepare;
1126 
1127 	return avs_component_pm_op(component, be, prepare_cb);
1128 }
1129 
avs_component_suspend_hw_free(struct snd_soc_component * component,bool be)1130 static int avs_component_suspend_hw_free(struct snd_soc_component *component, bool be)
1131 {
1132 	int (*hw_free_cb)(struct snd_soc_dai *dai, struct avs_dma_data *data);
1133 
1134 	if (be)
1135 		hw_free_cb = &avs_dai_suspend_be_hw_free;
1136 	else
1137 		hw_free_cb = &avs_dai_suspend_fe_hw_free;
1138 
1139 	return avs_component_pm_op(component, be, hw_free_cb);
1140 }
1141 
avs_component_suspend(struct snd_soc_component * component)1142 static int avs_component_suspend(struct snd_soc_component *component)
1143 {
1144 	int ret;
1145 
1146 	/*
1147 	 * When freeing paths, FEs need to be first as they perform
1148 	 * path unbinding.
1149 	 */
1150 	ret = avs_component_suspend_hw_free(component, false);
1151 	if (ret)
1152 		return ret;
1153 
1154 	return avs_component_suspend_hw_free(component, true);
1155 }
1156 
avs_component_resume(struct snd_soc_component * component)1157 static int avs_component_resume(struct snd_soc_component *component)
1158 {
1159 	int ret;
1160 
1161 	/*
1162 	 * When creating paths, FEs need to be last as they perform
1163 	 * path binding.
1164 	 */
1165 	ret = avs_component_resume_hw_params(component, true);
1166 	if (ret)
1167 		return ret;
1168 
1169 	ret = avs_component_resume_hw_params(component, false);
1170 	if (ret)
1171 		return ret;
1172 
1173 	/* It is expected that the LINK stream is prepared first. */
1174 	ret = avs_component_resume_prepare(component, true);
1175 	if (ret)
1176 		return ret;
1177 
1178 	return avs_component_resume_prepare(component, false);
1179 }
1180 
1181 static const struct snd_pcm_hardware avs_pcm_hardware = {
1182 	.info			= SNDRV_PCM_INFO_MMAP |
1183 				  SNDRV_PCM_INFO_MMAP_VALID |
1184 				  SNDRV_PCM_INFO_INTERLEAVED |
1185 				  SNDRV_PCM_INFO_PAUSE |
1186 				  SNDRV_PCM_INFO_RESUME |
1187 				  SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
1188 	.formats		= SNDRV_PCM_FMTBIT_S16_LE |
1189 				  SNDRV_PCM_FMTBIT_S32_LE,
1190 	.subformats		= SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1191 				  SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1192 				  SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1193 	.buffer_bytes_max	= AZX_MAX_BUF_SIZE,
1194 	.period_bytes_min	= 128,
1195 	.period_bytes_max	= AZX_MAX_BUF_SIZE / 2,
1196 	.periods_min		= 2,
1197 	.periods_max		= AZX_MAX_FRAG,
1198 	.fifo_size		= 0,
1199 };
1200 
avs_component_open(struct snd_soc_component * component,struct snd_pcm_substream * substream)1201 static int avs_component_open(struct snd_soc_component *component,
1202 			      struct snd_pcm_substream *substream)
1203 {
1204 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
1205 
1206 	/* only FE DAI links are handled here */
1207 	if (rtd->dai_link->no_pcm)
1208 		return 0;
1209 
1210 	return snd_soc_set_runtime_hwparams(substream, &avs_pcm_hardware);
1211 }
1212 
avs_hda_stream_dpib_read(struct hdac_ext_stream * stream)1213 static unsigned int avs_hda_stream_dpib_read(struct hdac_ext_stream *stream)
1214 {
1215 	return readl(hdac_stream(stream)->bus->remap_addr + AZX_REG_VS_SDXDPIB_XBASE +
1216 		     (AZX_REG_VS_SDXDPIB_XINTERVAL * hdac_stream(stream)->index));
1217 }
1218 
1219 static snd_pcm_uframes_t
avs_component_pointer(struct snd_soc_component * component,struct snd_pcm_substream * substream)1220 avs_component_pointer(struct snd_soc_component *component, struct snd_pcm_substream *substream)
1221 {
1222 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
1223 	struct avs_dma_data *data;
1224 	struct hdac_ext_stream *host_stream;
1225 	unsigned int pos;
1226 
1227 	data = snd_soc_dai_get_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream);
1228 	if (!data->host_stream)
1229 		return 0;
1230 
1231 	host_stream = data->host_stream;
1232 	pos = avs_hda_stream_dpib_read(host_stream);
1233 
1234 	if (pos >= hdac_stream(host_stream)->bufsize)
1235 		pos = 0;
1236 
1237 	return bytes_to_frames(substream->runtime, pos);
1238 }
1239 
avs_component_mmap(struct snd_soc_component * component,struct snd_pcm_substream * substream,struct vm_area_struct * vma)1240 static int avs_component_mmap(struct snd_soc_component *component,
1241 			      struct snd_pcm_substream *substream,
1242 			      struct vm_area_struct *vma)
1243 {
1244 	return snd_pcm_lib_default_mmap(substream, vma);
1245 }
1246 
1247 #define MAX_PREALLOC_SIZE	(32 * 1024 * 1024)
1248 
avs_component_construct(struct snd_soc_component * component,struct snd_soc_pcm_runtime * rtd)1249 static int avs_component_construct(struct snd_soc_component *component,
1250 				   struct snd_soc_pcm_runtime *rtd)
1251 {
1252 	struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
1253 	struct snd_pcm *pcm = rtd->pcm;
1254 
1255 	if (dai->driver->playback.channels_min)
1256 		snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
1257 					   SNDRV_DMA_TYPE_DEV_SG, component->dev, 0,
1258 					   MAX_PREALLOC_SIZE);
1259 
1260 	if (dai->driver->capture.channels_min)
1261 		snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
1262 					   SNDRV_DMA_TYPE_DEV_SG, component->dev, 0,
1263 					   MAX_PREALLOC_SIZE);
1264 
1265 	return 0;
1266 }
1267 
1268 static const struct snd_soc_component_driver avs_component_driver = {
1269 	.name			= "avs-pcm",
1270 	.probe			= avs_component_probe,
1271 	.remove			= avs_component_remove,
1272 	.suspend		= avs_component_suspend,
1273 	.resume			= avs_component_resume,
1274 	.open			= avs_component_open,
1275 	.pointer		= avs_component_pointer,
1276 	.mmap			= avs_component_mmap,
1277 	.pcm_construct		= avs_component_construct,
1278 	.module_get_upon_open	= 1, /* increment refcount when a pcm is opened */
1279 	.topology_name_prefix	= "intel/avs",
1280 };
1281 
avs_soc_component_register(struct device * dev,const char * name,const struct snd_soc_component_driver * drv,struct snd_soc_dai_driver * cpu_dais,int num_cpu_dais)1282 int avs_soc_component_register(struct device *dev, const char *name,
1283 			       const struct snd_soc_component_driver *drv,
1284 			       struct snd_soc_dai_driver *cpu_dais, int num_cpu_dais)
1285 {
1286 	struct avs_soc_component *acomp;
1287 	int ret;
1288 
1289 	acomp = devm_kzalloc(dev, sizeof(*acomp), GFP_KERNEL);
1290 	if (!acomp)
1291 		return -ENOMEM;
1292 
1293 	ret = snd_soc_component_initialize(&acomp->base, drv, dev);
1294 	if (ret < 0)
1295 		return ret;
1296 
1297 	/* force name change after ASoC is done with its init */
1298 	acomp->base.name = name;
1299 	INIT_LIST_HEAD(&acomp->node);
1300 
1301 	return snd_soc_add_component(&acomp->base, cpu_dais, num_cpu_dais);
1302 }
1303 
1304 static struct snd_soc_dai_driver dmic_cpu_dais[] = {
1305 {
1306 	.name = "DMIC Pin",
1307 	.ops = &avs_dai_nonhda_be_ops,
1308 	.capture = {
1309 		.stream_name	= "DMIC Rx",
1310 		.channels_min	= 1,
1311 		.channels_max	= 4,
1312 		.rates		= SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_48000,
1313 		.formats	= SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
1314 	},
1315 },
1316 {
1317 	.name = "DMIC WoV Pin",
1318 	.ops = &avs_dai_nonhda_be_ops,
1319 	.capture = {
1320 		.stream_name	= "DMIC WoV Rx",
1321 		.channels_min	= 1,
1322 		.channels_max	= 4,
1323 		.rates		= SNDRV_PCM_RATE_16000,
1324 		.formats	= SNDRV_PCM_FMTBIT_S16_LE,
1325 	},
1326 },
1327 };
1328 
avs_dmic_platform_register(struct avs_dev * adev,const char * name)1329 int avs_dmic_platform_register(struct avs_dev *adev, const char *name)
1330 {
1331 	return avs_soc_component_register(adev->dev, name, &avs_component_driver, dmic_cpu_dais,
1332 					  ARRAY_SIZE(dmic_cpu_dais));
1333 }
1334 
1335 static const struct snd_soc_dai_driver i2s_dai_template = {
1336 	.ops = &avs_dai_nonhda_be_ops,
1337 	.playback = {
1338 		.channels_min	= 1,
1339 		.channels_max	= 8,
1340 		.rates		= SNDRV_PCM_RATE_8000_192000 |
1341 				  SNDRV_PCM_RATE_12000 |
1342 				  SNDRV_PCM_RATE_24000 |
1343 				  SNDRV_PCM_RATE_128000,
1344 		.formats	= SNDRV_PCM_FMTBIT_S16_LE |
1345 				  SNDRV_PCM_FMTBIT_S32_LE,
1346 		.subformats	= SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1347 				  SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1348 				  SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1349 	},
1350 	.capture = {
1351 		.channels_min	= 1,
1352 		.channels_max	= 8,
1353 		.rates		= SNDRV_PCM_RATE_8000_192000 |
1354 				  SNDRV_PCM_RATE_12000 |
1355 				  SNDRV_PCM_RATE_24000 |
1356 				  SNDRV_PCM_RATE_128000,
1357 		.formats	= SNDRV_PCM_FMTBIT_S16_LE |
1358 				  SNDRV_PCM_FMTBIT_S32_LE,
1359 		.subformats	= SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1360 				  SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1361 				  SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1362 	},
1363 };
1364 
avs_i2s_platform_register(struct avs_dev * adev,const char * name,unsigned long port_mask,unsigned long * tdms)1365 int avs_i2s_platform_register(struct avs_dev *adev, const char *name, unsigned long port_mask,
1366 			      unsigned long *tdms)
1367 {
1368 	struct snd_soc_dai_driver *cpus, *dai;
1369 	size_t ssp_count, cpu_count;
1370 	int i, j;
1371 
1372 	ssp_count = adev->hw_cfg.i2s_caps.ctrl_count;
1373 
1374 	cpu_count = 0;
1375 	for_each_set_bit(i, &port_mask, ssp_count)
1376 		if (!tdms || test_bit(0, &tdms[i]))
1377 			cpu_count++;
1378 	if (tdms)
1379 		for_each_set_bit(i, &port_mask, ssp_count)
1380 			cpu_count += hweight_long(tdms[i]);
1381 
1382 	cpus = devm_kzalloc(adev->dev, sizeof(*cpus) * cpu_count, GFP_KERNEL);
1383 	if (!cpus)
1384 		return -ENOMEM;
1385 
1386 	dai = cpus;
1387 	for_each_set_bit(i, &port_mask, ssp_count) {
1388 		if (!tdms || test_bit(0, &tdms[i])) {
1389 			memcpy(dai, &i2s_dai_template, sizeof(*dai));
1390 
1391 			dai->name =
1392 				devm_kasprintf(adev->dev, GFP_KERNEL, "SSP%d Pin", i);
1393 			dai->playback.stream_name =
1394 				devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d Tx", i);
1395 			dai->capture.stream_name =
1396 				devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d Rx", i);
1397 
1398 			if (!dai->name || !dai->playback.stream_name || !dai->capture.stream_name)
1399 				return -ENOMEM;
1400 			dai++;
1401 		}
1402 	}
1403 
1404 	if (!tdms)
1405 		goto plat_register;
1406 
1407 	for_each_set_bit(i, &port_mask, ssp_count) {
1408 		for_each_set_bit(j, &tdms[i], ssp_count) {
1409 			memcpy(dai, &i2s_dai_template, sizeof(*dai));
1410 
1411 			dai->name =
1412 				devm_kasprintf(adev->dev, GFP_KERNEL, "SSP%d:%d Pin", i, j);
1413 			dai->playback.stream_name =
1414 				devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d:%d Tx", i, j);
1415 			dai->capture.stream_name =
1416 				devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d:%d Rx", i, j);
1417 
1418 			if (!dai->name || !dai->playback.stream_name || !dai->capture.stream_name)
1419 				return -ENOMEM;
1420 			dai++;
1421 		}
1422 	}
1423 
1424 plat_register:
1425 	return avs_soc_component_register(adev->dev, name, &avs_component_driver, cpus, cpu_count);
1426 }
1427 
1428 /* HD-Audio CPU DAI template */
1429 static const struct snd_soc_dai_driver hda_cpu_dai = {
1430 	.ops = &avs_dai_hda_be_ops,
1431 	.playback = {
1432 		.channels_min	= 1,
1433 		.channels_max	= 8,
1434 		.rates		= SNDRV_PCM_RATE_8000_192000,
1435 		.formats	= SNDRV_PCM_FMTBIT_S16_LE |
1436 				  SNDRV_PCM_FMTBIT_S32_LE,
1437 		.subformats	= SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1438 				  SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1439 				  SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1440 	},
1441 	.capture = {
1442 		.channels_min	= 1,
1443 		.channels_max	= 8,
1444 		.rates		= SNDRV_PCM_RATE_8000_192000,
1445 		.formats	= SNDRV_PCM_FMTBIT_S16_LE |
1446 				  SNDRV_PCM_FMTBIT_S32_LE,
1447 		.subformats	= SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1448 				  SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1449 				  SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1450 	},
1451 };
1452 
avs_component_hda_unregister_dais(struct snd_soc_component * component)1453 static void avs_component_hda_unregister_dais(struct snd_soc_component *component)
1454 {
1455 	struct snd_soc_acpi_mach *mach;
1456 	struct snd_soc_dai *dai, *save;
1457 	struct hda_codec *codec;
1458 	char name[32];
1459 
1460 	mach = dev_get_platdata(component->card->dev);
1461 	codec = mach->pdata;
1462 	snprintf(name, sizeof(name), "%s-cpu", dev_name(&codec->core.dev));
1463 
1464 	for_each_component_dais_safe(component, dai, save) {
1465 		int stream;
1466 
1467 		if (!strstr(dai->driver->name, name))
1468 			continue;
1469 
1470 		for_each_pcm_streams(stream)
1471 			snd_soc_dapm_free_widget(snd_soc_dai_get_widget(dai, stream));
1472 
1473 		snd_soc_unregister_dai(dai);
1474 	}
1475 }
1476 
avs_component_hda_probe(struct snd_soc_component * component)1477 static int avs_component_hda_probe(struct snd_soc_component *component)
1478 {
1479 	struct snd_soc_dapm_context *dapm;
1480 	struct snd_soc_dai_driver *dais;
1481 	struct snd_soc_acpi_mach *mach;
1482 	struct hda_codec *codec;
1483 	struct hda_pcm *pcm;
1484 	const char *cname;
1485 	int pcm_count = 0, ret, i;
1486 
1487 	mach = dev_get_platdata(component->card->dev);
1488 	if (!mach)
1489 		return -EINVAL;
1490 
1491 	codec = mach->pdata;
1492 	if (list_empty(&codec->pcm_list_head))
1493 		return -EINVAL;
1494 	list_for_each_entry(pcm, &codec->pcm_list_head, list)
1495 		pcm_count++;
1496 
1497 	dais = devm_kcalloc(component->dev, pcm_count, sizeof(*dais),
1498 			    GFP_KERNEL);
1499 	if (!dais)
1500 		return -ENOMEM;
1501 
1502 	cname = dev_name(&codec->core.dev);
1503 	dapm = snd_soc_component_get_dapm(component);
1504 	pcm = list_first_entry(&codec->pcm_list_head, struct hda_pcm, list);
1505 
1506 	for (i = 0; i < pcm_count; i++, pcm = list_next_entry(pcm, list)) {
1507 		struct snd_soc_dai *dai;
1508 
1509 		memcpy(&dais[i], &hda_cpu_dai, sizeof(*dais));
1510 		dais[i].id = i;
1511 		dais[i].name = devm_kasprintf(component->dev, GFP_KERNEL,
1512 					      "%s-cpu%d", cname, i);
1513 		if (!dais[i].name) {
1514 			ret = -ENOMEM;
1515 			goto exit;
1516 		}
1517 
1518 		if (pcm->stream[0].substreams) {
1519 			dais[i].playback.stream_name =
1520 				devm_kasprintf(component->dev, GFP_KERNEL,
1521 					       "%s-cpu%d Tx", cname, i);
1522 			if (!dais[i].playback.stream_name) {
1523 				ret = -ENOMEM;
1524 				goto exit;
1525 			}
1526 
1527 			if (!hda_codec_is_display(codec)) {
1528 				dais[i].playback.formats = pcm->stream[0].formats;
1529 				dais[i].playback.subformats = pcm->stream[0].subformats;
1530 				dais[i].playback.rates = pcm->stream[0].rates;
1531 				dais[i].playback.channels_min = pcm->stream[0].channels_min;
1532 				dais[i].playback.channels_max = pcm->stream[0].channels_max;
1533 				dais[i].playback.sig_bits = pcm->stream[0].maxbps;
1534 			}
1535 		}
1536 
1537 		if (pcm->stream[1].substreams) {
1538 			dais[i].capture.stream_name =
1539 				devm_kasprintf(component->dev, GFP_KERNEL,
1540 					       "%s-cpu%d Rx", cname, i);
1541 			if (!dais[i].capture.stream_name) {
1542 				ret = -ENOMEM;
1543 				goto exit;
1544 			}
1545 
1546 			if (!hda_codec_is_display(codec)) {
1547 				dais[i].capture.formats = pcm->stream[1].formats;
1548 				dais[i].capture.subformats = pcm->stream[1].subformats;
1549 				dais[i].capture.rates = pcm->stream[1].rates;
1550 				dais[i].capture.channels_min = pcm->stream[1].channels_min;
1551 				dais[i].capture.channels_max = pcm->stream[1].channels_max;
1552 				dais[i].capture.sig_bits = pcm->stream[1].maxbps;
1553 			}
1554 		}
1555 
1556 		dai = snd_soc_register_dai(component, &dais[i], false);
1557 		if (!dai) {
1558 			dev_err(component->dev, "register dai for %s failed\n",
1559 				pcm->name);
1560 			ret = -EINVAL;
1561 			goto exit;
1562 		}
1563 
1564 		ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1565 		if (ret < 0) {
1566 			dev_err(component->dev, "create widgets failed: %d\n",
1567 				ret);
1568 			goto exit;
1569 		}
1570 	}
1571 
1572 	ret = avs_component_probe(component);
1573 exit:
1574 	if (ret)
1575 		avs_component_hda_unregister_dais(component);
1576 
1577 	return ret;
1578 }
1579 
avs_component_hda_remove(struct snd_soc_component * component)1580 static void avs_component_hda_remove(struct snd_soc_component *component)
1581 {
1582 	avs_component_hda_unregister_dais(component);
1583 	avs_component_remove(component);
1584 }
1585 
avs_component_hda_open(struct snd_soc_component * component,struct snd_pcm_substream * substream)1586 static int avs_component_hda_open(struct snd_soc_component *component,
1587 				  struct snd_pcm_substream *substream)
1588 {
1589 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
1590 
1591 	if (!rtd->dai_link->no_pcm) {
1592 		struct snd_pcm_hardware hwparams = avs_pcm_hardware;
1593 		struct snd_soc_pcm_runtime *be;
1594 		struct snd_soc_dpcm *dpcm;
1595 		int dir = substream->stream;
1596 
1597 		/*
1598 		 * Support the DPCM reparenting while still fulfilling expectations of HDAudio
1599 		 * common code - a valid stream pointer at substream->runtime->private_data -
1600 		 * by having all FEs point to the same private data.
1601 		 */
1602 		for_each_dpcm_be(rtd, dir, dpcm) {
1603 			struct snd_pcm_substream *be_substream;
1604 
1605 			be = dpcm->be;
1606 			if (be->dpcm[dir].users == 1)
1607 				break;
1608 
1609 			be_substream = snd_soc_dpcm_get_substream(be, dir);
1610 			substream->runtime->private_data = be_substream->runtime->private_data;
1611 			break;
1612 		}
1613 
1614 		/* RESUME unsupported for de-coupled HD-Audio capture. */
1615 		if (dir == SNDRV_PCM_STREAM_CAPTURE)
1616 			hwparams.info &= ~SNDRV_PCM_INFO_RESUME;
1617 
1618 		return snd_soc_set_runtime_hwparams(substream, &hwparams);
1619 	}
1620 
1621 	return 0;
1622 }
1623 
1624 static const struct snd_soc_component_driver avs_hda_component_driver = {
1625 	.name			= "avs-hda-pcm",
1626 	.probe			= avs_component_hda_probe,
1627 	.remove			= avs_component_hda_remove,
1628 	.suspend		= avs_component_suspend,
1629 	.resume			= avs_component_resume,
1630 	.open			= avs_component_hda_open,
1631 	.pointer		= avs_component_pointer,
1632 	.mmap			= avs_component_mmap,
1633 	.pcm_construct		= avs_component_construct,
1634 	/*
1635 	 * hda platform component's probe() is dependent on
1636 	 * codec->pcm_list_head, it needs to be initialized after codec
1637 	 * component. remove_order is here for completeness sake
1638 	 */
1639 	.probe_order		= SND_SOC_COMP_ORDER_LATE,
1640 	.remove_order		= SND_SOC_COMP_ORDER_EARLY,
1641 	.module_get_upon_open	= 1,
1642 	.topology_name_prefix	= "intel/avs",
1643 };
1644 
avs_hda_platform_register(struct avs_dev * adev,const char * name)1645 int avs_hda_platform_register(struct avs_dev *adev, const char *name)
1646 {
1647 	return avs_soc_component_register(adev->dev, name,
1648 					  &avs_hda_component_driver, NULL, 0);
1649 }
1650