Skip to content

Commit 24c4bc5

Browse files
ranj063ujfalusi
authored andcommitted
ASoC: SOF: pcm: Modify the signature of a couple of PCM IPC ops
In order to reuse the pipeline triggering logic for compressed support with IPC4, modify the signature of the trigger and hw_free PCM IPC ops so that they can be reused. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 5c80069 commit 24c4bc5

4 files changed

Lines changed: 39 additions & 46 deletions

File tree

sound/soc/sof/ipc3-pcm.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,18 @@
1414
#include "sof-audio.h"
1515

1616
static int sof_ipc3_pcm_hw_free(struct snd_soc_component *component,
17-
struct snd_pcm_substream *substream)
17+
struct snd_pcm_substream *substream,
18+
struct snd_sof_pcm *spcm, int dir)
1819
{
1920
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
20-
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
2121
struct sof_ipc_stream stream;
22-
struct snd_sof_pcm *spcm;
23-
24-
spcm = snd_sof_find_spcm_dai(component, rtd);
25-
if (!spcm)
26-
return -EINVAL;
2722

28-
if (!spcm->prepared[substream->stream])
23+
if (!spcm->prepared[dir])
2924
return 0;
3025

3126
stream.hdr.size = sizeof(stream);
3227
stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE;
33-
stream.comp_id = spcm->stream[substream->stream].comp_id;
28+
stream.comp_id = spcm->stream[dir].comp_id;
3429

3530
/* send IPC to the DSP */
3631
return sof_ipc_tx_message_no_reply(sdev->ipc, &stream, sizeof(stream));
@@ -141,20 +136,15 @@ static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component,
141136
}
142137

143138
static int sof_ipc3_pcm_trigger(struct snd_soc_component *component,
144-
struct snd_pcm_substream *substream, int cmd)
139+
struct snd_pcm_substream *substream,
140+
struct snd_sof_pcm *spcm, int cmd, int dir)
145141
{
146-
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
147142
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
148143
struct sof_ipc_stream stream;
149-
struct snd_sof_pcm *spcm;
150-
151-
spcm = snd_sof_find_spcm_dai(component, rtd);
152-
if (!spcm)
153-
return -EINVAL;
154144

155145
stream.hdr.size = sizeof(stream);
156146
stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG;
157-
stream.comp_id = spcm->stream[substream->stream].comp_id;
147+
stream.comp_id = spcm->stream[dir].comp_id;
158148

159149
switch (cmd) {
160150
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
@@ -172,7 +162,7 @@ static int sof_ipc3_pcm_trigger(struct snd_soc_component *component,
172162
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
173163
break;
174164
default:
175-
spcm_err(spcm, substream->stream, "Unhandled trigger cmd %d\n", cmd);
165+
spcm_err(spcm, dir, "Unhandled trigger cmd %d\n", cmd);
176166
return -EINVAL;
177167
}
178168

sound/soc/sof/ipc4-pcm.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -412,28 +412,23 @@ static int sof_ipc4_chain_dma_trigger(struct snd_sof_dev *sdev,
412412
}
413413

414414
static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
415-
struct snd_pcm_substream *substream, int state, int cmd)
415+
struct snd_pcm_substream *substream, int state, int cmd,
416+
struct snd_sof_pcm *spcm, int dir)
416417
{
417418
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
418-
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
419419
struct snd_sof_pcm_stream_pipeline_list *pipeline_list;
420420
struct sof_ipc4_fw_data *ipc4_data = sdev->private;
421421
struct ipc4_pipeline_set_state_data *trigger_list;
422422
struct snd_sof_widget *pipe_widget;
423423
struct sof_ipc4_pipeline *pipeline;
424424
struct snd_sof_pipeline *spipe;
425-
struct snd_sof_pcm *spcm;
426425
u8 *pipe_priority;
427426
int ret;
428427
int i;
429428

430-
spcm = snd_sof_find_spcm_dai(component, rtd);
431-
if (!spcm)
432-
return -EINVAL;
429+
spcm_dbg(spcm, dir, "cmd: %d, state: %d\n", cmd, state);
433430

434-
spcm_dbg(spcm, substream->stream, "cmd: %d, state: %d\n", cmd, state);
435-
436-
pipeline_list = &spcm->stream[substream->stream].pipeline_list;
431+
pipeline_list = &spcm->stream[dir].pipeline_list;
437432

438433
/* nothing to trigger if the list is empty */
439434
if (!pipeline_list->pipelines || !pipeline_list->count)
@@ -450,9 +445,9 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
450445
if (pipeline->use_chain_dma) {
451446
struct sof_ipc4_timestamp_info *time_info;
452447

453-
time_info = sof_ipc4_sps_to_time_info(&spcm->stream[substream->stream]);
448+
time_info = sof_ipc4_sps_to_time_info(&spcm->stream[dir]);
454449

455-
ret = sof_ipc4_chain_dma_trigger(sdev, spcm, substream->stream,
450+
ret = sof_ipc4_chain_dma_trigger(sdev, spcm, dir,
456451
pipeline_list, state, cmd);
457452
if (ret || !time_info)
458453
return ret;
@@ -461,12 +456,16 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
461456
/*
462457
* Record the DAI position for delay reporting
463458
* To handle multiple pause/resume/xrun we need to add
464-
* the positions to simulate how the firmware behaves
459+
* the positions to simulate how the firmware behaves.
460+
* Chained DAM does not support compress streams. We should
461+
* never get here with compress.
465462
*/
466-
u64 pos = snd_sof_pcm_get_dai_frame_counter(sdev, component,
467-
substream);
463+
if (substream) {
464+
u64 pos = snd_sof_pcm_get_dai_frame_counter(sdev, component,
465+
substream);
468466

469-
time_info->stream_end_offset += pos;
467+
time_info->stream_end_offset += pos;
468+
}
470469
} else if (state == SOF_IPC4_PIPE_RESET) {
471470
/* Reset the end offset as the stream is stopped */
472471
time_info->stream_end_offset = 0;
@@ -527,7 +526,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
527526
*/
528527
ret = sof_ipc4_set_multi_pipeline_state(sdev, SOF_IPC4_PIPE_PAUSED, trigger_list);
529528
if (ret < 0) {
530-
spcm_err(spcm, substream->stream, "failed to pause all pipelines\n");
529+
spcm_err(spcm, dir, "failed to pause all pipelines\n");
531530
goto free;
532531
}
533532

@@ -546,7 +545,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
546545
* Invalidate the stream_start_offset to make sure that it is
547546
* going to be updated if the stream resumes
548547
*/
549-
time_info = sof_ipc4_sps_to_time_info(&spcm->stream[substream->stream]);
548+
time_info = sof_ipc4_sps_to_time_info(&spcm->stream[dir]);
550549
if (time_info)
551550
time_info->stream_start_offset = SOF_IPC4_INVALID_STREAM_POSITION;
552551

@@ -556,7 +555,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
556555
/* else set the RUNNING/RESET state in the DSP */
557556
ret = sof_ipc4_set_multi_pipeline_state(sdev, state, trigger_list);
558557
if (ret < 0) {
559-
spcm_err(spcm, substream->stream,
558+
spcm_err(spcm, dir,
560559
"failed to set final state %d for all pipelines\n",
561560
state);
562561
/*
@@ -586,7 +585,8 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
586585
}
587586

588587
static int sof_ipc4_pcm_trigger(struct snd_soc_component *component,
589-
struct snd_pcm_substream *substream, int cmd)
588+
struct snd_pcm_substream *substream,
589+
struct snd_sof_pcm *spcm, int cmd, int dir)
590590
{
591591
int state;
592592

@@ -608,14 +608,15 @@ static int sof_ipc4_pcm_trigger(struct snd_soc_component *component,
608608
}
609609

610610
/* set the pipeline state */
611-
return sof_ipc4_trigger_pipelines(component, substream, state, cmd);
611+
return sof_ipc4_trigger_pipelines(component, substream, state, cmd, spcm, dir);
612612
}
613613

614614
static int sof_ipc4_pcm_hw_free(struct snd_soc_component *component,
615-
struct snd_pcm_substream *substream)
615+
struct snd_pcm_substream *substream,
616+
struct snd_sof_pcm *spcm, int dir)
616617
{
617618
/* command is not relevant with RESET, so just pass 0 */
618-
return sof_ipc4_trigger_pipelines(component, substream, SOF_IPC4_PIPE_RESET, 0);
619+
return sof_ipc4_trigger_pipelines(component, substream, SOF_IPC4_PIPE_RESET, 0, spcm, dir);
619620
}
620621

621622
static int ipc4_ssp_dai_config_pcm_params_match(struct snd_sof_dev *sdev,

sound/soc/sof/pcm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
152152
* between. At least ALSA OSS emulation depends on this.
153153
*/
154154
if (spcm->prepared[substream->stream] && pcm_ops && pcm_ops->hw_free) {
155-
ret = pcm_ops->hw_free(component, substream);
155+
ret = pcm_ops->hw_free(component, substream, spcm, substream->stream);
156156
if (ret < 0)
157157
return ret;
158158

@@ -223,7 +223,8 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev,
223223

224224
/* free PCM in the DSP */
225225
if (pcm_ops && pcm_ops->hw_free) {
226-
ret = pcm_ops->hw_free(sdev->component, substream);
226+
ret = pcm_ops->hw_free(sdev->component, substream, spcm,
227+
substream->stream);
227228
if (ret < 0) {
228229
spcm_err(spcm, substream->stream,
229230
"pcm_ops->hw_free failed %d\n", ret);
@@ -458,7 +459,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
458459
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
459460

460461
if (pcm_ops && pcm_ops->trigger)
461-
ret = pcm_ops->trigger(component, substream, cmd);
462+
ret = pcm_ops->trigger(component, substream, spcm, cmd, substream->stream);
462463

463464
switch (cmd) {
464465
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:

sound/soc/sof/sof-audio.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ struct sof_ipc_pcm_ops {
125125
int (*hw_params)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
126126
struct snd_pcm_hw_params *params,
127127
struct snd_sof_platform_stream_params *platform_params);
128-
int (*hw_free)(struct snd_soc_component *component, struct snd_pcm_substream *substream);
129-
int (*trigger)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
130-
int cmd);
128+
int (*hw_free)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
129+
struct snd_sof_pcm *spcm, int dir);
130+
int (*trigger)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
131+
struct snd_sof_pcm *spcm, int cmd, int dir);
131132
int (*dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
132133
int (*pcm_setup)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);
133134
void (*pcm_free)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);

0 commit comments

Comments
 (0)