Skip to content

Commit beac3f4

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: Add trigger PCM op for IPC3
Add the trigger PCM op for IPC3 and use it. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20220317175044.1752400-16-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 621fd48 commit beac3f4

2 files changed

Lines changed: 49 additions & 17 deletions

File tree

sound/soc/sof/ipc3-pcm.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,50 @@ static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component,
137137
return ret;
138138
}
139139

140+
static int sof_ipc3_pcm_trigger(struct snd_soc_component *component,
141+
struct snd_pcm_substream *substream, int cmd)
142+
{
143+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
144+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
145+
struct sof_ipc_stream stream;
146+
struct sof_ipc_reply reply;
147+
struct snd_sof_pcm *spcm;
148+
149+
spcm = snd_sof_find_spcm_dai(component, rtd);
150+
if (!spcm)
151+
return -EINVAL;
152+
153+
stream.hdr.size = sizeof(stream);
154+
stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG;
155+
stream.comp_id = spcm->stream[substream->stream].comp_id;
156+
157+
switch (cmd) {
158+
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
159+
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_PAUSE;
160+
break;
161+
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
162+
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE;
163+
break;
164+
case SNDRV_PCM_TRIGGER_START:
165+
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_START;
166+
break;
167+
case SNDRV_PCM_TRIGGER_SUSPEND:
168+
fallthrough;
169+
case SNDRV_PCM_TRIGGER_STOP:
170+
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
171+
break;
172+
default:
173+
dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
174+
return -EINVAL;
175+
}
176+
177+
/* send IPC to the DSP */
178+
return sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
179+
sizeof(stream), &reply, sizeof(reply));
180+
}
181+
140182
const struct sof_ipc_pcm_ops ipc3_pcm_ops = {
141183
.hw_params = sof_ipc3_pcm_hw_params,
142184
.hw_free = sof_ipc3_pcm_hw_free,
185+
.trigger = sof_ipc3_pcm_trigger,
143186
};

sound/soc/sof/pcm.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,12 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
274274
{
275275
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
276276
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
277+
const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
277278
struct snd_sof_pcm *spcm;
278-
struct sof_ipc_stream stream;
279-
struct sof_ipc_reply reply;
280279
bool reset_hw_params = false;
281280
bool free_widget_list = false;
282281
bool ipc_first = false;
283-
int ret;
282+
int ret = 0;
284283

285284
/* nothing to do for BE */
286285
if (rtd->dai_link->no_pcm)
@@ -293,17 +292,11 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
293292
dev_dbg(component->dev, "pcm: trigger stream %d dir %d cmd %d\n",
294293
spcm->pcm.pcm_id, substream->stream, cmd);
295294

296-
stream.hdr.size = sizeof(stream);
297-
stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG;
298-
stream.comp_id = spcm->stream[substream->stream].comp_id;
299-
300295
switch (cmd) {
301296
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
302-
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_PAUSE;
303297
ipc_first = true;
304298
break;
305299
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
306-
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE;
307300
break;
308301
case SNDRV_PCM_TRIGGER_START:
309302
if (spcm->stream[substream->stream].suspend_ignored) {
@@ -315,7 +308,6 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
315308
spcm->stream[substream->stream].suspend_ignored = false;
316309
return 0;
317310
}
318-
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_START;
319311
break;
320312
case SNDRV_PCM_TRIGGER_SUSPEND:
321313
if (sdev->system_suspend_target == SOF_SUSPEND_S0IX &&
@@ -332,13 +324,11 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
332324
free_widget_list = true;
333325
fallthrough;
334326
case SNDRV_PCM_TRIGGER_STOP:
335-
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
336327
ipc_first = true;
337328
reset_hw_params = true;
338329
break;
339330
default:
340-
dev_err(component->dev, "error: unhandled trigger cmd %d\n",
341-
cmd);
331+
dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
342332
return -EINVAL;
343333
}
344334

@@ -349,11 +339,10 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
349339
if (!ipc_first)
350340
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
351341

352-
/* send IPC to the DSP */
353-
ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
354-
sizeof(stream), &reply, sizeof(reply));
342+
if (pcm_ops->trigger)
343+
ret = pcm_ops->trigger(component, substream, cmd);
355344

356-
/* need to STOP DMA even if STOP IPC failed */
345+
/* need to STOP DMA even if trigger IPC failed */
357346
if (ipc_first)
358347
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
359348

0 commit comments

Comments
 (0)