hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/soc/soc-compress.c
....@@ -19,23 +19,22 @@
1919 #include <sound/soc.h>
2020 #include <sound/initval.h>
2121 #include <sound/soc-dpcm.h>
22
+#include <sound/soc-link.h>
23
+#include <linux/pm_runtime.h>
2224
2325 static int soc_compr_components_open(struct snd_compr_stream *cstream,
2426 struct snd_soc_component **last)
2527 {
2628 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
2729 struct snd_soc_component *component;
28
- struct snd_soc_rtdcom_list *rtdcom;
29
- int ret;
30
+ int i, ret;
3031
31
- for_each_rtdcom(rtd, rtdcom) {
32
- component = rtdcom->component;
33
-
34
- if (!component->driver->compr_ops ||
35
- !component->driver->compr_ops->open)
32
+ for_each_rtd_components(rtd, i, component) {
33
+ if (!component->driver->compress_ops ||
34
+ !component->driver->compress_ops->open)
3635 continue;
3736
38
- ret = component->driver->compr_ops->open(cstream);
37
+ ret = component->driver->compress_ops->open(component, cstream);
3938 if (ret < 0) {
4039 dev_err(component->dev,
4140 "Compress ASoC: can't open platform %s: %d\n",
....@@ -55,19 +54,17 @@
5554 {
5655 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
5756 struct snd_soc_component *component;
58
- struct snd_soc_rtdcom_list *rtdcom;
57
+ int i;
5958
60
- for_each_rtdcom(rtd, rtdcom) {
61
- component = rtdcom->component;
62
-
59
+ for_each_rtd_components(rtd, i, component) {
6360 if (component == last)
6461 break;
6562
66
- if (!component->driver->compr_ops ||
67
- !component->driver->compr_ops->free)
63
+ if (!component->driver->compress_ops ||
64
+ !component->driver->compress_ops->free)
6865 continue;
6966
70
- component->driver->compr_ops->free(cstream);
67
+ component->driver->compress_ops->free(component, cstream);
7168 }
7269
7370 return 0;
....@@ -76,49 +73,43 @@
7673 static int soc_compr_open(struct snd_compr_stream *cstream)
7774 {
7875 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
79
- struct snd_soc_component *component;
80
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
76
+ struct snd_soc_component *component = NULL;
77
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
8178 int ret;
8279
83
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
80
+ ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream);
81
+ if (ret < 0)
82
+ goto pm_err;
8483
85
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) {
86
- ret = cpu_dai->driver->cops->startup(cstream, cpu_dai);
87
- if (ret < 0) {
88
- dev_err(cpu_dai->dev,
89
- "Compress ASoC: can't open interface %s: %d\n",
90
- cpu_dai->name, ret);
91
- goto out;
92
- }
93
- }
84
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
85
+
86
+ ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
87
+ if (ret < 0)
88
+ goto out;
9489
9590 ret = soc_compr_components_open(cstream, &component);
9691 if (ret < 0)
9792 goto machine_err;
9893
99
- if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) {
100
- ret = rtd->dai_link->compr_ops->startup(cstream);
101
- if (ret < 0) {
102
- dev_err(rtd->dev,
103
- "Compress ASoC: %s startup failed: %d\n",
104
- rtd->dai_link->name, ret);
105
- goto machine_err;
106
- }
107
- }
94
+ ret = snd_soc_link_compr_startup(cstream);
95
+ if (ret < 0)
96
+ goto machine_err;
10897
10998 snd_soc_runtime_activate(rtd, cstream->direction);
11099
111
- mutex_unlock(&rtd->pcm_mutex);
100
+ mutex_unlock(&rtd->card->pcm_mutex);
112101
113102 return 0;
114103
115104 machine_err:
116105 soc_compr_components_free(cstream, component);
117106
118
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
119
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
107
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream);
120108 out:
121
- mutex_unlock(&rtd->pcm_mutex);
109
+ mutex_unlock(&rtd->card->pcm_mutex);
110
+pm_err:
111
+ snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 1);
112
+
122113 return ret;
123114 }
124115
....@@ -128,7 +119,7 @@
128119 struct snd_pcm_substream *fe_substream =
129120 fe->pcm->streams[cstream->direction].substream;
130121 struct snd_soc_component *component;
131
- struct snd_soc_dai *cpu_dai = fe->cpu_dai;
122
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
132123 struct snd_soc_dpcm *dpcm;
133124 struct snd_soc_dapm_widget_list *list;
134125 int stream;
....@@ -157,7 +148,7 @@
157148 ret = dpcm_be_dai_startup(fe, stream);
158149 if (ret < 0) {
159150 /* clean up all links */
160
- list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
151
+ for_each_dpcm_be(fe, stream, dpcm)
161152 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
162153
163154 dpcm_be_disconnect(fe, stream);
....@@ -165,28 +156,17 @@
165156 goto out;
166157 }
167158
168
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) {
169
- ret = cpu_dai->driver->cops->startup(cstream, cpu_dai);
170
- if (ret < 0) {
171
- dev_err(cpu_dai->dev,
172
- "Compress ASoC: can't open interface %s: %d\n",
173
- cpu_dai->name, ret);
174
- goto out;
175
- }
176
- }
159
+ ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
160
+ if (ret < 0)
161
+ goto out;
177162
178163 ret = soc_compr_components_open(cstream, &component);
179164 if (ret < 0)
180165 goto open_err;
181166
182
- if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) {
183
- ret = fe->dai_link->compr_ops->startup(cstream);
184
- if (ret < 0) {
185
- pr_err("Compress ASoC: %s startup failed: %d\n",
186
- fe->dai_link->name, ret);
187
- goto machine_err;
188
- }
189
- }
167
+ ret = snd_soc_link_compr_startup(cstream);
168
+ if (ret < 0)
169
+ goto machine_err;
190170
191171 dpcm_clear_pending_state(fe, stream);
192172 dpcm_path_put(&list);
....@@ -203,8 +183,7 @@
203183 machine_err:
204184 soc_compr_components_free(cstream, component);
205185 open_err:
206
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
207
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
186
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream);
208187 out:
209188 dpcm_path_put(&list);
210189 be_err:
....@@ -213,43 +192,14 @@
213192 return ret;
214193 }
215194
216
-/*
217
- * Power down the audio subsystem pmdown_time msecs after close is called.
218
- * This is to ensure there are no pops or clicks in between any music tracks
219
- * due to DAPM power cycling.
220
- */
221
-static void close_delayed_work(struct work_struct *work)
222
-{
223
- struct snd_soc_pcm_runtime *rtd =
224
- container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
225
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
226
-
227
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
228
-
229
- dev_dbg(rtd->dev,
230
- "Compress ASoC: pop wq checking: %s status: %s waiting: %s\n",
231
- codec_dai->driver->playback.stream_name,
232
- codec_dai->playback_active ? "active" : "inactive",
233
- rtd->pop_wait ? "yes" : "no");
234
-
235
- /* are we waiting on this codec DAI stream */
236
- if (rtd->pop_wait == 1) {
237
- rtd->pop_wait = 0;
238
- snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
239
- SND_SOC_DAPM_STREAM_STOP);
240
- }
241
-
242
- mutex_unlock(&rtd->pcm_mutex);
243
-}
244
-
245195 static int soc_compr_free(struct snd_compr_stream *cstream)
246196 {
247197 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
248
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
249
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
198
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
199
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
250200 int stream;
251201
252
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
202
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
253203
254204 if (cstream->direction == SND_COMPRESS_PLAYBACK)
255205 stream = SNDRV_PCM_STREAM_PLAYBACK;
....@@ -260,46 +210,31 @@
260210
261211 snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
262212
263
- if (!cpu_dai->active)
213
+ if (!snd_soc_dai_active(cpu_dai))
264214 cpu_dai->rate = 0;
265215
266
- if (!codec_dai->active)
216
+ if (!snd_soc_dai_active(codec_dai))
267217 codec_dai->rate = 0;
268218
269
- if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown)
270
- rtd->dai_link->compr_ops->shutdown(cstream);
219
+ snd_soc_link_compr_shutdown(cstream);
271220
272221 soc_compr_components_free(cstream, NULL);
273222
274
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
275
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
223
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream);
276224
277
- if (cstream->direction == SND_COMPRESS_PLAYBACK) {
278
- if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
279
- snd_soc_dapm_stream_event(rtd,
280
- SNDRV_PCM_STREAM_PLAYBACK,
281
- SND_SOC_DAPM_STREAM_STOP);
282
- } else {
283
- rtd->pop_wait = 1;
284
- queue_delayed_work(system_power_efficient_wq,
285
- &rtd->delayed_work,
286
- msecs_to_jiffies(rtd->pmdown_time));
287
- }
288
- } else {
289
- /* capture streams can be powered down now */
290
- snd_soc_dapm_stream_event(rtd,
291
- SNDRV_PCM_STREAM_CAPTURE,
292
- SND_SOC_DAPM_STREAM_STOP);
293
- }
225
+ snd_soc_dapm_stream_stop(rtd, stream);
294226
295
- mutex_unlock(&rtd->pcm_mutex);
227
+ mutex_unlock(&rtd->card->pcm_mutex);
228
+
229
+ snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0);
230
+
296231 return 0;
297232 }
298233
299234 static int soc_compr_free_fe(struct snd_compr_stream *cstream)
300235 {
301236 struct snd_soc_pcm_runtime *fe = cstream->private_data;
302
- struct snd_soc_dai *cpu_dai = fe->cpu_dai;
237
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
303238 struct snd_soc_dpcm *dpcm;
304239 int stream, ret;
305240
....@@ -321,7 +256,7 @@
321256 ret = dpcm_be_dai_shutdown(fe, stream);
322257
323258 /* mark FE's links ready to prune */
324
- list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
259
+ for_each_dpcm_be(fe, stream, dpcm)
325260 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
326261
327262 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
....@@ -333,46 +268,53 @@
333268
334269 fe->dpcm[stream].runtime = NULL;
335270
336
- if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
337
- fe->dai_link->compr_ops->shutdown(cstream);
271
+ snd_soc_link_compr_shutdown(cstream);
338272
339273 soc_compr_components_free(cstream, NULL);
340274
341
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
342
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
275
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream);
343276
344277 mutex_unlock(&fe->card->mutex);
345278 return 0;
346279 }
347280
348
-static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
281
+static int soc_compr_components_trigger(struct snd_compr_stream *cstream,
282
+ int cmd)
349283 {
350
-
351284 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
352285 struct snd_soc_component *component;
353
- struct snd_soc_rtdcom_list *rtdcom;
354
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
355
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
356
- int ret = 0, __ret;
286
+ int i, ret;
357287
358
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
359
-
360
- for_each_rtdcom(rtd, rtdcom) {
361
- component = rtdcom->component;
362
-
363
- if (!component->driver->compr_ops ||
364
- !component->driver->compr_ops->trigger)
288
+ for_each_rtd_components(rtd, i, component) {
289
+ if (!component->driver->compress_ops ||
290
+ !component->driver->compress_ops->trigger)
365291 continue;
366292
367
- __ret = component->driver->compr_ops->trigger(cstream, cmd);
368
- if (__ret < 0)
369
- ret = __ret;
293
+ ret = component->driver->compress_ops->trigger(
294
+ component, cstream, cmd);
295
+ if (ret < 0)
296
+ return ret;
370297 }
298
+
299
+ return 0;
300
+}
301
+
302
+static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
303
+{
304
+ struct snd_soc_pcm_runtime *rtd = cstream->private_data;
305
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
306
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
307
+ int ret;
308
+
309
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
310
+
311
+ ret = soc_compr_components_trigger(cstream, cmd);
371312 if (ret < 0)
372313 goto out;
373314
374
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger)
375
- cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai);
315
+ ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
316
+ if (ret < 0)
317
+ goto out;
376318
377319 switch (cmd) {
378320 case SNDRV_PCM_TRIGGER_START:
....@@ -384,34 +326,19 @@
384326 }
385327
386328 out:
387
- mutex_unlock(&rtd->pcm_mutex);
329
+ mutex_unlock(&rtd->card->pcm_mutex);
388330 return ret;
389331 }
390332
391333 static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
392334 {
393335 struct snd_soc_pcm_runtime *fe = cstream->private_data;
394
- struct snd_soc_component *component;
395
- struct snd_soc_rtdcom_list *rtdcom;
396
- struct snd_soc_dai *cpu_dai = fe->cpu_dai;
397
- int ret = 0, __ret, stream;
336
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
337
+ int ret, stream;
398338
399339 if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
400
- cmd == SND_COMPR_TRIGGER_DRAIN) {
401
-
402
- for_each_rtdcom(fe, rtdcom) {
403
- component = rtdcom->component;
404
-
405
- if (!component->driver->compr_ops ||
406
- !component->driver->compr_ops->trigger)
407
- continue;
408
-
409
- __ret = component->driver->compr_ops->trigger(cstream, cmd);
410
- if (__ret < 0)
411
- ret = __ret;
412
- }
413
- return ret;
414
- }
340
+ cmd == SND_COMPR_TRIGGER_DRAIN)
341
+ return soc_compr_components_trigger(cstream, cmd);
415342
416343 if (cstream->direction == SND_COMPRESS_PLAYBACK)
417344 stream = SNDRV_PCM_STREAM_PLAYBACK;
....@@ -420,23 +347,11 @@
420347
421348 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
422349
423
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) {
424
- ret = cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai);
425
- if (ret < 0)
426
- goto out;
427
- }
350
+ ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
351
+ if (ret < 0)
352
+ goto out;
428353
429
- for_each_rtdcom(fe, rtdcom) {
430
- component = rtdcom->component;
431
-
432
- if (!component->driver->compr_ops ||
433
- !component->driver->compr_ops->trigger)
434
- continue;
435
-
436
- __ret = component->driver->compr_ops->trigger(cstream, cmd);
437
- if (__ret < 0)
438
- ret = __ret;
439
- }
354
+ ret = soc_compr_components_trigger(cstream, cmd);
440355 if (ret < 0)
441356 goto out;
442357
....@@ -465,16 +380,35 @@
465380 return ret;
466381 }
467382
468
-static int soc_compr_set_params(struct snd_compr_stream *cstream,
469
- struct snd_compr_params *params)
383
+static int soc_compr_components_set_params(struct snd_compr_stream *cstream,
384
+ struct snd_compr_params *params)
470385 {
471386 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
472387 struct snd_soc_component *component;
473
- struct snd_soc_rtdcom_list *rtdcom;
474
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
475
- int ret = 0, __ret;
388
+ int i, ret;
476389
477
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
390
+ for_each_rtd_components(rtd, i, component) {
391
+ if (!component->driver->compress_ops ||
392
+ !component->driver->compress_ops->set_params)
393
+ continue;
394
+
395
+ ret = component->driver->compress_ops->set_params(
396
+ component, cstream, params);
397
+ if (ret < 0)
398
+ return ret;
399
+ }
400
+
401
+ return 0;
402
+}
403
+
404
+static int soc_compr_set_params(struct snd_compr_stream *cstream,
405
+ struct snd_compr_params *params)
406
+{
407
+ struct snd_soc_pcm_runtime *rtd = cstream->private_data;
408
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
409
+ int ret;
410
+
411
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
478412
479413 /*
480414 * First we call set_params for the CPU DAI, then the component
....@@ -483,31 +417,17 @@
483417 * that these callbacks will configure everything for this compress
484418 * path, like configuring a PCM port for a CODEC.
485419 */
486
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) {
487
- ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai);
488
- if (ret < 0)
489
- goto err;
490
- }
491
-
492
- for_each_rtdcom(rtd, rtdcom) {
493
- component = rtdcom->component;
494
-
495
- if (!component->driver->compr_ops ||
496
- !component->driver->compr_ops->set_params)
497
- continue;
498
-
499
- __ret = component->driver->compr_ops->set_params(cstream, params);
500
- if (__ret < 0)
501
- ret = __ret;
502
- }
420
+ ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
503421 if (ret < 0)
504422 goto err;
505423
506
- if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) {
507
- ret = rtd->dai_link->compr_ops->set_params(cstream);
508
- if (ret < 0)
509
- goto err;
510
- }
424
+ ret = soc_compr_components_set_params(cstream, params);
425
+ if (ret < 0)
426
+ goto err;
427
+
428
+ ret = snd_soc_link_compr_set_params(cstream);
429
+ if (ret < 0)
430
+ goto err;
511431
512432 if (cstream->direction == SND_COMPRESS_PLAYBACK)
513433 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
....@@ -518,14 +438,14 @@
518438
519439 /* cancel any delayed stream shutdown that is pending */
520440 rtd->pop_wait = 0;
521
- mutex_unlock(&rtd->pcm_mutex);
441
+ mutex_unlock(&rtd->card->pcm_mutex);
522442
523443 cancel_delayed_work_sync(&rtd->delayed_work);
524444
525
- return ret;
445
+ return 0;
526446
527447 err:
528
- mutex_unlock(&rtd->pcm_mutex);
448
+ mutex_unlock(&rtd->card->pcm_mutex);
529449 return ret;
530450 }
531451
....@@ -535,10 +455,8 @@
535455 struct snd_soc_pcm_runtime *fe = cstream->private_data;
536456 struct snd_pcm_substream *fe_substream =
537457 fe->pcm->streams[cstream->direction].substream;
538
- struct snd_soc_component *component;
539
- struct snd_soc_rtdcom_list *rtdcom;
540
- struct snd_soc_dai *cpu_dai = fe->cpu_dai;
541
- int ret = 0, __ret, stream;
458
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
459
+ int ret, stream;
542460
543461 if (cstream->direction == SND_COMPRESS_PLAYBACK)
544462 stream = SNDRV_PCM_STREAM_PLAYBACK;
....@@ -565,31 +483,17 @@
565483 if (ret < 0)
566484 goto out;
567485
568
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) {
569
- ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai);
570
- if (ret < 0)
571
- goto out;
572
- }
573
-
574
- for_each_rtdcom(fe, rtdcom) {
575
- component = rtdcom->component;
576
-
577
- if (!component->driver->compr_ops ||
578
- !component->driver->compr_ops->set_params)
579
- continue;
580
-
581
- __ret = component->driver->compr_ops->set_params(cstream, params);
582
- if (__ret < 0)
583
- ret = __ret;
584
- }
486
+ ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
585487 if (ret < 0)
586488 goto out;
587489
588
- if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) {
589
- ret = fe->dai_link->compr_ops->set_params(cstream);
590
- if (ret < 0)
591
- goto out;
592
- }
490
+ ret = soc_compr_components_set_params(cstream, params);
491
+ if (ret < 0)
492
+ goto out;
493
+
494
+ ret = snd_soc_link_compr_set_params(cstream);
495
+ if (ret < 0)
496
+ goto out;
593497
594498 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
595499 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
....@@ -605,32 +509,27 @@
605509 {
606510 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
607511 struct snd_soc_component *component;
608
- struct snd_soc_rtdcom_list *rtdcom;
609
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
610
- int ret = 0, __ret;
512
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
513
+ int i, ret = 0;
611514
612
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
515
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
613516
614
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_params) {
615
- ret = cpu_dai->driver->cops->get_params(cstream, params, cpu_dai);
616
- if (ret < 0)
617
- goto err;
618
- }
517
+ ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params);
518
+ if (ret < 0)
519
+ goto err;
619520
620
- for_each_rtdcom(rtd, rtdcom) {
621
- component = rtdcom->component;
622
-
623
- if (!component->driver->compr_ops ||
624
- !component->driver->compr_ops->get_params)
521
+ for_each_rtd_components(rtd, i, component) {
522
+ if (!component->driver->compress_ops ||
523
+ !component->driver->compress_ops->get_params)
625524 continue;
626525
627
- __ret = component->driver->compr_ops->get_params(cstream, params);
628
- if (__ret < 0)
629
- ret = __ret;
526
+ ret = component->driver->compress_ops->get_params(
527
+ component, cstream, params);
528
+ break;
630529 }
631530
632531 err:
633
- mutex_unlock(&rtd->pcm_mutex);
532
+ mutex_unlock(&rtd->card->pcm_mutex);
634533 return ret;
635534 }
636535
....@@ -639,24 +538,21 @@
639538 {
640539 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
641540 struct snd_soc_component *component;
642
- struct snd_soc_rtdcom_list *rtdcom;
643
- int ret = 0, __ret;
541
+ int i, ret = 0;
644542
645
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
543
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
646544
647
- for_each_rtdcom(rtd, rtdcom) {
648
- component = rtdcom->component;
649
-
650
- if (!component->driver->compr_ops ||
651
- !component->driver->compr_ops->get_caps)
545
+ for_each_rtd_components(rtd, i, component) {
546
+ if (!component->driver->compress_ops ||
547
+ !component->driver->compress_ops->get_caps)
652548 continue;
653549
654
- __ret = component->driver->compr_ops->get_caps(cstream, caps);
655
- if (__ret < 0)
656
- ret = __ret;
550
+ ret = component->driver->compress_ops->get_caps(
551
+ component, cstream, caps);
552
+ break;
657553 }
658554
659
- mutex_unlock(&rtd->pcm_mutex);
555
+ mutex_unlock(&rtd->card->pcm_mutex);
660556 return ret;
661557 }
662558
....@@ -665,24 +561,21 @@
665561 {
666562 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
667563 struct snd_soc_component *component;
668
- struct snd_soc_rtdcom_list *rtdcom;
669
- int ret = 0, __ret;
564
+ int i, ret = 0;
670565
671
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
566
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
672567
673
- for_each_rtdcom(rtd, rtdcom) {
674
- component = rtdcom->component;
675
-
676
- if (!component->driver->compr_ops ||
677
- !component->driver->compr_ops->get_codec_caps)
568
+ for_each_rtd_components(rtd, i, component) {
569
+ if (!component->driver->compress_ops ||
570
+ !component->driver->compress_ops->get_codec_caps)
678571 continue;
679572
680
- __ret = component->driver->compr_ops->get_codec_caps(cstream, codec);
681
- if (__ret < 0)
682
- ret = __ret;
573
+ ret = component->driver->compress_ops->get_codec_caps(
574
+ component, cstream, codec);
575
+ break;
683576 }
684577
685
- mutex_unlock(&rtd->pcm_mutex);
578
+ mutex_unlock(&rtd->card->pcm_mutex);
686579 return ret;
687580 }
688581
....@@ -690,32 +583,28 @@
690583 {
691584 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
692585 struct snd_soc_component *component;
693
- struct snd_soc_rtdcom_list *rtdcom;
694
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
695
- int ret = 0, __ret;
586
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
587
+ int i, ret = 0;
696588
697
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
589
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
698590
699
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->ack) {
700
- ret = cpu_dai->driver->cops->ack(cstream, bytes, cpu_dai);
591
+ ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes);
592
+ if (ret < 0)
593
+ goto err;
594
+
595
+ for_each_rtd_components(rtd, i, component) {
596
+ if (!component->driver->compress_ops ||
597
+ !component->driver->compress_ops->ack)
598
+ continue;
599
+
600
+ ret = component->driver->compress_ops->ack(
601
+ component, cstream, bytes);
701602 if (ret < 0)
702603 goto err;
703604 }
704605
705
- for_each_rtdcom(rtd, rtdcom) {
706
- component = rtdcom->component;
707
-
708
- if (!component->driver->compr_ops ||
709
- !component->driver->compr_ops->ack)
710
- continue;
711
-
712
- __ret = component->driver->compr_ops->ack(cstream, bytes);
713
- if (__ret < 0)
714
- ret = __ret;
715
- }
716
-
717606 err:
718
- mutex_unlock(&rtd->pcm_mutex);
607
+ mutex_unlock(&rtd->card->pcm_mutex);
719608 return ret;
720609 }
721610
....@@ -724,28 +613,26 @@
724613 {
725614 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
726615 struct snd_soc_component *component;
727
- struct snd_soc_rtdcom_list *rtdcom;
728
- int ret = 0, __ret;
729
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
616
+ int i, ret = 0;
617
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
730618
731
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
619
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
732620
733
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer)
734
- cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai);
621
+ ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp);
622
+ if (ret < 0)
623
+ goto out;
735624
736
- for_each_rtdcom(rtd, rtdcom) {
737
- component = rtdcom->component;
738
-
739
- if (!component->driver->compr_ops ||
740
- !component->driver->compr_ops->pointer)
625
+ for_each_rtd_components(rtd, i, component) {
626
+ if (!component->driver->compress_ops ||
627
+ !component->driver->compress_ops->pointer)
741628 continue;
742629
743
- __ret = component->driver->compr_ops->pointer(cstream, tstamp);
744
- if (__ret < 0)
745
- ret = __ret;
630
+ ret = component->driver->compress_ops->pointer(
631
+ component, cstream, tstamp);
632
+ break;
746633 }
747
-
748
- mutex_unlock(&rtd->pcm_mutex);
634
+out:
635
+ mutex_unlock(&rtd->card->pcm_mutex);
749636 return ret;
750637 }
751638
....@@ -754,76 +641,48 @@
754641 {
755642 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
756643 struct snd_soc_component *component;
757
- struct snd_soc_rtdcom_list *rtdcom;
758
- int ret = 0;
644
+ int i, ret = 0;
759645
760
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
646
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
761647
762
- for_each_rtdcom(rtd, rtdcom) {
763
- component = rtdcom->component;
764
-
765
- if (!component->driver->compr_ops ||
766
- !component->driver->compr_ops->copy)
648
+ for_each_rtd_components(rtd, i, component) {
649
+ if (!component->driver->compress_ops ||
650
+ !component->driver->compress_ops->copy)
767651 continue;
768652
769
- ret = component->driver->compr_ops->copy(cstream, buf, count);
653
+ ret = component->driver->compress_ops->copy(
654
+ component, cstream, buf, count);
770655 break;
771656 }
772657
773
- mutex_unlock(&rtd->pcm_mutex);
658
+ mutex_unlock(&rtd->card->pcm_mutex);
774659 return ret;
775660 }
776
-
777
-static int sst_compr_set_next_track_param(struct snd_compr_stream *cstream,
778
- union snd_codec_options *codec_options)
779
-{
780
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
781
- struct snd_soc_component *component;
782
- struct snd_soc_rtdcom_list *rtdcom;
783
- int ret = 0;
784
-
785
- for_each_rtdcom(rtd, rtdcom) {
786
- component = rtdcom->component;
787
-
788
- if (component->driver->compr_ops &&
789
- component->driver->compr_ops->set_next_track_param)
790
- ret =
791
- component->driver->compr_ops->set_next_track_param(
792
- cstream, codec_options);
793
- }
794
-
795
- return ret;
796
-}
797
-
798661
799662 static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
800663 struct snd_compr_metadata *metadata)
801664 {
802665 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
803666 struct snd_soc_component *component;
804
- struct snd_soc_rtdcom_list *rtdcom;
805
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
806
- int ret = 0, __ret;
667
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
668
+ int i, ret;
807669
808
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_metadata) {
809
- ret = cpu_dai->driver->cops->set_metadata(cstream, metadata, cpu_dai);
670
+ ret = snd_soc_dai_compr_set_metadata(cpu_dai, cstream, metadata);
671
+ if (ret < 0)
672
+ return ret;
673
+
674
+ for_each_rtd_components(rtd, i, component) {
675
+ if (!component->driver->compress_ops ||
676
+ !component->driver->compress_ops->set_metadata)
677
+ continue;
678
+
679
+ ret = component->driver->compress_ops->set_metadata(
680
+ component, cstream, metadata);
810681 if (ret < 0)
811682 return ret;
812683 }
813684
814
- for_each_rtdcom(rtd, rtdcom) {
815
- component = rtdcom->component;
816
-
817
- if (!component->driver->compr_ops ||
818
- !component->driver->compr_ops->set_metadata)
819
- continue;
820
-
821
- __ret = component->driver->compr_ops->set_metadata(cstream, metadata);
822
- if (__ret < 0)
823
- ret = __ret;
824
- }
825
-
826
- return ret;
685
+ return 0;
827686 }
828687
829688 static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
....@@ -831,29 +690,23 @@
831690 {
832691 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
833692 struct snd_soc_component *component;
834
- struct snd_soc_rtdcom_list *rtdcom;
835
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
836
- int ret = 0, __ret;
693
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
694
+ int i, ret;
837695
838
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_metadata) {
839
- ret = cpu_dai->driver->cops->get_metadata(cstream, metadata, cpu_dai);
840
- if (ret < 0)
841
- return ret;
842
- }
696
+ ret = snd_soc_dai_compr_get_metadata(cpu_dai, cstream, metadata);
697
+ if (ret < 0)
698
+ return ret;
843699
844
- for_each_rtdcom(rtd, rtdcom) {
845
- component = rtdcom->component;
846
-
847
- if (!component->driver->compr_ops ||
848
- !component->driver->compr_ops->get_metadata)
700
+ for_each_rtd_components(rtd, i, component) {
701
+ if (!component->driver->compress_ops ||
702
+ !component->driver->compress_ops->get_metadata)
849703 continue;
850704
851
- __ret = component->driver->compr_ops->get_metadata(cstream, metadata);
852
- if (__ret < 0)
853
- ret = __ret;
705
+ return component->driver->compress_ops->get_metadata(
706
+ component, cstream, metadata);
854707 }
855708
856
- return ret;
709
+ return 0;
857710 }
858711
859712 /* ASoC Compress operations */
....@@ -862,7 +715,6 @@
862715 .free = soc_compr_free,
863716 .set_params = soc_compr_set_params,
864717 .set_metadata = soc_compr_set_metadata,
865
- .set_next_track_param = sst_compr_set_next_track_param,
866718 .get_metadata = soc_compr_get_metadata,
867719 .get_params = soc_compr_get_params,
868720 .trigger = soc_compr_trigger,
....@@ -879,7 +731,6 @@
879731 .set_params = soc_compr_set_params_fe,
880732 .get_params = soc_compr_get_params,
881733 .set_metadata = soc_compr_set_metadata,
882
- .set_next_track_param = sst_compr_set_next_track_param,
883734 .get_metadata = soc_compr_get_metadata,
884735 .trigger = soc_compr_trigger_fe,
885736 .pointer = soc_compr_pointer,
....@@ -899,29 +750,34 @@
899750 int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
900751 {
901752 struct snd_soc_component *component;
902
- struct snd_soc_rtdcom_list *rtdcom;
903
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
904
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
753
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
754
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
905755 struct snd_compr *compr;
906756 struct snd_pcm *be_pcm;
907757 char new_name[64];
908758 int ret = 0, direction = 0;
909759 int playback = 0, capture = 0;
760
+ int i;
910761
911
- if (rtd->num_codecs > 1) {
762
+ if (rtd->num_cpus > 1 ||
763
+ rtd->num_codecs > 1) {
912764 dev_err(rtd->card->dev,
913
- "Compress ASoC: Multicodec not supported\n");
765
+ "Compress ASoC: Multi CPU/Codec not supported\n");
766
+ return -EINVAL;
767
+ }
768
+
769
+ if (!codec_dai) {
770
+ dev_err(rtd->card->dev, "Missing codec\n");
914771 return -EINVAL;
915772 }
916773
917774 /* check client and interface hw capabilities */
918
- if (codec_dai->driver->playback.channels_min)
775
+ if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
776
+ snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
919777 playback = 1;
920
- if (codec_dai->driver->capture.channels_min)
778
+ if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
779
+ snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE))
921780 capture = 1;
922
-
923
- capture = capture && cpu_dai->driver->capture.channels_min;
924
- playback = playback && cpu_dai->driver->playback.channels_min;
925781
926782 /*
927783 * Compress devices are unidirectional so only one of the directions
....@@ -939,16 +795,14 @@
939795 else
940796 direction = SND_COMPRESS_CAPTURE;
941797
942
- compr = kzalloc(sizeof(*compr), GFP_KERNEL);
798
+ compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL);
943799 if (!compr)
944800 return -ENOMEM;
945801
946802 compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops),
947803 GFP_KERNEL);
948
- if (!compr->ops) {
949
- ret = -ENOMEM;
950
- goto compr_err;
951
- }
804
+ if (!compr->ops)
805
+ return -ENOMEM;
952806
953807 if (rtd->dai_link->dynamic) {
954808 snprintf(new_name, sizeof(new_name), "(%s)",
....@@ -961,14 +815,14 @@
961815 dev_err(rtd->card->dev,
962816 "Compress ASoC: can't create compressed for %s: %d\n",
963817 rtd->dai_link->name, ret);
964
- goto compr_err;
818
+ return ret;
965819 }
966820
967821 rtd->pcm = be_pcm;
968822 rtd->fe_compr = 1;
969823 if (rtd->dai_link->dpcm_playback)
970824 be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
971
- else if (rtd->dai_link->dpcm_capture)
825
+ if (rtd->dai_link->dpcm_capture)
972826 be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
973827 memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops));
974828 } else {
....@@ -978,11 +832,9 @@
978832 memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
979833 }
980834
981
- for_each_rtdcom(rtd, rtdcom) {
982
- component = rtdcom->component;
983
-
984
- if (!component->driver->compr_ops ||
985
- !component->driver->compr_ops->copy)
835
+ for_each_rtd_components(rtd, i, component) {
836
+ if (!component->driver->compress_ops ||
837
+ !component->driver->compress_ops->copy)
986838 continue;
987839
988840 compr->ops->copy = soc_compr_copy;
....@@ -993,38 +845,22 @@
993845 ret = snd_compress_new(rtd->card->snd_card, num, direction,
994846 new_name, compr);
995847 if (ret < 0) {
996
- component = rtd->codec_dai->component;
848
+ component = asoc_rtd_to_codec(rtd, 0)->component;
997849 dev_err(component->dev,
998850 "Compress ASoC: can't create compress for codec %s: %d\n",
999851 component->name, ret);
1000
- goto compr_err;
852
+ return ret;
1001853 }
1002854
1003855 /* DAPM dai link stream work */
1004
- INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
856
+ rtd->close_delayed_work_func = snd_soc_close_delayed_work;
1005857
1006858 rtd->compr = compr;
1007859 compr->private_data = rtd;
1008860
1009
- for_each_rtdcom(rtd, rtdcom) {
1010
- component = rtdcom->component;
861
+ dev_dbg(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n",
862
+ codec_dai->name, cpu_dai->name);
1011863
1012
- if (component->driver->pcm_new) {
1013
- ret = component->driver->pcm_new(rtd);
1014
- if (ret < 0) {
1015
- pr_err("asoc: compress pcm constructor failed\n");
1016
- goto compr_err;
1017
- }
1018
- }
1019
- }
1020
-
1021
- dev_info(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n",
1022
- codec_dai->name, cpu_dai->name);
1023
-
1024
- return ret;
1025
-
1026
-compr_err:
1027
- kfree(compr);
1028
- return ret;
864
+ return 0;
1029865 }
1030866 EXPORT_SYMBOL_GPL(snd_soc_new_compress);