.. | .. |
---|
19 | 19 | #include <sound/soc.h> |
---|
20 | 20 | #include <sound/initval.h> |
---|
21 | 21 | #include <sound/soc-dpcm.h> |
---|
| 22 | +#include <sound/soc-link.h> |
---|
| 23 | +#include <linux/pm_runtime.h> |
---|
22 | 24 | |
---|
23 | 25 | static int soc_compr_components_open(struct snd_compr_stream *cstream, |
---|
24 | 26 | struct snd_soc_component **last) |
---|
25 | 27 | { |
---|
26 | 28 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
27 | 29 | struct snd_soc_component *component; |
---|
28 | | - struct snd_soc_rtdcom_list *rtdcom; |
---|
29 | | - int ret; |
---|
| 30 | + int i, ret; |
---|
30 | 31 | |
---|
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) |
---|
36 | 35 | continue; |
---|
37 | 36 | |
---|
38 | | - ret = component->driver->compr_ops->open(cstream); |
---|
| 37 | + ret = component->driver->compress_ops->open(component, cstream); |
---|
39 | 38 | if (ret < 0) { |
---|
40 | 39 | dev_err(component->dev, |
---|
41 | 40 | "Compress ASoC: can't open platform %s: %d\n", |
---|
.. | .. |
---|
55 | 54 | { |
---|
56 | 55 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
57 | 56 | struct snd_soc_component *component; |
---|
58 | | - struct snd_soc_rtdcom_list *rtdcom; |
---|
| 57 | + int i; |
---|
59 | 58 | |
---|
60 | | - for_each_rtdcom(rtd, rtdcom) { |
---|
61 | | - component = rtdcom->component; |
---|
62 | | - |
---|
| 59 | + for_each_rtd_components(rtd, i, component) { |
---|
63 | 60 | if (component == last) |
---|
64 | 61 | break; |
---|
65 | 62 | |
---|
66 | | - if (!component->driver->compr_ops || |
---|
67 | | - !component->driver->compr_ops->free) |
---|
| 63 | + if (!component->driver->compress_ops || |
---|
| 64 | + !component->driver->compress_ops->free) |
---|
68 | 65 | continue; |
---|
69 | 66 | |
---|
70 | | - component->driver->compr_ops->free(cstream); |
---|
| 67 | + component->driver->compress_ops->free(component, cstream); |
---|
71 | 68 | } |
---|
72 | 69 | |
---|
73 | 70 | return 0; |
---|
.. | .. |
---|
76 | 73 | static int soc_compr_open(struct snd_compr_stream *cstream) |
---|
77 | 74 | { |
---|
78 | 75 | 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); |
---|
81 | 78 | int ret; |
---|
82 | 79 | |
---|
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; |
---|
84 | 83 | |
---|
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; |
---|
94 | 89 | |
---|
95 | 90 | ret = soc_compr_components_open(cstream, &component); |
---|
96 | 91 | if (ret < 0) |
---|
97 | 92 | goto machine_err; |
---|
98 | 93 | |
---|
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; |
---|
108 | 97 | |
---|
109 | 98 | snd_soc_runtime_activate(rtd, cstream->direction); |
---|
110 | 99 | |
---|
111 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 100 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
112 | 101 | |
---|
113 | 102 | return 0; |
---|
114 | 103 | |
---|
115 | 104 | machine_err: |
---|
116 | 105 | soc_compr_components_free(cstream, component); |
---|
117 | 106 | |
---|
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); |
---|
120 | 108 | 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 | + |
---|
122 | 113 | return ret; |
---|
123 | 114 | } |
---|
124 | 115 | |
---|
.. | .. |
---|
128 | 119 | struct snd_pcm_substream *fe_substream = |
---|
129 | 120 | fe->pcm->streams[cstream->direction].substream; |
---|
130 | 121 | 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); |
---|
132 | 123 | struct snd_soc_dpcm *dpcm; |
---|
133 | 124 | struct snd_soc_dapm_widget_list *list; |
---|
134 | 125 | int stream; |
---|
.. | .. |
---|
157 | 148 | ret = dpcm_be_dai_startup(fe, stream); |
---|
158 | 149 | if (ret < 0) { |
---|
159 | 150 | /* 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) |
---|
161 | 152 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
---|
162 | 153 | |
---|
163 | 154 | dpcm_be_disconnect(fe, stream); |
---|
.. | .. |
---|
165 | 156 | goto out; |
---|
166 | 157 | } |
---|
167 | 158 | |
---|
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; |
---|
177 | 162 | |
---|
178 | 163 | ret = soc_compr_components_open(cstream, &component); |
---|
179 | 164 | if (ret < 0) |
---|
180 | 165 | goto open_err; |
---|
181 | 166 | |
---|
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; |
---|
190 | 170 | |
---|
191 | 171 | dpcm_clear_pending_state(fe, stream); |
---|
192 | 172 | dpcm_path_put(&list); |
---|
.. | .. |
---|
203 | 183 | machine_err: |
---|
204 | 184 | soc_compr_components_free(cstream, component); |
---|
205 | 185 | 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); |
---|
208 | 187 | out: |
---|
209 | 188 | dpcm_path_put(&list); |
---|
210 | 189 | be_err: |
---|
.. | .. |
---|
213 | 192 | return ret; |
---|
214 | 193 | } |
---|
215 | 194 | |
---|
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 | | - |
---|
245 | 195 | static int soc_compr_free(struct snd_compr_stream *cstream) |
---|
246 | 196 | { |
---|
247 | 197 | 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); |
---|
250 | 200 | int stream; |
---|
251 | 201 | |
---|
252 | | - mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
---|
| 202 | + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
---|
253 | 203 | |
---|
254 | 204 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
---|
255 | 205 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
---|
.. | .. |
---|
260 | 210 | |
---|
261 | 211 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
---|
262 | 212 | |
---|
263 | | - if (!cpu_dai->active) |
---|
| 213 | + if (!snd_soc_dai_active(cpu_dai)) |
---|
264 | 214 | cpu_dai->rate = 0; |
---|
265 | 215 | |
---|
266 | | - if (!codec_dai->active) |
---|
| 216 | + if (!snd_soc_dai_active(codec_dai)) |
---|
267 | 217 | codec_dai->rate = 0; |
---|
268 | 218 | |
---|
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); |
---|
271 | 220 | |
---|
272 | 221 | soc_compr_components_free(cstream, NULL); |
---|
273 | 222 | |
---|
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); |
---|
276 | 224 | |
---|
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); |
---|
294 | 226 | |
---|
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 | + |
---|
296 | 231 | return 0; |
---|
297 | 232 | } |
---|
298 | 233 | |
---|
299 | 234 | static int soc_compr_free_fe(struct snd_compr_stream *cstream) |
---|
300 | 235 | { |
---|
301 | 236 | 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); |
---|
303 | 238 | struct snd_soc_dpcm *dpcm; |
---|
304 | 239 | int stream, ret; |
---|
305 | 240 | |
---|
.. | .. |
---|
321 | 256 | ret = dpcm_be_dai_shutdown(fe, stream); |
---|
322 | 257 | |
---|
323 | 258 | /* 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) |
---|
325 | 260 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
---|
326 | 261 | |
---|
327 | 262 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); |
---|
.. | .. |
---|
333 | 268 | |
---|
334 | 269 | fe->dpcm[stream].runtime = NULL; |
---|
335 | 270 | |
---|
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); |
---|
338 | 272 | |
---|
339 | 273 | soc_compr_components_free(cstream, NULL); |
---|
340 | 274 | |
---|
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); |
---|
343 | 276 | |
---|
344 | 277 | mutex_unlock(&fe->card->mutex); |
---|
345 | 278 | return 0; |
---|
346 | 279 | } |
---|
347 | 280 | |
---|
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) |
---|
349 | 283 | { |
---|
350 | | - |
---|
351 | 284 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
352 | 285 | 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; |
---|
357 | 287 | |
---|
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) |
---|
365 | 291 | continue; |
---|
366 | 292 | |
---|
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; |
---|
370 | 297 | } |
---|
| 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); |
---|
371 | 312 | if (ret < 0) |
---|
372 | 313 | goto out; |
---|
373 | 314 | |
---|
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; |
---|
376 | 318 | |
---|
377 | 319 | switch (cmd) { |
---|
378 | 320 | case SNDRV_PCM_TRIGGER_START: |
---|
.. | .. |
---|
384 | 326 | } |
---|
385 | 327 | |
---|
386 | 328 | out: |
---|
387 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 329 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
388 | 330 | return ret; |
---|
389 | 331 | } |
---|
390 | 332 | |
---|
391 | 333 | static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) |
---|
392 | 334 | { |
---|
393 | 335 | 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; |
---|
398 | 338 | |
---|
399 | 339 | 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); |
---|
415 | 342 | |
---|
416 | 343 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
---|
417 | 344 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
---|
.. | .. |
---|
420 | 347 | |
---|
421 | 348 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
---|
422 | 349 | |
---|
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; |
---|
428 | 353 | |
---|
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); |
---|
440 | 355 | if (ret < 0) |
---|
441 | 356 | goto out; |
---|
442 | 357 | |
---|
.. | .. |
---|
465 | 380 | return ret; |
---|
466 | 381 | } |
---|
467 | 382 | |
---|
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) |
---|
470 | 385 | { |
---|
471 | 386 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
472 | 387 | 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; |
---|
476 | 389 | |
---|
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); |
---|
478 | 412 | |
---|
479 | 413 | /* |
---|
480 | 414 | * First we call set_params for the CPU DAI, then the component |
---|
.. | .. |
---|
483 | 417 | * that these callbacks will configure everything for this compress |
---|
484 | 418 | * path, like configuring a PCM port for a CODEC. |
---|
485 | 419 | */ |
---|
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); |
---|
503 | 421 | if (ret < 0) |
---|
504 | 422 | goto err; |
---|
505 | 423 | |
---|
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; |
---|
511 | 431 | |
---|
512 | 432 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
---|
513 | 433 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
---|
.. | .. |
---|
518 | 438 | |
---|
519 | 439 | /* cancel any delayed stream shutdown that is pending */ |
---|
520 | 440 | rtd->pop_wait = 0; |
---|
521 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 441 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
522 | 442 | |
---|
523 | 443 | cancel_delayed_work_sync(&rtd->delayed_work); |
---|
524 | 444 | |
---|
525 | | - return ret; |
---|
| 445 | + return 0; |
---|
526 | 446 | |
---|
527 | 447 | err: |
---|
528 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 448 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
529 | 449 | return ret; |
---|
530 | 450 | } |
---|
531 | 451 | |
---|
.. | .. |
---|
535 | 455 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
---|
536 | 456 | struct snd_pcm_substream *fe_substream = |
---|
537 | 457 | 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; |
---|
542 | 460 | |
---|
543 | 461 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
---|
544 | 462 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
---|
.. | .. |
---|
565 | 483 | if (ret < 0) |
---|
566 | 484 | goto out; |
---|
567 | 485 | |
---|
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); |
---|
585 | 487 | if (ret < 0) |
---|
586 | 488 | goto out; |
---|
587 | 489 | |
---|
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; |
---|
593 | 497 | |
---|
594 | 498 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); |
---|
595 | 499 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
---|
.. | .. |
---|
605 | 509 | { |
---|
606 | 510 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
607 | 511 | 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; |
---|
611 | 514 | |
---|
612 | | - mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
---|
| 515 | + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
---|
613 | 516 | |
---|
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; |
---|
619 | 520 | |
---|
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) |
---|
625 | 524 | continue; |
---|
626 | 525 | |
---|
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; |
---|
630 | 529 | } |
---|
631 | 530 | |
---|
632 | 531 | err: |
---|
633 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 532 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
634 | 533 | return ret; |
---|
635 | 534 | } |
---|
636 | 535 | |
---|
.. | .. |
---|
639 | 538 | { |
---|
640 | 539 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
641 | 540 | struct snd_soc_component *component; |
---|
642 | | - struct snd_soc_rtdcom_list *rtdcom; |
---|
643 | | - int ret = 0, __ret; |
---|
| 541 | + int i, ret = 0; |
---|
644 | 542 | |
---|
645 | | - mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
---|
| 543 | + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
---|
646 | 544 | |
---|
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) |
---|
652 | 548 | continue; |
---|
653 | 549 | |
---|
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; |
---|
657 | 553 | } |
---|
658 | 554 | |
---|
659 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 555 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
660 | 556 | return ret; |
---|
661 | 557 | } |
---|
662 | 558 | |
---|
.. | .. |
---|
665 | 561 | { |
---|
666 | 562 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
667 | 563 | struct snd_soc_component *component; |
---|
668 | | - struct snd_soc_rtdcom_list *rtdcom; |
---|
669 | | - int ret = 0, __ret; |
---|
| 564 | + int i, ret = 0; |
---|
670 | 565 | |
---|
671 | | - mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
---|
| 566 | + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
---|
672 | 567 | |
---|
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) |
---|
678 | 571 | continue; |
---|
679 | 572 | |
---|
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; |
---|
683 | 576 | } |
---|
684 | 577 | |
---|
685 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 578 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
686 | 579 | return ret; |
---|
687 | 580 | } |
---|
688 | 581 | |
---|
.. | .. |
---|
690 | 583 | { |
---|
691 | 584 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
692 | 585 | 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; |
---|
696 | 588 | |
---|
697 | | - mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
---|
| 589 | + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
---|
698 | 590 | |
---|
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); |
---|
701 | 602 | if (ret < 0) |
---|
702 | 603 | goto err; |
---|
703 | 604 | } |
---|
704 | 605 | |
---|
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 | | - |
---|
717 | 606 | err: |
---|
718 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 607 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
719 | 608 | return ret; |
---|
720 | 609 | } |
---|
721 | 610 | |
---|
.. | .. |
---|
724 | 613 | { |
---|
725 | 614 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
726 | 615 | 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); |
---|
730 | 618 | |
---|
731 | | - mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
---|
| 619 | + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
---|
732 | 620 | |
---|
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; |
---|
735 | 624 | |
---|
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) |
---|
741 | 628 | continue; |
---|
742 | 629 | |
---|
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; |
---|
746 | 633 | } |
---|
747 | | - |
---|
748 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 634 | +out: |
---|
| 635 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
749 | 636 | return ret; |
---|
750 | 637 | } |
---|
751 | 638 | |
---|
.. | .. |
---|
754 | 641 | { |
---|
755 | 642 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
756 | 643 | struct snd_soc_component *component; |
---|
757 | | - struct snd_soc_rtdcom_list *rtdcom; |
---|
758 | | - int ret = 0; |
---|
| 644 | + int i, ret = 0; |
---|
759 | 645 | |
---|
760 | | - mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
---|
| 646 | + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
---|
761 | 647 | |
---|
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) |
---|
767 | 651 | continue; |
---|
768 | 652 | |
---|
769 | | - ret = component->driver->compr_ops->copy(cstream, buf, count); |
---|
| 653 | + ret = component->driver->compress_ops->copy( |
---|
| 654 | + component, cstream, buf, count); |
---|
770 | 655 | break; |
---|
771 | 656 | } |
---|
772 | 657 | |
---|
773 | | - mutex_unlock(&rtd->pcm_mutex); |
---|
| 658 | + mutex_unlock(&rtd->card->pcm_mutex); |
---|
774 | 659 | return ret; |
---|
775 | 660 | } |
---|
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 | | - |
---|
798 | 661 | |
---|
799 | 662 | static int soc_compr_set_metadata(struct snd_compr_stream *cstream, |
---|
800 | 663 | struct snd_compr_metadata *metadata) |
---|
801 | 664 | { |
---|
802 | 665 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
803 | 666 | 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; |
---|
807 | 669 | |
---|
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); |
---|
810 | 681 | if (ret < 0) |
---|
811 | 682 | return ret; |
---|
812 | 683 | } |
---|
813 | 684 | |
---|
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; |
---|
827 | 686 | } |
---|
828 | 687 | |
---|
829 | 688 | static int soc_compr_get_metadata(struct snd_compr_stream *cstream, |
---|
.. | .. |
---|
831 | 690 | { |
---|
832 | 691 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
---|
833 | 692 | 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; |
---|
837 | 695 | |
---|
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; |
---|
843 | 699 | |
---|
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) |
---|
849 | 703 | continue; |
---|
850 | 704 | |
---|
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); |
---|
854 | 707 | } |
---|
855 | 708 | |
---|
856 | | - return ret; |
---|
| 709 | + return 0; |
---|
857 | 710 | } |
---|
858 | 711 | |
---|
859 | 712 | /* ASoC Compress operations */ |
---|
.. | .. |
---|
862 | 715 | .free = soc_compr_free, |
---|
863 | 716 | .set_params = soc_compr_set_params, |
---|
864 | 717 | .set_metadata = soc_compr_set_metadata, |
---|
865 | | - .set_next_track_param = sst_compr_set_next_track_param, |
---|
866 | 718 | .get_metadata = soc_compr_get_metadata, |
---|
867 | 719 | .get_params = soc_compr_get_params, |
---|
868 | 720 | .trigger = soc_compr_trigger, |
---|
.. | .. |
---|
879 | 731 | .set_params = soc_compr_set_params_fe, |
---|
880 | 732 | .get_params = soc_compr_get_params, |
---|
881 | 733 | .set_metadata = soc_compr_set_metadata, |
---|
882 | | - .set_next_track_param = sst_compr_set_next_track_param, |
---|
883 | 734 | .get_metadata = soc_compr_get_metadata, |
---|
884 | 735 | .trigger = soc_compr_trigger_fe, |
---|
885 | 736 | .pointer = soc_compr_pointer, |
---|
.. | .. |
---|
899 | 750 | int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) |
---|
900 | 751 | { |
---|
901 | 752 | 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); |
---|
905 | 755 | struct snd_compr *compr; |
---|
906 | 756 | struct snd_pcm *be_pcm; |
---|
907 | 757 | char new_name[64]; |
---|
908 | 758 | int ret = 0, direction = 0; |
---|
909 | 759 | int playback = 0, capture = 0; |
---|
| 760 | + int i; |
---|
910 | 761 | |
---|
911 | | - if (rtd->num_codecs > 1) { |
---|
| 762 | + if (rtd->num_cpus > 1 || |
---|
| 763 | + rtd->num_codecs > 1) { |
---|
912 | 764 | 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"); |
---|
914 | 771 | return -EINVAL; |
---|
915 | 772 | } |
---|
916 | 773 | |
---|
917 | 774 | /* 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)) |
---|
919 | 777 | 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)) |
---|
921 | 780 | capture = 1; |
---|
922 | | - |
---|
923 | | - capture = capture && cpu_dai->driver->capture.channels_min; |
---|
924 | | - playback = playback && cpu_dai->driver->playback.channels_min; |
---|
925 | 781 | |
---|
926 | 782 | /* |
---|
927 | 783 | * Compress devices are unidirectional so only one of the directions |
---|
.. | .. |
---|
939 | 795 | else |
---|
940 | 796 | direction = SND_COMPRESS_CAPTURE; |
---|
941 | 797 | |
---|
942 | | - compr = kzalloc(sizeof(*compr), GFP_KERNEL); |
---|
| 798 | + compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL); |
---|
943 | 799 | if (!compr) |
---|
944 | 800 | return -ENOMEM; |
---|
945 | 801 | |
---|
946 | 802 | compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), |
---|
947 | 803 | GFP_KERNEL); |
---|
948 | | - if (!compr->ops) { |
---|
949 | | - ret = -ENOMEM; |
---|
950 | | - goto compr_err; |
---|
951 | | - } |
---|
| 804 | + if (!compr->ops) |
---|
| 805 | + return -ENOMEM; |
---|
952 | 806 | |
---|
953 | 807 | if (rtd->dai_link->dynamic) { |
---|
954 | 808 | snprintf(new_name, sizeof(new_name), "(%s)", |
---|
.. | .. |
---|
961 | 815 | dev_err(rtd->card->dev, |
---|
962 | 816 | "Compress ASoC: can't create compressed for %s: %d\n", |
---|
963 | 817 | rtd->dai_link->name, ret); |
---|
964 | | - goto compr_err; |
---|
| 818 | + return ret; |
---|
965 | 819 | } |
---|
966 | 820 | |
---|
967 | 821 | rtd->pcm = be_pcm; |
---|
968 | 822 | rtd->fe_compr = 1; |
---|
969 | 823 | if (rtd->dai_link->dpcm_playback) |
---|
970 | 824 | 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) |
---|
972 | 826 | be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; |
---|
973 | 827 | memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops)); |
---|
974 | 828 | } else { |
---|
.. | .. |
---|
978 | 832 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); |
---|
979 | 833 | } |
---|
980 | 834 | |
---|
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) |
---|
986 | 838 | continue; |
---|
987 | 839 | |
---|
988 | 840 | compr->ops->copy = soc_compr_copy; |
---|
.. | .. |
---|
993 | 845 | ret = snd_compress_new(rtd->card->snd_card, num, direction, |
---|
994 | 846 | new_name, compr); |
---|
995 | 847 | if (ret < 0) { |
---|
996 | | - component = rtd->codec_dai->component; |
---|
| 848 | + component = asoc_rtd_to_codec(rtd, 0)->component; |
---|
997 | 849 | dev_err(component->dev, |
---|
998 | 850 | "Compress ASoC: can't create compress for codec %s: %d\n", |
---|
999 | 851 | component->name, ret); |
---|
1000 | | - goto compr_err; |
---|
| 852 | + return ret; |
---|
1001 | 853 | } |
---|
1002 | 854 | |
---|
1003 | 855 | /* 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; |
---|
1005 | 857 | |
---|
1006 | 858 | rtd->compr = compr; |
---|
1007 | 859 | compr->private_data = rtd; |
---|
1008 | 860 | |
---|
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); |
---|
1011 | 863 | |
---|
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; |
---|
1029 | 865 | } |
---|
1030 | 866 | EXPORT_SYMBOL_GPL(snd_soc_new_compress); |
---|