^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) 2019 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: Ranjani Sridharan <ranjani.sridharan@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 "sof-audio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * helper to determine if there are only D0i3 compatible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * streams active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) bool d0i3_compatible_active = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) list_for_each_entry(spcm, &sdev->pcm_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) for_each_pcm_streams(dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) substream = spcm->stream[dir].substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (!substream || !substream->runtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * substream->runtime being not NULL indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * that the stream is open. No need to check the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * stream state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (!spcm->stream[dir].d0i3_compatible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) d0i3_compatible_active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return d0i3_compatible_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) EXPORT_SYMBOL(snd_sof_dsp_only_d0i3_compatible_stream_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) list_for_each_entry(spcm, &sdev->pcm_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].suspend_ignored ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) spcm->stream[SNDRV_PCM_STREAM_CAPTURE].suspend_ignored)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return true;
^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) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int sof_set_hw_params_upon_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct snd_sof_dev *sdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) snd_pcm_state_t state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * SOF requires hw_params to be set-up internally upon resume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * So, set the flag to indicate this for those streams that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * have been suspended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) list_for_each_entry(spcm, &sdev->pcm_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) for_each_pcm_streams(dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * do not reset hw_params upon resume for streams that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * were kept running during suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (spcm->stream[dir].suspend_ignored)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) substream = spcm->stream[dir].substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!substream || !substream->runtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) state = substream->runtime->status->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (state == SNDRV_PCM_STATE_SUSPENDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) spcm->prepared[dir] = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* set internal flag for BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return snd_sof_dsp_hw_params_upon_resume(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static int sof_restore_kcontrols(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct snd_sof_dev *sdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct snd_sof_control *scontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int ipc_cmd, ctrl_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* restore kcontrol values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* reset readback offset for scontrol after resuming */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) scontrol->readback_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* notify DSP of kcontrol values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) switch (scontrol->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) case SOF_CTRL_CMD_VOLUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) case SOF_CTRL_CMD_ENUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) case SOF_CTRL_CMD_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ipc_cmd = SOF_IPC_COMP_SET_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ctrl_type = SOF_CTRL_TYPE_VALUE_CHAN_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ret = snd_sof_ipc_set_get_comp_data(scontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ipc_cmd, ctrl_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) scontrol->cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) case SOF_CTRL_CMD_BINARY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ipc_cmd = SOF_IPC_COMP_SET_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ctrl_type = SOF_CTRL_TYPE_DATA_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ret = snd_sof_ipc_set_get_comp_data(scontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ipc_cmd, ctrl_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) scontrol->cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) "error: failed kcontrol value set for widget: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) scontrol->comp_id);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) const struct sof_ipc_pipe_new *snd_sof_pipeline_find(struct snd_sof_dev *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int pipeline_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) const struct snd_sof_widget *swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) list_for_each_entry(swidget, &sdev->widget_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (swidget->id == snd_soc_dapm_scheduler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) const struct sof_ipc_pipe_new *pipeline =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (pipeline->pipeline_id == pipeline_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return pipeline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int sof_restore_pipelines(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct snd_sof_dev *sdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct snd_sof_widget *swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct snd_sof_route *sroute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct sof_ipc_pipe_new *pipeline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct snd_sof_dai *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct sof_ipc_cmd_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct sof_ipc_comp *comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) size_t ipc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* restore pipeline components */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) list_for_each_entry_reverse(swidget, &sdev->widget_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct sof_ipc_comp_reply r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* skip if there is no private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!swidget->private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ret = sof_pipeline_core_enable(sdev, swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) "error: failed to enable target core: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) switch (swidget->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) case snd_soc_dapm_dai_in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) case snd_soc_dapm_dai_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ipc_size = sizeof(struct sof_ipc_comp_dai) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) sizeof(struct sof_ipc_comp_ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) comp = kzalloc(ipc_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!comp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dai = swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) memcpy(comp, &dai->comp_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) sizeof(struct sof_ipc_comp_dai));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* append extended data to the end of the component */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) memcpy((u8 *)comp + sizeof(struct sof_ipc_comp_dai),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) &swidget->comp_ext, sizeof(swidget->comp_ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ret = sof_ipc_tx_message(sdev->ipc, comp->hdr.cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) comp, ipc_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) &r, sizeof(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) kfree(comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) case snd_soc_dapm_scheduler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * During suspend, all DSP cores are powered off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * Therefore upon resume, create the pipeline comp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * and power up the core that the pipeline is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * scheduled on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) pipeline = swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ret = sof_load_pipeline_ipc(dev, pipeline, &r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) hdr = swidget->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) ret = sof_ipc_tx_message(sdev->ipc, hdr->cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) swidget->private, hdr->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) &r, sizeof(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) "error: failed to load widget type %d with ID: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) swidget->widget->id, swidget->comp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* restore pipeline connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) list_for_each_entry_reverse(sroute, &sdev->route_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct sof_ipc_pipe_comp_connect *connect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct sof_ipc_reply reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* skip if there's no private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!sroute->private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) connect = sroute->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* send ipc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ret = sof_ipc_tx_message(sdev->ipc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) connect->hdr.cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) connect, sizeof(*connect),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) &reply, sizeof(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) "error: failed to load route sink %s control %s source %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) sroute->route->sink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) sroute->route->control ? sroute->route->control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) : "none",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) sroute->route->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* restore dai links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) list_for_each_entry_reverse(dai, &sdev->dai_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct sof_ipc_reply reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct sof_ipc_dai_config *config = dai->dai_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!config) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) dev_err(dev, "error: no config for DAI %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dai->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * The link DMA channel would be invalidated for running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * streams but not for streams that were in the PAUSED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * state during suspend. So invalidate it here before setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * the dai config in the DSP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (config->type == SOF_DAI_INTEL_HDA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) config->hda.link_dma_ch = DMA_CHAN_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ret = sof_ipc_tx_message(sdev->ipc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) config->hdr.cmd, config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) config->hdr.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) &reply, sizeof(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) "error: failed to set dai config for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dai->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^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) /* complete pipeline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) list_for_each_entry(swidget, &sdev->widget_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) switch (swidget->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) case snd_soc_dapm_scheduler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) swidget->complete =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) snd_sof_complete_pipeline(dev, swidget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /* restore pipeline kcontrols */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ret = sof_restore_kcontrols(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) "error: restoring kcontrols after resume\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^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) * Generic object lookup APIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) list_for_each_entry(spcm, &sdev->pcm_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* match with PCM dai name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (strcmp(spcm->pcm.dai_name, name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* match with playback caps name if set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (*spcm->pcm.caps[0].name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) !strcmp(spcm->pcm.caps[0].name, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* match with capture caps name if set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (*spcm->pcm.caps[1].name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) !strcmp(spcm->pcm.caps[1].name, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) unsigned int comp_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) int *direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) int dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) list_for_each_entry(spcm, &sdev->pcm_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) for_each_pcm_streams(dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (spcm->stream[dir].comp_id == comp_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) *direction = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) unsigned int pcm_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct snd_sof_pcm *spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) list_for_each_entry(spcm, &sdev->pcm_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (le32_to_cpu(spcm->pcm.pcm_id) == pcm_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return spcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct snd_sof_widget *swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) list_for_each_entry(swidget, &sdev->widget_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (strcmp(name, swidget->widget->name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* find widget by stream name and direction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct snd_sof_widget *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) const char *pcm_name, int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct snd_sof_widget *swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) enum snd_soc_dapm_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (dir == SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) type = snd_soc_dapm_aif_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) type = snd_soc_dapm_aif_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) list_for_each_entry(swidget, &sdev->widget_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (!strcmp(pcm_name, swidget->widget->sname) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) swidget->id == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return swidget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return NULL;
^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 snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct snd_sof_dai *dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) list_for_each_entry(dai, &sdev->dai_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (dai->name && (strcmp(name, dai->name) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * SOF Driver enumeration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int sof_machine_check(struct snd_sof_dev *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct snd_sof_pdata *sof_pdata = sdev->pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) const struct sof_dev_desc *desc = sof_pdata->desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct snd_soc_acpi_mach *mach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* force nocodec mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) #if IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) dev_warn(sdev->dev, "Force to use nocodec mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) goto nocodec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* find machine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) snd_sof_machine_select(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (sof_pdata->machine) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) snd_sof_set_mach_params(sof_pdata->machine, sdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #if !IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) dev_err(sdev->dev, "error: no matching ASoC machine driver found - aborting probe\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) #if IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) nocodec:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /* select nocodec mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) dev_warn(sdev->dev, "Using nocodec machine driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) mach = devm_kzalloc(sdev->dev, sizeof(*mach), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (!mach)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) mach->drv_name = "sof-nocodec";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) sof_pdata->tplg_filename = desc->nocodec_tplg_filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) ret = sof_nocodec_setup(sdev->dev, desc->ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) sof_pdata->machine = mach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) snd_sof_set_mach_params(sof_pdata->machine, sdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) EXPORT_SYMBOL(sof_machine_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) int sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct snd_sof_pdata *plat_data = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) const char *drv_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) const void *mach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) drv_name = plat_data->machine->drv_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) mach = plat_data->machine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) size = sizeof(*plat_data->machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* register machine driver, pass machine info as pdata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) plat_data->pdev_mach =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) platform_device_register_data(sdev->dev, drv_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) PLATFORM_DEVID_NONE, mach, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (IS_ERR(plat_data->pdev_mach))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return PTR_ERR(plat_data->pdev_mach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) dev_dbg(sdev->dev, "created machine %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) dev_name(&plat_data->pdev_mach->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) EXPORT_SYMBOL(sof_machine_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct snd_sof_pdata *plat_data = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (!IS_ERR_OR_NULL(plat_data->pdev_mach))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) platform_device_unregister(plat_data->pdev_mach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) EXPORT_SYMBOL(sof_machine_unregister);