hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/soc/soc-core.c
....@@ -31,6 +31,7 @@
3131 #include <linux/of.h>
3232 #include <linux/of_graph.h>
3333 #include <linux/dmi.h>
34
+#include <linux/acpi.h>
3435 #include <sound/core.h>
3536 #include <sound/jack.h>
3637 #include <sound/pcm.h>
....@@ -38,20 +39,25 @@
3839 #include <sound/soc.h>
3940 #include <sound/soc-dpcm.h>
4041 #include <sound/soc-topology.h>
42
+#include <sound/soc-link.h>
4143 #include <sound/initval.h>
4244
4345 #define CREATE_TRACE_POINTS
4446 #include <trace/events/asoc.h>
4547
46
-#define NAME_SIZE 32
47
-
48
-#ifdef CONFIG_DEBUG_FS
49
-struct dentry *snd_soc_debugfs_root;
50
-EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
51
-#endif
52
-
5348 static DEFINE_MUTEX(client_mutex);
5449 static LIST_HEAD(component_list);
50
+static LIST_HEAD(unbind_card_list);
51
+
52
+#define for_each_component(component) \
53
+ list_for_each_entry(component, &component_list, list)
54
+
55
+/*
56
+ * This is used if driver don't need to have CPU/Codec/Platform
57
+ * dai_link. see soc.h
58
+ */
59
+struct snd_soc_dai_link_component null_dailink_component[0];
60
+EXPORT_SYMBOL_GPL(null_dailink_component);
5561
5662 /*
5763 * This is a timeout to do a DAPM powerdown after a stream is closed().
....@@ -61,20 +67,6 @@
6167 static int pmdown_time = 5000;
6268 module_param(pmdown_time, int, 0);
6369 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
64
-
65
-/* If a DMI filed contain strings in this blacklist (e.g.
66
- * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
67
- * as invalid and dropped when setting the card long name from DMI info.
68
- */
69
-static const char * const dmi_blacklist[] = {
70
- "To be filled by OEM",
71
- "TBD by OEM",
72
- "Default String",
73
- "Board Manufacturer",
74
- "Board Vendor Name",
75
- "Board Product Name",
76
- NULL, /* terminator */
77
-};
7870
7971 static ssize_t pmdown_time_show(struct device *dev,
8072 struct device_attribute *attr, char *buf)
....@@ -111,6 +103,9 @@
111103 struct device *dev = kobj_to_dev(kobj);
112104 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
113105
106
+ if (!rtd)
107
+ return 0;
108
+
114109 if (attr == &dev_attr_pmdown_time.attr)
115110 return attr->mode; /* always visible */
116111 return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */
....@@ -133,6 +128,9 @@
133128 };
134129
135130 #ifdef CONFIG_DEBUG_FS
131
+struct dentry *snd_soc_debugfs_root;
132
+EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
133
+
136134 static void soc_init_component_debugfs(struct snd_soc_component *component)
137135 {
138136 if (!component->card->debugfs_card_root)
....@@ -153,19 +151,16 @@
153151 component->card->debugfs_card_root);
154152 }
155153
156
- if (!component->debugfs_root) {
157
- dev_warn(component->dev,
158
- "ASoC: Failed to create component debugfs directory\n");
159
- return;
160
- }
161
-
162154 snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
163155 component->debugfs_root);
164156 }
165157
166158 static void soc_cleanup_component_debugfs(struct snd_soc_component *component)
167159 {
160
+ if (!component->debugfs_root)
161
+ return;
168162 debugfs_remove_recursive(component->debugfs_root);
163
+ component->debugfs_root = NULL;
169164 }
170165
171166 static int dai_list_show(struct seq_file *m, void *v)
....@@ -175,8 +170,8 @@
175170
176171 mutex_lock(&client_mutex);
177172
178
- list_for_each_entry(component, &component_list, list)
179
- list_for_each_entry(dai, &component->dai_list, list)
173
+ for_each_component(component)
174
+ for_each_component_dais(component, dai)
180175 seq_printf(m, "%s\n", dai->name);
181176
182177 mutex_unlock(&client_mutex);
....@@ -191,7 +186,7 @@
191186
192187 mutex_lock(&client_mutex);
193188
194
- list_for_each_entry(component, &component_list, list)
189
+ for_each_component(component)
195190 seq_printf(m, "%s\n", component->name);
196191
197192 mutex_unlock(&client_mutex);
....@@ -202,46 +197,30 @@
202197
203198 static void soc_init_card_debugfs(struct snd_soc_card *card)
204199 {
205
- if (!snd_soc_debugfs_root)
206
- return;
207
-
208200 card->debugfs_card_root = debugfs_create_dir(card->name,
209201 snd_soc_debugfs_root);
210
- if (!card->debugfs_card_root) {
211
- dev_warn(card->dev,
212
- "ASoC: Failed to create card debugfs directory\n");
213
- return;
214
- }
215202
216
- card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
217
- card->debugfs_card_root,
218
- &card->pop_time);
219
- if (!card->debugfs_pop_time)
220
- dev_warn(card->dev,
221
- "ASoC: Failed to create pop time debugfs file\n");
203
+ debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root,
204
+ &card->pop_time);
205
+
206
+ snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
222207 }
223208
224209 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
225210 {
226211 debugfs_remove_recursive(card->debugfs_card_root);
212
+ card->debugfs_card_root = NULL;
227213 }
228214
229215 static void snd_soc_debugfs_init(void)
230216 {
231217 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
232
- if (IS_ERR_OR_NULL(snd_soc_debugfs_root)) {
233
- pr_warn("ASoC: Failed to create debugfs directory\n");
234
- snd_soc_debugfs_root = NULL;
235
- return;
236
- }
237218
238
- if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
239
- &dai_list_fops))
240
- pr_warn("ASoC: Failed to create DAI list debugfs file\n");
219
+ debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
220
+ &dai_list_fops);
241221
242
- if (!debugfs_create_file("components", 0444, snd_soc_debugfs_root, NULL,
243
- &component_list_fops))
244
- pr_warn("ASoC: Failed to create component list debugfs file\n");
222
+ debugfs_create_file("components", 0444, snd_soc_debugfs_root, NULL,
223
+ &component_list_fops);
245224 }
246225
247226 static void snd_soc_debugfs_exit(void)
....@@ -279,154 +258,266 @@
279258
280259 #endif
281260
282
-static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
283
- struct snd_soc_component *component)
261
+static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
262
+ struct snd_soc_component *component)
284263 {
285
- struct snd_soc_rtdcom_list *rtdcom;
286
- struct snd_soc_rtdcom_list *new_rtdcom;
264
+ struct snd_soc_component *comp;
265
+ int i;
287266
288
- for_each_rtdcom(rtd, rtdcom) {
267
+ for_each_rtd_components(rtd, i, comp) {
289268 /* already connected */
290
- if (rtdcom->component == component)
269
+ if (comp == component)
291270 return 0;
292271 }
293272
294
- new_rtdcom = kmalloc(sizeof(*new_rtdcom), GFP_KERNEL);
295
- if (!new_rtdcom)
296
- return -ENOMEM;
297
-
298
- new_rtdcom->component = component;
299
- INIT_LIST_HEAD(&new_rtdcom->list);
300
-
301
- list_add_tail(&new_rtdcom->list, &rtd->component_list);
273
+ /* see for_each_rtd_components */
274
+ rtd->components[rtd->num_components] = component;
275
+ rtd->num_components++;
302276
303277 return 0;
304
-}
305
-
306
-static void snd_soc_rtdcom_del_all(struct snd_soc_pcm_runtime *rtd)
307
-{
308
- struct snd_soc_rtdcom_list *rtdcom1, *rtdcom2;
309
-
310
- for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
311
- kfree(rtdcom1);
312
-
313
- INIT_LIST_HEAD(&rtd->component_list);
314278 }
315279
316280 struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
317281 const char *driver_name)
318282 {
319
- struct snd_soc_rtdcom_list *rtdcom;
283
+ struct snd_soc_component *component;
284
+ int i;
320285
321286 if (!driver_name)
322287 return NULL;
323288
324
- for_each_rtdcom(rtd, rtdcom) {
325
- const char *component_name = rtdcom->component->driver->name;
289
+ /*
290
+ * NOTE
291
+ *
292
+ * snd_soc_rtdcom_lookup() will find component from rtd by using
293
+ * specified driver name.
294
+ * But, if many components which have same driver name are connected
295
+ * to 1 rtd, this function will return 1st found component.
296
+ */
297
+ for_each_rtd_components(rtd, i, component) {
298
+ const char *component_name = component->driver->name;
326299
327300 if (!component_name)
328301 continue;
329302
330303 if ((component_name == driver_name) ||
331304 strcmp(component_name, driver_name) == 0)
332
- return rtdcom->component;
305
+ return component;
333306 }
334307
335308 return NULL;
336309 }
337310 EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup);
338311
339
-struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
340
- const char *dai_link, int stream)
312
+struct snd_soc_component
313
+*snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name)
314
+{
315
+ struct snd_soc_component *component;
316
+ struct snd_soc_component *found_component;
317
+
318
+ found_component = NULL;
319
+ for_each_component(component) {
320
+ if ((dev == component->dev) &&
321
+ (!driver_name ||
322
+ (driver_name == component->driver->name) ||
323
+ (strcmp(component->driver->name, driver_name) == 0))) {
324
+ found_component = component;
325
+ break;
326
+ }
327
+ }
328
+
329
+ return found_component;
330
+}
331
+EXPORT_SYMBOL_GPL(snd_soc_lookup_component_nolocked);
332
+
333
+struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
334
+ const char *driver_name)
335
+{
336
+ struct snd_soc_component *component;
337
+
338
+ mutex_lock(&client_mutex);
339
+ component = snd_soc_lookup_component_nolocked(dev, driver_name);
340
+ mutex_unlock(&client_mutex);
341
+
342
+ return component;
343
+}
344
+EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
345
+
346
+struct snd_soc_pcm_runtime
347
+*snd_soc_get_pcm_runtime(struct snd_soc_card *card,
348
+ struct snd_soc_dai_link *dai_link)
341349 {
342350 struct snd_soc_pcm_runtime *rtd;
343351
344
- list_for_each_entry(rtd, &card->rtd_list, list) {
345
- if (rtd->dai_link->no_pcm &&
346
- !strcmp(rtd->dai_link->name, dai_link))
347
- return rtd->pcm->streams[stream].substream;
352
+ for_each_card_rtds(card, rtd) {
353
+ if (rtd->dai_link == dai_link)
354
+ return rtd;
348355 }
349
- dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
356
+ dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link->name);
350357 return NULL;
351358 }
352
-EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
359
+EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
353360
354
-static const struct snd_soc_ops null_snd_soc_ops;
361
+/*
362
+ * Power down the audio subsystem pmdown_time msecs after close is called.
363
+ * This is to ensure there are no pops or clicks in between any music tracks
364
+ * due to DAPM power cycling.
365
+ */
366
+void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
367
+{
368
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
369
+ int playback = SNDRV_PCM_STREAM_PLAYBACK;
370
+
371
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
372
+
373
+ dev_dbg(rtd->dev,
374
+ "ASoC: pop wq checking: %s status: %s waiting: %s\n",
375
+ codec_dai->driver->playback.stream_name,
376
+ snd_soc_dai_stream_active(codec_dai, playback) ?
377
+ "active" : "inactive",
378
+ rtd->pop_wait ? "yes" : "no");
379
+
380
+ /* are we waiting on this codec DAI stream */
381
+ if (rtd->pop_wait == 1) {
382
+ rtd->pop_wait = 0;
383
+ snd_soc_dapm_stream_event(rtd, playback,
384
+ SND_SOC_DAPM_STREAM_STOP);
385
+ }
386
+
387
+ mutex_unlock(&rtd->card->pcm_mutex);
388
+}
389
+EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work);
390
+
391
+static void soc_release_rtd_dev(struct device *dev)
392
+{
393
+ /* "dev" means "rtd->dev" */
394
+ kfree(dev);
395
+}
396
+
397
+static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
398
+{
399
+ if (!rtd)
400
+ return;
401
+
402
+ list_del(&rtd->list);
403
+
404
+ if (delayed_work_pending(&rtd->delayed_work))
405
+ flush_delayed_work(&rtd->delayed_work);
406
+ snd_soc_pcm_component_free(rtd);
407
+
408
+ /*
409
+ * we don't need to call kfree() for rtd->dev
410
+ * see
411
+ * soc_release_rtd_dev()
412
+ *
413
+ * We don't need rtd->dev NULL check, because
414
+ * it is alloced *before* rtd.
415
+ * see
416
+ * soc_new_pcm_runtime()
417
+ */
418
+ device_unregister(rtd->dev);
419
+}
420
+
421
+static void close_delayed_work(struct work_struct *work) {
422
+ struct snd_soc_pcm_runtime *rtd =
423
+ container_of(work, struct snd_soc_pcm_runtime,
424
+ delayed_work.work);
425
+
426
+ if (rtd->close_delayed_work_func)
427
+ rtd->close_delayed_work_func(rtd);
428
+}
355429
356430 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
357431 struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
358432 {
359433 struct snd_soc_pcm_runtime *rtd;
434
+ struct snd_soc_component *component;
435
+ struct device *dev;
436
+ int ret;
437
+ int stream;
360438
361
- rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
362
- if (!rtd)
439
+ /*
440
+ * for rtd->dev
441
+ */
442
+ dev = kzalloc(sizeof(struct device), GFP_KERNEL);
443
+ if (!dev)
363444 return NULL;
364445
365
- INIT_LIST_HEAD(&rtd->component_list);
366
- rtd->card = card;
367
- rtd->dai_link = dai_link;
368
- if (!rtd->dai_link->ops)
369
- rtd->dai_link->ops = &null_snd_soc_ops;
446
+ dev->parent = card->dev;
447
+ dev->release = soc_release_rtd_dev;
370448
371
- rtd->codec_dais = kcalloc(dai_link->num_codecs,
449
+ dev_set_name(dev, "%s", dai_link->name);
450
+
451
+ ret = device_register(dev);
452
+ if (ret < 0) {
453
+ put_device(dev); /* soc_release_rtd_dev */
454
+ return NULL;
455
+ }
456
+
457
+ /*
458
+ * for rtd
459
+ */
460
+ rtd = devm_kzalloc(dev,
461
+ sizeof(*rtd) +
462
+ sizeof(*component) * (dai_link->num_cpus +
463
+ dai_link->num_codecs +
464
+ dai_link->num_platforms),
465
+ GFP_KERNEL);
466
+ if (!rtd)
467
+ goto free_rtd;
468
+
469
+ rtd->dev = dev;
470
+ INIT_LIST_HEAD(&rtd->list);
471
+ for_each_pcm_streams(stream) {
472
+ INIT_LIST_HEAD(&rtd->dpcm[stream].be_clients);
473
+ INIT_LIST_HEAD(&rtd->dpcm[stream].fe_clients);
474
+ }
475
+ dev_set_drvdata(dev, rtd);
476
+ INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
477
+
478
+ /*
479
+ * for rtd->dais
480
+ */
481
+ rtd->dais = devm_kcalloc(dev, dai_link->num_cpus + dai_link->num_codecs,
372482 sizeof(struct snd_soc_dai *),
373483 GFP_KERNEL);
374
- if (!rtd->codec_dais) {
375
- kfree(rtd);
376
- return NULL;
377
- }
484
+ if (!rtd->dais)
485
+ goto free_rtd;
486
+
487
+ /*
488
+ * dais = [][][][][][][][][][][][][][][][][][]
489
+ * ^cpu_dais ^codec_dais
490
+ * |--- num_cpus ---|--- num_codecs --|
491
+ * see
492
+ * asoc_rtd_to_cpu()
493
+ * asoc_rtd_to_codec()
494
+ */
495
+ rtd->num_cpus = dai_link->num_cpus;
496
+ rtd->num_codecs = dai_link->num_codecs;
497
+ rtd->card = card;
498
+ rtd->dai_link = dai_link;
499
+ rtd->num = card->num_rtd++;
500
+
501
+ /* see for_each_card_rtds */
502
+ list_add_tail(&rtd->list, &card->rtd_list);
503
+
504
+ ret = device_add_groups(dev, soc_dev_attr_groups);
505
+ if (ret < 0)
506
+ goto free_rtd;
378507
379508 return rtd;
509
+
510
+free_rtd:
511
+ soc_free_pcm_runtime(rtd);
512
+ return NULL;
380513 }
381514
382
-static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
383
-{
384
- kfree(rtd->codec_dais);
385
- snd_soc_rtdcom_del_all(rtd);
386
- kfree(rtd);
387
-}
388
-
389
-static void soc_add_pcm_runtime(struct snd_soc_card *card,
390
- struct snd_soc_pcm_runtime *rtd)
391
-{
392
- list_add_tail(&rtd->list, &card->rtd_list);
393
- rtd->num = card->num_rtd;
394
- card->num_rtd++;
395
-}
396
-
397
-static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
398
-{
399
- struct snd_soc_pcm_runtime *rtd, *_rtd;
400
-
401
- list_for_each_entry_safe(rtd, _rtd, &card->rtd_list, list) {
402
- list_del(&rtd->list);
403
- soc_free_pcm_runtime(rtd);
404
- }
405
-
406
- card->num_rtd = 0;
407
-}
408
-
409
-struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
410
- const char *dai_link)
515
+static void snd_soc_flush_all_delayed_work(struct snd_soc_card *card)
411516 {
412517 struct snd_soc_pcm_runtime *rtd;
413518
414
- list_for_each_entry(rtd, &card->rtd_list, list) {
415
- if (!strcmp(rtd->dai_link->name, dai_link))
416
- return rtd;
417
- }
418
- dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
419
- return NULL;
420
-}
421
-EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
422
-
423
-static void codec2codec_close_delayed_work(struct work_struct *work)
424
-{
425
- /* Currently nothing to do for c2c links
426
- * Since c2c links are internal nodes in the DAPM graph and
427
- * don't interface with the outside world or application layer
428
- * we don't have to do any special handling on close.
429
- */
519
+ for_each_card_rtds(card, rtd)
520
+ flush_delayed_work(&rtd->delayed_work);
430521 }
431522
432523 #ifdef CONFIG_PM_SLEEP
....@@ -436,14 +527,16 @@
436527 struct snd_soc_card *card = dev_get_drvdata(dev);
437528 struct snd_soc_component *component;
438529 struct snd_soc_pcm_runtime *rtd;
530
+ int playback = SNDRV_PCM_STREAM_PLAYBACK;
439531 int i;
440532
441533 /* If the card is not initialized yet there is nothing to do */
442534 if (!card->instantiated)
443535 return 0;
444536
445
- /* Due to the resume being scheduled into a workqueue we could
446
- * suspend before that's finished - wait for it to complete.
537
+ /*
538
+ * Due to the resume being scheduled into a workqueue we could
539
+ * suspend before that's finished - wait for it to complete.
447540 */
448541 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
449542
....@@ -451,57 +544,40 @@
451544 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
452545
453546 /* mute any active DACs */
454
- list_for_each_entry(rtd, &card->rtd_list, list) {
547
+ for_each_card_rtds(card, rtd) {
548
+ struct snd_soc_dai *dai;
455549
456550 if (rtd->dai_link->ignore_suspend)
457551 continue;
458552
459
- for (i = 0; i < rtd->num_codecs; i++) {
460
- struct snd_soc_dai *dai = rtd->codec_dais[i];
461
- struct snd_soc_dai_driver *drv = dai->driver;
462
-
463
- if (drv->ops->digital_mute && dai->playback_active)
464
- drv->ops->digital_mute(dai, 1);
553
+ for_each_rtd_dais(rtd, i, dai) {
554
+ if (snd_soc_dai_stream_active(dai, playback))
555
+ snd_soc_dai_digital_mute(dai, 1, playback);
465556 }
466557 }
467558
468559 /* suspend all pcms */
469
- list_for_each_entry(rtd, &card->rtd_list, list) {
560
+ for_each_card_rtds(card, rtd) {
470561 if (rtd->dai_link->ignore_suspend)
471562 continue;
472563
473564 snd_pcm_suspend_all(rtd->pcm);
474565 }
475566
476
- if (card->suspend_pre)
477
- card->suspend_pre(card);
478
-
479
- list_for_each_entry(rtd, &card->rtd_list, list) {
480
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
481
-
482
- if (rtd->dai_link->ignore_suspend)
483
- continue;
484
-
485
- if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control)
486
- cpu_dai->driver->suspend(cpu_dai);
487
- }
567
+ snd_soc_card_suspend_pre(card);
488568
489569 /* close any waiting streams */
490
- list_for_each_entry(rtd, &card->rtd_list, list)
491
- flush_delayed_work(&rtd->delayed_work);
570
+ snd_soc_flush_all_delayed_work(card);
492571
493
- list_for_each_entry(rtd, &card->rtd_list, list) {
572
+ for_each_card_rtds(card, rtd) {
573
+ int stream;
494574
495575 if (rtd->dai_link->ignore_suspend)
496576 continue;
497577
498
- snd_soc_dapm_stream_event(rtd,
499
- SNDRV_PCM_STREAM_PLAYBACK,
500
- SND_SOC_DAPM_STREAM_SUSPEND);
501
-
502
- snd_soc_dapm_stream_event(rtd,
503
- SNDRV_PCM_STREAM_CAPTURE,
504
- SND_SOC_DAPM_STREAM_SUSPEND);
578
+ for_each_pcm_streams(stream)
579
+ snd_soc_dapm_stream_event(rtd, stream,
580
+ SND_SOC_DAPM_STREAM_SUSPEND);
505581 }
506582
507583 /* Recheck all endpoints too, their state is affected by suspend */
....@@ -509,12 +585,25 @@
509585 snd_soc_dapm_sync(&card->dapm);
510586
511587 /* suspend all COMPONENTs */
512
- list_for_each_entry(component, &card->component_dev_list, card_list) {
513
- struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
588
+ for_each_card_rtds(card, rtd) {
514589
515
- /* If there are paths active then the COMPONENT will be held with
516
- * bias _ON and should not be suspended. */
517
- if (!component->suspended) {
590
+ if (rtd->dai_link->ignore_suspend)
591
+ continue;
592
+
593
+ for_each_rtd_components(rtd, i, component) {
594
+ struct snd_soc_dapm_context *dapm =
595
+ snd_soc_component_get_dapm(component);
596
+
597
+ /*
598
+ * ignore if component was already suspended
599
+ */
600
+ if (snd_soc_component_is_suspended(component))
601
+ continue;
602
+
603
+ /*
604
+ * If there are paths active then the COMPONENT will be
605
+ * held with bias _ON and should not be suspended.
606
+ */
518607 switch (snd_soc_dapm_get_bias_level(dapm)) {
519608 case SND_SOC_BIAS_STANDBY:
520609 /*
....@@ -528,12 +617,10 @@
528617 "ASoC: idle_bias_off CODEC on over suspend\n");
529618 break;
530619 }
531
- /* fall through */
620
+ fallthrough;
532621
533622 case SND_SOC_BIAS_OFF:
534
- if (component->driver->suspend)
535
- component->driver->suspend(component);
536
- component->suspended = 1;
623
+ snd_soc_component_suspend(component);
537624 if (component->regmap)
538625 regcache_mark_dirty(component->regmap);
539626 /* deactivate pins to sleep state */
....@@ -547,38 +634,27 @@
547634 }
548635 }
549636
550
- list_for_each_entry(rtd, &card->rtd_list, list) {
551
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
552
-
553
- if (rtd->dai_link->ignore_suspend)
554
- continue;
555
-
556
- if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control)
557
- cpu_dai->driver->suspend(cpu_dai);
558
-
559
- /* deactivate pins to sleep state */
560
- pinctrl_pm_select_sleep_state(cpu_dai->dev);
561
- }
562
-
563
- if (card->suspend_post)
564
- card->suspend_post(card);
637
+ snd_soc_card_suspend_post(card);
565638
566639 return 0;
567640 }
568641 EXPORT_SYMBOL_GPL(snd_soc_suspend);
569642
570
-/* deferred resume work, so resume can complete before we finished
643
+/*
644
+ * deferred resume work, so resume can complete before we finished
571645 * setting our codec back up, which can be very slow on I2C
572646 */
573647 static void soc_resume_deferred(struct work_struct *work)
574648 {
575649 struct snd_soc_card *card =
576
- container_of(work, struct snd_soc_card, deferred_resume_work);
650
+ container_of(work, struct snd_soc_card,
651
+ deferred_resume_work);
577652 struct snd_soc_pcm_runtime *rtd;
578653 struct snd_soc_component *component;
579654 int i;
580655
581
- /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
656
+ /*
657
+ * our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
582658 * so userspace apps are blocked from touching us
583659 */
584660
....@@ -587,69 +663,39 @@
587663 /* Bring us up into D2 so that DAPM starts enabling things */
588664 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
589665
590
- if (card->resume_pre)
591
- card->resume_pre(card);
666
+ snd_soc_card_resume_pre(card);
592667
593
- /* resume control bus DAIs */
594
- list_for_each_entry(rtd, &card->rtd_list, list) {
595
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
668
+ for_each_card_components(card, component) {
669
+ if (snd_soc_component_is_suspended(component))
670
+ snd_soc_component_resume(component);
671
+ }
672
+
673
+ for_each_card_rtds(card, rtd) {
674
+ int stream;
596675
597676 if (rtd->dai_link->ignore_suspend)
598677 continue;
599678
600
- if (cpu_dai->driver->resume && cpu_dai->driver->bus_control)
601
- cpu_dai->driver->resume(cpu_dai);
602
- }
603
-
604
- list_for_each_entry(component, &card->component_dev_list, card_list) {
605
- if (component->suspended) {
606
- if (component->driver->resume)
607
- component->driver->resume(component);
608
- component->suspended = 0;
609
- }
610
- }
611
-
612
- list_for_each_entry(rtd, &card->rtd_list, list) {
613
-
614
- if (rtd->dai_link->ignore_suspend)
615
- continue;
616
-
617
- snd_soc_dapm_stream_event(rtd,
618
- SNDRV_PCM_STREAM_PLAYBACK,
619
- SND_SOC_DAPM_STREAM_RESUME);
620
-
621
- snd_soc_dapm_stream_event(rtd,
622
- SNDRV_PCM_STREAM_CAPTURE,
623
- SND_SOC_DAPM_STREAM_RESUME);
679
+ for_each_pcm_streams(stream)
680
+ snd_soc_dapm_stream_event(rtd, stream,
681
+ SND_SOC_DAPM_STREAM_RESUME);
624682 }
625683
626684 /* unmute any active DACs */
627
- list_for_each_entry(rtd, &card->rtd_list, list) {
685
+ for_each_card_rtds(card, rtd) {
686
+ struct snd_soc_dai *dai;
687
+ int playback = SNDRV_PCM_STREAM_PLAYBACK;
628688
629689 if (rtd->dai_link->ignore_suspend)
630690 continue;
631691
632
- for (i = 0; i < rtd->num_codecs; i++) {
633
- struct snd_soc_dai *dai = rtd->codec_dais[i];
634
- struct snd_soc_dai_driver *drv = dai->driver;
635
-
636
- if (drv->ops->digital_mute && dai->playback_active)
637
- drv->ops->digital_mute(dai, 0);
692
+ for_each_rtd_dais(rtd, i, dai) {
693
+ if (snd_soc_dai_stream_active(dai, playback))
694
+ snd_soc_dai_digital_mute(dai, 0, playback);
638695 }
639696 }
640697
641
- list_for_each_entry(rtd, &card->rtd_list, list) {
642
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
643
-
644
- if (rtd->dai_link->ignore_suspend)
645
- continue;
646
-
647
- if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control)
648
- cpu_dai->driver->resume(cpu_dai);
649
- }
650
-
651
- if (card->resume_post)
652
- card->resume_post(card);
698
+ snd_soc_card_resume_post(card);
653699
654700 dev_dbg(card->dev, "ASoC: resume work completed\n");
655701
....@@ -665,110 +711,90 @@
665711 int snd_soc_resume(struct device *dev)
666712 {
667713 struct snd_soc_card *card = dev_get_drvdata(dev);
668
- bool bus_control = false;
669
- struct snd_soc_pcm_runtime *rtd;
714
+ struct snd_soc_component *component;
670715
671716 /* If the card is not initialized yet there is nothing to do */
672717 if (!card->instantiated)
673718 return 0;
674719
675720 /* activate pins from sleep state */
676
- list_for_each_entry(rtd, &card->rtd_list, list) {
677
- struct snd_soc_dai **codec_dais = rtd->codec_dais;
678
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
679
- int j;
721
+ for_each_card_components(card, component)
722
+ if (snd_soc_component_active(component))
723
+ pinctrl_pm_select_default_state(component->dev);
680724
681
- if (cpu_dai->active)
682
- pinctrl_pm_select_default_state(cpu_dai->dev);
683
-
684
- for (j = 0; j < rtd->num_codecs; j++) {
685
- struct snd_soc_dai *codec_dai = codec_dais[j];
686
- if (codec_dai->active)
687
- pinctrl_pm_select_default_state(codec_dai->dev);
688
- }
689
- }
690
-
691
- /*
692
- * DAIs that also act as the control bus master might have other drivers
693
- * hanging off them so need to resume immediately. Other drivers don't
694
- * have that problem and may take a substantial amount of time to resume
695
- * due to I/O costs and anti-pop so handle them out of line.
696
- */
697
- list_for_each_entry(rtd, &card->rtd_list, list) {
698
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
699
- bus_control |= cpu_dai->driver->bus_control;
700
- }
701
- if (bus_control) {
702
- dev_dbg(dev, "ASoC: Resuming control bus master immediately\n");
703
- soc_resume_deferred(&card->deferred_resume_work);
704
- } else {
705
- dev_dbg(dev, "ASoC: Scheduling resume work\n");
706
- if (!schedule_work(&card->deferred_resume_work))
707
- dev_err(dev, "ASoC: resume work item may be lost\n");
708
- }
725
+ dev_dbg(dev, "ASoC: Scheduling resume work\n");
726
+ if (!schedule_work(&card->deferred_resume_work))
727
+ dev_err(dev, "ASoC: resume work item may be lost\n");
709728
710729 return 0;
711730 }
712731 EXPORT_SYMBOL_GPL(snd_soc_resume);
732
+
733
+static void soc_resume_init(struct snd_soc_card *card)
734
+{
735
+ /* deferred resume work */
736
+ INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
737
+}
713738 #else
714739 #define snd_soc_suspend NULL
715740 #define snd_soc_resume NULL
741
+static inline void soc_resume_init(struct snd_soc_card *card)
742
+{
743
+}
716744 #endif
717745
718
-static const struct snd_soc_dai_ops null_dai_ops = {
719
-};
746
+static struct device_node
747
+*soc_component_to_node(struct snd_soc_component *component)
748
+{
749
+ struct device_node *of_node;
720750
721
-/**
722
- * soc_find_component: find a component from component_list in ASoC core
723
- *
724
- * @of_node: of_node of the component to query.
725
- * @name: name of the component to query.
726
- *
727
- * function to find out if a component is already registered with ASoC core.
728
- *
729
- * Returns component handle for success, else NULL error.
730
- */
731
-struct snd_soc_component *soc_find_component(
732
- const struct device_node *of_node, const char *name)
751
+ of_node = component->dev->of_node;
752
+ if (!of_node && component->dev->parent)
753
+ of_node = component->dev->parent->of_node;
754
+
755
+ return of_node;
756
+}
757
+
758
+static int snd_soc_is_matching_component(
759
+ const struct snd_soc_dai_link_component *dlc,
760
+ struct snd_soc_component *component)
761
+{
762
+ struct device_node *component_of_node;
763
+
764
+ if (!dlc)
765
+ return 0;
766
+
767
+ component_of_node = soc_component_to_node(component);
768
+
769
+ if (dlc->of_node && component_of_node != dlc->of_node)
770
+ return 0;
771
+ if (dlc->name && strcmp(component->name, dlc->name))
772
+ return 0;
773
+
774
+ return 1;
775
+}
776
+
777
+static struct snd_soc_component *soc_find_component(
778
+ const struct snd_soc_dai_link_component *dlc)
733779 {
734780 struct snd_soc_component *component;
735781
736782 lockdep_assert_held(&client_mutex);
737783
738
- list_for_each_entry(component, &component_list, list) {
739
- if (of_node) {
740
- if (component->dev->of_node == of_node)
741
- return component;
742
- } else if (strcmp(component->name, name) == 0) {
784
+ /*
785
+ * NOTE
786
+ *
787
+ * It returns *1st* found component, but some driver
788
+ * has few components by same of_node/name
789
+ * ex)
790
+ * CPU component and generic DMAEngine component
791
+ */
792
+ for_each_component(component)
793
+ if (snd_soc_is_matching_component(dlc, component))
743794 return component;
744
- }
745
- }
746795
747796 return NULL;
748797 }
749
-EXPORT_SYMBOL(soc_find_component);
750
-
751
-/**
752
- * soc_find_component_locked: soc_find_component with client lock acquired
753
- *
754
- * @of_node: of_node of the component to query.
755
- * @name: name of the component to query.
756
- *
757
- * function to find out if a component is already registered with ASoC core.
758
- *
759
- * Returns component handle for success, else NULL error.
760
- */
761
-struct snd_soc_component *soc_find_component_locked(
762
- const struct device_node *of_node, const char *name)
763
-{
764
- struct snd_soc_component *component = NULL;
765
-
766
- mutex_lock(&client_mutex);
767
- component = soc_find_component(of_node, name);
768
- mutex_unlock(&client_mutex);
769
- return component;
770
-}
771
-EXPORT_SYMBOL(soc_find_component_locked);
772798
773799 /**
774800 * snd_soc_find_dai - Find a registered DAI
....@@ -786,21 +812,14 @@
786812 {
787813 struct snd_soc_component *component;
788814 struct snd_soc_dai *dai;
789
- struct device_node *component_of_node;
790815
791816 lockdep_assert_held(&client_mutex);
792817
793
- /* Find CPU DAI from registered DAIs*/
794
- list_for_each_entry(component, &component_list, list) {
795
- component_of_node = component->dev->of_node;
796
- if (!component_of_node && component->dev->parent)
797
- component_of_node = component->dev->parent->of_node;
798
-
799
- if (dlc->of_node && component_of_node != dlc->of_node)
818
+ /* Find CPU DAI from registered DAIs */
819
+ for_each_component(component) {
820
+ if (!snd_soc_is_matching_component(dlc, component))
800821 continue;
801
- if (dlc->name && strcmp(component->name, dlc->name))
802
- continue;
803
- list_for_each_entry(dai, &component->dai_list, list) {
822
+ for_each_component_dais(component, dai) {
804823 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
805824 && (!dai->driver->name
806825 || strcmp(dai->driver->name, dlc->dai_name)))
....@@ -814,466 +833,342 @@
814833 }
815834 EXPORT_SYMBOL_GPL(snd_soc_find_dai);
816835
836
+struct snd_soc_dai *snd_soc_find_dai_with_mutex(
837
+ const struct snd_soc_dai_link_component *dlc)
838
+{
839
+ struct snd_soc_dai *dai;
840
+
841
+ mutex_lock(&client_mutex);
842
+ dai = snd_soc_find_dai(dlc);
843
+ mutex_unlock(&client_mutex);
844
+
845
+ return dai;
846
+}
847
+EXPORT_SYMBOL_GPL(snd_soc_find_dai_with_mutex);
848
+
849
+static int soc_dai_link_sanity_check(struct snd_soc_card *card,
850
+ struct snd_soc_dai_link *link)
851
+{
852
+ int i;
853
+ struct snd_soc_dai_link_component *cpu, *codec, *platform;
854
+
855
+ for_each_link_codecs(link, i, codec) {
856
+ /*
857
+ * Codec must be specified by 1 of name or OF node,
858
+ * not both or neither.
859
+ */
860
+ if (!!codec->name == !!codec->of_node) {
861
+ dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
862
+ link->name);
863
+ return -EINVAL;
864
+ }
865
+
866
+ /* Codec DAI name must be specified */
867
+ if (!codec->dai_name) {
868
+ dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
869
+ link->name);
870
+ return -EINVAL;
871
+ }
872
+
873
+ /*
874
+ * Defer card registration if codec component is not added to
875
+ * component list.
876
+ */
877
+ if (!soc_find_component(codec)) {
878
+ dev_dbg(card->dev,
879
+ "ASoC: codec component %s not found for link %s\n",
880
+ codec->name, link->name);
881
+ return -EPROBE_DEFER;
882
+ }
883
+ }
884
+
885
+ for_each_link_platforms(link, i, platform) {
886
+ /*
887
+ * Platform may be specified by either name or OF node, but it
888
+ * can be left unspecified, then no components will be inserted
889
+ * in the rtdcom list
890
+ */
891
+ if (!!platform->name == !!platform->of_node) {
892
+ dev_err(card->dev,
893
+ "ASoC: Neither/both platform name/of_node are set for %s\n",
894
+ link->name);
895
+ return -EINVAL;
896
+ }
897
+
898
+ /*
899
+ * Defer card registration if platform component is not added to
900
+ * component list.
901
+ */
902
+ if (!soc_find_component(platform)) {
903
+ dev_dbg(card->dev,
904
+ "ASoC: platform component %s not found for link %s\n",
905
+ platform->name, link->name);
906
+ return -EPROBE_DEFER;
907
+ }
908
+ }
909
+
910
+ for_each_link_cpus(link, i, cpu) {
911
+ /*
912
+ * CPU device may be specified by either name or OF node, but
913
+ * can be left unspecified, and will be matched based on DAI
914
+ * name alone..
915
+ */
916
+ if (cpu->name && cpu->of_node) {
917
+ dev_err(card->dev,
918
+ "ASoC: Neither/both cpu name/of_node are set for %s\n",
919
+ link->name);
920
+ return -EINVAL;
921
+ }
922
+
923
+ /*
924
+ * Defer card registration if cpu dai component is not added to
925
+ * component list.
926
+ */
927
+ if ((cpu->of_node || cpu->name) &&
928
+ !soc_find_component(cpu)) {
929
+ dev_dbg(card->dev,
930
+ "ASoC: cpu component %s not found for link %s\n",
931
+ cpu->name, link->name);
932
+ return -EPROBE_DEFER;
933
+ }
934
+
935
+ /*
936
+ * At least one of CPU DAI name or CPU device name/node must be
937
+ * specified
938
+ */
939
+ if (!cpu->dai_name &&
940
+ !(cpu->name || cpu->of_node)) {
941
+ dev_err(card->dev,
942
+ "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
943
+ link->name);
944
+ return -EINVAL;
945
+ }
946
+ }
947
+
948
+ return 0;
949
+}
817950
818951 /**
819
- * snd_soc_find_dai_link - Find a DAI link
952
+ * snd_soc_remove_pcm_runtime - Remove a pcm_runtime from card
953
+ * @card: The ASoC card to which the pcm_runtime has
954
+ * @rtd: The pcm_runtime to remove
820955 *
821
- * @card: soc card
822
- * @id: DAI link ID to match
823
- * @name: DAI link name to match, optional
824
- * @stream_name: DAI link stream name to match, optional
825
- *
826
- * This function will search all existing DAI links of the soc card to
827
- * find the link of the same ID. Since DAI links may not have their
828
- * unique ID, so name and stream name should also match if being
829
- * specified.
830
- *
831
- * Return: pointer of DAI link, or NULL if not found.
956
+ * This function removes a pcm_runtime from the ASoC card.
832957 */
833
-struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
834
- int id, const char *name,
835
- const char *stream_name)
958
+void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
959
+ struct snd_soc_pcm_runtime *rtd)
836960 {
837
- struct snd_soc_dai_link *link, *_link;
961
+ lockdep_assert_held(&client_mutex);
962
+
963
+ /* release machine specific resources */
964
+ snd_soc_link_exit(rtd);
965
+
966
+ /*
967
+ * Notify the machine driver for extra destruction
968
+ */
969
+ snd_soc_card_remove_dai_link(card, rtd->dai_link);
970
+
971
+ soc_free_pcm_runtime(rtd);
972
+}
973
+EXPORT_SYMBOL_GPL(snd_soc_remove_pcm_runtime);
974
+
975
+/**
976
+ * snd_soc_add_pcm_runtime - Add a pcm_runtime dynamically via dai_link
977
+ * @card: The ASoC card to which the pcm_runtime is added
978
+ * @dai_link: The DAI link to find pcm_runtime
979
+ *
980
+ * This function adds a pcm_runtime ASoC card by using dai_link.
981
+ *
982
+ * Note: Topology can use this API to add pcm_runtime when probing the
983
+ * topology component. And machine drivers can still define static
984
+ * DAI links in dai_link array.
985
+ */
986
+int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
987
+ struct snd_soc_dai_link *dai_link)
988
+{
989
+ struct snd_soc_pcm_runtime *rtd;
990
+ struct snd_soc_dai_link_component *codec, *platform, *cpu;
991
+ struct snd_soc_component *component;
992
+ int i, ret;
838993
839994 lockdep_assert_held(&client_mutex);
840995
841
- list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
842
- if (link->id != id)
843
- continue;
844
-
845
- if (name && (!link->name || strcmp(name, link->name)))
846
- continue;
847
-
848
- if (stream_name && (!link->stream_name
849
- || strcmp(stream_name, link->stream_name)))
850
- continue;
851
-
852
- return link;
853
- }
854
-
855
- return NULL;
856
-}
857
-EXPORT_SYMBOL_GPL(snd_soc_find_dai_link);
858
-
859
-static bool soc_is_dai_link_bound(struct snd_soc_card *card,
860
- struct snd_soc_dai_link *dai_link)
861
-{
862
- struct snd_soc_pcm_runtime *rtd;
863
-
864
- list_for_each_entry(rtd, &card->rtd_list, list) {
865
- if (rtd->dai_link == dai_link)
866
- return true;
867
- }
868
-
869
- return false;
870
-}
871
-
872
-static int soc_bind_dai_link(struct snd_soc_card *card,
873
- struct snd_soc_dai_link *dai_link)
874
-{
875
- struct snd_soc_pcm_runtime *rtd;
876
- struct snd_soc_dai_link_component *codecs = dai_link->codecs;
877
- struct snd_soc_dai_link_component cpu_dai_component;
878
- struct snd_soc_component *component;
879
- struct snd_soc_dai **codec_dais;
880
- struct device_node *platform_of_node;
881
- const char *platform_name;
882
- int i;
996
+ /*
997
+ * Notify the machine driver for extra initialization
998
+ */
999
+ ret = snd_soc_card_add_dai_link(card, dai_link);
1000
+ if (ret < 0)
1001
+ return ret;
8831002
8841003 if (dai_link->ignore)
8851004 return 0;
8861005
8871006 dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
8881007
889
- if (soc_is_dai_link_bound(card, dai_link)) {
890
- dev_dbg(card->dev, "ASoC: dai link %s already bound\n",
891
- dai_link->name);
892
- return 0;
893
- }
1008
+ ret = soc_dai_link_sanity_check(card, dai_link);
1009
+ if (ret < 0)
1010
+ return ret;
8941011
8951012 rtd = soc_new_pcm_runtime(card, dai_link);
8961013 if (!rtd)
8971014 return -ENOMEM;
8981015
899
- cpu_dai_component.name = dai_link->cpu_name;
900
- cpu_dai_component.of_node = dai_link->cpu_of_node;
901
- cpu_dai_component.dai_name = dai_link->cpu_dai_name;
902
- rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component);
903
- if (!rtd->cpu_dai) {
904
- dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
905
- dai_link->cpu_dai_name);
906
- goto _err_defer;
907
- }
908
- snd_soc_rtdcom_add(rtd, rtd->cpu_dai->component);
909
-
910
- rtd->num_codecs = dai_link->num_codecs;
911
-
912
- /* Find CODEC from registered CODECs */
913
- codec_dais = rtd->codec_dais;
914
- for (i = 0; i < rtd->num_codecs; i++) {
915
- codec_dais[i] = snd_soc_find_dai(&codecs[i]);
916
- if (!codec_dais[i]) {
917
- dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
918
- codecs[i].dai_name);
1016
+ for_each_link_cpus(dai_link, i, cpu) {
1017
+ asoc_rtd_to_cpu(rtd, i) = snd_soc_find_dai(cpu);
1018
+ if (!asoc_rtd_to_cpu(rtd, i)) {
1019
+ dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
1020
+ cpu->dai_name);
9191021 goto _err_defer;
9201022 }
921
- snd_soc_rtdcom_add(rtd, codec_dais[i]->component);
1023
+ snd_soc_rtd_add_component(rtd, asoc_rtd_to_cpu(rtd, i)->component);
9221024 }
9231025
924
- /* Single codec links expect codec and codec_dai in runtime data */
925
- rtd->codec_dai = codec_dais[0];
926
-
927
- /* if there's no platform we match on the empty platform */
928
- platform_name = dai_link->platform_name;
929
- if (!platform_name && !dai_link->platform_of_node)
930
- platform_name = "snd-soc-dummy";
931
-
932
- /* find one from the set of registered platforms */
933
- list_for_each_entry(component, &component_list, list) {
934
- platform_of_node = component->dev->of_node;
935
- if (!platform_of_node && component->dev->parent->of_node)
936
- platform_of_node = component->dev->parent->of_node;
937
-
938
- if (dai_link->platform_of_node) {
939
- if (platform_of_node != dai_link->platform_of_node)
940
- continue;
941
- } else {
942
- if (strcmp(component->name, platform_name))
943
- continue;
1026
+ /* Find CODEC from registered CODECs */
1027
+ for_each_link_codecs(dai_link, i, codec) {
1028
+ asoc_rtd_to_codec(rtd, i) = snd_soc_find_dai(codec);
1029
+ if (!asoc_rtd_to_codec(rtd, i)) {
1030
+ dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n",
1031
+ codec->dai_name);
1032
+ goto _err_defer;
9441033 }
9451034
946
- snd_soc_rtdcom_add(rtd, component);
1035
+ snd_soc_rtd_add_component(rtd, asoc_rtd_to_codec(rtd, i)->component);
9471036 }
9481037
949
- soc_add_pcm_runtime(card, rtd);
1038
+ /* Find PLATFORM from registered PLATFORMs */
1039
+ for_each_link_platforms(dai_link, i, platform) {
1040
+ for_each_component(component) {
1041
+ if (!snd_soc_is_matching_component(platform, component))
1042
+ continue;
1043
+
1044
+ snd_soc_rtd_add_component(rtd, component);
1045
+ }
1046
+ }
1047
+
9501048 return 0;
9511049
9521050 _err_defer:
953
- soc_free_pcm_runtime(rtd);
954
- return -EPROBE_DEFER;
1051
+ snd_soc_remove_pcm_runtime(card, rtd);
1052
+ return -EPROBE_DEFER;
9551053 }
1054
+EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtime);
9561055
957
-static void soc_remove_component(struct snd_soc_component *component)
1056
+static int soc_init_pcm_runtime(struct snd_soc_card *card,
1057
+ struct snd_soc_pcm_runtime *rtd)
9581058 {
959
- if (!component->card)
960
- return;
961
-
962
- list_del(&component->card_list);
963
-
964
- if (component->driver->remove)
965
- component->driver->remove(component);
966
-
967
- snd_soc_dapm_free(snd_soc_component_get_dapm(component));
968
-
969
- soc_cleanup_component_debugfs(component);
970
- component->card = NULL;
971
- module_put(component->dev->driver->owner);
972
-}
973
-
974
-static void soc_remove_dai(struct snd_soc_dai *dai, int order)
975
-{
976
- int err;
977
-
978
- if (dai && dai->probed &&
979
- dai->driver->remove_order == order) {
980
- if (dai->driver->remove) {
981
- err = dai->driver->remove(dai);
982
- if (err < 0)
983
- dev_err(dai->dev,
984
- "ASoC: failed to remove %s: %d\n",
985
- dai->name, err);
986
- }
987
- dai->probed = 0;
988
- }
989
-}
990
-
991
-static void soc_remove_link_dais(struct snd_soc_card *card,
992
- struct snd_soc_pcm_runtime *rtd, int order)
993
-{
994
- int i;
995
-
996
- /* unregister the rtd device */
997
- if (rtd->dev_registered) {
998
- device_unregister(rtd->dev);
999
- rtd->dev_registered = 0;
1000
- }
1001
-
1002
- /* remove the CODEC DAI */
1003
- for (i = 0; i < rtd->num_codecs; i++)
1004
- soc_remove_dai(rtd->codec_dais[i], order);
1005
-
1006
- soc_remove_dai(rtd->cpu_dai, order);
1007
-}
1008
-
1009
-static void soc_remove_link_components(struct snd_soc_card *card,
1010
- struct snd_soc_pcm_runtime *rtd, int order)
1011
-{
1059
+ struct snd_soc_dai_link *dai_link = rtd->dai_link;
1060
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
10121061 struct snd_soc_component *component;
1013
- struct snd_soc_rtdcom_list *rtdcom;
1062
+ int ret, num, i;
10141063
1015
- for_each_rtdcom(rtd, rtdcom) {
1016
- component = rtdcom->component;
1064
+ /* set default power off timeout */
1065
+ rtd->pmdown_time = pmdown_time;
10171066
1018
- if (component->driver->remove_order == order)
1019
- soc_remove_component(component);
1020
- }
1021
-}
1067
+ /* do machine specific initialization */
1068
+ ret = snd_soc_link_init(rtd);
1069
+ if (ret < 0)
1070
+ return ret;
10221071
1023
-static void soc_remove_dai_links(struct snd_soc_card *card)
1024
-{
1025
- int order;
1026
- struct snd_soc_pcm_runtime *rtd;
1027
- struct snd_soc_dai_link *link, *_link;
1028
-
1029
- for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1030
- order++) {
1031
- list_for_each_entry(rtd, &card->rtd_list, list)
1032
- soc_remove_link_dais(card, rtd, order);
1072
+ if (dai_link->dai_fmt) {
1073
+ ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
1074
+ if (ret)
1075
+ return ret;
10331076 }
10341077
1035
- for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1036
- order++) {
1037
- list_for_each_entry(rtd, &card->rtd_list, list)
1038
- soc_remove_link_components(card, rtd, order);
1078
+ /* add DPCM sysfs entries */
1079
+ soc_dpcm_debugfs_add(rtd);
1080
+
1081
+ num = rtd->num;
1082
+
1083
+ /*
1084
+ * most drivers will register their PCMs using DAI link ordering but
1085
+ * topology based drivers can use the DAI link id field to set PCM
1086
+ * device number and then use rtd + a base offset of the BEs.
1087
+ */
1088
+ for_each_rtd_components(rtd, i, component) {
1089
+ if (!component->driver->use_dai_pcm_id)
1090
+ continue;
1091
+
1092
+ if (rtd->dai_link->no_pcm)
1093
+ num += component->driver->be_pcm_base;
1094
+ else
1095
+ num = rtd->dai_link->id;
10391096 }
10401097
1041
- list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1042
- if (link->dobj.type == SND_SOC_DOBJ_DAI_LINK)
1043
- dev_warn(card->dev, "Topology forgot to remove link %s?\n",
1044
- link->name);
1045
-
1046
- list_del(&link->list);
1047
- card->num_dai_links--;
1048
- }
1049
-}
1050
-
1051
-static int snd_soc_init_multicodec(struct snd_soc_card *card,
1052
- struct snd_soc_dai_link *dai_link)
1053
-{
1054
- /* Legacy codec/codec_dai link is a single entry in multicodec */
1055
- if (dai_link->codec_name || dai_link->codec_of_node ||
1056
- dai_link->codec_dai_name) {
1057
- dai_link->num_codecs = 1;
1058
-
1059
- dai_link->codecs = devm_kzalloc(card->dev,
1060
- sizeof(struct snd_soc_dai_link_component),
1061
- GFP_KERNEL);
1062
- if (!dai_link->codecs)
1063
- return -ENOMEM;
1064
-
1065
- dai_link->codecs[0].name = dai_link->codec_name;
1066
- dai_link->codecs[0].of_node = dai_link->codec_of_node;
1067
- dai_link->codecs[0].dai_name = dai_link->codec_dai_name;
1068
- }
1069
-
1070
- if (!dai_link->codecs) {
1071
- dev_err(card->dev, "ASoC: DAI link has no CODECs\n");
1072
- return -EINVAL;
1073
- }
1074
-
1075
- return 0;
1076
-}
1077
-
1078
-static int soc_init_dai_link(struct snd_soc_card *card,
1079
- struct snd_soc_dai_link *link)
1080
-{
1081
- int i, ret;
1082
-
1083
- ret = snd_soc_init_multicodec(card, link);
1084
- if (ret) {
1085
- dev_err(card->dev, "ASoC: failed to init multicodec\n");
1098
+ /* create compress_device if possible */
1099
+ ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);
1100
+ if (ret != -ENOTSUPP) {
1101
+ if (ret < 0)
1102
+ dev_err(card->dev, "ASoC: can't create compress %s\n",
1103
+ dai_link->stream_name);
10861104 return ret;
10871105 }
10881106
1089
- for (i = 0; i < link->num_codecs; i++) {
1090
- /*
1091
- * Codec must be specified by 1 of name or OF node,
1092
- * not both or neither.
1093
- */
1094
- if (!!link->codecs[i].name ==
1095
- !!link->codecs[i].of_node) {
1096
- dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
1097
- link->name);
1098
- return -EINVAL;
1099
- }
1100
- /* Codec DAI name must be specified */
1101
- if (!link->codecs[i].dai_name) {
1102
- dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
1103
- link->name);
1104
- return -EINVAL;
1105
- }
1107
+ /* create the pcm */
1108
+ ret = soc_new_pcm(rtd, num);
1109
+ if (ret < 0) {
1110
+ dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1111
+ dai_link->stream_name, ret);
1112
+ return ret;
11061113 }
11071114
1108
- /*
1109
- * Platform may be specified by either name or OF node, but
1110
- * can be left unspecified, and a dummy platform will be used.
1111
- */
1112
- if (link->platform_name && link->platform_of_node) {
1113
- dev_err(card->dev,
1114
- "ASoC: Both platform name/of_node are set for %s\n",
1115
- link->name);
1116
- return -EINVAL;
1117
- }
1118
-
1119
- /*
1120
- * CPU device may be specified by either name or OF node, but
1121
- * can be left unspecified, and will be matched based on DAI
1122
- * name alone..
1123
- */
1124
- if (link->cpu_name && link->cpu_of_node) {
1125
- dev_err(card->dev,
1126
- "ASoC: Neither/both cpu name/of_node are set for %s\n",
1127
- link->name);
1128
- return -EINVAL;
1129
- }
1130
- /*
1131
- * At least one of CPU DAI name or CPU device name/node must be
1132
- * specified
1133
- */
1134
- if (!link->cpu_dai_name &&
1135
- !(link->cpu_name || link->cpu_of_node)) {
1136
- dev_err(card->dev,
1137
- "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
1138
- link->name);
1139
- return -EINVAL;
1140
- }
1141
-
1142
- return 0;
1143
-}
1144
-
1145
-void snd_soc_disconnect_sync(struct device *dev)
1146
-{
1147
- struct snd_soc_component *component = snd_soc_lookup_component(dev, NULL);
1148
-
1149
- if (!component || !component->card)
1150
- return;
1151
-
1152
- snd_card_disconnect_sync(component->card->snd_card);
1153
-}
1154
-EXPORT_SYMBOL_GPL(snd_soc_disconnect_sync);
1155
-
1156
-/**
1157
- * snd_soc_add_dai_link - Add a DAI link dynamically
1158
- * @card: The ASoC card to which the DAI link is added
1159
- * @dai_link: The new DAI link to add
1160
- *
1161
- * This function adds a DAI link to the ASoC card's link list.
1162
- *
1163
- * Note: Topology can use this API to add DAI links when probing the
1164
- * topology component. And machine drivers can still define static
1165
- * DAI links in dai_link array.
1166
- */
1167
-int snd_soc_add_dai_link(struct snd_soc_card *card,
1168
- struct snd_soc_dai_link *dai_link)
1169
-{
1170
- if (dai_link->dobj.type
1171
- && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1172
- dev_err(card->dev, "Invalid dai link type %d\n",
1173
- dai_link->dobj.type);
1174
- return -EINVAL;
1175
- }
1176
-
1177
- lockdep_assert_held(&client_mutex);
1178
- /* Notify the machine driver for extra initialization
1179
- * on the link created by topology.
1180
- */
1181
- if (dai_link->dobj.type && card->add_dai_link)
1182
- card->add_dai_link(card, dai_link);
1183
-
1184
- list_add_tail(&dai_link->list, &card->dai_link_list);
1185
- card->num_dai_links++;
1186
-
1187
- return 0;
1188
-}
1189
-EXPORT_SYMBOL_GPL(snd_soc_add_dai_link);
1190
-
1191
-/**
1192
- * snd_soc_remove_dai_link - Remove a DAI link from the list
1193
- * @card: The ASoC card that owns the link
1194
- * @dai_link: The DAI link to remove
1195
- *
1196
- * This function removes a DAI link from the ASoC card's link list.
1197
- *
1198
- * For DAI links previously added by topology, topology should
1199
- * remove them by using the dobj embedded in the link.
1200
- */
1201
-void snd_soc_remove_dai_link(struct snd_soc_card *card,
1202
- struct snd_soc_dai_link *dai_link)
1203
-{
1204
- struct snd_soc_dai_link *link, *_link;
1205
-
1206
- if (dai_link->dobj.type
1207
- && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1208
- dev_err(card->dev, "Invalid dai link type %d\n",
1209
- dai_link->dobj.type);
1210
- return;
1211
- }
1212
-
1213
- lockdep_assert_held(&client_mutex);
1214
- /* Notify the machine driver for extra destruction
1215
- * on the link created by topology.
1216
- */
1217
- if (dai_link->dobj.type && card->remove_dai_link)
1218
- card->remove_dai_link(card, dai_link);
1219
-
1220
- list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1221
- if (link == dai_link) {
1222
- list_del(&link->list);
1223
- card->num_dai_links--;
1224
- return;
1225
- }
1226
- }
1227
-}
1228
-EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
1229
-
1230
-static void soc_set_of_name_prefix(struct snd_soc_component *component)
1231
-{
1232
- struct device_node *component_of_node = component->dev->of_node;
1233
- const char *str;
1234
- int ret;
1235
-
1236
- if (!component_of_node && component->dev->parent)
1237
- component_of_node = component->dev->parent->of_node;
1238
-
1239
- ret = of_property_read_string(component_of_node, "sound-name-prefix",
1240
- &str);
1241
- if (!ret)
1242
- component->name_prefix = str;
1115
+ return snd_soc_pcm_dai_new(rtd);
12431116 }
12441117
12451118 static void soc_set_name_prefix(struct snd_soc_card *card,
12461119 struct snd_soc_component *component)
12471120 {
1248
- int i;
1121
+ struct device_node *of_node = soc_component_to_node(component);
1122
+ const char *str;
1123
+ int ret, i;
12491124
1250
- for (i = 0; i < card->num_configs && card->codec_conf; i++) {
1125
+ for (i = 0; i < card->num_configs; i++) {
12511126 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1252
- struct device_node *component_of_node = component->dev->of_node;
12531127
1254
- if (!component_of_node && component->dev->parent)
1255
- component_of_node = component->dev->parent->of_node;
1256
-
1257
- if (map->of_node && component_of_node != map->of_node)
1258
- continue;
1259
- if (map->dev_name && strcmp(component->name, map->dev_name))
1260
- continue;
1261
- component->name_prefix = map->name_prefix;
1262
- return;
1128
+ if (snd_soc_is_matching_component(&map->dlc, component)) {
1129
+ component->name_prefix = map->name_prefix;
1130
+ return;
1131
+ }
12631132 }
12641133
12651134 /*
12661135 * If there is no configuration table or no match in the table,
12671136 * check if a prefix is provided in the node
12681137 */
1269
- soc_set_of_name_prefix(component);
1138
+ ret = of_property_read_string(of_node, "sound-name-prefix", &str);
1139
+ if (ret < 0)
1140
+ return;
1141
+
1142
+ component->name_prefix = str;
1143
+}
1144
+
1145
+static void soc_remove_component(struct snd_soc_component *component,
1146
+ int probed)
1147
+{
1148
+
1149
+ if (!component->card)
1150
+ return;
1151
+
1152
+ if (probed)
1153
+ snd_soc_component_remove(component);
1154
+
1155
+ /* For framework level robustness */
1156
+ snd_soc_component_set_jack(component, NULL, NULL);
1157
+
1158
+ list_del_init(&component->card_list);
1159
+ snd_soc_dapm_free(snd_soc_component_get_dapm(component));
1160
+ soc_cleanup_component_debugfs(component);
1161
+ component->card = NULL;
1162
+ snd_soc_component_module_put_when_remove(component);
12701163 }
12711164
12721165 static int soc_probe_component(struct snd_soc_card *card,
1273
- struct snd_soc_component *component)
1166
+ struct snd_soc_component *component)
12741167 {
1275
- struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
1168
+ struct snd_soc_dapm_context *dapm =
1169
+ snd_soc_component_get_dapm(component);
12761170 struct snd_soc_dai *dai;
1171
+ int probed = 0;
12771172 int ret;
12781173
12791174 if (!strcmp(component->name, "snd-soc-dummy"))
....@@ -1289,28 +1184,28 @@
12891184 return 0;
12901185 }
12911186
1292
- if (!try_module_get(component->dev->driver->owner))
1293
- return -ENODEV;
1187
+ ret = snd_soc_component_module_get_when_probe(component);
1188
+ if (ret < 0)
1189
+ return ret;
12941190
12951191 component->card = card;
1296
- dapm->card = card;
12971192 soc_set_name_prefix(card, component);
12981193
12991194 soc_init_component_debugfs(component);
13001195
1301
- if (component->driver->dapm_widgets) {
1302
- ret = snd_soc_dapm_new_controls(dapm,
1196
+ snd_soc_dapm_init(dapm, card, component);
1197
+
1198
+ ret = snd_soc_dapm_new_controls(dapm,
13031199 component->driver->dapm_widgets,
13041200 component->driver->num_dapm_widgets);
13051201
1306
- if (ret != 0) {
1307
- dev_err(component->dev,
1308
- "Failed to create new controls %d\n", ret);
1309
- goto err_probe;
1310
- }
1202
+ if (ret != 0) {
1203
+ dev_err(component->dev,
1204
+ "Failed to create new controls %d\n", ret);
1205
+ goto err_probe;
13111206 }
13121207
1313
- list_for_each_entry(dai, &component->dai_list, list) {
1208
+ for_each_component_dais(component, dai) {
13141209 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
13151210 if (ret != 0) {
13161211 dev_err(component->dev,
....@@ -1319,296 +1214,86 @@
13191214 }
13201215 }
13211216
1322
- if (component->driver->probe) {
1323
- ret = component->driver->probe(component);
1324
- if (ret < 0) {
1325
- dev_err(component->dev,
1326
- "ASoC: failed to probe component %d\n", ret);
1327
- goto err_probe;
1328
- }
1329
-
1330
- WARN(dapm->idle_bias_off &&
1331
- dapm->bias_level != SND_SOC_BIAS_OFF,
1332
- "codec %s can not start from non-off bias with idle_bias_off==1\n",
1333
- component->name);
1217
+ ret = snd_soc_component_probe(component);
1218
+ if (ret < 0) {
1219
+ dev_err(component->dev,
1220
+ "ASoC: failed to probe component %d\n", ret);
1221
+ goto err_probe;
13341222 }
1223
+ WARN(dapm->idle_bias_off &&
1224
+ dapm->bias_level != SND_SOC_BIAS_OFF,
1225
+ "codec %s can not start from non-off bias with idle_bias_off==1\n",
1226
+ component->name);
1227
+ probed = 1;
13351228
1336
- /* machine specific init */
1337
- if (component->init) {
1338
- ret = component->init(component);
1339
- if (ret < 0) {
1340
- dev_err(component->dev,
1341
- "Failed to do machine specific init %d\n", ret);
1229
+ /*
1230
+ * machine specific init
1231
+ * see
1232
+ * snd_soc_component_set_aux()
1233
+ */
1234
+ ret = snd_soc_component_init(component);
1235
+ if (ret < 0)
1236
+ goto err_probe;
1237
+
1238
+ ret = snd_soc_add_component_controls(component,
1239
+ component->driver->controls,
1240
+ component->driver->num_controls);
1241
+ if (ret < 0)
1242
+ goto err_probe;
1243
+
1244
+ ret = snd_soc_dapm_add_routes(dapm,
1245
+ component->driver->dapm_routes,
1246
+ component->driver->num_dapm_routes);
1247
+ if (ret < 0) {
1248
+ if (card->disable_route_checks) {
1249
+ dev_info(card->dev,
1250
+ "%s: disable_route_checks set, ignoring errors on add_routes\n",
1251
+ __func__);
1252
+ } else {
1253
+ dev_err(card->dev,
1254
+ "%s: snd_soc_dapm_add_routes failed: %d\n",
1255
+ __func__, ret);
13421256 goto err_probe;
13431257 }
13441258 }
13451259
1346
- if (component->driver->controls)
1347
- snd_soc_add_component_controls(component,
1348
- component->driver->controls,
1349
- component->driver->num_controls);
1350
- if (component->driver->dapm_routes)
1351
- snd_soc_dapm_add_routes(dapm,
1352
- component->driver->dapm_routes,
1353
- component->driver->num_dapm_routes);
1354
-
1355
- list_add(&dapm->list, &card->dapm_list);
1260
+ /* see for_each_card_components */
13561261 list_add(&component->card_list, &card->component_dev_list);
13571262
1358
- return 0;
1359
-
13601263 err_probe:
1361
- soc_cleanup_component_debugfs(component);
1362
- component->card = NULL;
1363
- module_put(component->dev->driver->owner);
1264
+ if (ret < 0)
1265
+ soc_remove_component(component, probed);
13641266
13651267 return ret;
13661268 }
13671269
1368
-static void rtd_release(struct device *dev)
1270
+static void soc_remove_link_dais(struct snd_soc_card *card)
13691271 {
1370
- kfree(dev);
1272
+ struct snd_soc_pcm_runtime *rtd;
1273
+ int order;
1274
+
1275
+ for_each_comp_order(order) {
1276
+ for_each_card_rtds(card, rtd) {
1277
+ /* remove all rtd connected DAIs in good order */
1278
+ snd_soc_pcm_dai_remove(rtd, order);
1279
+ }
1280
+ }
13711281 }
13721282
1373
-static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
1374
- const char *name)
1283
+static int soc_probe_link_dais(struct snd_soc_card *card)
13751284 {
1376
- int ret = 0;
1285
+ struct snd_soc_pcm_runtime *rtd;
1286
+ int order, ret;
13771287
1378
- /* register the rtd device */
1379
- rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1380
- if (!rtd->dev)
1381
- return -ENOMEM;
1382
- device_initialize(rtd->dev);
1383
- rtd->dev->parent = rtd->card->dev;
1384
- rtd->dev->release = rtd_release;
1385
- rtd->dev->groups = soc_dev_attr_groups;
1386
- dev_set_name(rtd->dev, "%s", name);
1387
- dev_set_drvdata(rtd->dev, rtd);
1388
- mutex_init(&rtd->pcm_mutex);
1389
- INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1390
- INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1391
- INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1392
- INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
1393
- ret = device_add(rtd->dev);
1394
- if (ret < 0) {
1395
- /* calling put_device() here to free the rtd->dev */
1396
- put_device(rtd->dev);
1397
- dev_err(rtd->card->dev,
1398
- "ASoC: failed to register runtime device: %d\n", ret);
1399
- return ret;
1400
- }
1401
- rtd->dev_registered = 1;
1402
- return 0;
1403
-}
1288
+ for_each_comp_order(order) {
1289
+ for_each_card_rtds(card, rtd) {
14041290
1405
-static int soc_probe_link_components(struct snd_soc_card *card,
1406
- struct snd_soc_pcm_runtime *rtd,
1407
- int order)
1408
-{
1409
- struct snd_soc_component *component;
1410
- struct snd_soc_rtdcom_list *rtdcom;
1411
- int ret;
1291
+ dev_dbg(card->dev,
1292
+ "ASoC: probe %s dai link %d late %d\n",
1293
+ card->name, rtd->num, order);
14121294
1413
- for_each_rtdcom(rtd, rtdcom) {
1414
- component = rtdcom->component;
1415
-
1416
- if (component->driver->probe_order == order) {
1417
- ret = soc_probe_component(card, component);
1418
- if (ret < 0)
1419
- return ret;
1420
- }
1421
- }
1422
-
1423
- return 0;
1424
-}
1425
-
1426
-static int soc_probe_dai(struct snd_soc_dai *dai, int order)
1427
-{
1428
- if (dai->probed ||
1429
- dai->driver->probe_order != order)
1430
- return 0;
1431
-
1432
- if (dai->driver->probe) {
1433
- int ret = dai->driver->probe(dai);
1434
- if (ret < 0) {
1435
- dev_err(dai->dev, "ASoC: failed to probe DAI %s: %d\n",
1436
- dai->name, ret);
1437
- return ret;
1438
- }
1439
- }
1440
-
1441
- dai->probed = 1;
1442
-
1443
- return 0;
1444
-}
1445
-
1446
-static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
1447
- struct snd_soc_pcm_runtime *rtd)
1448
-{
1449
- int i, ret = 0;
1450
-
1451
- for (i = 0; i < num_dais; ++i) {
1452
- struct snd_soc_dai_driver *drv = dais[i]->driver;
1453
-
1454
- if (!rtd->dai_link->no_pcm && drv->pcm_new)
1455
- ret = drv->pcm_new(rtd, dais[i]);
1456
- if (ret < 0) {
1457
- dev_err(dais[i]->dev,
1458
- "ASoC: Failed to bind %s with pcm device\n",
1459
- dais[i]->name);
1460
- return ret;
1461
- }
1462
- }
1463
-
1464
- return 0;
1465
-}
1466
-
1467
-static int soc_link_dai_widgets(struct snd_soc_card *card,
1468
- struct snd_soc_dai_link *dai_link,
1469
- struct snd_soc_pcm_runtime *rtd)
1470
-{
1471
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1472
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
1473
- struct snd_soc_dapm_widget *sink, *source;
1474
- int ret;
1475
-
1476
- if (rtd->num_codecs > 1)
1477
- dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n");
1478
-
1479
- /* link the DAI widgets */
1480
- sink = codec_dai->playback_widget;
1481
- source = cpu_dai->capture_widget;
1482
- if (sink && source) {
1483
- ret = snd_soc_dapm_new_pcm(card, rtd, dai_link->params,
1484
- dai_link->num_params,
1485
- source, sink);
1486
- if (ret != 0) {
1487
- dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1488
- sink->name, source->name, ret);
1489
- return ret;
1490
- }
1491
- }
1492
-
1493
- sink = cpu_dai->playback_widget;
1494
- source = codec_dai->capture_widget;
1495
- if (sink && source) {
1496
- ret = snd_soc_dapm_new_pcm(card, rtd, dai_link->params,
1497
- dai_link->num_params,
1498
- source, sink);
1499
- if (ret != 0) {
1500
- dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1501
- sink->name, source->name, ret);
1502
- return ret;
1503
- }
1504
- }
1505
-
1506
- return 0;
1507
-}
1508
-
1509
-static int soc_probe_link_dais(struct snd_soc_card *card,
1510
- struct snd_soc_pcm_runtime *rtd, int order)
1511
-{
1512
- struct snd_soc_dai_link *dai_link = rtd->dai_link;
1513
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1514
- struct snd_soc_rtdcom_list *rtdcom;
1515
- struct snd_soc_component *component;
1516
- int i, ret, num;
1517
-
1518
- dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
1519
- card->name, rtd->num, order);
1520
-
1521
- /* set default power off timeout */
1522
- rtd->pmdown_time = pmdown_time;
1523
-
1524
- ret = soc_probe_dai(cpu_dai, order);
1525
- if (ret)
1526
- return ret;
1527
-
1528
- /* probe the CODEC DAI */
1529
- for (i = 0; i < rtd->num_codecs; i++) {
1530
- ret = soc_probe_dai(rtd->codec_dais[i], order);
1531
- if (ret)
1532
- return ret;
1533
- }
1534
-
1535
- /* complete DAI probe during last probe */
1536
- if (order != SND_SOC_COMP_ORDER_LAST)
1537
- return 0;
1538
-
1539
- /* do machine specific initialization */
1540
- if (dai_link->init) {
1541
- ret = dai_link->init(rtd);
1542
- if (ret < 0) {
1543
- dev_err(card->dev, "ASoC: failed to init %s: %d\n",
1544
- dai_link->name, ret);
1545
- return ret;
1546
- }
1547
- }
1548
-
1549
- if (dai_link->dai_fmt)
1550
- snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
1551
-
1552
- ret = soc_post_component_init(rtd, dai_link->name);
1553
- if (ret)
1554
- return ret;
1555
-
1556
-#ifdef CONFIG_DEBUG_FS
1557
- /* add DPCM sysfs entries */
1558
- if (dai_link->dynamic)
1559
- soc_dpcm_debugfs_add(rtd);
1560
-#endif
1561
-
1562
- num = rtd->num;
1563
-
1564
- /*
1565
- * most drivers will register their PCMs using DAI link ordering but
1566
- * topology based drivers can use the DAI link id field to set PCM
1567
- * device number and then use rtd + a base offset of the BEs.
1568
- */
1569
- for_each_rtdcom(rtd, rtdcom) {
1570
- component = rtdcom->component;
1571
-
1572
- if (!component->driver->use_dai_pcm_id)
1573
- continue;
1574
-
1575
- if (rtd->dai_link->no_pcm)
1576
- num += component->driver->be_pcm_base;
1577
- else
1578
- num = rtd->dai_link->id;
1579
- }
1580
-
1581
- if (cpu_dai->driver->compress_new) {
1582
- /*create compress_device"*/
1583
- ret = cpu_dai->driver->compress_new(rtd, num);
1584
- if (ret < 0) {
1585
- dev_err(card->dev, "ASoC: can't create compress %s\n",
1586
- dai_link->stream_name);
1587
- return ret;
1588
- }
1589
- } else {
1590
-
1591
- if (!dai_link->params) {
1592
- /* create the pcm */
1593
- ret = soc_new_pcm(rtd, num);
1594
- if (ret < 0) {
1595
- dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1596
- dai_link->stream_name, ret);
1597
- return ret;
1598
- }
1599
- ret = soc_link_dai_pcm_new(&cpu_dai, 1, rtd);
1600
- if (ret < 0)
1601
- return ret;
1602
- ret = soc_link_dai_pcm_new(rtd->codec_dais,
1603
- rtd->num_codecs, rtd);
1604
- if (ret < 0)
1605
- return ret;
1606
- } else {
1607
- INIT_DELAYED_WORK(&rtd->delayed_work,
1608
- codec2codec_close_delayed_work);
1609
-
1610
- /* link the DAI widgets */
1611
- ret = soc_link_dai_widgets(card, dai_link, rtd);
1295
+ /* probe all rtd connected DAIs in good order */
1296
+ ret = snd_soc_pcm_dai_probe(rtd, order);
16121297 if (ret)
16131298 return ret;
16141299 }
....@@ -1617,62 +1302,91 @@
16171302 return 0;
16181303 }
16191304
1620
-static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
1305
+static void soc_remove_link_components(struct snd_soc_card *card)
16211306 {
1622
- struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
16231307 struct snd_soc_component *component;
1624
- const char *name;
1625
- struct device_node *codec_of_node;
1308
+ struct snd_soc_pcm_runtime *rtd;
1309
+ int i, order;
16261310
1627
- if (aux_dev->codec_of_node || aux_dev->codec_name) {
1628
- /* codecs, usually analog devices */
1629
- name = aux_dev->codec_name;
1630
- codec_of_node = aux_dev->codec_of_node;
1631
- component = soc_find_component(codec_of_node, name);
1632
- if (!component) {
1633
- if (codec_of_node)
1634
- name = of_node_full_name(codec_of_node);
1635
- goto err_defer;
1311
+ for_each_comp_order(order) {
1312
+ for_each_card_rtds(card, rtd) {
1313
+ for_each_rtd_components(rtd, i, component) {
1314
+ if (component->driver->remove_order != order)
1315
+ continue;
1316
+
1317
+ soc_remove_component(component, 1);
1318
+ }
16361319 }
1637
- } else if (aux_dev->name) {
1638
- /* generic components */
1639
- name = aux_dev->name;
1640
- component = soc_find_component(NULL, name);
1641
- if (!component)
1642
- goto err_defer;
1643
- } else {
1644
- dev_err(card->dev, "ASoC: Invalid auxiliary device\n");
1645
- return -EINVAL;
1320
+ }
1321
+}
1322
+
1323
+static int soc_probe_link_components(struct snd_soc_card *card)
1324
+{
1325
+ struct snd_soc_component *component;
1326
+ struct snd_soc_pcm_runtime *rtd;
1327
+ int i, ret, order;
1328
+
1329
+ for_each_comp_order(order) {
1330
+ for_each_card_rtds(card, rtd) {
1331
+ for_each_rtd_components(rtd, i, component) {
1332
+ if (component->driver->probe_order != order)
1333
+ continue;
1334
+
1335
+ ret = soc_probe_component(card, component);
1336
+ if (ret < 0)
1337
+ return ret;
1338
+ }
1339
+ }
16461340 }
16471341
1648
- component->init = aux_dev->init;
1649
- list_add(&component->card_aux_list, &card->aux_comp_list);
1650
-
16511342 return 0;
1343
+}
16521344
1653
-err_defer:
1654
- dev_err(card->dev, "ASoC: %s not registered\n", name);
1655
- return -EPROBE_DEFER;
1345
+static void soc_unbind_aux_dev(struct snd_soc_card *card)
1346
+{
1347
+ struct snd_soc_component *component, *_component;
1348
+
1349
+ for_each_card_auxs_safe(card, component, _component) {
1350
+ /* for snd_soc_component_init() */
1351
+ snd_soc_component_set_aux(component, NULL);
1352
+ list_del(&component->card_aux_list);
1353
+ }
1354
+}
1355
+
1356
+static int soc_bind_aux_dev(struct snd_soc_card *card)
1357
+{
1358
+ struct snd_soc_component *component;
1359
+ struct snd_soc_aux_dev *aux;
1360
+ int i;
1361
+
1362
+ for_each_card_pre_auxs(card, i, aux) {
1363
+ /* codecs, usually analog devices */
1364
+ component = soc_find_component(&aux->dlc);
1365
+ if (!component)
1366
+ return -EPROBE_DEFER;
1367
+
1368
+ /* for snd_soc_component_init() */
1369
+ snd_soc_component_set_aux(component, aux);
1370
+ /* see for_each_card_auxs */
1371
+ list_add(&component->card_aux_list, &card->aux_comp_list);
1372
+ }
1373
+ return 0;
16561374 }
16571375
16581376 static int soc_probe_aux_devices(struct snd_soc_card *card)
16591377 {
1660
- struct snd_soc_component *comp;
1378
+ struct snd_soc_component *component;
16611379 int order;
16621380 int ret;
16631381
1664
- for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1665
- order++) {
1666
- list_for_each_entry(comp, &card->aux_comp_list, card_aux_list) {
1667
- if (comp->driver->probe_order == order) {
1668
- ret = soc_probe_component(card, comp);
1669
- if (ret < 0) {
1670
- dev_err(card->dev,
1671
- "ASoC: failed to probe aux component %s %d\n",
1672
- comp->name, ret);
1673
- return ret;
1674
- }
1675
- }
1382
+ for_each_comp_order(order) {
1383
+ for_each_card_auxs(card, component) {
1384
+ if (component->driver->probe_order != order)
1385
+ continue;
1386
+
1387
+ ret = soc_probe_component(card, component);
1388
+ if (ret < 0)
1389
+ return ret;
16761390 }
16771391 }
16781392
....@@ -1684,16 +1398,10 @@
16841398 struct snd_soc_component *comp, *_comp;
16851399 int order;
16861400
1687
- for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1688
- order++) {
1689
- list_for_each_entry_safe(comp, _comp,
1690
- &card->aux_comp_list, card_aux_list) {
1691
-
1692
- if (comp->driver->remove_order == order) {
1693
- soc_remove_component(comp);
1694
- /* remove it from the card's aux_comp_list */
1695
- list_del(&comp->card_aux_list);
1696
- }
1401
+ for_each_comp_order(order) {
1402
+ for_each_card_auxs_safe(card, comp, _comp) {
1403
+ if (comp->driver->remove_order == order)
1404
+ soc_remove_component(comp, 1);
16971405 }
16981406 }
16991407 }
....@@ -1714,14 +1422,13 @@
17141422 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
17151423 unsigned int dai_fmt)
17161424 {
1717
- struct snd_soc_dai **codec_dais = rtd->codec_dais;
1718
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1425
+ struct snd_soc_dai *cpu_dai;
1426
+ struct snd_soc_dai *codec_dai;
1427
+ unsigned int inv_dai_fmt;
17191428 unsigned int i;
17201429 int ret;
17211430
1722
- for (i = 0; i < rtd->num_codecs; i++) {
1723
- struct snd_soc_dai *codec_dai = codec_dais[i];
1724
-
1431
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
17251432 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
17261433 if (ret != 0 && ret != -ENOTSUPP) {
17271434 dev_warn(codec_dai->dev,
....@@ -1730,44 +1437,61 @@
17301437 }
17311438 }
17321439
1733
- /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */
1734
- /* the component which has non_legacy_dai_naming is Codec */
1735
- if (cpu_dai->component->driver->non_legacy_dai_naming) {
1736
- unsigned int inv_dai_fmt;
1737
-
1738
- inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1739
- switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1740
- case SND_SOC_DAIFMT_CBM_CFM:
1741
- inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1742
- break;
1743
- case SND_SOC_DAIFMT_CBM_CFS:
1744
- inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1745
- break;
1746
- case SND_SOC_DAIFMT_CBS_CFM:
1747
- inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1748
- break;
1749
- case SND_SOC_DAIFMT_CBS_CFS:
1750
- inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1751
- break;
1752
- }
1753
-
1754
- dai_fmt = inv_dai_fmt;
1440
+ /*
1441
+ * Flip the polarity for the "CPU" end of a CODEC<->CODEC link
1442
+ * the component which has non_legacy_dai_naming is Codec
1443
+ */
1444
+ inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1445
+ switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1446
+ case SND_SOC_DAIFMT_CBM_CFM:
1447
+ inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1448
+ break;
1449
+ case SND_SOC_DAIFMT_CBM_CFS:
1450
+ inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1451
+ break;
1452
+ case SND_SOC_DAIFMT_CBS_CFM:
1453
+ inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1454
+ break;
1455
+ case SND_SOC_DAIFMT_CBS_CFS:
1456
+ inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1457
+ break;
17551458 }
1459
+ for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
1460
+ unsigned int fmt = dai_fmt;
17561461
1757
- ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
1758
- if (ret != 0 && ret != -ENOTSUPP) {
1759
- dev_warn(cpu_dai->dev,
1760
- "ASoC: Failed to set DAI format: %d\n", ret);
1761
- return ret;
1462
+ if (cpu_dai->component->driver->non_legacy_dai_naming)
1463
+ fmt = inv_dai_fmt;
1464
+
1465
+ ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
1466
+ if (ret != 0 && ret != -ENOTSUPP) {
1467
+ dev_warn(cpu_dai->dev,
1468
+ "ASoC: Failed to set DAI format: %d\n", ret);
1469
+ return ret;
1470
+ }
17621471 }
17631472
17641473 return 0;
17651474 }
17661475 EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
17671476
1768
-
17691477 #ifdef CONFIG_DMI
1770
-/* Trim special characters, and replace '-' with '_' since '-' is used to
1478
+/*
1479
+ * If a DMI filed contain strings in this blacklist (e.g.
1480
+ * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
1481
+ * as invalid and dropped when setting the card long name from DMI info.
1482
+ */
1483
+static const char * const dmi_blacklist[] = {
1484
+ "To be filled by OEM",
1485
+ "TBD by OEM",
1486
+ "Default String",
1487
+ "Board Manufacturer",
1488
+ "Board Vendor Name",
1489
+ "Board Product Name",
1490
+ NULL, /* terminator */
1491
+};
1492
+
1493
+/*
1494
+ * Trim special characters, and replace '-' with '_' since '-' is used to
17711495 * separate different DMI fields in the card long name. Only number and
17721496 * alphabet characters and a few separator characters are kept.
17731497 */
....@@ -1786,7 +1510,8 @@
17861510 name[j] = '\0';
17871511 }
17881512
1789
-/* Check if a DMI field is valid, i.e. not containing any string
1513
+/*
1514
+ * Check if a DMI field is valid, i.e. not containing any string
17901515 * in the black list.
17911516 */
17921517 static int is_dmi_valid(const char *field)
....@@ -1800,6 +1525,23 @@
18001525 }
18011526
18021527 return 1;
1528
+}
1529
+
1530
+/*
1531
+ * Append a string to card->dmi_longname with character cleanups.
1532
+ */
1533
+static void append_dmi_string(struct snd_soc_card *card, const char *str)
1534
+{
1535
+ char *dst = card->dmi_longname;
1536
+ size_t dst_len = sizeof(card->dmi_longname);
1537
+ size_t len;
1538
+
1539
+ len = strlen(dst);
1540
+ snprintf(dst + len, dst_len - len, "-%s", str);
1541
+
1542
+ len++; /* skip the separator "-" */
1543
+ if (len < dst_len)
1544
+ cleanup_dmi_name(dst + len);
18031545 }
18041546
18051547 /**
....@@ -1836,61 +1578,40 @@
18361578 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
18371579 {
18381580 const char *vendor, *product, *product_version, *board;
1839
- size_t longname_buf_size = sizeof(card->snd_card->longname);
1840
- size_t len;
18411581
18421582 if (card->long_name)
18431583 return 0; /* long name already set by driver or from DMI */
18441584
1845
- /* make up dmi long name as: vendor.product.version.board */
1585
+ if (!is_acpi_device_node(card->dev->fwnode))
1586
+ return 0;
1587
+
1588
+ /* make up dmi long name as: vendor-product-version-board */
18461589 vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
18471590 if (!vendor || !is_dmi_valid(vendor)) {
18481591 dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
18491592 return 0;
18501593 }
18511594
1852
-
1853
- snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
1854
- "%s", vendor);
1595
+ snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
18551596 cleanup_dmi_name(card->dmi_longname);
18561597
18571598 product = dmi_get_system_info(DMI_PRODUCT_NAME);
18581599 if (product && is_dmi_valid(product)) {
1859
- len = strlen(card->dmi_longname);
1860
- snprintf(card->dmi_longname + len,
1861
- longname_buf_size - len,
1862
- "-%s", product);
1600
+ append_dmi_string(card, product);
18631601
1864
- len++; /* skip the separator "-" */
1865
- if (len < longname_buf_size)
1866
- cleanup_dmi_name(card->dmi_longname + len);
1867
-
1868
- /* some vendors like Lenovo may only put a self-explanatory
1602
+ /*
1603
+ * some vendors like Lenovo may only put a self-explanatory
18691604 * name in the product version field
18701605 */
18711606 product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
1872
- if (product_version && is_dmi_valid(product_version)) {
1873
- len = strlen(card->dmi_longname);
1874
- snprintf(card->dmi_longname + len,
1875
- longname_buf_size - len,
1876
- "-%s", product_version);
1877
-
1878
- len++;
1879
- if (len < longname_buf_size)
1880
- cleanup_dmi_name(card->dmi_longname + len);
1881
- }
1607
+ if (product_version && is_dmi_valid(product_version))
1608
+ append_dmi_string(card, product_version);
18821609 }
18831610
18841611 board = dmi_get_system_info(DMI_BOARD_NAME);
18851612 if (board && is_dmi_valid(board)) {
1886
- len = strlen(card->dmi_longname);
1887
- snprintf(card->dmi_longname + len,
1888
- longname_buf_size - len,
1889
- "-%s", board);
1890
-
1891
- len++;
1892
- if (len < longname_buf_size)
1893
- cleanup_dmi_name(card->dmi_longname + len);
1613
+ if (!product || strcasecmp(board, product))
1614
+ append_dmi_string(card, board);
18941615 } else if (!product) {
18951616 /* fall back to using legacy name */
18961617 dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
....@@ -1898,16 +1619,8 @@
18981619 }
18991620
19001621 /* Add flavour to dmi long name */
1901
- if (flavour) {
1902
- len = strlen(card->dmi_longname);
1903
- snprintf(card->dmi_longname + len,
1904
- longname_buf_size - len,
1905
- "-%s", flavour);
1906
-
1907
- len++;
1908
- if (len < longname_buf_size)
1909
- cleanup_dmi_name(card->dmi_longname + len);
1910
- }
1622
+ if (flavour)
1623
+ append_dmi_string(card, flavour);
19111624
19121625 /* set the card long name */
19131626 card->long_name = card->dmi_longname;
....@@ -1924,21 +1637,22 @@
19241637 struct snd_soc_dai_link *dai_link;
19251638 int i;
19261639
1927
- list_for_each_entry(component, &component_list, list) {
1640
+ for_each_component(component) {
19281641
1929
- /* does this component override FEs ? */
1642
+ /* does this component override BEs ? */
19301643 if (!component->driver->ignore_machine)
19311644 continue;
19321645
19331646 /* for this machine ? */
1647
+ if (!strcmp(component->driver->ignore_machine,
1648
+ card->dev->driver->name))
1649
+ goto match;
19341650 if (strcmp(component->driver->ignore_machine,
1935
- card->dev->driver->name))
1651
+ dev_name(card->dev)))
19361652 continue;
1937
-
1653
+match:
19381654 /* machine matches, so override the rtd data */
1939
- for (i = 0; i < card->num_links; i++) {
1940
-
1941
- dai_link = &card->dai_link[i];
1655
+ for_each_card_prelinks(card, i, dai_link) {
19421656
19431657 /* ignore this FE */
19441658 if (dai_link->dynamic) {
....@@ -1946,11 +1660,15 @@
19461660 continue;
19471661 }
19481662
1949
- dev_info(card->dev, "info: override FE DAI link %s\n",
1950
- card->dai_link[i].name);
1663
+ dev_dbg(card->dev, "info: override BE DAI link %s\n",
1664
+ card->dai_link[i].name);
19511665
19521666 /* override platform component */
1953
- dai_link->platform_name = component->name;
1667
+ if (!dai_link->platforms) {
1668
+ dev_err(card->dev, "init platform error");
1669
+ continue;
1670
+ }
1671
+ dai_link->platforms->name = component->name;
19541672
19551673 /* convert non BE into BE */
19561674 if (!dai_link->no_pcm) {
....@@ -1973,11 +1691,16 @@
19731691 }
19741692 }
19751693
1976
- /* override any BE fixups */
1694
+ /*
1695
+ * override any BE fixups
1696
+ * see
1697
+ * snd_soc_link_be_hw_params_fixup()
1698
+ */
19771699 dai_link->be_hw_params_fixup =
19781700 component->driver->be_hw_params_fixup;
19791701
1980
- /* most BE links don't set stream name, so set it to
1702
+ /*
1703
+ * most BE links don't set stream name, so set it to
19811704 * dai link name if it's NULL to help bind widgets.
19821705 */
19831706 if (!dai_link->stream_name)
....@@ -1987,7 +1710,7 @@
19871710 /* Inform userspace we are using alternate topology */
19881711 if (component->driver->topology_name_prefix) {
19891712
1990
- /* topology shortname created ? */
1713
+ /* topology shortname created? */
19911714 if (!card->topology_shortname_created) {
19921715 comp_drv = component->driver;
19931716
....@@ -2003,35 +1726,116 @@
20031726 }
20041727 }
20051728
2006
-static int snd_soc_instantiate_card(struct snd_soc_card *card)
1729
+#define soc_setup_card_name(name, name1, name2, norm) \
1730
+ __soc_setup_card_name(name, sizeof(name), name1, name2, norm)
1731
+static void __soc_setup_card_name(char *name, int len,
1732
+ const char *name1, const char *name2,
1733
+ int normalization)
1734
+{
1735
+ int i;
1736
+
1737
+ snprintf(name, len, "%s", name1 ? name1 : name2);
1738
+
1739
+ if (!normalization)
1740
+ return;
1741
+
1742
+ /*
1743
+ * Name normalization
1744
+ *
1745
+ * The driver name is somewhat special, as it's used as a key for
1746
+ * searches in the user-space.
1747
+ *
1748
+ * ex)
1749
+ * "abcd??efg" -> "abcd__efg"
1750
+ */
1751
+ for (i = 0; i < len; i++) {
1752
+ switch (name[i]) {
1753
+ case '_':
1754
+ case '-':
1755
+ case '\0':
1756
+ break;
1757
+ default:
1758
+ if (!isalnum(name[i]))
1759
+ name[i] = '_';
1760
+ break;
1761
+ }
1762
+ }
1763
+}
1764
+
1765
+static void soc_cleanup_card_resources(struct snd_soc_card *card)
1766
+{
1767
+ struct snd_soc_pcm_runtime *rtd, *n;
1768
+
1769
+ if (card->snd_card)
1770
+ snd_card_disconnect_sync(card->snd_card);
1771
+
1772
+ snd_soc_dapm_shutdown(card);
1773
+
1774
+ /* remove and free each DAI */
1775
+ soc_remove_link_dais(card);
1776
+ soc_remove_link_components(card);
1777
+
1778
+ for_each_card_rtds_safe(card, rtd, n)
1779
+ snd_soc_remove_pcm_runtime(card, rtd);
1780
+
1781
+ /* remove auxiliary devices */
1782
+ soc_remove_aux_devices(card);
1783
+ soc_unbind_aux_dev(card);
1784
+
1785
+ snd_soc_dapm_free(&card->dapm);
1786
+ soc_cleanup_card_debugfs(card);
1787
+
1788
+ /* remove the card */
1789
+ snd_soc_card_remove(card);
1790
+
1791
+ if (card->snd_card) {
1792
+ snd_card_free(card->snd_card);
1793
+ card->snd_card = NULL;
1794
+ }
1795
+}
1796
+
1797
+static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister)
1798
+{
1799
+ if (card->instantiated) {
1800
+ card->instantiated = false;
1801
+ snd_soc_flush_all_delayed_work(card);
1802
+
1803
+ soc_cleanup_card_resources(card);
1804
+ if (!unregister)
1805
+ list_add(&card->list, &unbind_card_list);
1806
+ } else {
1807
+ if (unregister)
1808
+ list_del(&card->list);
1809
+ }
1810
+}
1811
+
1812
+static int snd_soc_bind_card(struct snd_soc_card *card)
20071813 {
20081814 struct snd_soc_pcm_runtime *rtd;
1815
+ struct snd_soc_component *component;
20091816 struct snd_soc_dai_link *dai_link;
2010
- int ret, i, order;
1817
+ int ret, i;
20111818
20121819 mutex_lock(&client_mutex);
20131820 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
20141821
1822
+ snd_soc_dapm_init(&card->dapm, card, NULL);
1823
+
20151824 /* check whether any platform is ignore machine FE and using topology */
20161825 soc_check_tplg_fes(card);
20171826
2018
- /* bind DAIs */
2019
- for (i = 0; i < card->num_links; i++) {
2020
- ret = soc_bind_dai_link(card, &card->dai_link[i]);
2021
- if (ret != 0)
2022
- goto base_error;
2023
- }
2024
-
20251827 /* bind aux_devs too */
2026
- for (i = 0; i < card->num_aux_devs; i++) {
2027
- ret = soc_bind_aux_dev(card, i);
2028
- if (ret != 0)
2029
- goto base_error;
2030
- }
1828
+ ret = soc_bind_aux_dev(card);
1829
+ if (ret < 0)
1830
+ goto probe_end;
20311831
20321832 /* add predefined DAI links to the list */
2033
- for (i = 0; i < card->num_links; i++)
2034
- snd_soc_add_dai_link(card, card->dai_link+i);
1833
+ card->num_rtd = 0;
1834
+ for_each_card_prelinks(card, i, dai_link) {
1835
+ ret = snd_soc_add_pcm_runtime(card, dai_link);
1836
+ if (ret < 0)
1837
+ goto probe_end;
1838
+ }
20351839
20361840 /* card bind complete so register a sound card */
20371841 ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
....@@ -2040,132 +1844,112 @@
20401844 dev_err(card->dev,
20411845 "ASoC: can't create sound card for card %s: %d\n",
20421846 card->name, ret);
2043
- goto base_error;
1847
+ goto probe_end;
20441848 }
20451849
20461850 soc_init_card_debugfs(card);
20471851
2048
- card->dapm.bias_level = SND_SOC_BIAS_OFF;
2049
- card->dapm.dev = card->dev;
2050
- card->dapm.card = card;
2051
- list_add(&card->dapm.list, &card->dapm_list);
1852
+ soc_resume_init(card);
20521853
2053
-#ifdef CONFIG_DEBUG_FS
2054
- snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
2055
-#endif
1854
+ ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1855
+ card->num_dapm_widgets);
1856
+ if (ret < 0)
1857
+ goto probe_end;
20561858
2057
-#ifdef CONFIG_PM_SLEEP
2058
- /* deferred resume work */
2059
- INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
2060
-#endif
2061
-
2062
- if (card->dapm_widgets)
2063
- snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
2064
- card->num_dapm_widgets);
2065
-
2066
- if (card->of_dapm_widgets)
2067
- snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
2068
- card->num_of_dapm_widgets);
1859
+ ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
1860
+ card->num_of_dapm_widgets);
1861
+ if (ret < 0)
1862
+ goto probe_end;
20691863
20701864 /* initialise the sound card only once */
2071
- if (card->probe) {
2072
- ret = card->probe(card);
2073
- if (ret < 0)
2074
- goto card_probe_error;
2075
- }
1865
+ ret = snd_soc_card_probe(card);
1866
+ if (ret < 0)
1867
+ goto probe_end;
20761868
20771869 /* probe all components used by DAI links on this card */
2078
- for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
2079
- order++) {
2080
- list_for_each_entry(rtd, &card->rtd_list, list) {
2081
- ret = soc_probe_link_components(card, rtd, order);
2082
- if (ret < 0) {
2083
- dev_err(card->dev,
2084
- "ASoC: failed to instantiate card %d\n",
2085
- ret);
2086
- goto probe_dai_err;
2087
- }
2088
- }
1870
+ ret = soc_probe_link_components(card);
1871
+ if (ret < 0) {
1872
+ dev_err(card->dev,
1873
+ "ASoC: failed to instantiate card %d\n", ret);
1874
+ goto probe_end;
20891875 }
20901876
20911877 /* probe auxiliary components */
20921878 ret = soc_probe_aux_devices(card);
2093
- if (ret < 0)
2094
- goto probe_dai_err;
2095
-
2096
- /* Find new DAI links added during probing components and bind them.
2097
- * Components with topology may bring new DAIs and DAI links.
2098
- */
2099
- list_for_each_entry(dai_link, &card->dai_link_list, list) {
2100
- if (soc_is_dai_link_bound(card, dai_link))
2101
- continue;
2102
-
2103
- ret = soc_init_dai_link(card, dai_link);
2104
- if (ret)
2105
- goto probe_dai_err;
2106
- ret = soc_bind_dai_link(card, dai_link);
2107
- if (ret)
2108
- goto probe_dai_err;
1879
+ if (ret < 0) {
1880
+ dev_err(card->dev,
1881
+ "ASoC: failed to probe aux component %d\n", ret);
1882
+ goto probe_end;
21091883 }
21101884
21111885 /* probe all DAI links on this card */
2112
- for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
2113
- order++) {
2114
- list_for_each_entry(rtd, &card->rtd_list, list) {
2115
- ret = soc_probe_link_dais(card, rtd, order);
2116
- if (ret < 0) {
2117
- dev_err(card->dev,
2118
- "ASoC: failed to instantiate card %d\n",
2119
- ret);
2120
- goto probe_dai_err;
2121
- }
2122
- }
1886
+ ret = soc_probe_link_dais(card);
1887
+ if (ret < 0) {
1888
+ dev_err(card->dev,
1889
+ "ASoC: failed to instantiate card %d\n", ret);
1890
+ goto probe_end;
1891
+ }
1892
+
1893
+ for_each_card_rtds(card, rtd) {
1894
+ ret = soc_init_pcm_runtime(card, rtd);
1895
+ if (ret < 0)
1896
+ goto probe_end;
21231897 }
21241898
21251899 snd_soc_dapm_link_dai_widgets(card);
21261900 snd_soc_dapm_connect_dai_link_widgets(card);
21271901
2128
- if (card->controls)
2129
- snd_soc_add_card_controls(card, card->controls, card->num_controls);
1902
+ ret = snd_soc_add_card_controls(card, card->controls,
1903
+ card->num_controls);
1904
+ if (ret < 0)
1905
+ goto probe_end;
21301906
2131
- if (card->dapm_routes)
2132
- snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
2133
- card->num_dapm_routes);
1907
+ ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1908
+ card->num_dapm_routes);
1909
+ if (ret < 0) {
1910
+ if (card->disable_route_checks) {
1911
+ dev_info(card->dev,
1912
+ "%s: disable_route_checks set, ignoring errors on add_routes\n",
1913
+ __func__);
1914
+ } else {
1915
+ dev_err(card->dev,
1916
+ "%s: snd_soc_dapm_add_routes failed: %d\n",
1917
+ __func__, ret);
1918
+ goto probe_end;
1919
+ }
1920
+ }
21341921
2135
- if (card->of_dapm_routes)
2136
- snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
2137
- card->num_of_dapm_routes);
1922
+ ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
1923
+ card->num_of_dapm_routes);
1924
+ if (ret < 0)
1925
+ goto probe_end;
21381926
21391927 /* try to set some sane longname if DMI is available */
21401928 snd_soc_set_dmi_name(card, NULL);
21411929
2142
- snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
2143
- "%s", card->name);
2144
- snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
2145
- "%s", card->long_name ? card->long_name : card->name);
2146
- snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
2147
- "%s", card->driver_name ? card->driver_name : card->name);
2148
- for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
2149
- switch (card->snd_card->driver[i]) {
2150
- case '_':
2151
- case '-':
2152
- case '\0':
2153
- break;
2154
- default:
2155
- if (!isalnum(card->snd_card->driver[i]))
2156
- card->snd_card->driver[i] = '_';
2157
- break;
1930
+ soc_setup_card_name(card->snd_card->shortname,
1931
+ card->name, NULL, 0);
1932
+ soc_setup_card_name(card->snd_card->longname,
1933
+ card->long_name, card->name, 0);
1934
+ soc_setup_card_name(card->snd_card->driver,
1935
+ card->driver_name, card->name, 1);
1936
+
1937
+ if (card->components) {
1938
+ /* the current implementation of snd_component_add() accepts */
1939
+ /* multiple components in the string separated by space, */
1940
+ /* but the string collision (identical string) check might */
1941
+ /* not work correctly */
1942
+ ret = snd_component_add(card->snd_card, card->components);
1943
+ if (ret < 0) {
1944
+ dev_err(card->dev, "ASoC: %s snd_component_add() failed: %d\n",
1945
+ card->name, ret);
1946
+ goto probe_end;
21581947 }
21591948 }
21601949
2161
- if (card->late_probe) {
2162
- ret = card->late_probe(card);
2163
- if (ret < 0) {
2164
- dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
2165
- card->name, ret);
2166
- goto probe_aux_dev_err;
2167
- }
2168
- }
1950
+ ret = snd_soc_card_late_probe(card);
1951
+ if (ret < 0)
1952
+ goto probe_end;
21691953
21701954 snd_soc_dapm_new_widgets(card);
21711955
....@@ -2173,34 +1957,22 @@
21731957 if (ret < 0) {
21741958 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
21751959 ret);
2176
- goto probe_aux_dev_err;
1960
+ goto probe_end;
21771961 }
21781962
21791963 card->instantiated = 1;
21801964 dapm_mark_endpoints_dirty(card);
21811965 snd_soc_dapm_sync(&card->dapm);
2182
- mutex_unlock(&card->mutex);
2183
- mutex_unlock(&client_mutex);
21841966
2185
- return 0;
1967
+ /* deactivate pins to sleep state */
1968
+ for_each_card_components(card, component)
1969
+ if (!snd_soc_component_active(component))
1970
+ pinctrl_pm_select_sleep_state(component->dev);
21861971
2187
-probe_aux_dev_err:
2188
- soc_remove_aux_devices(card);
1972
+probe_end:
1973
+ if (ret < 0)
1974
+ soc_cleanup_card_resources(card);
21891975
2190
-probe_dai_err:
2191
- if (ret != -ENODEV)
2192
- soc_remove_dai_links(card);
2193
-
2194
-card_probe_error:
2195
- if (card->remove)
2196
- card->remove(card);
2197
-
2198
- snd_soc_dapm_free(&card->dapm);
2199
- soc_cleanup_card_debugfs(card);
2200
- snd_card_free(card->snd_card);
2201
-
2202
-base_error:
2203
- soc_remove_pcm_runtimes(card);
22041976 mutex_unlock(&card->mutex);
22051977 mutex_unlock(&client_mutex);
22061978
....@@ -2226,72 +1998,28 @@
22261998 /* Bodge while we unpick instantiation */
22271999 card->dev = &pdev->dev;
22282000
2229
- return snd_soc_register_card(card);
2230
-}
2231
-
2232
-static int soc_cleanup_card_resources(struct snd_soc_card *card)
2233
-{
2234
- struct snd_soc_pcm_runtime *rtd;
2235
-
2236
- /* make sure any delayed work runs */
2237
- list_for_each_entry(rtd, &card->rtd_list, list)
2238
- flush_delayed_work(&rtd->delayed_work);
2239
-
2240
- /* free the ALSA card at first; this syncs with pending operations */
2241
- snd_card_free(card->snd_card);
2242
-
2243
- /* remove and free each DAI */
2244
- soc_remove_dai_links(card);
2245
- soc_remove_pcm_runtimes(card);
2246
-
2247
- /* remove auxiliary devices */
2248
- soc_remove_aux_devices(card);
2249
-
2250
- snd_soc_dapm_free(&card->dapm);
2251
- soc_cleanup_card_debugfs(card);
2252
-
2253
- /* remove the card */
2254
- if (card->remove)
2255
- card->remove(card);
2256
-
2257
- return 0;
2258
-}
2259
-
2260
-/* removes a socdev */
2261
-static int soc_remove(struct platform_device *pdev)
2262
-{
2263
- struct snd_soc_card *card = platform_get_drvdata(pdev);
2264
-
2265
- snd_soc_unregister_card(card);
2266
- return 0;
2001
+ return devm_snd_soc_register_card(&pdev->dev, card);
22672002 }
22682003
22692004 int snd_soc_poweroff(struct device *dev)
22702005 {
22712006 struct snd_soc_card *card = dev_get_drvdata(dev);
2272
- struct snd_soc_pcm_runtime *rtd;
2007
+ struct snd_soc_component *component;
22732008
22742009 if (!card->instantiated)
22752010 return 0;
22762011
2277
- /* Flush out pmdown_time work - we actually do want to run it
2278
- * now, we're shutting down so no imminent restart. */
2279
- list_for_each_entry(rtd, &card->rtd_list, list)
2280
- flush_delayed_work(&rtd->delayed_work);
2012
+ /*
2013
+ * Flush out pmdown_time work - we actually do want to run it
2014
+ * now, we're shutting down so no imminent restart.
2015
+ */
2016
+ snd_soc_flush_all_delayed_work(card);
22812017
22822018 snd_soc_dapm_shutdown(card);
22832019
22842020 /* deactivate pins to sleep state */
2285
- list_for_each_entry(rtd, &card->rtd_list, list) {
2286
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2287
- int i;
2288
-
2289
- pinctrl_pm_select_sleep_state(cpu_dai->dev);
2290
- for (i = 0; i < rtd->num_codecs; i++) {
2291
- struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
2292
- pinctrl_pm_select_sleep_state(codec_dai->dev);
2293
- }
2294
- }
2021
+ for_each_card_components(card, component)
2022
+ pinctrl_pm_select_sleep_state(component->dev);
22952023
22962024 return 0;
22972025 }
....@@ -2314,7 +2042,6 @@
23142042 .pm = &snd_soc_pm_ops,
23152043 },
23162044 .probe = soc_probe,
2317
- .remove = soc_remove,
23182045 };
23192046
23202047 /**
....@@ -2368,6 +2095,7 @@
23682095
23692096 for (i = 0; i < num_controls; i++) {
23702097 const struct snd_kcontrol_new *control = &controls[i];
2098
+
23712099 err = snd_ctl_add(card, snd_soc_cnew(control, data,
23722100 control->name, prefix));
23732101 if (err < 0) {
....@@ -2379,22 +2107,6 @@
23792107
23802108 return 0;
23812109 }
2382
-
2383
-struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
2384
- const char *name)
2385
-{
2386
- struct snd_card *card = soc_card->snd_card;
2387
- struct snd_kcontrol *kctl;
2388
-
2389
- if (unlikely(!name))
2390
- return NULL;
2391
-
2392
- list_for_each_entry(kctl, &card->controls, list)
2393
- if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
2394
- return kctl;
2395
- return NULL;
2396
-}
2397
-EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
23982110
23992111 /**
24002112 * snd_soc_add_component_controls - Add an array of controls to a component.
....@@ -2456,297 +2168,6 @@
24562168 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
24572169
24582170 /**
2459
- * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2460
- * @dai: DAI
2461
- * @clk_id: DAI specific clock ID
2462
- * @freq: new clock frequency in Hz
2463
- * @dir: new clock direction - input/output.
2464
- *
2465
- * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2466
- */
2467
-int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2468
- unsigned int freq, int dir)
2469
-{
2470
- if (dai->driver->ops->set_sysclk)
2471
- return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2472
-
2473
- return snd_soc_component_set_sysclk(dai->component, clk_id, 0,
2474
- freq, dir);
2475
-}
2476
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2477
-
2478
-/**
2479
- * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
2480
- * @component: COMPONENT
2481
- * @clk_id: DAI specific clock ID
2482
- * @source: Source for the clock
2483
- * @freq: new clock frequency in Hz
2484
- * @dir: new clock direction - input/output.
2485
- *
2486
- * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2487
- */
2488
-int snd_soc_component_set_sysclk(struct snd_soc_component *component, int clk_id,
2489
- int source, unsigned int freq, int dir)
2490
-{
2491
- if (component->driver->set_sysclk)
2492
- return component->driver->set_sysclk(component, clk_id, source,
2493
- freq, dir);
2494
-
2495
- return -ENOTSUPP;
2496
-}
2497
-EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
2498
-
2499
-/**
2500
- * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2501
- * @dai: DAI
2502
- * @div_id: DAI specific clock divider ID
2503
- * @div: new clock divisor.
2504
- *
2505
- * Configures the clock dividers. This is used to derive the best DAI bit and
2506
- * frame clocks from the system or master clock. It's best to set the DAI bit
2507
- * and frame clocks as low as possible to save system power.
2508
- */
2509
-int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2510
- int div_id, int div)
2511
-{
2512
- if (dai->driver->ops->set_clkdiv)
2513
- return dai->driver->ops->set_clkdiv(dai, div_id, div);
2514
- else
2515
- return -EINVAL;
2516
-}
2517
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2518
-
2519
-/**
2520
- * snd_soc_dai_set_pll - configure DAI PLL.
2521
- * @dai: DAI
2522
- * @pll_id: DAI specific PLL ID
2523
- * @source: DAI specific source for the PLL
2524
- * @freq_in: PLL input clock frequency in Hz
2525
- * @freq_out: requested PLL output clock frequency in Hz
2526
- *
2527
- * Configures and enables PLL to generate output clock based on input clock.
2528
- */
2529
-int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2530
- unsigned int freq_in, unsigned int freq_out)
2531
-{
2532
- if (dai->driver->ops->set_pll)
2533
- return dai->driver->ops->set_pll(dai, pll_id, source,
2534
- freq_in, freq_out);
2535
-
2536
- return snd_soc_component_set_pll(dai->component, pll_id, source,
2537
- freq_in, freq_out);
2538
-}
2539
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2540
-
2541
-/*
2542
- * snd_soc_component_set_pll - configure component PLL.
2543
- * @component: COMPONENT
2544
- * @pll_id: DAI specific PLL ID
2545
- * @source: DAI specific source for the PLL
2546
- * @freq_in: PLL input clock frequency in Hz
2547
- * @freq_out: requested PLL output clock frequency in Hz
2548
- *
2549
- * Configures and enables PLL to generate output clock based on input clock.
2550
- */
2551
-int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
2552
- int source, unsigned int freq_in,
2553
- unsigned int freq_out)
2554
-{
2555
- if (component->driver->set_pll)
2556
- return component->driver->set_pll(component, pll_id, source,
2557
- freq_in, freq_out);
2558
-
2559
- return -EINVAL;
2560
-}
2561
-EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
2562
-
2563
-/**
2564
- * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
2565
- * @dai: DAI
2566
- * @ratio: Ratio of BCLK to Sample rate.
2567
- *
2568
- * Configures the DAI for a preset BCLK to sample rate ratio.
2569
- */
2570
-int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2571
-{
2572
- if (dai->driver->ops->set_bclk_ratio)
2573
- return dai->driver->ops->set_bclk_ratio(dai, ratio);
2574
- else
2575
- return -EINVAL;
2576
-}
2577
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
2578
-
2579
-/**
2580
- * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2581
- * @dai: DAI
2582
- * @fmt: SND_SOC_DAIFMT_* format value.
2583
- *
2584
- * Configures the DAI hardware format and clocking.
2585
- */
2586
-int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2587
-{
2588
- if (dai->driver == NULL)
2589
- return -EINVAL;
2590
- if (dai->driver->ops->set_fmt == NULL)
2591
- return -ENOTSUPP;
2592
- return dai->driver->ops->set_fmt(dai, fmt);
2593
-}
2594
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2595
-
2596
-/**
2597
- * snd_soc_xlate_tdm_slot - generate tx/rx slot mask.
2598
- * @slots: Number of slots in use.
2599
- * @tx_mask: bitmask representing active TX slots.
2600
- * @rx_mask: bitmask representing active RX slots.
2601
- *
2602
- * Generates the TDM tx and rx slot default masks for DAI.
2603
- */
2604
-static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
2605
- unsigned int *tx_mask,
2606
- unsigned int *rx_mask)
2607
-{
2608
- if (*tx_mask || *rx_mask)
2609
- return 0;
2610
-
2611
- if (!slots)
2612
- return -EINVAL;
2613
-
2614
- *tx_mask = (1 << slots) - 1;
2615
- *rx_mask = (1 << slots) - 1;
2616
-
2617
- return 0;
2618
-}
2619
-
2620
-/**
2621
- * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation
2622
- * @dai: The DAI to configure
2623
- * @tx_mask: bitmask representing active TX slots.
2624
- * @rx_mask: bitmask representing active RX slots.
2625
- * @slots: Number of slots in use.
2626
- * @slot_width: Width in bits for each slot.
2627
- *
2628
- * This function configures the specified DAI for TDM operation. @slot contains
2629
- * the total number of slots of the TDM stream and @slot_with the width of each
2630
- * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the
2631
- * active slots of the TDM stream for the specified DAI, i.e. which slots the
2632
- * DAI should write to or read from. If a bit is set the corresponding slot is
2633
- * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to
2634
- * the first slot, bit 1 to the second slot and so on. The first active slot
2635
- * maps to the first channel of the DAI, the second active slot to the second
2636
- * channel and so on.
2637
- *
2638
- * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask,
2639
- * @rx_mask and @slot_width will be ignored.
2640
- *
2641
- * Returns 0 on success, a negative error code otherwise.
2642
- */
2643
-int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2644
- unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2645
-{
2646
- if (dai->driver->ops->xlate_tdm_slot_mask)
2647
- dai->driver->ops->xlate_tdm_slot_mask(slots,
2648
- &tx_mask, &rx_mask);
2649
- else
2650
- snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
2651
-
2652
- dai->tx_mask = tx_mask;
2653
- dai->rx_mask = rx_mask;
2654
-
2655
- if (dai->driver->ops->set_tdm_slot)
2656
- return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2657
- slots, slot_width);
2658
- else
2659
- return -ENOTSUPP;
2660
-}
2661
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2662
-
2663
-/**
2664
- * snd_soc_dai_set_channel_map - configure DAI audio channel map
2665
- * @dai: DAI
2666
- * @tx_num: how many TX channels
2667
- * @tx_slot: pointer to an array which imply the TX slot number channel
2668
- * 0~num-1 uses
2669
- * @rx_num: how many RX channels
2670
- * @rx_slot: pointer to an array which imply the RX slot number channel
2671
- * 0~num-1 uses
2672
- *
2673
- * configure the relationship between channel number and TDM slot number.
2674
- */
2675
-int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2676
- unsigned int tx_num, unsigned int *tx_slot,
2677
- unsigned int rx_num, unsigned int *rx_slot)
2678
-{
2679
- if (dai->driver->ops->set_channel_map)
2680
- return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2681
- rx_num, rx_slot);
2682
- else
2683
- return -EINVAL;
2684
-}
2685
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2686
-
2687
-/**
2688
- * snd_soc_dai_get_channel_map - Get DAI audio channel map
2689
- * @dai: DAI
2690
- * @tx_num: how many TX channels
2691
- * @tx_slot: pointer to an array which imply the TX slot number channel
2692
- * 0~num-1 uses
2693
- * @rx_num: how many RX channels
2694
- * @rx_slot: pointer to an array which imply the RX slot number channel
2695
- * 0~num-1 uses
2696
- */
2697
-int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai,
2698
- unsigned int *tx_num, unsigned int *tx_slot,
2699
- unsigned int *rx_num, unsigned int *rx_slot)
2700
-{
2701
- if (dai->driver->ops->get_channel_map)
2702
- return dai->driver->ops->get_channel_map(dai, tx_num, tx_slot,
2703
- rx_num, rx_slot);
2704
- else
2705
- return -ENOTSUPP;
2706
-}
2707
-EXPORT_SYMBOL_GPL(snd_soc_dai_get_channel_map);
2708
-
2709
-/**
2710
- * snd_soc_dai_set_tristate - configure DAI system or master clock.
2711
- * @dai: DAI
2712
- * @tristate: tristate enable
2713
- *
2714
- * Tristates the DAI so that others can use it.
2715
- */
2716
-int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2717
-{
2718
- if (dai->driver->ops->set_tristate)
2719
- return dai->driver->ops->set_tristate(dai, tristate);
2720
- else
2721
- return -EINVAL;
2722
-}
2723
-EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2724
-
2725
-/**
2726
- * snd_soc_dai_digital_mute - configure DAI system or master clock.
2727
- * @dai: DAI
2728
- * @mute: mute enable
2729
- * @direction: stream to mute
2730
- *
2731
- * Mutes the DAI DAC.
2732
- */
2733
-int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
2734
- int direction)
2735
-{
2736
- if (!dai->driver)
2737
- return -ENOTSUPP;
2738
-
2739
- if (dai->driver->ops->mute_stream)
2740
- return dai->driver->ops->mute_stream(dai, mute, direction);
2741
- else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
2742
- dai->driver->ops->digital_mute)
2743
- return dai->driver->ops->digital_mute(dai, mute);
2744
- else
2745
- return -ENOTSUPP;
2746
-}
2747
-EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2748
-
2749
-/**
27502171 * snd_soc_register_card - Register a card with the ASoC core
27512172 *
27522173 * @card: Card to register
....@@ -2754,60 +2175,28 @@
27542175 */
27552176 int snd_soc_register_card(struct snd_soc_card *card)
27562177 {
2757
- int i, ret;
2758
- struct snd_soc_pcm_runtime *rtd;
2759
-
27602178 if (!card->name || !card->dev)
27612179 return -EINVAL;
27622180
2763
- for (i = 0; i < card->num_links; i++) {
2764
- struct snd_soc_dai_link *link = &card->dai_link[i];
2765
-
2766
- ret = soc_init_dai_link(card, link);
2767
- if (ret) {
2768
- dev_err(card->dev, "ASoC: failed to init link %s\n",
2769
- link->name);
2770
- return ret;
2771
- }
2772
- }
2773
-
27742181 dev_set_drvdata(card->dev, card);
27752182
2776
- snd_soc_initialize_card_lists(card);
2777
-
2778
- INIT_LIST_HEAD(&card->dai_link_list);
2779
- card->num_dai_links = 0;
2780
-
2183
+ INIT_LIST_HEAD(&card->widgets);
2184
+ INIT_LIST_HEAD(&card->paths);
2185
+ INIT_LIST_HEAD(&card->dapm_list);
2186
+ INIT_LIST_HEAD(&card->aux_comp_list);
2187
+ INIT_LIST_HEAD(&card->component_dev_list);
2188
+ INIT_LIST_HEAD(&card->list);
27812189 INIT_LIST_HEAD(&card->rtd_list);
2782
- card->num_rtd = 0;
2783
-
27842190 INIT_LIST_HEAD(&card->dapm_dirty);
27852191 INIT_LIST_HEAD(&card->dobj_list);
2192
+
27862193 card->instantiated = 0;
27872194 mutex_init(&card->mutex);
27882195 mutex_init(&card->dapm_mutex);
2789
- mutex_init(&card->dapm_power_mutex);
2196
+ mutex_init(&card->pcm_mutex);
2197
+ spin_lock_init(&card->dpcm_lock);
27902198
2791
- ret = snd_soc_instantiate_card(card);
2792
- if (ret != 0)
2793
- return ret;
2794
-
2795
- /* deactivate pins to sleep state */
2796
- list_for_each_entry(rtd, &card->rtd_list, list) {
2797
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2798
- int j;
2799
-
2800
- for (j = 0; j < rtd->num_codecs; j++) {
2801
- struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
2802
- if (!codec_dai->active)
2803
- pinctrl_pm_select_sleep_state(codec_dai->dev);
2804
- }
2805
-
2806
- if (!cpu_dai->active)
2807
- pinctrl_pm_select_sleep_state(cpu_dai->dev);
2808
- }
2809
-
2810
- return ret;
2199
+ return snd_soc_bind_card(card);
28112200 }
28122201 EXPORT_SYMBOL_GPL(snd_soc_register_card);
28132202
....@@ -2819,12 +2208,10 @@
28192208 */
28202209 int snd_soc_unregister_card(struct snd_soc_card *card)
28212210 {
2822
- if (card->instantiated) {
2823
- card->instantiated = false;
2824
- snd_soc_dapm_shutdown(card);
2825
- soc_cleanup_card_resources(card);
2826
- dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
2827
- }
2211
+ mutex_lock(&client_mutex);
2212
+ snd_soc_unbind_card(card, true);
2213
+ mutex_unlock(&client_mutex);
2214
+ dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
28282215
28292216 return 0;
28302217 }
....@@ -2836,13 +2223,16 @@
28362223 */
28372224 static char *fmt_single_name(struct device *dev, int *id)
28382225 {
2839
- char *found, name[NAME_SIZE];
2226
+ const char *devname = dev_name(dev);
2227
+ char *found, *name;
28402228 int id1, id2;
28412229
2842
- if (dev_name(dev) == NULL)
2230
+ if (devname == NULL)
28432231 return NULL;
28442232
2845
- strlcpy(name, dev_name(dev), NAME_SIZE);
2233
+ name = devm_kstrdup(dev, devname, GFP_KERNEL);
2234
+ if (!name)
2235
+ return NULL;
28462236
28472237 /* are we a "%s.%d" name (platform and SPI components) */
28482238 found = strstr(name, dev->driver->name);
....@@ -2855,22 +2245,21 @@
28552245 found[strlen(dev->driver->name)] = '\0';
28562246 }
28572247
2248
+ /* I2C component devices are named "bus-addr" */
2249
+ } else if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2250
+
2251
+ /* create unique ID number from I2C addr and bus */
2252
+ *id = ((id1 & 0xffff) << 16) + id2;
2253
+
2254
+ devm_kfree(dev, name);
2255
+
2256
+ /* sanitize component name for DAI link creation */
2257
+ name = devm_kasprintf(dev, GFP_KERNEL, "%s.%s", dev->driver->name, devname);
28582258 } else {
2859
- /* I2C component devices are named "bus-addr" */
2860
- if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2861
- char tmp[NAME_SIZE];
2862
-
2863
- /* create unique ID number from I2C addr and bus */
2864
- *id = ((id1 & 0xffff) << 16) + id2;
2865
-
2866
- /* sanitize component name for DAI link creation */
2867
- snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2868
- strlcpy(name, tmp, NAME_SIZE);
2869
- } else
2870
- *id = 0;
2259
+ *id = 0;
28712260 }
28722261
2873
- return kstrdup(name, GFP_KERNEL);
2262
+ return name;
28742263 }
28752264
28762265 /*
....@@ -2887,38 +2276,40 @@
28872276 return NULL;
28882277 }
28892278
2890
- return kstrdup(dai_drv->name, GFP_KERNEL);
2279
+ return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL);
28912280 }
2281
+
2282
+void snd_soc_unregister_dai(struct snd_soc_dai *dai)
2283
+{
2284
+ dev_dbg(dai->dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
2285
+ list_del(&dai->list);
2286
+}
2287
+EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
28922288
28932289 /**
2894
- * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
2290
+ * snd_soc_register_dai - Register a DAI dynamically & create its widgets
28952291 *
2896
- * @component: The component for which the DAIs should be unregistered
2292
+ * @component: The component the DAIs are registered for
2293
+ * @dai_drv: DAI driver to use for the DAI
2294
+ * @legacy_dai_naming: if %true, use legacy single-name format;
2295
+ * if %false, use multiple-name format;
2296
+ *
2297
+ * Topology can use this API to register DAIs when probing a component.
2298
+ * These DAIs's widgets will be freed in the card cleanup and the DAIs
2299
+ * will be freed in the component cleanup.
28972300 */
2898
-static void snd_soc_unregister_dais(struct snd_soc_component *component)
2899
-{
2900
- struct snd_soc_dai *dai, *_dai;
2901
-
2902
- list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
2903
- dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
2904
- dai->name);
2905
- list_del(&dai->list);
2906
- kfree(dai->name);
2907
- kfree(dai);
2908
- }
2909
-}
2910
-
2911
-/* Create a DAI and add it to the component's DAI list */
2912
-static struct snd_soc_dai *soc_add_dai(struct snd_soc_component *component,
2913
- struct snd_soc_dai_driver *dai_drv,
2914
- bool legacy_dai_naming)
2301
+struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
2302
+ struct snd_soc_dai_driver *dai_drv,
2303
+ bool legacy_dai_naming)
29152304 {
29162305 struct device *dev = component->dev;
29172306 struct snd_soc_dai *dai;
29182307
29192308 dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
29202309
2921
- dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
2310
+ lockdep_assert_held(&client_mutex);
2311
+
2312
+ dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL);
29222313 if (dai == NULL)
29232314 return NULL;
29242315
....@@ -2931,7 +2322,7 @@
29312322 * component-less anymore.
29322323 */
29332324 if (legacy_dai_naming &&
2934
- (dai_drv->id == 0 || dai_drv->name == NULL)) {
2325
+ (dai_drv->id == 0 || dai_drv->name == NULL)) {
29352326 dai->name = fmt_single_name(dev, &dai->id);
29362327 } else {
29372328 dai->name = fmt_multiple_name(dev, dai_drv);
....@@ -2940,17 +2331,14 @@
29402331 else
29412332 dai->id = component->num_dai;
29422333 }
2943
- if (dai->name == NULL) {
2944
- kfree(dai);
2334
+ if (!dai->name)
29452335 return NULL;
2946
- }
29472336
29482337 dai->component = component;
29492338 dai->dev = dev;
29502339 dai->driver = dai_drv;
2951
- if (!dai->driver->ops)
2952
- dai->driver->ops = &null_dai_ops;
29532340
2341
+ /* see for_each_component_dais */
29542342 list_add_tail(&dai->list, &component->dai_list);
29552343 component->num_dai++;
29562344
....@@ -2959,28 +2347,36 @@
29592347 }
29602348
29612349 /**
2350
+ * snd_soc_unregister_dais - Unregister DAIs from the ASoC core
2351
+ *
2352
+ * @component: The component for which the DAIs should be unregistered
2353
+ */
2354
+static void snd_soc_unregister_dais(struct snd_soc_component *component)
2355
+{
2356
+ struct snd_soc_dai *dai, *_dai;
2357
+
2358
+ for_each_component_dais_safe(component, dai, _dai)
2359
+ snd_soc_unregister_dai(dai);
2360
+}
2361
+
2362
+/**
29622363 * snd_soc_register_dais - Register a DAI with the ASoC core
29632364 *
29642365 * @component: The component the DAIs are registered for
29652366 * @dai_drv: DAI driver to use for the DAIs
29662367 * @count: Number of DAIs
2967
- * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
2968
- * parent's name.
29692368 */
29702369 static int snd_soc_register_dais(struct snd_soc_component *component,
2971
- struct snd_soc_dai_driver *dai_drv, size_t count)
2370
+ struct snd_soc_dai_driver *dai_drv,
2371
+ size_t count)
29722372 {
2973
- struct device *dev = component->dev;
29742373 struct snd_soc_dai *dai;
29752374 unsigned int i;
29762375 int ret;
29772376
2978
- dev_dbg(dev, "ASoC: dai register %s #%zu\n", dev_name(dev), count);
2979
-
29802377 for (i = 0; i < count; i++) {
2981
-
2982
- dai = soc_add_dai(component, dai_drv + i,
2983
- count == 1 && !component->driver->non_legacy_dai_naming);
2378
+ dai = snd_soc_register_dai(component, dai_drv + i, count == 1 &&
2379
+ !component->driver->non_legacy_dai_naming);
29842380 if (dai == NULL) {
29852381 ret = -ENOMEM;
29862382 goto err;
....@@ -2993,186 +2389,6 @@
29932389 snd_soc_unregister_dais(component);
29942390
29952391 return ret;
2996
-}
2997
-
2998
-/**
2999
- * snd_soc_register_dai - Register a DAI dynamically & create its widgets
3000
- *
3001
- * @component: The component the DAIs are registered for
3002
- * @dai_drv: DAI driver to use for the DAI
3003
- *
3004
- * Topology can use this API to register DAIs when probing a component.
3005
- * These DAIs's widgets will be freed in the card cleanup and the DAIs
3006
- * will be freed in the component cleanup.
3007
- */
3008
-int snd_soc_register_dai(struct snd_soc_component *component,
3009
- struct snd_soc_dai_driver *dai_drv)
3010
-{
3011
- struct snd_soc_dapm_context *dapm =
3012
- snd_soc_component_get_dapm(component);
3013
- struct snd_soc_dai *dai;
3014
- int ret;
3015
-
3016
- if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) {
3017
- dev_err(component->dev, "Invalid dai type %d\n",
3018
- dai_drv->dobj.type);
3019
- return -EINVAL;
3020
- }
3021
-
3022
- lockdep_assert_held(&client_mutex);
3023
- dai = soc_add_dai(component, dai_drv, false);
3024
- if (!dai)
3025
- return -ENOMEM;
3026
-
3027
- /* Create the DAI widgets here. After adding DAIs, topology may
3028
- * also add routes that need these widgets as source or sink.
3029
- */
3030
- ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
3031
- if (ret != 0) {
3032
- dev_err(component->dev,
3033
- "Failed to create DAI widgets %d\n", ret);
3034
- }
3035
-
3036
- return ret;
3037
-}
3038
-EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3039
-
3040
-static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm,
3041
- enum snd_soc_dapm_type type, int subseq)
3042
-{
3043
- struct snd_soc_component *component = dapm->component;
3044
-
3045
- component->driver->seq_notifier(component, type, subseq);
3046
-}
3047
-
3048
-static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm,
3049
- int event)
3050
-{
3051
- struct snd_soc_component *component = dapm->component;
3052
-
3053
- return component->driver->stream_event(component, event);
3054
-}
3055
-
3056
-static int snd_soc_component_set_bias_level(struct snd_soc_dapm_context *dapm,
3057
- enum snd_soc_bias_level level)
3058
-{
3059
- struct snd_soc_component *component = dapm->component;
3060
-
3061
- return component->driver->set_bias_level(component, level);
3062
-}
3063
-
3064
-static int snd_soc_component_initialize(struct snd_soc_component *component,
3065
- const struct snd_soc_component_driver *driver, struct device *dev)
3066
-{
3067
- struct snd_soc_dapm_context *dapm;
3068
-
3069
- component->name = fmt_single_name(dev, &component->id);
3070
- if (!component->name) {
3071
- dev_err(dev, "ASoC: Failed to allocate name\n");
3072
- return -ENOMEM;
3073
- }
3074
-
3075
- component->dev = dev;
3076
- component->driver = driver;
3077
-
3078
- dapm = snd_soc_component_get_dapm(component);
3079
- dapm->dev = dev;
3080
- dapm->component = component;
3081
- dapm->bias_level = SND_SOC_BIAS_OFF;
3082
- dapm->idle_bias_off = !driver->idle_bias_on;
3083
- dapm->suspend_bias_off = driver->suspend_bias_off;
3084
- if (driver->seq_notifier)
3085
- dapm->seq_notifier = snd_soc_component_seq_notifier;
3086
- if (driver->stream_event)
3087
- dapm->stream_event = snd_soc_component_stream_event;
3088
- if (driver->set_bias_level)
3089
- dapm->set_bias_level = snd_soc_component_set_bias_level;
3090
-
3091
- INIT_LIST_HEAD(&component->dai_list);
3092
- mutex_init(&component->io_mutex);
3093
-
3094
- return 0;
3095
-}
3096
-
3097
-static void snd_soc_component_setup_regmap(struct snd_soc_component *component)
3098
-{
3099
- int val_bytes = regmap_get_val_bytes(component->regmap);
3100
-
3101
- /* Errors are legitimate for non-integer byte multiples */
3102
- if (val_bytes > 0)
3103
- component->val_bytes = val_bytes;
3104
-}
3105
-
3106
-#ifdef CONFIG_REGMAP
3107
-
3108
-/**
3109
- * snd_soc_component_init_regmap() - Initialize regmap instance for the component
3110
- * @component: The component for which to initialize the regmap instance
3111
- * @regmap: The regmap instance that should be used by the component
3112
- *
3113
- * This function allows deferred assignment of the regmap instance that is
3114
- * associated with the component. Only use this if the regmap instance is not
3115
- * yet ready when the component is registered. The function must also be called
3116
- * before the first IO attempt of the component.
3117
- */
3118
-void snd_soc_component_init_regmap(struct snd_soc_component *component,
3119
- struct regmap *regmap)
3120
-{
3121
- component->regmap = regmap;
3122
- snd_soc_component_setup_regmap(component);
3123
-}
3124
-EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
3125
-
3126
-/**
3127
- * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component
3128
- * @component: The component for which to de-initialize the regmap instance
3129
- *
3130
- * Calls regmap_exit() on the regmap instance associated to the component and
3131
- * removes the regmap instance from the component.
3132
- *
3133
- * This function should only be used if snd_soc_component_init_regmap() was used
3134
- * to initialize the regmap instance.
3135
- */
3136
-void snd_soc_component_exit_regmap(struct snd_soc_component *component)
3137
-{
3138
- regmap_exit(component->regmap);
3139
- component->regmap = NULL;
3140
-}
3141
-EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
3142
-
3143
-#endif
3144
-
3145
-static void snd_soc_component_add(struct snd_soc_component *component)
3146
-{
3147
- mutex_lock(&client_mutex);
3148
-
3149
- if (!component->driver->write && !component->driver->read) {
3150
- if (!component->regmap)
3151
- component->regmap = dev_get_regmap(component->dev, NULL);
3152
- if (component->regmap)
3153
- snd_soc_component_setup_regmap(component);
3154
- }
3155
-
3156
- list_add(&component->list, &component_list);
3157
- INIT_LIST_HEAD(&component->dobj_list);
3158
-
3159
- mutex_unlock(&client_mutex);
3160
-}
3161
-
3162
-static void snd_soc_component_cleanup(struct snd_soc_component *component)
3163
-{
3164
- snd_soc_unregister_dais(component);
3165
- kfree(component->name);
3166
-}
3167
-
3168
-static void snd_soc_component_del_unlocked(struct snd_soc_component *component)
3169
-{
3170
- struct snd_soc_card *card = component->card;
3171
-
3172
- if (card)
3173
- snd_soc_unregister_card(card);
3174
-
3175
- list_del(&component->list);
31762392 }
31772393
31782394 #define ENDIANNESS_MAP(name) \
....@@ -3210,20 +2426,60 @@
32102426 stream->formats |= endianness_format_map[i];
32112427 }
32122428
3213
-int snd_soc_add_component(struct device *dev,
3214
- struct snd_soc_component *component,
3215
- const struct snd_soc_component_driver *component_driver,
3216
- struct snd_soc_dai_driver *dai_drv,
3217
- int num_dai)
2429
+static void snd_soc_try_rebind_card(void)
2430
+{
2431
+ struct snd_soc_card *card, *c;
2432
+
2433
+ list_for_each_entry_safe(card, c, &unbind_card_list, list)
2434
+ if (!snd_soc_bind_card(card))
2435
+ list_del(&card->list);
2436
+}
2437
+
2438
+static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
2439
+{
2440
+ struct snd_soc_card *card = component->card;
2441
+
2442
+ snd_soc_unregister_dais(component);
2443
+
2444
+ if (card)
2445
+ snd_soc_unbind_card(card, false);
2446
+
2447
+ list_del(&component->list);
2448
+}
2449
+
2450
+int snd_soc_component_initialize(struct snd_soc_component *component,
2451
+ const struct snd_soc_component_driver *driver,
2452
+ struct device *dev)
2453
+{
2454
+ INIT_LIST_HEAD(&component->dai_list);
2455
+ INIT_LIST_HEAD(&component->dobj_list);
2456
+ INIT_LIST_HEAD(&component->card_list);
2457
+ INIT_LIST_HEAD(&component->list);
2458
+ mutex_init(&component->io_mutex);
2459
+
2460
+ component->name = fmt_single_name(dev, &component->id);
2461
+ if (!component->name) {
2462
+ dev_err(dev, "ASoC: Failed to allocate name\n");
2463
+ return -ENOMEM;
2464
+ }
2465
+
2466
+ component->dev = dev;
2467
+ component->driver = driver;
2468
+
2469
+ return 0;
2470
+}
2471
+EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
2472
+
2473
+int snd_soc_add_component(struct snd_soc_component *component,
2474
+ struct snd_soc_dai_driver *dai_drv,
2475
+ int num_dai)
32182476 {
32192477 int ret;
32202478 int i;
32212479
3222
- ret = snd_soc_component_initialize(component, component_driver, dev);
3223
- if (ret)
3224
- goto err_free;
2480
+ mutex_lock(&client_mutex);
32252481
3226
- if (component_driver->endianness) {
2482
+ if (component->driver->endianness) {
32272483 for (i = 0; i < num_dai; i++) {
32282484 convert_endianness_formats(&dai_drv[i].playback);
32292485 convert_endianness_formats(&dai_drv[i].capture);
....@@ -3232,17 +2488,31 @@
32322488
32332489 ret = snd_soc_register_dais(component, dai_drv, num_dai);
32342490 if (ret < 0) {
3235
- dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
2491
+ dev_err(component->dev, "ASoC: Failed to register DAIs: %d\n",
2492
+ ret);
32362493 goto err_cleanup;
32372494 }
32382495
3239
- snd_soc_component_add(component);
2496
+ if (!component->driver->write && !component->driver->read) {
2497
+ if (!component->regmap)
2498
+ component->regmap = dev_get_regmap(component->dev,
2499
+ NULL);
2500
+ if (component->regmap)
2501
+ snd_soc_component_setup_regmap(component);
2502
+ }
32402503
3241
- return 0;
2504
+ /* see for_each_component */
2505
+ list_add(&component->list, &component_list);
32422506
32432507 err_cleanup:
3244
- snd_soc_component_cleanup(component);
3245
-err_free:
2508
+ if (ret < 0)
2509
+ snd_soc_del_component_unlocked(component);
2510
+
2511
+ mutex_unlock(&client_mutex);
2512
+
2513
+ if (ret == 0)
2514
+ snd_soc_try_rebind_card();
2515
+
32462516 return ret;
32472517 }
32482518 EXPORT_SYMBOL_GPL(snd_soc_add_component);
....@@ -3253,15 +2523,46 @@
32532523 int num_dai)
32542524 {
32552525 struct snd_soc_component *component;
2526
+ int ret;
32562527
32572528 component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
32582529 if (!component)
32592530 return -ENOMEM;
32602531
3261
- return snd_soc_add_component(dev, component, component_driver,
3262
- dai_drv, num_dai);
2532
+ ret = snd_soc_component_initialize(component, component_driver, dev);
2533
+ if (ret < 0)
2534
+ return ret;
2535
+
2536
+ return snd_soc_add_component(component, dai_drv, num_dai);
32632537 }
32642538 EXPORT_SYMBOL_GPL(snd_soc_register_component);
2539
+
2540
+/**
2541
+ * snd_soc_unregister_component_by_driver - Unregister component using a given driver
2542
+ * from the ASoC core
2543
+ *
2544
+ * @dev: The device to unregister
2545
+ * @component_driver: The component driver to unregister
2546
+ */
2547
+void snd_soc_unregister_component_by_driver(struct device *dev,
2548
+ const struct snd_soc_component_driver *component_driver)
2549
+{
2550
+ struct snd_soc_component *component;
2551
+
2552
+ if (!component_driver)
2553
+ return;
2554
+
2555
+ mutex_lock(&client_mutex);
2556
+ component = snd_soc_lookup_component_nolocked(dev, component_driver->name);
2557
+ if (!component)
2558
+ goto out;
2559
+
2560
+ snd_soc_del_component_unlocked(component);
2561
+
2562
+out:
2563
+ mutex_unlock(&client_mutex);
2564
+}
2565
+EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver);
32652566
32662567 /**
32672568 * snd_soc_unregister_component - Unregister all related component
....@@ -3269,72 +2570,21 @@
32692570 *
32702571 * @dev: The device to unregister
32712572 */
3272
-static int __snd_soc_unregister_component(struct device *dev)
3273
-{
3274
- struct snd_soc_component *component;
3275
- int found = 0;
3276
-
3277
- mutex_lock(&client_mutex);
3278
- list_for_each_entry(component, &component_list, list) {
3279
- if (dev != component->dev)
3280
- continue;
3281
-
3282
- snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL);
3283
- snd_soc_component_del_unlocked(component);
3284
- found = 1;
3285
- break;
3286
- }
3287
- mutex_unlock(&client_mutex);
3288
-
3289
- if (found) {
3290
- snd_soc_component_cleanup(component);
3291
- }
3292
-
3293
- return found;
3294
-}
3295
-
32962573 void snd_soc_unregister_component(struct device *dev)
32972574 {
3298
- while (__snd_soc_unregister_component(dev));
3299
-}
3300
-EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
3301
-
3302
-struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
3303
- const char *driver_name)
3304
-{
33052575 struct snd_soc_component *component;
3306
- struct snd_soc_component *ret;
33072576
3308
- ret = NULL;
33092577 mutex_lock(&client_mutex);
3310
- list_for_each_entry(component, &component_list, list) {
3311
- if (dev != component->dev)
3312
- continue;
2578
+ while (1) {
2579
+ component = snd_soc_lookup_component_nolocked(dev, NULL);
2580
+ if (!component)
2581
+ break;
33132582
3314
- if (driver_name &&
3315
- (driver_name != component->driver->name) &&
3316
- (strcmp(component->driver->name, driver_name) != 0))
3317
- continue;
3318
-
3319
- ret = component;
3320
- break;
2583
+ snd_soc_del_component_unlocked(component);
33212584 }
33222585 mutex_unlock(&client_mutex);
3323
-
3324
- return ret;
33252586 }
3326
-EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
3327
-
3328
-/**
3329
- * snd_soc_card_change_online_state - Mark if soc card is online/offline
3330
- *
3331
- * @soc_card : soc_card to mark
3332
- */
3333
-void snd_soc_card_change_online_state(struct snd_soc_card *soc_card, int online)
3334
-{
3335
- snd_card_change_online_state(soc_card->snd_card, online);
3336
-}
3337
-EXPORT_SYMBOL_GPL(snd_soc_card_change_online_state);
2587
+EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
33382588
33392589 /* Retrieve a card's name from device tree */
33402590 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
....@@ -3509,12 +2759,11 @@
35092759 }
35102760 EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
35112761
3512
-void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
3513
- struct snd_soc_codec_conf *codec_conf,
3514
- struct device_node *of_node,
3515
- const char *propname)
2762
+void snd_soc_of_parse_node_prefix(struct device_node *np,
2763
+ struct snd_soc_codec_conf *codec_conf,
2764
+ struct device_node *of_node,
2765
+ const char *propname)
35162766 {
3517
- struct device_node *np = card->dev->of_node;
35182767 const char *str;
35192768 int ret;
35202769
....@@ -3524,10 +2773,10 @@
35242773 return;
35252774 }
35262775
3527
- codec_conf->of_node = of_node;
2776
+ codec_conf->dlc.of_node = of_node;
35282777 codec_conf->name_prefix = str;
35292778 }
3530
-EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_prefix);
2779
+EXPORT_SYMBOL_GPL(snd_soc_of_parse_node_prefix);
35312780
35322781 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
35332782 const char *propname)
....@@ -3584,6 +2833,37 @@
35842833 return 0;
35852834 }
35862835 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
2836
+
2837
+int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname)
2838
+{
2839
+ struct device_node *node = card->dev->of_node;
2840
+ struct snd_soc_aux_dev *aux;
2841
+ int num, i;
2842
+
2843
+ num = of_count_phandle_with_args(node, propname, NULL);
2844
+ if (num == -ENOENT) {
2845
+ return 0;
2846
+ } else if (num < 0) {
2847
+ dev_err(card->dev, "ASOC: Property '%s' could not be read: %d\n",
2848
+ propname, num);
2849
+ return num;
2850
+ }
2851
+
2852
+ aux = devm_kcalloc(card->dev, num, sizeof(*aux), GFP_KERNEL);
2853
+ if (!aux)
2854
+ return -ENOMEM;
2855
+ card->aux_dev = aux;
2856
+ card->num_aux_devs = num;
2857
+
2858
+ for_each_card_pre_auxs(card, i, aux) {
2859
+ aux->dlc.of_node = of_parse_phandle(node, propname, i);
2860
+ if (!aux->dlc.of_node)
2861
+ return -EINVAL;
2862
+ }
2863
+
2864
+ return 0;
2865
+}
2866
+EXPORT_SYMBOL_GPL(snd_soc_of_parse_aux_devs);
35872867
35882868 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
35892869 const char *prefix,
....@@ -3704,12 +2984,12 @@
37042984
37052985 int snd_soc_get_dai_id(struct device_node *ep)
37062986 {
3707
- struct snd_soc_component *pos;
3708
- struct device_node *node;
2987
+ struct snd_soc_component *component;
2988
+ struct snd_soc_dai_link_component dlc;
37092989 int ret;
37102990
3711
- node = of_graph_get_port_parent(ep);
3712
-
2991
+ dlc.of_node = of_graph_get_port_parent(ep);
2992
+ dlc.name = NULL;
37132993 /*
37142994 * For example HDMI case, HDMI has video/sound port,
37152995 * but ALSA SoC needs sound port number only.
....@@ -3718,23 +2998,12 @@
37182998 */
37192999 ret = -ENOTSUPP;
37203000 mutex_lock(&client_mutex);
3721
- list_for_each_entry(pos, &component_list, list) {
3722
- struct device_node *component_of_node = pos->dev->of_node;
3723
-
3724
- if (!component_of_node && pos->dev->parent)
3725
- component_of_node = pos->dev->parent->of_node;
3726
-
3727
- if (component_of_node != node)
3728
- continue;
3729
-
3730
- if (pos->driver->of_xlate_dai_id)
3731
- ret = pos->driver->of_xlate_dai_id(pos, ep);
3732
-
3733
- break;
3734
- }
3001
+ component = soc_find_component(&dlc);
3002
+ if (component)
3003
+ ret = snd_soc_component_of_xlate_dai_id(component, ep);
37353004 mutex_unlock(&client_mutex);
37363005
3737
- of_node_put(node);
3006
+ of_node_put(dlc.of_node);
37383007
37393008 return ret;
37403009 }
....@@ -3781,19 +3050,14 @@
37813050 int ret = -EPROBE_DEFER;
37823051
37833052 mutex_lock(&client_mutex);
3784
- list_for_each_entry(pos, &component_list, list) {
3785
- component_of_node = pos->dev->of_node;
3786
- if (!component_of_node && pos->dev->parent)
3787
- component_of_node = pos->dev->parent->of_node;
3053
+ for_each_component(pos) {
3054
+ component_of_node = soc_component_to_node(pos);
37883055
3789
- if (component_of_node != args->np)
3056
+ if (component_of_node != args->np || !pos->num_dai)
37903057 continue;
37913058
3792
- if (pos->driver->of_xlate_dai_name) {
3793
- ret = pos->driver->of_xlate_dai_name(pos,
3794
- args,
3795
- dai_name);
3796
- } else {
3059
+ ret = snd_soc_component_of_xlate_dai_name(pos, args, dai_name);
3060
+ if (ret == -ENOTSUPP) {
37973061 struct snd_soc_dai *dai;
37983062 int id = -1;
37993063
....@@ -3817,7 +3081,7 @@
38173081 ret = 0;
38183082
38193083 /* find target DAI */
3820
- list_for_each_entry(dai, &pos->dai_list, list) {
3084
+ for_each_component_dais(pos, dai) {
38213085 if (id == 0)
38223086 break;
38233087 id--;
....@@ -3826,6 +3090,14 @@
38263090 *dai_name = dai->driver->name;
38273091 if (!*dai_name)
38283092 *dai_name = pos->name;
3093
+ } else if (ret) {
3094
+ /*
3095
+ * if another error than ENOTSUPP is returned go on and
3096
+ * check if another component is provided with the same
3097
+ * node. This may happen if a device provides several
3098
+ * components
3099
+ */
3100
+ continue;
38293101 }
38303102
38313103 break;
....@@ -3862,10 +3134,10 @@
38623134 */
38633135 void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
38643136 {
3865
- struct snd_soc_dai_link_component *component = dai_link->codecs;
3137
+ struct snd_soc_dai_link_component *component;
38663138 int index;
38673139
3868
- for (index = 0; index < dai_link->num_codecs; index++, component++) {
3140
+ for_each_link_codecs(dai_link, index, component) {
38693141 if (!component->of_node)
38703142 break;
38713143 of_node_put(component->of_node);
....@@ -3917,12 +3189,10 @@
39173189 dai_link->num_codecs = num_codecs;
39183190
39193191 /* Parse the list */
3920
- for (index = 0, component = dai_link->codecs;
3921
- index < dai_link->num_codecs;
3922
- index++, component++) {
3192
+ for_each_link_codecs(dai_link, index, component) {
39233193 ret = of_parse_phandle_with_args(of_node, name,
39243194 "#sound-dai-cells",
3925
- index, &args);
3195
+ index, &args);
39263196 if (ret)
39273197 goto err;
39283198 component->of_node = args.np;
....@@ -3941,10 +3211,23 @@
39413211
39423212 static int __init snd_soc_init(void)
39433213 {
3944
- snd_soc_debugfs_init();
3945
- snd_soc_util_init();
3214
+ int ret;
39463215
3947
- return platform_driver_register(&soc_driver);
3216
+ snd_soc_debugfs_init();
3217
+ ret = snd_soc_util_init();
3218
+ if (ret)
3219
+ goto err_util_init;
3220
+
3221
+ ret = platform_driver_register(&soc_driver);
3222
+ if (ret)
3223
+ goto err_register;
3224
+ return 0;
3225
+
3226
+err_register:
3227
+ snd_soc_util_exit();
3228
+err_util_init:
3229
+ snd_soc_debugfs_exit();
3230
+ return ret;
39483231 }
39493232 module_init(snd_soc_init);
39503233