1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
11 #include <linux/firmware.h>
12 #include <sound/tlv.h>
13 #include <sound/pcm_params.h>
14 #include <uapi/sound/sof/tokens.h>
18 #define COMP_ID_UNASSIGNED 0xffffffff
20 * Constants used in the computation of linear volume gain
21 * from dB gain 20th root of 10 in Q1.16 fixed-point notation
23 #define VOL_TWENTIETH_ROOT_OF_TEN 73533
24 /* 40th root of 10 in Q1.16 fixed-point notation*/
25 #define VOL_FORTIETH_ROOT_OF_TEN 69419
27 * Volume fractional word length define to 16 sets
28 * the volume linear gain value to use Qx.16 format
31 /* 0.5 dB step value in topology TLV */
32 #define VOL_HALF_DB_STEP 50
33 /* Full volume for default values */
34 #define VOL_ZERO_DB BIT(VOLUME_FWL)
42 /* size of tplg abi in byte */
43 #define SOF_TPLG_ABI_SIZE 3
45 /* send pcm params ipc */
46 static int ipc_pcm_params(struct snd_sof_widget *swidget, int dir)
48 struct sof_ipc_pcm_params_reply ipc_params_reply;
49 struct snd_sof_dev *sdev = swidget->sdev;
50 struct sof_ipc_pcm_params pcm;
51 struct snd_pcm_hw_params *params;
52 struct snd_sof_pcm *spcm;
55 memset(&pcm, 0, sizeof(pcm));
57 /* get runtime PCM params using widget's stream name */
58 spcm = snd_sof_find_spcm_name(sdev, swidget->widget->sname);
60 dev_err(sdev->dev, "error: cannot find PCM for %s\n",
61 swidget->widget->name);
65 params = &spcm->params[dir];
67 /* set IPC PCM params */
68 pcm.hdr.size = sizeof(pcm);
69 pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS;
70 pcm.comp_id = swidget->comp_id;
71 pcm.params.hdr.size = sizeof(pcm.params);
72 pcm.params.direction = dir;
73 pcm.params.sample_valid_bytes = params_width(params) >> 3;
74 pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
75 pcm.params.rate = params_rate(params);
76 pcm.params.channels = params_channels(params);
77 pcm.params.host_period_bytes = params_period_bytes(params);
80 switch (params_format(params)) {
81 case SNDRV_PCM_FORMAT_S16:
82 pcm.params.frame_fmt = SOF_IPC_FRAME_S16_LE;
84 case SNDRV_PCM_FORMAT_S24:
85 pcm.params.frame_fmt = SOF_IPC_FRAME_S24_4LE;
87 case SNDRV_PCM_FORMAT_S32:
88 pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE;
94 /* send IPC to the DSP */
95 ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm),
96 &ipc_params_reply, sizeof(ipc_params_reply));
98 dev_err(sdev->dev, "error: pcm params failed for %s\n",
99 swidget->widget->name);
104 /* send stream trigger ipc */
105 static int ipc_trigger(struct snd_sof_widget *swidget, int cmd)
107 struct snd_sof_dev *sdev = swidget->sdev;
108 struct sof_ipc_stream stream;
109 struct sof_ipc_reply reply;
112 /* set IPC stream params */
113 stream.hdr.size = sizeof(stream);
114 stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | cmd;
115 stream.comp_id = swidget->comp_id;
117 /* send IPC to the DSP */
118 ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
119 sizeof(stream), &reply, sizeof(reply));
121 dev_err(sdev->dev, "error: failed to trigger %s\n",
122 swidget->widget->name);
127 static int sof_keyword_dapm_event(struct snd_soc_dapm_widget *w,
128 struct snd_kcontrol *k, int event)
130 struct snd_sof_widget *swidget = w->dobj.private;
131 struct snd_sof_dev *sdev;
137 sdev = swidget->sdev;
139 dev_dbg(sdev->dev, "received event %d for widget %s\n",
144 case SND_SOC_DAPM_PRE_PMU:
146 ret = ipc_pcm_params(swidget, SOF_IPC_STREAM_CAPTURE);
149 "error: failed to set pcm params for widget %s\n",
150 swidget->widget->name);
155 ret = ipc_trigger(swidget, SOF_IPC_STREAM_TRIG_START);
158 "error: failed to trigger widget %s\n",
159 swidget->widget->name);
161 case SND_SOC_DAPM_POST_PMD:
163 ret = ipc_trigger(swidget, SOF_IPC_STREAM_TRIG_STOP);
166 "error: failed to trigger widget %s\n",
167 swidget->widget->name);
170 ret = ipc_trigger(swidget, SOF_IPC_STREAM_PCM_FREE);
173 "error: failed to trigger widget %s\n",
174 swidget->widget->name);
183 /* event handlers for keyword detect component */
184 static const struct snd_soc_tplg_widget_events sof_kwd_events[] = {
185 {SOF_KEYWORD_DETECT_DAPM_EVENT, sof_keyword_dapm_event},
188 static inline int get_tlv_data(const int *p, int tlv[TLV_ITEMS])
190 /* we only support dB scale TLV type at the moment */
191 if ((int)p[SNDRV_CTL_TLVO_TYPE] != SNDRV_CTL_TLVT_DB_SCALE)
194 /* min value in topology tlv data is multiplied by 100 */
195 tlv[TLV_MIN] = (int)p[SNDRV_CTL_TLVO_DB_SCALE_MIN] / 100;
198 tlv[TLV_STEP] = (int)(p[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] &
202 if ((p[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] &
203 TLV_DB_SCALE_MUTE) == 0)
212 * Function to truncate an unsigned 64-bit number
213 * by x bits and return 32-bit unsigned number. This
214 * function also takes care of rounding while truncating
216 static inline u32 vol_shift_64(u64 i, u32 x)
218 /* do not truncate more than 32 bits */
225 return (u32)(((i >> (x - 1)) + 1) >> 1);
229 * Function to compute a ^ exp where,
230 * a is a fractional number represented by a fixed-point
231 * integer with a fractional world length of "fwl"
233 * fwl is the fractional word length
234 * Return value is a fractional number represented by a
235 * fixed-point integer with a fractional word length of "fwl"
237 static u32 vol_pow32(u32 a, int exp, u32 fwl)
240 u32 power = 1 << fwl;
243 /* if exponent is 0, return 1 */
247 /* determine the number of iterations based on the exponent */
253 /* mutiply a "iter" times to compute power */
254 for (i = 0; i < iter; i++) {
256 * Product of 2 Qx.fwl fixed-point numbers yields a Q2*x.2*fwl
257 * Truncate product back to fwl fractional bits with rounding
259 power = vol_shift_64((u64)power * a, fwl);
263 /* if exp is positive, return the result */
267 /* if exp is negative, return the multiplicative inverse */
268 numerator = (u64)1 << (fwl << 1);
269 do_div(numerator, power);
271 return (u32)numerator;
275 * Function to calculate volume gain from TLV data.
276 * This function can only handle gain steps that are multiples of 0.5 dB
278 static u32 vol_compute_gain(u32 value, int *tlv)
285 if (value == 0 && tlv[TLV_MUTE])
289 * compute dB gain from tlv. tlv_step
290 * in topology is multiplied by 100
292 dB_gain = tlv[TLV_MIN] + (value * tlv[TLV_STEP]) / 100;
295 * compute linear gain represented by fixed-point
296 * int with VOLUME_FWL fractional bits
298 linear_gain = vol_pow32(VOL_TWENTIETH_ROOT_OF_TEN, dB_gain, VOLUME_FWL);
300 /* extract the fractional part of volume step */
301 f_step = tlv[TLV_STEP] - (tlv[TLV_STEP] / 100);
303 /* if volume step is an odd multiple of 0.5 dB */
304 if (f_step == VOL_HALF_DB_STEP && (value & 1))
305 linear_gain = vol_shift_64((u64)linear_gain *
306 VOL_FORTIETH_ROOT_OF_TEN,
313 * Set up volume table for kcontrols from tlv data
314 * "size" specifies the number of entries in the table
316 static int set_up_volume_table(struct snd_sof_control *scontrol,
317 int tlv[TLV_ITEMS], int size)
321 /* init the volume table */
322 scontrol->volume_table = kcalloc(size, sizeof(u32), GFP_KERNEL);
323 if (!scontrol->volume_table)
326 /* populate the volume table */
327 for (j = 0; j < size ; j++)
328 scontrol->volume_table[j] = vol_compute_gain(j, tlv);
333 struct sof_dai_types {
335 enum sof_ipc_dai_type type;
338 static const struct sof_dai_types sof_dais[] = {
339 {"SSP", SOF_DAI_INTEL_SSP},
340 {"HDA", SOF_DAI_INTEL_HDA},
341 {"DMIC", SOF_DAI_INTEL_DMIC},
344 static enum sof_ipc_dai_type find_dai(const char *name)
348 for (i = 0; i < ARRAY_SIZE(sof_dais); i++) {
349 if (strcmp(name, sof_dais[i].name) == 0)
350 return sof_dais[i].type;
353 return SOF_DAI_INTEL_NONE;
357 * Supported Frame format types and lookup, add new ones to end of list.
360 struct sof_frame_types {
362 enum sof_ipc_frame frame;
365 static const struct sof_frame_types sof_frames[] = {
366 {"s16le", SOF_IPC_FRAME_S16_LE},
367 {"s24le", SOF_IPC_FRAME_S24_4LE},
368 {"s32le", SOF_IPC_FRAME_S32_LE},
369 {"float", SOF_IPC_FRAME_FLOAT},
372 static enum sof_ipc_frame find_format(const char *name)
376 for (i = 0; i < ARRAY_SIZE(sof_frames); i++) {
377 if (strcmp(name, sof_frames[i].name) == 0)
378 return sof_frames[i].frame;
381 /* use s32le if nothing is specified */
382 return SOF_IPC_FRAME_S32_LE;
385 struct sof_process_types {
387 enum sof_ipc_process_type type;
388 enum sof_comp_type comp_type;
391 static const struct sof_process_types sof_process[] = {
392 {"EQFIR", SOF_PROCESS_EQFIR, SOF_COMP_EQ_FIR},
393 {"EQIIR", SOF_PROCESS_EQIIR, SOF_COMP_EQ_IIR},
394 {"KEYWORD_DETECT", SOF_PROCESS_KEYWORD_DETECT, SOF_COMP_KEYWORD_DETECT},
395 {"KPB", SOF_PROCESS_KPB, SOF_COMP_KPB},
396 {"CHAN_SELECTOR", SOF_PROCESS_CHAN_SELECTOR, SOF_COMP_SELECTOR},
399 static enum sof_ipc_process_type find_process(const char *name)
403 for (i = 0; i < ARRAY_SIZE(sof_process); i++) {
404 if (strcmp(name, sof_process[i].name) == 0)
405 return sof_process[i].type;
408 return SOF_PROCESS_NONE;
411 static enum sof_comp_type find_process_comp_type(enum sof_ipc_process_type type)
415 for (i = 0; i < ARRAY_SIZE(sof_process); i++) {
416 if (sof_process[i].type == type)
417 return sof_process[i].comp_type;
420 return SOF_COMP_NONE;
424 * Standard Kcontrols.
427 static int sof_control_load_volume(struct snd_soc_component *scomp,
428 struct snd_sof_control *scontrol,
429 struct snd_kcontrol_new *kc,
430 struct snd_soc_tplg_ctl_hdr *hdr)
432 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
433 struct snd_soc_tplg_mixer_control *mc =
434 container_of(hdr, struct snd_soc_tplg_mixer_control, hdr);
435 struct sof_ipc_ctrl_data *cdata;
440 /* validate topology data */
441 if (le32_to_cpu(mc->num_channels) > SND_SOC_TPLG_MAX_CHAN)
444 /* init the volume get/put data */
445 scontrol->size = sizeof(struct sof_ipc_ctrl_data) +
446 sizeof(struct sof_ipc_ctrl_value_chan) *
447 le32_to_cpu(mc->num_channels);
448 scontrol->control_data = kzalloc(scontrol->size, GFP_KERNEL);
449 if (!scontrol->control_data)
452 scontrol->comp_id = sdev->next_comp_id;
453 scontrol->num_channels = le32_to_cpu(mc->num_channels);
455 /* set cmd for mixer control */
456 if (le32_to_cpu(mc->max) == 1) {
457 scontrol->cmd = SOF_CTRL_CMD_SWITCH;
461 scontrol->cmd = SOF_CTRL_CMD_VOLUME;
463 /* extract tlv data */
464 if (get_tlv_data(kc->tlv.p, tlv) < 0) {
465 dev_err(sdev->dev, "error: invalid TLV data\n");
469 /* set up volume table */
470 ret = set_up_volume_table(scontrol, tlv, le32_to_cpu(mc->max) + 1);
472 dev_err(sdev->dev, "error: setting up volume table\n");
476 /* set default volume values to 0dB in control */
477 cdata = scontrol->control_data;
478 for (i = 0; i < scontrol->num_channels; i++) {
479 cdata->chanv[i].channel = i;
480 cdata->chanv[i].value = VOL_ZERO_DB;
484 dev_dbg(sdev->dev, "tplg: load kcontrol index %d chans %d\n",
485 scontrol->comp_id, scontrol->num_channels);
490 static int sof_control_load_enum(struct snd_soc_component *scomp,
491 struct snd_sof_control *scontrol,
492 struct snd_kcontrol_new *kc,
493 struct snd_soc_tplg_ctl_hdr *hdr)
495 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
496 struct snd_soc_tplg_enum_control *ec =
497 container_of(hdr, struct snd_soc_tplg_enum_control, hdr);
499 /* validate topology data */
500 if (le32_to_cpu(ec->num_channels) > SND_SOC_TPLG_MAX_CHAN)
503 /* init the enum get/put data */
504 scontrol->size = sizeof(struct sof_ipc_ctrl_data) +
505 sizeof(struct sof_ipc_ctrl_value_chan) *
506 le32_to_cpu(ec->num_channels);
507 scontrol->control_data = kzalloc(scontrol->size, GFP_KERNEL);
508 if (!scontrol->control_data)
511 scontrol->comp_id = sdev->next_comp_id;
512 scontrol->num_channels = le32_to_cpu(ec->num_channels);
514 scontrol->cmd = SOF_CTRL_CMD_ENUM;
516 dev_dbg(sdev->dev, "tplg: load kcontrol index %d chans %d comp_id %d\n",
517 scontrol->comp_id, scontrol->num_channels, scontrol->comp_id);
522 static int sof_control_load_bytes(struct snd_soc_component *scomp,
523 struct snd_sof_control *scontrol,
524 struct snd_kcontrol_new *kc,
525 struct snd_soc_tplg_ctl_hdr *hdr)
527 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
528 struct sof_ipc_ctrl_data *cdata;
529 struct snd_soc_tplg_bytes_control *control =
530 container_of(hdr, struct snd_soc_tplg_bytes_control, hdr);
531 struct soc_bytes_ext *sbe = (struct soc_bytes_ext *)kc->private_value;
532 int max_size = sbe->max;
534 if (le32_to_cpu(control->priv.size) > max_size) {
535 dev_err(sdev->dev, "err: bytes data size %d exceeds max %d.\n",
536 control->priv.size, max_size);
540 /* init the get/put bytes data */
541 scontrol->size = sizeof(struct sof_ipc_ctrl_data) +
542 le32_to_cpu(control->priv.size);
543 scontrol->control_data = kzalloc(max_size, GFP_KERNEL);
544 cdata = scontrol->control_data;
545 if (!scontrol->control_data)
548 scontrol->comp_id = sdev->next_comp_id;
549 scontrol->cmd = SOF_CTRL_CMD_BINARY;
551 dev_dbg(sdev->dev, "tplg: load kcontrol index %d chans %d\n",
552 scontrol->comp_id, scontrol->num_channels);
554 if (le32_to_cpu(control->priv.size) > 0) {
555 memcpy(cdata->data, control->priv.data,
556 le32_to_cpu(control->priv.size));
558 if (cdata->data->magic != SOF_ABI_MAGIC) {
559 dev_err(sdev->dev, "error: Wrong ABI magic 0x%08x.\n",
563 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION,
566 "error: Incompatible ABI version 0x%08x.\n",
570 if (cdata->data->size + sizeof(const struct sof_abi_hdr) !=
571 le32_to_cpu(control->priv.size)) {
573 "error: Conflict in bytes vs. priv size.\n");
581 * Topology Token Parsing.
582 * New tokens should be added to headers and parsing tables below.
585 struct sof_topology_token {
588 int (*get_token)(void *elem, void *object, u32 offset, u32 size);
593 static int get_token_u32(void *elem, void *object, u32 offset, u32 size)
595 struct snd_soc_tplg_vendor_value_elem *velem = elem;
596 u32 *val = (u32 *)((u8 *)object + offset);
598 *val = le32_to_cpu(velem->value);
602 static int get_token_u16(void *elem, void *object, u32 offset, u32 size)
604 struct snd_soc_tplg_vendor_value_elem *velem = elem;
605 u16 *val = (u16 *)((u8 *)object + offset);
607 *val = (u16)le32_to_cpu(velem->value);
611 static int get_token_comp_format(void *elem, void *object, u32 offset, u32 size)
613 struct snd_soc_tplg_vendor_string_elem *velem = elem;
614 u32 *val = (u32 *)((u8 *)object + offset);
616 *val = find_format(velem->string);
620 static int get_token_dai_type(void *elem, void *object, u32 offset, u32 size)
622 struct snd_soc_tplg_vendor_string_elem *velem = elem;
623 u32 *val = (u32 *)((u8 *)object + offset);
625 *val = find_dai(velem->string);
629 static int get_token_process_type(void *elem, void *object, u32 offset,
632 struct snd_soc_tplg_vendor_string_elem *velem = elem;
633 u32 *val = (u32 *)((u8 *)object + offset);
635 *val = find_process(velem->string);
640 static const struct sof_topology_token buffer_tokens[] = {
641 {SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
642 offsetof(struct sof_ipc_buffer, size), 0},
643 {SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
644 offsetof(struct sof_ipc_buffer, caps), 0},
648 static const struct sof_topology_token dai_tokens[] = {
649 {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
650 offsetof(struct sof_ipc_comp_dai, type), 0},
651 {SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
652 offsetof(struct sof_ipc_comp_dai, dai_index), 0},
653 {SOF_TKN_DAI_DIRECTION, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
654 offsetof(struct sof_ipc_comp_dai, direction), 0},
658 static const struct sof_topology_token dai_link_tokens[] = {
659 {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
660 offsetof(struct sof_ipc_dai_config, type), 0},
661 {SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
662 offsetof(struct sof_ipc_dai_config, dai_index), 0},
666 static const struct sof_topology_token sched_tokens[] = {
667 {SOF_TKN_SCHED_PERIOD, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
668 offsetof(struct sof_ipc_pipe_new, period), 0},
669 {SOF_TKN_SCHED_PRIORITY, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
670 offsetof(struct sof_ipc_pipe_new, priority), 0},
671 {SOF_TKN_SCHED_MIPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
672 offsetof(struct sof_ipc_pipe_new, period_mips), 0},
673 {SOF_TKN_SCHED_CORE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
674 offsetof(struct sof_ipc_pipe_new, core), 0},
675 {SOF_TKN_SCHED_FRAMES, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
676 offsetof(struct sof_ipc_pipe_new, frames_per_sched), 0},
677 {SOF_TKN_SCHED_TIME_DOMAIN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
678 offsetof(struct sof_ipc_pipe_new, time_domain), 0},
682 static const struct sof_topology_token volume_tokens[] = {
683 {SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
684 get_token_u32, offsetof(struct sof_ipc_comp_volume, ramp), 0},
685 {SOF_TKN_VOLUME_RAMP_STEP_MS,
686 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
687 offsetof(struct sof_ipc_comp_volume, initial_ramp), 0},
691 static const struct sof_topology_token src_tokens[] = {
692 {SOF_TKN_SRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
693 offsetof(struct sof_ipc_comp_src, source_rate), 0},
694 {SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
695 offsetof(struct sof_ipc_comp_src, sink_rate), 0},
699 static const struct sof_topology_token tone_tokens[] = {
703 static const struct sof_topology_token process_tokens[] = {
704 {SOF_TKN_PROCESS_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING,
705 get_token_process_type,
706 offsetof(struct sof_ipc_comp_process, type), 0},
710 static const struct sof_topology_token pcm_tokens[] = {
711 {SOF_TKN_PCM_DMAC_CONFIG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
712 offsetof(struct sof_ipc_comp_host, dmac_config), 0},
715 /* Generic components */
716 static const struct sof_topology_token comp_tokens[] = {
717 {SOF_TKN_COMP_PERIOD_SINK_COUNT,
718 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
719 offsetof(struct sof_ipc_comp_config, periods_sink), 0},
720 {SOF_TKN_COMP_PERIOD_SOURCE_COUNT,
721 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
722 offsetof(struct sof_ipc_comp_config, periods_source), 0},
723 {SOF_TKN_COMP_FORMAT,
724 SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format,
725 offsetof(struct sof_ipc_comp_config, frame_fmt), 0},
729 static const struct sof_topology_token ssp_tokens[] = {
730 {SOF_TKN_INTEL_SSP_CLKS_CONTROL,
731 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
732 offsetof(struct sof_ipc_dai_ssp_params, clks_control), 0},
733 {SOF_TKN_INTEL_SSP_MCLK_ID,
734 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
735 offsetof(struct sof_ipc_dai_ssp_params, mclk_id), 0},
736 {SOF_TKN_INTEL_SSP_SAMPLE_BITS, SND_SOC_TPLG_TUPLE_TYPE_WORD,
738 offsetof(struct sof_ipc_dai_ssp_params, sample_valid_bits), 0},
739 {SOF_TKN_INTEL_SSP_FRAME_PULSE_WIDTH, SND_SOC_TPLG_TUPLE_TYPE_SHORT,
741 offsetof(struct sof_ipc_dai_ssp_params, frame_pulse_width), 0},
742 {SOF_TKN_INTEL_SSP_QUIRKS, SND_SOC_TPLG_TUPLE_TYPE_WORD,
744 offsetof(struct sof_ipc_dai_ssp_params, quirks), 0},
745 {SOF_TKN_INTEL_SSP_TDM_PADDING_PER_SLOT, SND_SOC_TPLG_TUPLE_TYPE_BOOL,
747 offsetof(struct sof_ipc_dai_ssp_params,
748 tdm_per_slot_padding_flag), 0},
753 static const struct sof_topology_token dmic_tokens[] = {
754 {SOF_TKN_INTEL_DMIC_DRIVER_VERSION,
755 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
756 offsetof(struct sof_ipc_dai_dmic_params, driver_ipc_version),
758 {SOF_TKN_INTEL_DMIC_CLK_MIN,
759 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
760 offsetof(struct sof_ipc_dai_dmic_params, pdmclk_min), 0},
761 {SOF_TKN_INTEL_DMIC_CLK_MAX,
762 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
763 offsetof(struct sof_ipc_dai_dmic_params, pdmclk_max), 0},
764 {SOF_TKN_INTEL_DMIC_SAMPLE_RATE,
765 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
766 offsetof(struct sof_ipc_dai_dmic_params, fifo_fs), 0},
767 {SOF_TKN_INTEL_DMIC_DUTY_MIN,
768 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
769 offsetof(struct sof_ipc_dai_dmic_params, duty_min), 0},
770 {SOF_TKN_INTEL_DMIC_DUTY_MAX,
771 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
772 offsetof(struct sof_ipc_dai_dmic_params, duty_max), 0},
773 {SOF_TKN_INTEL_DMIC_NUM_PDM_ACTIVE,
774 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
775 offsetof(struct sof_ipc_dai_dmic_params,
777 {SOF_TKN_INTEL_DMIC_FIFO_WORD_LENGTH,
778 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
779 offsetof(struct sof_ipc_dai_dmic_params, fifo_bits), 0},
784 * SOF_TKN_INTEL_DMIC_PDM_CTRL_ID should be the first token
785 * as it increments the index while parsing the array of pdm tokens
786 * and determines the correct offset
788 static const struct sof_topology_token dmic_pdm_tokens[] = {
789 {SOF_TKN_INTEL_DMIC_PDM_CTRL_ID,
790 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
791 offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, id),
793 {SOF_TKN_INTEL_DMIC_PDM_MIC_A_Enable,
794 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
795 offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, enable_mic_a),
797 {SOF_TKN_INTEL_DMIC_PDM_MIC_B_Enable,
798 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
799 offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, enable_mic_b),
801 {SOF_TKN_INTEL_DMIC_PDM_POLARITY_A,
802 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
803 offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, polarity_mic_a),
805 {SOF_TKN_INTEL_DMIC_PDM_POLARITY_B,
806 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
807 offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, polarity_mic_b),
809 {SOF_TKN_INTEL_DMIC_PDM_CLK_EDGE,
810 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
811 offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, clk_edge),
813 {SOF_TKN_INTEL_DMIC_PDM_SKEW,
814 SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
815 offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, skew),
820 static const struct sof_topology_token hda_tokens[] = {
823 static void sof_parse_uuid_tokens(struct snd_soc_component *scomp,
825 const struct sof_topology_token *tokens,
827 struct snd_soc_tplg_vendor_array *array)
829 struct snd_soc_tplg_vendor_uuid_elem *elem;
832 /* parse element by element */
833 for (i = 0; i < le32_to_cpu(array->num_elems); i++) {
834 elem = &array->uuid[i];
836 /* search for token */
837 for (j = 0; j < count; j++) {
838 /* match token type */
839 if (tokens[j].type != SND_SOC_TPLG_TUPLE_TYPE_UUID)
843 if (tokens[j].token != le32_to_cpu(elem->token))
846 /* matched - now load token */
847 tokens[j].get_token(elem, object, tokens[j].offset,
853 static void sof_parse_string_tokens(struct snd_soc_component *scomp,
855 const struct sof_topology_token *tokens,
857 struct snd_soc_tplg_vendor_array *array)
859 struct snd_soc_tplg_vendor_string_elem *elem;
862 /* parse element by element */
863 for (i = 0; i < le32_to_cpu(array->num_elems); i++) {
864 elem = &array->string[i];
866 /* search for token */
867 for (j = 0; j < count; j++) {
868 /* match token type */
869 if (tokens[j].type != SND_SOC_TPLG_TUPLE_TYPE_STRING)
873 if (tokens[j].token != le32_to_cpu(elem->token))
876 /* matched - now load token */
877 tokens[j].get_token(elem, object, tokens[j].offset,
883 static void sof_parse_word_tokens(struct snd_soc_component *scomp,
885 const struct sof_topology_token *tokens,
887 struct snd_soc_tplg_vendor_array *array)
889 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
890 struct snd_soc_tplg_vendor_value_elem *elem;
891 size_t size = sizeof(struct sof_ipc_dai_dmic_pdm_ctrl);
896 /* parse element by element */
897 for (i = 0; i < le32_to_cpu(array->num_elems); i++) {
898 elem = &array->value[i];
900 /* search for token */
901 for (j = 0; j < count; j++) {
902 /* match token type */
903 if (!(tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_WORD ||
904 tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_SHORT))
908 if (tokens[j].token != le32_to_cpu(elem->token))
911 /* pdm config array index */
913 index = sdev->private;
915 /* matched - determine offset */
916 switch (tokens[j].token) {
917 case SOF_TKN_INTEL_DMIC_PDM_CTRL_ID:
919 /* inc number of pdm array index */
923 case SOF_TKN_INTEL_DMIC_PDM_MIC_A_Enable:
924 case SOF_TKN_INTEL_DMIC_PDM_MIC_B_Enable:
925 case SOF_TKN_INTEL_DMIC_PDM_POLARITY_A:
926 case SOF_TKN_INTEL_DMIC_PDM_POLARITY_B:
927 case SOF_TKN_INTEL_DMIC_PDM_CLK_EDGE:
928 case SOF_TKN_INTEL_DMIC_PDM_SKEW:
930 /* check if array index is valid */
931 if (!index || *index == 0) {
933 "error: invalid array offset\n");
936 /* offset within the pdm config array */
937 offset = size * (*index - 1);
946 tokens[j].get_token(elem, object,
947 offset + tokens[j].offset,
953 static int sof_parse_tokens(struct snd_soc_component *scomp,
955 const struct sof_topology_token *tokens,
957 struct snd_soc_tplg_vendor_array *array,
960 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
963 while (priv_size > 0) {
964 asize = le32_to_cpu(array->size);
967 if (asize < 0) { /* FIXME: A zero-size array makes no sense */
968 dev_err(sdev->dev, "error: invalid array size 0x%x\n",
973 /* make sure there is enough data before parsing */
976 dev_err(sdev->dev, "error: invalid array size 0x%x\n",
981 /* call correct parser depending on type */
982 switch (le32_to_cpu(array->type)) {
983 case SND_SOC_TPLG_TUPLE_TYPE_UUID:
984 sof_parse_uuid_tokens(scomp, object, tokens, count,
987 case SND_SOC_TPLG_TUPLE_TYPE_STRING:
988 sof_parse_string_tokens(scomp, object, tokens, count,
991 case SND_SOC_TPLG_TUPLE_TYPE_BOOL:
992 case SND_SOC_TPLG_TUPLE_TYPE_BYTE:
993 case SND_SOC_TPLG_TUPLE_TYPE_WORD:
994 case SND_SOC_TPLG_TUPLE_TYPE_SHORT:
995 sof_parse_word_tokens(scomp, object, tokens, count,
999 dev_err(sdev->dev, "error: unknown token type %d\n",
1005 array = (struct snd_soc_tplg_vendor_array *)((u8 *)array
1011 static void sof_dbg_comp_config(struct snd_soc_component *scomp,
1012 struct sof_ipc_comp_config *config)
1014 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1016 dev_dbg(sdev->dev, " config: periods snk %d src %d fmt %d\n",
1017 config->periods_sink, config->periods_source,
1021 /* external kcontrol init - used for any driver specific init */
1022 static int sof_control_load(struct snd_soc_component *scomp, int index,
1023 struct snd_kcontrol_new *kc,
1024 struct snd_soc_tplg_ctl_hdr *hdr)
1026 struct soc_mixer_control *sm;
1027 struct soc_bytes_ext *sbe;
1028 struct soc_enum *se;
1029 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1030 struct snd_soc_dobj *dobj;
1031 struct snd_sof_control *scontrol;
1034 dev_dbg(sdev->dev, "tplg: load control type %d name : %s\n",
1035 hdr->type, hdr->name);
1037 scontrol = kzalloc(sizeof(*scontrol), GFP_KERNEL);
1041 scontrol->sdev = sdev;
1043 switch (le32_to_cpu(hdr->ops.info)) {
1044 case SND_SOC_TPLG_CTL_VOLSW:
1045 case SND_SOC_TPLG_CTL_VOLSW_SX:
1046 case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
1047 sm = (struct soc_mixer_control *)kc->private_value;
1049 ret = sof_control_load_volume(scomp, scontrol, kc, hdr);
1051 case SND_SOC_TPLG_CTL_BYTES:
1052 sbe = (struct soc_bytes_ext *)kc->private_value;
1054 ret = sof_control_load_bytes(scomp, scontrol, kc, hdr);
1056 case SND_SOC_TPLG_CTL_ENUM:
1057 case SND_SOC_TPLG_CTL_ENUM_VALUE:
1058 se = (struct soc_enum *)kc->private_value;
1060 ret = sof_control_load_enum(scomp, scontrol, kc, hdr);
1062 case SND_SOC_TPLG_CTL_RANGE:
1063 case SND_SOC_TPLG_CTL_STROBE:
1064 case SND_SOC_TPLG_DAPM_CTL_VOLSW:
1065 case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
1066 case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
1067 case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
1068 case SND_SOC_TPLG_DAPM_CTL_PIN:
1070 dev_warn(sdev->dev, "control type not supported %d:%d:%d\n",
1071 hdr->ops.get, hdr->ops.put, hdr->ops.info);
1076 dobj->private = scontrol;
1077 list_add(&scontrol->list, &sdev->kcontrol_list);
1081 static int sof_control_unload(struct snd_soc_component *scomp,
1082 struct snd_soc_dobj *dobj)
1084 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1085 struct sof_ipc_free fcomp;
1086 struct snd_sof_control *scontrol = dobj->private;
1088 dev_dbg(sdev->dev, "tplg: unload control name : %s\n", scomp->name);
1090 fcomp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_FREE;
1091 fcomp.hdr.size = sizeof(fcomp);
1092 fcomp.id = scontrol->comp_id;
1094 kfree(scontrol->control_data);
1095 list_del(&scontrol->list);
1097 /* send IPC to the DSP */
1098 return sof_ipc_tx_message(sdev->ipc,
1099 fcomp.hdr.cmd, &fcomp, sizeof(fcomp),
1107 static int sof_connect_dai_widget(struct snd_soc_component *scomp,
1108 struct snd_soc_dapm_widget *w,
1109 struct snd_soc_tplg_dapm_widget *tw,
1110 struct snd_sof_dai *dai)
1112 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1113 struct snd_soc_card *card = scomp->card;
1114 struct snd_soc_pcm_runtime *rtd;
1116 list_for_each_entry(rtd, &card->rtd_list, list) {
1117 dev_vdbg(sdev->dev, "tplg: check widget: %s stream: %s dai stream: %s\n",
1118 w->name, w->sname, rtd->dai_link->stream_name);
1120 if (!w->sname || !rtd->dai_link->stream_name)
1123 /* does stream match DAI link ? */
1124 if (strcmp(w->sname, rtd->dai_link->stream_name))
1128 case snd_soc_dapm_dai_out:
1129 rtd->cpu_dai->capture_widget = w;
1130 dai->name = rtd->dai_link->name;
1131 dev_dbg(sdev->dev, "tplg: connected widget %s -> DAI link %s\n",
1132 w->name, rtd->dai_link->name);
1134 case snd_soc_dapm_dai_in:
1135 rtd->cpu_dai->playback_widget = w;
1136 dai->name = rtd->dai_link->name;
1137 dev_dbg(sdev->dev, "tplg: connected widget %s -> DAI link %s\n",
1138 w->name, rtd->dai_link->name);
1145 /* check we have a connection */
1147 dev_err(sdev->dev, "error: can't connect DAI %s stream %s\n",
1155 static int sof_widget_load_dai(struct snd_soc_component *scomp, int index,
1156 struct snd_sof_widget *swidget,
1157 struct snd_soc_tplg_dapm_widget *tw,
1158 struct sof_ipc_comp_reply *r,
1159 struct snd_sof_dai *dai)
1161 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1162 struct snd_soc_tplg_private *private = &tw->priv;
1163 struct sof_ipc_comp_dai comp_dai;
1166 /* configure dai IPC message */
1167 memset(&comp_dai, 0, sizeof(comp_dai));
1168 comp_dai.comp.hdr.size = sizeof(comp_dai);
1169 comp_dai.comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1170 comp_dai.comp.id = swidget->comp_id;
1171 comp_dai.comp.type = SOF_COMP_DAI;
1172 comp_dai.comp.pipeline_id = index;
1173 comp_dai.config.hdr.size = sizeof(comp_dai.config);
1175 ret = sof_parse_tokens(scomp, &comp_dai, dai_tokens,
1176 ARRAY_SIZE(dai_tokens), private->array,
1177 le32_to_cpu(private->size));
1179 dev_err(sdev->dev, "error: parse dai tokens failed %d\n",
1180 le32_to_cpu(private->size));
1184 ret = sof_parse_tokens(scomp, &comp_dai.config, comp_tokens,
1185 ARRAY_SIZE(comp_tokens), private->array,
1186 le32_to_cpu(private->size));
1188 dev_err(sdev->dev, "error: parse dai.cfg tokens failed %d\n",
1193 dev_dbg(sdev->dev, "dai %s: type %d index %d\n",
1194 swidget->widget->name, comp_dai.type, comp_dai.dai_index);
1195 sof_dbg_comp_config(scomp, &comp_dai.config);
1197 ret = sof_ipc_tx_message(sdev->ipc, comp_dai.comp.hdr.cmd,
1198 &comp_dai, sizeof(comp_dai), r, sizeof(*r));
1200 if (ret == 0 && dai) {
1202 memcpy(&dai->comp_dai, &comp_dai, sizeof(comp_dai));
1212 static int sof_widget_load_buffer(struct snd_soc_component *scomp, int index,
1213 struct snd_sof_widget *swidget,
1214 struct snd_soc_tplg_dapm_widget *tw,
1215 struct sof_ipc_comp_reply *r)
1217 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1218 struct snd_soc_tplg_private *private = &tw->priv;
1219 struct sof_ipc_buffer *buffer;
1222 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
1226 /* configure dai IPC message */
1227 buffer->comp.hdr.size = sizeof(*buffer);
1228 buffer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_BUFFER_NEW;
1229 buffer->comp.id = swidget->comp_id;
1230 buffer->comp.type = SOF_COMP_BUFFER;
1231 buffer->comp.pipeline_id = index;
1233 ret = sof_parse_tokens(scomp, buffer, buffer_tokens,
1234 ARRAY_SIZE(buffer_tokens), private->array,
1235 le32_to_cpu(private->size));
1237 dev_err(sdev->dev, "error: parse buffer tokens failed %d\n",
1243 dev_dbg(sdev->dev, "buffer %s: size %d caps 0x%x\n",
1244 swidget->widget->name, buffer->size, buffer->caps);
1246 swidget->private = buffer;
1248 ret = sof_ipc_tx_message(sdev->ipc, buffer->comp.hdr.cmd, buffer,
1249 sizeof(*buffer), r, sizeof(*r));
1251 dev_err(sdev->dev, "error: buffer %s load failed\n",
1252 swidget->widget->name);
1259 /* bind PCM ID to host component ID */
1260 static int spcm_bind(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
1263 struct snd_sof_widget *host_widget;
1265 host_widget = snd_sof_find_swidget_sname(sdev,
1266 spcm->pcm.caps[dir].name,
1269 dev_err(sdev->dev, "can't find host comp to bind pcm\n");
1273 spcm->stream[dir].comp_id = host_widget->comp_id;
1282 static int sof_widget_load_pcm(struct snd_soc_component *scomp, int index,
1283 struct snd_sof_widget *swidget,
1284 enum sof_ipc_stream_direction dir,
1285 struct snd_soc_tplg_dapm_widget *tw,
1286 struct sof_ipc_comp_reply *r)
1288 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1289 struct snd_soc_tplg_private *private = &tw->priv;
1290 struct sof_ipc_comp_host *host;
1293 host = kzalloc(sizeof(*host), GFP_KERNEL);
1297 /* configure host comp IPC message */
1298 host->comp.hdr.size = sizeof(*host);
1299 host->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1300 host->comp.id = swidget->comp_id;
1301 host->comp.type = SOF_COMP_HOST;
1302 host->comp.pipeline_id = index;
1303 host->direction = dir;
1304 host->config.hdr.size = sizeof(host->config);
1306 ret = sof_parse_tokens(scomp, host, pcm_tokens,
1307 ARRAY_SIZE(pcm_tokens), private->array,
1308 le32_to_cpu(private->size));
1310 dev_err(sdev->dev, "error: parse host tokens failed %d\n",
1315 ret = sof_parse_tokens(scomp, &host->config, comp_tokens,
1316 ARRAY_SIZE(comp_tokens), private->array,
1317 le32_to_cpu(private->size));
1319 dev_err(sdev->dev, "error: parse host.cfg tokens failed %d\n",
1320 le32_to_cpu(private->size));
1324 dev_dbg(sdev->dev, "loaded host %s\n", swidget->widget->name);
1325 sof_dbg_comp_config(scomp, &host->config);
1327 swidget->private = host;
1329 ret = sof_ipc_tx_message(sdev->ipc, host->comp.hdr.cmd, host,
1330 sizeof(*host), r, sizeof(*r));
1341 int sof_load_pipeline_ipc(struct snd_sof_dev *sdev,
1342 struct sof_ipc_pipe_new *pipeline,
1343 struct sof_ipc_comp_reply *r)
1345 struct sof_ipc_pm_core_config pm_core_config;
1348 ret = sof_ipc_tx_message(sdev->ipc, pipeline->hdr.cmd, pipeline,
1349 sizeof(*pipeline), r, sizeof(*r));
1351 dev_err(sdev->dev, "error: load pipeline ipc failure\n");
1355 /* power up the core that this pipeline is scheduled on */
1356 ret = snd_sof_dsp_core_power_up(sdev, 1 << pipeline->core);
1358 dev_err(sdev->dev, "error: powering up pipeline schedule core %d\n",
1363 /* update enabled cores mask */
1364 sdev->enabled_cores_mask |= 1 << pipeline->core;
1367 * Now notify DSP that the core that this pipeline is scheduled on
1368 * has been powered up
1370 memset(&pm_core_config, 0, sizeof(pm_core_config));
1371 pm_core_config.enable_mask = sdev->enabled_cores_mask;
1373 /* configure CORE_ENABLE ipc message */
1374 pm_core_config.hdr.size = sizeof(pm_core_config);
1375 pm_core_config.hdr.cmd = SOF_IPC_GLB_PM_MSG | SOF_IPC_PM_CORE_ENABLE;
1378 ret = sof_ipc_tx_message(sdev->ipc, pm_core_config.hdr.cmd,
1379 &pm_core_config, sizeof(pm_core_config),
1380 &pm_core_config, sizeof(pm_core_config));
1382 dev_err(sdev->dev, "error: core enable ipc failure\n");
1387 static int sof_widget_load_pipeline(struct snd_soc_component *scomp,
1388 int index, struct snd_sof_widget *swidget,
1389 struct snd_soc_tplg_dapm_widget *tw,
1390 struct sof_ipc_comp_reply *r)
1392 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1393 struct snd_soc_tplg_private *private = &tw->priv;
1394 struct sof_ipc_pipe_new *pipeline;
1395 struct snd_sof_widget *comp_swidget;
1398 pipeline = kzalloc(sizeof(*pipeline), GFP_KERNEL);
1402 /* configure dai IPC message */
1403 pipeline->hdr.size = sizeof(*pipeline);
1404 pipeline->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_NEW;
1405 pipeline->pipeline_id = index;
1406 pipeline->comp_id = swidget->comp_id;
1408 /* component at start of pipeline is our stream id */
1409 comp_swidget = snd_sof_find_swidget(sdev, tw->sname);
1410 if (!comp_swidget) {
1411 dev_err(sdev->dev, "error: widget %s refers to non existent widget %s\n",
1412 tw->name, tw->sname);
1417 pipeline->sched_id = comp_swidget->comp_id;
1419 dev_dbg(sdev->dev, "tplg: pipeline id %d comp %d scheduling comp id %d\n",
1420 pipeline->pipeline_id, pipeline->comp_id, pipeline->sched_id);
1422 ret = sof_parse_tokens(scomp, pipeline, sched_tokens,
1423 ARRAY_SIZE(sched_tokens), private->array,
1424 le32_to_cpu(private->size));
1426 dev_err(sdev->dev, "error: parse pipeline tokens failed %d\n",
1431 dev_dbg(sdev->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d\n",
1432 swidget->widget->name, pipeline->period, pipeline->priority,
1433 pipeline->period_mips, pipeline->core, pipeline->frames_per_sched);
1435 swidget->private = pipeline;
1437 /* send ipc's to create pipeline comp and power up schedule core */
1438 ret = sof_load_pipeline_ipc(sdev, pipeline, r);
1450 static int sof_widget_load_mixer(struct snd_soc_component *scomp, int index,
1451 struct snd_sof_widget *swidget,
1452 struct snd_soc_tplg_dapm_widget *tw,
1453 struct sof_ipc_comp_reply *r)
1455 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1456 struct snd_soc_tplg_private *private = &tw->priv;
1457 struct sof_ipc_comp_mixer *mixer;
1460 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
1464 /* configure mixer IPC message */
1465 mixer->comp.hdr.size = sizeof(*mixer);
1466 mixer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1467 mixer->comp.id = swidget->comp_id;
1468 mixer->comp.type = SOF_COMP_MIXER;
1469 mixer->comp.pipeline_id = index;
1470 mixer->config.hdr.size = sizeof(mixer->config);
1472 ret = sof_parse_tokens(scomp, &mixer->config, comp_tokens,
1473 ARRAY_SIZE(comp_tokens), private->array,
1474 le32_to_cpu(private->size));
1476 dev_err(sdev->dev, "error: parse mixer.cfg tokens failed %d\n",
1482 sof_dbg_comp_config(scomp, &mixer->config);
1484 swidget->private = mixer;
1486 ret = sof_ipc_tx_message(sdev->ipc, mixer->comp.hdr.cmd, mixer,
1487 sizeof(*mixer), r, sizeof(*r));
1497 static int sof_widget_load_mux(struct snd_soc_component *scomp, int index,
1498 struct snd_sof_widget *swidget,
1499 struct snd_soc_tplg_dapm_widget *tw,
1500 struct sof_ipc_comp_reply *r)
1502 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1503 struct snd_soc_tplg_private *private = &tw->priv;
1504 struct sof_ipc_comp_mux *mux;
1507 mux = kzalloc(sizeof(*mux), GFP_KERNEL);
1511 /* configure mux IPC message */
1512 mux->comp.hdr.size = sizeof(*mux);
1513 mux->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1514 mux->comp.id = swidget->comp_id;
1515 mux->comp.type = SOF_COMP_MUX;
1516 mux->comp.pipeline_id = index;
1517 mux->config.hdr.size = sizeof(mux->config);
1519 ret = sof_parse_tokens(scomp, &mux->config, comp_tokens,
1520 ARRAY_SIZE(comp_tokens), private->array,
1521 le32_to_cpu(private->size));
1523 dev_err(sdev->dev, "error: parse mux.cfg tokens failed %d\n",
1529 sof_dbg_comp_config(scomp, &mux->config);
1531 swidget->private = mux;
1533 ret = sof_ipc_tx_message(sdev->ipc, mux->comp.hdr.cmd, mux,
1534 sizeof(*mux), r, sizeof(*r));
1545 static int sof_widget_load_pga(struct snd_soc_component *scomp, int index,
1546 struct snd_sof_widget *swidget,
1547 struct snd_soc_tplg_dapm_widget *tw,
1548 struct sof_ipc_comp_reply *r)
1550 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1551 struct snd_soc_tplg_private *private = &tw->priv;
1552 struct sof_ipc_comp_volume *volume;
1555 volume = kzalloc(sizeof(*volume), GFP_KERNEL);
1559 if (le32_to_cpu(tw->num_kcontrols) != 1) {
1560 dev_err(sdev->dev, "error: invalid kcontrol count %d for volume\n",
1566 /* configure volume IPC message */
1567 volume->comp.hdr.size = sizeof(*volume);
1568 volume->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1569 volume->comp.id = swidget->comp_id;
1570 volume->comp.type = SOF_COMP_VOLUME;
1571 volume->comp.pipeline_id = index;
1572 volume->config.hdr.size = sizeof(volume->config);
1574 ret = sof_parse_tokens(scomp, volume, volume_tokens,
1575 ARRAY_SIZE(volume_tokens), private->array,
1576 le32_to_cpu(private->size));
1578 dev_err(sdev->dev, "error: parse volume tokens failed %d\n",
1582 ret = sof_parse_tokens(scomp, &volume->config, comp_tokens,
1583 ARRAY_SIZE(comp_tokens), private->array,
1584 le32_to_cpu(private->size));
1586 dev_err(sdev->dev, "error: parse volume.cfg tokens failed %d\n",
1587 le32_to_cpu(private->size));
1591 sof_dbg_comp_config(scomp, &volume->config);
1593 swidget->private = volume;
1595 ret = sof_ipc_tx_message(sdev->ipc, volume->comp.hdr.cmd, volume,
1596 sizeof(*volume), r, sizeof(*r));
1608 static int sof_widget_load_src(struct snd_soc_component *scomp, int index,
1609 struct snd_sof_widget *swidget,
1610 struct snd_soc_tplg_dapm_widget *tw,
1611 struct sof_ipc_comp_reply *r)
1613 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1614 struct snd_soc_tplg_private *private = &tw->priv;
1615 struct sof_ipc_comp_src *src;
1618 src = kzalloc(sizeof(*src), GFP_KERNEL);
1622 /* configure src IPC message */
1623 src->comp.hdr.size = sizeof(*src);
1624 src->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1625 src->comp.id = swidget->comp_id;
1626 src->comp.type = SOF_COMP_SRC;
1627 src->comp.pipeline_id = index;
1628 src->config.hdr.size = sizeof(src->config);
1630 ret = sof_parse_tokens(scomp, src, src_tokens,
1631 ARRAY_SIZE(src_tokens), private->array,
1632 le32_to_cpu(private->size));
1634 dev_err(sdev->dev, "error: parse src tokens failed %d\n",
1639 ret = sof_parse_tokens(scomp, &src->config, comp_tokens,
1640 ARRAY_SIZE(comp_tokens), private->array,
1641 le32_to_cpu(private->size));
1643 dev_err(sdev->dev, "error: parse src.cfg tokens failed %d\n",
1644 le32_to_cpu(private->size));
1648 dev_dbg(sdev->dev, "src %s: source rate %d sink rate %d\n",
1649 swidget->widget->name, src->source_rate, src->sink_rate);
1650 sof_dbg_comp_config(scomp, &src->config);
1652 swidget->private = src;
1654 ret = sof_ipc_tx_message(sdev->ipc, src->comp.hdr.cmd, src,
1655 sizeof(*src), r, sizeof(*r));
1664 * Signal Generator Topology
1667 static int sof_widget_load_siggen(struct snd_soc_component *scomp, int index,
1668 struct snd_sof_widget *swidget,
1669 struct snd_soc_tplg_dapm_widget *tw,
1670 struct sof_ipc_comp_reply *r)
1672 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1673 struct snd_soc_tplg_private *private = &tw->priv;
1674 struct sof_ipc_comp_tone *tone;
1677 tone = kzalloc(sizeof(*tone), GFP_KERNEL);
1681 /* configure siggen IPC message */
1682 tone->comp.hdr.size = sizeof(*tone);
1683 tone->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1684 tone->comp.id = swidget->comp_id;
1685 tone->comp.type = SOF_COMP_TONE;
1686 tone->comp.pipeline_id = index;
1687 tone->config.hdr.size = sizeof(tone->config);
1689 ret = sof_parse_tokens(scomp, tone, tone_tokens,
1690 ARRAY_SIZE(tone_tokens), private->array,
1691 le32_to_cpu(private->size));
1693 dev_err(sdev->dev, "error: parse tone tokens failed %d\n",
1694 le32_to_cpu(private->size));
1698 ret = sof_parse_tokens(scomp, &tone->config, comp_tokens,
1699 ARRAY_SIZE(comp_tokens), private->array,
1700 le32_to_cpu(private->size));
1702 dev_err(sdev->dev, "error: parse tone.cfg tokens failed %d\n",
1703 le32_to_cpu(private->size));
1707 dev_dbg(sdev->dev, "tone %s: frequency %d amplitude %d\n",
1708 swidget->widget->name, tone->frequency, tone->amplitude);
1709 sof_dbg_comp_config(scomp, &tone->config);
1711 swidget->private = tone;
1713 ret = sof_ipc_tx_message(sdev->ipc, tone->comp.hdr.cmd, tone,
1714 sizeof(*tone), r, sizeof(*r));
1722 static int sof_process_load(struct snd_soc_component *scomp, int index,
1723 struct snd_sof_widget *swidget,
1724 struct snd_soc_tplg_dapm_widget *tw,
1725 struct sof_ipc_comp_reply *r,
1728 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1729 struct snd_soc_tplg_private *private = &tw->priv;
1730 struct snd_soc_dapm_widget *widget = swidget->widget;
1731 const struct snd_kcontrol_new *kc;
1732 struct soc_bytes_ext *sbe;
1733 struct soc_mixer_control *sm;
1734 struct soc_enum *se;
1735 struct snd_sof_control *scontrol = NULL;
1736 struct sof_abi_hdr *pdata = NULL;
1737 struct sof_ipc_comp_process *process;
1738 size_t ipc_size, ipc_data_size = 0;
1739 int ret, i, offset = 0;
1741 if (type == SOF_COMP_NONE) {
1742 dev_err(sdev->dev, "error: invalid process comp type %d\n",
1748 * get possible component controls - get size of all pdata,
1749 * then memcpy with headers
1751 for (i = 0; i < widget->num_kcontrols; i++) {
1753 kc = &widget->kcontrol_news[i];
1755 switch (widget->dobj.widget.kcontrol_type) {
1756 case SND_SOC_TPLG_TYPE_MIXER:
1757 sm = (struct soc_mixer_control *)kc->private_value;
1758 scontrol = sm->dobj.private;
1760 case SND_SOC_TPLG_TYPE_BYTES:
1761 sbe = (struct soc_bytes_ext *)kc->private_value;
1762 scontrol = sbe->dobj.private;
1764 case SND_SOC_TPLG_TYPE_ENUM:
1765 se = (struct soc_enum *)kc->private_value;
1766 scontrol = se->dobj.private;
1769 dev_err(sdev->dev, "error: unknown kcontrol type %d in widget %s\n",
1770 widget->dobj.widget.kcontrol_type,
1776 dev_err(sdev->dev, "error: no scontrol for widget %s\n",
1781 /* don't include if no private data */
1782 pdata = scontrol->control_data->data;
1786 /* make sure data is valid - data can be updated at runtime */
1787 if (pdata->magic != SOF_ABI_MAGIC)
1790 ipc_data_size += pdata->size;
1793 ipc_size = sizeof(struct sof_ipc_comp_process) +
1794 le32_to_cpu(private->size) +
1797 process = kzalloc(ipc_size, GFP_KERNEL);
1801 /* configure iir IPC message */
1802 process->comp.hdr.size = ipc_size;
1803 process->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
1804 process->comp.id = swidget->comp_id;
1805 process->comp.type = type;
1806 process->comp.pipeline_id = index;
1807 process->config.hdr.size = sizeof(process->config);
1809 ret = sof_parse_tokens(scomp, &process->config, comp_tokens,
1810 ARRAY_SIZE(comp_tokens), private->array,
1811 le32_to_cpu(private->size));
1813 dev_err(sdev->dev, "error: parse process.cfg tokens failed %d\n",
1814 le32_to_cpu(private->size));
1818 sof_dbg_comp_config(scomp, &process->config);
1821 * found private data in control, so copy it.
1822 * get possible component controls - get size of all pdata,
1823 * then memcpy with headers
1825 for (i = 0; i < widget->num_kcontrols; i++) {
1826 kc = &widget->kcontrol_news[i];
1828 switch (widget->dobj.widget.kcontrol_type) {
1829 case SND_SOC_TPLG_TYPE_MIXER:
1830 sm = (struct soc_mixer_control *)kc->private_value;
1831 scontrol = sm->dobj.private;
1833 case SND_SOC_TPLG_TYPE_BYTES:
1834 sbe = (struct soc_bytes_ext *)kc->private_value;
1835 scontrol = sbe->dobj.private;
1837 case SND_SOC_TPLG_TYPE_ENUM:
1838 se = (struct soc_enum *)kc->private_value;
1839 scontrol = se->dobj.private;
1842 dev_err(sdev->dev, "error: unknown kcontrol type %d in widget %s\n",
1843 widget->dobj.widget.kcontrol_type,
1848 /* don't include if no private data */
1849 pdata = scontrol->control_data->data;
1853 /* make sure data is valid - data can be updated at runtime */
1854 if (pdata->magic != SOF_ABI_MAGIC)
1857 memcpy(&process->data + offset, pdata->data, pdata->size);
1858 offset += pdata->size;
1861 process->size = ipc_data_size;
1862 swidget->private = process;
1864 ret = sof_ipc_tx_message(sdev->ipc, process->comp.hdr.cmd, process,
1865 ipc_size, r, sizeof(*r));
1874 * Processing Component Topology - can be "effect", "codec", or general
1878 static int sof_widget_load_process(struct snd_soc_component *scomp, int index,
1879 struct snd_sof_widget *swidget,
1880 struct snd_soc_tplg_dapm_widget *tw,
1881 struct sof_ipc_comp_reply *r)
1883 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1884 struct snd_soc_tplg_private *private = &tw->priv;
1885 struct sof_ipc_comp_process config;
1888 /* check we have some tokens - we need at least process type */
1889 if (le32_to_cpu(private->size) == 0) {
1890 dev_err(sdev->dev, "error: process tokens not found\n");
1894 memset(&config, 0, sizeof(config));
1896 /* get the process token */
1897 ret = sof_parse_tokens(scomp, &config, process_tokens,
1898 ARRAY_SIZE(process_tokens), private->array,
1899 le32_to_cpu(private->size));
1901 dev_err(sdev->dev, "error: parse process tokens failed %d\n",
1902 le32_to_cpu(private->size));
1906 /* now load process specific data and send IPC */
1907 ret = sof_process_load(scomp, index, swidget, tw, r,
1908 find_process_comp_type(config.type));
1910 dev_err(sdev->dev, "error: process loading failed\n");
1917 static int sof_widget_bind_event(struct snd_sof_dev *sdev,
1918 struct snd_sof_widget *swidget,
1921 struct sof_ipc_comp *ipc_comp;
1923 /* validate widget event type */
1924 switch (event_type) {
1925 case SOF_KEYWORD_DETECT_DAPM_EVENT:
1926 /* only KEYWORD_DETECT comps should handle this */
1927 if (swidget->id != snd_soc_dapm_effect)
1930 ipc_comp = swidget->private;
1931 if (ipc_comp && ipc_comp->type != SOF_COMP_KEYWORD_DETECT)
1934 /* bind event to keyword detect comp */
1935 return snd_soc_tplg_widget_bind_event(swidget->widget,
1937 ARRAY_SIZE(sof_kwd_events),
1944 "error: invalid event type %d for widget %s\n",
1945 event_type, swidget->widget->name);
1949 /* external widget init - used for any driver specific init */
1950 static int sof_widget_ready(struct snd_soc_component *scomp, int index,
1951 struct snd_soc_dapm_widget *w,
1952 struct snd_soc_tplg_dapm_widget *tw)
1954 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1955 struct snd_sof_widget *swidget;
1956 struct snd_sof_dai *dai;
1957 struct sof_ipc_comp_reply reply;
1958 struct snd_sof_control *scontrol;
1961 swidget = kzalloc(sizeof(*swidget), GFP_KERNEL);
1965 swidget->sdev = sdev;
1966 swidget->widget = w;
1967 swidget->comp_id = sdev->next_comp_id++;
1968 swidget->complete = 0;
1969 swidget->id = w->id;
1970 swidget->pipeline_id = index;
1971 swidget->private = NULL;
1972 memset(&reply, 0, sizeof(reply));
1974 dev_dbg(sdev->dev, "tplg: ready widget id %d pipe %d type %d name : %s stream %s\n",
1975 swidget->comp_id, index, swidget->id, tw->name,
1976 strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0
1977 ? tw->sname : "none");
1979 /* handle any special case widgets */
1981 case snd_soc_dapm_dai_in:
1982 case snd_soc_dapm_dai_out:
1983 dai = kzalloc(sizeof(*dai), GFP_KERNEL);
1989 ret = sof_widget_load_dai(scomp, index, swidget, tw, &reply,
1992 sof_connect_dai_widget(scomp, w, tw, dai);
1993 list_add(&dai->list, &sdev->dai_list);
1994 swidget->private = dai;
1999 case snd_soc_dapm_mixer:
2000 ret = sof_widget_load_mixer(scomp, index, swidget, tw, &reply);
2002 case snd_soc_dapm_pga:
2003 ret = sof_widget_load_pga(scomp, index, swidget, tw, &reply);
2004 /* Find scontrol for this pga and set readback offset*/
2005 list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
2006 if (scontrol->comp_id == swidget->comp_id) {
2007 scontrol->readback_offset = reply.offset;
2012 case snd_soc_dapm_buffer:
2013 ret = sof_widget_load_buffer(scomp, index, swidget, tw, &reply);
2015 case snd_soc_dapm_scheduler:
2016 ret = sof_widget_load_pipeline(scomp, index, swidget, tw,
2019 case snd_soc_dapm_aif_out:
2020 ret = sof_widget_load_pcm(scomp, index, swidget,
2021 SOF_IPC_STREAM_CAPTURE, tw, &reply);
2023 case snd_soc_dapm_aif_in:
2024 ret = sof_widget_load_pcm(scomp, index, swidget,
2025 SOF_IPC_STREAM_PLAYBACK, tw, &reply);
2027 case snd_soc_dapm_src:
2028 ret = sof_widget_load_src(scomp, index, swidget, tw, &reply);
2030 case snd_soc_dapm_siggen:
2031 ret = sof_widget_load_siggen(scomp, index, swidget, tw, &reply);
2033 case snd_soc_dapm_effect:
2034 ret = sof_widget_load_process(scomp, index, swidget, tw,
2037 case snd_soc_dapm_mux:
2038 case snd_soc_dapm_demux:
2039 ret = sof_widget_load_mux(scomp, index, swidget, tw, &reply);
2041 case snd_soc_dapm_switch:
2042 case snd_soc_dapm_dai_link:
2043 case snd_soc_dapm_kcontrol:
2045 dev_warn(sdev->dev, "warning: widget type %d name %s not handled\n",
2046 swidget->id, tw->name);
2050 /* check IPC reply */
2051 if (ret < 0 || reply.rhdr.error < 0) {
2053 "error: DSP failed to add widget id %d type %d name : %s stream %s reply %d\n",
2054 tw->shift, swidget->id, tw->name,
2055 strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0
2056 ? tw->sname : "none", reply.rhdr.error);
2061 /* bind widget to external event */
2062 if (tw->event_type) {
2063 ret = sof_widget_bind_event(sdev, swidget,
2064 le16_to_cpu(tw->event_type));
2066 dev_err(sdev->dev, "error: widget event binding failed\n");
2067 kfree(swidget->private);
2073 w->dobj.private = swidget;
2074 list_add(&swidget->list, &sdev->widget_list);
2078 static int sof_route_unload(struct snd_soc_component *scomp,
2079 struct snd_soc_dobj *dobj)
2081 struct snd_sof_route *sroute;
2083 sroute = dobj->private;
2087 /* free sroute and its private data */
2088 kfree(sroute->private);
2089 list_del(&sroute->list);
2095 static int sof_widget_unload(struct snd_soc_component *scomp,
2096 struct snd_soc_dobj *dobj)
2098 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2099 const struct snd_kcontrol_new *kc;
2100 struct snd_soc_dapm_widget *widget;
2101 struct sof_ipc_pipe_new *pipeline;
2102 struct snd_sof_control *scontrol;
2103 struct snd_sof_widget *swidget;
2104 struct soc_mixer_control *sm;
2105 struct soc_bytes_ext *sbe;
2106 struct snd_sof_dai *dai;
2107 struct soc_enum *se;
2111 swidget = dobj->private;
2115 widget = swidget->widget;
2117 switch (swidget->id) {
2118 case snd_soc_dapm_dai_in:
2119 case snd_soc_dapm_dai_out:
2120 dai = swidget->private;
2123 /* free dai config */
2124 kfree(dai->dai_config);
2125 list_del(&dai->list);
2128 case snd_soc_dapm_scheduler:
2130 /* power down the pipeline schedule core */
2131 pipeline = swidget->private;
2132 ret = snd_sof_dsp_core_power_down(sdev, 1 << pipeline->core);
2134 dev_err(sdev->dev, "error: powering down pipeline schedule core %d\n",
2137 /* update enabled cores mask */
2138 sdev->enabled_cores_mask &= ~(1 << pipeline->core);
2144 for (i = 0; i < widget->num_kcontrols; i++) {
2145 kc = &widget->kcontrol_news[i];
2146 switch (dobj->widget.kcontrol_type) {
2147 case SND_SOC_TPLG_TYPE_MIXER:
2148 sm = (struct soc_mixer_control *)kc->private_value;
2149 scontrol = sm->dobj.private;
2151 kfree(scontrol->volume_table);
2153 case SND_SOC_TPLG_TYPE_ENUM:
2154 se = (struct soc_enum *)kc->private_value;
2155 scontrol = se->dobj.private;
2157 case SND_SOC_TPLG_TYPE_BYTES:
2158 sbe = (struct soc_bytes_ext *)kc->private_value;
2159 scontrol = sbe->dobj.private;
2162 dev_warn(sdev->dev, "unsupported kcontrol_type\n");
2165 kfree(scontrol->control_data);
2166 list_del(&scontrol->list);
2171 /* free private value */
2172 kfree(swidget->private);
2174 /* remove and free swidget object */
2175 list_del(&swidget->list);
2182 * DAI HW configuration.
2185 /* FE DAI - used for any driver specific init */
2186 static int sof_dai_load(struct snd_soc_component *scomp, int index,
2187 struct snd_soc_dai_driver *dai_drv,
2188 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai)
2190 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2191 struct snd_soc_tplg_stream_caps *caps;
2192 struct snd_sof_pcm *spcm;
2193 int stream = SNDRV_PCM_STREAM_PLAYBACK;
2196 /* nothing to do for BEs atm */
2200 spcm = kzalloc(sizeof(*spcm), GFP_KERNEL);
2205 spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].comp_id = COMP_ID_UNASSIGNED;
2206 spcm->stream[SNDRV_PCM_STREAM_CAPTURE].comp_id = COMP_ID_UNASSIGNED;
2210 dev_dbg(sdev->dev, "tplg: load pcm %s\n", pcm->dai_name);
2212 dai_drv->dobj.private = spcm;
2213 list_add(&spcm->list, &sdev->pcm_list);
2215 /* do we need to allocate playback PCM DMA pages */
2216 if (!spcm->pcm.playback)
2219 caps = &spcm->pcm.caps[stream];
2221 /* allocate playback page table buffer */
2222 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, sdev->dev,
2223 PAGE_SIZE, &spcm->stream[stream].page_table);
2225 dev_err(sdev->dev, "error: can't alloc page table for %s %d\n",
2231 /* bind pcm to host comp */
2232 ret = spcm_bind(sdev, spcm, stream);
2235 "error: can't bind pcm to host\n");
2236 goto free_playback_tables;
2240 stream = SNDRV_PCM_STREAM_CAPTURE;
2242 /* do we need to allocate capture PCM DMA pages */
2243 if (!spcm->pcm.capture)
2246 caps = &spcm->pcm.caps[stream];
2248 /* allocate capture page table buffer */
2249 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, sdev->dev,
2250 PAGE_SIZE, &spcm->stream[stream].page_table);
2252 dev_err(sdev->dev, "error: can't alloc page table for %s %d\n",
2254 goto free_playback_tables;
2257 /* bind pcm to host comp */
2258 ret = spcm_bind(sdev, spcm, stream);
2261 "error: can't bind pcm to host\n");
2262 snd_dma_free_pages(&spcm->stream[stream].page_table);
2263 goto free_playback_tables;
2268 free_playback_tables:
2269 if (spcm->pcm.playback)
2270 snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].page_table);
2275 static int sof_dai_unload(struct snd_soc_component *scomp,
2276 struct snd_soc_dobj *dobj)
2278 struct snd_sof_pcm *spcm = dobj->private;
2280 /* free PCM DMA pages */
2281 if (spcm->pcm.playback)
2282 snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].page_table);
2284 if (spcm->pcm.capture)
2285 snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_CAPTURE].page_table);
2287 /* remove from list and free spcm */
2288 list_del(&spcm->list);
2294 static void sof_dai_set_format(struct snd_soc_tplg_hw_config *hw_config,
2295 struct sof_ipc_dai_config *config)
2297 /* clock directions wrt codec */
2298 if (hw_config->bclk_master == SND_SOC_TPLG_BCLK_CM) {
2299 /* codec is bclk master */
2300 if (hw_config->fsync_master == SND_SOC_TPLG_FSYNC_CM)
2301 config->format |= SOF_DAI_FMT_CBM_CFM;
2303 config->format |= SOF_DAI_FMT_CBM_CFS;
2305 /* codec is bclk slave */
2306 if (hw_config->fsync_master == SND_SOC_TPLG_FSYNC_CM)
2307 config->format |= SOF_DAI_FMT_CBS_CFM;
2309 config->format |= SOF_DAI_FMT_CBS_CFS;
2312 /* inverted clocks ? */
2313 if (hw_config->invert_bclk) {
2314 if (hw_config->invert_fsync)
2315 config->format |= SOF_DAI_FMT_IB_IF;
2317 config->format |= SOF_DAI_FMT_IB_NF;
2319 if (hw_config->invert_fsync)
2320 config->format |= SOF_DAI_FMT_NB_IF;
2322 config->format |= SOF_DAI_FMT_NB_NF;
2326 /* set config for all DAI's with name matching the link name */
2327 static int sof_set_dai_config(struct snd_sof_dev *sdev, u32 size,
2328 struct snd_soc_dai_link *link,
2329 struct sof_ipc_dai_config *config)
2331 struct snd_sof_dai *dai;
2334 list_for_each_entry(dai, &sdev->dai_list, list) {
2338 if (strcmp(link->name, dai->name) == 0) {
2339 dai->dai_config = kmemdup(config, size, GFP_KERNEL);
2340 if (!dai->dai_config)
2348 * machine driver may define a dai link with playback and capture
2349 * dai enabled, but the dai link in topology would support both, one
2350 * or none of them. Here print a warning message to notify user
2353 dev_warn(sdev->dev, "warning: failed to find dai for dai link %s",
2360 static int sof_link_ssp_load(struct snd_soc_component *scomp, int index,
2361 struct snd_soc_dai_link *link,
2362 struct snd_soc_tplg_link_config *cfg,
2363 struct snd_soc_tplg_hw_config *hw_config,
2364 struct sof_ipc_dai_config *config)
2366 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2367 struct snd_soc_tplg_private *private = &cfg->priv;
2368 struct sof_ipc_reply reply;
2369 u32 size = sizeof(*config);
2372 /* handle master/slave and inverted clocks */
2373 sof_dai_set_format(hw_config, config);
2376 memset(&config->ssp, 0, sizeof(struct sof_ipc_dai_ssp_params));
2377 config->hdr.size = size;
2379 ret = sof_parse_tokens(scomp, &config->ssp, ssp_tokens,
2380 ARRAY_SIZE(ssp_tokens), private->array,
2381 le32_to_cpu(private->size));
2383 dev_err(sdev->dev, "error: parse ssp tokens failed %d\n",
2384 le32_to_cpu(private->size));
2388 config->ssp.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
2389 config->ssp.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
2390 config->ssp.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
2391 config->ssp.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
2392 config->ssp.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
2393 config->ssp.mclk_direction = hw_config->mclk_direction;
2394 config->ssp.rx_slots = le32_to_cpu(hw_config->rx_slots);
2395 config->ssp.tx_slots = le32_to_cpu(hw_config->tx_slots);
2397 dev_dbg(sdev->dev, "tplg: config SSP%d fmt 0x%x mclk %d bclk %d fclk %d width (%d)%d slots %d mclk id %d quirks %d\n",
2398 config->dai_index, config->format,
2399 config->ssp.mclk_rate, config->ssp.bclk_rate,
2400 config->ssp.fsync_rate, config->ssp.sample_valid_bits,
2401 config->ssp.tdm_slot_width, config->ssp.tdm_slots,
2402 config->ssp.mclk_id, config->ssp.quirks);
2404 /* validate SSP fsync rate and channel count */
2405 if (config->ssp.fsync_rate < 8000 || config->ssp.fsync_rate > 192000) {
2406 dev_err(sdev->dev, "error: invalid fsync rate for SSP%d\n",
2411 if (config->ssp.tdm_slots < 1 || config->ssp.tdm_slots > 8) {
2412 dev_err(sdev->dev, "error: invalid channel count for SSP%d\n",
2417 /* send message to DSP */
2418 ret = sof_ipc_tx_message(sdev->ipc,
2419 config->hdr.cmd, config, size, &reply,
2423 dev_err(sdev->dev, "error: failed to set DAI config for SSP%d\n",
2428 /* set config for all DAI's with name matching the link name */
2429 ret = sof_set_dai_config(sdev, size, link, config);
2431 dev_err(sdev->dev, "error: failed to save DAI config for SSP%d\n",
2437 static int sof_link_dmic_load(struct snd_soc_component *scomp, int index,
2438 struct snd_soc_dai_link *link,
2439 struct snd_soc_tplg_link_config *cfg,
2440 struct snd_soc_tplg_hw_config *hw_config,
2441 struct sof_ipc_dai_config *config)
2443 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2444 struct snd_soc_tplg_private *private = &cfg->priv;
2445 struct sof_ipc_dai_config *ipc_config;
2446 struct sof_ipc_reply reply;
2447 struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
2448 struct sof_ipc_fw_version *v = &ready->version;
2453 * config is only used for the common params in dmic_params structure
2454 * that does not include the PDM controller config array
2455 * Set the common params to 0.
2457 memset(&config->dmic, 0, sizeof(struct sof_ipc_dai_dmic_params));
2459 /* get DMIC tokens */
2460 ret = sof_parse_tokens(scomp, &config->dmic, dmic_tokens,
2461 ARRAY_SIZE(dmic_tokens), private->array,
2462 le32_to_cpu(private->size));
2464 dev_err(sdev->dev, "error: parse dmic tokens failed %d\n",
2465 le32_to_cpu(private->size));
2470 * allocate memory for dmic dai config accounting for the
2471 * variable number of active pdm controllers
2472 * This will be the ipc payload for setting dai config
2474 size = sizeof(*config) + sizeof(struct sof_ipc_dai_dmic_pdm_ctrl) *
2475 config->dmic.num_pdm_active;
2477 ipc_config = kzalloc(size, GFP_KERNEL);
2481 /* copy the common dai config and dmic params */
2482 memcpy(ipc_config, config, sizeof(*config));
2485 * alloc memory for private member
2486 * Used to track the pdm config array index currently being parsed
2488 sdev->private = kzalloc(sizeof(u32), GFP_KERNEL);
2489 if (!sdev->private) {
2494 /* get DMIC PDM tokens */
2495 ret = sof_parse_tokens(scomp, &ipc_config->dmic.pdm[0], dmic_pdm_tokens,
2496 ARRAY_SIZE(dmic_pdm_tokens), private->array,
2497 le32_to_cpu(private->size));
2499 dev_err(sdev->dev, "error: parse dmic pdm tokens failed %d\n",
2500 le32_to_cpu(private->size));
2504 /* set IPC header size */
2505 ipc_config->hdr.size = size;
2507 /* debug messages */
2508 dev_dbg(sdev->dev, "tplg: config DMIC%d driver version %d\n",
2509 ipc_config->dai_index, ipc_config->dmic.driver_ipc_version);
2510 dev_dbg(sdev->dev, "pdmclk_min %d pdm_clkmax %d duty_min %hd\n",
2511 ipc_config->dmic.pdmclk_min, ipc_config->dmic.pdmclk_max,
2512 ipc_config->dmic.duty_min);
2513 dev_dbg(sdev->dev, "duty_max %hd fifo_fs %d num_pdms active %d\n",
2514 ipc_config->dmic.duty_max, ipc_config->dmic.fifo_fs,
2515 ipc_config->dmic.num_pdm_active);
2516 dev_dbg(sdev->dev, "fifo word length %hd\n",
2517 ipc_config->dmic.fifo_bits);
2519 for (j = 0; j < ipc_config->dmic.num_pdm_active; j++) {
2520 dev_dbg(sdev->dev, "pdm %hd mic a %hd mic b %hd\n",
2521 ipc_config->dmic.pdm[j].id,
2522 ipc_config->dmic.pdm[j].enable_mic_a,
2523 ipc_config->dmic.pdm[j].enable_mic_b);
2524 dev_dbg(sdev->dev, "pdm %hd polarity a %hd polarity b %hd\n",
2525 ipc_config->dmic.pdm[j].id,
2526 ipc_config->dmic.pdm[j].polarity_mic_a,
2527 ipc_config->dmic.pdm[j].polarity_mic_b);
2528 dev_dbg(sdev->dev, "pdm %hd clk_edge %hd skew %hd\n",
2529 ipc_config->dmic.pdm[j].id,
2530 ipc_config->dmic.pdm[j].clk_edge,
2531 ipc_config->dmic.pdm[j].skew);
2534 if (SOF_ABI_VER(v->major, v->minor, v->micro) < SOF_ABI_VER(3, 0, 1)) {
2535 /* this takes care of backwards compatible handling of fifo_bits_b */
2536 ipc_config->dmic.reserved_2 = ipc_config->dmic.fifo_bits;
2539 /* send message to DSP */
2540 ret = sof_ipc_tx_message(sdev->ipc,
2541 ipc_config->hdr.cmd, ipc_config, size, &reply,
2546 "error: failed to set DAI config for DMIC%d\n",
2551 /* set config for all DAI's with name matching the link name */
2552 ret = sof_set_dai_config(sdev, size, link, ipc_config);
2554 dev_err(sdev->dev, "error: failed to save DAI config for DMIC%d\n",
2558 kfree(sdev->private);
2565 * for hda link, playback and capture are supported by different dai
2566 * in FW. Here get the dai_index, set dma channel of each dai
2567 * and send config to FW. In FW, each dai sets config by dai_index
2569 static int sof_link_hda_process(struct snd_sof_dev *sdev,
2570 struct snd_soc_dai_link *link,
2571 struct sof_ipc_dai_config *config,
2575 struct sof_ipc_reply reply;
2576 u32 size = sizeof(*config);
2577 struct snd_sof_dai *sof_dai;
2581 list_for_each_entry(sof_dai, &sdev->dai_list, list) {
2585 if (strcmp(link->name, sof_dai->name) == 0) {
2586 if (sof_dai->comp_dai.direction ==
2587 SNDRV_PCM_STREAM_PLAYBACK) {
2588 if (!link->dpcm_playback)
2591 config->hda.link_dma_ch = tx_slot;
2593 if (!link->dpcm_capture)
2596 config->hda.link_dma_ch = rx_slot;
2599 config->dai_index = sof_dai->comp_dai.dai_index;
2602 /* save config in dai component */
2603 sof_dai->dai_config = kmemdup(config, size, GFP_KERNEL);
2604 if (!sof_dai->dai_config)
2607 /* send message to DSP */
2608 ret = sof_ipc_tx_message(sdev->ipc,
2609 config->hdr.cmd, config, size,
2610 &reply, sizeof(reply));
2613 dev_err(sdev->dev, "error: failed to set DAI config for direction:%d of HDA dai %d\n",
2614 sof_dai->comp_dai.direction,
2623 * machine driver may define a dai link with playback and capture
2624 * dai enabled, but the dai link in topology would support both, one
2625 * or none of them. Here print a warning message to notify user
2628 dev_warn(sdev->dev, "warning: failed to find dai for dai link %s",
2635 static int sof_link_hda_load(struct snd_soc_component *scomp, int index,
2636 struct snd_soc_dai_link *link,
2637 struct snd_soc_tplg_link_config *cfg,
2638 struct snd_soc_tplg_hw_config *hw_config,
2639 struct sof_ipc_dai_config *config)
2641 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2642 struct snd_soc_dai_link_component dai_component;
2643 struct snd_soc_tplg_private *private = &cfg->priv;
2644 struct snd_soc_dai *dai;
2645 u32 size = sizeof(*config);
2653 memset(&dai_component, 0, sizeof(dai_component));
2654 memset(&config->hda, 0, sizeof(struct sof_ipc_dai_hda_params));
2655 config->hdr.size = size;
2657 /* get any bespoke DAI tokens */
2658 ret = sof_parse_tokens(scomp, config, hda_tokens,
2659 ARRAY_SIZE(hda_tokens), private->array,
2660 le32_to_cpu(private->size));
2662 dev_err(sdev->dev, "error: parse hda tokens failed %d\n",
2663 le32_to_cpu(private->size));
2667 dai_component.dai_name = link->cpu_dai_name;
2668 dai = snd_soc_find_dai(&dai_component);
2670 dev_err(sdev->dev, "error: failed to find dai %s in %s",
2671 dai_component.dai_name, __func__);
2675 if (link->dpcm_playback)
2678 if (link->dpcm_capture)
2681 ret = snd_soc_dai_get_channel_map(dai, &tx_num, &tx_slot,
2684 dev_err(sdev->dev, "error: failed to get dma channel for HDA%d\n",
2690 ret = sof_link_hda_process(sdev, link, config, tx_slot, rx_slot);
2692 dev_err(sdev->dev, "error: failed to process hda dai link %s",
2698 /* DAI link - used for any driver specific init */
2699 static int sof_link_load(struct snd_soc_component *scomp, int index,
2700 struct snd_soc_dai_link *link,
2701 struct snd_soc_tplg_link_config *cfg)
2703 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2704 struct snd_soc_tplg_private *private = &cfg->priv;
2705 struct sof_ipc_dai_config config;
2706 struct snd_soc_tplg_hw_config *hw_config;
2711 link->platform_name = dev_name(sdev->dev);
2714 * Set nonatomic property for FE dai links as their trigger action
2717 if (!link->no_pcm) {
2718 link->nonatomic = true;
2720 /* nothing more to do for FE dai links */
2724 /* check we have some tokens - we need at least DAI type */
2725 if (le32_to_cpu(private->size) == 0) {
2726 dev_err(sdev->dev, "error: expected tokens for DAI, none found\n");
2730 /* Send BE DAI link configurations to DSP */
2731 memset(&config, 0, sizeof(config));
2733 /* get any common DAI tokens */
2734 ret = sof_parse_tokens(scomp, &config, dai_link_tokens,
2735 ARRAY_SIZE(dai_link_tokens), private->array,
2736 le32_to_cpu(private->size));
2738 dev_err(sdev->dev, "error: parse link tokens failed %d\n",
2739 le32_to_cpu(private->size));
2744 * DAI links are expected to have at least 1 hw_config.
2745 * But some older topologies might have no hw_config for HDA dai links.
2747 num_hw_configs = le32_to_cpu(cfg->num_hw_configs);
2748 if (!num_hw_configs) {
2749 if (config.type != SOF_DAI_INTEL_HDA) {
2750 dev_err(sdev->dev, "error: unexpected DAI config count %d!\n",
2751 le32_to_cpu(cfg->num_hw_configs));
2755 dev_dbg(sdev->dev, "tplg: %d hw_configs found, default id: %d!\n",
2756 cfg->num_hw_configs, le32_to_cpu(cfg->default_hw_config_id));
2758 for (i = 0; i < num_hw_configs; i++) {
2759 if (cfg->hw_config[i].id == cfg->default_hw_config_id)
2763 if (i == num_hw_configs) {
2764 dev_err(sdev->dev, "error: default hw_config id: %d not found!\n",
2765 le32_to_cpu(cfg->default_hw_config_id));
2770 /* configure dai IPC message */
2771 hw_config = &cfg->hw_config[i];
2773 config.hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG;
2774 config.format = le32_to_cpu(hw_config->fmt);
2776 /* now load DAI specific data and send IPC - type comes from token */
2777 switch (config.type) {
2778 case SOF_DAI_INTEL_SSP:
2779 ret = sof_link_ssp_load(scomp, index, link, cfg, hw_config,
2782 case SOF_DAI_INTEL_DMIC:
2783 ret = sof_link_dmic_load(scomp, index, link, cfg, hw_config,
2786 case SOF_DAI_INTEL_HDA:
2787 ret = sof_link_hda_load(scomp, index, link, cfg, hw_config,
2791 dev_err(sdev->dev, "error: invalid DAI type %d\n", config.type);
2801 static int sof_link_hda_unload(struct snd_sof_dev *sdev,
2802 struct snd_soc_dai_link *link)
2804 struct snd_soc_dai_link_component dai_component;
2805 struct snd_soc_dai *dai;
2808 memset(&dai_component, 0, sizeof(dai_component));
2809 dai_component.dai_name = link->cpu_dai_name;
2810 dai = snd_soc_find_dai(&dai_component);
2812 dev_err(sdev->dev, "error: failed to find dai %s in %s",
2813 dai_component.dai_name, __func__);
2818 * FIXME: this call to hw_free is mainly to release the link DMA ID.
2819 * This is abusing the API and handling SOC internals is not
2820 * recommended. This part will be reworked.
2822 if (dai->driver->ops->hw_free)
2823 ret = dai->driver->ops->hw_free(NULL, dai);
2825 dev_err(sdev->dev, "error: failed to free hda resource for %s\n",
2831 static int sof_link_unload(struct snd_soc_component *scomp,
2832 struct snd_soc_dobj *dobj)
2834 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2835 struct snd_soc_dai_link *link =
2836 container_of(dobj, struct snd_soc_dai_link, dobj);
2838 struct snd_sof_dai *sof_dai;
2841 /* only BE link is loaded by sof */
2845 list_for_each_entry(sof_dai, &sdev->dai_list, list) {
2849 if (strcmp(link->name, sof_dai->name) == 0)
2853 dev_err(sdev->dev, "error: failed to find dai %s in %s",
2854 link->name, __func__);
2858 switch (sof_dai->dai_config->type) {
2859 case SOF_DAI_INTEL_SSP:
2860 case SOF_DAI_INTEL_DMIC:
2861 /* no resource needs to be released for SSP and DMIC */
2863 case SOF_DAI_INTEL_HDA:
2864 ret = sof_link_hda_unload(sdev, link);
2867 dev_err(sdev->dev, "error: invalid DAI type %d\n",
2868 sof_dai->dai_config->type);
2876 /* DAI link - used for any driver specific init */
2877 static int sof_route_load(struct snd_soc_component *scomp, int index,
2878 struct snd_soc_dapm_route *route)
2880 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2881 struct sof_ipc_pipe_comp_connect *connect;
2882 struct snd_sof_widget *source_swidget, *sink_swidget;
2883 struct snd_soc_dobj *dobj = &route->dobj;
2884 struct snd_sof_route *sroute;
2885 struct sof_ipc_reply reply;
2888 /* allocate memory for sroute and connect */
2889 sroute = kzalloc(sizeof(*sroute), GFP_KERNEL);
2893 sroute->sdev = sdev;
2895 connect = kzalloc(sizeof(*connect), GFP_KERNEL);
2901 connect->hdr.size = sizeof(*connect);
2902 connect->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_CONNECT;
2904 dev_dbg(sdev->dev, "sink %s control %s source %s\n",
2905 route->sink, route->control ? route->control : "none",
2908 /* source component */
2909 source_swidget = snd_sof_find_swidget(sdev, (char *)route->source);
2910 if (!source_swidget) {
2911 dev_err(sdev->dev, "error: source %s not found\n",
2918 * Virtual widgets of type output/out_drv may be added in topology
2919 * for compatibility. These are not handled by the FW.
2920 * So, don't send routes whose source/sink widget is of such types
2923 if (source_swidget->id == snd_soc_dapm_out_drv ||
2924 source_swidget->id == snd_soc_dapm_output)
2927 connect->source_id = source_swidget->comp_id;
2929 /* sink component */
2930 sink_swidget = snd_sof_find_swidget(sdev, (char *)route->sink);
2931 if (!sink_swidget) {
2932 dev_err(sdev->dev, "error: sink %s not found\n",
2939 * Don't send routes whose sink widget is of type
2940 * output or out_drv to the DSP
2942 if (sink_swidget->id == snd_soc_dapm_out_drv ||
2943 sink_swidget->id == snd_soc_dapm_output)
2946 connect->sink_id = sink_swidget->comp_id;
2949 * For virtual routes, both sink and source are not
2950 * buffer. Since only buffer linked to component is supported by
2951 * FW, others are reported as error, add check in route function,
2952 * do not send it to FW when both source and sink are not buffer
2954 if (source_swidget->id != snd_soc_dapm_buffer &&
2955 sink_swidget->id != snd_soc_dapm_buffer) {
2956 dev_dbg(sdev->dev, "warning: neither Linked source component %s nor sink component %s is of buffer type, ignoring link\n",
2957 route->source, route->sink);
2961 ret = sof_ipc_tx_message(sdev->ipc,
2963 connect, sizeof(*connect),
2964 &reply, sizeof(reply));
2966 /* check IPC return value */
2968 dev_err(sdev->dev, "error: failed to add route sink %s control %s source %s\n",
2970 route->control ? route->control : "none",
2975 /* check IPC reply */
2976 if (reply.error < 0) {
2977 dev_err(sdev->dev, "error: DSP failed to add route sink %s control %s source %s result %d\n",
2979 route->control ? route->control : "none",
2980 route->source, reply.error);
2985 sroute->route = route;
2986 dobj->private = sroute;
2987 sroute->private = connect;
2989 /* add route to route list */
2990 list_add(&sroute->list, &sdev->route_list);
3001 int snd_sof_complete_pipeline(struct snd_sof_dev *sdev,
3002 struct snd_sof_widget *swidget)
3004 struct sof_ipc_pipe_ready ready;
3005 struct sof_ipc_reply reply;
3008 dev_dbg(sdev->dev, "tplg: complete pipeline %s id %d\n",
3009 swidget->widget->name, swidget->comp_id);
3011 memset(&ready, 0, sizeof(ready));
3012 ready.hdr.size = sizeof(ready);
3013 ready.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_COMPLETE;
3014 ready.comp_id = swidget->comp_id;
3016 ret = sof_ipc_tx_message(sdev->ipc,
3017 ready.hdr.cmd, &ready, sizeof(ready), &reply,
3024 /* completion - called at completion of firmware loading */
3025 static void sof_complete(struct snd_soc_component *scomp)
3027 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
3028 struct snd_sof_widget *swidget;
3030 /* some widget types require completion notificattion */
3031 list_for_each_entry(swidget, &sdev->widget_list, list) {
3032 if (swidget->complete)
3035 switch (swidget->id) {
3036 case snd_soc_dapm_scheduler:
3038 snd_sof_complete_pipeline(sdev, swidget);
3046 /* manifest - optional to inform component of manifest */
3047 static int sof_manifest(struct snd_soc_component *scomp, int index,
3048 struct snd_soc_tplg_manifest *man)
3050 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
3054 size = le32_to_cpu(man->priv.size);
3056 /* backward compatible with tplg without ABI info */
3058 dev_dbg(sdev->dev, "No topology ABI info\n");
3062 if (size != SOF_TPLG_ABI_SIZE) {
3063 dev_err(sdev->dev, "error: invalid topology ABI size\n");
3068 "Topology: ABI %d:%d:%d Kernel ABI %d:%d:%d\n",
3069 man->priv.data[0], man->priv.data[1],
3070 man->priv.data[2], SOF_ABI_MAJOR, SOF_ABI_MINOR,
3073 abi_version = SOF_ABI_VER(man->priv.data[0],
3077 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, abi_version)) {
3078 dev_err(sdev->dev, "error: incompatible topology ABI version\n");
3082 if (abi_version > SOF_ABI_VERSION) {
3083 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS)) {
3084 dev_warn(sdev->dev, "warn: topology ABI is more recent than kernel\n");
3086 dev_err(sdev->dev, "error: topology ABI is more recent than kernel\n");
3094 /* vendor specific kcontrol handlers available for binding */
3095 static const struct snd_soc_tplg_kcontrol_ops sof_io_ops[] = {
3096 {SOF_TPLG_KCTL_VOL_ID, snd_sof_volume_get, snd_sof_volume_put},
3097 {SOF_TPLG_KCTL_BYTES_ID, snd_sof_bytes_get, snd_sof_bytes_put},
3098 {SOF_TPLG_KCTL_ENUM_ID, snd_sof_enum_get, snd_sof_enum_put},
3099 {SOF_TPLG_KCTL_SWITCH_ID, snd_sof_switch_get, snd_sof_switch_put},
3102 /* vendor specific bytes ext handlers available for binding */
3103 static const struct snd_soc_tplg_bytes_ext_ops sof_bytes_ext_ops[] = {
3104 {SOF_TPLG_KCTL_BYTES_ID, snd_sof_bytes_ext_get, snd_sof_bytes_ext_put},
3107 static struct snd_soc_tplg_ops sof_tplg_ops = {
3108 /* external kcontrol init - used for any driver specific init */
3109 .control_load = sof_control_load,
3110 .control_unload = sof_control_unload,
3112 /* external kcontrol init - used for any driver specific init */
3113 .dapm_route_load = sof_route_load,
3114 .dapm_route_unload = sof_route_unload,
3116 /* external widget init - used for any driver specific init */
3117 /* .widget_load is not currently used */
3118 .widget_ready = sof_widget_ready,
3119 .widget_unload = sof_widget_unload,
3121 /* FE DAI - used for any driver specific init */
3122 .dai_load = sof_dai_load,
3123 .dai_unload = sof_dai_unload,
3125 /* DAI link - used for any driver specific init */
3126 .link_load = sof_link_load,
3127 .link_unload = sof_link_unload,
3129 /* completion - called at completion of firmware loading */
3130 .complete = sof_complete,
3132 /* manifest - optional to inform component of manifest */
3133 .manifest = sof_manifest,
3135 /* vendor specific kcontrol handlers available for binding */
3136 .io_ops = sof_io_ops,
3137 .io_ops_count = ARRAY_SIZE(sof_io_ops),
3139 /* vendor specific bytes ext handlers available for binding */
3140 .bytes_ext_ops = sof_bytes_ext_ops,
3141 .bytes_ext_ops_count = ARRAY_SIZE(sof_bytes_ext_ops),
3144 int snd_sof_init_topology(struct snd_sof_dev *sdev,
3145 struct snd_soc_tplg_ops *ops)
3147 /* TODO: support linked list of topologies */
3148 sdev->tplg_ops = ops;
3151 EXPORT_SYMBOL(snd_sof_init_topology);
3153 int snd_sof_load_topology(struct snd_sof_dev *sdev, const char *file)
3155 const struct firmware *fw;
3158 dev_dbg(sdev->dev, "loading topology:%s\n", file);
3160 ret = request_firmware(&fw, file, sdev->dev);
3162 dev_err(sdev->dev, "error: tplg request firmware %s failed err: %d\n",
3167 ret = snd_soc_tplg_component_load(sdev->component,
3169 SND_SOC_TPLG_INDEX_ALL);
3171 dev_err(sdev->dev, "error: tplg component load failed %d\n",
3176 release_firmware(fw);
3179 EXPORT_SYMBOL(snd_sof_load_topology);