Skip to content

Commit 74ec9c1

Browse files
ujfalusigregkh
authored andcommitted
ASoC: SOF: pcm: Add snd_sof_pcm specific wrappers for dev_dbg() and dev_err()
[ Upstream commit 8606931 ] Introduce spcm_dbg() and spcm_err() macros to provide consistent printing for debug and error messages which includes usable information in the print's prefix. Update the prints in pcm.c, ipc3-pcm.c and ipc4-pcm.c to take advantage of the features provided by the macros. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Liam Girdwood <liam.r.girdwood@intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Link: https://patch.msgid.link/20250206092828.7569-4-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org> Stable-dep-of: 17661c6 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5f291ad commit 74ec9c1

4 files changed

Lines changed: 65 additions & 58 deletions

File tree

sound/soc/sof/ipc3-pcm.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,23 @@ static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component,
117117
if (platform_params->cont_update_posn)
118118
pcm.params.cont_update_posn = 1;
119119

120-
dev_dbg(component->dev, "stream_tag %d", pcm.params.stream_tag);
120+
spcm_dbg(spcm, substream->stream, "stream_tag %d\n",
121+
pcm.params.stream_tag);
121122

122123
/* send hw_params IPC to the DSP */
123124
ret = sof_ipc_tx_message(sdev->ipc, &pcm, sizeof(pcm),
124125
&ipc_params_reply, sizeof(ipc_params_reply));
125126
if (ret < 0) {
126-
dev_err(component->dev, "HW params ipc failed for stream %d\n",
127-
pcm.params.stream_tag);
127+
spcm_err(spcm, substream->stream,
128+
"STREAM_PCM_PARAMS ipc failed for stream_tag %d\n",
129+
pcm.params.stream_tag);
128130
return ret;
129131
}
130132

131133
ret = snd_sof_set_stream_data_offset(sdev, &spcm->stream[substream->stream],
132134
ipc_params_reply.posn_offset);
133135
if (ret < 0) {
134-
dev_err(component->dev, "%s: invalid stream data offset for PCM %d\n",
135-
__func__, spcm->pcm.pcm_id);
136+
spcm_err(spcm, substream->stream, "invalid stream data offset\n");
136137
return ret;
137138
}
138139

@@ -171,7 +172,7 @@ static int sof_ipc3_pcm_trigger(struct snd_soc_component *component,
171172
stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
172173
break;
173174
default:
174-
dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
175+
spcm_err(spcm, substream->stream, "Unhandled trigger cmd %d\n", cmd);
175176
return -EINVAL;
176177
}
177178

sound/soc/sof/ipc4-pcm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
291291
int ret;
292292
int i;
293293

294-
dev_dbg(sdev->dev, "trigger cmd: %d state: %d\n", cmd, state);
295-
296294
spcm = snd_sof_find_spcm_dai(component, rtd);
297295
if (!spcm)
298296
return -EINVAL;
299297

298+
spcm_dbg(spcm, substream->stream, "cmd: %d, state: %d\n", cmd, state);
299+
300300
pipeline_list = &spcm->stream[substream->stream].pipeline_list;
301301

302302
/* nothing to trigger if the list is empty */
@@ -358,7 +358,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
358358
*/
359359
ret = sof_ipc4_set_multi_pipeline_state(sdev, SOF_IPC4_PIPE_PAUSED, trigger_list);
360360
if (ret < 0) {
361-
dev_err(sdev->dev, "failed to pause all pipelines\n");
361+
spcm_err(spcm, substream->stream, "failed to pause all pipelines\n");
362362
goto free;
363363
}
364364

@@ -376,7 +376,9 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
376376
/* else set the RUNNING/RESET state in the DSP */
377377
ret = sof_ipc4_set_multi_pipeline_state(sdev, state, trigger_list);
378378
if (ret < 0) {
379-
dev_err(sdev->dev, "failed to set final state %d for all pipelines\n", state);
379+
spcm_err(spcm, substream->stream,
380+
"failed to set final state %d for all pipelines\n",
381+
state);
380382
/*
381383
* workaround: if the firmware is crashed while setting the
382384
* pipelines to reset state we must ignore the error code and

sound/soc/sof/pcm.c

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,16 @@ sof_pcm_setup_connected_widgets(struct snd_sof_dev *sdev, struct snd_soc_pcm_run
9999
ret = snd_soc_dapm_dai_get_connected_widgets(dai, dir, &list,
100100
dpcm_end_walk_at_be);
101101
if (ret < 0) {
102-
dev_err(sdev->dev, "error: dai %s has no valid %s path\n", dai->name,
103-
snd_pcm_direction_name(dir));
102+
spcm_err(spcm, dir, "dai %s has no valid %s path\n",
103+
dai->name, snd_pcm_direction_name(dir));
104104
return ret;
105105
}
106106

107107
spcm->stream[dir].list = list;
108108

109109
ret = sof_widget_list_setup(sdev, spcm, params, platform_params, dir);
110110
if (ret < 0) {
111-
dev_err(sdev->dev, "error: failed widget list set up for pcm %d dir %d\n",
112-
spcm->pcm.pcm_id, dir);
111+
spcm_err(spcm, dir, "Widget list set up failed\n");
113112
spcm->stream[dir].list = NULL;
114113
snd_soc_dapm_dai_free_widgets(&list);
115114
return ret;
@@ -139,6 +138,8 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
139138
if (!spcm)
140139
return -EINVAL;
141140

141+
spcm_dbg(spcm, substream->stream, "Entry: hw_params\n");
142+
142143
/*
143144
* Handle repeated calls to hw_params() without free_pcm() in
144145
* between. At least ALSA OSS emulation depends on this.
@@ -151,12 +152,9 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
151152
spcm->prepared[substream->stream] = false;
152153
}
153154

154-
dev_dbg(component->dev, "pcm: hw params stream %d dir %d\n",
155-
spcm->pcm.pcm_id, substream->stream);
156-
157155
ret = snd_sof_pcm_platform_hw_params(sdev, substream, params, &platform_params);
158156
if (ret < 0) {
159-
dev_err(component->dev, "platform hw params failed\n");
157+
spcm_err(spcm, substream->stream, "platform hw params failed\n");
160158
return ret;
161159
}
162160

@@ -224,7 +222,8 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev,
224222
if (free_widget_list) {
225223
ret = sof_widget_list_free(sdev, spcm, dir);
226224
if (ret < 0)
227-
dev_err(sdev->dev, "failed to free widgets during suspend\n");
225+
spcm_err(spcm, substream->stream,
226+
"failed to free widgets during suspend\n");
228227
}
229228

230229
return ret;
@@ -273,8 +272,7 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
273272
if (!spcm)
274273
return -EINVAL;
275274

276-
dev_dbg(component->dev, "pcm: free stream %d dir %d\n",
277-
spcm->pcm.pcm_id, substream->stream);
275+
spcm_dbg(spcm, substream->stream, "Entry: hw_free\n");
278276

279277
if (spcm->prepared[substream->stream]) {
280278
/* stop DMA first if needed */
@@ -323,18 +321,17 @@ static int sof_pcm_prepare(struct snd_soc_component *component,
323321
if (!spcm)
324322
return -EINVAL;
325323

324+
spcm_dbg(spcm, substream->stream, "Entry: prepare\n");
325+
326326
if (spcm->prepared[substream->stream])
327327
return 0;
328328

329-
dev_dbg(component->dev, "pcm: prepare stream %d dir %d\n",
330-
spcm->pcm.pcm_id, substream->stream);
331-
332329
/* set hw_params */
333330
ret = sof_pcm_hw_params(component,
334331
substream, &spcm->params[substream->stream]);
335332
if (ret < 0) {
336-
dev_err(component->dev,
337-
"error: set pcm hw_params after resume\n");
333+
spcm_err(spcm, substream->stream,
334+
"failed to set hw_params after resume\n");
338335
return ret;
339336
}
340337

@@ -364,8 +361,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
364361
if (!spcm)
365362
return -EINVAL;
366363

367-
dev_dbg(component->dev, "pcm: trigger stream %d dir %d cmd %d\n",
368-
spcm->pcm.pcm_id, substream->stream, cmd);
364+
spcm_dbg(spcm, substream->stream, "Entry: trigger (cmd: %d)\n", cmd);
369365

370366
switch (cmd) {
371367
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
@@ -412,7 +408,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
412408
reset_hw_params = true;
413409
break;
414410
default:
415-
dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
411+
spcm_err(spcm, substream->stream, "Unhandled trigger cmd %d\n", cmd);
416412
return -EINVAL;
417413
}
418414

@@ -497,9 +493,7 @@ static int sof_pcm_open(struct snd_soc_component *component,
497493
if (!spcm)
498494
return -EINVAL;
499495

500-
dev_dbg(component->dev, "pcm: open stream %d dir %d\n",
501-
spcm->pcm.pcm_id, substream->stream);
502-
496+
spcm_dbg(spcm, substream->stream, "Entry: open\n");
503497

504498
caps = &spcm->pcm.caps[substream->stream];
505499

@@ -529,18 +523,16 @@ static int sof_pcm_open(struct snd_soc_component *component,
529523

530524
ret = snd_sof_pcm_platform_open(sdev, substream);
531525
if (ret < 0) {
532-
dev_err(component->dev, "error: pcm open failed %d\n", ret);
526+
spcm_err(spcm, substream->stream,
527+
"platform pcm open failed %d\n", ret);
533528
return ret;
534529
}
535530

536-
dev_dbg(component->dev, "period bytes min %zd, max %zd\n",
537-
runtime->hw.period_bytes_min,
538-
runtime->hw.period_bytes_max);
539-
dev_dbg(component->dev, "period count min %d, max %d\n",
540-
runtime->hw.periods_min,
541-
runtime->hw.periods_max);
542-
dev_dbg(component->dev, "buffer bytes max %zd\n",
543-
runtime->hw.buffer_bytes_max);
531+
spcm_dbg(spcm, substream->stream, "period bytes min %zd, max %zd\n",
532+
runtime->hw.period_bytes_min, runtime->hw.period_bytes_max);
533+
spcm_dbg(spcm, substream->stream, "period count min %d, max %d\n",
534+
runtime->hw.periods_min, runtime->hw.periods_max);
535+
spcm_dbg(spcm, substream->stream, "buffer bytes max %zd\n", runtime->hw.buffer_bytes_max);
544536

545537
return 0;
546538
}
@@ -561,13 +553,12 @@ static int sof_pcm_close(struct snd_soc_component *component,
561553
if (!spcm)
562554
return -EINVAL;
563555

564-
dev_dbg(component->dev, "pcm: close stream %d dir %d\n",
565-
spcm->pcm.pcm_id, substream->stream);
556+
spcm_dbg(spcm, substream->stream, "Entry: close\n");
566557

567558
err = snd_sof_pcm_platform_close(sdev, substream);
568559
if (err < 0) {
569-
dev_err(component->dev, "error: pcm close failed %d\n",
570-
err);
560+
spcm_err(spcm, substream->stream,
561+
"platform pcm close failed %d\n", err);
571562
/*
572563
* keep going, no point in preventing the close
573564
* from happening
@@ -601,24 +592,24 @@ static int sof_pcm_new(struct snd_soc_component *component,
601592
return 0;
602593
}
603594

604-
dev_dbg(component->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
595+
dev_dbg(spcm->scomp->dev, "pcm%u (%s): Entry: pcm_construct\n",
596+
spcm->pcm.pcm_id, spcm->pcm.pcm_name);
605597

606598
/* do we need to pre-allocate playback audio buffer pages */
607599
if (!spcm->pcm.playback)
608600
goto capture;
609601

610602
caps = &spcm->pcm.caps[stream];
611603

612-
/* pre-allocate playback audio buffer pages */
613-
dev_dbg(component->dev,
614-
"spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
615-
caps->name, caps->buffer_size_min, caps->buffer_size_max);
616-
617604
if (!pcm->streams[stream].substream) {
618-
dev_err(component->dev, "error: NULL playback substream!\n");
605+
spcm_err(spcm, stream, "NULL playback substream!\n");
619606
return -EINVAL;
620607
}
621608

609+
/* pre-allocate playback audio buffer pages */
610+
spcm_dbg(spcm, stream, "allocate %s playback DMA buffer size 0x%x max 0x%x\n",
611+
caps->name, caps->buffer_size_min, caps->buffer_size_max);
612+
622613
snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
623614
SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
624615
0, le32_to_cpu(caps->buffer_size_max));
@@ -631,16 +622,15 @@ static int sof_pcm_new(struct snd_soc_component *component,
631622

632623
caps = &spcm->pcm.caps[stream];
633624

634-
/* pre-allocate capture audio buffer pages */
635-
dev_dbg(component->dev,
636-
"spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
637-
caps->name, caps->buffer_size_min, caps->buffer_size_max);
638-
639625
if (!pcm->streams[stream].substream) {
640-
dev_err(component->dev, "error: NULL capture substream!\n");
626+
spcm_err(spcm, stream, "NULL capture substream!\n");
641627
return -EINVAL;
642628
}
643629

630+
/* pre-allocate capture audio buffer pages */
631+
spcm_dbg(spcm, stream, "allocate %s capture DMA buffer size 0x%x max 0x%x\n",
632+
caps->name, caps->buffer_size_min, caps->buffer_size_max);
633+
644634
snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
645635
SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
646636
0, le32_to_cpu(caps->buffer_size_max));

sound/soc/sof/sof-audio.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,20 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
601601
void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
602602
void snd_sof_pcm_init_elapsed_work(struct work_struct *work);
603603

604+
/*
605+
* snd_sof_pcm specific wrappers for dev_dbg() and dev_err() to provide
606+
* consistent and useful prints.
607+
*/
608+
#define spcm_dbg(__spcm, __dir, __fmt, ...) \
609+
dev_dbg((__spcm)->scomp->dev, "pcm%u (%s), dir %d: " __fmt, \
610+
(__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \
611+
##__VA_ARGS__)
612+
613+
#define spcm_err(__spcm, __dir, __fmt, ...) \
614+
dev_err((__spcm)->scomp->dev, "%s: pcm%u (%s), dir %d: " __fmt, \
615+
__func__, (__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \
616+
##__VA_ARGS__)
617+
604618
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
605619
void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
606620
void snd_sof_compr_init_elapsed_work(struct work_struct *work);

0 commit comments

Comments
 (0)