Skip to content

Commit 5d11291

Browse files
ujfalusibardliao
authored andcommitted
ASoC: SOF: pcm: Add snd_sof_pcm specific wrappers for dev_dbg() and dev_err()
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>
1 parent d8a5530 commit 5d11291

4 files changed

Lines changed: 72 additions & 66 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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static int sof_ipc4_chain_dma_trigger(struct snd_sof_dev *sdev,
313313
set_fifo_size = false;
314314
break;
315315
default:
316-
dev_err(sdev->dev, "Unexpected state %d", state);
316+
spcm_err(spcm, direction, "Unexpected pipeline state %d\n", state);
317317
return -EINVAL;
318318
}
319319

@@ -333,8 +333,8 @@ static int sof_ipc4_chain_dma_trigger(struct snd_sof_dev *sdev,
333333
struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
334334

335335
if (!pipeline->use_chain_dma) {
336-
dev_err(sdev->dev,
337-
"All pipelines in chained DMA stream should have use_chain_dma attribute set.");
336+
spcm_err(spcm, direction,
337+
"All pipelines in chained DMA path should have use_chain_dma attribute set.");
338338
return -EINVAL;
339339
}
340340

@@ -389,12 +389,12 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
389389
int ret;
390390
int i;
391391

392-
dev_dbg(sdev->dev, "trigger cmd: %d state: %d\n", cmd, state);
393-
394392
spcm = snd_sof_find_spcm_dai(component, rtd);
395393
if (!spcm)
396394
return -EINVAL;
397395

396+
spcm_dbg(spcm, substream->stream, "cmd: %d, state: %d\n", cmd, state);
397+
398398
pipeline_list = &spcm->stream[substream->stream].pipeline_list;
399399

400400
/* nothing to trigger if the list is empty */
@@ -465,7 +465,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
465465
*/
466466
ret = sof_ipc4_set_multi_pipeline_state(sdev, SOF_IPC4_PIPE_PAUSED, trigger_list);
467467
if (ret < 0) {
468-
dev_err(sdev->dev, "failed to pause all pipelines\n");
468+
spcm_err(spcm, substream->stream, "failed to pause all pipelines\n");
469469
goto free;
470470
}
471471

@@ -494,7 +494,9 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
494494
/* else set the RUNNING/RESET state in the DSP */
495495
ret = sof_ipc4_set_multi_pipeline_state(sdev, state, trigger_list);
496496
if (ret < 0) {
497-
dev_err(sdev->dev, "failed to set final state %d for all pipelines\n", state);
497+
spcm_err(spcm, substream->stream,
498+
"failed to set final state %d for all pipelines\n",
499+
state);
498500
/*
499501
* workaround: if the firmware is crashed while setting the
500502
* pipelines to reset state we must ignore the error code and

sound/soc/sof/pcm.c

Lines changed: 42 additions & 53 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

@@ -210,8 +208,8 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev,
210208
if (pcm_ops && pcm_ops->hw_free) {
211209
ret = pcm_ops->hw_free(sdev->component, substream);
212210
if (ret < 0) {
213-
dev_err(sdev->dev, "%s: pcm_ops hw_free failed %d\n",
214-
__func__, ret);
211+
spcm_err(spcm, substream->stream,
212+
"pcm_ops->hw_free failed %d\n", ret);
215213
err = ret;
216214
}
217215
}
@@ -223,8 +221,8 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev,
223221
/* reset the DMA */
224222
ret = snd_sof_pcm_platform_hw_free(sdev, substream);
225223
if (ret < 0) {
226-
dev_err(sdev->dev, "%s: platform hw free failed %d\n",
227-
__func__, ret);
224+
spcm_err(spcm, substream->stream,
225+
"platform hw free failed %d\n", ret);
228226
if (!err)
229227
err = ret;
230228
}
@@ -233,8 +231,8 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev,
233231
if (free_widget_list) {
234232
ret = sof_widget_list_free(sdev, spcm, dir);
235233
if (ret < 0) {
236-
dev_err(sdev->dev, "%s: sof_widget_list_free failed %d\n",
237-
__func__, ret);
234+
spcm_err(spcm, substream->stream,
235+
"sof_widget_list_free failed %d\n", ret);
238236
if (!err)
239237
err = ret;
240238
}
@@ -285,8 +283,7 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
285283
if (!spcm)
286284
return -EINVAL;
287285

288-
dev_dbg(component->dev, "pcm: free stream %d dir %d\n",
289-
spcm->pcm.pcm_id, substream->stream);
286+
spcm_dbg(spcm, substream->stream, "Entry: hw_free\n");
290287

291288
ret = sof_pcm_stream_free(sdev, substream, spcm, substream->stream, true);
292289

@@ -311,6 +308,8 @@ static int sof_pcm_prepare(struct snd_soc_component *component,
311308
if (!spcm)
312309
return -EINVAL;
313310

311+
spcm_dbg(spcm, substream->stream, "Entry: prepare\n");
312+
314313
if (spcm->prepared[substream->stream]) {
315314
if (!spcm->pending_stop[substream->stream])
316315
return 0;
@@ -324,15 +323,12 @@ static int sof_pcm_prepare(struct snd_soc_component *component,
324323
return ret;
325324
}
326325

327-
dev_dbg(component->dev, "pcm: prepare stream %d dir %d\n",
328-
spcm->pcm.pcm_id, substream->stream);
329-
330326
/* set hw_params */
331327
ret = sof_pcm_hw_params(component,
332328
substream, &spcm->params[substream->stream]);
333329
if (ret < 0) {
334-
dev_err(component->dev,
335-
"error: set pcm hw_params after resume\n");
330+
spcm_err(spcm, substream->stream,
331+
"failed to set hw_params after resume\n");
336332
return ret;
337333
}
338334

@@ -362,8 +358,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
362358
if (!spcm)
363359
return -EINVAL;
364360

365-
dev_dbg(component->dev, "pcm: trigger stream %d dir %d cmd %d\n",
366-
spcm->pcm.pcm_id, substream->stream, cmd);
361+
spcm_dbg(spcm, substream->stream, "Entry: trigger (cmd: %d)\n", cmd);
367362

368363
spcm->pending_stop[substream->stream] = false;
369364

@@ -412,7 +407,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
412407
reset_hw_params = true;
413408
break;
414409
default:
415-
dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
410+
spcm_err(spcm, substream->stream, "Unhandled trigger cmd %d\n", cmd);
416411
return -EINVAL;
417412
}
418413

@@ -514,9 +509,7 @@ static int sof_pcm_open(struct snd_soc_component *component,
514509
if (!spcm)
515510
return -EINVAL;
516511

517-
dev_dbg(component->dev, "pcm: open stream %d dir %d\n",
518-
spcm->pcm.pcm_id, substream->stream);
519-
512+
spcm_dbg(spcm, substream->stream, "Entry: open\n");
520513

521514
caps = &spcm->pcm.caps[substream->stream];
522515

@@ -546,18 +539,16 @@ static int sof_pcm_open(struct snd_soc_component *component,
546539

547540
ret = snd_sof_pcm_platform_open(sdev, substream);
548541
if (ret < 0) {
549-
dev_err(component->dev, "error: pcm open failed %d\n", ret);
542+
spcm_err(spcm, substream->stream,
543+
"platform pcm open failed %d\n", ret);
550544
return ret;
551545
}
552546

553-
dev_dbg(component->dev, "period bytes min %zd, max %zd\n",
554-
runtime->hw.period_bytes_min,
555-
runtime->hw.period_bytes_max);
556-
dev_dbg(component->dev, "period count min %d, max %d\n",
557-
runtime->hw.periods_min,
558-
runtime->hw.periods_max);
559-
dev_dbg(component->dev, "buffer bytes max %zd\n",
560-
runtime->hw.buffer_bytes_max);
547+
spcm_dbg(spcm, substream->stream, "period bytes min %zd, max %zd\n",
548+
runtime->hw.period_bytes_min, runtime->hw.period_bytes_max);
549+
spcm_dbg(spcm, substream->stream, "period count min %d, max %d\n",
550+
runtime->hw.periods_min, runtime->hw.periods_max);
551+
spcm_dbg(spcm, substream->stream, "buffer bytes max %zd\n", runtime->hw.buffer_bytes_max);
561552

562553
return 0;
563554
}
@@ -578,13 +569,12 @@ static int sof_pcm_close(struct snd_soc_component *component,
578569
if (!spcm)
579570
return -EINVAL;
580571

581-
dev_dbg(component->dev, "pcm: close stream %d dir %d\n",
582-
spcm->pcm.pcm_id, substream->stream);
572+
spcm_dbg(spcm, substream->stream, "Entry: close\n");
583573

584574
err = snd_sof_pcm_platform_close(sdev, substream);
585575
if (err < 0) {
586-
dev_err(component->dev, "error: pcm close failed %d\n",
587-
err);
576+
spcm_err(spcm, substream->stream,
577+
"platform pcm close failed %d\n", err);
588578
/*
589579
* keep going, no point in preventing the close
590580
* from happening
@@ -618,24 +608,24 @@ static int sof_pcm_new(struct snd_soc_component *component,
618608
return 0;
619609
}
620610

621-
dev_dbg(component->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
611+
dev_dbg(spcm->scomp->dev, "pcm%u (%s): Entry: pcm_construct\n",
612+
spcm->pcm.pcm_id, spcm->pcm.pcm_name);
622613

623614
/* do we need to pre-allocate playback audio buffer pages */
624615
if (!spcm->pcm.playback)
625616
goto capture;
626617

627618
caps = &spcm->pcm.caps[stream];
628619

629-
/* pre-allocate playback audio buffer pages */
630-
dev_dbg(component->dev,
631-
"spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
632-
caps->name, caps->buffer_size_min, caps->buffer_size_max);
633-
634620
if (!pcm->streams[stream].substream) {
635-
dev_err(component->dev, "error: NULL playback substream!\n");
621+
spcm_err(spcm, stream, "NULL playback substream!\n");
636622
return -EINVAL;
637623
}
638624

625+
/* pre-allocate playback audio buffer pages */
626+
spcm_dbg(spcm, stream, "allocate %s playback DMA buffer size 0x%x max 0x%x\n",
627+
caps->name, caps->buffer_size_min, caps->buffer_size_max);
628+
639629
snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
640630
SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
641631
0, le32_to_cpu(caps->buffer_size_max));
@@ -648,16 +638,15 @@ static int sof_pcm_new(struct snd_soc_component *component,
648638

649639
caps = &spcm->pcm.caps[stream];
650640

651-
/* pre-allocate capture audio buffer pages */
652-
dev_dbg(component->dev,
653-
"spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
654-
caps->name, caps->buffer_size_min, caps->buffer_size_max);
655-
656641
if (!pcm->streams[stream].substream) {
657-
dev_err(component->dev, "error: NULL capture substream!\n");
642+
spcm_err(spcm, stream, "NULL capture substream!\n");
658643
return -EINVAL;
659644
}
660645

646+
/* pre-allocate capture audio buffer pages */
647+
spcm_dbg(spcm, stream, "allocate %s capture DMA buffer size 0x%x max 0x%x\n",
648+
caps->name, caps->buffer_size_min, caps->buffer_size_max);
649+
661650
snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
662651
SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
663652
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
@@ -617,6 +617,20 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
617617
void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
618618
void snd_sof_pcm_init_elapsed_work(struct work_struct *work);
619619

620+
/*
621+
* snd_sof_pcm specific wrappers for dev_dbg() and dev_err() to provide
622+
* consistent and useful prints.
623+
*/
624+
#define spcm_dbg(__spcm, __dir, __fmt, ...) \
625+
dev_dbg((__spcm)->scomp->dev, "pcm%u (%s), dir %d: " __fmt, \
626+
(__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \
627+
##__VA_ARGS__)
628+
629+
#define spcm_err(__spcm, __dir, __fmt, ...) \
630+
dev_err((__spcm)->scomp->dev, "%s: pcm%u (%s), dir %d: " __fmt, \
631+
__func__, (__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \
632+
##__VA_ARGS__)
633+
620634
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
621635
void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
622636
void snd_sof_compr_init_elapsed_work(struct work_struct *work);

0 commit comments

Comments
 (0)