^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // This file is provided under a dual BSD/GPLv2 license. When using or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // redistributing this file, you may do so under either license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Copyright(c) 2018 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/bits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <uapi/sound/sof/tokens.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "sof-priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "sof-audio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define COMP_ID_UNASSIGNED 0xffffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Constants used in the computation of linear volume gain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * from dB gain 20th root of 10 in Q1.16 fixed-point notation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define VOL_TWENTIETH_ROOT_OF_TEN 73533
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* 40th root of 10 in Q1.16 fixed-point notation*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define VOL_FORTIETH_ROOT_OF_TEN 69419
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Volume fractional word length define to 16 sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * the volume linear gain value to use Qx.16 format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define VOLUME_FWL 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* 0.5 dB step value in topology TLV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define VOL_HALF_DB_STEP 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* Full volume for default values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define VOL_ZERO_DB BIT(VOLUME_FWL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* TLV data items */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define TLV_ITEMS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define TLV_MIN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define TLV_STEP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define TLV_MUTE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* size of tplg abi in byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define SOF_TPLG_ABI_SIZE 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct sof_widget_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int ctrl_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int ipc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct sof_abi_hdr *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct snd_sof_control *control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* send pcm params ipc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int ipc_pcm_params(struct snd_sof_widget *swidget, int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct sof_ipc_pcm_params_reply ipc_params_reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct snd_soc_component *scomp = swidget->scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct sof_ipc_pcm_params pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct snd_pcm_hw_params *params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) memset(&pcm, 0, sizeof(pcm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* get runtime PCM params using widget's stream name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (!spcm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) dev_err(scomp->dev, "error: cannot find PCM for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) params = &spcm->params[dir];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* set IPC PCM params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) pcm.hdr.size = sizeof(pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) pcm.comp_id = swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) pcm.params.hdr.size = sizeof(pcm.params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) pcm.params.direction = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) pcm.params.sample_valid_bytes = params_width(params) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) pcm.params.rate = params_rate(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) pcm.params.channels = params_channels(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) pcm.params.host_period_bytes = params_period_bytes(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* set format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) switch (params_format(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) case SNDRV_PCM_FORMAT_S16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pcm.params.frame_fmt = SOF_IPC_FRAME_S16_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case SNDRV_PCM_FORMAT_S24:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) pcm.params.frame_fmt = SOF_IPC_FRAME_S24_4LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) case SNDRV_PCM_FORMAT_S32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* send IPC to the DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) &ipc_params_reply, sizeof(ipc_params_reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) dev_err(scomp->dev, "error: pcm params failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* send stream trigger ipc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int ipc_trigger(struct snd_sof_widget *swidget, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct snd_soc_component *scomp = swidget->scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct sof_ipc_stream stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct sof_ipc_reply reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* set IPC stream params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) stream.hdr.size = sizeof(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) stream.comp_id = swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* send IPC to the DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) sizeof(stream), &reply, sizeof(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) dev_err(scomp->dev, "error: failed to trigger %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int sof_keyword_dapm_event(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct snd_kcontrol *k, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct snd_sof_widget *swidget = w->dobj.private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct snd_soc_component *scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int stream = SNDRV_PCM_STREAM_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!swidget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) scomp = swidget->scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) dev_dbg(scomp->dev, "received event %d for widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) event, w->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* get runtime PCM params using widget's stream name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (!spcm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) dev_err(scomp->dev, "error: cannot find PCM for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* process events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) case SND_SOC_DAPM_PRE_PMU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (spcm->stream[stream].suspend_ignored) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) dev_dbg(scomp->dev, "PRE_PMU event ignored, KWD pipeline is already RUNNING\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* set pcm params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ret = ipc_pcm_params(swidget, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) "error: failed to set pcm params for widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* start trigger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ret = ipc_trigger(swidget, SOF_IPC_STREAM_TRIG_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) "error: failed to trigger widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) case SND_SOC_DAPM_POST_PMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (spcm->stream[stream].suspend_ignored) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) dev_dbg(scomp->dev, "POST_PMD even ignored, KWD pipeline will remain RUNNING\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* stop trigger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ret = ipc_trigger(swidget, SOF_IPC_STREAM_TRIG_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) "error: failed to trigger widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* pcm free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ret = ipc_trigger(swidget, SOF_IPC_STREAM_PCM_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) "error: failed to trigger widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* event handlers for keyword detect component */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static const struct snd_soc_tplg_widget_events sof_kwd_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {SOF_KEYWORD_DETECT_DAPM_EVENT, sof_keyword_dapm_event},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static inline int get_tlv_data(const int *p, int tlv[TLV_ITEMS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* we only support dB scale TLV type at the moment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if ((int)p[SNDRV_CTL_TLVO_TYPE] != SNDRV_CTL_TLVT_DB_SCALE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* min value in topology tlv data is multiplied by 100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) tlv[TLV_MIN] = (int)p[SNDRV_CTL_TLVO_DB_SCALE_MIN] / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* volume steps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) tlv[TLV_STEP] = (int)(p[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) TLV_DB_SCALE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* mute ON/OFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if ((p[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) TLV_DB_SCALE_MUTE) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) tlv[TLV_MUTE] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) tlv[TLV_MUTE] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * Function to truncate an unsigned 64-bit number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * by x bits and return 32-bit unsigned number. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * function also takes care of rounding while truncating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static inline u32 vol_shift_64(u64 i, u32 x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* do not truncate more than 32 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (x > 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) x = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (x == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return (u32)i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return (u32)(((i >> (x - 1)) + 1) >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * Function to compute a ^ exp where,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * a is a fractional number represented by a fixed-point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * integer with a fractional world length of "fwl"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * exp is an integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * fwl is the fractional word length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * Return value is a fractional number represented by a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * fixed-point integer with a fractional word length of "fwl"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static u32 vol_pow32(u32 a, int exp, u32 fwl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int i, iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) u32 power = 1 << fwl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) u64 numerator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* if exponent is 0, return 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (exp == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* determine the number of iterations based on the exponent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (exp < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) iter = exp * -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) iter = exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* mutiply a "iter" times to compute power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) for (i = 0; i < iter; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * Product of 2 Qx.fwl fixed-point numbers yields a Q2*x.2*fwl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Truncate product back to fwl fractional bits with rounding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) power = vol_shift_64((u64)power * a, fwl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (exp > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* if exp is positive, return the result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* if exp is negative, return the multiplicative inverse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) numerator = (u64)1 << (fwl << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) do_div(numerator, power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return (u32)numerator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * Function to calculate volume gain from TLV data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * This function can only handle gain steps that are multiples of 0.5 dB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static u32 vol_compute_gain(u32 value, int *tlv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) int dB_gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) u32 linear_gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int f_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* mute volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (value == 0 && tlv[TLV_MUTE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * compute dB gain from tlv. tlv_step
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * in topology is multiplied by 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) dB_gain = tlv[TLV_MIN] + (value * tlv[TLV_STEP]) / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * compute linear gain represented by fixed-point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * int with VOLUME_FWL fractional bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) linear_gain = vol_pow32(VOL_TWENTIETH_ROOT_OF_TEN, dB_gain, VOLUME_FWL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* extract the fractional part of volume step */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) f_step = tlv[TLV_STEP] - (tlv[TLV_STEP] / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* if volume step is an odd multiple of 0.5 dB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (f_step == VOL_HALF_DB_STEP && (value & 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) linear_gain = vol_shift_64((u64)linear_gain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) VOL_FORTIETH_ROOT_OF_TEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) VOLUME_FWL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return linear_gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * Set up volume table for kcontrols from tlv data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * "size" specifies the number of entries in the table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static int set_up_volume_table(struct snd_sof_control *scontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int tlv[TLV_ITEMS], int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* init the volume table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) scontrol->volume_table = kcalloc(size, sizeof(u32), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (!scontrol->volume_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* populate the volume table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) for (j = 0; j < size ; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) scontrol->volume_table[j] = vol_compute_gain(j, tlv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct sof_dai_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) enum sof_ipc_dai_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static const struct sof_dai_types sof_dais[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {"SSP", SOF_DAI_INTEL_SSP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {"HDA", SOF_DAI_INTEL_HDA},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {"DMIC", SOF_DAI_INTEL_DMIC},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {"ALH", SOF_DAI_INTEL_ALH},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {"SAI", SOF_DAI_IMX_SAI},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {"ESAI", SOF_DAI_IMX_ESAI},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static enum sof_ipc_dai_type find_dai(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) for (i = 0; i < ARRAY_SIZE(sof_dais); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (strcmp(name, sof_dais[i].name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return sof_dais[i].type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return SOF_DAI_INTEL_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * Supported Frame format types and lookup, add new ones to end of list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct sof_frame_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) enum sof_ipc_frame frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static const struct sof_frame_types sof_frames[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {"s16le", SOF_IPC_FRAME_S16_LE},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {"s24le", SOF_IPC_FRAME_S24_4LE},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {"s32le", SOF_IPC_FRAME_S32_LE},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {"float", SOF_IPC_FRAME_FLOAT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static enum sof_ipc_frame find_format(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) for (i = 0; i < ARRAY_SIZE(sof_frames); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (strcmp(name, sof_frames[i].name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return sof_frames[i].frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /* use s32le if nothing is specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return SOF_IPC_FRAME_S32_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct sof_process_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) enum sof_ipc_process_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) enum sof_comp_type comp_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static const struct sof_process_types sof_process[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {"EQFIR", SOF_PROCESS_EQFIR, SOF_COMP_EQ_FIR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {"EQIIR", SOF_PROCESS_EQIIR, SOF_COMP_EQ_IIR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {"KEYWORD_DETECT", SOF_PROCESS_KEYWORD_DETECT, SOF_COMP_KEYWORD_DETECT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {"KPB", SOF_PROCESS_KPB, SOF_COMP_KPB},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {"CHAN_SELECTOR", SOF_PROCESS_CHAN_SELECTOR, SOF_COMP_SELECTOR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {"MUX", SOF_PROCESS_MUX, SOF_COMP_MUX},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {"DEMUX", SOF_PROCESS_DEMUX, SOF_COMP_DEMUX},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {"DCBLOCK", SOF_PROCESS_DCBLOCK, SOF_COMP_DCBLOCK},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {"SMART_AMP", SOF_PROCESS_SMART_AMP, SOF_COMP_SMART_AMP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static enum sof_ipc_process_type find_process(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) for (i = 0; i < ARRAY_SIZE(sof_process); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (strcmp(name, sof_process[i].name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return sof_process[i].type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return SOF_PROCESS_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static enum sof_comp_type find_process_comp_type(enum sof_ipc_process_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) for (i = 0; i < ARRAY_SIZE(sof_process); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (sof_process[i].type == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return sof_process[i].comp_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return SOF_COMP_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * Topology Token Parsing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * New tokens should be added to headers and parsing tables below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct sof_topology_token {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) u32 token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int (*get_token)(void *elem, void *object, u32 offset, u32 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) u32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static int get_token_u32(void *elem, void *object, u32 offset, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct snd_soc_tplg_vendor_value_elem *velem = elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) u32 *val = (u32 *)((u8 *)object + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) *val = le32_to_cpu(velem->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static int get_token_u16(void *elem, void *object, u32 offset, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct snd_soc_tplg_vendor_value_elem *velem = elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) u16 *val = (u16 *)((u8 *)object + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) *val = (u16)le32_to_cpu(velem->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static int get_token_uuid(void *elem, void *object, u32 offset, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) struct snd_soc_tplg_vendor_uuid_elem *velem = elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) u8 *dst = (u8 *)object + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) memcpy(dst, velem->uuid, UUID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static int get_token_comp_format(void *elem, void *object, u32 offset, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct snd_soc_tplg_vendor_string_elem *velem = elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) u32 *val = (u32 *)((u8 *)object + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) *val = find_format(velem->string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int get_token_dai_type(void *elem, void *object, u32 offset, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct snd_soc_tplg_vendor_string_elem *velem = elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) u32 *val = (u32 *)((u8 *)object + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) *val = find_dai(velem->string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static int get_token_process_type(void *elem, void *object, u32 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct snd_soc_tplg_vendor_string_elem *velem = elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) u32 *val = (u32 *)((u8 *)object + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) *val = find_process(velem->string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /* Buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static const struct sof_topology_token buffer_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) offsetof(struct sof_ipc_buffer, size), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) offsetof(struct sof_ipc_buffer, caps), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* DAI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static const struct sof_topology_token dai_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) offsetof(struct sof_ipc_comp_dai, type), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) offsetof(struct sof_ipc_comp_dai, dai_index), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {SOF_TKN_DAI_DIRECTION, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) offsetof(struct sof_ipc_comp_dai, direction), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* BE DAI link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static const struct sof_topology_token dai_link_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) offsetof(struct sof_ipc_dai_config, type), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) offsetof(struct sof_ipc_dai_config, dai_index), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /* scheduling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static const struct sof_topology_token sched_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {SOF_TKN_SCHED_PERIOD, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) offsetof(struct sof_ipc_pipe_new, period), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {SOF_TKN_SCHED_PRIORITY, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) offsetof(struct sof_ipc_pipe_new, priority), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {SOF_TKN_SCHED_MIPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) offsetof(struct sof_ipc_pipe_new, period_mips), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {SOF_TKN_SCHED_CORE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) offsetof(struct sof_ipc_pipe_new, core), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {SOF_TKN_SCHED_FRAMES, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) offsetof(struct sof_ipc_pipe_new, frames_per_sched), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {SOF_TKN_SCHED_TIME_DOMAIN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) offsetof(struct sof_ipc_pipe_new, time_domain), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /* volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static const struct sof_topology_token volume_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) {SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) get_token_u32, offsetof(struct sof_ipc_comp_volume, ramp), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {SOF_TKN_VOLUME_RAMP_STEP_MS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) offsetof(struct sof_ipc_comp_volume, initial_ramp), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /* SRC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static const struct sof_topology_token src_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {SOF_TKN_SRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) offsetof(struct sof_ipc_comp_src, source_rate), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) {SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) offsetof(struct sof_ipc_comp_src, sink_rate), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) /* ASRC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static const struct sof_topology_token asrc_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {SOF_TKN_ASRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) offsetof(struct sof_ipc_comp_asrc, source_rate), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {SOF_TKN_ASRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) offsetof(struct sof_ipc_comp_asrc, sink_rate), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {SOF_TKN_ASRC_ASYNCHRONOUS_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) offsetof(struct sof_ipc_comp_asrc, asynchronous_mode), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {SOF_TKN_ASRC_OPERATION_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) offsetof(struct sof_ipc_comp_asrc, operation_mode), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) /* Tone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static const struct sof_topology_token tone_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* EFFECT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static const struct sof_topology_token process_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {SOF_TKN_PROCESS_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) get_token_process_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) offsetof(struct sof_ipc_comp_process, type), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /* PCM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static const struct sof_topology_token pcm_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) {SOF_TKN_PCM_DMAC_CONFIG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) offsetof(struct sof_ipc_comp_host, dmac_config), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* PCM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static const struct sof_topology_token stream_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {SOF_TKN_STREAM_PLAYBACK_COMPATIBLE_D0I3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) offsetof(struct snd_sof_pcm, stream[0].d0i3_compatible), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {SOF_TKN_STREAM_CAPTURE_COMPATIBLE_D0I3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) offsetof(struct snd_sof_pcm, stream[1].d0i3_compatible), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) /* Generic components */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static const struct sof_topology_token comp_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {SOF_TKN_COMP_PERIOD_SINK_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) offsetof(struct sof_ipc_comp_config, periods_sink), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {SOF_TKN_COMP_PERIOD_SOURCE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) offsetof(struct sof_ipc_comp_config, periods_source), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) {SOF_TKN_COMP_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) offsetof(struct sof_ipc_comp_config, frame_fmt), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* SSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static const struct sof_topology_token ssp_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) {SOF_TKN_INTEL_SSP_CLKS_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) offsetof(struct sof_ipc_dai_ssp_params, clks_control), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {SOF_TKN_INTEL_SSP_MCLK_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) offsetof(struct sof_ipc_dai_ssp_params, mclk_id), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {SOF_TKN_INTEL_SSP_SAMPLE_BITS, SND_SOC_TPLG_TUPLE_TYPE_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) offsetof(struct sof_ipc_dai_ssp_params, sample_valid_bits), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {SOF_TKN_INTEL_SSP_FRAME_PULSE_WIDTH, SND_SOC_TPLG_TUPLE_TYPE_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) offsetof(struct sof_ipc_dai_ssp_params, frame_pulse_width), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {SOF_TKN_INTEL_SSP_QUIRKS, SND_SOC_TPLG_TUPLE_TYPE_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) offsetof(struct sof_ipc_dai_ssp_params, quirks), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {SOF_TKN_INTEL_SSP_TDM_PADDING_PER_SLOT, SND_SOC_TPLG_TUPLE_TYPE_BOOL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) offsetof(struct sof_ipc_dai_ssp_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) tdm_per_slot_padding_flag), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {SOF_TKN_INTEL_SSP_BCLK_DELAY, SND_SOC_TPLG_TUPLE_TYPE_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) offsetof(struct sof_ipc_dai_ssp_params, bclk_delay), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /* ALH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static const struct sof_topology_token alh_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {SOF_TKN_INTEL_ALH_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) offsetof(struct sof_ipc_dai_alh_params, rate), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {SOF_TKN_INTEL_ALH_CH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) offsetof(struct sof_ipc_dai_alh_params, channels), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /* DMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) static const struct sof_topology_token dmic_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {SOF_TKN_INTEL_DMIC_DRIVER_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) offsetof(struct sof_ipc_dai_dmic_params, driver_ipc_version),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {SOF_TKN_INTEL_DMIC_CLK_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) offsetof(struct sof_ipc_dai_dmic_params, pdmclk_min), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {SOF_TKN_INTEL_DMIC_CLK_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) offsetof(struct sof_ipc_dai_dmic_params, pdmclk_max), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) {SOF_TKN_INTEL_DMIC_SAMPLE_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) offsetof(struct sof_ipc_dai_dmic_params, fifo_fs), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) {SOF_TKN_INTEL_DMIC_DUTY_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) offsetof(struct sof_ipc_dai_dmic_params, duty_min), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {SOF_TKN_INTEL_DMIC_DUTY_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) offsetof(struct sof_ipc_dai_dmic_params, duty_max), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) {SOF_TKN_INTEL_DMIC_NUM_PDM_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) offsetof(struct sof_ipc_dai_dmic_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) num_pdm_active), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {SOF_TKN_INTEL_DMIC_FIFO_WORD_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) offsetof(struct sof_ipc_dai_dmic_params, fifo_bits), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {SOF_TKN_INTEL_DMIC_UNMUTE_RAMP_TIME_MS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) offsetof(struct sof_ipc_dai_dmic_params, unmute_ramp_time), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) /* ESAI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static const struct sof_topology_token esai_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {SOF_TKN_IMX_ESAI_MCLK_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) offsetof(struct sof_ipc_dai_esai_params, mclk_id), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /* SAI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) static const struct sof_topology_token sai_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) {SOF_TKN_IMX_SAI_MCLK_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) offsetof(struct sof_ipc_dai_sai_params, mclk_id), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) /* Core tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) static const struct sof_topology_token core_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {SOF_TKN_COMP_CORE_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) offsetof(struct sof_ipc_comp, core), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) /* Component extended tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static const struct sof_topology_token comp_ext_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) {SOF_TKN_COMP_UUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) SND_SOC_TPLG_TUPLE_TYPE_UUID, get_token_uuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) offsetof(struct sof_ipc_comp_ext, uuid), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * DMIC PDM Tokens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * SOF_TKN_INTEL_DMIC_PDM_CTRL_ID should be the first token
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) * as it increments the index while parsing the array of pdm tokens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * and determines the correct offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) static const struct sof_topology_token dmic_pdm_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) {SOF_TKN_INTEL_DMIC_PDM_CTRL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) {SOF_TKN_INTEL_DMIC_PDM_MIC_A_Enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, enable_mic_a),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) {SOF_TKN_INTEL_DMIC_PDM_MIC_B_Enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, enable_mic_b),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {SOF_TKN_INTEL_DMIC_PDM_POLARITY_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, polarity_mic_a),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {SOF_TKN_INTEL_DMIC_PDM_POLARITY_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, polarity_mic_b),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) {SOF_TKN_INTEL_DMIC_PDM_CLK_EDGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, clk_edge),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {SOF_TKN_INTEL_DMIC_PDM_SKEW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, skew),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) /* HDA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static const struct sof_topology_token hda_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {SOF_TKN_INTEL_HDA_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) offsetof(struct sof_ipc_dai_hda_params, rate), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) {SOF_TKN_INTEL_HDA_CH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) offsetof(struct sof_ipc_dai_hda_params, channels), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) /* Leds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) static const struct sof_topology_token led_tokens[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) {SOF_TKN_MUTE_LED_USE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) offsetof(struct snd_sof_led_control, use_led), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) {SOF_TKN_MUTE_LED_DIRECTION, SND_SOC_TPLG_TUPLE_TYPE_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) get_token_u32, offsetof(struct snd_sof_led_control, direction), 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) static int sof_parse_uuid_tokens(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) void *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) const struct sof_topology_token *tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) struct snd_soc_tplg_vendor_array *array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) size_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct snd_soc_tplg_vendor_uuid_elem *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) /* parse element by element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) for (i = 0; i < le32_to_cpu(array->num_elems); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) elem = &array->uuid[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) /* search for token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) for (j = 0; j < count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* match token type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (tokens[j].type != SND_SOC_TPLG_TUPLE_TYPE_UUID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) /* match token id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (tokens[j].token != le32_to_cpu(elem->token))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) /* matched - now load token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) tokens[j].get_token(elem, object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) offset + tokens[j].offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) tokens[j].size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) static int sof_parse_string_tokens(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) void *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) const struct sof_topology_token *tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct snd_soc_tplg_vendor_array *array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) size_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) struct snd_soc_tplg_vendor_string_elem *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /* parse element by element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) for (i = 0; i < le32_to_cpu(array->num_elems); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) elem = &array->string[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /* search for token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) for (j = 0; j < count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) /* match token type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if (tokens[j].type != SND_SOC_TPLG_TUPLE_TYPE_STRING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) /* match token id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (tokens[j].token != le32_to_cpu(elem->token))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) /* matched - now load token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) tokens[j].get_token(elem, object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) offset + tokens[j].offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) tokens[j].size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) static int sof_parse_word_tokens(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) void *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) const struct sof_topology_token *tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) struct snd_soc_tplg_vendor_array *array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) size_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) struct snd_soc_tplg_vendor_value_elem *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) /* parse element by element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) for (i = 0; i < le32_to_cpu(array->num_elems); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) elem = &array->value[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* search for token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) for (j = 0; j < count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) /* match token type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (!(tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_WORD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_SHORT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_BYTE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) tokens[j].type == SND_SOC_TPLG_TUPLE_TYPE_BOOL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) /* match token id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (tokens[j].token != le32_to_cpu(elem->token))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) /* load token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) tokens[j].get_token(elem, object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) offset + tokens[j].offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) tokens[j].size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) * sof_parse_token_sets - Parse multiple sets of tokens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) * @scomp: pointer to soc component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) * @object: target ipc struct for parsed values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) * @tokens: token definition array describing what tokens to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) * @count: number of tokens in definition array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) * @array: source pointer to consecutive vendor arrays to be parsed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) * @priv_size: total size of the consecutive source arrays
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) * @sets: number of similar token sets to be parsed, 1 set has count elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) * @object_size: offset to next target ipc struct with multiple sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) * This function parses multiple sets of tokens in vendor arrays into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * consecutive ipc structs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) static int sof_parse_token_sets(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) void *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) const struct sof_topology_token *tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) struct snd_soc_tplg_vendor_array *array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) int priv_size, int sets, size_t object_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) size_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) int total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) int asize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) while (priv_size > 0 && total < count * sets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) asize = le32_to_cpu(array->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) /* validate asize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (asize < 0) { /* FIXME: A zero-size array makes no sense */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) dev_err(scomp->dev, "error: invalid array size 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) asize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) /* make sure there is enough data before parsing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) priv_size -= asize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) if (priv_size < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) dev_err(scomp->dev, "error: invalid array size 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) asize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) /* call correct parser depending on type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) switch (le32_to_cpu(array->type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) case SND_SOC_TPLG_TUPLE_TYPE_UUID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) found += sof_parse_uuid_tokens(scomp, object, tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) count, array, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) case SND_SOC_TPLG_TUPLE_TYPE_STRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) found += sof_parse_string_tokens(scomp, object, tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) count, array, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) case SND_SOC_TPLG_TUPLE_TYPE_BOOL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) case SND_SOC_TPLG_TUPLE_TYPE_BYTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) case SND_SOC_TPLG_TUPLE_TYPE_WORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) case SND_SOC_TPLG_TUPLE_TYPE_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) found += sof_parse_word_tokens(scomp, object, tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) count, array, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) dev_err(scomp->dev, "error: unknown token type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) array->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) /* next array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) array = (struct snd_soc_tplg_vendor_array *)((u8 *)array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) + asize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) /* move to next target struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if (found >= count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) offset += object_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) total += found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) static int sof_parse_tokens(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) void *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) const struct sof_topology_token *tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) struct snd_soc_tplg_vendor_array *array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) int priv_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * sof_parse_tokens is used when topology contains only a single set of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) * identical tuples arrays. So additional parameters to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) * sof_parse_token_sets are sets = 1 (only 1 set) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) * object_size = 0 (irrelevant).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) return sof_parse_token_sets(scomp, object, tokens, count, array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) priv_size, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static void sof_dbg_comp_config(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) struct sof_ipc_comp_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) dev_dbg(scomp->dev, " config: periods snk %d src %d fmt %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) config->periods_sink, config->periods_source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) config->frame_fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * Standard Kcontrols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) static int sof_control_load_volume(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) struct snd_sof_control *scontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) struct snd_kcontrol_new *kc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) struct snd_soc_tplg_ctl_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) struct snd_soc_tplg_mixer_control *mc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) container_of(hdr, struct snd_soc_tplg_mixer_control, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) struct sof_ipc_ctrl_data *cdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) int tlv[TLV_ITEMS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /* validate topology data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (le32_to_cpu(mc->num_channels) > SND_SOC_TPLG_MAX_CHAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) /* init the volume get/put data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) scontrol->size = struct_size(scontrol->control_data, chanv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) le32_to_cpu(mc->num_channels));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) scontrol->control_data = kzalloc(scontrol->size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (!scontrol->control_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) scontrol->comp_id = sdev->next_comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) scontrol->min_volume_step = le32_to_cpu(mc->min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) scontrol->max_volume_step = le32_to_cpu(mc->max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) scontrol->num_channels = le32_to_cpu(mc->num_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) /* set cmd for mixer control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (le32_to_cpu(mc->max) == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) scontrol->cmd = SOF_CTRL_CMD_SWITCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) scontrol->cmd = SOF_CTRL_CMD_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) /* extract tlv data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (get_tlv_data(kc->tlv.p, tlv) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) dev_err(scomp->dev, "error: invalid TLV data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) /* set up volume table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) ret = set_up_volume_table(scontrol, tlv, le32_to_cpu(mc->max) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) dev_err(scomp->dev, "error: setting up volume table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) /* set default volume values to 0dB in control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) cdata = scontrol->control_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) for (i = 0; i < scontrol->num_channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) cdata->chanv[i].channel = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) cdata->chanv[i].value = VOL_ZERO_DB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) /* set up possible led control from mixer private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) ret = sof_parse_tokens(scomp, &scontrol->led_ctl, led_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) ARRAY_SIZE(led_tokens), mc->priv.array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) le32_to_cpu(mc->priv.size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) dev_err(scomp->dev, "error: parse led tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) le32_to_cpu(mc->priv.size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) goto out_free_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) dev_dbg(scomp->dev, "tplg: load kcontrol index %d chans %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) scontrol->comp_id, scontrol->num_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) out_free_table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (le32_to_cpu(mc->max) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) kfree(scontrol->volume_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) kfree(scontrol->control_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) static int sof_control_load_enum(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) struct snd_sof_control *scontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) struct snd_kcontrol_new *kc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) struct snd_soc_tplg_ctl_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) struct snd_soc_tplg_enum_control *ec =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) container_of(hdr, struct snd_soc_tplg_enum_control, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) /* validate topology data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) if (le32_to_cpu(ec->num_channels) > SND_SOC_TPLG_MAX_CHAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) /* init the enum get/put data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) scontrol->size = struct_size(scontrol->control_data, chanv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) le32_to_cpu(ec->num_channels));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) scontrol->control_data = kzalloc(scontrol->size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) if (!scontrol->control_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) scontrol->comp_id = sdev->next_comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) scontrol->num_channels = le32_to_cpu(ec->num_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) scontrol->cmd = SOF_CTRL_CMD_ENUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) dev_dbg(scomp->dev, "tplg: load kcontrol index %d chans %d comp_id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) scontrol->comp_id, scontrol->num_channels, scontrol->comp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) static int sof_control_load_bytes(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) struct snd_sof_control *scontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) struct snd_kcontrol_new *kc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) struct snd_soc_tplg_ctl_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) struct sof_ipc_ctrl_data *cdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) struct snd_soc_tplg_bytes_control *control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) container_of(hdr, struct snd_soc_tplg_bytes_control, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) struct soc_bytes_ext *sbe = (struct soc_bytes_ext *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) size_t max_size = sbe->max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) size_t priv_size = le32_to_cpu(control->priv.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (max_size < sizeof(struct sof_ipc_ctrl_data) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) max_size < sizeof(struct sof_abi_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) /* init the get/put bytes data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (priv_size > max_size - sizeof(struct sof_ipc_ctrl_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) dev_err(scomp->dev, "err: bytes data size %zu exceeds max %zu.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) priv_size, max_size - sizeof(struct sof_ipc_ctrl_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) scontrol->size = sizeof(struct sof_ipc_ctrl_data) + priv_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) scontrol->control_data = kzalloc(max_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) cdata = scontrol->control_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (!scontrol->control_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) scontrol->comp_id = sdev->next_comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) scontrol->cmd = SOF_CTRL_CMD_BINARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) dev_dbg(scomp->dev, "tplg: load kcontrol index %d chans %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) scontrol->comp_id, scontrol->num_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) if (le32_to_cpu(control->priv.size) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) memcpy(cdata->data, control->priv.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) le32_to_cpu(control->priv.size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) if (cdata->data->magic != SOF_ABI_MAGIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) dev_err(scomp->dev, "error: Wrong ABI magic 0x%08x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) cdata->data->magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) cdata->data->abi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) "error: Incompatible ABI version 0x%08x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) cdata->data->abi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (cdata->data->size + sizeof(const struct sof_abi_hdr) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) le32_to_cpu(control->priv.size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) "error: Conflict in bytes vs. priv size.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) kfree(scontrol->control_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) /* external kcontrol init - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) static int sof_control_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) struct snd_kcontrol_new *kc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) struct snd_soc_tplg_ctl_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) struct soc_mixer_control *sm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) struct soc_bytes_ext *sbe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) struct soc_enum *se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) struct snd_soc_dobj *dobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct snd_sof_control *scontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) dev_dbg(scomp->dev, "tplg: load control type %d name : %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) hdr->type, hdr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) scontrol = kzalloc(sizeof(*scontrol), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (!scontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) scontrol->scomp = scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) switch (le32_to_cpu(hdr->ops.info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) case SND_SOC_TPLG_CTL_VOLSW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) case SND_SOC_TPLG_CTL_VOLSW_SX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) sm = (struct soc_mixer_control *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) dobj = &sm->dobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) ret = sof_control_load_volume(scomp, scontrol, kc, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) case SND_SOC_TPLG_CTL_BYTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) sbe = (struct soc_bytes_ext *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) dobj = &sbe->dobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) ret = sof_control_load_bytes(scomp, scontrol, kc, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) case SND_SOC_TPLG_CTL_ENUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) case SND_SOC_TPLG_CTL_ENUM_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) se = (struct soc_enum *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) dobj = &se->dobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) ret = sof_control_load_enum(scomp, scontrol, kc, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) case SND_SOC_TPLG_CTL_RANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) case SND_SOC_TPLG_CTL_STROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) case SND_SOC_TPLG_DAPM_CTL_VOLSW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) case SND_SOC_TPLG_DAPM_CTL_PIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) dev_warn(scomp->dev, "control type not supported %d:%d:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) hdr->ops.get, hdr->ops.put, hdr->ops.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) kfree(scontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) kfree(scontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) scontrol->led_ctl.led_value = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) dobj->private = scontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) list_add(&scontrol->list, &sdev->kcontrol_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) static int sof_control_unload(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) struct snd_soc_dobj *dobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) struct sof_ipc_free fcomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct snd_sof_control *scontrol = dobj->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) dev_dbg(scomp->dev, "tplg: unload control name : %s\n", scomp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) fcomp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) fcomp.hdr.size = sizeof(fcomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) fcomp.id = scontrol->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) kfree(scontrol->control_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) list_del(&scontrol->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) kfree(scontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) /* send IPC to the DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return sof_ipc_tx_message(sdev->ipc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) fcomp.hdr.cmd, &fcomp, sizeof(fcomp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) * DAI Topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) /* Static DSP core power management so far, should be extended in the future */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) static int sof_core_enable(struct snd_sof_dev *sdev, int core)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) struct sof_ipc_pm_core_config pm_core_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) .hdr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) .cmd = SOF_IPC_GLB_PM_MSG | SOF_IPC_PM_CORE_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) .size = sizeof(pm_core_config),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) .enable_mask = sdev->enabled_cores_mask | BIT(core),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (sdev->enabled_cores_mask & BIT(core))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) /* power up the core if it is host managed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) ret = snd_sof_dsp_core_power_up(sdev, BIT(core));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) dev_err(sdev->dev, "error: %d powering up core %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) ret, core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) /* Now notify DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) ret = sof_ipc_tx_message(sdev->ipc, pm_core_config.hdr.cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) &pm_core_config, sizeof(pm_core_config),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) &pm_core_config, sizeof(pm_core_config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) dev_err(sdev->dev, "error: core %d enable ipc failure %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) core, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) /* update enabled cores mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) sdev->enabled_cores_mask |= BIT(core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) /* power down core if it is host managed and return the original error if this fails too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) if (snd_sof_dsp_core_power_down(sdev, BIT(core)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) dev_err(sdev->dev, "error: powering down core %d\n", core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) int sof_pipeline_core_enable(struct snd_sof_dev *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) const struct snd_sof_widget *swidget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) const struct sof_ipc_pipe_new *pipeline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) if (swidget->id == snd_soc_dapm_scheduler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) pipeline = swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) pipeline = snd_sof_pipeline_find(sdev, swidget->pipeline_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) if (!pipeline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) /* First enable the pipeline core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) ret = sof_core_enable(sdev, pipeline->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) return sof_core_enable(sdev, swidget->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) static int sof_connect_dai_widget(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) struct snd_sof_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) struct snd_soc_card *card = scomp->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) struct snd_soc_pcm_runtime *rtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) struct snd_soc_dai *cpu_dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) list_for_each_entry(rtd, &card->rtd_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) dev_vdbg(scomp->dev, "tplg: check widget: %s stream: %s dai stream: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) w->name, w->sname, rtd->dai_link->stream_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) if (!w->sname || !rtd->dai_link->stream_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /* does stream match DAI link ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (strcmp(w->sname, rtd->dai_link->stream_name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) switch (w->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) case snd_soc_dapm_dai_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) * Please create DAI widget in the right order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) * to ensure BE will connect to the right DAI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) * widget.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) if (!cpu_dai->capture_widget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) cpu_dai->capture_widget = w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (i == rtd->num_cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) dev_err(scomp->dev, "error: can't find BE for DAI %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) w->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) dai->name = rtd->dai_link->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) dev_dbg(scomp->dev, "tplg: connected widget %s -> DAI link %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) w->name, rtd->dai_link->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) case snd_soc_dapm_dai_in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) * Please create DAI widget in the right order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) * to ensure BE will connect to the right DAI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) * widget.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (!cpu_dai->playback_widget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) cpu_dai->playback_widget = w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) if (i == rtd->num_cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) dev_err(scomp->dev, "error: can't find BE for DAI %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) w->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) dai->name = rtd->dai_link->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) dev_dbg(scomp->dev, "tplg: connected widget %s -> DAI link %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) w->name, rtd->dai_link->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) /* check we have a connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) if (!dai->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) dev_err(scomp->dev, "error: can't connect DAI %s stream %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) w->name, w->sname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) * sof_comp_alloc - allocate and initialize buffer for a new component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * @swidget: pointer to struct snd_sof_widget containing extended data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * @ipc_size: IPC payload size that will be updated depending on valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) * extended data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) * @index: ID of the pipeline the component belongs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) * Return: The pointer to the new allocated component, NULL if failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) static struct sof_ipc_comp *sof_comp_alloc(struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) size_t *ipc_size, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) u8 nil_uuid[SOF_UUID_SIZE] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) struct sof_ipc_comp *comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) size_t total_size = *ipc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) /* only non-zero UUID is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) if (memcmp(&swidget->comp_ext, nil_uuid, SOF_UUID_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) total_size += sizeof(swidget->comp_ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) comp = kzalloc(total_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) if (!comp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) /* configure comp new IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) comp->hdr.size = total_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) comp->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) comp->id = swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) comp->pipeline_id = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) comp->core = swidget->core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) /* handle the extended data if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) if (total_size > *ipc_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) /* append extended data to the end of the component */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) memcpy((u8 *)comp + *ipc_size, &swidget->comp_ext, sizeof(swidget->comp_ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) comp->ext_data_length = sizeof(swidget->comp_ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) /* update ipc_size and return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) *ipc_size = total_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) return comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) static int sof_widget_load_dai(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) struct sof_ipc_comp_reply *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) struct snd_sof_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) struct sof_ipc_comp_dai *comp_dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) size_t ipc_size = sizeof(*comp_dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) comp_dai = (struct sof_ipc_comp_dai *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) if (!comp_dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) /* configure dai IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) comp_dai->comp.type = SOF_COMP_DAI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) comp_dai->config.hdr.size = sizeof(comp_dai->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) ret = sof_parse_tokens(scomp, comp_dai, dai_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) ARRAY_SIZE(dai_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) dev_err(scomp->dev, "error: parse dai tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) goto finish;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) ret = sof_parse_tokens(scomp, &comp_dai->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) dev_err(scomp->dev, "error: parse dai.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) goto finish;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) dev_dbg(scomp->dev, "dai %s: type %d index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) swidget->widget->name, comp_dai->type, comp_dai->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) sof_dbg_comp_config(scomp, &comp_dai->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) ret = sof_ipc_tx_message(sdev->ipc, comp_dai->comp.hdr.cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) comp_dai, ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) if (ret == 0 && dai) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) dai->scomp = scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) * copy only the sof_ipc_comp_dai to avoid collapsing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) * the snd_sof_dai, the extended data is kept in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) * snd_sof_widget.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) memcpy(&dai->comp_dai, comp_dai, sizeof(*comp_dai));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) finish:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) kfree(comp_dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) * Buffer topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) static int sof_widget_load_buffer(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) struct sof_ipc_buffer *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) /* configure dai IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) buffer->comp.hdr.size = sizeof(*buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) buffer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_BUFFER_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) buffer->comp.id = swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) buffer->comp.type = SOF_COMP_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) buffer->comp.pipeline_id = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) buffer->comp.core = swidget->core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) ret = sof_parse_tokens(scomp, buffer, buffer_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) ARRAY_SIZE(buffer_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) dev_err(scomp->dev, "error: parse buffer tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) dev_dbg(scomp->dev, "buffer %s: size %d caps 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) swidget->widget->name, buffer->size, buffer->caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) swidget->private = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) ret = sof_ipc_tx_message(sdev->ipc, buffer->comp.hdr.cmd, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) sizeof(*buffer), r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) dev_err(scomp->dev, "error: buffer %s load failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) /* bind PCM ID to host component ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) static int spcm_bind(struct snd_soc_component *scomp, struct snd_sof_pcm *spcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) struct snd_sof_widget *host_widget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) host_widget = snd_sof_find_swidget_sname(scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) spcm->pcm.caps[dir].name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (!host_widget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) dev_err(scomp->dev, "can't find host comp to bind pcm\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) spcm->stream[dir].comp_id = host_widget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) * PCM Topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) static int sof_widget_load_pcm(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) enum sof_ipc_stream_direction dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) struct sof_ipc_comp_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) size_t ipc_size = sizeof(*host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) host = (struct sof_ipc_comp_host *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) /* configure host comp IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) host->comp.type = SOF_COMP_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) host->direction = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) host->config.hdr.size = sizeof(host->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) ret = sof_parse_tokens(scomp, host, pcm_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) ARRAY_SIZE(pcm_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) dev_err(scomp->dev, "error: parse host tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) ret = sof_parse_tokens(scomp, &host->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) dev_err(scomp->dev, "error: parse host.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) dev_dbg(scomp->dev, "loaded host %s\n", swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) sof_dbg_comp_config(scomp, &host->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) swidget->private = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) ret = sof_ipc_tx_message(sdev->ipc, host->comp.hdr.cmd, host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) kfree(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) * Pipeline Topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) int sof_load_pipeline_ipc(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) struct sof_ipc_pipe_new *pipeline,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) struct snd_sof_dev *sdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) int ret = sof_core_enable(sdev, pipeline->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) ret = sof_ipc_tx_message(sdev->ipc, pipeline->hdr.cmd, pipeline,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) sizeof(*pipeline), r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) dev_err(dev, "error: load pipeline ipc failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) static int sof_widget_load_pipeline(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct sof_ipc_pipe_new *pipeline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) struct snd_sof_widget *comp_swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) pipeline = kzalloc(sizeof(*pipeline), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) if (!pipeline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) /* configure dai IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) pipeline->hdr.size = sizeof(*pipeline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) pipeline->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) pipeline->pipeline_id = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) pipeline->comp_id = swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) /* component at start of pipeline is our stream id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) comp_swidget = snd_sof_find_swidget(scomp, tw->sname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) if (!comp_swidget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) dev_err(scomp->dev, "error: widget %s refers to non existent widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) tw->name, tw->sname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) pipeline->sched_id = comp_swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) dev_dbg(scomp->dev, "tplg: pipeline id %d comp %d scheduling comp id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) pipeline->pipeline_id, pipeline->comp_id, pipeline->sched_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) ret = sof_parse_tokens(scomp, pipeline, sched_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) ARRAY_SIZE(sched_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) dev_err(scomp->dev, "error: parse pipeline tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) dev_dbg(scomp->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) swidget->widget->name, pipeline->period, pipeline->priority,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) pipeline->period_mips, pipeline->core, pipeline->frames_per_sched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) swidget->private = pipeline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) /* send ipc's to create pipeline comp and power up schedule core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) ret = sof_load_pipeline_ipc(scomp->dev, pipeline, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) kfree(pipeline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) * Mixer topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) static int sof_widget_load_mixer(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) struct sof_ipc_comp_mixer *mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) size_t ipc_size = sizeof(*mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) mixer = (struct sof_ipc_comp_mixer *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) if (!mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) /* configure mixer IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) mixer->comp.type = SOF_COMP_MIXER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) mixer->config.hdr.size = sizeof(mixer->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) ret = sof_parse_tokens(scomp, &mixer->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) dev_err(scomp->dev, "error: parse mixer.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) kfree(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) sof_dbg_comp_config(scomp, &mixer->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) swidget->private = mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) ret = sof_ipc_tx_message(sdev->ipc, mixer->comp.hdr.cmd, mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) kfree(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) * Mux topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) static int sof_widget_load_mux(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) struct sof_ipc_comp_mux *mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) size_t ipc_size = sizeof(*mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) mux = (struct sof_ipc_comp_mux *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) if (!mux)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) /* configure mux IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) mux->comp.type = SOF_COMP_MUX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) mux->config.hdr.size = sizeof(mux->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) ret = sof_parse_tokens(scomp, &mux->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) dev_err(scomp->dev, "error: parse mux.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) kfree(mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) sof_dbg_comp_config(scomp, &mux->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) swidget->private = mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) ret = sof_ipc_tx_message(sdev->ipc, mux->comp.hdr.cmd, mux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) kfree(mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) * PGA Topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) static int sof_widget_load_pga(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) struct sof_ipc_comp_volume *volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) struct snd_sof_control *scontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) size_t ipc_size = sizeof(*volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) int min_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) int max_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) volume = (struct sof_ipc_comp_volume *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) if (!volume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) if (!le32_to_cpu(tw->num_kcontrols)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) dev_err(scomp->dev, "error: invalid kcontrol count %d for volume\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) tw->num_kcontrols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) /* configure volume IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) volume->comp.type = SOF_COMP_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) volume->config.hdr.size = sizeof(volume->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) ret = sof_parse_tokens(scomp, volume, volume_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) ARRAY_SIZE(volume_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) dev_err(scomp->dev, "error: parse volume tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) ret = sof_parse_tokens(scomp, &volume->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) dev_err(scomp->dev, "error: parse volume.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) sof_dbg_comp_config(scomp, &volume->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) swidget->private = volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) if (scontrol->comp_id == swidget->comp_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) scontrol->volume_table) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) min_step = scontrol->min_volume_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) max_step = scontrol->max_volume_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) volume->min_value = scontrol->volume_table[min_step];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) volume->max_value = scontrol->volume_table[max_step];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) volume->channels = scontrol->num_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) ret = sof_ipc_tx_message(sdev->ipc, volume->comp.hdr.cmd, volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) kfree(volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) * SRC Topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) static int sof_widget_load_src(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) struct sof_ipc_comp_src *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) size_t ipc_size = sizeof(*src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) src = (struct sof_ipc_comp_src *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) if (!src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) /* configure src IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) src->comp.type = SOF_COMP_SRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) src->config.hdr.size = sizeof(src->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) ret = sof_parse_tokens(scomp, src, src_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) ARRAY_SIZE(src_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) dev_err(scomp->dev, "error: parse src tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) ret = sof_parse_tokens(scomp, &src->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) dev_err(scomp->dev, "error: parse src.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) dev_dbg(scomp->dev, "src %s: source rate %d sink rate %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) swidget->widget->name, src->source_rate, src->sink_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) sof_dbg_comp_config(scomp, &src->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) swidget->private = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) ret = sof_ipc_tx_message(sdev->ipc, src->comp.hdr.cmd, src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) kfree(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) * ASRC Topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) static int sof_widget_load_asrc(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) struct sof_ipc_comp_asrc *asrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) size_t ipc_size = sizeof(*asrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) asrc = (struct sof_ipc_comp_asrc *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) if (!asrc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) /* configure ASRC IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) asrc->comp.type = SOF_COMP_ASRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) asrc->config.hdr.size = sizeof(asrc->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) ret = sof_parse_tokens(scomp, asrc, asrc_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) ARRAY_SIZE(asrc_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) dev_err(scomp->dev, "error: parse asrc tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) private->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) ret = sof_parse_tokens(scomp, &asrc->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) dev_err(scomp->dev, "error: parse asrc.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) dev_dbg(scomp->dev, "asrc %s: source rate %d sink rate %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) "asynch %d operation %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) swidget->widget->name, asrc->source_rate, asrc->sink_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) asrc->asynchronous_mode, asrc->operation_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) sof_dbg_comp_config(scomp, &asrc->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) swidget->private = asrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) ret = sof_ipc_tx_message(sdev->ipc, asrc->comp.hdr.cmd, asrc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) kfree(asrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) * Signal Generator Topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) static int sof_widget_load_siggen(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) struct sof_ipc_comp_tone *tone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) size_t ipc_size = sizeof(*tone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) tone = (struct sof_ipc_comp_tone *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) if (!tone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) /* configure siggen IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) tone->comp.type = SOF_COMP_TONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) tone->config.hdr.size = sizeof(tone->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) ret = sof_parse_tokens(scomp, tone, tone_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) ARRAY_SIZE(tone_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) dev_err(scomp->dev, "error: parse tone tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) ret = sof_parse_tokens(scomp, &tone->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) dev_err(scomp->dev, "error: parse tone.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) dev_dbg(scomp->dev, "tone %s: frequency %d amplitude %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) swidget->widget->name, tone->frequency, tone->amplitude);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) sof_dbg_comp_config(scomp, &tone->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) swidget->private = tone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) ret = sof_ipc_tx_message(sdev->ipc, tone->comp.hdr.cmd, tone,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) kfree(tone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) static int sof_get_control_data(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) struct snd_soc_dapm_widget *widget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) struct sof_widget_data *wdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) size_t *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) const struct snd_kcontrol_new *kc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) struct soc_mixer_control *sm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) struct soc_bytes_ext *sbe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) struct soc_enum *se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) *size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) for (i = 0; i < widget->num_kcontrols; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) kc = &widget->kcontrol_news[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) switch (widget->dobj.widget.kcontrol_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) case SND_SOC_TPLG_TYPE_MIXER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) sm = (struct soc_mixer_control *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) wdata[i].control = sm->dobj.private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) case SND_SOC_TPLG_TYPE_BYTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) sbe = (struct soc_bytes_ext *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) wdata[i].control = sbe->dobj.private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) case SND_SOC_TPLG_TYPE_ENUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) se = (struct soc_enum *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) wdata[i].control = se->dobj.private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) dev_err(scomp->dev, "error: unknown kcontrol type %d in widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) widget->dobj.widget.kcontrol_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) if (!wdata[i].control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) dev_err(scomp->dev, "error: no scontrol for widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) wdata[i].pdata = wdata[i].control->control_data->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) if (!wdata[i].pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) /* make sure data is valid - data can be updated at runtime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) if (wdata[i].pdata->magic != SOF_ABI_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) *size += wdata[i].pdata->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) /* get data type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) switch (wdata[i].control->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) case SOF_CTRL_CMD_VOLUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) case SOF_CTRL_CMD_ENUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) case SOF_CTRL_CMD_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) wdata[i].ipc_cmd = SOF_IPC_COMP_SET_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) wdata[i].ctrl_type = SOF_CTRL_TYPE_VALUE_CHAN_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) case SOF_CTRL_CMD_BINARY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) wdata[i].ipc_cmd = SOF_IPC_COMP_SET_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) wdata[i].ctrl_type = SOF_CTRL_TYPE_DATA_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) static int sof_process_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) struct sof_ipc_comp_reply *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) struct snd_soc_dapm_widget *widget = swidget->widget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) struct sof_ipc_comp_process *process;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) struct sof_widget_data *wdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) size_t ipc_data_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) size_t ipc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) int offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) /* allocate struct for widget control data sizes and types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) if (widget->num_kcontrols) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) wdata = kcalloc(widget->num_kcontrols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) sizeof(*wdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) if (!wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) /* get possible component controls and get size of all pdata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) ret = sof_get_control_data(scomp, widget, wdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) &ipc_data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) ipc_size = sizeof(struct sof_ipc_comp_process) + ipc_data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) /* we are exceeding max ipc size, config needs to be sent separately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) if (ipc_size > SOF_IPC_MSG_MAX_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) ipc_size -= ipc_data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) ipc_data_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) process = (struct sof_ipc_comp_process *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) sof_comp_alloc(swidget, &ipc_size, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) if (!process) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) /* configure iir IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) process->comp.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) process->config.hdr.size = sizeof(process->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) ret = sof_parse_tokens(scomp, &process->config, comp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) ARRAY_SIZE(comp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) dev_err(scomp->dev, "error: parse process.cfg tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) sof_dbg_comp_config(scomp, &process->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) * found private data in control, so copy it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) * get possible component controls - get size of all pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) * then memcpy with headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) if (ipc_data_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) for (i = 0; i < widget->num_kcontrols; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) memcpy(&process->data + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) wdata[i].pdata->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) wdata[i].pdata->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) offset += wdata[i].pdata->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) process->size = ipc_data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) swidget->private = process;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) ret = sof_ipc_tx_message(sdev->ipc, process->comp.hdr.cmd, process,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) ipc_size, r, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) dev_err(scomp->dev, "error: create process failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) /* we sent the data in single message so return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) if (ipc_data_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) /* send control data with large message supported method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) for (i = 0; i < widget->num_kcontrols; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) wdata[i].control->readback_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) ret = snd_sof_ipc_set_get_comp_data(wdata[i].control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) wdata[i].ipc_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) wdata[i].ctrl_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) wdata[i].control->cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) dev_err(scomp->dev, "error: send control failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) kfree(process);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) kfree(wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) * Processing Component Topology - can be "effect", "codec", or general
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) * "processing".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) static int sof_widget_load_process(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) struct snd_soc_tplg_dapm_widget *tw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) struct sof_ipc_comp_reply *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) struct snd_soc_tplg_private *private = &tw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) struct sof_ipc_comp_process config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) /* check we have some tokens - we need at least process type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) if (le32_to_cpu(private->size) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) dev_err(scomp->dev, "error: process tokens not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) memset(&config, 0, sizeof(config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) config.comp.core = swidget->core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) /* get the process token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) ret = sof_parse_tokens(scomp, &config, process_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) ARRAY_SIZE(process_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) dev_err(scomp->dev, "error: parse process tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) /* now load process specific data and send IPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) ret = sof_process_load(scomp, index, swidget, tw, r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) find_process_comp_type(config.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) dev_err(scomp->dev, "error: process loading failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) static int sof_widget_bind_event(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) struct snd_sof_widget *swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) u16 event_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) struct sof_ipc_comp *ipc_comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) /* validate widget event type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) switch (event_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) case SOF_KEYWORD_DETECT_DAPM_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) /* only KEYWORD_DETECT comps should handle this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) if (swidget->id != snd_soc_dapm_effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) ipc_comp = swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) if (ipc_comp && ipc_comp->type != SOF_COMP_KEYWORD_DETECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) /* bind event to keyword detect comp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) return snd_soc_tplg_widget_bind_event(swidget->widget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) sof_kwd_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) ARRAY_SIZE(sof_kwd_events),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) "error: invalid event type %d for widget %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) event_type, swidget->widget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) /* external widget init - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) static int sof_widget_ready(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) struct snd_soc_tplg_dapm_widget *tw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) struct snd_sof_widget *swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) struct snd_sof_dai *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) struct sof_ipc_comp_reply reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) struct snd_sof_control *scontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) struct sof_ipc_comp comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) .core = SOF_DSP_PRIMARY_CORE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) swidget = kzalloc(sizeof(*swidget), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) if (!swidget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) swidget->scomp = scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) swidget->widget = w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) swidget->comp_id = sdev->next_comp_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) swidget->complete = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) swidget->id = w->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) swidget->pipeline_id = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) swidget->private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) memset(&reply, 0, sizeof(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) dev_dbg(scomp->dev, "tplg: ready widget id %d pipe %d type %d name : %s stream %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) swidget->comp_id, index, swidget->id, tw->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) ? tw->sname : "none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) ret = sof_parse_tokens(scomp, &comp, core_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) ARRAY_SIZE(core_tokens), tw->priv.array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) le32_to_cpu(tw->priv.size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) dev_err(scomp->dev, "error: parsing core tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) kfree(swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) swidget->core = comp.core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) /* default is primary core, safe to call for already enabled cores */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) ret = sof_core_enable(sdev, comp.core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) dev_err(scomp->dev, "error: enable core: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) kfree(swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) ret = sof_parse_tokens(scomp, &swidget->comp_ext, comp_ext_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) ARRAY_SIZE(comp_ext_tokens), tw->priv.array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) le32_to_cpu(tw->priv.size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) dev_err(scomp->dev, "error: parsing comp_ext_tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) kfree(swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) /* handle any special case widgets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) switch (w->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) case snd_soc_dapm_dai_in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) case snd_soc_dapm_dai_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) dai = kzalloc(sizeof(*dai), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) if (!dai) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) kfree(swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) ret = sof_widget_load_dai(scomp, index, swidget, tw, &reply, dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) sof_connect_dai_widget(scomp, w, tw, dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) list_add(&dai->list, &sdev->dai_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) swidget->private = dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) kfree(dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) case snd_soc_dapm_mixer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) ret = sof_widget_load_mixer(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) case snd_soc_dapm_pga:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) ret = sof_widget_load_pga(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) /* Find scontrol for this pga and set readback offset*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) if (scontrol->comp_id == swidget->comp_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) scontrol->readback_offset = reply.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) case snd_soc_dapm_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) ret = sof_widget_load_buffer(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) case snd_soc_dapm_scheduler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) ret = sof_widget_load_pipeline(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) case snd_soc_dapm_aif_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) ret = sof_widget_load_pcm(scomp, index, swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) SOF_IPC_STREAM_CAPTURE, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) case snd_soc_dapm_aif_in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) ret = sof_widget_load_pcm(scomp, index, swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) SOF_IPC_STREAM_PLAYBACK, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) case snd_soc_dapm_src:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) ret = sof_widget_load_src(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) case snd_soc_dapm_asrc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) ret = sof_widget_load_asrc(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) case snd_soc_dapm_siggen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) ret = sof_widget_load_siggen(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) case snd_soc_dapm_effect:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) ret = sof_widget_load_process(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) case snd_soc_dapm_mux:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) case snd_soc_dapm_demux:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) ret = sof_widget_load_mux(scomp, index, swidget, tw, &reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) case snd_soc_dapm_switch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) case snd_soc_dapm_dai_link:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) case snd_soc_dapm_kcontrol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) dev_dbg(scomp->dev, "widget type %d name %s not handled\n", swidget->id, tw->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) /* check IPC reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) if (ret < 0 || reply.rhdr.error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) "error: DSP failed to add widget id %d type %d name : %s stream %s reply %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) tw->shift, swidget->id, tw->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) ? tw->sname : "none", reply.rhdr.error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) kfree(swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) /* bind widget to external event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) if (tw->event_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) ret = sof_widget_bind_event(scomp, swidget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) le16_to_cpu(tw->event_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) dev_err(scomp->dev, "error: widget event binding failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) kfree(swidget->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) kfree(swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) w->dobj.private = swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) list_add(&swidget->list, &sdev->widget_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) static int sof_route_unload(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) struct snd_soc_dobj *dobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) struct snd_sof_route *sroute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) sroute = dobj->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) if (!sroute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) /* free sroute and its private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) kfree(sroute->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) list_del(&sroute->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) kfree(sroute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) static int sof_widget_unload(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) struct snd_soc_dobj *dobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) const struct snd_kcontrol_new *kc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) struct snd_soc_dapm_widget *widget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) struct sof_ipc_pipe_new *pipeline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) struct snd_sof_control *scontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) struct snd_sof_widget *swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) struct soc_mixer_control *sm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) struct soc_bytes_ext *sbe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) struct snd_sof_dai *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) struct soc_enum *se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) swidget = dobj->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) if (!swidget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) widget = swidget->widget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) switch (swidget->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) case snd_soc_dapm_dai_in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) case snd_soc_dapm_dai_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) dai = swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) if (dai) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) /* free dai config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) kfree(dai->dai_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) list_del(&dai->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) case snd_soc_dapm_scheduler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) /* power down the pipeline schedule core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) pipeline = swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) * Runtime PM should still function normally if topology loading fails and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) * it's components are unloaded. Do not power down the primary core so that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) * CTX_SAVE IPC can succeed during runtime suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) if (pipeline->core == SOF_DSP_PRIMARY_CORE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) ret = snd_sof_dsp_core_power_down(sdev, 1 << pipeline->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) dev_err(scomp->dev, "error: powering down pipeline schedule core %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) pipeline->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) /* update enabled cores mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) sdev->enabled_cores_mask &= ~(1 << pipeline->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) for (i = 0; i < widget->num_kcontrols; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) kc = &widget->kcontrol_news[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) switch (dobj->widget.kcontrol_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) case SND_SOC_TPLG_TYPE_MIXER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) sm = (struct soc_mixer_control *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) scontrol = sm->dobj.private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) if (sm->max > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) kfree(scontrol->volume_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) case SND_SOC_TPLG_TYPE_ENUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) se = (struct soc_enum *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) scontrol = se->dobj.private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) case SND_SOC_TPLG_TYPE_BYTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) sbe = (struct soc_bytes_ext *)kc->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) scontrol = sbe->dobj.private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) dev_warn(scomp->dev, "unsupported kcontrol_type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) kfree(scontrol->control_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) list_del(&scontrol->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) kfree(scontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) /* free private value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) kfree(swidget->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) /* remove and free swidget object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) list_del(&swidget->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) kfree(swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) * DAI HW configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) /* FE DAI - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) static int sof_dai_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) struct snd_soc_dai_driver *dai_drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) struct snd_soc_tplg_stream_caps *caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) struct snd_soc_tplg_private *private = &pcm->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) int stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) /* nothing to do for BEs atm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) if (!pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) spcm = kzalloc(sizeof(*spcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) if (!spcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) spcm->scomp = scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) for_each_pcm_streams(stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) spcm->stream[stream].comp_id = COMP_ID_UNASSIGNED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) INIT_WORK(&spcm->stream[stream].period_elapsed_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) snd_sof_pcm_period_elapsed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) spcm->pcm = *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) dev_dbg(scomp->dev, "tplg: load pcm %s\n", pcm->dai_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) dai_drv->dobj.private = spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) list_add(&spcm->list, &sdev->pcm_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) ret = sof_parse_tokens(scomp, spcm, stream_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) ARRAY_SIZE(stream_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) dev_err(scomp->dev, "error: parse stream tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) /* do we need to allocate playback PCM DMA pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) if (!spcm->pcm.playback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) goto capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) stream = SNDRV_PCM_STREAM_PLAYBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) dev_vdbg(scomp->dev, "tplg: pcm %s stream tokens: playback d0i3:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) spcm->pcm.pcm_name, spcm->stream[stream].d0i3_compatible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) caps = &spcm->pcm.caps[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) /* allocate playback page table buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, sdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) PAGE_SIZE, &spcm->stream[stream].page_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) dev_err(scomp->dev, "error: can't alloc page table for %s %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) caps->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) /* bind pcm to host comp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) ret = spcm_bind(scomp, spcm, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) "error: can't bind pcm to host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) goto free_playback_tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) capture:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) stream = SNDRV_PCM_STREAM_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) /* do we need to allocate capture PCM DMA pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) if (!spcm->pcm.capture)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) dev_vdbg(scomp->dev, "tplg: pcm %s stream tokens: capture d0i3:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) spcm->pcm.pcm_name, spcm->stream[stream].d0i3_compatible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) caps = &spcm->pcm.caps[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) /* allocate capture page table buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, sdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) PAGE_SIZE, &spcm->stream[stream].page_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) dev_err(scomp->dev, "error: can't alloc page table for %s %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) caps->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) goto free_playback_tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) /* bind pcm to host comp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) ret = spcm_bind(scomp, spcm, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) "error: can't bind pcm to host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) snd_dma_free_pages(&spcm->stream[stream].page_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) goto free_playback_tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) free_playback_tables:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) if (spcm->pcm.playback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].page_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) static int sof_dai_unload(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) struct snd_soc_dobj *dobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) struct snd_sof_pcm *spcm = dobj->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) /* free PCM DMA pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) if (spcm->pcm.playback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].page_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) if (spcm->pcm.capture)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_CAPTURE].page_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) /* remove from list and free spcm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) list_del(&spcm->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) kfree(spcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) static void sof_dai_set_format(struct snd_soc_tplg_hw_config *hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) /* clock directions wrt codec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) if (hw_config->bclk_master == SND_SOC_TPLG_BCLK_CM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) /* codec is bclk master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) if (hw_config->fsync_master == SND_SOC_TPLG_FSYNC_CM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) config->format |= SOF_DAI_FMT_CBM_CFM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) config->format |= SOF_DAI_FMT_CBM_CFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) /* codec is bclk slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) if (hw_config->fsync_master == SND_SOC_TPLG_FSYNC_CM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) config->format |= SOF_DAI_FMT_CBS_CFM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) config->format |= SOF_DAI_FMT_CBS_CFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) /* inverted clocks ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) if (hw_config->invert_bclk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) if (hw_config->invert_fsync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) config->format |= SOF_DAI_FMT_IB_IF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) config->format |= SOF_DAI_FMT_IB_NF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) if (hw_config->invert_fsync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) config->format |= SOF_DAI_FMT_NB_IF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) config->format |= SOF_DAI_FMT_NB_NF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) * Send IPC and set the same config for all DAIs with name matching the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) * name. Note that the function can only be used for the case that all DAIs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) * have a common DAI config for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) static int sof_set_dai_config(struct snd_sof_dev *sdev, u32 size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) struct snd_sof_dai *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) list_for_each_entry(dai, &sdev->dai_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) if (!dai->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) if (strcmp(link->name, dai->name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) struct sof_ipc_reply reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) * the same dai config will be applied to all DAIs in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) * the same dai link. We have to ensure that the ipc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) * dai config's dai_index match to the component's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) * dai_index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) config->dai_index = dai->comp_dai.dai_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) /* send message to DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) ret = sof_ipc_tx_message(sdev->ipc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) config->hdr.cmd, config, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) &reply, sizeof(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) dev_err(sdev->dev, "error: failed to set DAI config for %s index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) dai->name, config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) dai->dai_config = kmemdup(config, size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) if (!dai->dai_config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) /* set cpu_dai_name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) dai->cpu_dai_name = link->cpus->dai_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) * machine driver may define a dai link with playback and capture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) * dai enabled, but the dai link in topology would support both, one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) * or none of them. Here print a warning message to notify user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) dev_warn(sdev->dev, "warning: failed to find dai for dai link %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) link->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) static int sof_link_ssp_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) struct snd_soc_tplg_link_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) struct snd_soc_tplg_hw_config *hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) struct snd_soc_tplg_private *private = &cfg->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) u32 size = sizeof(*config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) /* handle master/slave and inverted clocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) sof_dai_set_format(hw_config, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) /* init IPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) memset(&config->ssp, 0, sizeof(struct sof_ipc_dai_ssp_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) config->hdr.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) ret = sof_parse_tokens(scomp, &config->ssp, ssp_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) ARRAY_SIZE(ssp_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) dev_err(scomp->dev, "error: parse ssp tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) config->ssp.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) config->ssp.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) config->ssp.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) config->ssp.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) config->ssp.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) config->ssp.mclk_direction = hw_config->mclk_direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) config->ssp.rx_slots = le32_to_cpu(hw_config->rx_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) config->ssp.tx_slots = le32_to_cpu(hw_config->tx_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) dev_dbg(scomp->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",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) config->dai_index, config->format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) config->ssp.mclk_rate, config->ssp.bclk_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) config->ssp.fsync_rate, config->ssp.sample_valid_bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) config->ssp.tdm_slot_width, config->ssp.tdm_slots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) config->ssp.mclk_id, config->ssp.quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) /* validate SSP fsync rate and channel count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) if (config->ssp.fsync_rate < 8000 || config->ssp.fsync_rate > 192000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) dev_err(scomp->dev, "error: invalid fsync rate for SSP%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) if (config->ssp.tdm_slots < 1 || config->ssp.tdm_slots > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) dev_err(scomp->dev, "error: invalid channel count for SSP%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) /* set config for all DAI's with name matching the link name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) ret = sof_set_dai_config(sdev, size, link, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) dev_err(scomp->dev, "error: failed to save DAI config for SSP%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) static int sof_link_sai_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) struct snd_soc_tplg_link_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) struct snd_soc_tplg_hw_config *hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) struct snd_soc_tplg_private *private = &cfg->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) u32 size = sizeof(*config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) /* handle master/slave and inverted clocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) sof_dai_set_format(hw_config, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) /* init IPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) memset(&config->sai, 0, sizeof(struct sof_ipc_dai_sai_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) config->hdr.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) ret = sof_parse_tokens(scomp, &config->sai, sai_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) ARRAY_SIZE(sai_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) dev_err(scomp->dev, "error: parse sai tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) config->sai.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) config->sai.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) config->sai.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) config->sai.mclk_direction = hw_config->mclk_direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) config->sai.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) config->sai.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) config->sai.rx_slots = le32_to_cpu(hw_config->rx_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) config->sai.tx_slots = le32_to_cpu(hw_config->tx_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) dev_info(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) "tplg: config SAI%d fmt 0x%x mclk %d width %d slots %d mclk id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) config->dai_index, config->format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) config->sai.mclk_rate, config->sai.tdm_slot_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) config->sai.tdm_slots, config->sai.mclk_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) if (config->sai.tdm_slots < 1 || config->sai.tdm_slots > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) dev_err(scomp->dev, "error: invalid channel count for SAI%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) /* set config for all DAI's with name matching the link name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) ret = sof_set_dai_config(sdev, size, link, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) dev_err(scomp->dev, "error: failed to save DAI config for SAI%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) static int sof_link_esai_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) struct snd_soc_tplg_link_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) struct snd_soc_tplg_hw_config *hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) struct snd_soc_tplg_private *private = &cfg->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) u32 size = sizeof(*config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) /* handle master/slave and inverted clocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) sof_dai_set_format(hw_config, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) /* init IPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) memset(&config->esai, 0, sizeof(struct sof_ipc_dai_esai_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) config->hdr.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) ret = sof_parse_tokens(scomp, &config->esai, esai_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) ARRAY_SIZE(esai_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) dev_err(scomp->dev, "error: parse esai tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) config->esai.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) config->esai.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) config->esai.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) config->esai.mclk_direction = hw_config->mclk_direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) config->esai.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) config->esai.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) config->esai.rx_slots = le32_to_cpu(hw_config->rx_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) config->esai.tx_slots = le32_to_cpu(hw_config->tx_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) dev_info(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) "tplg: config ESAI%d fmt 0x%x mclk %d width %d slots %d mclk id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) config->dai_index, config->format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) config->esai.mclk_rate, config->esai.tdm_slot_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) config->esai.tdm_slots, config->esai.mclk_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) if (config->esai.tdm_slots < 1 || config->esai.tdm_slots > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) dev_err(scomp->dev, "error: invalid channel count for ESAI%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) /* set config for all DAI's with name matching the link name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) ret = sof_set_dai_config(sdev, size, link, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) dev_err(scomp->dev, "error: failed to save DAI config for ESAI%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) static int sof_link_dmic_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) struct snd_soc_tplg_link_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) struct snd_soc_tplg_hw_config *hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) struct snd_soc_tplg_private *private = &cfg->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) struct sof_ipc_fw_version *v = &ready->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) size_t size = sizeof(*config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) int ret, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) /* Ensure the entire DMIC config struct is zeros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) memset(&config->dmic, 0, sizeof(struct sof_ipc_dai_dmic_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) /* get DMIC tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) ret = sof_parse_tokens(scomp, &config->dmic, dmic_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) ARRAY_SIZE(dmic_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) dev_err(scomp->dev, "error: parse dmic tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) /* get DMIC PDM tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) ret = sof_parse_token_sets(scomp, &config->dmic.pdm[0], dmic_pdm_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) ARRAY_SIZE(dmic_pdm_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) le32_to_cpu(private->size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) config->dmic.num_pdm_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) sizeof(struct sof_ipc_dai_dmic_pdm_ctrl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) dev_err(scomp->dev, "error: parse dmic pdm tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) /* set IPC header size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) config->hdr.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) /* debug messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) dev_dbg(scomp->dev, "tplg: config DMIC%d driver version %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) config->dai_index, config->dmic.driver_ipc_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) dev_dbg(scomp->dev, "pdmclk_min %d pdm_clkmax %d duty_min %hd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) config->dmic.pdmclk_min, config->dmic.pdmclk_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) config->dmic.duty_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) dev_dbg(scomp->dev, "duty_max %hd fifo_fs %d num_pdms active %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) config->dmic.duty_max, config->dmic.fifo_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) config->dmic.num_pdm_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) dev_dbg(scomp->dev, "fifo word length %hd\n", config->dmic.fifo_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) for (j = 0; j < config->dmic.num_pdm_active; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) dev_dbg(scomp->dev, "pdm %hd mic a %hd mic b %hd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) config->dmic.pdm[j].id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) config->dmic.pdm[j].enable_mic_a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) config->dmic.pdm[j].enable_mic_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) dev_dbg(scomp->dev, "pdm %hd polarity a %hd polarity b %hd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) config->dmic.pdm[j].id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) config->dmic.pdm[j].polarity_mic_a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) config->dmic.pdm[j].polarity_mic_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) dev_dbg(scomp->dev, "pdm %hd clk_edge %hd skew %hd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) config->dmic.pdm[j].id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) config->dmic.pdm[j].clk_edge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) config->dmic.pdm[j].skew);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) * this takes care of backwards compatible handling of fifo_bits_b.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) * It is deprecated since firmware ABI version 3.0.1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) if (SOF_ABI_VER(v->major, v->minor, v->micro) < SOF_ABI_VER(3, 0, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) config->dmic.fifo_bits_b = config->dmic.fifo_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) /* set config for all DAI's with name matching the link name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) ret = sof_set_dai_config(sdev, size, link, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) dev_err(scomp->dev, "error: failed to save DAI config for DMIC%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) static int sof_link_hda_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) struct snd_soc_tplg_link_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) struct snd_soc_tplg_hw_config *hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) struct snd_soc_tplg_private *private = &cfg->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) struct snd_soc_dai *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) u32 size = sizeof(*config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) /* init IPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) memset(&config->hda, 0, sizeof(struct sof_ipc_dai_hda_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) config->hdr.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) /* get any bespoke DAI tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) ret = sof_parse_tokens(scomp, &config->hda, hda_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) ARRAY_SIZE(hda_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) dev_err(scomp->dev, "error: parse hda tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) dev_dbg(scomp->dev, "HDA config rate %d channels %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) config->hda.rate, config->hda.channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) dai = snd_soc_find_dai(link->cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) if (!dai) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) dev_err(scomp->dev, "error: failed to find dai %s in %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) link->cpus->dai_name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) config->hda.link_dma_ch = DMA_CHAN_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) ret = sof_set_dai_config(sdev, size, link, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) dev_err(scomp->dev, "error: failed to process hda dai link %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) link->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) static int sof_link_alh_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) struct snd_soc_tplg_link_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) struct snd_soc_tplg_hw_config *hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) struct sof_ipc_dai_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) struct snd_soc_tplg_private *private = &cfg->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) u32 size = sizeof(*config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) ret = sof_parse_tokens(scomp, &config->alh, alh_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) ARRAY_SIZE(alh_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) dev_err(scomp->dev, "error: parse alh tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) /* init IPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) config->hdr.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) /* set config for all DAI's with name matching the link name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) ret = sof_set_dai_config(sdev, size, link, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) dev_err(scomp->dev, "error: failed to save DAI config for ALH %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) config->dai_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) /* DAI link - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) static int sof_link_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) struct snd_soc_tplg_link_config *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) struct snd_soc_tplg_private *private = &cfg->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) struct sof_ipc_dai_config config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) struct snd_soc_tplg_hw_config *hw_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) int num_hw_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) if (!link->platforms) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) dev_err(scomp->dev, "error: no platforms\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) link->platforms->name = dev_name(scomp->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) * Set nonatomic property for FE dai links as their trigger action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) * involves IPC's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) if (!link->no_pcm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) link->nonatomic = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) * set default trigger order for all links. Exceptions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) * the rule will be handled in sof_pcm_dai_link_fixup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) * For playback, the sequence is the following: start FE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) * start BE, stop BE, stop FE; for Capture the sequence is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) * inverted start BE, start FE, stop FE, stop BE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) link->trigger[SNDRV_PCM_STREAM_PLAYBACK] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) SND_SOC_DPCM_TRIGGER_PRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) link->trigger[SNDRV_PCM_STREAM_CAPTURE] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) SND_SOC_DPCM_TRIGGER_POST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) /* nothing more to do for FE dai links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) /* check we have some tokens - we need at least DAI type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) if (le32_to_cpu(private->size) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) dev_err(scomp->dev, "error: expected tokens for DAI, none found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) /* Send BE DAI link configurations to DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) memset(&config, 0, sizeof(config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) /* get any common DAI tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) ret = sof_parse_tokens(scomp, &config, dai_link_tokens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) ARRAY_SIZE(dai_link_tokens), private->array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) dev_err(scomp->dev, "error: parse link tokens failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) le32_to_cpu(private->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) * DAI links are expected to have at least 1 hw_config.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) * But some older topologies might have no hw_config for HDA dai links.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) num_hw_configs = le32_to_cpu(cfg->num_hw_configs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) if (!num_hw_configs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) if (config.type != SOF_DAI_INTEL_HDA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) dev_err(scomp->dev, "error: unexpected DAI config count %d!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) le32_to_cpu(cfg->num_hw_configs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) dev_dbg(scomp->dev, "tplg: %d hw_configs found, default id: %d!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) cfg->num_hw_configs, le32_to_cpu(cfg->default_hw_config_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) for (i = 0; i < num_hw_configs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) if (cfg->hw_config[i].id == cfg->default_hw_config_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) if (i == num_hw_configs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) dev_err(scomp->dev, "error: default hw_config id: %d not found!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) le32_to_cpu(cfg->default_hw_config_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) /* configure dai IPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) hw_config = &cfg->hw_config[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) config.hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) config.format = le32_to_cpu(hw_config->fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) /* now load DAI specific data and send IPC - type comes from token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) switch (config.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) case SOF_DAI_INTEL_SSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) ret = sof_link_ssp_load(scomp, index, link, cfg, hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) case SOF_DAI_INTEL_DMIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) ret = sof_link_dmic_load(scomp, index, link, cfg, hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) case SOF_DAI_INTEL_HDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) ret = sof_link_hda_load(scomp, index, link, cfg, hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) case SOF_DAI_INTEL_ALH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) ret = sof_link_alh_load(scomp, index, link, cfg, hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) case SOF_DAI_IMX_SAI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) ret = sof_link_sai_load(scomp, index, link, cfg, hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) case SOF_DAI_IMX_ESAI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) ret = sof_link_esai_load(scomp, index, link, cfg, hw_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) dev_err(scomp->dev, "error: invalid DAI type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) config.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) static int sof_link_hda_unload(struct snd_sof_dev *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) struct snd_soc_dai_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) struct snd_soc_dai *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) dai = snd_soc_find_dai(link->cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) if (!dai) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) dev_err(sdev->dev, "error: failed to find dai %s in %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) link->cpus->dai_name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) static int sof_link_unload(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) struct snd_soc_dobj *dobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) struct snd_soc_dai_link *link =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) container_of(dobj, struct snd_soc_dai_link, dobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) struct snd_sof_dai *sof_dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) /* only BE link is loaded by sof */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) if (!link->no_pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) list_for_each_entry(sof_dai, &sdev->dai_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) if (!sof_dai->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) if (strcmp(link->name, sof_dai->name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) dev_err(scomp->dev, "error: failed to find dai %s in %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) link->name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) switch (sof_dai->dai_config->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) case SOF_DAI_INTEL_SSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) case SOF_DAI_INTEL_DMIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) case SOF_DAI_INTEL_ALH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) case SOF_DAI_IMX_SAI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) case SOF_DAI_IMX_ESAI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) /* no resource needs to be released for all cases above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) case SOF_DAI_INTEL_HDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) ret = sof_link_hda_unload(sdev, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) dev_err(scomp->dev, "error: invalid DAI type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) sof_dai->dai_config->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) /* DAI link - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) static int sof_route_load(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) struct snd_soc_dapm_route *route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) struct sof_ipc_pipe_comp_connect *connect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) struct snd_sof_widget *source_swidget, *sink_swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) struct snd_soc_dobj *dobj = &route->dobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) struct snd_sof_route *sroute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) struct sof_ipc_reply reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) /* allocate memory for sroute and connect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) sroute = kzalloc(sizeof(*sroute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) if (!sroute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) sroute->scomp = scomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) connect = kzalloc(sizeof(*connect), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) if (!connect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) kfree(sroute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) connect->hdr.size = sizeof(*connect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) connect->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_CONNECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) dev_dbg(scomp->dev, "sink %s control %s source %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) route->sink, route->control ? route->control : "none",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) route->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) /* source component */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) source_swidget = snd_sof_find_swidget(scomp, (char *)route->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) if (!source_swidget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) dev_err(scomp->dev, "error: source %s not found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) route->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) * Virtual widgets of type output/out_drv may be added in topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) * for compatibility. These are not handled by the FW.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) * So, don't send routes whose source/sink widget is of such types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) * to the DSP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) if (source_swidget->id == snd_soc_dapm_out_drv ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) source_swidget->id == snd_soc_dapm_output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) connect->source_id = source_swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) /* sink component */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) sink_swidget = snd_sof_find_swidget(scomp, (char *)route->sink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) if (!sink_swidget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) dev_err(scomp->dev, "error: sink %s not found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) route->sink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) * Don't send routes whose sink widget is of type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) * output or out_drv to the DSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) if (sink_swidget->id == snd_soc_dapm_out_drv ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) sink_swidget->id == snd_soc_dapm_output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) connect->sink_id = sink_swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) * For virtual routes, both sink and source are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) * buffer. Since only buffer linked to component is supported by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) * FW, others are reported as error, add check in route function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) * do not send it to FW when both source and sink are not buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) if (source_swidget->id != snd_soc_dapm_buffer &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) sink_swidget->id != snd_soc_dapm_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) dev_dbg(scomp->dev, "warning: neither Linked source component %s nor sink component %s is of buffer type, ignoring link\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) route->source, route->sink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) ret = sof_ipc_tx_message(sdev->ipc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) connect->hdr.cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) connect, sizeof(*connect),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) &reply, sizeof(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) /* check IPC return value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) dev_err(scomp->dev, "error: failed to add route sink %s control %s source %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) route->sink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) route->control ? route->control : "none",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) route->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) /* check IPC reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) if (reply.error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) dev_err(scomp->dev, "error: DSP failed to add route sink %s control %s source %s result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) route->sink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) route->control ? route->control : "none",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) route->source, reply.error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) ret = reply.error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) sroute->route = route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) dobj->private = sroute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) sroute->private = connect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) /* add route to route list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) list_add(&sroute->list, &sdev->route_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) kfree(connect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) kfree(sroute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) /* Function to set the initial value of SOF kcontrols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) * The value will be stored in scontrol->control_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) static int snd_sof_cache_kcontrol_val(struct snd_soc_component *scomp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) struct snd_sof_control *scontrol = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) int ipc_cmd, ctrl_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) /* notify DSP of kcontrol values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) switch (scontrol->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) case SOF_CTRL_CMD_VOLUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) case SOF_CTRL_CMD_ENUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) case SOF_CTRL_CMD_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) ipc_cmd = SOF_IPC_COMP_GET_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) ctrl_type = SOF_CTRL_TYPE_VALUE_CHAN_GET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) case SOF_CTRL_CMD_BINARY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) ipc_cmd = SOF_IPC_COMP_GET_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) ctrl_type = SOF_CTRL_TYPE_DATA_GET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) dev_err(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) "error: Invalid scontrol->cmd: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) scontrol->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) ret = snd_sof_ipc_set_get_comp_data(scontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) ipc_cmd, ctrl_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) scontrol->cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) dev_warn(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) "error: kcontrol value get for widget: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) scontrol->comp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) int snd_sof_complete_pipeline(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) struct snd_sof_widget *swidget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) struct snd_sof_dev *sdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) struct sof_ipc_pipe_ready ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) struct sof_ipc_reply reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) dev_dbg(dev, "tplg: complete pipeline %s id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) swidget->widget->name, swidget->comp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) memset(&ready, 0, sizeof(ready));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) ready.hdr.size = sizeof(ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) ready.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) ready.comp_id = swidget->comp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) ret = sof_ipc_tx_message(sdev->ipc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) ready.hdr.cmd, &ready, sizeof(ready), &reply,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) sizeof(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) /* completion - called at completion of firmware loading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) static void sof_complete(struct snd_soc_component *scomp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) struct snd_sof_widget *swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) /* some widget types require completion notificattion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) list_for_each_entry(swidget, &sdev->widget_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) if (swidget->complete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) switch (swidget->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) case snd_soc_dapm_scheduler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) swidget->complete =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) snd_sof_complete_pipeline(scomp->dev, swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) * cache initial values of SOF kcontrols by reading DSP value over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) * IPC. It may be overwritten by alsa-mixer after booting up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) snd_sof_cache_kcontrol_val(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) /* manifest - optional to inform component of manifest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) static int sof_manifest(struct snd_soc_component *scomp, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) struct snd_soc_tplg_manifest *man)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) u32 abi_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) size = le32_to_cpu(man->priv.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) /* backward compatible with tplg without ABI info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) if (!size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) dev_dbg(scomp->dev, "No topology ABI info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) if (size != SOF_TPLG_ABI_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) dev_err(scomp->dev, "error: invalid topology ABI size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) dev_info(scomp->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) "Topology: ABI %d:%d:%d Kernel ABI %d:%d:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) man->priv.data[0], man->priv.data[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) man->priv.data[2], SOF_ABI_MAJOR, SOF_ABI_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) SOF_ABI_PATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) abi_version = SOF_ABI_VER(man->priv.data[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) man->priv.data[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) man->priv.data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, abi_version)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) dev_err(scomp->dev, "error: incompatible topology ABI version\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) if (abi_version > SOF_ABI_VERSION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) if (!IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) dev_warn(scomp->dev, "warn: topology ABI is more recent than kernel\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) dev_err(scomp->dev, "error: topology ABI is more recent than kernel\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) /* vendor specific kcontrol handlers available for binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) static const struct snd_soc_tplg_kcontrol_ops sof_io_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) {SOF_TPLG_KCTL_VOL_ID, snd_sof_volume_get, snd_sof_volume_put},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) {SOF_TPLG_KCTL_BYTES_ID, snd_sof_bytes_get, snd_sof_bytes_put},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) {SOF_TPLG_KCTL_ENUM_ID, snd_sof_enum_get, snd_sof_enum_put},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) {SOF_TPLG_KCTL_SWITCH_ID, snd_sof_switch_get, snd_sof_switch_put},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) /* vendor specific bytes ext handlers available for binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) static const struct snd_soc_tplg_bytes_ext_ops sof_bytes_ext_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) {SOF_TPLG_KCTL_BYTES_ID, snd_sof_bytes_ext_get, snd_sof_bytes_ext_put},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) {SOF_TPLG_KCTL_BYTES_VOLATILE_RO, snd_sof_bytes_ext_volatile_get},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) static struct snd_soc_tplg_ops sof_tplg_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) /* external kcontrol init - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) .control_load = sof_control_load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) .control_unload = sof_control_unload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) /* external kcontrol init - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) .dapm_route_load = sof_route_load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) .dapm_route_unload = sof_route_unload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) /* external widget init - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) /* .widget_load is not currently used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) .widget_ready = sof_widget_ready,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) .widget_unload = sof_widget_unload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) /* FE DAI - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) .dai_load = sof_dai_load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) .dai_unload = sof_dai_unload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) /* DAI link - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) .link_load = sof_link_load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) .link_unload = sof_link_unload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) /* completion - called at completion of firmware loading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) .complete = sof_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) /* manifest - optional to inform component of manifest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) .manifest = sof_manifest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) /* vendor specific kcontrol handlers available for binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) .io_ops = sof_io_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) .io_ops_count = ARRAY_SIZE(sof_io_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) /* vendor specific bytes ext handlers available for binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) .bytes_ext_ops = sof_bytes_ext_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) .bytes_ext_ops_count = ARRAY_SIZE(sof_bytes_ext_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) dev_dbg(scomp->dev, "loading topology:%s\n", file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) ret = request_firmware(&fw, file, scomp->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) dev_err(scomp->dev, "error: tplg request firmware %s failed err: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) file, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) ret = snd_soc_tplg_component_load(scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) &sof_tplg_ops, fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) SND_SOC_TPLG_INDEX_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) dev_err(scomp->dev, "error: tplg component load failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) EXPORT_SYMBOL(snd_sof_load_topology);